-
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.
kvserver: prevent split at invalid tenant prefix keys
Closes #104796. Epic: None Release note (bug fix): prevents invalid splits that can crash (and prevent restarts) of nodes that hold a replica for the right-hand side.
- Loading branch information
1 parent
810d4f2
commit ef8d5da
Showing
3 changed files
with
53 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright 2023 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 kvserver_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/cockroachdb/cockroach/pkg/base" | ||
"github.com/cockroachdb/cockroach/pkg/keys" | ||
"github.com/cockroachdb/cockroach/pkg/testutils/testcluster" | ||
"github.com/cockroachdb/cockroach/pkg/util/leaktest" | ||
"github.com/cockroachdb/cockroach/pkg/util/log" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestSplitAtInvalidTenantPrefix(t *testing.T) { | ||
defer leaktest.AfterTest(t)() | ||
defer log.Scope(t).Close(t) | ||
|
||
// badKey is the tenant prefix followed by a "large" byte that indicates | ||
// that it should be followed by a separate uvarint encoded key (which is | ||
// not there). | ||
// | ||
// See: https://github.com/cockroachdb/cockroach/issues/104796 | ||
var badKey = append([]byte{'\xfe'}, '\xfd') | ||
_, _, err := keys.DecodeTenantPrefix(badKey) | ||
t.Log(err) | ||
require.Error(t, err) | ||
|
||
ctx := context.Background() | ||
|
||
tc := testcluster.StartTestCluster(t, 1, base.TestClusterArgs{ | ||
ReplicationMode: base.ReplicationManual, | ||
}) | ||
defer tc.Stopper().Stop(ctx) | ||
|
||
_, _, err = tc.SplitRange(badKey) | ||
require.Error(t, err) | ||
require.Contains(t, err.Error(), `checking for valid tenantID`) | ||
} |
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