From faf59e186a150c4ce95eddfaf611fff2e1676aa7 Mon Sep 17 00:00:00 2001 From: Nick Mills-Barrett Date: Thu, 28 Nov 2024 10:43:56 +0000 Subject: [PATCH] Add `DB.CloseForRestart` method for liteserv process restarts This skips the wal & replica syncs and just closes as fast as possible since we'll resume syncing once the process comes back up. --- db.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/db.go b/db.go index 9bd23898..f086f468 100644 --- a/db.go +++ b/db.go @@ -370,6 +370,39 @@ func (db *DB) Close(ctx context.Context) error { return nil } +// Fast close variant for liteserv process restarts, no need to copy shadow wal +// in these cases since we'll pick it up on restart. +func (db *DB) CloseForRestart(ctx context.Context) error { + db.cancel() + db.wg.Wait() + + // Stop any replicas + for _, r := range db.Replicas { + r.Stop(true) + } + + // Release the read lock to allow other applications to handle checkpointing. + if db.rtx != nil { + if err := db.releaseReadLock(); err != nil { + return err + } + } + + if db.db != nil { + if err := db.db.Close(); err != nil { + return err + } + } + + if db.f != nil { + if err := db.f.Close(); err != nil { + return err + } + } + + return nil +} + // UpdatedAt returns the last modified time of the database or WAL file. func (db *DB) UpdatedAt() (time.Time, error) { // Determine database modified time.