Repository navigation
Fix blocksToDelete shipper initialization race - #7753
Rohithmatham12 wants to merge 2 commits into
Conversation
Signed-off-by: Rohithmatham12 <rohithmatham@gmail.com>
| userDB.shipperMetadataFilePath = filepath.Join(db.Dir(), filepath.Clean(shipper.DefaultMetaFilename)) | ||
| } | ||
|
|
||
| userDB.db = db |
There was a problem hiding this comment.
Moving this assignment after the shipper changes the order of two plain writes, but it doesn't synchronize them with the reader. tsdb.Open has already started the reload goroutine (BlockReloadInterval is 1m), which calls blocksToDelete and reads u.db and u.shipper without a lock or atomic, so -race still reports this write against the u.db == nil read. I reproduced it with a small probe: a goroutine calling u.blocksToDelete(nil) in a loop while the test assigns u.db = db fails under go test -race with a data race on exactly this pair. Could we publish with synchronization instead, e.g. an atomic.Bool set after db and shipper are assigned and checked at the top of blocksToDelete, and add a -race test for it?
|
Thanks for catching this. I added an atomic publication flag that is stored only after
It passes at |
What this changes
Why
tsdb.Open installs userDB.blocksToDelete as a callback and can run block reload work concurrently. Previously createTSDB assigned userDB.db before creating userDB.shipper, so the callback could read userDB.shipper while the constructor wrote it. Creating the shipper before making db visible removes that race window without adding locks to the callback path.
Fixes #6413.
Testing