From 222228cb716b0bac58e1dcc47f1a5cd8c8dddf67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Rold=C3=A1n=20Betancort?= Date: Mon, 16 Sep 2024 15:53:44 +0100 Subject: [PATCH] PG: emits Watch API checkpoints outside of changes the Watch API loop does not emit checkpoints outside of changes, making it hard for clients to distinguish between actual lagging and a system that isn't observing any changes. For example, CockroachDB datastore implementation will emit checkpoints even if no changes are emitted. --- internal/datastore/postgres/watch.go | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/internal/datastore/postgres/watch.go b/internal/datastore/postgres/watch.go index 2c7a2d3c97..1f95a72fcb 100644 --- a/internal/datastore/postgres/watch.go +++ b/internal/datastore/postgres/watch.go @@ -158,18 +158,6 @@ func (pgd *pgDatastore) Watch( optionalNanosTimestamp: currentTxn.optionalNanosTimestamp, } } - - // If checkpoints were requested, output a checkpoint. While the Postgres datastore does not - // move revisions forward outside of changes, these could be necessary if the caller is - // watching only a *subset* of changes. - if options.Content&datastore.WatchCheckpoints == datastore.WatchCheckpoints { - if !sendChange(&datastore.RevisionChanges{ - Revision: currentTxn, - IsCheckpoint: true, - }) { - return - } - } } else { sleep := time.NewTimer(watchSleep) @@ -181,6 +169,18 @@ func (pgd *pgDatastore) Watch( return } } + + // If checkpoints were requested, output a checkpoint. While the Postgres datastore does not + // move revisions forward outside of changes, these could be necessary if the caller is + // watching only a *subset* of changes. + if options.Content&datastore.WatchCheckpoints == datastore.WatchCheckpoints { + if !sendChange(&datastore.RevisionChanges{ + Revision: currentTxn, + IsCheckpoint: true, + }) { + return + } + } } }()