Repository: matrixorigin/matrixcube
Pull request #517 (2021-12-13 05:58:28)

Simplified how orphan snapshots are handled
**What type of PR is this?**

- [ ] API-change
- [ ] BUG
- [x] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

**Which issue(s) this PR fixes:**

Fixes #

**What this PR does / why we need it:**

Not Available

**Special notes for your reviewer:**

Not Available

**Additional documentation (e.g. design docs, usage docs, etc.):**

Not Available



Patch:
diff --git a/raftstore/replica_event_raft_ready.go b/raftstore/replica_event_raft_ready.go
index 94f015b..54ad91c 100644
--- a/raftstore/replica_event_raft_ready.go
+++ b/raftstore/replica_event_raft_ready.go
@@ -58,9 +58,6 @@ func (pr *replica) processReady(rd raft.Ready, wc *logdb.WorkerContext) error {
 	if err := pr.appendEntries(rd); err != nil {
 		return err
 	}
-	if err := pr.onSnapshotSaved(rd); err != nil {
-		return err
-	}
 	pr.sendRaftMessages(rd)
 	if err := pr.applyCommittedEntries(rd); err != nil {
 		return err
@@ -72,18 +69,6 @@ func (pr *replica) processReady(rd raft.Ready, wc *logdb.WorkerContext) error {
 	return nil
 }
 
-// the flag file is used to minimize the possibility to have the snapshot
-// re-transmitted after reboot. for a quick reboot, e.g. a 10 minutes offline,
-// it will be unlikely for the leader to have another log compaction, it thus
-// still make sense to apply the latest received but not applied snapshot.
-func (pr *replica) onSnapshotSaved(rd raft.Ready) error {
-	if !raft.IsEmptySnap(rd.Snapshot) {
-		env := pr.snapshotter.getRecoverSnapshotEnv(rd.Snapshot)
-		return env.RemoveFlagFile()
-	}
-	return nil
-}
-
 func (pr *replica) handleRaftState(rd raft.Ready) {
 	// etcd raft won't repeatedly return the same non-empty soft state
 	if rd.SoftState != nil {
diff --git a/raftstore/snapshotter.go b/raftstore/snapshotter.go
index 462e876..c1aeed4 100644
--- a/raftstore/snapshotter.go
+++ b/raftstore/snapshotter.go
@@ -144,14 +144,7 @@ func (s *snapshotter) removeOrphanSnapshots() error {
 		}
 		fn := dirInfo.Name()
 		dirName := s.fs.PathJoin(s.rootDir, fn)
-		if s.isOrphan(fn) {
-			s.logger.Info("found an orphan folder",
-				zap.String("dirname", fn))
-			// looks like a complete snapshot, but the flag file is still in the dir
-			if err := s.processOrphans(dirName, noss, ss, removeDir); err != nil {
-				return err
-			}
-		} else if s.isZombie(fn) {
+		if s.isZombie(fn) {
 			s.logger.Info("found a zombie folder",
 				zap.String("dirname", fn))
 			// snapshot dir name with the ".receiving" or ".generating" suffix
@@ -159,7 +152,7 @@ func (s *snapshotter) removeOrphanSnapshots() error {
 			if err := removeDir(dirName); err != nil {
 				return err
 			}
-		} else if s.isSnapshot(fn) {
+		} else if s.isSnapshotDirectory(fn) {
 			// fully processed snapshot image with the flag file already removed
 			index := s.parseIndex(fn)
 			s.logger.Info("found a snapshot folder",
@@ -177,30 +170,6 @@ func (s *snapshotter) removeOrphanSnapshots() error {
 	return nil
 }
 
-func (s *snapshotter) processOrphans(dirName string,
-	noss bool, ss raftpb.Snapshot, removeDir func(string) error) error {
-	var ssFromDir raftpb.Snapshot
-	if err := fileutil.GetFlagFileContent(dirName,
-		fileutil.SnapshotFlagFilename, &ssFromDir, s.fs); err != nil {
-		return err
-	}
-	if raft.IsEmptySnap(ssFromDir) {
-		panic("empty snapshot found")
-	}
-	remove := false
-	if noss {
-		remove = true
-	} else {
-		if ss.Metadata.Index != ssFromDir.Metadata.Index {
-			remove = true
-		}
-	}
-	if remove {
-		return removeDir(dirName)
-	}
-	return s.removeFlagFile(dirName)
-}
-
 func (s *snapshotter) save(de saveable,
 	cs raftpb.ConfState, index uint64, term uint64) (ss raftpb.Snapshot,
 	env snapshot.SSEnv, err error) {
@@ -261,12 +230,7 @@ func (s *snapshotter) recover(rc recoverable,
 
 func (s *snapshotter) commit(ss raftpb.Snapshot, env snapshot.SSEnv) error {
 	env.FinalizeIndex(ss.Metadata.Index)
-	if err := env.SaveSSMetadata(&ss.Metadata); err != nil {
-		s.logger.Error("failed to commit saved snapshot",
-			zap.Error(err))
-		return err
-	}
-	if err := env.FinalizeSnapshot(&ss); err != nil {
+	if err := env.FinalizeSnapshot(); err != nil {
 		if errors.Is(err, snapshot.ErrSnapshotOutOfDate) {
 			return errSnapshotOutOfDate
 		}
@@ -274,18 +238,9 @@ func (s *snapshotter) commit(ss raftpb.Snapshot, env snapshot.SSEnv) error {
 			zap.Error(err))
 		return err
 	}
-	if err := env.RemoveFlagFile(); err != nil {
-		s.logger.Error("failed to remove flag file",
-			zap.Error(err))
-		return err
-	}
 	return nil
 }
 
-func (s *snapshotter) removeFlagFile(dirName string) error {
-	return fileutil.RemoveFlagFile(dirName, fileutil.SnapshotFlagFilename, s.fs)
-}
-
 func (s *snapshotter) getRecoverSnapshotEnv(ss raftpb.Snapshot) snapshot.SSEnv {
 	var si meta.SnapshotInfo
 	protoc.MustUnmarshal(&si, ss.Data)
@@ -299,7 +254,7 @@ func (s *snapshotter) getCreatingSnapshotEnv(extra uint64) snapshot.SSEnv {
 		s.shardID, s.replicaID, 0, extra, snapshot.CreatingMode, s.fs)
 }
 
-func (s *snapshotter) dirMatch(dir string) bool {
+func (s *snapshotter) isSnapshotDirectory(dir string) bool {
 	return snapshot.SnapshotDirNameRe.Match([]byte(dir))
 }
 
@@ -317,22 +272,6 @@ func (s *snapshotter) parseIndex(dir string) uint64 {
 	return 0
 }
 
-func (s *snapshotter) isSnapshot(dir string) bool {
-	if !s.dirMatch(dir) {
-		return false
-	}
-	fdir := s.fs.PathJoin(s.rootDir, dir)
-	return !fileutil.HasFlagFile(fdir, fileutil.SnapshotFlagFilename, s.fs)
-}
-
-func (s *snapshotter) isOrphan(dir string) bool {
-	if !s.dirMatch(dir) {
-		return false
-	}
-	fdir := s.fs.PathJoin(s.rootDir, dir)
-	return fileutil.HasFlagFile(fdir, fileutil.SnapshotFlagFilename, s.fs)
-}
-
 func (s *snapshotter) isZombie(dir string) bool {
 	return snapshot.GenSnapshotDirNameRe.Match([]byte(dir)) ||
 		snapshot.RecvSnapshotDirNameRe.Match([]byte(dir))
diff --git a/snapshot/snapshot_env.go b/snapshot/snapshot_env.go
index 4552215..ba9793f 100644
--- a/snapshot/snapshot_env.go
+++ b/snapshot/snapshot_env.go
@@ -45,8 +45,6 @@ import (
 var (
 	// ErrSnapshotOutOfDate is the error to indicate that snapshot is out of date.
 	ErrSnapshotOutOfDate = errors.New("snapshot out of date")
-	// MetadataFilename is the filename of a snapshot's metadata file.
-	MetadataFilename = "snapshot.metadata"
 	// SnapshotDirNameRe is the regex of snapshot names.
 	SnapshotDirNameRe = regexp.MustCompile(`^snapshot-[0-9A-F]+-[0-9A-F]+$`)
 	// SnapshotDirNamePartsRe is used to find the index value from snapshot folder name.
@@ -204,12 +202,9 @@ func (se *SSEnv) MustRemoveTempDir() {
 }
 
 // FinalizeSnapshot finalizes the snapshot.
-func (se *SSEnv) FinalizeSnapshot(msg fileutil.Marshaler) error {
+func (se *SSEnv) FinalizeSnapshot() error {
 	finalizeLock.Lock()
 	defer finalizeLock.Unlock()
-	if err := se.createFlagFile(msg); err != nil {
-		return err
-	}
 	if se.finalDirExists() {
 		return ErrSnapshotOutOfDate
 	}
@@ -226,25 +221,6 @@ func (se *SSEnv) RemoveFinalDir() error {
 	return se.removeDir(se.GetFinalDir())
 }
 
-// SaveSSMetadata saves the metadata of the snapshot file.
-func (se *SSEnv) SaveSSMetadata(msg fileutil.Marshaler) error {
-	return fileutil.CreateFlagFile(se.GetTempDir(), MetadataFilename, msg, se.fs)
-}
-
-// HasFlagFile returns a boolean flag indicating whether the flag file is
-// available in the final directory.
-func (se *SSEnv) HasFlagFile() bool {
-	fp := se.fs.PathJoin(se.GetFinalDir(), fileutil.SnapshotFlagFilename)
-	_, err := se.fs.Stat(fp)
-	return !vfs.IsNotExist(err)
-}
-
-// RemoveFlagFile removes the flag file from the final directory.
-func (se *SSEnv) RemoveFlagFile() error {
-	return fileutil.RemoveFlagFile(se.GetFinalDir(),
-		fileutil.SnapshotFlagFilename, se.fs)
-}
-
 func (se *SSEnv) FinalDirExists() bool {
 	return se.finalDirExists()
 }
@@ -273,8 +249,3 @@ func (se *SSEnv) renameToFinalDir() error {
 	}
 	return fileutil.SyncDir(se.rootDir, se.fs)
 }
-
-func (se *SSEnv) createFlagFile(msg fileutil.Marshaler) error {
-	return fileutil.CreateFlagFile(se.GetTempDir(),
-		fileutil.SnapshotFlagFilename, msg, se.fs)
-}
diff --git a/transport/chunk.go b/transport/chunk.go
index 5e4475e..ece2e7a 100644
--- a/transport/chunk.go
+++ b/transport/chunk.go
@@ -286,7 +286,7 @@ func (c *Chunk) addLocked(chunk meta.SnapshotChunk) bool {
 		c.logger.Debug("last snapshot chunk received",
 			zap.String("key", key))
 		defer c.reset(key)
-		if err := c.finalize(chunk, td); err != nil {
+		if err := c.finalize(td); err != nil {
 			c.removeTempDir(chunk)
 			if !errors.Is(err, ErrSnapshotOutOfDate) {
 				c.logger.Fatal("failed when finalizing snapshot dir",
@@ -351,14 +351,13 @@ func (c *Chunk) getEnv(chunk meta.SnapshotChunk) snapshot.SSEnv {
 		chunk.Index, chunk.From, snapshot.ReceivingMode, c.fs)
 }
 
-func (c *Chunk) finalize(chunk meta.SnapshotChunk, td *tracked) error {
-	env := c.getEnv(chunk)
+func (c *Chunk) finalize(td *tracked) error {
+	env := c.getEnv(td.first)
 	msg := c.toMessage(td.first)
 	if len(msg.Messages) != 1 || msg.Messages[0].Message.Type != raftpb.MsgSnap {
 		panic("invalid message")
 	}
-	ss := &msg.Messages[0].Message.Snapshot
-	err := env.FinalizeSnapshot(ss)
+	err := env.FinalizeSnapshot()
 	if err == snapshot.ErrSnapshotOutOfDate {
 		return ErrSnapshotOutOfDate
 	}
diff --git a/util/fileutil/utils.go b/util/fileutil/utils.go
index da7022e..6d09c29 100644
--- a/util/fileutil/utils.go
+++ b/util/fileutil/utils.go
@@ -44,11 +44,9 @@ import (
 
 const (
 	// DefaultFileMode is the default file mode for files generated.
-	DefaultFileMode = 0640
-	// SnapshotFlagFilename defines the filename of the snapshot flag file.
-	SnapshotFlagFilename = "matrixcube.snapshot.message"
-	defaultDirFileMode   = 0750
-	deleteFilename       = "DELETED.matrixcube"
+	DefaultFileMode    = 0640
+	defaultDirFileMode = 0750
+	deleteFilename     = "DELETED.matrixcube"
 )
 
 var firstError = util.FirstError


Test patch:
diff --git a/logdb/logdb_test.go b/logdb/logdb_test.go
index 87b8e57..5d986d2 100644
--- a/logdb/logdb_test.go
+++ b/logdb/logdb_test.go
@@ -277,6 +277,28 @@ func TestLogDBSaveRaftState(t *testing.T) {
 	runLogDBTest(t, tf, fs)
 }
 
+func TestLogDBReadRaftState(t *testing.T) {
+	tf := func(t *testing.T, db *KVLogDB) {
+		rd := raft.Ready{
+			Entries:   []raftpb.Entry{{Index: 4, Term: 1}, {Index: 5, Term: 1}, {Index: 6, Term: 1}},
+			HardState: raftpb.HardState{Commit: 4, Term: 1, Vote: 2},
+		}
+		wc := db.NewWorkerContext()
+		if err := db.SaveRaftState(testShardID, testReplicaID, rd, wc); err != nil {
+			t.Fatalf("failed to save raft state, %v", err)
+		}
+		rs, err := db.ReadRaftState(testShardID, testReplicaID, 5)
+		if errors.Is(err, ErrNoSavedLog) {
+			t.Fatalf("failed to get raft state, %v", err)
+		}
+		assert.Equal(t, uint64(5), rs.FirstIndex)
+		assert.Equal(t, uint64(2), rs.EntryCount)
+		assert.Equal(t, rd.HardState, rs.State)
+	}
+	fs := vfs.GetTestFS()
+	runLogDBTest(t, tf, fs)
+}
+
 func TestLogDBIterateEntries(t *testing.T) {
 	tf := func(t *testing.T, db *KVLogDB) {
 		rd := raft.Ready{
diff --git a/raftstore/replica_event_raft_ready_test.go b/raftstore/replica_event_raft_ready_test.go
index 4ebc5c1..d6fb73a 100644
--- a/raftstore/replica_event_raft_ready_test.go
+++ b/raftstore/replica_event_raft_ready_test.go
@@ -237,12 +237,6 @@ func TestApplyReceivedSnapshot(t *testing.T) {
 		assert.Equal(t, uint64(100), ss.Metadata.Index)
 		assert.True(t, created)
 
-		// created snapshot doesn't have the flag file, we need to fake it to make
-		// the snapshot looks like a received snapshot
-		env := r.snapshotter.getRecoverSnapshotEnv(ss)
-		fileutil.CreateFlagFile(env.GetFinalDir(),
-			fileutil.SnapshotFlagFilename, &ss, fs)
-
 		// reset the data storage
 		dsMem := mem.NewStorage()
 		base := kv.NewBaseStorage(dsMem, fs)
@@ -264,7 +258,7 @@ func TestApplyReceivedSnapshot(t *testing.T) {
 		assert.Equal(t, 1, len(sms))
 		assert.Equal(t, shard, sms[0].Metadata.Shard)
 
-		env = r.snapshotter.getRecoverSnapshotEnv(ss)
+		env := r.snapshotter.getRecoverSnapshotEnv(ss)
 		exist, err := fileutil.Exist(env.GetFinalDir(), fs)
 		assert.NoError(t, err)
 		assert.True(t, exist)
diff --git a/raftstore/replica_snapshot_test.go b/raftstore/replica_snapshot_test.go
index 48145d2..dfc4bd8 100644
--- a/raftstore/replica_snapshot_test.go
+++ b/raftstore/replica_snapshot_test.go
@@ -95,20 +95,10 @@ func TestReplicaSnapshotCanBeCreated(t *testing.T) {
 		if _, err := fs.Stat(snapshotDir); vfs.IsNotExist(err) {
 			t.Errorf("snapshot final dir not created, %v", err)
 		}
-		mf := fs.PathJoin(snapshotDir, snapshot.MetadataFilename)
-		if _, err := fs.Stat(mf); vfs.IsNotExist(err) {
-			t.Errorf("snapshot metadata file not created, %v", err)
-		}
 		dbf := fs.PathJoin(snapshotDir, "db.data")
 		if _, err := fs.Stat(dbf); vfs.IsNotExist(err) {
 			t.Errorf("snapshot data file not created, %v", err)
 		}
-		var ssFromDir raftpb.SnapshotMetadata
-		if err := fileutil.GetFlagFileContent(snapshotDir,
-			snapshot.MetadataFilename, &ssFromDir, fs); err != nil {
-			t.Errorf("failed to get flag file content %v", err)
-		}
-		assert.Equal(t, ss.Metadata.Index, ssFromDir.Index)
 		_, err = r.logdb.GetSnapshot(1)
 		assert.Equal(t, logdb.ErrNoSnapshot, err)
 	}
diff --git a/raftstore/snapshotter_test.go b/raftstore/snapshotter_test.go
index 7797a3f..2283d31 100644
--- a/raftstore/snapshotter_test.go
+++ b/raftstore/snapshotter_test.go
@@ -40,7 +40,6 @@ import (
 	"github.com/matrixorigin/matrixcube/components/log"
 	"github.com/matrixorigin/matrixcube/logdb"
 	"github.com/matrixorigin/matrixcube/storage/kv/mem"
-	"github.com/matrixorigin/matrixcube/util/fileutil"
 	"github.com/matrixorigin/matrixcube/util/leaktest"
 	"github.com/matrixorigin/matrixcube/vfs"
 )
@@ -230,21 +229,12 @@ func TestOnlyMostRecentSnapshotIsKept(t *testing.T) {
 func TestFirstSnapshotBecomeOrphanedIsHandled(t *testing.T) {
 	fs := vfs.GetTestFS()
 	fn := func(t *testing.T, ldb logdb.LogDB, s *snapshotter) {
-		s1 := raftpb.Snapshot{
-			Metadata: raftpb.SnapshotMetadata{
-				Index: 100,
-				Term:  200,
-			},
-		}
 		env := s.getCreatingSnapshotEnv(0)
 		env.FinalizeIndex(100)
 		fd1 := env.GetFinalDir()
 		if err := fs.MkdirAll(fd1, 0755); err != nil {
 			t.Errorf("failed to create dir %v", err)
 		}
-		if err := fileutil.CreateFlagFile(fd1, fileutil.SnapshotFlagFilename, &s1, fs); err != nil {
-			t.Errorf("failed to create flag file %s", err)
-		}
 		if err := s.removeOrphanSnapshots(); err != nil {
 			t.Errorf("failed to process orphaned snapshtos %s", err)
 		}
@@ -282,12 +272,6 @@ func TestOrphanedSnapshotRecordIsRemoved(t *testing.T) {
 		if err := fs.MkdirAll(fd2, 0755); err != nil {
 			t.Errorf("failed to create dir %v", err)
 		}
-		if err := fileutil.CreateFlagFile(fd1, fileutil.SnapshotFlagFilename, &s1, fs); err != nil {
-			t.Errorf("failed to create flag file %s", err)
-		}
-		if err := fileutil.CreateFlagFile(fd2, fileutil.SnapshotFlagFilename, &s2, fs); err != nil {
-			t.Errorf("failed to create flag file %s", err)
-		}
 		if err := s.saveSnapshot(s1); err != nil {
 			t.Errorf("failed to save snapshot to logdb")
 		}
@@ -304,9 +288,6 @@ func TestOrphanedSnapshotRecordIsRemoved(t *testing.T) {
 		if _, err := fs.Stat(fd2); vfs.IsNotExist(err) {
 			t.Errorf("unexpectedly removed fd2")
 		}
-		if fileutil.HasFlagFile(fd2, fileutil.SnapshotFlagFilename, fs) {
-			t.Errorf("flag for fd2 not removed")
-		}
 		snapshot, err := s.ldb.GetSnapshot(1)
 		if err != nil {
 			t.Fatalf("failed to list snapshot %v", err)
@@ -356,15 +337,6 @@ func TestOrphanedSnapshotsCanBeProcessed(t *testing.T) {
 		if err := fs.MkdirAll(fd4, 0755); err != nil {
 			t.Errorf("failed to create dir %v", err)
 		}
-		if err := fileutil.CreateFlagFile(fd1, fileutil.SnapshotFlagFilename, &s1, fs); err != nil {
-			t.Errorf("failed to create flag file %s", err)
-		}
-		if err := fileutil.CreateFlagFile(fd2, fileutil.SnapshotFlagFilename, &s2, fs); err != nil {
-			t.Errorf("failed to create flag file %s", err)
-		}
-		if err := fileutil.CreateFlagFile(fd4, fileutil.SnapshotFlagFilename, &s3, fs); err != nil {
-			t.Errorf("failed to create flag file %s", err)
-		}
 		if err := s.saveSnapshot(s1); err != nil {
 			t.Errorf("failed to save snapshot to logdb")
 		}
@@ -375,15 +347,6 @@ func TestOrphanedSnapshotsCanBeProcessed(t *testing.T) {
 		if err := s.removeOrphanSnapshots(); err != nil {
 			t.Errorf("failed to process orphaned snapshtos %s", err)
 		}
-		if fileutil.HasFlagFile(fd1, fileutil.SnapshotFlagFilename, fs) {
-			t.Errorf("flag for fd1 not removed")
-		}
-		if fileutil.HasFlagFile(fd2, fileutil.SnapshotFlagFilename, fs) {
-			t.Errorf("flag for fd2 not removed")
-		}
-		if !fileutil.HasFlagFile(fd4, fileutil.SnapshotFlagFilename, fs) {
-			t.Errorf("flag for fd4 is missing")
-		}
 		if _, err := fs.Stat(fd1); vfs.IsNotExist(err) {
 			t.Errorf("fd1 removed by mistake")
 		}
@@ -411,7 +374,7 @@ func TestSnapshotDirNameMatchWorks(t *testing.T) {
 			{"snapshot-", false},
 		}
 		for idx, tt := range tests {
-			v := s.dirMatch(tt.dirName)
+			v := s.isSnapshotDirectory(tt.dirName)
 			if v != tt.valid {
 				t.Errorf("dir name %s (%d) failed to match", tt.dirName, idx)
 			}
@@ -561,9 +524,6 @@ func TestSnapshotCanBeFinalized(t *testing.T) {
 		if !fi.IsDir() {
 			t.Errorf("not a dir")
 		}
-		if fileutil.HasFlagFile(finalSnapDir, fileutil.SnapshotFlagFilename, fs) {
-			t.Errorf("flag file not removed")
-		}
 		vfp := fs.PathJoin(finalSnapDir, "test.data")
 		fi, err = fs.Stat(vfp)
 		if err != nil {
diff --git a/snapshot/snapshot_env_test.go b/snapshot/snapshot_env_test.go
index 65b3fe1..a9571d9 100644
--- a/snapshot/snapshot_env_test.go
+++ b/snapshot/snapshot_env_test.go
@@ -34,7 +34,6 @@ import (
 	"testing"
 
 	"github.com/stretchr/testify/assert"
-	pb "go.etcd.io/etcd/raft/v3/raftpb"
 
 	"github.com/matrixorigin/matrixcube/vfs"
 )
@@ -216,34 +215,6 @@ func TestRenameTempDirToFinalDirCanComplete(t *testing.T) {
 		if !env.finalDirExists() {
 			t.Errorf("final dir does not exist")
 		}
-		if env.HasFlagFile() {
-			t.Errorf("flag file not suppose to be there")
-		}
-	}
-	fs := vfs.GetTestFS()
-	runEnvTest(t, tf, fs)
-}
-
-func TestFlagFileExists(t *testing.T) {
-	tf := func(t *testing.T, env SSEnv) {
-		env.FinalizeIndex(100)
-		if env.finalDirExists() {
-			t.Errorf("final dir already exist")
-		}
-		msg := &pb.Message{}
-		if err := env.createFlagFile(msg); err != nil {
-			t.Errorf("failed to create flag file")
-		}
-		err := env.renameToFinalDir()
-		if err != nil {
-			t.Errorf("rename tmp dir to final dir failed %v", err)
-		}
-		if !env.finalDirExists() {
-			t.Errorf("final dir does not exist")
-		}
-		if !env.HasFlagFile() {
-			t.Errorf("flag file not suppose to be there")
-		}
 	}
 	fs := vfs.GetTestFS()
 	runEnvTest(t, tf, fs)
@@ -251,14 +222,10 @@ func TestFlagFileExists(t *testing.T) {
 
 func TestFinalizeSnapshotCanComplete(t *testing.T) {
 	tf := func(t *testing.T, env SSEnv) {
-		m := &pb.Message{}
 		env.FinalizeIndex(100)
-		if err := env.FinalizeSnapshot(m); err != nil {
+		if err := env.FinalizeSnapshot(); err != nil {
 			t.Errorf("failed to finalize snapshot %v", err)
 		}
-		if !env.HasFlagFile() {
-			t.Errorf("no flag file")
-		}
 		if !env.finalDirExists() {
 			t.Errorf("no final dir")
 		}
@@ -274,13 +241,9 @@ func TestFinalizeSnapshotReturnOutOfDateWhenFinalDirExist(t *testing.T) {
 		if err := env.fs.MkdirAll(finalDir, 0755); err != nil {
 			t.Fatalf("%v", err)
 		}
-		m := &pb.Message{}
-		if err := env.FinalizeSnapshot(m); err != ErrSnapshotOutOfDate {
+		if err := env.FinalizeSnapshot(); err != ErrSnapshotOutOfDate {
 			t.Errorf("didn't return ErrSnapshotOutOfDate %v", err)
 		}
-		if env.HasFlagFile() {
-			t.Errorf("flag file exist")
-		}
 	}
 	fs := vfs.GetTestFS()
 	runEnvTest(t, tf, fs)