forked from cockroachdb/cockroach
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
storage: remove TestStoreRangeRebalance
Add the check that preemptive snapshots are being used to TestStoreRangeUpReplicate. Add TestReplicateQueueRebalance for testing that basic rebalancing is working. Fixes cockroachdb#10193 Fixes cockroachdb#10156 Fixes cockroachdb#9395
- Loading branch information
1 parent
375eee3
commit de3434d
Showing
5 changed files
with
128 additions
and
163 deletions.
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
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 |
---|---|---|
@@ -0,0 +1,99 @@ | ||
// Copyright 2016 The Cockroach Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or | ||
// implied. See the License for the specific language governing | ||
// permissions and limitations under the License. | ||
// | ||
// Author: Peter Mattis | ||
|
||
package storage_test | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"golang.org/x/net/context" | ||
|
||
"github.com/cockroachdb/cockroach/pkg/base" | ||
"github.com/cockroachdb/cockroach/pkg/keys" | ||
"github.com/cockroachdb/cockroach/pkg/storage" | ||
"github.com/cockroachdb/cockroach/pkg/testutils" | ||
"github.com/cockroachdb/cockroach/pkg/testutils/testcluster" | ||
"github.com/cockroachdb/cockroach/pkg/util" | ||
"github.com/cockroachdb/cockroach/pkg/util/leaktest" | ||
"github.com/cockroachdb/cockroach/pkg/util/log" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
func TestReplicateQueueRebalance(t *testing.T) { | ||
defer leaktest.AfterTest(t)() | ||
|
||
// Set the gossip stores interval lower to speed up rebalancing. With the | ||
// default of 5s we have to wait ~5s for the rebalancing to start. | ||
if err := os.Setenv("COCKROACH_GOSSIP_STORES_INTERVAL", "100ms"); err != nil { | ||
t.Fatal(err) | ||
} | ||
defer func() { | ||
if err := os.Unsetenv("COCKROACH_GOSSIP_STORES_INTERVAL"); err != nil { | ||
t.Fatal(err) | ||
} | ||
}() | ||
|
||
// TODO(peter): Bump this to 10 nodes. Doing so is flaky (we encounter a | ||
// situation where 1 node never receives a replica). Need to figure out why. | ||
tc := testcluster.StartTestCluster(t, 5, | ||
base.TestClusterArgs{ReplicationMode: base.ReplicationAuto}, | ||
) | ||
defer tc.Stopper().Stop() | ||
|
||
// Create a handful of ranges. Along with the initial ranges in the cluster, | ||
// this will result in 15 total ranges and 45 total replicas. Spread across | ||
// the 10 nodes in the cluster the average is 4.5 replicas per node. | ||
for i := 0; i < 10; i++ { | ||
tableID := keys.MaxReservedDescID + i + 1 | ||
splitKey := keys.MakeRowSentinelKey(keys.MakeTablePrefix(uint32(tableID))) | ||
for { | ||
if _, _, err := tc.SplitRange(splitKey); err != nil { | ||
if testutils.IsError(err, "split at key .* failed: conflict updating range descriptors") { | ||
continue | ||
} | ||
t.Fatal(err) | ||
} | ||
break | ||
} | ||
} | ||
|
||
countReplicas := func() []int { | ||
counts := make([]int, len(tc.Servers)) | ||
for i, s := range tc.Servers { | ||
err := s.Stores().VisitStores(func(s *storage.Store) error { | ||
counts[i] += s.ReplicaCount() | ||
return nil | ||
}) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
} | ||
return counts | ||
} | ||
|
||
util.SucceedsSoon(t, func() error { | ||
counts := countReplicas() | ||
for _, c := range counts { | ||
if c == 0 { | ||
err := errors.Errorf("not balanced: %d", counts) | ||
log.Info(context.Background(), err) | ||
return err | ||
} | ||
} | ||
return nil | ||
}) | ||
} |