Skip to content

multitenant: retain range splits after TRUNCATE for secondary tenants#93325

Merged
craig[bot] merged 1 commit intocockroachdb:masterfrom
ecwall:multitenant_retain_splits_after_truncate
Dec 14, 2022
Merged

multitenant: retain range splits after TRUNCATE for secondary tenants#93325
craig[bot] merged 1 commit intocockroachdb:masterfrom
ecwall:multitenant_retain_splits_after_truncate

Conversation

@ecwall
Copy link
Copy Markdown
Contributor

@ecwall ecwall commented Dec 9, 2022

Fixes #69499
Fixes #82944

Existing split points are preserved after a TRUNCATE statement is executed by a secondary tenant.

Release note: None

@ecwall ecwall requested review from arulajmani, knz and rafiss December 9, 2022 15:48
@ecwall ecwall requested review from a team as code owners December 9, 2022 15:48
@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

Copy link
Copy Markdown
Collaborator

@arulajmani arulajmani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @ecwall, @knz, and @rafiss)


pkg/sql/truncate.go line 409 at r2 (raw file):

	}

	nNodes := execCfg.NodeDescs.GetNodeDescriptorCount()

As you've correctly pointed out, this runs into #93348. Interestingly, what you're replacing here, also wasn't great -- the kv_node_status table doesn't actually account for node liveness. So, if a node was (say) decommissioned, we might still be using it in this calculation as long as its descriptor's TTL in gossip hadn't expired.

We should instead have been using the kv_node_liveness table to begin with. Which brings about a couple of questions -- do we envision making this table available to tenants? If we do, should we build this PR on top of that?

@knz do you have thoughts about this? Or are we happy with this general approach for now?

Copy link
Copy Markdown
Contributor

@knz knz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @arulajmani and @rafiss)


pkg/sql/truncate.go line 409 at r2 (raw file):

Previously, arulajmani (Arul Ajmani) wrote…

As you've correctly pointed out, this runs into #93348. Interestingly, what you're replacing here, also wasn't great -- the kv_node_status table doesn't actually account for node liveness. So, if a node was (say) decommissioned, we might still be using it in this calculation as long as its descriptor's TTL in gossip hadn't expired.

We should instead have been using the kv_node_liveness table to begin with. Which brings about a couple of questions -- do we envision making this table available to tenants? If we do, should we build this PR on top of that?

@knz do you have thoughts about this? Or are we happy with this general approach for now?

The SQL layer has no business inspecting nodes and the number of nodes to do this computation.

There should be a new KV endpoint that does this:

  1. enumerate the split points within the table/index key span
  2. return the list of current split points to the SQL layer
  3. also returns alongside the split points:
    • a recommended number of splits (nSplits)
    • a recommended expiration time (computed off SplitByLoadMergeDelay)

The only remaining code in SQL should be to generate new split points (based on the KV returned details) and issue the AdminSplit/Scatter commands.

Fixes #69499
Fixes #82944

Existing split points are preserved after a TRUNCATE statement is executed
by a secondary tenant.

Release note: None
Copy link
Copy Markdown
Contributor Author

@ecwall ecwall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @arulajmani and @rafiss)


pkg/sql/truncate.go line 409 at r2 (raw file):

Previously, knz (Raphael 'kena' Poss) wrote…

The SQL layer has no business inspecting nodes and the number of nodes to do this computation.

There should be a new KV endpoint that does this:

  1. enumerate the split points within the table/index key span
  2. return the list of current split points to the SQL layer
  3. also returns alongside the split points:
    • a recommended number of splits (nSplits)
    • a recommended expiration time (computed off SplitByLoadMergeDelay)

The only remaining code in SQL should be to generate new split points (based on the KV returned details) and issue the AdminSplit/Scatter commands.

I created #93549 and linked to it in a TODO.

@ecwall ecwall requested a review from knz December 13, 2022 21:00
Copy link
Copy Markdown
Contributor

@knz knz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 5 of 7 files at r1, 3 of 3 files at r2, 2 of 2 files at r3, all commit messages.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @arulajmani and @rafiss)

@ecwall
Copy link
Copy Markdown
Contributor Author

ecwall commented Dec 14, 2022

bors r=knz

@craig craig bot merged commit a30fb14 into cockroachdb:master Dec 14, 2022
@craig
Copy link
Copy Markdown
Contributor

craig bot commented Dec 14, 2022

Build succeeded:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sql: TRUNCATE unable to preserve split point when run from a tenant sql: split new indexes in TRUNCATE in new secondary tenants

4 participants