Skip to content

Commit

Permalink
PG: emits Watch API checkpoints outside of changes
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
vroldanbet committed Sep 16, 2024
1 parent e629448 commit 222228c
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions internal/datastore/postgres/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
}
}
}
}()

Expand Down

0 comments on commit 222228c

Please sign in to comment.