Skip to content

Commit dc8b344

Browse files
NRG: When clfs=0, don't snapshot very often (#6277)
If the stream is ingesting loads of new messages, for example in a benchmark, either the `compactNumMin` or `compactSizeMin` would be reached fairly quickly. The `minSnapDelta` (10s) is used to not snapshot too often, since that would degrade performance. However, if `clfs=0` then we'd be forcing snapshots every time the compact minimums are reached. Signed-off-by: Maurice van Veen <[email protected]>
2 parents d323e23 + af354c7 commit dc8b344

File tree

2 files changed

+39
-6
lines changed

2 files changed

+39
-6
lines changed

server/jetstream_cluster.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2606,12 +2606,6 @@ func (js *jetStream) monitorStream(mset *stream, sa *streamAssignment, sendSnaps
26062606
// Check about snapshotting
26072607
// If we have at least min entries to compact, go ahead and try to snapshot/compact.
26082608
if ne >= compactNumMin || nb > compactSizeMin || mset.getCLFS() > pclfs {
2609-
// We want to make sure we do not short circuit if transistioning from no clfs.
2610-
if pclfs == 0 {
2611-
// This is always false by default.
2612-
lastState.firstNeedsUpdate = true
2613-
lastSnapTime = time.Time{}
2614-
}
26152609
doSnapshot()
26162610
}
26172611

server/jetstream_cluster_1_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6945,6 +6945,45 @@ func TestJetStreamClusterConsumerInfoAfterCreate(t *testing.T) {
69456945
require_NoError(t, err)
69466946
}
69476947

6948+
func TestJetStreamClusterDontSnapshotTooOften(t *testing.T) {
6949+
c := createJetStreamClusterExplicit(t, "R3S", 3)
6950+
defer c.shutdown()
6951+
6952+
nc, js := jsClientConnect(t, c.randomServer())
6953+
defer nc.Close()
6954+
6955+
_, err := js.AddStream(&nats.StreamConfig{
6956+
Name: "TEST",
6957+
Subjects: []string{"foo"},
6958+
Replicas: 3,
6959+
})
6960+
require_NoError(t, err)
6961+
6962+
// We force the snapshot compact size to hit multiple times.
6963+
// But, we should not be making snapshots too often since that would degrade performance.
6964+
data := make([]byte, 1024*1024) // 1MB payload
6965+
_, err = crand.Read(data)
6966+
require_NoError(t, err)
6967+
for i := 0; i < 50; i++ {
6968+
// We do synchronous publishes so we're more likely to have entries pass through the apply queue.
6969+
_, err = js.Publish("foo", data)
6970+
require_NoError(t, err)
6971+
}
6972+
6973+
for _, s := range c.servers {
6974+
acc, err := s.lookupAccount(globalAccountName)
6975+
require_NoError(t, err)
6976+
mset, err := acc.lookupStream("TEST")
6977+
require_NoError(t, err)
6978+
snap, err := mset.node.(*raft).loadLastSnapshot()
6979+
require_NoError(t, err)
6980+
// This measure is not exact and more of a side effect.
6981+
// We expect one snapshot to be made pretty soon and to be on cooldown after.
6982+
// So no snapshots should be made after that.
6983+
require_LessThan(t, snap.lastIndex, 20)
6984+
}
6985+
}
6986+
69486987
//
69496988
// DO NOT ADD NEW TESTS IN THIS FILE (unless to balance test times)
69506989
// Add at the end of jetstream_cluster_<n>_test.go, with <n> being the highest value.

0 commit comments

Comments
 (0)