Skip to content
Open
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
15 changes: 15 additions & 0 deletions server/storage/mvcc/watchable_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,18 @@ func (s *watchableStore) syncWatchers() int {

return len(s.unsynced.watchers)
}

func (s *watchableStore) compact(rev int64) {
s.Mu.Lock()
defer s.Mu.Unlock()
s.store.compact(rev)
for w := range s.unsynced.watchers {
if w.minRev <= rev {
select {
case w.ch <- WatchResponse{WatchID: w.id, CompactRevision: rev}:
default:
}
delete(s.unsynced.watchers, w)
}
}
}
6 changes: 5 additions & 1 deletion server/storage/mvcc/watchable_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,17 @@ func TestConcurrentCompactionAndWatch(t *testing.T) {

// Simulate concurrent compaction and watch creation
ch := make(chan WatchResponse, 1)
compactDone := make(chan struct{})
go func() {
time.Sleep(10 * time.Millisecond)
st.compact(5)
store.compact(5)
close(compactDone)
}()

_, err := store.watch([]byte("foo"), nil, 5, 1, ch)
if err == nil {
// Wait for compaction to complete
<-compactDone
// If watch creation succeeded, syncWatchers should catch it if compaction has progressed
store.syncWatchers()
select {
Expand Down