Skip to content

Commit

Permalink
backend: print snapshotting duration warning every 30s
Browse files Browse the repository at this point in the history
FIXES #7870
  • Loading branch information
fanminshi committed May 4, 2017
1 parent 505bf8c commit 76e4a8d
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions mvcc/backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ var (
initialMmapSize = uint64(10 * 1024 * 1024 * 1024)

plog = capnslog.NewPackageLogger("github.com/coreos/etcd", "mvcc/backend")

snapshotWarningTimeout = 30 * time.Second
)

type Backend interface {
Expand Down Expand Up @@ -163,6 +165,20 @@ func (b *backend) ForceCommit() {
}

func (b *backend) Snapshot() Snapshot {
stopc, donec := make(chan struct{}), make(chan struct{})
go func() {
defer close(donec)
now := time.Now()
for {
select {
case <-time.After(snapshotWarningTimeout):
plog.Warningf("snapshotting is taking more than %v to finish [started at %v]", time.Since(now).Seconds(), now)
case <-stopc:
return
}
}
}()

b.batchTx.Commit()

b.mu.RLock()
Expand All @@ -171,7 +187,7 @@ func (b *backend) Snapshot() Snapshot {
if err != nil {
plog.Fatalf("cannot begin tx (%s)", err)
}
return &snapshot{tx}
return &snapshot{tx, stopc, donec}
}

type IgnoreKey struct {
Expand Down Expand Up @@ -403,6 +419,12 @@ func NewDefaultTmpBackend() (*backend, string) {

type snapshot struct {
*bolt.Tx
stopc chan struct{}
donec chan struct{}
}

func (s *snapshot) Close() error { return s.Tx.Rollback() }
func (s *snapshot) Close() error {
close(s.stopc)
<-s.donec
return s.Tx.Rollback()
}

0 comments on commit 76e4a8d

Please sign in to comment.