From e234aa7ff092d0c7cfa22259941fbe6368500f74 Mon Sep 17 00:00:00 2001 From: davidby-influx <72418212+davidby-influx@users.noreply.github.com> Date: Mon, 26 Apr 2021 10:13:49 -0700 Subject: [PATCH] fix: Anti-Entropy loops endlessly with empty shard (#21275) (#21290) The anti-entropy service will loop trying to copy an empty shard to a data node missing that shard. This fix is one of two changes that correctly create an empty shard on a new node. This fix will set the LastModified date of an empty shard directory to the modification time of that directory, instead of to the Unix epoch. Fixes: https://github.com/influxdata/influxdb/issues/21273 (cherry picked from commit 7f300dc248d767ee1a96642480dfa1daa28f18ba) --- CHANGELOG.md | 2 ++ tsdb/engine/tsm1/file_store.go | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aafa1a741e..0a59a33bbc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ v1.8.6 [unreleased] ------------------- +- [#21290](https://github.com/influxdata/influxdb/pull/21290): fix: Anti-Entropy loops endlessly with empty shard + v1.8.5 [2021-04-19] ------------------- diff --git a/tsdb/engine/tsm1/file_store.go b/tsdb/engine/tsm1/file_store.go index 09c19d348a..d491ffb89c 100644 --- a/tsdb/engine/tsm1/file_store.go +++ b/tsdb/engine/tsm1/file_store.go @@ -566,6 +566,7 @@ func (f *FileStore) Open() error { } var lm int64 + isEmpty := true for range files { res := <-readerC if res.err != nil { @@ -585,9 +586,18 @@ func (f *FileStore) Open() error { if res.r.LastModified() > lm { lm = res.r.LastModified() } - + isEmpty = false + } + if isEmpty { + if fi, err := os.Stat(f.dir); err == nil { + f.lastModified = fi.ModTime().UTC() + } else { + close(readerC) + return err + } + } else { + f.lastModified = time.Unix(0, lm).UTC() } - f.lastModified = time.Unix(0, lm).UTC() close(readerC) sort.Sort(tsmReaders(f.files))