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

NRG: Use configured sync intervals for group stores #6041

Merged
merged 2 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 6 additions & 1 deletion server/filestore.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"io"
"io/fs"
"math"
mrand "math/rand/v2"
"net"
"os"
"path/filepath"
Expand Down Expand Up @@ -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)
}
}

Expand Down
13 changes: 11 additions & 2 deletions server/jetstream_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down