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

Add Flush and BufferGet requests for pipelined DML #1218

Merged
merged 13 commits into from
Feb 6, 2024

Conversation

ekexium
Copy link
Contributor

@ekexium ekexium commented Jan 5, 2024

Ref tikv/tikv#16291
Don't merge it until corresponding work finishes.

@ekexium ekexium changed the title Add Flush and BufferGet requests for large transactions Add Flush and BufferGet requests for pipelined DML Jan 8, 2024
@ekexium ekexium force-pushed the large-txn branch 2 times, most recently from 83e2d9d to 84c879f Compare January 10, 2024 05:17
proto/kvrpcpb.proto Outdated Show resolved Hide resolved
@you06
Copy link
Contributor

you06 commented Jan 31, 2024

Need to rebase master, I cannot build the latest TiDB with this PR because some protocols are missing.

@ekexium ekexium marked this pull request as ready for review January 31, 2024 08:07
@ekexium ekexium requested a review from cfzjywxk January 31, 2024 08:08
Copy link
Contributor

@you06 you06 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

proto/kvrpcpb.proto Outdated Show resolved Hide resolved
message BufferBatchGetRequest {
Context context = 1;
repeated bytes keys = 2;
uint64 version = 3;
Copy link
Contributor

Choose a reason for hiding this comment

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

Shall we add a variable to control whether enable snapshot read after buffer read miss? This may save one RPC.

Copy link
Contributor

Choose a reason for hiding this comment

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

A similar question, if it's designed to support both buffer-read and snapshot read, or do we need another interface to implement "UnionStoreBatchGet" at tikv side?

Copy link
Contributor Author

@ekexium ekexium Jan 31, 2024

Choose a reason for hiding this comment

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

Shall we add a variable to control whether enable snapshot read after buffer read miss? This may save one RPC.

We can do it later when we are about to implement this. We don't have to finalize all details in one PR.

A similar question, if it's designed to support both buffer-read and snapshot read, or do we need another interface to implement "UnionStoreBatchGet" at tikv side?

BufferBatchGet only serves buffer read. Its semantics is "reading the content offloaded to TiKV in the membuffer"
Snapshot read does not change.
Something like UnionStoreBatchGet is not needed for now(before we implement the optimization to save one RPC), as unionstore.get is simply implemented as "buffer.get, if not found, try snapshot.get". This implementation does not have to change at all.
The only thing we need to change is how we do buffer read. Does that sound straightforward and reasonable?

Previous:
membuffer.get = memdb.get
snapshot.get = tikv.get
unionstore.get = membuffer.get +? snapshot.get = memdb.get +? tikv.get

Now:
membuffer.get = mutable_memdb.get +? immutable_memdb.get +? tikv.buffer_batch_get
snapshot.get = tikv.get
unionstore.get = membuffer.get +? snapshot.get = mutable_memdb.get +? immutable_memdb.get +? tikv.buffer_batch_get +? tikv.get

@cfzjywxk
Copy link
Contributor

cfzjywxk commented Jan 31, 2024

Another way for reading a transaction's own uncommitted data in tikv:

  • kv-client: For pipelined-dml read, adding a flag in the existing BatchGet request, it indicates whether the current read is membuf read in tikv or union store read in tikv.

  • tikv: reuse the same BatchGet interface.

    • storage: implement the buffer_batch_get and union_store_batch_get methods.

So we could avoid introducing the BufferGet interface and do union store get within one RPC request.

@ekexium
Copy link
Contributor Author

ekexium commented Jan 31, 2024

Another way for reading a transaction's own uncommitted data in tikv:

  • kv-client: For pipelined-dml read, adding a flag in the existing BatchGet request, it indicates whether the current read is membuf read in tikv or union store read in tikv.

  • tikv: reuse the same BatchGet interface.

    • storage: implement the buffer_batch_get and union_store_batch_get methods.

So we could avoid introducing the BufferGet interface and do union store get within one RPC request.

So the only difference is in the grpc level, whether to use 3 different RPCs for snapshot read, buffer read, and union read; or use one RPC for all of them and use flags to differentiate.

Seems a trade-off between interface simplicity and clarity. Imagine when we see a batch_get from logs or metrics, we would have no idea what it is reading.

@cfzjywxk
Copy link
Contributor

We essentially need to support one RPC to complete the membuf read + snapshot read, regardless of whether or not a separate KV interface is split out. This scalability needs to be reserved.
It doesn't seem to introduce too much protocol complexity to separately split out BufferBatchGetRequest, although it introduces a new interface. However, I don't think we need to introduce another UnionStoreBatchGetRequest interface.

@cfzjywxk cfzjywxk requested a review from MyonKeminta January 31, 2024 09:10
@cfzjywxk
Copy link
Contributor

@MyonKeminta PTAL

@MyonKeminta
Copy link
Contributor

It doesn't seem to introduce too much protocol complexity to separately split out BufferBatchGetRequest, although it introduces a new interface. However, I don't think we need to introduce another UnionStoreBatchGetRequest interface.

I agree with this. We can regard it as an RPC interface that supports reading with the buffer, including buffer reading only and mixed (union) reading.

But my problem is whether the word "buffer" is proper here...

@ekexium
Copy link
Contributor Author

ekexium commented Feb 5, 2024

@MyonKeminta any suggestions on names?

Copy link
Contributor

@MyonKeminta MyonKeminta left a comment

Choose a reason for hiding this comment

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

How about using the word "staged"?
..And maybe i'd better approve this PR for now as I don't have any better idea...

Copy link
Contributor

@cfzjywxk cfzjywxk left a comment

Choose a reason for hiding this comment

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

LGTM.

@ekexium ekexium merged commit 05a3758 into pingcap:master Feb 6, 2024
4 checks passed
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.

4 participants