From b2bed86b3b1ff6684e04c6014f9667a7580dfcbb Mon Sep 17 00:00:00 2001 From: Nathan VanBenschoten Date: Wed, 30 Jun 2021 17:52:29 -0400 Subject: [PATCH] kv: remove EvalContext.DB Related to #66486. Command evaluation is meant to operate in a sandbox. It certainly shouldn't have access to a DB handle. --- pkg/kv/kvserver/batcheval/BUILD.bazel | 1 - pkg/kv/kvserver/batcheval/eval_context.go | 5 ----- pkg/kv/kvserver/replica.go | 9 ++------- pkg/kv/kvserver/replica_eval_context_span.go | 6 ------ 4 files changed, 2 insertions(+), 19 deletions(-) diff --git a/pkg/kv/kvserver/batcheval/BUILD.bazel b/pkg/kv/kvserver/batcheval/BUILD.bazel index d514e21bba3c..23cee95e6fed 100644 --- a/pkg/kv/kvserver/batcheval/BUILD.bazel +++ b/pkg/kv/kvserver/batcheval/BUILD.bazel @@ -50,7 +50,6 @@ go_library( deps = [ "//pkg/clusterversion", "//pkg/keys", - "//pkg/kv", "//pkg/kv/kvserver/abortspan", "//pkg/kv/kvserver/batcheval/result", "//pkg/kv/kvserver/closedts", diff --git a/pkg/kv/kvserver/batcheval/eval_context.go b/pkg/kv/kvserver/batcheval/eval_context.go index 333820f7668c..7bb34eeca3db 100644 --- a/pkg/kv/kvserver/batcheval/eval_context.go +++ b/pkg/kv/kvserver/batcheval/eval_context.go @@ -14,7 +14,6 @@ import ( "context" "fmt" - "github.com/cockroachdb/cockroach/pkg/kv" "github.com/cockroachdb/cockroach/pkg/kv/kvserver/abortspan" "github.com/cockroachdb/cockroach/pkg/kv/kvserver/closedts" "github.com/cockroachdb/cockroach/pkg/kv/kvserver/concurrency" @@ -53,7 +52,6 @@ type EvalContext interface { Engine() storage.Engine Clock() *hlc.Clock - DB() *kv.DB AbortSpan() *abortspan.AbortSpan GetConcurrencyManager() concurrency.Manager @@ -178,9 +176,6 @@ func (m *mockEvalCtxImpl) Engine() storage.Engine { func (m *mockEvalCtxImpl) Clock() *hlc.Clock { return m.MockEvalCtx.Clock } -func (m *mockEvalCtxImpl) DB() *kv.DB { - panic("unimplemented") -} func (m *mockEvalCtxImpl) AbortSpan() *abortspan.AbortSpan { return m.MockEvalCtx.AbortSpan } diff --git a/pkg/kv/kvserver/replica.go b/pkg/kv/kvserver/replica.go index fb848b2a1a42..b1d7f7b02a7a 100644 --- a/pkg/kv/kvserver/replica.go +++ b/pkg/kv/kvserver/replica.go @@ -807,11 +807,6 @@ func (r *Replica) Clock() *hlc.Clock { return r.store.Clock() } -// DB returns the Replica's client DB. -func (r *Replica) DB() *kv.DB { - return r.store.DB() -} - // Engine returns the Replica's underlying Engine. In most cases the // evaluation Batch should be used instead. func (r *Replica) Engine() storage.Engine { @@ -1647,7 +1642,7 @@ func (r *Replica) maybeWatchForMergeLocked(ctx context.Context) (bool, error) { PusheeTxn: intent.Txn, PushType: roachpb.PUSH_ABORT, }) - if err := r.DB().Run(ctx, b); err != nil { + if err := r.store.DB().Run(ctx, b); err != nil { select { case <-r.store.stopper.ShouldQuiesce(): // The server is shutting down. The error while pushing the @@ -1682,7 +1677,7 @@ func (r *Replica) maybeWatchForMergeLocked(ctx context.Context) (bool, error) { var getRes *roachpb.GetResponse for retry := retry.Start(base.DefaultRetryOptions()); retry.Next(); { metaKey := keys.RangeMetaKey(desc.EndKey) - res, pErr := kv.SendWrappedWith(ctx, r.DB().NonTransactionalSender(), roachpb.Header{ + res, pErr := kv.SendWrappedWith(ctx, r.store.DB().NonTransactionalSender(), roachpb.Header{ // Use READ_UNCOMMITTED to avoid trying to resolve intents, since // resolving those intents might involve sending requests to this // range, and that could deadlock. See the comment on diff --git a/pkg/kv/kvserver/replica_eval_context_span.go b/pkg/kv/kvserver/replica_eval_context_span.go index 0afcb0de2c15..69c80d1c90e2 100644 --- a/pkg/kv/kvserver/replica_eval_context_span.go +++ b/pkg/kv/kvserver/replica_eval_context_span.go @@ -14,7 +14,6 @@ import ( "context" "github.com/cockroachdb/cockroach/pkg/keys" - "github.com/cockroachdb/cockroach/pkg/kv" "github.com/cockroachdb/cockroach/pkg/kv/kvserver/abortspan" "github.com/cockroachdb/cockroach/pkg/kv/kvserver/batcheval" "github.com/cockroachdb/cockroach/pkg/kv/kvserver/closedts" @@ -72,11 +71,6 @@ func (rec *SpanSetReplicaEvalContext) Clock() *hlc.Clock { return rec.i.Clock() } -// DB returns the Replica's client DB. -func (rec *SpanSetReplicaEvalContext) DB() *kv.DB { - return rec.i.DB() -} - // GetConcurrencyManager returns the concurrency.Manager. func (rec *SpanSetReplicaEvalContext) GetConcurrencyManager() concurrency.Manager { return rec.i.GetConcurrencyManager()