tursodatabase/libsql

Sqld will recover databases multiple times if namespace is unloaded

MarinPostma opened this issue · 0 comments

At startup, sqld can be dirty if some assumptions do not hold. When in a dirty state, sqld will attempt to recover replication logs when a namespace gets loaded. This recovery takes some time. This issue arises when the namespace is unloaded and reloaded: sqld has no way to know that the specific namespace was already recovered, and it will recover it again for nothing.

How can we fix this? here's a proposal:

  • at startup, a session id is generated for the whole instance.
  • when the instance is dirty and a namespace is loaded, look into the namespace directory for a file, called for example .recover
  • the .recover file contains a session id
  • compare the session id, with the current session id; if the current session id matches that of the file, then we have already recovered this namespace, otherwise, perform recovery, and leave a .recover file with the current session id in the namespace directory.