1
0
Fork 0

Avoid the race during testing

master
Philip O'Toole 1 year ago
parent 7c88b93979
commit e7919a906f

@ -81,6 +81,8 @@ const (
numBackups = "num_backups" numBackups = "num_backups"
numLoads = "num_loads" numLoads = "num_loads"
numRestores = "num_restores" numRestores = "num_restores"
numAutoRestores = "num_auto_restores"
numAutoRestoresSkipped = "num_auto_restores_skipped"
numRecoveries = "num_recoveries" numRecoveries = "num_recoveries"
numUncompressedCommands = "num_uncompressed_commands" numUncompressedCommands = "num_uncompressed_commands"
numCompressedCommands = "num_compressed_commands" numCompressedCommands = "num_compressed_commands"
@ -113,6 +115,8 @@ func ResetStats() {
stats.Add(numBackups, 0) stats.Add(numBackups, 0)
stats.Add(numRestores, 0) stats.Add(numRestores, 0)
stats.Add(numRecoveries, 0) stats.Add(numRecoveries, 0)
stats.Add(numAutoRestores, 0)
stats.Add(numAutoRestoresSkipped, 0)
stats.Add(numUncompressedCommands, 0) stats.Add(numUncompressedCommands, 0)
stats.Add(numCompressedCommands, 0) stats.Add(numCompressedCommands, 0)
stats.Add(numJoins, 0) stats.Add(numJoins, 0)
@ -1553,6 +1557,7 @@ func (s *Store) selfLeaderChange(leader bool) {
if !leader { if !leader {
s.logger.Printf("different node became Leader, not performing auto-restore") s.logger.Printf("different node became Leader, not performing auto-restore")
stats.Add(numAutoRestoresSkipped, 1)
return return
} }
@ -1576,6 +1581,7 @@ func (s *Store) selfLeaderChange(leader bool) {
s.logger.Printf("failed to load store from %s: %s", s.restorePath, err.Error()) s.logger.Printf("failed to load store from %s: %s", s.restorePath, err.Error())
return return
} }
stats.Add(numAutoRestores, 1)
s.logger.Printf("node auto-restored successfully from %s", s.restorePath) s.logger.Printf("node auto-restored successfully from %s", s.restorePath)
} }

@ -2,6 +2,7 @@ package store
import ( import (
"bytes" "bytes"
"expvar"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"math/rand" "math/rand"
@ -1625,8 +1626,15 @@ func Test_MultiNodeStoreAutoRestoreBootstrap(t *testing.T) {
t.Fatalf("failed to get leader: %s", err.Error()) t.Fatalf("failed to get leader: %s", err.Error())
} }
// Check the data. // Ultimately there is a hard-to-control timing issue here. Knowing
testPoll(t, s0.Ready, 100*time.Millisecond, 2*time.Second) // exactly when the leader has applied the restore is difficult, so
// just wait a bit.
time.Sleep(2 * time.Second)
if !s0.Ready() {
t.Fatalf("node is not ready")
}
qr := queryRequestFromString("SELECT * FROM foo WHERE id=2", false, true) qr := queryRequestFromString("SELECT * FROM foo WHERE id=2", false, true)
r, err := s0.Query(qr) r, err := s0.Query(qr)
if err != nil { if err != nil {
@ -1639,28 +1647,16 @@ func Test_MultiNodeStoreAutoRestoreBootstrap(t *testing.T) {
t.Fatalf("unexpected results for query\nexp: %s\ngot: %s", exp, got) t.Fatalf("unexpected results for query\nexp: %s\ngot: %s", exp, got)
} }
// Give the follower some time to catch up.
f := func() bool {
qr := queryRequestFromString("SELECT * FROM foo WHERE id=2", false, false)
qr.Level = command.QueryRequest_QUERY_REQUEST_LEVEL_NONE
r, err = s1.Query(qr)
if err != nil {
return false
}
if exp, got := `["id","name"]`, asJSON(r[0].Columns); exp != got {
return false
}
if exp, got := `[[2,"fiona"]]`, asJSON(r[0].Values); exp != got {
return false
}
return true
}
testPoll(t, f, 100*time.Millisecond, 2*time.Second)
if pathExists(path0) || pathExists(path1) || pathExists(path2) { if pathExists(path0) || pathExists(path1) || pathExists(path2) {
t.Fatalf("an auto-restore file was not removed") t.Fatalf("an auto-restore file was not removed")
} }
if stats.Get(numAutoRestores).(*expvar.Int).Value() != 1 {
t.Fatalf("numAutoRestore is incorrect")
}
if stats.Get(numAutoRestoresSkipped).(*expvar.Int).Value() != 2 {
t.Fatalf("numAutoRestoresSkipped is incorrect")
}
} }
func Test_MultiNodeJoinNonVoterRemove(t *testing.T) { func Test_MultiNodeJoinNonVoterRemove(t *testing.T) {

Loading…
Cancel
Save