Skip to content

Commit

Permalink
kvserver: add AdminSplit and AdminScatter to secondary tenants API
Browse files Browse the repository at this point in the history
This adds support for AdminSplit and AdminScatter for secondary tenants.
This API allows indicating to KV that more data will be ingested, and
so the range should be split and re-distributed across the cluster.
This API will not be exposed through SQL, and in the future we might change
it to give KV more control over whether and how to deal with expected ingest
load. More discussion can be found in the github issue: #74389
 and Epic: https://cockroachlabs.atlassian.net/browse/CRDB-10720

Release note: None
  • Loading branch information
shralex committed Jan 18, 2022
1 parent ca44523 commit 22f5264
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 12 deletions.
4 changes: 3 additions & 1 deletion pkg/rpc/auth_tenant.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,14 @@ var reqMethodAllowlist = [...]bool{
roachpb.Scan: true,
roachpb.ReverseScan: true,
roachpb.EndTxn: true,
roachpb.AdminSplit: true,
roachpb.HeartbeatTxn: true,
roachpb.QueryTxn: true,
roachpb.QueryIntent: true,
roachpb.InitPut: true,
roachpb.AddSSTable: true,
roachpb.Export: true,
roachpb.AdminScatter: true,
roachpb.AddSSTable: true,
roachpb.Refresh: true,
roachpb.RefreshRange: true,
}
Expand Down
96 changes: 85 additions & 11 deletions pkg/rpc/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,21 @@ func TestTenantAuthRequest(t *testing.T) {
h := roachpb.RequestHeaderFromSpan(s)
return &roachpb.ScanRequest{RequestHeader: h}
}
makeAdminReq := func(key string) roachpb.Request {
makeDisallowedAdminReq := func(key string) roachpb.Request {
s := makeSpan(key)
h := roachpb.RequestHeader{Key: s.Key}
return &roachpb.AdminUnsplitRequest{RequestHeader: h}
}
makeAdminSplitReq := func(key string) roachpb.Request {
s := makeSpan(key)
h := roachpb.RequestHeaderFromSpan(s)
return &roachpb.AdminSplitRequest{RequestHeader: h, SplitKey: s.Key}
}
makeAdminScatterReq := func(key string) roachpb.Request {
s := makeSpan(key)
h := roachpb.RequestHeaderFromSpan(s)
return &roachpb.AdminScatterRequest{RequestHeader: h}
}
makeReqs := func(reqs ...roachpb.Request) []roachpb.RequestUnion {
ru := make([]roachpb.RequestUnion, len(reqs))
for i, r := range reqs {
Expand Down Expand Up @@ -249,35 +259,99 @@ func TestTenantAuthRequest(t *testing.T) {
},
{
req: &roachpb.BatchRequest{Requests: makeReqs(
makeAdminReq("a"),
makeDisallowedAdminReq("a"),
)},
expErr: `request \[1 AdmUnsplit\] not permitted`,
},
{
req: &roachpb.BatchRequest{Requests: makeReqs(
makeDisallowedAdminReq(prefix(10, "a")),
)},
expErr: `request \[1 AdmSplit\] not permitted`,
expErr: `request \[1 AdmUnsplit\] not permitted`,
},
{
req: &roachpb.BatchRequest{Requests: makeReqs(
makeAdminReq(prefix(10, "a")),
makeDisallowedAdminReq(prefix(50, "a")),
)},
expErr: `request \[1 AdmSplit\] not permitted`,
expErr: `request \[1 AdmUnsplit\] not permitted`,
},
{
req: &roachpb.BatchRequest{Requests: makeReqs(
makeAdminReq(prefix(50, "a")),
makeDisallowedAdminReq(prefix(10, "a")),
makeReq(prefix(10, "a"), prefix(10, "b")),
)},
expErr: `request \[1 AdmSplit\] not permitted`,
expErr: `request \[1 Scan, 1 AdmUnsplit\] not permitted`,
},
{
req: &roachpb.BatchRequest{Requests: makeReqs(
makeAdminReq(prefix(10, "a")),
makeReq(prefix(10, "a"), prefix(10, "b")),
makeDisallowedAdminReq(prefix(10, "a")),
)},
expErr: `request \[1 Scan, 1 AdmUnsplit\] not permitted`,
},
{
req: &roachpb.BatchRequest{Requests: makeReqs(
makeAdminSplitReq("a"),
)},
expErr: `request \[1 Scan, 1 AdmSplit\] not permitted`,
expErr: `requested key span a{-\\x00} not fully contained in tenant keyspace /Tenant/1{0-1}`,
},
{
req: &roachpb.BatchRequest{Requests: makeReqs(
makeAdminSplitReq(prefix(10, "a")),
)},
expErr: noError,
},
{
req: &roachpb.BatchRequest{Requests: makeReqs(
makeAdminSplitReq(prefix(50, "a")),
)},
expErr: `requested key span /Tenant/50"a{"-\\x00"} not fully contained in tenant keyspace /Tenant/1{0-1}`,
},
{
req: &roachpb.BatchRequest{Requests: makeReqs(
makeAdminSplitReq(prefix(10, "a")),
makeReq(prefix(10, "a"), prefix(10, "b")),
makeAdminReq(prefix(10, "a")),
)},
expErr: `request \[1 Scan, 1 AdmSplit\] not permitted`,
expErr: noError,
},
{
req: &roachpb.BatchRequest{Requests: makeReqs(
makeReq(prefix(10, "a"), prefix(10, "b")),
makeAdminSplitReq(prefix(10, "a")),
)},
expErr: noError,
},
{
req: &roachpb.BatchRequest{Requests: makeReqs(
makeAdminScatterReq("a"),
)},
expErr: `requested key span a{-\\x00} not fully contained in tenant keyspace /Tenant/1{0-1}`,
},
{
req: &roachpb.BatchRequest{Requests: makeReqs(
makeAdminScatterReq(prefix(10, "a")),
)},
expErr: noError,
},
{
req: &roachpb.BatchRequest{Requests: makeReqs(
makeAdminScatterReq(prefix(50, "a")),
)},
expErr: `requested key span /Tenant/50"a{"-\\x00"} not fully contained in tenant keyspace /Tenant/1{0-1}`,
},
{
req: &roachpb.BatchRequest{Requests: makeReqs(
makeAdminScatterReq(prefix(10, "a")),
makeReq(prefix(10, "a"), prefix(10, "b")),
)},
expErr: noError,
},
{
req: &roachpb.BatchRequest{Requests: makeReqs(
makeReq(prefix(10, "a"), prefix(10, "b")),
makeAdminScatterReq(prefix(10, "a")),
)},
expErr: noError,
},
{
req: &roachpb.BatchRequest{Requests: makeReqs(
Expand Down

0 comments on commit 22f5264

Please sign in to comment.