Skip to content

Commit 96eac46

Browse files
committed
Add nodeStatus check state helpers
1 parent 90c1288 commit 96eac46

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

pbm/restore/physical.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -854,6 +854,20 @@ const (
854854
)
855855

856856
func (n nodeStatus) is(s nodeStatus) bool { return n&s != 0 }
857+
// isForCleanup returns true when internal node state if so
858+
// any sort of clean-up: full cleanup or fallbacksync.
859+
// Status indicates that content of db path contains state
860+
// which is not correct, and therefore it needs to be
861+
// discarded.
862+
func (n nodeStatus) isForCleanup() bool {
863+
return n&restoreStared != 0 && n&restoreDone == 0
864+
}
865+
866+
// isFailed returns true when internal node state didn't reach
867+
// done state, no matter whether it was started or not.
868+
func (n nodeStatus) isFailed() bool {
869+
return n&restoreDone == 0
870+
}
857871

858872
// log buffer that will dump content to the storage on restore
859873
// finish (whether it's successful or not). It also dumps content

pbm/restore/physical_test.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,44 @@ import (
1313
"github.com/percona/percona-backup-mongodb/pbm/log"
1414
)
1515

16+
func TestNodeStatus(t *testing.T) {
17+
t.Run("isForCleanup", func(t *testing.T) {
18+
var progress nodeStatus
19+
20+
if progress.isForCleanup() {
21+
t.Errorf("in initial progress phase, node is not for the cleanup")
22+
}
23+
24+
progress |= restoreStared
25+
if !progress.isForCleanup() {
26+
t.Errorf("in point of no return phase cleanup should be done")
27+
}
28+
29+
progress |= restoreDone
30+
if progress.isForCleanup() {
31+
t.Errorf("in done phase, node is not for the cleanup")
32+
}
33+
})
34+
35+
t.Run("isFailed", func(t *testing.T) {
36+
var progress nodeStatus
37+
38+
if !progress.isFailed() {
39+
t.Errorf("node is int initial progress phase, so it should be marked as failed")
40+
}
41+
42+
progress |= restoreStared
43+
if !progress.isFailed() {
44+
t.Errorf("node is in started phase, so it should be marked as failed")
45+
}
46+
47+
progress |= restoreDone
48+
if progress.isFailed() {
49+
t.Errorf("in done phase, node shouldn't be marked as failed")
50+
}
51+
})
52+
}
53+
1654
func TestMoveAll(t *testing.T) {
1755
t.Run("move all files and dir", func(t *testing.T) {
1856
tempSrc, _ := os.MkdirTemp("", "src")

0 commit comments

Comments
 (0)