Skip to content

Commit

Permalink
Add DB.CloseForRestart method for liteserv process restarts
Browse files Browse the repository at this point in the history
This skips the wal & replica syncs and just closes as fast as possible
since we'll resume syncing once the process comes back up.
  • Loading branch information
Fizzadar committed Nov 28, 2024
1 parent 17349c6 commit faf59e1
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions db.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit faf59e1

Please sign in to comment.