Minor fixes and improvements for progress tracking#311
Minor fixes and improvements for progress tracking#311mason-sharp wants to merge 3 commits intomainfrom
Conversation
mason-sharp
commented
Jan 12, 2026
- 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
danolivo
left a comment
There was a problem hiding this comment.
It looks correct. Minor fixes should be addressed before the merge.
src/spock_group.c
Outdated
| 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", |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
Good catch! But call:
progress_entries_list = adjust_progress_info(origin_conn);
should be done right before the ensure_replication_slot_snapshot().
There was a problem hiding this comment.
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
679df29 to
a78e2cf
Compare
src/spock_sync.c
Outdated
| origin_conn_repl = spock_connect_replica(sub->origin_if->dsn, | ||
| sub->name, "snap"); | ||
|
|
||
| adjust_progress_info(origin_conn); |
There was a problem hiding this comment.
How is it supposed to work?
I don't see here following spock_group_progress_update_list() ...
📝 WalkthroughWalkthroughReplaces public API Changes
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
ec5beab to
7a36d8b
Compare
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.
648f376 to
d5d7c1a
Compare
There was a problem hiding this comment.
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 | 🟠 MajorProgress 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., withincopy_replication_sets_dataafterstart_copy_origin_tx) and returning the list for the post‑COPY update at Line 1254. Also, whenSyncKindData(sync->kind)is false, the list is allocated but never freed; guard the call or free the list in the non‑data path.