Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve file utilization when using a JetStream stream as a KV. #2456

Merged
merged 4 commits into from
Aug 20, 2021
Merged
Changes from 1 commit
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
Prev Previous commit
Only compact when msg is not first.
Make sure compact works with snapshots.

Signed-off-by: Derek Collison <derek@nats.io>
derekcollison committed Aug 20, 2021

Verified

This commit was signed with the committer’s verified signature.
derekcollison Derek Collison
commit 12c912d7f44a80ab06856680759101909580e3b1
9 changes: 4 additions & 5 deletions server/filestore.go
Original file line number Diff line number Diff line change
@@ -1831,14 +1831,13 @@ func (fs *fileStore) removeMsg(seq uint64, secure, needFSLock bool) (bool, error
mb.dmap = make(map[uint64]struct{})
}
mb.dmap[seq] = struct{}{}
// Check if <50% utilization and minimum size met.
if mb.rbytes > compactMinimum && mb.rbytes>>1 > mb.bytes {
mb.compact()
}
}
}

// Check if <50% utilization and minimum size met.
if mb.rbytes > compactMinimum && mb.rbytes>>1 > mb.bytes {
mb.compact()
}

var qch, fch chan struct{}
if shouldWriteIndex {
qch, fch = mb.qch, mb.fch
12 changes: 12 additions & 0 deletions server/filestore_test.go
Original file line number Diff line number Diff line change
@@ -1827,6 +1827,18 @@ func TestFileStoreSnapshot(t *testing.T) {
snap = snapshot()
verifySnapshot(snap)

// Make sure compaction works with snapshots.
fs.mu.RLock()
for _, mb := range fs.blks {
mb.mu.Lock()
mb.compact()
mb.mu.Unlock()
}
fs.mu.RUnlock()

snap = snapshot()
verifySnapshot(snap)

// Now check to make sure that we get the correct error when trying to delete or erase
// a message when a snapshot is in progress and that closing the reader releases that condition.
sr, err := fs.Snapshot(5*time.Second, false, true)
4 changes: 2 additions & 2 deletions server/norace_test.go
Original file line number Diff line number Diff line change
@@ -2904,7 +2904,7 @@ func TestNoRaceJetStreamFileStoreCompaction(t *testing.T) {
t.Fatalf("Unexpected error: %v", err)
}
total, used, _ := mset.Store().Utilization()
if pu := 100.0 * float32(used) / float32(total); pu < 90.0 {
t.Fatalf("Utilization is less than 90%%, got %.2f", pu)
if pu := 100.0 * float32(used) / float32(total); pu < 80.0 {
t.Fatalf("Utilization is less than 80%%, got %.2f", pu)
}
}