Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add DB.CloseForRestart method for liteserv process restarts #2

Merged
merged 1 commit into from
Nov 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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