cockroachdb / cockroach

CockroachDB — the cloud native, distributed SQL database designed for high availability, effortless scale, and control over data placement.
https://www.cockroachlabs.com
Other
30.21k stars 3.82k forks source link

multitenant: SHOW RANGES leaks adjacent tenant ID #94377

Open ecwall opened 1 year ago

ecwall commented 1 year ago

Only the ID of the next tenant is displayed, not table/index IDs or primary keys.

In a cluster with multiple tenants, the output of SHOW RANGES for one tenant will display the next tenant's ID

        tc := testCase{
        system: tenantExpected{
            result: [][]string{
                {"<before:/Table/104/1/1>", "…/1"},
                {"…/1", "<after:/Tenant/10>"},
            },
        },
        secondaryNoCapability: tenantExpected{
            result: [][]string{
                {"<before:/Tenant/10/Table/104/1/1>", "…/104/2/1"},
                {"…/104/2/1", "<after:/Tenant/11>"},
            },
        },
        secondaryCapability: tenantExpected{
            result: [][]string{
                {"<before:/Tenant/11/Table/104/1/1>", "…/104/2/1"},
                {"…/104/2/1", "<after:/Max"},
            },
        },
    }

https://github.com/cockroachdb/cockroach/pull/94314/files#diff-f7f3f42a43ce63bb6a1479e91b24673827957dab6f52d4a018d50c47e1e56a35R547

Cluster has tenants 1, 10, 11. system is tenant 1, but sees this span end key <after:/Tenant/10> which is tenant 10's span's start key. secondaryNoCapability is tenant 10, but sees this span end key <after:/Tenant/11> which is tenant 10's span's start key.

Jira issue: CRDB-22863

Epic CRDB-26091

knz commented 1 year ago

Slack thread: https://cockroachlabs.slack.com/archives/C0KB9Q03D/p1675795955408409

TLDR: we are not going to change the low-level split points, and the logical exclusive end key for tenant 10 will continue to be the first key for tenant 11, or possibly the start key for one of the tenants afterwards.

However, we will want to update the display of these keys (really, any key beyond the current tenant's keyspace) in crdb_internal.ranges{,no_lease} and the output of SHOW RANGES, to translate /Tenant/<NextID> to /Tenant/<curID/Max during pretty-printing.