Skip to content

Commit b89e4aa

Browse files
craig[bot]fqazi
andcommitted
Merge #159541
159541: catalog/lease: fix race condition against rangefeed start r=fqazi a=fqazi Previously, it was possible for the lease manager range feed to start tracking updates later then when we started handing out leases. This was possible because no timestamp was provided to the range feed, so the server would select the start time, when the request was processed. This meant there was a small timing window during which updates to descriptors could be lost, which could happen within test scenarios. To address this, this patch explicitly selects the current time to start the range feed to avoid risk of missing updates. Fixes: #158328 Release note: None Co-authored-by: Faizan Qazi <[email protected]>
2 parents 7eb4054 + 334aa80 commit b89e4aa

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

pkg/sql/catalog/lease/lease.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2826,11 +2826,18 @@ func (m *Manager) watchForUpdates(ctx context.Context) {
28262826
}
28272827
log.Dev.Warningf(ctx, "range feed was not closed before a restart attempt")
28282828
}
2829+
// Always populate a timestamp on the range feed, otherwise we run the risk
2830+
// of a race condition between when the range feed selects a timestamp versus
2831+
// when we start handing out leases (i.e. close waitForInit) The startup below
2832+
// is asynchronous in nature, so the timestamp could be after close the waitForInit
2833+
// channel.
2834+
now := m.storage.db.KV().Clock().Now()
2835+
log.Dev.Infof(ctx, "starting lease manager rangefeed at timestamp %s", now)
28292836
// Ignore errors here because they indicate that the server is shutting down.
28302837
// Also note that the range feed automatically shuts down when the server
28312838
// shuts down, so we don't need to call Close() ourselves.
28322839
m.mu.rangeFeed, _ = m.rangeFeedFactory.RangeFeed(
2833-
ctx, "lease", []roachpb.Span{descriptorTableSpan}, hlc.Timestamp{}, handleEvent,
2840+
ctx, "lease", []roachpb.Span{descriptorTableSpan}, now, handleEvent,
28342841
rangefeed.WithSystemTablePriority(),
28352842
rangefeed.WithOnCheckpoint(handleCheckpoint),
28362843
rangefeed.WithOnInternalError(func(ctx context.Context, err error) {

0 commit comments

Comments
 (0)