Power loss killed two badger databases running in separate applications.
Testing with Ctrl-C also killed one.
Then downgraded to v3.2011.1 and the one destroyed with Ctrl-C became functional.
Can’t include traceback.
“New users limited to 2 links”
That will allow Badger to do any best effort cleanup to avoid issues with Ctrl+C or a container being terminated externally. Nothing will help a true power outage that doesn’t provide the time to call the close function.
Specifically, if you want to gracefully handle shutdown for Ctrl+C and OS shutdown, you’ll need the the following:
interrupt := make(chan os.Signal, 1)
signal.Notify(interrupt, os.Interrupt, syscall.SIGTERM)
go func() {
err := server.ListenAndServe()
if err != nil {
log.Printf("Error running service: %s", err)
}
}()
killSignal := <-interrupt
switch killSignal {
case os.Interrupt:
log.Print("Received OS Interrupt")
case syscall.SIGTERM:
log.Print("Received Termination Signal")
}
if err = server.Shutdown(context.Background()); err != nil {
log.Printf("Shutdown error: %s", err)
}
Thanks for the reply.
Mitigations such as you describe are present.
The problem is most frequent on Windows.
But just today on Linux I have a key that can’t be updated.
In this case, the DB opened correctly.
Once the DB was restored from backup, it worked correctly.