mirror of
https://github.com/gogrlx/nats-server.git
synced 2026-04-02 03:38:42 -07:00
Add ability to set storage directory
Signed-off-by: Derek Collison <derek@nats.io>
This commit is contained in:
1
main.go
1
main.go
@@ -49,6 +49,7 @@ Logging Options:
|
||||
|
||||
JetStream Options:
|
||||
-js, --jetstream Enable JetStream functionality.
|
||||
-sd, --store_dir <dir> Set the storage directory.
|
||||
|
||||
Authorization Options:
|
||||
--user <user> User required for connections
|
||||
|
||||
@@ -113,7 +113,7 @@ const (
|
||||
JetStreamCreateObservable = "$JS.OBSERVABLE.CREATE"
|
||||
jsCreateObservableExport = "$JS.*.OBSERVABLE.CREATE"
|
||||
|
||||
// JetStreamMsgSets is the endpoint to list all message sets for this account.
|
||||
// JetStreamObservables is the endpoint to list all observables for the message set.
|
||||
// Will return json list of string on success and -ERR on failure.
|
||||
JetStreamObservables = "$JS.OBSERVABLES"
|
||||
jsObservablesExport = "$JS.*.OBSERVABLES"
|
||||
@@ -200,9 +200,13 @@ func (s *Server) EnableJetStream(config *JetStreamConfig) error {
|
||||
return fmt.Errorf("jetstream already enabled")
|
||||
}
|
||||
s.Noticef("Starting JetStream")
|
||||
if config == nil {
|
||||
s.Debugf("JetStream creating dynamic configuration - 75%% system memory, %s disk", FriendlyBytes(JetStreamMaxStoreDefault))
|
||||
config = s.dynJetStreamConfig()
|
||||
if config == nil || config.MaxMemory <= 0 || config.MaxStore <= 0 {
|
||||
var storeDir string
|
||||
s.Debugf("JetStream creating dynamic configuration - 75%% of system memory, %s disk", FriendlyBytes(JetStreamMaxStoreDefault))
|
||||
if config != nil {
|
||||
storeDir = config.StoreDir
|
||||
}
|
||||
config = s.dynJetStreamConfig(storeDir)
|
||||
}
|
||||
// Copy, don't change callers.
|
||||
cfg := *config
|
||||
@@ -1122,9 +1126,13 @@ const (
|
||||
)
|
||||
|
||||
// Dynamically create a config with a tmp based directory (repeatable) and 75% of system memory.
|
||||
func (s *Server) dynJetStreamConfig() *JetStreamConfig {
|
||||
func (s *Server) dynJetStreamConfig(storeDir string) *JetStreamConfig {
|
||||
jsc := &JetStreamConfig{}
|
||||
jsc.StoreDir = filepath.Join(os.TempDir(), JetStreamStoreDir)
|
||||
if storeDir != "" {
|
||||
jsc.StoreDir = filepath.Join(storeDir, JetStreamStoreDir)
|
||||
} else {
|
||||
jsc.StoreDir = filepath.Join(os.TempDir(), JetStreamStoreDir)
|
||||
}
|
||||
jsc.MaxStore = JetStreamMaxStoreDefault
|
||||
// Estimate to 75% of total memory if we can determine system memory.
|
||||
if sysMem := sysmem.Memory(); sysMem > 0 {
|
||||
|
||||
@@ -184,6 +184,7 @@ type Options struct {
|
||||
Gateway GatewayOpts `json:"gateway,omitempty"`
|
||||
LeafNode LeafNodeOpts `json:"leaf,omitempty"`
|
||||
JetStream bool `json:"jetstream"`
|
||||
StoreDir string `json:"-"`
|
||||
ProfPort int `json:"-"`
|
||||
PidFile string `json:"-"`
|
||||
PortsFileDir string `json:"-"`
|
||||
@@ -3149,6 +3150,8 @@ func ConfigureOptions(fs *flag.FlagSet, args []string, printVersion, printHelp,
|
||||
fs.IntVar(&opts.MaxTracedMsgLen, "max_traced_msg_len", 0, "Maximum printable length for traced messages. 0 for unlimited.")
|
||||
fs.BoolVar(&opts.JetStream, "js", false, "Enable JetStream.")
|
||||
fs.BoolVar(&opts.JetStream, "jetstream", false, "Enable JetStream.")
|
||||
fs.StringVar(&opts.StoreDir, "sd", "", "Storage directory.")
|
||||
fs.StringVar(&opts.StoreDir, "store_dir", "", "Storage directory.")
|
||||
|
||||
// The flags definition above set "default" values to some of the options.
|
||||
// Calling Parse() here will override the default options with any value
|
||||
|
||||
@@ -1258,7 +1258,11 @@ func (s *Server) Start() {
|
||||
// the system account setup above. JetStream will create its
|
||||
// own system account if one is not present.
|
||||
if opts.JetStream {
|
||||
if err := s.EnableJetStream(nil); err != nil {
|
||||
var cfg *JetStreamConfig
|
||||
if opts.StoreDir != "" {
|
||||
cfg = &JetStreamConfig{StoreDir: opts.StoreDir}
|
||||
}
|
||||
if err := s.EnableJetStream(cfg); err != nil {
|
||||
s.Fatalf("Can't start jetstream: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user