Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

backend: print snapshotting duration warning every 30s #7877

Merged
merged 1 commit into from
May 5, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 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,22 @@ func (b *backend) ForceCommit() {
}

func (b *backend) Snapshot() Snapshot {
stopc, donec := make(chan struct{}), make(chan struct{})
go func() {
defer close(donec)
start := time.Now()
ticker := time.NewTicker(snapshotWarningTimeout)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

defer ticker.Stop() is more future proof, although there's no bug here at the moment.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alrighty. will change.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

defer ticker.Stop()
for {
select {
case <-ticker.C:
plog.Warningf("snapshotting is taking more than %v seconds to finish [started at %v]", time.Since(start).Seconds(), start)
case <-stopc:
return
}
}
}()

b.batchTx.Commit()

b.mu.RLock()
Expand All @@ -171,7 +189,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 +421,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()
}