Skip to content

Minor fixes and improvements for progress tracking#311

Open
mason-sharp wants to merge 3 commits intomainfrom
progress-track-minor-improvements
Open

Minor fixes and improvements for progress tracking#311
mason-sharp wants to merge 3 commits intomainfrom
progress-track-minor-improvements

Conversation

@mason-sharp
Copy link
Member

  • Refactor apply_worker_get_progress() to return only the timestamp needed. Return value instead of pointer to entire struct.
  • Lock sooner in spock_group_resource_dump() because of getting the number of entries
  • Properly handle progress updates after COPY operations in replication set data sync and avoid potential memory leak
  • Address compiler warnings

Copy link
Contributor

@danolivo danolivo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks correct. Minor fixes should be addressed before the merge.

elog(LOG, "SPOCK: adjust spock.progress %d->%d to "
"remote_commit_ts='%s' "
"remote_commit_lsn=%llX remote_insert_lsn=%llX",
"remote_commit_lsn=%lX remote_insert_lsn=%lX",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both variants are incorrect. Conventional way: use the LSN_FORMAT_ARGS macros instead.

src/spock_sync.c Outdated
}

adjust_progress_info(origin_conn);
progress_entries_list = adjust_progress_info(origin_conn);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! But call:
progress_entries_list = adjust_progress_info(origin_conn);
should be done right before the ensure_replication_slot_snapshot().

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After fixing this, you may launch the following workflow on your branch: https://github.com/pgEdge/spock/actions/runs/21101567363
It fails now in 100% of cases. With this case, it should pass (about 99% or so).

- Refactor apply_worker_get_progress() to return only the timestamp needed. Return value instead of pointer to entire struct.
- Lock sooner in spock_group_resource_dump() because of getting the number of entries
- Properly handle progress updates after COPY operations in replication set data sync and avoid potential memory leak
- Address compiler warnings
@mason-sharp mason-sharp force-pushed the progress-track-minor-improvements branch from 679df29 to a78e2cf Compare February 3, 2026 02:18
src/spock_sync.c Outdated
origin_conn_repl = spock_connect_replica(sub->origin_if->dsn,
sub->name, "snap");

adjust_progress_info(origin_conn);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is it supposed to work?
I don't see here following spock_group_progress_update_list() ...

@coderabbitai
Copy link

coderabbitai bot commented Feb 5, 2026

📝 Walkthrough

Walkthrough

Replaces public API apply_worker_get_progress() (returning SpockApplyProgress *) with apply_worker_get_prev_remote_ts() (returns TimestampTz); updates call sites to use the new accessor, adjusts locking and LSN formatting in group code, defers progress updates around COPY, and removes a local variable in executor code.

Changes

Cohort / File(s) Summary
Public API & Header
include/spock_group.h
Changed declaration: extern SpockApplyProgress *apply_worker_get_progress(void);extern TimestampTz apply_worker_get_prev_remote_ts(void); (public signature changed).
Group implementation & logging
src/spock_group.c
Replaced old accessor with apply_worker_get_prev_remote_ts() returning a timestamp; adjusted progress handling, parenthesized invariant, moved an early lock in resource_dump, and switched LSN log formatting to LSN_FORMAT_ARGS.
Apply path usage
src/spock_apply.c
Replaced apply_worker_get_progress()->prev_remote_ts usages with apply_worker_get_prev_remote_ts() in comparisons and log messages.
Sync / COPY progress aggregation
src/spock_sync.c
Deferred immediate adjust_progress_info(); introduced progress_entries_list to collect entries and call spock_group_progress_update_list(progress_entries_list) after the COPY phase.
Executor potential issue
src/spock_executor.c
Removed local ObjectAddress object declaration in the OAT_DROP branch of spock_object_access(), which may leave object undefined for subsequent ObjectAddressSubSet use—requires review.

Poem

🐇 I nibble timestamps under starlit code,
I fetch the last remote where markers flowed.
Locks lined up, LSNs in bright array,
Progress bundled after COPY’s long day.
Hop—new name, same trail, off I go!

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main refactoring work: improving progress tracking through API simplification and minor fixes.
Description check ✅ Passed The description is directly related to the changeset, covering the key improvements: API refactoring, lock timing, progress update handling, and compiler warnings.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch progress-track-minor-improvements

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@mason-sharp mason-sharp force-pushed the progress-track-minor-improvements branch from ec5beab to 7a36d8b Compare February 5, 2026 03:07
Previously, adjust_progress_info() and spock_group_progress_update_list()
were called inside copy_replication_sets_data(), between the COPY
transaction finish and function return. This was incorrect because the
progress update must happen after the COPY transaction is committed on
both origin and target, and the snapshot used for progress info must be
consistent with the replication slot snapshot.

Move adjust_progress_info() to spock_sync_subscription() right before
ensure_replication_slot_snapshot(), so it captures progress using the
same connection and transaction context. Move
spock_group_progress_update_list() to after copy_replication_sets_data()
returns, ensuring replication progress is updated only after all copied
data has been committed.
@danolivo danolivo force-pushed the progress-track-minor-improvements branch from 648f376 to d5d7c1a Compare February 5, 2026 10:13
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/spock_sync.c (1)

1163-1254: ⚠️ Potential issue | 🟠 Major

Progress list is captured outside the COPY snapshot.

Line 1179 calls adjust_progress_info(origin_conn) before the replication-slot snapshot is exported, so the values can drift from the snapshot used for COPY. That can lead to over/under‑skipping when replication starts. Consider capturing progress inside the COPY snapshot transaction (e.g., within copy_replication_sets_data after start_copy_origin_tx) and returning the list for the post‑COPY update at Line 1254. Also, when SyncKindData(sync->kind) is false, the list is allocated but never freed; guard the call or free the list in the non‑data path.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants