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

storage: expose etcd's transaction as LowLevelTxn interface to kv.Base #9016

Merged
merged 13 commits into from
Feb 19, 2025

Conversation

MyonKeminta
Copy link
Contributor

@MyonKeminta MyonKeminta commented Jan 20, 2025

What problem does this PR solve?

Issue Number: Ref #8978
Split out from #8989

What is changed and how does it work?

Exposes etcd's transactoin API to kv.Base layer. The behavior is also simulated in `MemKV` and `LevelDBKV` to provide the same interface.

Check List

Tests

  • Unit test

Code changes

Side effects

  • Increased code complexity

Related changes

Release note

None.

…te the behavior in memkv and leveldb

Signed-off-by: MyonKeminta <[email protected]>
Copy link
Contributor

ti-chi-bot bot commented Jan 20, 2025

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@ti-chi-bot ti-chi-bot bot added release-note-none Denotes a PR that doesn't merit a release note. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. dco-signoff: yes Indicates the PR's author has signed the dco. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Jan 20, 2025
@MyonKeminta MyonKeminta marked this pull request as ready for review January 20, 2025 10:17
@ti-chi-bot ti-chi-bot bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jan 20, 2025
Signed-off-by: MyonKeminta <[email protected]>
Signed-off-by: MyonKeminta <[email protected]>
Copy link
Member

@JmPotato JmPotato left a comment

Choose a reason for hiding this comment

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

LGTM. Let's wait for #8919.

@JmPotato
Copy link
Member

/retest

Copy link

codecov bot commented Feb 12, 2025

Codecov Report

Attention: Patch coverage is 80.20833% with 19 lines in your changes missing coverage. Please review.

Project coverage is 76.24%. Comparing base (daa23f8) to head (b7f7d12).
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #9016      +/-   ##
==========================================
+ Coverage   76.20%   76.24%   +0.03%     
==========================================
  Files         468      468              
  Lines       71546    71642      +96     
==========================================
+ Hits        54522    54623     +101     
+ Misses      13619    13606      -13     
- Partials     3405     3413       +8     
Flag Coverage Δ
unittests 76.24% <80.20%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

@ti-chi-bot ti-chi-bot bot added needs-1-more-lgtm Indicates a PR needs 1 more LGTM. approved labels Feb 12, 2025
If(conditions ...LowLevelTxnCondition) LowLevelTxn
Then(ops ...LowLevelTxnOp) LowLevelTxn
Else(ops ...LowLevelTxnOp) LowLevelTxn
Commit(ctx context.Context) (LowLevelTxnResult, error)
Copy link
Member

Choose a reason for hiding this comment

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

Do we need ctx?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When I'm writing the interface, consitering that ectd needs calling RPC when committing a transaction, I added it, but later I found etcd's API doesn't accept the context in its methods.
I'll remove it.

Signed-off-by: MyonKeminta <[email protected]>
@@ -147,3 +155,132 @@ func (txn *levelDBTxn) commit() error {

return txn.kv.Write(txn.batch, nil)
}

type levelDBLowLevelTxnSimulator struct {
Copy link
Member

Choose a reason for hiding this comment

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

Why name it *Simulator?


succeeds := true
for _, condition := range t.condition {
value, err := t.kv.DB.Get([]byte(condition.Key), nil)
Copy link
Member

Choose a reason for hiding this comment

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

I think kv.DB.Get is not right.

}
}

if !condition.CheckOnValue(valueStr, exists) {
Copy link
Member

Choose a reason for hiding this comment

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

Shall we use Has?

@MyonKeminta
Copy link
Contributor Author

/hold

@ti-chi-bot ti-chi-bot bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Feb 13, 2025
// Put and delete operations of etcd's transaction won't return any previous data. Skip handling it.
resultItem = RawEtcdTxnResultItem{}
if put.PrevKv != nil {
key := strings.TrimPrefix(strings.TrimPrefix(string(put.PrevKv.Key), l.rootPath), "/")
Copy link
Member

Choose a reason for hiding this comment

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

Can we merge two trims?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was just keeping the same way to write it as the existing code.
By the way this code can be removed as etcd's transaction api doesn't return the previous kv for Put ops. I removed it and updated only the rangeResp branch.

}

// CheckOnValue checks whether the condition is satisfied on the given value.
func (c *RawEtcdTxnCondition) CheckOnValue(value string, exists bool) bool {
Copy link
Member

Choose a reason for hiding this comment

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

Where do we use it now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No usage now. Removing it.

// RawEtcdTxnResult represents the result of a RawEtcdTxn. The results of operations in `Then` or `Else` branches
// will be listed in `ResultItems` in the same order as the operations are added.
// For Put or Delete operations, its corresponding result is the previous value before writing.
type RawEtcdTxnResult struct {
Copy link
Member

@rleungx rleungx Feb 18, 2025

Choose a reason for hiding this comment

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

How about RawTxnResponse?

// * For Get operations, the result contains a key-value pair representing the get result. In case the key
// does not exist, its `KeyValuePairs` field will be empty.
// * For GetRange operations, the result is a list of key-value pairs containing key-value paris that are scanned.
ResultItems []RawEtcdTxnResultItem
Copy link
Member

Choose a reason for hiding this comment

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

How about Responses?

@@ -80,6 +80,11 @@ func (kv *LevelDBKV) Remove(key string) error {
return errors.WithStack(kv.Delete([]byte(key), nil))
}

// CreateRawEtcdTxn implements kv.Base interface.
func (*LevelDBKV) CreateRawEtcdTxn() RawEtcdTxn {
Copy link
Member

Choose a reason for hiding this comment

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

How about?

Suggested change
func (*LevelDBKV) CreateRawEtcdTxn() RawEtcdTxn {
func (*LevelDBKV) CreateRawTxn() RawEtcdTxn {

@ti-chi-bot ti-chi-bot bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Feb 18, 2025
@MyonKeminta
Copy link
Contributor Author

/retest

@MyonKeminta MyonKeminta requested a review from JmPotato February 18, 2025 09:36
@ti-chi-bot ti-chi-bot bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Feb 18, 2025
Copy link
Contributor

ti-chi-bot bot commented Feb 18, 2025

[LGTM Timeline notifier]

Timeline:

  • 2025-02-12 06:01:55.148072924 +0000 UTC m=+422757.544294986: ☑️ agreed by JmPotato.
  • 2025-02-18 09:36:47.457506008 +0000 UTC m=+954049.853728068: ☑️ agreed by rleungx.

Copy link
Contributor

ti-chi-bot bot commented Feb 18, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: JmPotato, rleungx

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

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@rleungx
Copy link
Member

rleungx commented Feb 19, 2025

/unhold

@ti-chi-bot ti-chi-bot bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Feb 19, 2025
@rleungx
Copy link
Member

rleungx commented Feb 19, 2025

/retest

1 similar comment
@MyonKeminta
Copy link
Contributor Author

/retest

@ti-chi-bot ti-chi-bot bot merged commit 9336139 into tikv:master Feb 19, 2025
25 checks passed
@MyonKeminta MyonKeminta deleted the m/low-level-txn-interface branch February 19, 2025 08:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved dco-signoff: yes Indicates the PR's author has signed the dco. lgtm 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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants