Skip to content

Commit

Permalink
mvcc: support structured logging in compact restore
Browse files Browse the repository at this point in the history
Signed-off-by: Gyuho Lee <[email protected]>
  • Loading branch information
gyuho committed May 2, 2018
1 parent d2e1484 commit 4d863da
Showing 1 changed file with 32 additions and 3 deletions.
35 changes: 32 additions & 3 deletions mvcc/kvstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"context"
"encoding/binary"
"errors"
"fmt"
"hash/crc32"
"math"
"sync"
Expand Down Expand Up @@ -330,7 +331,17 @@ func (s *store) restore() error {
_, finishedCompactBytes := tx.UnsafeRange(metaBucketName, finishedCompactKeyName, nil, 0)
if len(finishedCompactBytes) != 0 {
s.compactMainRev = bytesToRev(finishedCompactBytes[0]).main
plog.Printf("restore compact to %d", s.compactMainRev)

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)
Expand Down Expand Up @@ -377,15 +388,33 @@ func (s *store) restore() error {
}
err := s.le.Attach(lid, []lease.LeaseItem{{Key: key}})
if err != nil {
plog.Errorf("unexpected Attach error: %v", err)
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)
plog.Printf("resume scheduled compaction at %d", 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
Expand Down

0 comments on commit 4d863da

Please sign in to comment.