Skip to content
Merged
Show file tree
Hide file tree
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
10 changes: 9 additions & 1 deletion server/internal/database/wait_for_sync_event_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,20 @@ func (r *WaitForSyncEventResource) Refresh(ctx context.Context, rc *resource.Con
}

// TODO: Set wait limit
err = postgres.WaitForSyncEvent(r.ProviderNode, syncEvent.SyncEventLsn, 100).Exec(ctx, subscriberConn)
synced, err := postgres.WaitForSyncEvent(r.ProviderNode, syncEvent.SyncEventLsn, 100).Scalar(ctx, subscriberConn)
if errors.Is(err, pgx.ErrNoRows) {
return resource.ErrNotFound
} else if err != nil {
return fmt.Errorf("failed to wait for sync event on subscriber: %w", err)
}
if !synced {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

After waiting for replication to catch up, this code checks Spock’s result.

  • If synced is false, it means the subscriber node did not reach the required replication point (the expected LSN) before the timeout.
  • Because of that, the control plane treats it as a real failure and stops the workflow.
  • The error message includes the provider node, subscriber node, the LSN it was waiting for, and the timeout, so anyone reading the logs can quickly see what sync check failed and why.

return fmt.Errorf("replication sync not confirmed: provider=%s subscriber=%s lsn=%s timeout_seconds=%d",
r.ProviderNode,
r.SubscriberNode,
syncEvent.SyncEventLsn,
100,
Copy link

Copilot AI Jan 19, 2026

Choose a reason for hiding this comment

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

The timeout value 100 is hardcoded in multiple places (line 76 and line 89). Consider extracting this magic number into a named constant to improve maintainability and ensure consistency.

Copilot uses AI. Check for mistakes.
)
}

return nil
}
Expand Down
4 changes: 2 additions & 2 deletions server/internal/postgres/create_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,8 @@ func SyncEvent() Query[string] {
}
}

func WaitForSyncEvent(originNode, lsn string, timeoutSeconds int) Statement {
return Statement{
func WaitForSyncEvent(originNode, lsn string, timeoutSeconds int) Query[bool] {
return Query[bool]{
SQL: "CALL spock.wait_for_sync_event(true, @origin_node, @lsn, @timeout);",
Args: pgx.NamedArgs{
"origin_node": originNode,
Expand Down