Skip to content

Commit

Permalink
storage/concurrency: define concurrency control interfaces
Browse files Browse the repository at this point in the history
Informs cockroachdb#41720.

The commit creates a new concurrency package that provides a concurrency manager
structure that encapsulates the details of concurrency control and contention
handling for serializable key-value transactions. Interested readers should
start at `concurrency_control.go` and move out from there.

The new package has a few primary objectives:

1. centralize the handling of request synchronization and transaction contention
handling in a single location, allowing for the topic to be documented,
understood, and tested in isolation.

2. rework contention handling to react to intent state transitions directly.
This simplifies the transaction queueing story, reduces the frequency of
transaction push RPCs, and allows waiters to proceed immediately after intent
resolution.

3. create a framework that naturally permits "update" locking, which is required
for kv-level SELECT FOR UPDATE support (cockroachdb#6583).

4. provide stronger guarantees around fairness when transactions conflict, to
reduce tail latencies under contended sceneries.

5. create a structure that can extend to address the long-term goals of a fully
centralized lock-table laid out in cockroachdb#41720.

This commit pulls over a lot of already reviewed code from cockroachdb#43775. The big
differences are that it updates the lockTable interface to match the one
introduced in cockroachdb#43740 and it addresses the remaining TODOs to document the rest
of the concurrency control mechanisms in CockroachDB. At this point, a reader
of this file should get a good idea of how KV transactions interact in CRDB...
now we just need to make the system actually work this way.
  • Loading branch information
nvanbenschoten committed Feb 10, 2020
1 parent 21810df commit a840dbe
Show file tree
Hide file tree
Showing 12 changed files with 1,080 additions and 563 deletions.
2 changes: 2 additions & 0 deletions pkg/storage/batcheval/cmd_resolve_intent.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ func init() {
func declareKeysResolveIntentCombined(
desc *roachpb.RangeDescriptor, header roachpb.Header, req roachpb.Request, spans *spanset.SpanSet,
) {
// TODO(nvanbenschoten): declare this span at the txn's MinTimestamp. See
// lockTable.UpdateLocks for more.
DefaultDeclareKeys(desc, header, req, spans)
var status roachpb.TransactionStatus
var txnID uuid.UUID
Expand Down
734 changes: 734 additions & 0 deletions pkg/storage/concurrency/concurrency_control.go

Large diffs are not rendered by default.

35 changes: 35 additions & 0 deletions pkg/storage/concurrency/latch_manager.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright 2020 The Cockroach Authors.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.

package concurrency

import (
"context"

"github.com/cockroachdb/cockroach/pkg/roachpb"
"github.com/cockroachdb/cockroach/pkg/storage/spanlatch"
)

// latchManagerImpl implements the latchManager interface.
type latchManagerImpl struct {
m spanlatch.Manager
}

func (m *latchManagerImpl) Acquire(ctx context.Context, req Request) (latchGuard, *Error) {
lg, err := m.m.Acquire(ctx, req.Spans)
if err != nil {
return nil, roachpb.NewError(err)
}
return lg, nil
}

func (m *latchManagerImpl) Release(lg latchGuard) {
m.m.Release(lg.(*spanlatch.Guard))
}
610 changes: 177 additions & 433 deletions pkg/storage/concurrency/lock_table.go

Large diffs are not rendered by default.

Loading

0 comments on commit a840dbe

Please sign in to comment.