Skip to content

Commit

Permalink
[FIXED] Only mark fs as dirty vs full write on mb compaction. (#4657)
Browse files Browse the repository at this point in the history
On streams that were constantly removing items, like KVs, this could
become over active when not needed. Simply mark the store as dirty for
next check.

Signed-off-by: Derek Collison <derek@nats.io>
  • Loading branch information
derekcollison committed Oct 12, 2023
2 parents ea70590 + 0a64f18 commit 2a7d70c
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions server/filestore.go
Expand Up @@ -4740,7 +4740,7 @@ func (fs *fileStore) syncBlocks() {
lmb := fs.lmb
fs.mu.RUnlock()

var shouldWriteState bool
var markDirty bool
for _, mb := range blks {
// Do actual sync. Hold lock for consistency.
mb.mu.Lock()
Expand All @@ -4756,7 +4756,7 @@ func (fs *fileStore) syncBlocks() {
// Do not compact last mb.
if mb != lmb && mb.ensureRawBytesLoaded() == nil && mb.rbytes > mb.bytes {
mb.compact()
shouldWriteState = true
markDirty = true
}

// Check if we need to sync. We will not hold lock during actual sync.
Expand Down Expand Up @@ -4787,12 +4787,11 @@ func (fs *fileStore) syncBlocks() {
fs.syncTmr = time.AfterFunc(fs.fcfg.SyncInterval, fs.syncBlocks)
fn := filepath.Join(fs.fcfg.StoreDir, msgDir, streamStreamStateFile)
syncAlways := fs.fcfg.SyncAlways
if markDirty {
fs.dirty++
}
fs.mu.Unlock()

// Check if we should write out our state due to compaction of one or more msg blocks.
if shouldWriteState {
fs.writeFullState()
}
// Sync state file if we are not running with sync always.
if !syncAlways {
if fd, _ := os.OpenFile(fn, os.O_RDWR, defaultFilePerms); fd != nil {
Expand Down

0 comments on commit 2a7d70c

Please sign in to comment.