Skip to content

Commit

Permalink
Return sync options in varz / jsz
Browse files Browse the repository at this point in the history
Signed-off-by: Derek Collison <derek@nats.io>
  • Loading branch information
derekcollison committed Sep 4, 2023
1 parent a2d5779 commit 38ba45d
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 16 deletions.
29 changes: 19 additions & 10 deletions server/jetstream.go
Expand Up @@ -38,12 +38,14 @@ import (
// JetStreamConfig determines this server's configuration.
// MaxMemory and MaxStore are in bytes.
type JetStreamConfig struct {
MaxMemory int64 `json:"max_memory"`
MaxStore int64 `json:"max_storage"`
StoreDir string `json:"store_dir,omitempty"`
Domain string `json:"domain,omitempty"`
CompressOK bool `json:"compress_ok,omitempty"`
UniqueTag string `json:"unique_tag,omitempty"`
MaxMemory int64 `json:"max_memory"`
MaxStore int64 `json:"max_storage"`
StoreDir string `json:"store_dir,omitempty"`
SyncInterval time.Duration `json:"sync_interval,omitempty"`
SyncAlways bool `json:"sync_always,omitempty"`
Domain string `json:"domain,omitempty"`
CompressOK bool `json:"compress_ok,omitempty"`
UniqueTag string `json:"unique_tag,omitempty"`
}

// Statistics about JetStream for this server.
Expand Down Expand Up @@ -490,10 +492,12 @@ func (s *Server) updateJetStreamInfoStatus(enabled bool) {
func (s *Server) restartJetStream() error {
opts := s.getOpts()
cfg := JetStreamConfig{
StoreDir: opts.StoreDir,
MaxMemory: opts.JetStreamMaxMemory,
MaxStore: opts.JetStreamMaxStore,
Domain: opts.JetStreamDomain,
StoreDir: opts.StoreDir,
SyncInterval: opts.SyncInterval,
SyncAlways: opts.SyncAlways,
MaxMemory: opts.JetStreamMaxMemory,
MaxStore: opts.JetStreamMaxStore,
Domain: opts.JetStreamDomain,
}
s.Noticef("Restarting JetStream")
err := s.EnableJetStream(&cfg)
Expand Down Expand Up @@ -2397,6 +2401,10 @@ func (s *Server) dynJetStreamConfig(storeDir string, maxStore, maxMem int64) *Je

opts := s.getOpts()

// Sync options.
jsc.SyncInterval = opts.SyncInterval
jsc.SyncAlways = opts.SyncAlways

if opts.maxStoreSet && maxStore >= 0 {
jsc.MaxStore = maxStore
} else {
Expand All @@ -2413,6 +2421,7 @@ func (s *Server) dynJetStreamConfig(storeDir string, maxStore, maxMem int64) *Je
jsc.MaxMemory = JetStreamMaxMemDefault
}
}

return jsc
}

Expand Down
17 changes: 17 additions & 0 deletions server/monitor_test.go
Expand Up @@ -5244,3 +5244,20 @@ func TestIpqzWithGenerics(t *testing.T) {
require_True(t, len(queues) >= 4)
require_True(t, queues["SendQ"] != nil)
}

func TestVarzSyncInterval(t *testing.T) {
resetPreviousHTTPConnections()
opts := DefaultMonitorOptions()
opts.JetStream = true
opts.SyncInterval = 22 * time.Second
opts.SyncAlways = true

s := RunServer(opts)
defer s.Shutdown()

url := fmt.Sprintf("http://127.0.0.1:%d/varz", s.MonitorAddr().Port)

jscfg := pollVarz(t, s, 0, url, nil).JetStream.Config
require_True(t, jscfg.SyncInterval == opts.SyncInterval)
require_True(t, jscfg.SyncAlways)
}
14 changes: 8 additions & 6 deletions server/server.go
Expand Up @@ -2211,12 +2211,14 @@ func (s *Server) Start() {
s.Fatalf("Not allowed to enable JetStream on the system account")
}
cfg := &JetStreamConfig{
StoreDir: opts.StoreDir,
MaxMemory: opts.JetStreamMaxMemory,
MaxStore: opts.JetStreamMaxStore,
Domain: opts.JetStreamDomain,
CompressOK: true,
UniqueTag: opts.JetStreamUniqueTag,
StoreDir: opts.StoreDir,
SyncInterval: opts.SyncInterval,
SyncAlways: opts.SyncAlways,
MaxMemory: opts.JetStreamMaxMemory,
MaxStore: opts.JetStreamMaxStore,
Domain: opts.JetStreamDomain,
CompressOK: true,
UniqueTag: opts.JetStreamUniqueTag,
}
if err := s.EnableJetStream(cfg); err != nil {
s.Fatalf("Can't start JetStream: %v", err)
Expand Down

0 comments on commit 38ba45d

Please sign in to comment.