-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
roachpb: add lock table metadata structures
This change adds the protobuf structures, as well as the method, needed to capture the state of a replica's lock table. This is part of the work coming out of #75541, and is needed to be able to implement the `QueryLocks` RPC. Release justification: (Category 2) The structures created here are entirely new, for the purposes of observability, and do not represent a risk to any existing code or functionality. Release note: None
- Loading branch information
Showing
10 changed files
with
312 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright 2022 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 lock provides type definitions for locking-related concepts used by | ||
// concurrency control in the key-value layer. | ||
package lock | ||
|
||
import "github.com/cockroachdb/redact" | ||
|
||
// SafeFormat implements redact.SafeFormatter. | ||
func (lw Waiter) SafeFormat(w redact.SafePrinter, _ rune) { | ||
expand := w.Flag('+') | ||
|
||
txnIDRedactableString := redact.Sprint(nil) | ||
if lw.WaitingTxn != nil { | ||
if expand { | ||
txnIDRedactableString = redact.Sprint(lw.WaitingTxn.ID) | ||
} else { | ||
txnIDRedactableString = redact.Sprint(lw.WaitingTxn.Short()) | ||
} | ||
} | ||
w.Printf("waiting_txn:%s active_waiter:%t strength:%s wait_duration:%s", txnIDRedactableString, lw.ActiveWaiter, lw.Strength, lw.WaitDuration) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright 2022 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. | ||
|
||
syntax = "proto3"; | ||
package cockroach.kv.kvserver.concurrency.lock; | ||
option go_package = "lock"; | ||
|
||
import "kv/kvserver/concurrency/lock/locking.proto"; | ||
import "storage/enginepb/mvcc3.proto"; | ||
import "gogoproto/gogo.proto"; | ||
import "google/protobuf/duration.proto"; | ||
|
||
// Waiter represents a transaction (or non-transactional operation) that is | ||
// waiting in the wait queue of readers or writers on an individual lock. | ||
message Waiter { | ||
// The transaction associated with this waiter, or nil in the case of a | ||
// non-transactional waiter. | ||
storage.enginepb.TxnMeta waiting_txn = 1; | ||
// Represents if this operation is actively waiting on the lock. While all | ||
// readers are active waiters, there are some cases in which writers may not | ||
// be actively waiting, for instance in the case of a broken reservation. | ||
bool active_waiter = 2; | ||
// The strength at which this waiter is attempting to acquire the lock. | ||
Strength strength = 3; | ||
// The wall clock duration since this operation began waiting on the lock. | ||
google.protobuf.Duration wait_duration = 4 [(gogoproto.nullable) = false, | ||
(gogoproto.stdduration) = true]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// Copyright 2022 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 lock provides type definitions for locking-related concepts used by | ||
// concurrency control in the key-value layer. | ||
package lock_test | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/concurrency/lock" | ||
"github.com/cockroachdb/cockroach/pkg/roachpb" | ||
"github.com/cockroachdb/cockroach/pkg/storage/enginepb" | ||
"github.com/cockroachdb/cockroach/pkg/util/hlc" | ||
"github.com/cockroachdb/cockroach/pkg/util/uuid" | ||
"github.com/cockroachdb/redact" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestWaiterSafeFormat(t *testing.T) { | ||
ts := hlc.Timestamp{Logical: 1} | ||
txnMeta := &enginepb.TxnMeta{ | ||
Key: roachpb.Key("foo"), | ||
ID: uuid.NamespaceDNS, | ||
Epoch: 2, | ||
WriteTimestamp: ts, | ||
MinTimestamp: ts, | ||
Priority: 957356782, | ||
Sequence: 123, | ||
CoordinatorNodeID: 3, | ||
} | ||
waiter := &lock.Waiter{ | ||
WaitingTxn: txnMeta, | ||
ActiveWaiter: true, | ||
Strength: lock.Exclusive, | ||
WaitDuration: 135 * time.Second, | ||
} | ||
|
||
require.EqualValues(t, | ||
"waiting_txn:6ba7b810 active_waiter:true strength:Exclusive wait_duration:2m15s", | ||
redact.Sprint(waiter).StripMarkers()) | ||
require.EqualValues(t, | ||
"waiting_txn:6ba7b810-9dad-11d1-80b4-00c04fd430c8 active_waiter:true strength:Exclusive wait_duration:2m15s", | ||
redact.Sprintf("%+v", waiter).StripMarkers()) | ||
require.EqualValues(t, | ||
"waiting_txn:6ba7b810 active_waiter:true strength:Exclusive wait_duration:2m15s", | ||
redact.Sprint(waiter).Redact()) | ||
require.EqualValues(t, | ||
"waiting_txn:‹×› active_waiter:true strength:Exclusive wait_duration:2m15s", | ||
redact.Sprintf("%+v", waiter).Redact()) | ||
|
||
nonTxnWaiter := &lock.Waiter{ | ||
WaitingTxn: nil, | ||
ActiveWaiter: false, | ||
Strength: lock.None, | ||
WaitDuration: 17 * time.Millisecond, | ||
} | ||
|
||
require.EqualValues(t, | ||
"waiting_txn:<nil> active_waiter:false strength:None wait_duration:17ms", | ||
redact.Sprint(nonTxnWaiter).StripMarkers()) | ||
require.EqualValues(t, | ||
"waiting_txn:<nil> active_waiter:false strength:None wait_duration:17ms", | ||
redact.Sprintf("%+v", nonTxnWaiter).StripMarkers()) | ||
require.EqualValues(t, | ||
"waiting_txn:<nil> active_waiter:false strength:None wait_duration:17ms", | ||
redact.Sprint(nonTxnWaiter).Redact()) | ||
require.EqualValues(t, | ||
"waiting_txn:<nil> active_waiter:false strength:None wait_duration:17ms", | ||
redact.Sprintf("%+v", nonTxnWaiter).Redact()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.