Skip to content

Commit

Permalink
race detected
Browse files Browse the repository at this point in the history
  • Loading branch information
lezhnev74 committed Jan 12, 2024
1 parent 2a14692 commit f87f7e0
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@ type Storage struct {
// Checking In Segments:
termsDir *TermsDir

incomingSegmentTermsLastFlush time.Time
incomingSegmentTerms chan appendSegmentTerm // row values for the appender
segmentTermsAppender *duckdb.Appender
incomingSegmentTermsLastFlush time.Time
incomingSegmentTermsLastFlushLock sync.RWMutex

incomingSegmentTerms chan appendSegmentTerm // row values for the appender
segmentTermsAppender *duckdb.Appender

incomingSegmentMessageLastFlush time.Time
incomingSegmentMessage chan appendSegmentMessage // row values for the appender
Expand Down Expand Up @@ -387,8 +389,10 @@ WaitLoop:
tick.Stop()
break WaitLoop
case <-tick.C: // try every tick in case the system is under load
s.incomingSegmentTermsLastFlushLock.RLock()
messagesFlushed := len(segment.Messages) > 0 && now.After(s.incomingSegmentTermsLastFlush)
termsFlushed := len(terms) > 0 && now.After(s.incomingSegmentTermsLastFlush)
s.incomingSegmentTermsLastFlushLock.RUnlock()
if messagesFlushed && termsFlushed {
tick.Stop()
break WaitLoop
Expand Down Expand Up @@ -470,7 +474,9 @@ func (s *Storage) ingestSegmentTerms(flushInterval time.Duration) {
log.Printf("unable to ingest a segment term: %v", err)
}
lastFlushed = counter
s.incomingSegmentTermsLastFlushLock.Lock()
s.incomingSegmentTermsLastFlush = time.Now()
s.incomingSegmentTermsLastFlushLock.Unlock()
}

for {
Expand Down

0 comments on commit f87f7e0

Please sign in to comment.