From f3290fa7ed522760f65e36cbfcfbcebe1d7e2ee8 Mon Sep 17 00:00:00 2001 From: Toni Spets Date: Fri, 13 Oct 2023 09:20:21 +0300 Subject: [PATCH] fixup! Improved restore/sync logging --- db.go | 2 +- replica.go | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/db.go b/db.go index d5869209..f2416791 100644 --- a/db.go +++ b/db.go @@ -1411,7 +1411,7 @@ func (db *DB) execCheckpoint(mode string) (err error) { if err := db.db.QueryRow(rawsql).Scan(&row[0], &row[1], &row[2]); err != nil { return err } - log.Printf("%s: checkpoint: mode=%v (%d,%d,%d)", db.path, mode, row[0], row[1], row[2]) + db.Logger.Printf("%s: checkpoint: mode=%v (%d,%d,%d)", db.path, mode, row[0], row[1], row[2]) // Reacquire the read lock immediately after the checkpoint. if err := db.acquireReadLock(); err != nil { diff --git a/replica.go b/replica.go index 9d661ea3..c1a1ab72 100644 --- a/replica.go +++ b/replica.go @@ -226,7 +226,7 @@ func (r *Replica) syncWAL(ctx context.Context) (err error) { startTime := time.Now() var bytesWritten int - log.Printf("%s(%s): write wal segment %s/%08x:%08x", r.db.Path(), r.Name(), initialPos.Generation, initialPos.Index, initialPos.Offset) + r.Logger.Printf("%s(%s): write wal segment %s/%08x:%08x", r.db.Path(), r.Name(), initialPos.Generation, initialPos.Index, initialPos.Offset) // Copy through pipe into client from the starting position. var g errgroup.Group @@ -321,7 +321,7 @@ func (r *Replica) syncWAL(ctx context.Context) (err error) { replicaWALIndexGaugeVec.WithLabelValues(r.db.Path(), r.Name()).Set(float64(rd.Pos().Index)) replicaWALOffsetGaugeVec.WithLabelValues(r.db.Path(), r.Name()).Set(float64(rd.Pos().Offset)) - log.Printf("%s(%s): wal segment written %s/%08x:%08x elapsed=%s sz=%d", r.db.Path(), r.Name(), initialPos.Generation, initialPos.Index, initialPos.Offset, time.Since(startTime).String(), bytesWritten) + r.Logger.Printf("%s(%s): wal segment written %s/%08x:%08x elapsed=%s sz=%d", r.db.Path(), r.Name(), initialPos.Generation, initialPos.Index, initialPos.Offset, time.Since(startTime).String(), bytesWritten) return nil } @@ -543,7 +543,7 @@ func (r *Replica) Snapshot(ctx context.Context) (info SnapshotInfo, err error) { return wc.Close() }) - log.Printf("%s(%s): write snapshot %s/%08x", r.db.Path(), r.Name(), pos.Generation, pos.Index) + r.Logger.Printf("%s(%s): write snapshot %s/%08x", r.db.Path(), r.Name(), pos.Generation, pos.Index) startTime := time.Now() // Delegate write to client & wait for writer goroutine to finish. @@ -742,14 +742,14 @@ func (r *Replica) snapshotter(ctx context.Context) { nextSnapshot = 0 } - log.Printf("%s(%s): previous snapshot created at %s, next in %s", r.db.Path(), r.Name(), snapshot.CreatedAt.Format(time.RFC3339), nextSnapshot.String()) + r.Logger.Printf("%s(%s): previous snapshot created at %s, next in %s", r.db.Path(), r.Name(), snapshot.CreatedAt.Format(time.RFC3339), nextSnapshot.String()) select { case <-ctx.Done(): return case <-time.After(nextSnapshot): if _, err := r.Snapshot(ctx); err != nil && err != ErrNoGeneration { - log.Printf("%s(%s): snapshotter error: %s", r.db.Path(), r.Name(), err) + r.Logger.Printf("%s(%s): snapshotter error: %s", r.db.Path(), r.Name(), err) } } }