Skip to content

Commit

Permalink
Merge pull request #9 from mohini-crl/backupccl/backup-compaction-ite…
Browse files Browse the repository at this point in the history
…rator

backupccl: create backup compaction iterator
  • Loading branch information
mohini-crl authored Dec 19, 2024
2 parents 1e7077a + 9c30e58 commit 92400bc
Show file tree
Hide file tree
Showing 36 changed files with 1,286 additions and 94 deletions.
12 changes: 6 additions & 6 deletions DEPS.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -1821,10 +1821,10 @@ def go_deps():
name = "com_github_cockroachdb_logtags",
build_file_proto_mode = "disable_global",
importpath = "github.com/cockroachdb/logtags",
sha256 = "ca7776f47e5fecb4c495490a679036bfc29d95bd7625290cfdb9abb0baf97476",
strip_prefix = "github.com/cockroachdb/[email protected]20230118201751-21c54148d20b",
sha256 = "ff8b3d36873cfff78669000d194cbaa96520549a62408c52b538380d953b99d7",
strip_prefix = "github.com/cockroachdb/[email protected]20241205023844-89a8856d99be",
urls = [
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/logtags/com_github_cockroachdb_logtags-v0.0.0-20230118201751-21c54148d20b.zip",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/logtags/com_github_cockroachdb_logtags-v0.0.0-20241205023844-89a8856d99be.zip",
],
)
go_repository(
Expand Down Expand Up @@ -3880,10 +3880,10 @@ def go_deps():
patches = [
"@com_github_cockroachdb_cockroach//build/patches:com_github_gogo_protobuf.patch",
],
sha256 = "1382d1ef3a015855f8268c595e2afeef7ae7374b7e27c2181b27a42c2fb639a7",
strip_prefix = "github.com/cockroachdb/[email protected].20241118145159-46874edb1b83",
sha256 = "dcd238e23ee4363de82379741ef09b6583947fcd4d8d6a4616ce1516cc8945b3",
strip_prefix = "github.com/cockroachdb/[email protected].20241214030254-fb9ffcbc9553",
urls = [
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/gogoproto/com_github_cockroachdb_gogoproto-v1.3.3-0.20241118145159-46874edb1b83.zip",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/gogoproto/com_github_cockroachdb_gogoproto-v1.3.3-0.20241214030254-fb9ffcbc9553.zip",
],
)
go_repository(
Expand Down
4 changes: 2 additions & 2 deletions build/bazelutil/distdir_files.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -350,9 +350,9 @@ DISTDIR_FILES = {
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/datadriven/com_github_cockroachdb_datadriven-v1.0.3-0.20240530155848-7682d40af056.zip": "f4cb70fec2b2904a56bfbda6a6c8bf9ea1d568a5994ecdb825f770671119b63b",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/errors/com_github_cockroachdb_errors-v1.11.3.zip": "d11ed59d96afef2d1f0ce56892839c62ff5c0cbca8dff0aaefeaef7eb190e73c",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/go-test-teamcity/com_github_cockroachdb_go_test_teamcity-v0.0.0-20191211140407-cff980ad0a55.zip": "bac30148e525b79d004da84d16453ddd2d5cd20528e9187f1d7dac708335674b",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/gogoproto/com_github_cockroachdb_gogoproto-v1.3.3-0.20241118145159-46874edb1b83.zip": "1382d1ef3a015855f8268c595e2afeef7ae7374b7e27c2181b27a42c2fb639a7",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/gogoproto/com_github_cockroachdb_gogoproto-v1.3.3-0.20241214030254-fb9ffcbc9553.zip": "dcd238e23ee4363de82379741ef09b6583947fcd4d8d6a4616ce1516cc8945b3",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/gostdlib/com_github_cockroachdb_gostdlib-v1.19.0.zip": "c4d516bcfe8c07b6fc09b8a9a07a95065b36c2855627cb3514e40c98f872b69e",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/logtags/com_github_cockroachdb_logtags-v0.0.0-20230118201751-21c54148d20b.zip": "ca7776f47e5fecb4c495490a679036bfc29d95bd7625290cfdb9abb0baf97476",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/logtags/com_github_cockroachdb_logtags-v0.0.0-20241205023844-89a8856d99be.zip": "ff8b3d36873cfff78669000d194cbaa96520549a62408c52b538380d953b99d7",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/metamorphic/com_github_cockroachdb_metamorphic-v0.0.0-20231108215700-4ba948b56895.zip": "28c8cf42192951b69378cf537be5a9a43f2aeb35542908cc4fe5f689505853ea",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/pebble/com_github_cockroachdb_pebble-v0.0.0-20241206160845-91e091aa3637.zip": "dfd82d8e65c0b4cf44629de5ad07104a327c80d2cd515a387fc008f6051df040",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/redact/com_github_cockroachdb_redact-v1.1.5.zip": "11b30528eb0dafc8bc1a5ba39d81277c257cbe6946a7564402f588357c164560",
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ require (
github.com/cockroachdb/errors v1.11.3
github.com/cockroachdb/go-test-teamcity v0.0.0-20191211140407-cff980ad0a55
github.com/cockroachdb/gostdlib v1.19.0
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b
github.com/cockroachdb/logtags v0.0.0-20241205023844-89a8856d99be
github.com/cockroachdb/pebble v0.0.0-20241206160845-91e091aa3637
github.com/cockroachdb/redact v1.1.5
github.com/cockroachdb/returncheck v0.0.0-20200612231554-92cdbca611dd
Expand Down Expand Up @@ -483,4 +483,4 @@ replace github.com/docker/docker => github.com/moby/moby v24.0.6+incompatible

replace golang.org/x/time => github.com/cockroachdb/x-time v0.3.1-0.20230525123634-71747adb5d5c

replace github.com/gogo/protobuf => github.com/cockroachdb/gogoproto v1.3.3-0.20241118145159-46874edb1b83
replace github.com/gogo/protobuf => github.com/cockroachdb/gogoproto v1.3.3-0.20241214030254-fb9ffcbc9553
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -536,13 +536,13 @@ github.com/cockroachdb/errors v1.11.3 h1:5bA+k2Y6r+oz/6Z/RFlNeVCesGARKuC6YymtcDr
github.com/cockroachdb/errors v1.11.3/go.mod h1:m4UIW4CDjx+R5cybPsNrRbreomiFqt8o1h1wUVazSd8=
github.com/cockroachdb/go-test-teamcity v0.0.0-20191211140407-cff980ad0a55 h1:YqzBA7tf8Gv8Oz0BbBsPenqkyjiohS7EUIwi7p1QJCU=
github.com/cockroachdb/go-test-teamcity v0.0.0-20191211140407-cff980ad0a55/go.mod h1:QqVqNIiRhLqJXif5C9wbM4JydBhrAF2WDMxkv5xkyxQ=
github.com/cockroachdb/gogoproto v1.3.3-0.20241118145159-46874edb1b83 h1:PVow08bqk5r9oZXAXgdeFYq3FN7m6fuMEjheeQmqxcA=
github.com/cockroachdb/gogoproto v1.3.3-0.20241118145159-46874edb1b83/go.mod h1:wIrkfXJOUk95vmhcdlmaou6FpqbEExZWBM7EAtKDvYg=
github.com/cockroachdb/gogoproto v1.3.3-0.20241214030254-fb9ffcbc9553 h1:qVbAx/t2EU//lHyR4LCDgHoZStlYnUuBeMYejUo/ado=
github.com/cockroachdb/gogoproto v1.3.3-0.20241214030254-fb9ffcbc9553/go.mod h1:wIrkfXJOUk95vmhcdlmaou6FpqbEExZWBM7EAtKDvYg=
github.com/cockroachdb/gostdlib v1.19.0 h1:cSISxkVnTlWhTkyple/T6NXzOi5659FkhxvUgZv+Eb0=
github.com/cockroachdb/gostdlib v1.19.0/go.mod h1:+dqqpARXbE/gRDEhCak6dm0l14AaTymPZUKMfURjBtY=
github.com/cockroachdb/logtags v0.0.0-20211118104740-dabe8e521a4f/go.mod h1:Vz9DsVWQQhf3vs21MhPMZpMGSht7O/2vFW2xusFUVOs=
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b h1:r6VH0faHjZeQy818SGhaone5OnYfxFR/+AzdY3sf5aE=
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b/go.mod h1:Vz9DsVWQQhf3vs21MhPMZpMGSht7O/2vFW2xusFUVOs=
github.com/cockroachdb/logtags v0.0.0-20241205023844-89a8856d99be h1:74/l4OkGUedTm/IzF3IUzecZ4y4ClCoQZkLN0X8sMQg=
github.com/cockroachdb/logtags v0.0.0-20241205023844-89a8856d99be/go.mod h1:Vz9DsVWQQhf3vs21MhPMZpMGSht7O/2vFW2xusFUVOs=
github.com/cockroachdb/metamorphic v0.0.0-20231108215700-4ba948b56895 h1:XANOgPYtvELQ/h4IrmPAohXqe2pWA8Bwhejr3VQoZsA=
github.com/cockroachdb/metamorphic v0.0.0-20231108215700-4ba948b56895/go.mod h1:aPd7gM9ov9M8v32Yy5NJrDyOcD8z642dqs+F0CeNXfA=
github.com/cockroachdb/pebble v0.0.0-20241206160845-91e091aa3637 h1:DHpvNh7WubKNL0yv0nIK318JbMxQo5/CZA1C26KBGJc=
Expand Down
1 change: 1 addition & 0 deletions pkg/base/serverident/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ go_library(
srcs = ["server_ident.go"],
importpath = "github.com/cockroachdb/cockroach/pkg/base/serverident",
visibility = ["//visibility:public"],
deps = ["//pkg/util/ctxutil"],
)
22 changes: 14 additions & 8 deletions pkg/base/serverident/server_ident.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,44 @@

package serverident

import "context"
import (
"context"

"github.com/cockroachdb/cockroach/pkg/util/ctxutil"
)

// SystemTenantID is the string representation of
// roachpb.SystemTenantID. Injected at initialization to avoid
// an import dependency cycle. See SetSystemTenantID.
var SystemTenantID string

// ServerIdentificationContextKey is the type of a context.Value key
// used to carry ServerIdentificationPayload values.
type ServerIdentificationContextKey struct{}
// ServerIdentificationContextKey is the fast value key used to annotate a
// context with a ServerIdentificationPayload.
var ServerIdentificationContextKey = ctxutil.RegisterFastValueKey()

// ContextWithServerIdentification returns a context annotated with the provided
// server identity. Use ServerIdentificationFromContext(ctx) to retrieve it from
// the ctx later.
func ContextWithServerIdentification(
ctx context.Context, serverID ServerIdentificationPayload,
) context.Context {
return context.WithValue(ctx, ServerIdentificationContextKey{}, serverID)
return ctxutil.WithFastValue(ctx, ServerIdentificationContextKey, serverID)
}

// ServerIdentificationFromContext retrieves the server identity put in the
// context by ContextWithServerIdentification.
func ServerIdentificationFromContext(ctx context.Context) ServerIdentificationPayload {
r := ctx.Value(ServerIdentificationContextKey{})
r := ctxutil.FastValue(ctx, ServerIdentificationContextKey)
if r == nil {
return nil
}
// TODO(radu): an interface-to-interface conversion is not great in a hot
// path. Maybe the type should be just a func instead of an interface.
return r.(ServerIdentificationPayload)
}

// ServerIdentificationPayload is the type of a context.Value payload
// associated with a ServerIdentificationContextKey.
// associated with a serverIdentificationContextKey.
type ServerIdentificationPayload interface {
// ServerIdentityString retrieves an identifier corresponding to the
// given retrieval key. If there is no value known for a given key,
Expand All @@ -57,7 +63,7 @@ const (
IdentifyInstanceID
// IdentifyTenantID retrieves the tenant ID of the server.
IdentifyTenantID
// IdentifyTenantLabel retrieves the tenant name of the server.
// IdentifyTenantName retrieves the tenant name of the server.
IdentifyTenantName
)

Expand Down
1 change: 1 addition & 0 deletions pkg/ccl/sqlproxyccl/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ go_library(
"//pkg/sql/pgwire/pgcode",
"//pkg/sql/pgwire/pgwirebase",
"//pkg/util/cache",
"//pkg/util/ctxutil",
"//pkg/util/grpcutil",
"//pkg/util/httputil",
"//pkg/util/log",
Expand Down
11 changes: 6 additions & 5 deletions pkg/ccl/sqlproxyccl/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"time"

"github.com/cockroachdb/cockroach/pkg/util/cache"
"github.com/cockroachdb/cockroach/pkg/util/ctxutil"
"github.com/cockroachdb/cockroach/pkg/util/grpcutil"
"github.com/cockroachdb/cockroach/pkg/util/httputil"
"github.com/cockroachdb/cockroach/pkg/util/log"
Expand Down Expand Up @@ -453,20 +454,20 @@ func (s *Server) shouldLogError(
return limiter.ShouldLog()
}

// requestTagsContextKey is the type of a context.Value key used to carry the
// request tags map in a context.Context object.
type requestTagsContextKey struct{}
// requestTagsContextKey is the fast value key used to carry the request tags
// map in a context.Context object.
var requestTagsContextKey = ctxutil.RegisterFastValueKey()

// contextWithRequestTags returns a context annotated with the provided request
// tags map. Use requestTagsFromContext(ctx) to retrieve it back.
func contextWithRequestTags(ctx context.Context, reqTags map[string]interface{}) context.Context {
return context.WithValue(ctx, requestTagsContextKey{}, reqTags)
return ctxutil.WithFastValue(ctx, requestTagsContextKey, reqTags)
}

// requestTagsFromContext retrieves the request tags map stored in the context
// via contextWithRequestTags.
func requestTagsFromContext(ctx context.Context) map[string]interface{} {
r := ctx.Value(requestTagsContextKey{})
r := ctxutil.FastValue(ctx, requestTagsContextKey)
if r == nil {
return nil
}
Expand Down
12 changes: 7 additions & 5 deletions pkg/cmd/roachtest/tests/kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -740,11 +740,13 @@ func registerKVSplits(r registry.Registry) {
} {
item := item // for use in closure below
r.Add(registry.TestSpec{
Name: fmt.Sprintf("kv/splits/nodes=3/quiesce=%t/lease=%s", item.quiesce, item.leases),
Owner: registry.OwnerKV,
Timeout: item.timeout,
Cluster: r.MakeClusterSpec(4, spec.WorkloadNode()),
CompatibleClouds: registry.AllExceptAWS,
Name: fmt.Sprintf("kv/splits/nodes=3/quiesce=%t/lease=%s", item.quiesce, item.leases),
Owner: registry.OwnerKV,
Timeout: item.timeout,
Cluster: r.MakeClusterSpec(4, spec.WorkloadNode()),
// These tests are carefully tuned to succeed up to certain number of
// splits; they are flaky in slower environments.
CompatibleClouds: registry.Clouds(spec.GCE, spec.Local),
Suites: registry.Suites(registry.Nightly),
Leases: item.leases,
Run: func(ctx context.Context, t test.Test, c cluster.Cluster) {
Expand Down
4 changes: 0 additions & 4 deletions pkg/cmd/roachtest/tests/tpcc.go
Original file line number Diff line number Diff line change
Expand Up @@ -683,10 +683,6 @@ func registerTPCC(r registry.Registry) {
ExtraRunArgs: "--wait=false",
SetupType: usingImport,
ExpensiveChecks: true,
// Increase the vmodule level around transaction pushes so that if we do
// see a transaction retry error, we can debug it. This may affect perf,
// so we should not use this as a performance test.
ExtraStartArgs: []string{"--vmodule=cmd_push_txn=2,queue=2,transaction=2,lock_table_waiter=2,manager=2"},
WorkloadInstances: func() (ret []workloadInstance) {
isoLevels := []string{"read_uncommitted", "read_committed", "repeatable_read", "snapshot", "serializable"}
for i, isoLevel := range isoLevels {
Expand Down
1 change: 1 addition & 0 deletions pkg/kv/kvserver/kvflowcontrol/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ go_library(
"//pkg/settings",
"//pkg/settings/cluster",
"//pkg/util/admission/admissionpb",
"//pkg/util/ctxutil",
"@com_github_cockroachdb_redact//:redact",
"@com_github_dustin_go_humanize//:go-humanize",
],
Expand Down
7 changes: 4 additions & 3 deletions pkg/kv/kvserver/kvflowcontrol/kvflowcontrol.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/settings"
"github.com/cockroachdb/cockroach/pkg/settings/cluster"
"github.com/cockroachdb/cockroach/pkg/util/admission/admissionpb"
"github.com/cockroachdb/cockroach/pkg/util/ctxutil"
"github.com/cockroachdb/redact"
"github.com/dustin/go-humanize"
)
Expand Down Expand Up @@ -436,7 +437,7 @@ func (s Stream) SafeFormat(p redact.SafePrinter, verb rune) {
p.Printf("t%s/s%s", tenantSt, s.StoreID.String())
}

type raftAdmissionMetaKey struct{}
var raftAdmissionMetaKey = ctxutil.RegisterFastValueKey()

// ContextWithMeta returns a Context wrapping the supplied raft admission meta,
// if any.
Expand All @@ -445,15 +446,15 @@ type raftAdmissionMetaKey struct{}
// #104154.
func ContextWithMeta(ctx context.Context, meta *kvflowcontrolpb.RaftAdmissionMeta) context.Context {
if meta != nil {
ctx = context.WithValue(ctx, raftAdmissionMetaKey{}, meta)
ctx = ctxutil.WithFastValue(ctx, raftAdmissionMetaKey, meta)
}
return ctx
}

// MetaFromContext returns the raft admission meta embedded in the Context, if
// any.
func MetaFromContext(ctx context.Context) *kvflowcontrolpb.RaftAdmissionMeta {
val := ctx.Value(raftAdmissionMetaKey{})
val := ctxutil.FastValue(ctx, raftAdmissionMetaKey)
h, ok := val.(*kvflowcontrolpb.RaftAdmissionMeta)
if !ok {
return nil
Expand Down
11 changes: 9 additions & 2 deletions pkg/kv/kvserver/kvflowcontrol/rac2/range_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,8 @@ type RaftEvent struct {
// Entries contains the log entries to be written to storage.
Entries []raftpb.Entry
// MsgApps to followers. Only populated on the leader, when operating in
// MsgAppPush mode. This is informational, for bookkeeping in the callee.
// MsgAppPush mode. This is informational, for bookkeeping in the callee,
// which only looks at MsgApps with non-empty Entries.
//
// These MsgApps can be for entries in Entries, or for earlier ones.
// Typically, the MsgApps are ordered by entry index, and are a sequence of
Expand Down Expand Up @@ -436,7 +437,13 @@ func RaftEventFromMsgStorageAppendAndMsgApps(
event.Snap = appendMsg.Snapshot
event.Entries = appendMsg.Entries
}
if len(outboundMsgs) == 0 {
if len(outboundMsgs) == 0 || mode == MsgAppPull {
// MsgAppPull mode can have MsgApps with entries under some cases: (a)
// when the replica is in StateProbe, (b) stale MsgApps queued up inside
// Raft from when the replica was in StateProbe, even though it is now in
// StateReplicate. We ignore those in the RaftEvent created for the
// RangeController. They will get sent, but that is not the concern of the
// RACv2 code.
return event
}
// Clear the slices, to reuse slice allocations.
Expand Down
9 changes: 9 additions & 0 deletions pkg/kv/kvserver/kvflowcontrol/rac2/range_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1853,6 +1853,15 @@ func TestRaftEventFromMsgStorageAppendAndMsgAppsBasic(t *testing.T) {
})
require.Equal(t, []raftpb.Message{outboundMsgs[0], outboundMsgs[3], outboundMsgs[2]}, msgApps)
checkSnapAndMap(event)
// Outbound msgs contains MsgApps for followers, but they are ignored
// since in pull mode.
event = RaftEventFromMsgStorageAppendAndMsgApps(
MsgAppPull, 19, appendMsg, outboundMsgs, logSnap, msgAppScratch, infoMap)
require.Equal(t, uint64(10), event.Term)
require.Equal(t, appendMsg.Snapshot, event.Snap)
require.Equal(t, appendMsg.Entries, event.Entries)
require.Nil(t, event.MsgApps)
checkSnapAndMap(event)
}
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/server/testserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -2509,14 +2509,14 @@ func TestingMakeLoggingContexts(
appTenantID roachpb.TenantID,
) (sysContext, appContext context.Context) {
ctxSysTenant := context.Background()
ctxSysTenant = context.WithValue(ctxSysTenant, serverident.ServerIdentificationContextKey{}, &idProvider{
ctxSysTenant = serverident.ContextWithServerIdentification(ctxSysTenant, &idProvider{
tenantID: roachpb.SystemTenantID,
clusterID: &base.ClusterIDContainer{},
serverID: &base.NodeIDContainer{},
tenantName: roachpb.NewTenantNameContainer("system"),
})
ctxAppTenant := context.Background()
ctxAppTenant = context.WithValue(ctxAppTenant, serverident.ServerIdentificationContextKey{}, &idProvider{
ctxAppTenant = serverident.ContextWithServerIdentification(ctxAppTenant, &idProvider{
tenantID: appTenantID,
clusterID: &base.ClusterIDContainer{},
serverID: &base.NodeIDContainer{},
Expand Down
1 change: 1 addition & 0 deletions pkg/sql/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,7 @@ go_library(
"//pkg/util/collatedstring",
"//pkg/util/ctxgroup",
"//pkg/util/ctxlog",
"//pkg/util/ctxutil",
"//pkg/util/duration",
"//pkg/util/encoding",
"//pkg/util/encoding/csv",
Expand Down
17 changes: 7 additions & 10 deletions pkg/sql/conn_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/util/buildutil"
"github.com/cockroachdb/cockroach/pkg/util/cancelchecker"
"github.com/cockroachdb/cockroach/pkg/util/ctxlog"
"github.com/cockroachdb/cockroach/pkg/util/ctxutil"
"github.com/cockroachdb/cockroach/pkg/util/errorutil"
"github.com/cockroachdb/cockroach/pkg/util/fsm"
"github.com/cockroachdb/cockroach/pkg/util/hlc"
Expand Down Expand Up @@ -4714,38 +4715,34 @@ func (ps connExPrepStmtsAccessor) DeleteAll(ctx context.Context) {
)
}

// contextStatementKey is an empty type for the handle associated with the
// statement value (see context.Value).
type contextStatementKey struct{}
var contextStatementKey = ctxutil.RegisterFastValueKey()

// withStatement adds a SQL statement to the provided context. The statement
// will then be included in crash reports which use that context.
func withStatement(ctx context.Context, stmt tree.Statement) context.Context {
return context.WithValue(ctx, contextStatementKey{}, stmt)
return ctxutil.WithFastValue(ctx, contextStatementKey, stmt)
}

// statementFromCtx returns the statement value from a context, or nil if unset.
func statementFromCtx(ctx context.Context) tree.Statement {
stmt := ctx.Value(contextStatementKey{})
stmt := ctxutil.FastValue(ctx, contextStatementKey)
if stmt == nil {
return nil
}
return stmt.(tree.Statement)
}

// contextGistKey is an empty type for the handle associated with the
// gist value (see context.Value).
type contextPlanGistKey struct{}
var contextPlanGistKey = ctxutil.RegisterFastValueKey()

func withPlanGist(ctx context.Context, gist string) context.Context {
if gist == "" {
return ctx
}
return context.WithValue(ctx, contextPlanGistKey{}, gist)
return ctxutil.WithFastValue(ctx, contextPlanGistKey, gist)
}

func planGistFromCtx(ctx context.Context) string {
val := ctx.Value(contextPlanGistKey{})
val := ctxutil.FastValue(ctx, contextPlanGistKey)
if val != nil {
return val.(string)
}
Expand Down
Loading

0 comments on commit 92400bc

Please sign in to comment.