diff --git a/server/filestore.go b/server/filestore.go index 11661cacec2..c23e6ce9bee 100644 --- a/server/filestore.go +++ b/server/filestore.go @@ -29,6 +29,7 @@ import ( "io" "io/fs" "math" + mrand "math/rand/v2" "net" "os" "path/filepath" @@ -7946,7 +7947,11 @@ func (fs *fileStore) setSyncTimer() { if fs.syncTmr != nil { fs.syncTmr.Reset(fs.fcfg.SyncInterval) } else { - fs.syncTmr = time.AfterFunc(fs.fcfg.SyncInterval, fs.syncBlocks) + // First time this fires will be any time up to the fs.fcfg.SyncInterval, + // so that different stores are spread out, rather than having many of + // them trying to all sync at once, causing blips and contending dios. + start := time.Duration(mrand.Int64N(int64(fs.fcfg.SyncInterval))) + fs.syncTmr = time.AfterFunc(min(start, time.Second), fs.syncBlocks) } } diff --git a/server/jetstream_cluster.go b/server/jetstream_cluster.go index fa06a93a0d1..cedfc0aa7e2 100644 --- a/server/jetstream_cluster.go +++ b/server/jetstream_cluster.go @@ -782,8 +782,12 @@ func (js *jetStream) setupMetaGroup() error { sysAcc := s.SystemAccount() storeDir := filepath.Join(js.config.StoreDir, sysAcc.Name, defaultStoreDirName, defaultMetaGroupName) + js.srv.optsMu.RLock() + syncAlways := js.srv.opts.SyncAlways + syncInterval := js.srv.opts.SyncInterval + js.srv.optsMu.RUnlock() fs, err := newFileStoreWithCreated( - FileStoreConfig{StoreDir: storeDir, BlockSize: defaultMetaFSBlkSize, AsyncFlush: false, srv: s}, + FileStoreConfig{StoreDir: storeDir, BlockSize: defaultMetaFSBlkSize, AsyncFlush: false, SyncAlways: syncAlways, SyncInterval: syncInterval, srv: s}, StreamConfig{Name: defaultMetaGroupName, Storage: FileStorage}, time.Now().UTC(), s.jsKeyGen(s.getOpts().JetStreamKey, defaultMetaGroupName), @@ -2078,8 +2082,13 @@ func (js *jetStream) createRaftGroup(accName string, rg *raftGroup, storage Stor storeDir := filepath.Join(js.config.StoreDir, sysAcc.Name, defaultStoreDirName, rg.Name) var store StreamStore if storage == FileStorage { + // If the server is set to sync always, do the same for the Raft log. + js.srv.optsMu.RLock() + syncAlways := js.srv.opts.SyncAlways + syncInterval := js.srv.opts.SyncInterval + js.srv.optsMu.RUnlock() fs, err := newFileStoreWithCreated( - FileStoreConfig{StoreDir: storeDir, BlockSize: defaultMediumBlockSize, AsyncFlush: false, SyncInterval: 5 * time.Minute, srv: s}, + FileStoreConfig{StoreDir: storeDir, BlockSize: defaultMediumBlockSize, AsyncFlush: false, SyncAlways: syncAlways, SyncInterval: syncInterval, srv: s}, StreamConfig{Name: rg.Name, Storage: FileStorage, Metadata: labels}, time.Now().UTC(), s.jsKeyGen(s.getOpts().JetStreamKey, rg.Name),