Skip to content

Commit

Permalink
Merge #32541
Browse files Browse the repository at this point in the history
32541: engine: fix a comment r=andreimatei a=andreimatei

A misleading comment was suggesting that an MVCCMetadata is adjusted
when an intent is resolved. In fact, it is deleted.

Release note: None

Co-authored-by: Andrei Matei <[email protected]>
  • Loading branch information
craig[bot] and andreimatei committed Nov 26, 2018
2 parents c767737 + fe28581 commit a7e13e8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
2 changes: 2 additions & 0 deletions pkg/storage/engine/enginepb/mvcc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pkg/storage/engine/enginepb/mvcc.proto
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import "util/hlc/legacy_timestamp.proto";
import "gogoproto/gogo.proto";

// MVCCMetadata holds MVCC metadata for a key. Used by storage/engine/mvcc.go.
// An MVCCMetadata is stored for a versioned key while there is an intent on
// that key.
message MVCCMetadata {
option (gogoproto.populate) = true;

Expand Down
23 changes: 10 additions & 13 deletions pkg/storage/engine/mvcc.go
Original file line number Diff line number Diff line change
Expand Up @@ -2145,27 +2145,24 @@ func mvccResolveWriteIntent(
return true, nil
}

// This method shouldn't be called in this instance, but there's
// nothing to do if meta's epoch is greater than or equal txn's
// epoch and the state is still PENDING.
if intent.Status == roachpb.PENDING && meta.Txn.Epoch >= intent.Txn.Epoch {
return false, nil
}

// Otherwise, we're deleting the intent. We must find the next
// versioned value and reset the metadata's latest timestamp. If
// there are no other versioned values, we delete the metadata
// key.
// Otherwise, we're deleting the intent, which includes deleting the
// MVCCMetadata.
//
// Note that the somewhat unintuitive case of an ABORT with
// intent.Txn.Epoch < meta.Txn.Epoch is possible:
// Note that we have to support a somewhat unintuitive case - an ABORT with
// intent.Txn.Epoch < meta.Txn.Epoch:
// - writer1 writes key0 at epoch 0
// - writer2 with higher priority encounters intent at key0 (epoch 0)
// - writer1 restarts, now at epoch one (txn record not updated)
// - writer1 writes key0 at epoch 1
// - writer2 dispatches ResolveIntent to key0 (with epoch 0)
// - ResolveIntent with epoch 0 aborts intent from epoch 1.

// There's nothing to do if meta's epoch is greater than or equal txn's epoch
// and the state is still PENDING.
if intent.Status == roachpb.PENDING && meta.Txn.Epoch >= intent.Txn.Epoch {
return false, nil
}

// First clear the intent value.
latestKey := MVCCKey{Key: intent.Key, Timestamp: hlc.Timestamp(meta.Timestamp)}
if err := engine.Clear(latestKey); err != nil {
Expand Down

0 comments on commit a7e13e8

Please sign in to comment.