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

executor: add retriver for tidb_hot_regions_history #27375

Merged
merged 36 commits into from
Nov 19, 2021

Conversation

IcePigZDB
Copy link
Contributor

@IcePigZDB IcePigZDB commented Aug 19, 2021

Signed-off-by: IcePigZDB icepigzdb@gmail.com

Problem Summary: Create a new table TIDB_HOT_REGIONS_HISTORY in the INFORMATION_SCHEMAT database to retrieve history hotspot information stored by PD periodically.

What problem does this PR solve?

Proposal: pingcap/tidb#27487
Associated Issue: #25281

Associated PRs in TiDB:
PRs splited from oversize PR #27224 in merge order :

  1. infoschema: add tidb_hot_regions_history virtual table #27373
  2. planner: add extractor for tidb_hot_regions_history #27374
  3. executor: add retriver for tidb_hot_regions_history  #27375 <- current one
  4. planner: add test for HotRegionsHistoryTableExtractor #27899
  5. executor: add test for hotRegionsHistoryRetriver #27900

Associated PR in PD:
PRs splited from old oversize one: tikv/pd/pull/3989

Check List

Tests

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

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

select * from information_schema.tidb_hot_regions_history where update_time>='2019-10-10 10:10:10' and update_time<'2019-10-11 10:10:10'

Signed-off-by: IcePigZDB <icepigzdb@gmail.com>
@ti-chi-bot
Copy link
Member

ti-chi-bot commented Aug 19, 2021

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • nolouch
  • rleungx

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 release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Aug 19, 2021
@github-actions github-actions bot added the sig/execution SIG execution label Aug 19, 2021
Signed-off-by: IcePigZDB <icepigzdb@gmail.com>
Signed-off-by: IcePigZDB <icepigzdb@gmail.com>
…e key

Signed-off-by: IcePigZDB <icepigzdb@gmail.com>
…heck

Signed-off-by: IcePigZDB <icepigzdb@gmail.com>
…x results order overlap

Signed-off-by: IcePigZDB <icepigzdb@gmail.com>
Signed-off-by: IcePigZDB <icepigzdb@gmail.com>
Signed-off-by: IcePigZDB <icepigzdb@gmail.com>
Signed-off-by: IcePigZDB <icepigzdb@gmail.com>
Signed-off-by: IcePigZDB <icepigzdb@gmail.com>
Signed-off-by: IcePigZDB <icepigzdb@gmail.com>
Signed-off-by: IcePigZDB <icepigzdb@gmail.com>
Signed-off-by: IcePigZDB <icepigzdb@gmail.com>
Signed-off-by: IcePigZDB <icepigzdb@gmail.com>
Signed-off-by: IcePigZDB <icepigzdb@gmail.com>
Signed-off-by: IcePigZDB <icepigzdb@gmail.com>
Signed-off-by: IcePigZDB <icepigzdb@gmail.com>
Co-authored-by: ShuNing <nolouch@gmail.com>
@ti-chi-bot ti-chi-bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 20, 2021
IcePigZDB and others added 2 commits October 20, 2021 08:35
@ti-chi-bot ti-chi-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 2, 2021
@ti-chi-bot ti-chi-bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 9, 2021
@nolouch
Copy link
Member

nolouch commented Nov 16, 2021

PTAL @rleungx

@JmPotato
Copy link
Member

/uncc JmPotato

@ti-chi-bot ti-chi-bot removed the request for review from JmPotato November 16, 2021 09:17
sctx.GetSessionVars().StmtCtx.AppendWarning(result.err)
}
if result.err != nil || len(result.messages.HistoryHotRegion) == 0 {
continue
Copy link
Member

Choose a reason for hiding this comment

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

move continue to line 886 and check len(result.messages.HistoryHotRegion) > 0?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

) ([]types.Datum, error) {
_, startKey, _ := codec.DecodeBytes(hisHotRegion.StartKey, []byte{})
_, endKey, _ := codec.DecodeBytes(hisHotRegion.EndKey, []byte{})
region := &tikv.KeyLocation{StartKey: startKey, EndKey: endKey}
Copy link
Member

Choose a reason for hiding this comment

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

Is there possible the old table is dropped?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, we have discussed this case, dropped tables' hot region will be ignore in current implement.

	_, startKey, _ := codec.DecodeBytes(hisHotRegion.StartKey, []byte{})
	_, endKey, _ := codec.DecodeBytes(hisHotRegion.EndKey, []byte{})
	region := &tikv.KeyLocation{StartKey: startKey, EndKey: endKey}
	hotRange, err := helper.NewRegionFrameRange(region)
	if err != nil {
		return nil, err
	}

	f := tikvHelper.FindTableIndexOfRegion(allSchemas, hotRange)
	// Ignore row without corresponding schema f.
	if f == nil {
		return nil, nil
	}

This case has been tested in memtable_reader_test.go/TestTiDBHotRegionsHistory line 1097-1099, code run as expected.

		//      table_id = 131, index_id = 1, index_value = 1, deleted schema
		{"2019-10-10 10:10:23", "UNKONW", "UNKONW", "131", "UNKONW", "1", "5", "5", "55555", "0", "1", "READ", "99", "99", "99", "99"},
		{"2019-10-10 10:10:24", "UNKONW", "UNKONW", "131", "UNKONW", "1", "6", "6", "66666", "0", "0", "WRITE", "99", "99", "99", "99"},

@@ -541,6 +541,24 @@ func (helper extractHelper) convertToTime(t int64) time.Time {
return time.Unix(0, t)
}

func (helper extractHelper) extractRoleBoolSliceFromUint64Slice(uint64Slice []uint64) []bool {
Copy link
Member

Choose a reason for hiding this comment

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

The function name is too long.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

change to convertToBoolSlice according to previous func convertToTime.

for _, k := range slice {
l = append(l, fmt.Sprintf(`%t`, k))
}
sort.Strings(l)
Copy link
Member

Choose a reason for hiding this comment

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

What is the purpose of sort?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In unnormal case, user may query is_leader in(0,1), sort can keep the order of result string.

Signed-off-by: IcePigZDB <icepigzdb@gmail.com>
@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Nov 18, 2021
@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 Nov 18, 2021
@Yisaer
Copy link
Contributor

Yisaer commented Nov 19, 2021

/merge

@ti-chi-bot
Copy link
Member

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

Commit hash: e4d113f

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Nov 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/execution SIG execution size/XXL Denotes a PR that changes 1000+ 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.

6 participants