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

dml : dml read operation for cache table #29184

Merged
merged 18 commits into from
Nov 4, 2021

Conversation

JayLZhou
Copy link
Contributor

What problem does this PR solve?

Issue Number:

Problem Summary:

This is a subtask for #25293

What is changed and how it works?

This is a cache table with no read lock protocol to determine the version
So the read condition function that should be judged by ts. It returns true directly here.
About the judgment of the read lock, I will add it after the completion of this pr #29151

The time to read data from the original table is critical

When a cache table is read for the first time, we will return directly to failure. The backend go coroutine will update the lock information (of course, we did not implement this pr) and then read the data from the original table. So the second read will read the data from the cache
Like the temporary table, we use membuffer to store the data of the cache table

Check List

Tests

  • Unit test

Release note

None

@ti-chi-bot
Copy link
Member

ti-chi-bot commented Oct 27, 2021

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • lcwangchao
  • tiancaiamao

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 the release-note-none Denotes a PR that doesn't merit a release note. label Oct 27, 2021
@JayLZhou JayLZhou marked this pull request as draft October 27, 2021 15:54
@ti-chi-bot ti-chi-bot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Oct 27, 2021
table/tables/cache.go Outdated Show resolved Hide resolved
if err != nil {
return err
}
buffTxn, err := ctx.GetStore().BeginWithOption(tikv.DefaultStartTSOption().SetStartTS(0))
Copy link
Contributor

Choose a reason for hiding this comment

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

The way to get a MemBuffer instance if tricky.
Add some comments here.

executor/table_reader.go Outdated Show resolved Hide resolved
@ti-chi-bot ti-chi-bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Oct 29, 2021
@tiancaiamao tiancaiamao marked this pull request as ready for review October 29, 2021 14:11
@ti-chi-bot ti-chi-bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Oct 29, 2021
@JayLZhou
Copy link
Contributor Author

./rebuild

@JayLZhou
Copy link
Contributor Author

@djshow832 @tisonkun PTAL thks

@JayLZhou
Copy link
Contributor Author

/cc @tiancaiamao @djshow832

Copy link
Contributor

@tiancaiamao tiancaiamao left a comment

Choose a reason for hiding this comment

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

Despite some minor problems, this mostly LGTM

if cacheInfo.IsReadCacheTable {
tbl, ok := domain.GetDomain(ctx).InfoSchema().TableByID(cacheInfo.TableID)
if !ok {
return nil, errors.Trace(infoschema.ErrTableNotExists)
Copy link
Contributor

Choose a reason for hiding this comment

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

infoschema.ErrTableNotExists.GenStackByArgs() and provide the table name?
Grep the ErrTableNotExists to see how it's used.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sorry. provide the table name and the db name is okay

executor/mem_reader.go Outdated Show resolved Hide resolved
if !ok {
return nil, errors.Trace(infoschema.ErrTableNotExists)
}
cacheIter, err := tbl.(table.CachedTable).GetMemCache().Iter(rg.StartKey, rg.EndKey)
Copy link
Contributor

Choose a reason for hiding this comment

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

rg.StartKey, rg.EndKey is unnecessary?
The actual range should be [-int64, +int64) because the tbl.(table.CachedTable).GetMemCache() will not contain data from other tables.

executor/table_reader.go Outdated Show resolved Hide resolved
@@ -88,7 +88,10 @@ type StatementContext struct {
MaybeOverOptimized4PlanCache bool
IgnoreExplainIDSuffix bool
IsStaleness bool

CacheTableInfo struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

What happen if "select * from t1 join t2 ..." where t1 and t2 are both cached table?

table/table.go Show resolved Hide resolved
@JayLZhou
Copy link
Contributor Author

JayLZhou commented Nov 2, 2021

/cc @lcwangchao

@JayLZhou
Copy link
Contributor Author

JayLZhou commented Nov 3, 2021

/run-check_dev_2

@@ -173,6 +172,8 @@ type StatementContext struct {
// Map to store all CTE storages of current SQL.
// Will clean up at the end of the execution.
CTEStorageMap interface{}
// cachedTables is used to store cache table id when it satisfies the cache read condition
cachedTables map[int64]bool
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe a slice is better here?

cachedTables []struct{
    id int64
    used bool
}

There won't be much cached table here, so the performance of slice should be good enough.
And this is in the performance critical path, reuse slice to avoid allocation is much easier, just cachedTables = cachedTables[: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.

okay

@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Nov 3, 2021
@ti-chi-bot
Copy link
Member

@jayl-zxl: /merge is only allowed for the committers, you can assign this pull request to the committer in list by filling /assign @committer in the comment to help merge this pull request.

In response to this:

/merge

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.

table/tables/cache.go Outdated Show resolved Hide resolved
table/table.go Outdated Show resolved Hide resolved
table/table.go Outdated Show resolved Hide resolved
sessionctx/stmtctx/stmtctx.go Outdated Show resolved Hide resolved
table/tables/cache.go Outdated Show resolved Hide resolved
}

func (c *cachedTable) loadDataFromOriginalTable(ctx sessionctx.Context) error {
var mu sync.RWMutex
Copy link
Collaborator

Choose a reason for hiding this comment

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

You should move this variable ti cachedTable

Copy link
Collaborator

Choose a reason for hiding this comment

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

Another question is that you should not lock entire function. Just locking setter for memebuffer is enough.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

okay understand

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sorry my mistake

@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 4, 2021
@lcwangchao
Copy link
Collaborator

/merge

@ti-chi-bot
Copy link
Member

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

Commit hash: 6779d40

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Nov 4, 2021
@ti-chi-bot ti-chi-bot merged commit 9bbc7ad into pingcap:master Nov 4, 2021
@tiancaiamao tiancaiamao linked an issue Nov 4, 2021 that may be closed by this pull request
@tiancaiamao
Copy link
Contributor

Close #29546

@JayLZhou JayLZhou deleted the dml_read_cache_table branch November 8, 2021 11:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-note-none Denotes a PR that doesn't merit a release note. size/XL Denotes a PR that changes 500-999 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.

Support read from a cached table
4 participants