Skip to content

Commit

Permalink
engine: Add more test cases to test mvccResolveIntentHistory
Browse files Browse the repository at this point in the history
The previous change made mvccResolveIntentHistory more complex
in some subtle ways, such as the larger variety of cases where
they can expect to be called (such as around cleaning up intent
histories).

This change tests those cases and ensures that the resolution
code does the appropriate thing in all expected combinations of
those conditions.

Release note: None
  • Loading branch information
itsbilal committed Jan 8, 2020
1 parent 514d084 commit eb43678
Show file tree
Hide file tree
Showing 4 changed files with 437 additions and 16 deletions.
12 changes: 6 additions & 6 deletions pkg/storage/engine/mvcc.go
Original file line number Diff line number Diff line change
Expand Up @@ -2751,8 +2751,6 @@ func mvccResolveWriteIntent(
// testing.
inProgress := !intent.Status.IsFinalized() && meta.Txn.Epoch >= intent.Txn.Epoch
pushed := inProgress && hlc.Timestamp(meta.Timestamp).Less(intent.Txn.WriteTimestamp)
collapsedIntent := false
var rolledBackVal []byte
latestKey := MVCCKey{Key: intent.Key, Timestamp: hlc.Timestamp(meta.Timestamp)}

// Handle partial txn rollbacks. If the current txn sequence
Expand All @@ -2761,7 +2759,9 @@ func mvccResolveWriteIntent(
// If _all_ the writes get removed in this way, the intent
// "collapses" and should be considered empty (i.e. can be removed altogether).
// If only part of the intent history was rolled back, but the intent still
// remains, updatedIntent is set to true.
// remains, the rolledBackVal is set to a non-nil value.
collapsedIntent := false
var rolledBackVal []byte
if len(intent.IgnoredSeqNums) > 0 {
collapsedIntent, rolledBackVal, err = mvccMaybeRewriteIntentHistory(ctx, rw, intent.IgnoredSeqNums, meta, latestKey)
if err != nil {
Expand Down Expand Up @@ -2791,7 +2791,7 @@ func mvccResolveWriteIntent(

// Update or remove the metadata key.
var metaKeySize, metaValSize int64
if pushed || (rolledBackVal != nil && !commit) {
if !commit {
// Keep existing intent if we're updating it. We keep the
// existing metadata instead of using the supplied intent meta
// to avoid overwriting a newer epoch (see comments above). The
Expand Down Expand Up @@ -2939,7 +2939,7 @@ func mvccResolveWriteIntent(
// mvccMaybeRewriteIntentHistory rewrites the intent to reveal the latest
// stored value, ignoring all values from the history that have an
// ignored seqnum.
// The cleared return value, when true, indicates that
// The collapsed return value, when true, indicates that
// all the writes in the intent are ignored and the intent should
// not be considered to exist any more.
// The updatedVal, when non-nil, indicates that the intent was updated
Expand All @@ -2950,7 +2950,7 @@ func mvccMaybeRewriteIntentHistory(
ignoredSeqNums []enginepb.IgnoredSeqNumRange,
meta *enginepb.MVCCMetadata,
latestKey MVCCKey,
) (cleared bool, updatedVal []byte, err error) {
) (collapsed bool, updatedVal []byte, err error) {
if !enginepb.TxnSeqIsIgnored(meta.Txn.Sequence, ignoredSeqNums) {
// The latest write was not ignored. Nothing to do here. We'll
// proceed with the intent as usual.
Expand Down
Loading

0 comments on commit eb43678

Please sign in to comment.