Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

meta,structure: modify structure hash API to avoid conflict on auto table ID key #25221

Merged
merged 11 commits into from
Jun 10, 2021

Conversation

tiancaiamao
Copy link
Contributor

@tiancaiamao tiancaiamao commented Jun 7, 2021

What problem does this PR solve?

Issue Number: close #25197

Problem Summary:

Insert into different tables should not conflict on the table meta key, but it does!

GenAutoTableID() use the structure HInc API, that API is not scalable because the hash structure maintain a meta key to store the hash table size.

What is changed and how it works?

What's Changed:

Provide a IgnoreHashMeta option for the structure API.

How it Works:

If IgnoreHashMeta is called, the structure API will ignore the hash related things.
That means HLen API is not available any more with this option.

TiDB do not use HLen, so it's set to get rid of the meta key conflict.

Check List

Tests

  • Unit test
  • Manual test (add detailed scripts or steps below)

Release note

  • Fix table meta key conflict for concurrent connections visiting different tables. Downgrade after this change might be problematic.

@ti-chi-bot ti-chi-bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Jun 7, 2021
@@ -145,6 +156,11 @@ func (t *TxStructure) updateHash(key []byte, field []byte, fn func(oldValue []by

// HLen gets the number of fields in a hash.
func (t *TxStructure) HLen(key []byte) (int64, error) {
if t.ignoreHashMeta {
Copy link
Contributor

Choose a reason for hiding this comment

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

If TiDB doesn't use HLen, how about remove all logic about it?

Copy link
Contributor

Choose a reason for hiding this comment

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

I worry that someone could call HLen in future.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

HLen API is reasonable, you can find the structure package provides API similar to Redis, and Redis also has HLen.
This package design is general, it can be used by outside projects.
I think it is better to provide an option instead of limit its ability to TiDB only.

Copy link
Contributor Author

@tiancaiamao tiancaiamao Jun 7, 2021

Choose a reason for hiding this comment

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

Without this PR, it means whether you use HLen or not, you pay for the cost.
With this PR, it means you can choose to pay for exactly what you want.
If you wipe out HLen, it means this functionality is missing, you don't have choice.

I prefer providing flexibility to users, and let them do their choices.

@hicqu
Copy link
Contributor

hicqu commented Jun 7, 2021

Rest LGTM. Thank you very much! I can continue my test based on it.

@github-actions github-actions bot added the sig/sql-infra SIG: SQL Infra label Jun 7, 2021
@ti-chi-bot
Copy link
Member

@hicqu: Thanks for your review. The bot only counts approvals from reviewers and higher roles in list, but you're still welcome to leave your comments.

In response to this:

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository.

@tiancaiamao tiancaiamao requested review from djshow832 and AilinKid June 9, 2021 09:09
Copy link
Contributor

@AilinKid AilinKid left a comment

Choose a reason for hiding this comment

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

LGTM

@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Jun 9, 2021
@@ -127,6 +134,10 @@ func (t *TxStructure) updateHash(key []byte, field []byte, fn func(oldValue []by
return errors.Trace(err)
}

if t.ignoreHashMeta {
Copy link
Contributor

Choose a reason for hiding this comment

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

When TiDB downgrades to an older version that reads and writes hash meta, but now the hash meta is all wrong, what will happen?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It doesn't matter, even in the downgrade case the data is wrong, old TiDB never use those data.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think so. For example, HDel checks meta hash, and if meta.IsEmpty(), it will report an error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So we can highlight the downgrade compatibility? there are many new feature, if TiDB upgrade and use the new feature, then downgrade, there will be a problem. Any suggestion?

@disksing
Copy link
Contributor

disksing commented Jun 9, 2021

Why not remove HLen directly? Do meta have users other than TiDB?

@tiancaiamao
Copy link
Contributor Author

Since so many of you dislike the HLen API, I remove it. @hicqu @disksing

PTAL @AilinKid @djshow832

@ti-chi-bot ti-chi-bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jun 10, 2021
Copy link
Contributor

@xhebox xhebox left a comment

Choose a reason for hiding this comment

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

Rest LGTM

structure/hash.go Outdated Show resolved Hide resolved
structure/structure.go Outdated Show resolved Hide resolved
@ti-chi-bot
Copy link
Member

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • AilinKid
  • xhebox

To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

The full list of commands accepted by this bot can be found here.

Reviewer can indicate their review by submitting an approval review.
Reviewer can cancel approval by submitting a request changes review.

@ti-chi-bot ti-chi-bot added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Jun 10, 2021
@xhebox
Copy link
Contributor

xhebox commented Jun 10, 2021

/merge

@ti-chi-bot
Copy link
Member

This pull request has been accepted and is ready to merge.

Commit hash: bc88557

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Jun 10, 2021
@tiancaiamao
Copy link
Contributor Author

/run-integration-common-test

@ti-chi-bot ti-chi-bot merged commit 537d8de into pingcap:master Jun 10, 2021
@tiancaiamao tiancaiamao deleted the meta-key branch June 18, 2021 11:59
@sticnarf
Copy link
Contributor

sticnarf commented Jul 26, 2021

@tiancaiamao Need this PR be picked to release branches?

Ah, I find this is a breaking change so it can be hard to backport...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sig/sql-infra SIG: SQL Infra size/L Denotes a PR that changes 100-499 lines, ignoring generated files. status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

allocHandleIDs conflicts very heavy when there are lots of tables in one database
8 participants