go/store/nbs: flush journal writer before returning record ranges

This commit is contained in:
Andy Arthur
2023-02-17 11:32:38 -08:00
parent 2ddf1fd9f5
commit 4036810654
2 changed files with 22 additions and 3 deletions
+4 -2
View File
@@ -149,8 +149,10 @@ func (s journalChunkSource) getRecordRanges(requests []getRecord) (map[hash.Hash
if req.found {
continue
}
rng, ok := s.journal.getRange(*req.a)
if !ok {
rng, ok, err := s.journal.getRange(*req.a)
if err != nil {
return nil, err
} else if !ok {
continue
}
req.found = true // update |requests|
+18 -1
View File
@@ -317,6 +317,18 @@ func (wr *journalWriter) flush() (err error) {
return
}
func (wr *journalWriter) maybeFlush() (err error) {
wr.lock.RLock()
empty := len(wr.buf) == 0
wr.lock.RUnlock()
if empty {
return
}
wr.lock.Lock()
defer wr.lock.Unlock()
return wr.flush()
}
func (wr *journalWriter) has(h addr) (ok bool) {
wr.lock.RLock()
defer wr.lock.RUnlock()
@@ -324,7 +336,12 @@ func (wr *journalWriter) has(h addr) (ok bool) {
return
}
func (wr *journalWriter) getRange(h addr) (rng Range, ok bool) {
func (wr *journalWriter) getRange(h addr) (rng Range, ok bool, err error) {
// callers will use |rng| to read directly from the
// journal file, so we must flush here
if err = wr.maybeFlush(); err != nil {
return
}
wr.lock.RLock()
defer wr.lock.RUnlock()
var l recLookup