Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "client: don't allocate some commit batches" #30773

Merged
merged 1 commit into from
Sep 28, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 2 additions & 34 deletions pkg/internal/client/txn.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,6 @@ type Txn struct {
// typ indicates the type of transaction.
typ TxnType

// alloc holds pre-allocated fields that can be used to avoid heap allocations
// for batches with lifetimes tied to a Txn.
// TODO(andrei): A lot more things should be pre-allocated or otherwise pooled
// - in particular the roachpb.Transaction proto and the TxnCoordSender which
// are quite large. Pooling them would also force us to clean up their
// lifetimes, which is a good idea on its own.
alloc struct {
requests [1]roachpb.RequestUnion
etUnion roachpb.RequestUnion_EndTransaction
et roachpb.EndTransactionRequest
}

// gatewayNodeID, if != 0, is the ID of the node on whose behalf this
// transaction is running. Normally this is the current node, but in the case
// of Txns created on remote nodes by DistSQL this will be the gateway.
Expand Down Expand Up @@ -521,7 +509,8 @@ func (txn *Txn) Run(ctx context.Context, b *Batch) error {
}

func (txn *Txn) commit(ctx context.Context) error {
ba := txn.getCommitReq(txn.deadline(), txn.systemConfigTrigger)
var ba roachpb.BatchRequest
ba.Add(endTxnReq(true /* commit */, txn.deadline(), txn.systemConfigTrigger))
_, pErr := txn.Send(ctx, ba)
if pErr == nil {
for _, t := range txn.commitTriggers {
Expand All @@ -545,27 +534,6 @@ func (txn *Txn) CleanupOnError(ctx context.Context, err error) {
}
}

func (txn *Txn) getCommitReq(deadline *hlc.Timestamp, hasTrigger bool) roachpb.BatchRequest {
ba := roachpb.BatchRequest{
Requests: txn.alloc.requests[:1],
}
etReq := &txn.alloc.et
etUnion := &txn.alloc.etUnion
ba.Requests[0].Value = etUnion
etUnion.EndTransaction = etReq
etReq.Reset()
etReq.Commit = true
etReq.Deadline = deadline
if hasTrigger {
etReq.InternalCommitTrigger = &roachpb.InternalCommitTrigger{
ModifiedSpanTrigger: &roachpb.ModifiedSpanTrigger{
SystemConfigSpan: true,
},
}
}
return ba
}

// Commit is the same as CommitOrCleanup but will not attempt to clean
// up on failure. This can be used when the caller is prepared to do proper
// cleanup.
Expand Down