From c3e14cb9ae2ac98e307f17d60b1a248aebb7e513 Mon Sep 17 00:00:00 2001 From: Matthew Jaffee Date: Wed, 27 Oct 2021 15:08:58 -0500 Subject: [PATCH] don't fsync on RBF Open if WAL is empty This is targeted at reducing startup times, especially on OSX where the fsync calls seem to be taking an egregiously long time. I got one index to go from ~1min to open to ~1sec. This looks safe to me, but will get opinions from RBF experts. --- rbf/db.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/rbf/db.go b/rbf/db.go index 4f88de259..68a41ac08 100644 --- a/rbf/db.go +++ b/rbf/db.go @@ -206,6 +206,13 @@ func (db *DB) checkpoint() error { return nil // skip if transactions open } + // Check if there are any WAL pages, if not do nothing as + // checkpointing and calling fsync can be very expensive even if + // there are no writes. + if db.walPageN == 0 { + return nil + } + for i := 0; i < db.walPageN; i++ { page, err := db.readWALPageAt(i) if err != nil { @@ -245,7 +252,7 @@ func (db *DB) checkpoint() error { db.walPageN = 0 db.pageMap = NewPageMap() - // Notify halted tranactions that the WAL has been checkpointed. + // Notify halted transactions that the WAL has been checkpointed. db.haltCond.Broadcast() return nil