Skip to content

Commit

Permalink
Merge #33001
Browse files Browse the repository at this point in the history
33001: storage: allow transactions to run at a lower sequence r=ridwanmsharif a=ridwanmsharif

Continuing off #32688, final part of #5861 (comment).

Adds support to have transactions run at a lower sequence
at a given key. It asserts the value it computes with the
value written for the sequence in the intent history instead
or returning a retry-able error.

Release note: None

Co-authored-by: Ridwan Sharif <[email protected]>
  • Loading branch information
craig[bot] and Ridwan Sharif committed Dec 12, 2018
2 parents b1424c3 + e2459a2 commit c05c516
Show file tree
Hide file tree
Showing 12 changed files with 350 additions and 263 deletions.
43 changes: 6 additions & 37 deletions c-deps/libroach/protos/storage/engine/enginepb/mvcc3.pb.cc

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

21 changes: 0 additions & 21 deletions c-deps/libroach/protos/storage/engine/enginepb/mvcc3.pb.h

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

5 changes: 0 additions & 5 deletions pkg/roachpb/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,6 @@ func (ba *BatchRequest) IsTransactionWrite() bool {
return ba.hasFlag(isTxnWrite)
}

// IsRange returns true iff the BatchRequest contains range-based requests.
func (ba *BatchRequest) IsRange() bool {
return ba.hasFlag(isRange)
}

// IsUnsplittable returns true iff the BatchRequest an un-splittable request.
func (ba *BatchRequest) IsUnsplittable() bool {
return ba.hasFlag(isUnsplittable)
Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/below_raft_protos_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ var belowRaftGoldenProtos = map[reflect.Type]fixture{
return m
},
emptySum: 7551962144604783939,
populatedSum: 10215960487899724343,
populatedSum: 17791546305376889937,
},
reflect.TypeOf(&enginepb.RangeAppliedState{}): {
populatedConstructor: func(r *rand.Rand) protoutil.Message {
Expand Down
8 changes: 4 additions & 4 deletions pkg/storage/client_split_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -674,8 +674,8 @@ func TestStoreRangeSplitIdempotency(t *testing.T) {
_, pErr := client.SendWrappedWith(context.Background(), store.TestSender(), roachpb.Header{
Txn: &lTxn,
}, lIncArgs)
if _, ok := pErr.GetDetail().(*roachpb.TransactionRetryError); !ok {
t.Fatalf("unexpected idempotency failure: %v", pErr)
if pErr != nil {
t.Fatal(pErr)
}

// Send out the same increment copied from above (same txn/sequence), but
Expand All @@ -684,8 +684,8 @@ func TestStoreRangeSplitIdempotency(t *testing.T) {
RangeID: newRng.RangeID,
Txn: &rTxn,
}, rIncArgs)
if _, ok := pErr.GetDetail().(*roachpb.TransactionRetryError); !ok {
t.Fatalf("unexpected idempotency failure: %v", pErr)
if pErr != nil {
t.Fatal(pErr)
}

// Compare stats of split ranges to ensure they are non zero and
Expand Down
26 changes: 26 additions & 0 deletions pkg/storage/engine/enginepb/mvcc.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

package enginepb

import "sort"

// Short returns a prefix of the transaction's ID.
func (t TxnMeta) Short() string {
return t.ID.Short()
Expand Down Expand Up @@ -135,3 +137,27 @@ func (meta *MVCCMetadata) AddToIntentHistory(seq int32, val []byte) {
meta.IntentHistory = append(meta.IntentHistory,
MVCCMetadata_SequencedIntent{Sequence: seq, Value: val})
}

// GetPrevIntentSeq goes through the intent history and finds the previous
// intent's sequence number given the current sequence.
func (meta *MVCCMetadata) GetPrevIntentSeq(seq int32) (int32, bool) {
index := sort.Search(len(meta.IntentHistory), func(i int) bool {
return meta.IntentHistory[i].Sequence >= seq
})
if index > 0 && index < len(meta.IntentHistory) {
return meta.IntentHistory[index-1].Sequence, true
}
return 0, false
}

// GetIntentValue goes through the intent history and finds the value
// written at the sequence number.
func (meta *MVCCMetadata) GetIntentValue(seq int32) ([]byte, bool) {
index := sort.Search(len(meta.IntentHistory), func(i int) bool {
return meta.IntentHistory[i].Sequence >= seq
})
if index < len(meta.IntentHistory) && meta.IntentHistory[index].Sequence == seq {
return meta.IntentHistory[index].Value, true
}
return nil, false
}
Loading

0 comments on commit c05c516

Please sign in to comment.