-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #78190 from cockroachdb/blathers/backport-release-…
…22.1-78122 release-22.1: kvserver: disable merge queue until kvsubscriber has updated
- Loading branch information
Showing
4 changed files
with
104 additions
and
1 deletion.
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
90 changes: 90 additions & 0 deletions
90
pkg/spanconfig/spanconfigkvsubscriber/kvsubscriber_client_test.go
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,90 @@ | ||
// Copyright 2022 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package spanconfigkvsubscriber_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/cockroachdb/cockroach/pkg/base" | ||
"github.com/cockroachdb/cockroach/pkg/kv/kvclient/rangefeed/rangefeedcache" | ||
"github.com/cockroachdb/cockroach/pkg/kv/kvserver" | ||
"github.com/cockroachdb/cockroach/pkg/roachpb" | ||
"github.com/cockroachdb/cockroach/pkg/spanconfig" | ||
"github.com/cockroachdb/cockroach/pkg/testutils" | ||
"github.com/cockroachdb/cockroach/pkg/testutils/testcluster" | ||
"github.com/cockroachdb/cockroach/pkg/util/leaktest" | ||
"github.com/cockroachdb/cockroach/pkg/util/log" | ||
"github.com/cockroachdb/errors" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
// TestBlockedKVSubscriberDisablesMerges ensures that the merge queue is | ||
// disabled until the KVSubscriber has some snapshot. | ||
func TestBlockedKVSubscriberDisablesMerges(t *testing.T) { | ||
defer leaktest.AfterTest(t)() | ||
defer log.Scope(t).Close(t) | ||
|
||
ctx := context.Background() | ||
|
||
blockSubscriberCh := make(chan struct{}) | ||
tc := testcluster.StartTestCluster(t, 1, base.TestClusterArgs{ | ||
ServerArgs: base.TestServerArgs{ | ||
Knobs: base.TestingKnobs{ | ||
SpanConfig: &spanconfig.TestingKnobs{ | ||
KVSubscriberRangeFeedKnobs: &rangefeedcache.TestingKnobs{ | ||
PostRangeFeedStart: func() { <-blockSubscriberCh }, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}) | ||
|
||
defer tc.Stopper().Stop(ctx) | ||
ts := tc.Server(0) | ||
scKVSubscriber := ts.SpanConfigKVSubscriber().(spanconfig.KVSubscriber) | ||
require.True(t, scKVSubscriber.LastUpdated().IsEmpty()) | ||
|
||
store := tc.GetFirstStoreFromServer(t, 0) | ||
scratchKey := tc.ScratchRange(t) | ||
tc.SplitRangeOrFatal(t, scratchKey.Next()) | ||
|
||
var repl *kvserver.Replica | ||
testutils.SucceedsSoon(t, func() error { | ||
repl = store.LookupReplica(roachpb.RKey(scratchKey)) | ||
if repl == nil { | ||
return errors.New(`could not find replica`) | ||
} | ||
return nil | ||
}) | ||
|
||
{ | ||
trace, processErr, err := store.ManuallyEnqueue(ctx, "merge", repl, true /* skipShouldQueue */) | ||
require.NoError(t, err) | ||
require.NoError(t, processErr) | ||
require.NoError(t, testutils.MatchInOrder(trace.String(), `skipping merge: queue has been disabled`)) | ||
} | ||
|
||
close(blockSubscriberCh) | ||
testutils.SucceedsSoon(t, func() error { | ||
if scKVSubscriber.LastUpdated().IsEmpty() { | ||
return errors.New("expected non-empty update ts") | ||
} | ||
return nil | ||
}) | ||
|
||
{ | ||
trace, processErr, err := store.ManuallyEnqueue(ctx, "merge", repl, true /* skipShouldQueue */) | ||
require.NoError(t, err) | ||
require.NoError(t, processErr) | ||
require.Error(t, testutils.MatchInOrder(trace.String(), `skipping merge: queue has been disabled`)) | ||
} | ||
} |