Skip to content

Commit

Permalink
Warn if using temp storage for JetStream (#5935)
Browse files Browse the repository at this point in the history
Based on [a discussion on Community NATS
Slack](https://natsio.slack.com/archives/CM3T6T7JQ/p1727353138572209?thread_ts=1727312314.349369&cid=CM3T6T7JQ).

When just running `nats-server -js` or with Docker using `docker run
--network host nats -js`, a temporary storage directory will be used
since `-sd`/`jetstream.store_dir` is not specified.

There have been some times where people lost data, because they were not
aware of the temp storage being used.
A user commented if a warning could be shown for this, therefore
proposing this small fix to try and make it more obvious.

@bruth, tagging as you commented in the thread as well.

Signed-off-by: Maurice van Veen <github@mauricevanveen.com>
  • Loading branch information
derekcollison authored Oct 1, 2024
2 parents 1326e6c + b4ce313 commit a6e07ab
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions server/jetstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ func (s *Server) EnableJetStream(config *JetStreamConfig) error {
cfg := *config
if cfg.StoreDir == _EMPTY_ {
cfg.StoreDir = filepath.Join(os.TempDir(), JetStreamStoreDir)
s.Warnf("Temporary storage directory used, data could be lost on system reboot")
}

// We will consistently place the 'jetstream' directory under the storedir that was handed to us. Prior to 2.2.3 though
Expand Down Expand Up @@ -2521,6 +2522,7 @@ func (s *Server) dynJetStreamConfig(storeDir string, maxStore, maxMem int64) *Je
} else {
// Create one in tmp directory, but make it consistent for restarts.
jsc.StoreDir = filepath.Join(os.TempDir(), "nats", JetStreamStoreDir)
s.Warnf("Temporary storage directory used, data could be lost on system reboot")
}

opts := s.getOpts()
Expand Down

0 comments on commit a6e07ab

Please sign in to comment.