Skip to content

Commit

Permalink
Bug fixes related to txn nil callbacks and badgerMove key.
Browse files Browse the repository at this point in the history
  • Loading branch information
manishrjain committed Jun 13, 2018
1 parent cdf9ffb commit 3340933
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
4 changes: 3 additions & 1 deletion iterator.go
Expand Up @@ -167,7 +167,9 @@ func (item *Item) yieldItemValue() ([]byte, func(), error) {
// The value pointer is pointing to a deleted value log. Look for the
// move key and read that instead.
runCallback(cb)
key = append(badgerMove, y.KeyWithTs(item.Key(), item.Version())...)
// Do not put badgerMove on the left in append. It seems to cause some sort of manipulation.
key = append([]byte{}, badgerMove...)
key = append(key, y.KeyWithTs(item.Key(), item.Version())...)
// Note that we can't set item.key to move key, because that would
// change the key user sees before and after this call. Also, this move
// logic is internal logic and should not impact the external behavior
Expand Down
2 changes: 1 addition & 1 deletion transaction.go
Expand Up @@ -411,7 +411,7 @@ func (txn *Txn) runCallbacks() {
for _, cb := range txn.callbacks {
cb()
}
txn.callbacks = nil
txn.callbacks = txn.callbacks[:0]
}

// Discard discards a created transaction. This method is very important and must be called. Commit
Expand Down
3 changes: 2 additions & 1 deletion value.go
Expand Up @@ -387,7 +387,8 @@ func (vlog *valueLog) rewrite(f *logFile, tr trace.Trace) error {
if bytes.HasPrefix(e.Key, badgerMove) {
ne.Key = append([]byte{}, e.Key...)
} else {
ne.Key = append(badgerMove, e.Key...)
ne.Key = append([]byte{}, badgerMove...)
ne.Key = append(ne.Key, e.Key...)

This comment has been minimized.

Copy link
@cloudaice

cloudaice Jun 25, 2018

Contributor
ne.Key = make([]byte, len(badgerMove) + len(e.Key))
n := copy(ne.Key, badgerMove)
copy(ne.Key[n:], e.Key)

More fast and reduce "alloc objects"

This comment has been minimized.

Copy link
@manishrjain

manishrjain Jun 25, 2018

Author Contributor

Can you send a PR? For this and also for above append?

}

ne.Value = append([]byte{}, e.Value...)
Expand Down

1 comment on commit 3340933

@cloudaice
Copy link
Contributor

Choose a reason for hiding this comment

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

Alloc enough space is better than multi append

Please sign in to comment.