-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
storage: Consider which replica will be removed when adding a replica… #18364
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,7 @@ import ( | |
"github.com/cockroachdb/cockroach/pkg/roachpb" | ||
"github.com/cockroachdb/cockroach/pkg/rpc" | ||
"github.com/cockroachdb/cockroach/pkg/settings/cluster" | ||
"github.com/cockroachdb/cockroach/pkg/storage/engine/enginepb" | ||
"github.com/cockroachdb/cockroach/pkg/testutils" | ||
"github.com/cockroachdb/cockroach/pkg/testutils/gossiputil" | ||
"github.com/cockroachdb/cockroach/pkg/util" | ||
|
@@ -657,6 +658,7 @@ func TestAllocatorRebalance(t *testing.T) { | |
result, _ := a.RebalanceTarget( | ||
ctx, | ||
config.Constraints{}, | ||
nil, | ||
testRangeInfo([]roachpb.ReplicaDescriptor{{StoreID: 3}}, firstRange), | ||
storeFilterThrottled, | ||
) | ||
|
@@ -685,6 +687,136 @@ func TestAllocatorRebalance(t *testing.T) { | |
} | ||
} | ||
|
||
// TestAllocatorRebalanceTarget could help us to verify whether we'll rebalance to a target that | ||
// we'll immediately remove. | ||
func TestAllocatorRebalanceTarget(t *testing.T) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you confirm that this test passes with your change but fails without it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I could confirm that. |
||
defer leaktest.AfterTest(t)() | ||
manual := hlc.NewManualClock(123) | ||
clock := hlc.NewClock(manual.UnixNano, time.Nanosecond) | ||
stopper, g, _, a, _ := createTestAllocator( /* deterministic */ false) | ||
defer stopper.Stop(context.Background()) | ||
// We make 4 stores in this test, store1 and store2 are in the same datacenter a, | ||
// store3 in the datacenter b, store4 in the datacenter c. all of our replicas are | ||
// distributed within these three datacenters. Originally, store4 has much more replicas | ||
// than other stores. So if we didn't make the simulation in RebalanceTarget, it will | ||
// try to choose store2 as the target store to make an rebalance. | ||
// However, we'll immediately remove the replica on the store2 to guarantee the locality diversity. | ||
// But after we make the simulation in RebalanceTarget, we could avoid that happen. | ||
stores := []*roachpb.StoreDescriptor{ | ||
{ | ||
StoreID: 1, | ||
Node: roachpb.NodeDescriptor{ | ||
NodeID: 1, | ||
Locality: roachpb.Locality{ | ||
Tiers: []roachpb.Tier{ | ||
{Key: "datacenter", Value: "a"}, | ||
}, | ||
}, | ||
}, | ||
Capacity: roachpb.StoreCapacity{ | ||
RangeCount: 50, | ||
}, | ||
}, | ||
{ | ||
StoreID: 2, | ||
Node: roachpb.NodeDescriptor{ | ||
NodeID: 2, | ||
Locality: roachpb.Locality{ | ||
Tiers: []roachpb.Tier{ | ||
{Key: "datacenter", Value: "a"}, | ||
}, | ||
}, | ||
}, | ||
Capacity: roachpb.StoreCapacity{ | ||
RangeCount: 56, | ||
}, | ||
}, | ||
{ | ||
StoreID: 3, | ||
Node: roachpb.NodeDescriptor{ | ||
NodeID: 3, | ||
Locality: roachpb.Locality{ | ||
Tiers: []roachpb.Tier{ | ||
{Key: "datacenter", Value: "b"}, | ||
}, | ||
}, | ||
}, | ||
Capacity: roachpb.StoreCapacity{ | ||
RangeCount: 55, | ||
}, | ||
}, | ||
{ | ||
StoreID: 4, | ||
Node: roachpb.NodeDescriptor{ | ||
NodeID: 4, | ||
Locality: roachpb.Locality{ | ||
Tiers: []roachpb.Tier{ | ||
{Key: "datacenter", Value: "c"}, | ||
}, | ||
}, | ||
}, | ||
Capacity: roachpb.StoreCapacity{ | ||
RangeCount: 150, | ||
}, | ||
}, | ||
} | ||
sg := gossiputil.NewStoreGossiper(g) | ||
sg.GossipStores(stores, t) | ||
|
||
st := a.storePool.st | ||
EnableStatsBasedRebalancing.Override(&st.SV, false) | ||
replicas := []roachpb.ReplicaDescriptor{ | ||
{ | ||
StoreID: 1, | ||
NodeID: 1, | ||
}, | ||
{ | ||
StoreID: 3, | ||
NodeID: 3, | ||
}, | ||
{ | ||
StoreID: 4, | ||
NodeID: 4, | ||
}, | ||
} | ||
repl := &Replica{RangeID: firstRange} | ||
|
||
repl.mu.Lock() | ||
repl.mu.state.Stats = &enginepb.MVCCStats{} | ||
repl.mu.Unlock() | ||
|
||
rs := newReplicaStats(clock, nil) | ||
repl.writeStats = rs | ||
|
||
desc := &roachpb.RangeDescriptor{ | ||
Replicas: replicas, | ||
RangeID: firstRange, | ||
} | ||
|
||
rangeInfo := rangeInfoForRepl(repl, desc) | ||
|
||
status := &raft.Status{ | ||
Progress: make(map[uint64]raft.Progress), | ||
} | ||
for _, replica := range replicas { | ||
status.Progress[uint64(replica.NodeID)] = raft.Progress{ | ||
Match: 10, | ||
} | ||
} | ||
for i := 0; i < 10; i++ { | ||
result, _ := a.RebalanceTarget( | ||
context.Background(), | ||
config.Constraints{}, | ||
status, | ||
rangeInfo, | ||
storeFilterThrottled, | ||
) | ||
if result != nil { | ||
t.Errorf("expected no rebalance, but got %d.", result.StoreID) | ||
} | ||
} | ||
} | ||
|
||
func TestAllocatorRebalanceDeadNodes(t *testing.T) { | ||
defer leaktest.AfterTest(t)() | ||
|
||
|
@@ -754,7 +886,7 @@ func TestAllocatorRebalanceDeadNodes(t *testing.T) { | |
for _, c := range testCases { | ||
t.Run("", func(t *testing.T) { | ||
result, _ := a.RebalanceTarget( | ||
ctx, config.Constraints{}, testRangeInfo(c.existing, firstRange), storeFilterThrottled) | ||
ctx, config.Constraints{}, nil, testRangeInfo(c.existing, firstRange), storeFilterThrottled) | ||
if c.expected > 0 { | ||
if result == nil { | ||
t.Fatalf("expected %d, but found nil", c.expected) | ||
|
@@ -949,6 +1081,7 @@ func TestAllocatorRebalanceByCount(t *testing.T) { | |
result, _ := a.RebalanceTarget( | ||
ctx, | ||
config.Constraints{}, | ||
nil, | ||
testRangeInfo([]roachpb.ReplicaDescriptor{{StoreID: stores[0].StoreID}}, firstRange), | ||
storeFilterThrottled, | ||
) | ||
|
@@ -2552,6 +2685,7 @@ func TestAllocatorRebalanceAway(t *testing.T) { | |
actual, _ := a.RebalanceTarget( | ||
ctx, | ||
constraints, | ||
nil, | ||
testRangeInfo(existingReplicas, firstRange), | ||
storeFilterThrottled, | ||
) | ||
|
@@ -2672,6 +2806,7 @@ func Example_rebalancing() { | |
target, _ := alloc.RebalanceTarget( | ||
context.Background(), | ||
config.Constraints{}, | ||
nil, | ||
testRangeInfo([]roachpb.ReplicaDescriptor{{NodeID: ts.Node.NodeID, StoreID: ts.StoreID}}, firstRange), | ||
storeFilterThrottled, | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think we could avoid this code duplication with what's in
replicate_queue.go
and instead create a shared function they can both use? If they're separate like this, it seems likely that they'll accidentally diverge in the future.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, Sorry, I couldn't quite understand what do you mean here. I didn't make any change to
replicate_queue.go
.Would you please point out the code duplication with
replicate_queue.go
? Thank you very much.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was referring to the code for the
AllocatorRemove
case inprocessOneChange
, but on looking at it again it doesn't look like there's much that could be de-duped. Sorry for the confusion!