mvcc: support structured logging in compact restore
@@ -18,6 +18,7 @@ import (
"context"
"encoding/binary"
"errors"
+ "fmt"
"hash/crc32"
"math"
"sync"
@@ -330,8 +331,18 @@ func (s *store) restore() error {
_, finishedCompactBytes := tx.UnsafeRange(metaBucketName, finishedCompactKeyName, nil, 0)
if len(finishedCompactBytes) != 0 {
s.compactMainRev = bytesToRev(finishedCompactBytes[0]).main
+
+ if s.lg != nil {
+ s.lg.Info(
+ "restored last compact revision",
+ zap.String("meta-bucket-name", string(metaBucketName)),
+ zap.String("meta-bucket-name-key", string(finishedCompactKeyName)),
+ zap.Int64("restored-compact-revision", s.compactMainRev),
+ )
+ } else {
plog.Printf("restore compact to %d", s.compactMainRev)
}
+ }
_, scheduledCompactBytes := tx.UnsafeRange(metaBucketName, scheduledCompactKeyName, nil, 0)
scheduledCompact := int64(0)
if len(scheduledCompactBytes) != 0 {
@@ -377,16 +388,34 @@ func (s *store) restore() error {
}
err := s.le.Attach(lid, []lease.LeaseItem{{Key: key}})
if err != nil {
+ if s.lg != nil {
+ s.lg.Warn(
+ "failed to attach a lease",
+ zap.String("lease-id", fmt.Sprintf("%016x", lid)),
+ zap.Error(err),
+ )
+ } else {
plog.Errorf("unexpected Attach error: %v", err)
}
}
+ }
tx.Unlock()
if scheduledCompact != 0 {
s.Compact(scheduledCompact)
+
+ if s.lg != nil {
+ s.lg.Info(
+ "resume scheduled compaction",
+ zap.String("meta-bucket-name", string(metaBucketName)),
+ zap.String("meta-bucket-name-key", string(scheduledCompactKeyName)),
+ zap.Int64("scheduled-compact-revision", scheduledCompact),
+ )
+ } else {
plog.Printf("resume scheduled compaction at %d", scheduledCompact)
}
+ }
return nil
}
