Skip to content

Commit eda3396

Browse files
NRG: Use configured sync intervals for group stores (#6041)
Signed-off-by: Neil Twigg <[email protected]>
2 parents d4decde + 886e9ee commit eda3396

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

server/filestore.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"io"
3030
"io/fs"
3131
"math"
32+
mrand "math/rand/v2"
3233
"net"
3334
"os"
3435
"path/filepath"
@@ -7946,7 +7947,11 @@ func (fs *fileStore) setSyncTimer() {
79467947
if fs.syncTmr != nil {
79477948
fs.syncTmr.Reset(fs.fcfg.SyncInterval)
79487949
} else {
7949-
fs.syncTmr = time.AfterFunc(fs.fcfg.SyncInterval, fs.syncBlocks)
7950+
// First time this fires will be any time up to the fs.fcfg.SyncInterval,
7951+
// so that different stores are spread out, rather than having many of
7952+
// them trying to all sync at once, causing blips and contending dios.
7953+
start := time.Duration(mrand.Int64N(int64(fs.fcfg.SyncInterval)))
7954+
fs.syncTmr = time.AfterFunc(min(start, time.Second), fs.syncBlocks)
79507955
}
79517956
}
79527957

server/jetstream_cluster.go

+11-2
Original file line numberDiff line numberDiff line change
@@ -782,8 +782,12 @@ func (js *jetStream) setupMetaGroup() error {
782782
sysAcc := s.SystemAccount()
783783
storeDir := filepath.Join(js.config.StoreDir, sysAcc.Name, defaultStoreDirName, defaultMetaGroupName)
784784

785+
js.srv.optsMu.RLock()
786+
syncAlways := js.srv.opts.SyncAlways
787+
syncInterval := js.srv.opts.SyncInterval
788+
js.srv.optsMu.RUnlock()
785789
fs, err := newFileStoreWithCreated(
786-
FileStoreConfig{StoreDir: storeDir, BlockSize: defaultMetaFSBlkSize, AsyncFlush: false, srv: s},
790+
FileStoreConfig{StoreDir: storeDir, BlockSize: defaultMetaFSBlkSize, AsyncFlush: false, SyncAlways: syncAlways, SyncInterval: syncInterval, srv: s},
787791
StreamConfig{Name: defaultMetaGroupName, Storage: FileStorage},
788792
time.Now().UTC(),
789793
s.jsKeyGen(s.getOpts().JetStreamKey, defaultMetaGroupName),
@@ -2078,8 +2082,13 @@ func (js *jetStream) createRaftGroup(accName string, rg *raftGroup, storage Stor
20782082
storeDir := filepath.Join(js.config.StoreDir, sysAcc.Name, defaultStoreDirName, rg.Name)
20792083
var store StreamStore
20802084
if storage == FileStorage {
2085+
// If the server is set to sync always, do the same for the Raft log.
2086+
js.srv.optsMu.RLock()
2087+
syncAlways := js.srv.opts.SyncAlways
2088+
syncInterval := js.srv.opts.SyncInterval
2089+
js.srv.optsMu.RUnlock()
20812090
fs, err := newFileStoreWithCreated(
2082-
FileStoreConfig{StoreDir: storeDir, BlockSize: defaultMediumBlockSize, AsyncFlush: false, SyncInterval: 5 * time.Minute, srv: s},
2091+
FileStoreConfig{StoreDir: storeDir, BlockSize: defaultMediumBlockSize, AsyncFlush: false, SyncAlways: syncAlways, SyncInterval: syncInterval, srv: s},
20832092
StreamConfig{Name: rg.Name, Storage: FileStorage, Metadata: labels},
20842093
time.Now().UTC(),
20852094
s.jsKeyGen(s.getOpts().JetStreamKey, rg.Name),

0 commit comments

Comments
 (0)