0
0
Fork 0

scorch RollbackPoints() no error at start & fix TestIndexRollback

When a scorch is just opened and is "empty", RollbackPoints() no
longer considers that an error situation.

Also, this commit makes the TestIndexRollback unit tests is a bit more
forgiving to races, as we were seeing failures sometimes in travis-CI
environments (TestIndexRollback was passing fine on my dev macbook).
The theory is the double-looping in the persisterLoop would sometimes
be racy, leading to 1 or 2 rollback points.
This commit is contained in:
Steve Yen 2018-02-08 10:12:20 -08:00
parent ea20b1be42
commit 99852accb0
2 changed files with 22 additions and 11 deletions

View File

@ -31,10 +31,9 @@ func (r *RollbackPoint) GetInternal(key []byte) []byte {
return r.meta[string(key)]
}
// RollbackPoints returns an array of rollback points available
// for the application to make a decision on where to rollback
// to. A nil return value indicates that there are no available
// rollback points.
// RollbackPoints returns an array of rollback points available for
// the application to rollback to, with more recent rollback points
// (higher epochs) coming first.
func (s *Scorch) RollbackPoints() ([]*RollbackPoint, error) {
if s.rootBolt == nil {
return nil, fmt.Errorf("RollbackPoints: root is nil")
@ -54,7 +53,7 @@ func (s *Scorch) RollbackPoints() ([]*RollbackPoint, error) {
snapshots := tx.Bucket(boltSnapshotsBucket)
if snapshots == nil {
return nil, fmt.Errorf("RollbackPoints: no snapshots available")
return nil, nil
}
rollbackPoints := []*RollbackPoint{}

View File

@ -62,6 +62,15 @@ func TestIndexRollback(t *testing.T) {
go sh.mainLoop()
go sh.persisterLoop()
// should have no rollback points initially
rollbackPoints, err := sh.RollbackPoints()
if err != nil {
t.Fatalf("expected no err, got: %v, %d", err, len(rollbackPoints))
}
if len(rollbackPoints) != 0 {
t.Fatalf("expected no rollbackPoints, got %d", len(rollbackPoints))
}
// create a batch, insert 2 new documents
batch := index.NewBatch()
doc := document.NewDocument("1")
@ -84,10 +93,13 @@ func TestIndexRollback(t *testing.T) {
_ = readerSlow.Close()
}()
// fetch rollback points available as of here
rollbackPoints, err := sh.RollbackPoints()
if err != nil || len(rollbackPoints) != 1 {
t.Fatal(err, len(rollbackPoints))
// fetch rollback points after first batch
rollbackPoints, err = sh.RollbackPoints()
if err != nil {
t.Fatalf("expected no err, got: %v, %d", err, len(rollbackPoints))
}
if len(rollbackPoints) == 0 {
t.Fatalf("expected some rollbackPoints, got none")
}
// set this as a rollback point for the future
@ -109,8 +121,8 @@ func TestIndexRollback(t *testing.T) {
}
rollbackPointsB, err := sh.RollbackPoints()
if err != nil || len(rollbackPointsB) != 3 {
t.Fatal(err, len(rollbackPointsB))
if err != nil || len(rollbackPointsB) <= len(rollbackPoints) {
t.Fatalf("expected no err, got: %v, %d", err, len(rollbackPointsB))
}
found := false