Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only trigger bootstrap on topology change if node receives new shards #1868

Merged
merged 3 commits into from
Sep 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
richardartoul marked this conversation as resolved.
Show resolved Hide resolved
// 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