From 1d7639f7967055080b51ed56a407d6e7aa5cdf27 Mon Sep 17 00:00:00 2001 From: Benjamin Wang Date: Wed, 12 Oct 2022 19:35:06 +0800 Subject: [PATCH] etcdserver: added more debug log for the purgeFile goroutine Signed-off-by: Benjamin Wang --- embed/etcd.go | 2 ++ pkg/fileutil/purge.go | 27 ++++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/embed/etcd.go b/embed/etcd.go index 5af6eee4f..03830ebe7 100644 --- a/embed/etcd.go +++ b/embed/etcd.go @@ -322,6 +322,8 @@ func print(lg *zap.Logger, ec Config, sc etcdserver.ServerConfig, memberInitiali zap.String("election-timeout", fmt.Sprintf("%v", time.Duration(sc.ElectionTicks*int(sc.TickMs))*time.Millisecond)), zap.Bool("initial-election-tick-advance", sc.InitialElectionTickAdvance), zap.Uint64("snapshot-count", sc.SnapshotCount), + zap.Uint("max-wals", sc.MaxWALFiles), + zap.Uint("max-snapshots", sc.MaxSnapFiles), zap.Uint64("snapshot-catchup-entries", sc.SnapshotCatchUpEntries), zap.Strings("initial-advertise-peer-urls", ec.getAPURLs()), zap.Strings("listen-peer-urls", ec.getLPURLs()), diff --git a/pkg/fileutil/purge.go b/pkg/fileutil/purge.go index d116f340b..50a1f08c1 100644 --- a/pkg/fileutil/purge.go +++ b/pkg/fileutil/purge.go @@ -38,6 +38,16 @@ func PurgeFileWithDoneNotify(lg *zap.Logger, dirname string, suffix string, max // if donec is non-nil, the function closes it to notify its exit. func purgeFile(lg *zap.Logger, dirname string, suffix string, max uint, interval time.Duration, stop <-chan struct{}, purgec chan<- string, donec chan<- struct{}) <-chan error { errC := make(chan error, 1) + if lg != nil { + lg.Info("started to purge file", + zap.String("dir", dirname), + zap.String("suffix", suffix), + zap.Uint("max", max), + zap.Duration("interval", interval)) + } else { + plog.Infof("started to purge file, dir: %s, suffix: %s, max: %d, interval: %v", dirname, suffix, max, interval) + } + go func() { if donec != nil { defer close(donec) @@ -45,6 +55,11 @@ func purgeFile(lg *zap.Logger, dirname string, suffix string, max uint, interval for { fnames, err := ReadDir(dirname) if err != nil { + if lg != nil { + lg.Warn("failed to read files", zap.String("dir", dirname), zap.Error(err)) + } else { + plog.Warningf("failed to read files, dir: %s, error: %v", dirname, err) + } errC <- err return } @@ -60,15 +75,25 @@ func purgeFile(lg *zap.Logger, dirname string, suffix string, max uint, interval f := filepath.Join(dirname, newfnames[0]) l, err := TryLockFile(f, os.O_WRONLY, PrivateFileMode) if err != nil { + if lg != nil { + lg.Warn("failed to lock file", zap.String("path", f), zap.Error(err)) + } else { + plog.Warningf("failed to lock file, path: %s, error: %v", f, err) + } break } if err = os.Remove(f); err != nil { + if lg != nil { + lg.Error("failed to remove file", zap.String("path", f), zap.Error(err)) + } else { + plog.Errorf("failed to remove file, path: %s, error: %v", f, err) + } errC <- err return } if err = l.Close(); err != nil { if lg != nil { - lg.Warn("failed to unlock/close", zap.String("path", l.Name()), zap.Error(err)) + lg.Error("failed to unlock/close", zap.String("path", l.Name()), zap.Error(err)) } else { plog.Errorf("error unlocking %s when purging file (%v)", l.Name(), err) }