Skip to content

Commit

Permalink
Merge pull request #22477 from spencerkimball/optimize-serializable-c…
Browse files Browse the repository at this point in the history
…ommits

storage: further optimize serializable transactions
  • Loading branch information
spencerkimball authored Feb 8, 2018
2 parents 16db1d1 + d87a94e commit 35a94fc
Show file tree
Hide file tree
Showing 18 changed files with 930 additions and 543 deletions.
57 changes: 50 additions & 7 deletions c-deps/libroach/protos/roachpb/data.pb.cc

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

21 changes: 21 additions & 0 deletions c-deps/libroach/protos/roachpb/data.pb.h

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

9 changes: 9 additions & 0 deletions pkg/internal/client/txn.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,15 @@ func (txn *Txn) Isolation() enginepb.IsolationType {
return txn.mu.Proto.Isolation
}

// OrigTimestampWasObserved when called indicates that
// the value of OrigTimestamp was observed and matters
// for transaction ordering (i.e. don't bump)
func (txn *Txn) OrigTimestampWasObserved() {
txn.mu.Lock()
defer txn.mu.Unlock()
txn.mu.Proto.OrigTimestampWasObserved = true
}

// OrigTimestamp returns the transaction's starting timestamp.
func (txn *Txn) OrigTimestamp() hlc.Timestamp {
txn.mu.Lock()
Expand Down
38 changes: 36 additions & 2 deletions pkg/kv/dist_sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,40 @@ func (ds *DistSender) initAndVerifyBatch(
// request.
var errNo1PCTxn = roachpb.NewErrorf("cannot send 1PC txn to multiple ranges")

// splitBatchAndCheckForRefreshSpans splits the batch according to the
// canSplitET parmeter and checks whether the final request is an
// EndTransaction. If so, the EndTransactionRequest.NoRefreshSpans
// flag is reset to indicate whether earlier parts of the split may
// result in refresh spans.
func splitBatchAndCheckForRefreshSpans(
ba roachpb.BatchRequest, canSplitET bool,
) [][]roachpb.RequestUnion {
parts := ba.Split(canSplitET)
// If the final part contains an EndTransaction, we need to check
// whether earlier split parts contain any refresh spans and properly
// set the NoRefreshSpans flag on the end transaction.
lastPart := parts[len(parts)-1]
lastReq := lastPart[len(lastPart)-1].GetInner()
if et, ok := lastReq.(*roachpb.EndTransactionRequest); ok && et.NoRefreshSpans {
hasRefreshSpans := false
for _, part := range parts[:len(parts)-1] {
for _, req := range part {
if roachpb.NeedsRefresh(req.GetInner()) {
hasRefreshSpans = true
}
}
}
if hasRefreshSpans {
etCopy := *et
etCopy.NoRefreshSpans = false
lastPart = append([]roachpb.RequestUnion(nil), lastPart...)
lastPart[len(lastPart)-1].MustSetInner(&etCopy)
parts[len(parts)-1] = lastPart
}
}
return parts
}

// Send implements the batch.Sender interface. It subdivides the Batch
// into batches admissible for sending (preventing certain illegal
// mixtures of requests), executes each individual part (which may
Expand Down Expand Up @@ -615,7 +649,7 @@ func (ds *DistSender) Send(
if ba.Txn != nil && ba.Txn.Epoch > 0 {
splitET = true
}
parts := ba.Split(splitET)
parts := splitBatchAndCheckForRefreshSpans(ba, splitET)
if len(parts) > 1 && ba.MaxSpanRequestKeys != 0 {
// We already verified above that the batch contains only scan requests of the same type.
// Such a batch should never need splitting.
Expand Down Expand Up @@ -646,7 +680,7 @@ func (ds *DistSender) Send(
if len(parts) != 1 {
panic("EndTransaction not in last chunk of batch")
}
parts = ba.Split(true /* split ET */)
parts = splitBatchAndCheckForRefreshSpans(ba, true /* split ET */)
if len(parts) != 2 {
panic("split of final EndTransaction chunk resulted in != 2 parts")
}
Expand Down
Loading

0 comments on commit 35a94fc

Please sign in to comment.