-
Notifications
You must be signed in to change notification settings - Fork 728
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
storage: expose etcd's transaction as LowLevelTxn interface to kv.Base #9016
Conversation
…te the behavior in memkv and leveldb Signed-off-by: MyonKeminta <[email protected]>
Skipping CI for Draft Pull Request. |
Signed-off-by: MyonKeminta <[email protected]>
Signed-off-by: MyonKeminta <[email protected]>
There was a problem hiding this 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.
/retest |
Codecov ReportAttention: Patch coverage is
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
Flags with carried forward coverage won't be shown. Click here to find out more. |
pkg/storage/kv/kv.go
Outdated
If(conditions ...LowLevelTxnCondition) LowLevelTxn | ||
Then(ops ...LowLevelTxnOp) LowLevelTxn | ||
Else(ops ...LowLevelTxnOp) LowLevelTxn | ||
Commit(ctx context.Context) (LowLevelTxnResult, error) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need ctx?
There was a problem hiding this comment.
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]>
pkg/storage/kv/levedb_kv.go
Outdated
@@ -147,3 +155,132 @@ func (txn *levelDBTxn) commit() error { | |||
|
|||
return txn.kv.Write(txn.batch, nil) | |||
} | |||
|
|||
type levelDBLowLevelTxnSimulator struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why name it *Simulator?
pkg/storage/kv/levedb_kv.go
Outdated
|
||
succeeds := true | ||
for _, condition := range t.condition { | ||
value, err := t.kv.DB.Get([]byte(condition.Key), nil) |
There was a problem hiding this comment.
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.
pkg/storage/kv/levedb_kv.go
Outdated
} | ||
} | ||
|
||
if !condition.CheckOnValue(valueStr, exists) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shall we use Has
?
/hold |
Signed-off-by: MyonKeminta <[email protected]>
Signed-off-by: MyonKeminta <[email protected]>
Signed-off-by: MyonKeminta <[email protected]>
Signed-off-by: MyonKeminta <[email protected]>
Signed-off-by: MyonKeminta <[email protected]>
pkg/storage/kv/etcd_kv.go
Outdated
// 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), "/") |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
pkg/storage/kv/kv.go
Outdated
} | ||
|
||
// CheckOnValue checks whether the condition is satisfied on the given value. | ||
func (c *RawEtcdTxnCondition) CheckOnValue(value string, exists bool) bool { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
pkg/storage/kv/kv.go
Outdated
// 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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about RawTxnResponse?
pkg/storage/kv/kv.go
Outdated
// * 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about Responses?
pkg/storage/kv/levedb_kv.go
Outdated
@@ -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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about?
func (*LevelDBKV) CreateRawEtcdTxn() RawEtcdTxn { | |
func (*LevelDBKV) CreateRawTxn() RawEtcdTxn { |
Signed-off-by: MyonKeminta <[email protected]>
Signed-off-by: MyonKeminta <[email protected]>
/retest |
[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 |
/unhold |
/retest |
1 similar comment
/retest |
What problem does this PR solve?
Issue Number: Ref #8978
Split out from #8989
What is changed and how does it work?
Check List
Tests
Code changes
Side effects
Related changes
Release note