lib/{mergeset,storage}: simplify the code a bit after ae55ad8749

This commit is contained in:
Aliaksandr Valialkin 2022-10-21 14:33:03 +03:00
parent af648279ce
commit 1fb2be0cae
No known key found for this signature in database
GPG Key ID: A72BEC6CD3D0DED1
2 changed files with 22 additions and 16 deletions

View File

@ -644,7 +644,11 @@ func (ris *rawItemsShard) appendBlocksToFlush(dst []*inmemoryBlock, tb *Table, i
flushSeconds = 1 flushSeconds = 1
} }
lastFlushTime := atomic.LoadUint64(&ris.lastFlushTime) lastFlushTime := atomic.LoadUint64(&ris.lastFlushTime)
if isFinal || currentTime-lastFlushTime > uint64(flushSeconds) { if !isFinal && currentTime <= lastFlushTime+uint64(flushSeconds) {
// Fast path - nothing to flush
return dst
}
// Slow path - move ris.ibs to dst
ris.mu.Lock() ris.mu.Lock()
ibs := ris.ibs ibs := ris.ibs
dst = append(dst, ibs...) dst = append(dst, ibs...)
@ -654,7 +658,6 @@ func (ris *rawItemsShard) appendBlocksToFlush(dst []*inmemoryBlock, tb *Table, i
ris.ibs = ibs[:0] ris.ibs = ibs[:0]
atomic.StoreUint64(&ris.lastFlushTime, currentTime) atomic.StoreUint64(&ris.lastFlushTime, currentTime)
ris.mu.Unlock() ris.mu.Unlock()
}
return dst return dst
} }

View File

@ -747,13 +747,16 @@ func (rrs *rawRowsShard) appendRawRowsToFlush(dst []rawRow, pt *partition, isFin
flushSeconds = 1 flushSeconds = 1
} }
lastFlushTime := atomic.LoadUint64(&rrs.lastFlushTime) lastFlushTime := atomic.LoadUint64(&rrs.lastFlushTime)
if isFinal || currentTime-lastFlushTime > uint64(flushSeconds) { if !isFinal && currentTime <= lastFlushTime+uint64(flushSeconds) {
// Fast path - nothing to flush
return dst
}
// Slow path - move rrs.rows to dst.
rrs.mu.Lock() rrs.mu.Lock()
dst = append(dst, rrs.rows...) dst = append(dst, rrs.rows...)
rrs.rows = rrs.rows[:0] rrs.rows = rrs.rows[:0]
atomic.StoreUint64(&rrs.lastFlushTime, currentTime) atomic.StoreUint64(&rrs.lastFlushTime, currentTime)
rrs.mu.Unlock() rrs.mu.Unlock()
}
return dst return dst
} }