nats-io / nats-streaming-server

NATS Streaming System Server
https://nats.io
Apache License 2.0
2.51k stars 284 forks source link

no recovered state when missing server.dat file #1263

Closed nvol closed 2 years ago

nvol commented 2 years ago

noticed that if server.dat file (in data/ dir) is absent, the server doesn't attempt to recover its state
can see messages in logs:
STREAM: Recovering the state... STREAM: No recovered state

but, no matter what, server.dat file is being created and on the next server relaunch the recovery process starts as expected

kozlovic commented 2 years ago

@nvol Currently the server will indeed create the file if empty, but since the server state is considered empty, it assumes that it is a new start and will not proceed with recovery. Recovering without a server.dat, but existing clients/subscriptions inside the channel is, I believe, bad. The server.dat contains internal subjects that client send the protocols to, etc..

If I make the server check presence of other files when server.dat was not found and in that case fail the startup all-together, then I am afraid the server will never be able to restart - unless the user deletes the whole datastore directory.

I really am not sure what is the best course of action here, but wonder how you got in a situation where server.dat is missing but rest of store is present.

nvol commented 2 years ago

i got into this situation accidently setting up experiments...
why can't we just initialize the server with creating server.dat and then go to the standard process of preparing the server for regular launch with the recovery and so on?