Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add additional sync finish condition check to fix infinite catchup status #447

Open
wants to merge 1 commit into
base: REL2_x_STABLE
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions pglogical_apply.c
Original file line number Diff line number Diff line change
Expand Up @@ -1485,7 +1485,38 @@ apply_work(PGconn *streamConn)
send_feedback(applyconn, last_received, GetCurrentTimestamp(), false);

if (!in_remote_transaction)
{
process_syncing_tables(last_received);

/* checking whether sync can finish.
* If sync process synced very closely to the remote,
* there is a possibility that no commit after the start point.
* If that is the case, sync/apply workers are infinitely waiting a commit to finish.
* This can happened when `alter_subscription_resynchronize_table()` called
* randomly.
* To address that issue, we can evaluate sync finish condition here */
if (MyPGLogicalWorker->worker_type == PGLOGICAL_WORKER_SYNC &&
MyApplyWorker->replay_stop_lsn != InvalidXLogRecPtr &&
last_received >= MyApplyWorker->replay_stop_lsn) {
StartTransactionCommand();
/*
* In case there is nothing to catchup, finish immediately.
* Note pglogical_sync_worker_finish() will commit.
*/
/* Mark local table as done. */
set_table_sync_status(MyApplyWorker->subid,
NameStr(MyPGLogicalWorker->worker.sync.nspname),
NameStr(MyPGLogicalWorker->worker.sync.relname),
SYNC_STATUS_SYNCDONE, last_received);
CommitTransactionCommand();
PQfinish(applyconn);
pglogical_sync_worker_finish();

/* stop process */
proc_exit(0);
}
}


/* We must not have switched out of MessageContext by mistake */
Assert(CurrentMemoryContext == MessageContext);
Expand Down