-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
kv: merge batch get results to fix insert ignore in a transaction block #6215
Changes from 4 commits
b78268f
beb287c
c099a72
68b08e3
b8b3c4e
97978c6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -88,3 +88,31 @@ func BackOff(attempts uint) int { | |
time.Sleep(sleep) | ||
return int(sleep) | ||
} | ||
|
||
// BatchGetValues gets values in batch. | ||
// The values from buffer in transaction and the values from the storage node are merged together. | ||
func BatchGetValues(txn Transaction, keys []Key) (map[string][]byte, error) { | ||
bufferValues := make(map[string][]byte, len(keys)) | ||
shrinkKeys := make([]Key, 0, len(keys)) | ||
for _, key := range keys { | ||
val, err := txn.GetMemBuffer().Get(key) | ||
if IsErrNotFound(err) { | ||
shrinkKeys = append(shrinkKeys, key) | ||
continue | ||
} | ||
if err != nil { | ||
return nil, errors.Trace(err) | ||
} | ||
if len(val) != 0 { | ||
bufferValues[string(key)] = val | ||
} | ||
} | ||
storageValues, err := txn.GetSnapshot().BatchGet(shrinkKeys) | ||
if err != nil { | ||
return nil, errors.Trace(err) | ||
} | ||
for key, val := range bufferValues { | ||
storageValues[string(key)] = val | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to do There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ignore it. |
||
return storageValues, 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.
Using a keys slice and a values slice has a lower cost.