Skip to content

Commit

Permalink
Merge #80893
Browse files Browse the repository at this point in the history
80893: admission: move WorkPriority into admissionpb.WorkPriority r=ajwerner a=otan

This commit moves WorkPriority into a separate, smaller package to
reduce the dependencies on packages that only need the WorkPriority
constants.

Release note: None

Co-authored-by: Oliver Tan <otan@cockroachlabs.com>
  • Loading branch information
craig[bot] and otan committed May 3, 2022
2 parents d63a369 + 3a9f7ad commit 1c41988
Show file tree
Hide file tree
Showing 32 changed files with 161 additions and 97 deletions.
2 changes: 1 addition & 1 deletion pkg/ccl/backupccl/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ go_library(
"//pkg/sql/types",
"//pkg/storage",
"//pkg/util",
"//pkg/util/admission",
"//pkg/util/admission/admissionpb",
"//pkg/util/contextutil",
"//pkg/util/ctxgroup",
"//pkg/util/encoding",
Expand Down
4 changes: 2 additions & 2 deletions pkg/ccl/backupccl/backup_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/sql/types"
"github.com/cockroachdb/cockroach/pkg/storage"
"github.com/cockroachdb/cockroach/pkg/util"
"github.com/cockroachdb/cockroach/pkg/util/admission"
"github.com/cockroachdb/cockroach/pkg/util/admission/admissionpb"
"github.com/cockroachdb/cockroach/pkg/util/contextutil"
"github.com/cockroachdb/cockroach/pkg/util/ctxgroup"
"github.com/cockroachdb/cockroach/pkg/util/hlc"
Expand Down Expand Up @@ -410,7 +410,7 @@ func runBackupProcessor(
// Export requests are currently assigned NormalPri.
//
// TODO(dt): Consider linking this to/from the UserPriority field.
Priority: int32(admission.BulkNormalPri),
Priority: int32(admissionpb.BulkNormalPri),
CreateTime: timeutil.Now().UnixNano(),
Source: roachpb.AdmissionHeader_FROM_SQL,
NoMemoryReservedAtSource: true,
Expand Down
1 change: 1 addition & 0 deletions pkg/kv/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ go_library(
"//pkg/storage/enginepb",
"//pkg/testutils",
"//pkg/util/admission",
"//pkg/util/admission/admissionpb",
"//pkg/util/contextutil",
"//pkg/util/duration",
"//pkg/util/errorutil/unimplemented",
Expand Down
2 changes: 1 addition & 1 deletion pkg/kv/bulk/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ go_library(
"//pkg/settings/cluster",
"//pkg/storage",
"//pkg/storage/enginepb",
"//pkg/util/admission",
"//pkg/util/admission/admissionpb",
"//pkg/util/ctxgroup",
"//pkg/util/hlc",
"//pkg/util/humanizeutil",
Expand Down
4 changes: 2 additions & 2 deletions pkg/kv/bulk/sst_batcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/settings/cluster"
"github.com/cockroachdb/cockroach/pkg/storage"
"github.com/cockroachdb/cockroach/pkg/storage/enginepb"
"github.com/cockroachdb/cockroach/pkg/util/admission"
"github.com/cockroachdb/cockroach/pkg/util/admission/admissionpb"
"github.com/cockroachdb/cockroach/pkg/util/ctxgroup"
"github.com/cockroachdb/cockroach/pkg/util/hlc"
"github.com/cockroachdb/cockroach/pkg/util/log"
Expand Down Expand Up @@ -615,7 +615,7 @@ func (b *SSTBatcher) addSSTable(
ba := roachpb.BatchRequest{
Header: roachpb.Header{Timestamp: batchTS, ClientRangeInfo: roachpb.ClientRangeInfo{ExplicitlyRequested: true}},
AdmissionHeader: roachpb.AdmissionHeader{
Priority: int32(admission.BulkNormalPri),
Priority: int32(admissionpb.BulkNormalPri),
CreateTime: timeutil.Now().UnixNano(),
Source: roachpb.AdmissionHeader_FROM_SQL,
NoMemoryReservedAtSource: true,
Expand Down
5 changes: 3 additions & 2 deletions pkg/kv/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/sql/sessiondatapb"
"github.com/cockroachdb/cockroach/pkg/storage/enginepb"
"github.com/cockroachdb/cockroach/pkg/util/admission"
"github.com/cockroachdb/cockroach/pkg/util/admission/admissionpb"
"github.com/cockroachdb/cockroach/pkg/util/hlc"
"github.com/cockroachdb/cockroach/pkg/util/log"
"github.com/cockroachdb/cockroach/pkg/util/protoutil"
Expand Down Expand Up @@ -888,15 +889,15 @@ func (db *DB) NewTxn(ctx context.Context, debugName string) *Txn {
// resetting the transaction and retrying the callback.
func (db *DB) Txn(ctx context.Context, retryable func(context.Context, *Txn) error) error {
return db.TxnWithAdmissionControl(
ctx, roachpb.AdmissionHeader_OTHER, admission.NormalPri, retryable)
ctx, roachpb.AdmissionHeader_OTHER, admissionpb.NormalPri, retryable)
}

// TxnWithAdmissionControl is like Txn, but uses a configurable admission
// control source and priority.
func (db *DB) TxnWithAdmissionControl(
ctx context.Context,
source roachpb.AdmissionHeader_Source,
priority admission.WorkPriority,
priority admissionpb.WorkPriority,
retryable func(context.Context, *Txn) error,
) error {
// TODO(radu): we should open a tracing Span here (we need to figure out how
Expand Down
1 change: 1 addition & 0 deletions pkg/kv/kvclient/kvstreamer/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ go_library(
"//pkg/settings",
"//pkg/settings/cluster",
"//pkg/util/admission",
"//pkg/util/admission/admissionpb",
"//pkg/util/buildutil",
"//pkg/util/mon",
"//pkg/util/quotapool",
Expand Down
3 changes: 2 additions & 1 deletion pkg/kv/kvclient/kvstreamer/streamer.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/settings"
"github.com/cockroachdb/cockroach/pkg/settings/cluster"
"github.com/cockroachdb/cockroach/pkg/util/admission"
"github.com/cockroachdb/cockroach/pkg/util/admission/admissionpb"
"github.com/cockroachdb/cockroach/pkg/util/buildutil"
"github.com/cockroachdb/cockroach/pkg/util/mon"
"github.com/cockroachdb/cockroach/pkg/util/quotapool"
Expand Down Expand Up @@ -1117,7 +1118,7 @@ func (w *workerCoordinator) performRequestAsync(
if br != nil && w.responseAdmissionQ != nil {
responseAdmission := admission.WorkInfo{
TenantID: roachpb.SystemTenantID,
Priority: admission.WorkPriority(w.requestAdmissionHeader.Priority),
Priority: admissionpb.WorkPriority(w.requestAdmissionHeader.Priority),
CreateTime: w.requestAdmissionHeader.CreateTime,
}
if _, err := w.responseAdmissionQ.Admit(ctx, responseAdmission); err != nil {
Expand Down
1 change: 1 addition & 0 deletions pkg/kv/kvserver/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ go_library(
"//pkg/storage/fs",
"//pkg/util",
"//pkg/util/admission",
"//pkg/util/admission/admissionpb",
"//pkg/util/bufalloc",
"//pkg/util/buildutil",
"//pkg/util/circuit",
Expand Down
4 changes: 2 additions & 2 deletions pkg/kv/kvserver/mvcc_gc_queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/settings/cluster"
"github.com/cockroachdb/cockroach/pkg/spanconfig"
"github.com/cockroachdb/cockroach/pkg/storage/enginepb"
"github.com/cockroachdb/cockroach/pkg/util/admission"
"github.com/cockroachdb/cockroach/pkg/util/admission/admissionpb"
"github.com/cockroachdb/cockroach/pkg/util/hlc"
"github.com/cockroachdb/cockroach/pkg/util/humanizeutil"
"github.com/cockroachdb/cockroach/pkg/util/log"
Expand Down Expand Up @@ -453,7 +453,7 @@ func (r *replicaGCer) send(ctx context.Context, req roachpb.GCRequest) error {
// increase write amplification of the store since there is more live
// data. Ideally, we should adjust this priority based on how far behind
// we are wrt GCing in this range.
Priority: int32(admission.NormalPri),
Priority: int32(admissionpb.NormalPri),
CreateTime: timeutil.Now().UnixNano(),
Source: roachpb.AdmissionHeader_ROOT_KV,
NoMemoryReservedAtSource: true,
Expand Down
3 changes: 2 additions & 1 deletion pkg/kv/kvserver/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/storage"
"github.com/cockroachdb/cockroach/pkg/storage/enginepb"
"github.com/cockroachdb/cockroach/pkg/util/admission"
"github.com/cockroachdb/cockroach/pkg/util/admission/admissionpb"
"github.com/cockroachdb/cockroach/pkg/util/contextutil"
"github.com/cockroachdb/cockroach/pkg/util/ctxgroup"
"github.com/cockroachdb/cockroach/pkg/util/envutil"
Expand Down Expand Up @@ -3728,7 +3729,7 @@ func (n KVAdmissionControllerImpl) AdmitKVWork(
}
admissionInfo := admission.WorkInfo{
TenantID: tenantID,
Priority: admission.WorkPriority(ba.AdmissionHeader.Priority),
Priority: admissionpb.WorkPriority(ba.AdmissionHeader.Priority),
CreateTime: createTime,
BypassAdmission: bypassAdmission,
}
Expand Down
14 changes: 7 additions & 7 deletions pkg/kv/txn.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/settings"
"github.com/cockroachdb/cockroach/pkg/sql/sessiondatapb"
"github.com/cockroachdb/cockroach/pkg/storage/enginepb"
"github.com/cockroachdb/cockroach/pkg/util/admission"
"github.com/cockroachdb/cockroach/pkg/util/admission/admissionpb"
"github.com/cockroachdb/cockroach/pkg/util/contextutil"
"github.com/cockroachdb/cockroach/pkg/util/errorutil/unimplemented"
"github.com/cockroachdb/cockroach/pkg/util/hlc"
Expand Down Expand Up @@ -119,7 +119,7 @@ type Txn struct {
// See also db.NewTxn().
func NewTxn(ctx context.Context, db *DB, gatewayNodeID roachpb.NodeID) *Txn {
return NewTxnWithAdmissionControl(
ctx, db, gatewayNodeID, roachpb.AdmissionHeader_OTHER, admission.NormalPri)
ctx, db, gatewayNodeID, roachpb.AdmissionHeader_OTHER, admissionpb.NormalPri)
}

// NewTxnWithAdmissionControl creates a new transaction with the specified
Expand All @@ -129,7 +129,7 @@ func NewTxnWithAdmissionControl(
db *DB,
gatewayNodeID roachpb.NodeID,
source roachpb.AdmissionHeader_Source,
priority admission.WorkPriority,
priority admissionpb.WorkPriority,
) *Txn {
if db == nil {
panic(errors.WithContextTags(
Expand Down Expand Up @@ -158,15 +158,15 @@ func NewTxnWithAdmissionControl(
// that this initializes Txn.admissionHeader to specify that the source is
// FROM_SQL.
// qualityOfService is the QoSLevel level to use in admission control, whose
// value also corresponds exactly with the admission.WorkPriority to use.
// value also corresponds exactly with the admissionpb.WorkPriority to use.
func NewTxnWithSteppingEnabled(
ctx context.Context,
db *DB,
gatewayNodeID roachpb.NodeID,
qualityOfService sessiondatapb.QoSLevel,
) *Txn {
txn := NewTxnWithAdmissionControl(ctx, db, gatewayNodeID,
roachpb.AdmissionHeader_FROM_SQL, admission.WorkPriority(qualityOfService))
roachpb.AdmissionHeader_FROM_SQL, admissionpb.WorkPriority(qualityOfService))
_ = txn.ConfigureStepping(ctx, SteppingEnabled)
return txn
}
Expand All @@ -179,7 +179,7 @@ func NewTxnWithSteppingEnabled(
// details.
func NewTxnRootKV(ctx context.Context, db *DB, gatewayNodeID roachpb.NodeID) *Txn {
return NewTxnWithAdmissionControl(
ctx, db, gatewayNodeID, roachpb.AdmissionHeader_ROOT_KV, admission.NormalPri)
ctx, db, gatewayNodeID, roachpb.AdmissionHeader_ROOT_KV, admissionpb.NormalPri)
}

// NewTxnFromProto is like NewTxn but assumes the Transaction object is already initialized.
Expand Down Expand Up @@ -1683,7 +1683,7 @@ func (txn *Txn) AdmissionHeader() roachpb.AdmissionHeader {
// the transaction throughput by 10+%. In that experiment 40% of the
// BatchRequests evaluated by KV had been assigned high priority due to
// locking.
h.Priority = int32(admission.LockingPri)
h.Priority = int32(admissionpb.LockingPri)
}
return h
}
Expand Down
1 change: 1 addition & 0 deletions pkg/sql/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@ go_library(
"//pkg/testutils/serverutils",
"//pkg/util",
"//pkg/util/admission",
"//pkg/util/admission/admissionpb",
"//pkg/util/bitarray",
"//pkg/util/buildutil",
"//pkg/util/cache",
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/backfill/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ go_library(
"//pkg/sql/sqlerrors",
"//pkg/sql/types",
"//pkg/util",
"//pkg/util/admission",
"//pkg/util/admission/admissionpb",
"//pkg/util/ctxgroup",
"//pkg/util/hlc",
"//pkg/util/log",
Expand Down
6 changes: 3 additions & 3 deletions pkg/sql/backfill/mvcc_index_merger.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/sql/sem/eval"
"github.com/cockroachdb/cockroach/pkg/sql/sem/tree"
"github.com/cockroachdb/cockroach/pkg/sql/types"
"github.com/cockroachdb/cockroach/pkg/util/admission"
"github.com/cockroachdb/cockroach/pkg/util/admission/admissionpb"
"github.com/cockroachdb/cockroach/pkg/util/ctxgroup"
"github.com/cockroachdb/cockroach/pkg/util/hlc"
"github.com/cockroachdb/cockroach/pkg/util/log"
Expand Down Expand Up @@ -264,7 +264,7 @@ func (ibm *IndexBackfillMerger) scan(

var nextStart roachpb.Key
var br *roachpb.BatchResponse
if err := ibm.flowCtx.Cfg.DB.TxnWithAdmissionControl(ctx, roachpb.AdmissionHeader_FROM_SQL, admission.BulkNormalPri,
if err := ibm.flowCtx.Cfg.DB.TxnWithAdmissionControl(ctx, roachpb.AdmissionHeader_FROM_SQL, admissionpb.BulkNormalPri,
func(ctx context.Context, txn *kv.Txn) error {
if err := txn.SetFixedTimestamp(ctx, readAsOf); err != nil {
return err
Expand Down Expand Up @@ -336,7 +336,7 @@ func (ibm *IndexBackfillMerger) merge(
sourcePrefix := rowenc.MakeIndexKeyPrefix(codec, table.GetID(), sourceID)
destPrefix := rowenc.MakeIndexKeyPrefix(codec, table.GetID(), destinationID)

err := ibm.flowCtx.Cfg.DB.TxnWithAdmissionControl(ctx, roachpb.AdmissionHeader_FROM_SQL, admission.BulkNormalPri,
err := ibm.flowCtx.Cfg.DB.TxnWithAdmissionControl(ctx, roachpb.AdmissionHeader_FROM_SQL, admissionpb.BulkNormalPri,
func(ctx context.Context, txn *kv.Txn) error {
var deletedCount int
txn.AddCommitTrigger(func(ctx context.Context) {
Expand Down
1 change: 1 addition & 0 deletions pkg/sql/flowinfra/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ go_library(
"//pkg/sql/sqltelemetry",
"//pkg/sql/types",
"//pkg/util/admission",
"//pkg/util/admission/admissionpb",
"//pkg/util/cancelchecker",
"//pkg/util/contextutil",
"//pkg/util/log",
Expand Down
5 changes: 3 additions & 2 deletions pkg/sql/flowinfra/flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/sql/execinfra/execreleasable"
"github.com/cockroachdb/cockroach/pkg/sql/execinfrapb"
"github.com/cockroachdb/cockroach/pkg/util/admission"
"github.com/cockroachdb/cockroach/pkg/util/admission/admissionpb"
"github.com/cockroachdb/cockroach/pkg/util/cancelchecker"
"github.com/cockroachdb/cockroach/pkg/util/contextutil"
"github.com/cockroachdb/cockroach/pkg/util/log"
Expand Down Expand Up @@ -277,11 +278,11 @@ func NewFlowBase(
// use SystemTenantID since it is already defined.
admissionInfo := admission.WorkInfo{TenantID: roachpb.SystemTenantID}
if flowCtx.Txn == nil {
admissionInfo.Priority = admission.NormalPri
admissionInfo.Priority = admissionpb.NormalPri
admissionInfo.CreateTime = timeutil.Now().UnixNano()
} else {
h := flowCtx.Txn.AdmissionHeader()
admissionInfo.Priority = admission.WorkPriority(h.Priority)
admissionInfo.Priority = admissionpb.WorkPriority(h.Priority)
admissionInfo.CreateTime = h.CreateTime
}
return &FlowBase{
Expand Down
1 change: 1 addition & 0 deletions pkg/sql/row/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ go_library(
"//pkg/storage/enginepb",
"//pkg/util",
"//pkg/util/admission",
"//pkg/util/admission/admissionpb",
"//pkg/util/encoding",
"//pkg/util/hlc",
"//pkg/util/log",
Expand Down
3 changes: 2 additions & 1 deletion pkg/sql/row/kv_batch_fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/sql/rowinfra"
"github.com/cockroachdb/cockroach/pkg/util"
"github.com/cockroachdb/cockroach/pkg/util/admission"
"github.com/cockroachdb/cockroach/pkg/util/admission/admissionpb"
"github.com/cockroachdb/cockroach/pkg/util/log"
"github.com/cockroachdb/cockroach/pkg/util/mon"
"github.com/cockroachdb/errors"
Expand Down Expand Up @@ -447,7 +448,7 @@ func (f *txnKVFetcher) fetch(ctx context.Context) error {
if br != nil && f.responseAdmissionQ != nil {
responseAdmission := admission.WorkInfo{
TenantID: roachpb.SystemTenantID,
Priority: admission.WorkPriority(f.requestAdmissionHeader.Priority),
Priority: admissionpb.WorkPriority(f.requestAdmissionHeader.Priority),
CreateTime: f.requestAdmissionHeader.CreateTime,
}
if _, err := f.responseAdmissionQ.Admit(ctx, responseAdmission); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/rowexec/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ go_library(
"//pkg/sql/stats",
"//pkg/sql/types",
"//pkg/util",
"//pkg/util/admission",
"//pkg/util/admission/admissionpb",
"//pkg/util/cancelchecker",
"//pkg/util/ctxgroup",
"//pkg/util/encoding",
Expand Down
4 changes: 2 additions & 2 deletions pkg/sql/rowexec/columnbackfiller.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/sql/execinfra"
"github.com/cockroachdb/cockroach/pkg/sql/execinfrapb"
"github.com/cockroachdb/cockroach/pkg/sql/rowinfra"
"github.com/cockroachdb/cockroach/pkg/util/admission"
"github.com/cockroachdb/cockroach/pkg/util/admission/admissionpb"
"github.com/cockroachdb/cockroach/pkg/util/hlc"
)

Expand Down Expand Up @@ -107,7 +107,7 @@ func (cb *columnBackfiller) runChunk(
var key roachpb.Key
var commitWaitFn func(context.Context) error
err := cb.flowCtx.Cfg.DB.TxnWithAdmissionControl(
ctx, roachpb.AdmissionHeader_FROM_SQL, admission.BulkNormalPri,
ctx, roachpb.AdmissionHeader_FROM_SQL, admissionpb.BulkNormalPri,
func(ctx context.Context, txn *kv.Txn) error {
if cb.flowCtx.Cfg.TestingKnobs.RunBeforeBackfillChunk != nil {
if err := cb.flowCtx.Cfg.TestingKnobs.RunBeforeBackfillChunk(sp); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/sessiondatapb/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ go_library(
visibility = ["//visibility:public"],
deps = [
"//pkg/security/username",
"//pkg/util/admission",
"//pkg/util/admission/admissionpb",
"@com_github_cockroachdb_errors//:errors",
"@com_github_lib_pq//oid", # keep
],
Expand Down
Loading

0 comments on commit 1c41988

Please sign in to comment.