Skip to content

Commit

Permalink
Only trigger bootstrap on topology change if node receives new shards (
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard Artoul authored Sep 4, 2019
1 parent fe885e6 commit 08d94a1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/dbnode/storage/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,15 @@ func (d *db) AssignShardSet(shardSet sharding.ShardSet) {
ns.AssignShardSet(shardSet)
}

d.queueBootstrapWithLock()
if receivedNewShards {
// Only trigger a bootstrap if the node received new shards otherwise
// the nodes will perform lots of small bootstraps (that accomplish nothing)
// during topology changes as other nodes mark their shards as available.
//
// These small bootstraps can significantly delay topology changes as they prevent
// the nodes from marking themselves as bootstrapped and durable, for example.
d.queueBootstrapWithLock()
}
}

func (d *db) hasReceivedNewShardsWithLock(incoming sharding.ShardSet) bool {
Expand Down
8 changes: 7 additions & 1 deletion src/dbnode/storage/database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ func TestDatabaseAssignShardSet(t *testing.T) {
wg.Wait()
}

func TestDatabaseAssignShardSetDoesNotUpdateLastReceivedNewShardsIfNoNewShards(t *testing.T) {
func TestDatabaseAssignShardSetBehaviorNoNewShards(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

Expand All @@ -413,6 +413,11 @@ func TestDatabaseAssignShardSetDoesNotUpdateLastReceivedNewShardsIfNoNewShards(t
close(mapCh)
}()

// Set a mock mediator to be certain that bootstrap is not called when
// no new shards are assigned.
mediator := NewMockdatabaseMediator(ctrl)
d.mediator = mediator

var ns []*MockdatabaseNamespace
ns = append(ns, dbAddNewMockNamespace(ctrl, d, "testns1"))
ns = append(ns, dbAddNewMockNamespace(ctrl, d, "testns2"))
Expand All @@ -427,6 +432,7 @@ func TestDatabaseAssignShardSetDoesNotUpdateLastReceivedNewShardsIfNoNewShards(t

t1 := d.lastReceivedNewShards
d.AssignShardSet(d.shardSet)
// Ensure that lastReceivedNewShards is not updated if no new shards are assigned.
require.True(t, d.lastReceivedNewShards.Equal(t1))

wg.Wait()
Expand Down

0 comments on commit 08d94a1

Please sign in to comment.