From 73bae4bedccace28f6083383a6565591107a331f Mon Sep 17 00:00:00 2001 From: Marylia Gutierrez Date: Wed, 17 Nov 2021 14:07:29 -0500 Subject: [PATCH 1/3] ui: save sort on cache for Transaction page Previously, a sort selection was not maintained when the page change (e.g. coming back from Transaction details). This commits saves the selected value to be used. Partially adressed #68199 Release note: None --- .../localStorage/localStorage.reducer.ts | 4 + .../transactionsPage/transactions.fixture.ts | 6 ++ .../transactionsPage.selectors.ts | 5 ++ .../transactionsPage.stories.tsx | 11 +++ .../src/transactionsPage/transactionsPage.tsx | 75 ++++++++++++------- .../transactionsPageConnected.tsx | 15 ++++ .../views/transactions/transactionsPage.tsx | 16 ++++ 7 files changed, 104 insertions(+), 28 deletions(-) diff --git a/pkg/ui/workspaces/cluster-ui/src/store/localStorage/localStorage.reducer.ts b/pkg/ui/workspaces/cluster-ui/src/store/localStorage/localStorage.reducer.ts index e28dbc27fda8..13b081781e4c 100644 --- a/pkg/ui/workspaces/cluster-ui/src/store/localStorage/localStorage.reducer.ts +++ b/pkg/ui/workspaces/cluster-ui/src/store/localStorage/localStorage.reducer.ts @@ -28,6 +28,7 @@ export type LocalStorageState = { "showColumns/TransactionPage": string; "dateRange/StatementsPage": StatementsDateRangeState; "sortSetting/StatementsPage": SortSetting; + "sortSetting/TransactionsPage": SortSetting; }; type Payload = { @@ -63,6 +64,9 @@ const initialState: LocalStorageState = { "sortSetting/StatementsPage": JSON.parse(localStorage.getItem("sortSetting/StatementsPage")) || defaultSortSetting, + "sortSetting/TransactionsPage": + JSON.parse(localStorage.getItem("sortSetting/TransactionsPage")) || + defaultSortSetting, }; const localStorageSlice = createSlice({ diff --git a/pkg/ui/workspaces/cluster-ui/src/transactionsPage/transactions.fixture.ts b/pkg/ui/workspaces/cluster-ui/src/transactionsPage/transactions.fixture.ts index f67cdd3874df..b921eca4921a 100644 --- a/pkg/ui/workspaces/cluster-ui/src/transactionsPage/transactions.fixture.ts +++ b/pkg/ui/workspaces/cluster-ui/src/transactionsPage/transactions.fixture.ts @@ -13,6 +13,7 @@ import { cockroach } from "@cockroachlabs/crdb-protobuf-client"; import Long from "long"; import moment from "moment"; import * as protos from "@cockroachlabs/crdb-protobuf-client"; +import { SortSetting } from "../sortedtable"; const history = createMemoryHistory({ initialEntries: ["/transactions"] }); @@ -47,6 +48,11 @@ export const timestamp = new protos.google.protobuf.Timestamp({ seconds: new Long(Date.parse("Sep 15 2021 01:00:00 GMT") * 1e-3), }); +export const sortSetting: SortSetting = { + ascending: false, + columnTitle: "executionCount", +}; + export const data: cockroach.server.serverpb.IStatementsResponse = { statements: [ { diff --git a/pkg/ui/workspaces/cluster-ui/src/transactionsPage/transactionsPage.selectors.ts b/pkg/ui/workspaces/cluster-ui/src/transactionsPage/transactionsPage.selectors.ts index 4698f1161897..2846fb33fe33 100644 --- a/pkg/ui/workspaces/cluster-ui/src/transactionsPage/transactionsPage.selectors.ts +++ b/pkg/ui/workspaces/cluster-ui/src/transactionsPage/transactionsPage.selectors.ts @@ -40,3 +40,8 @@ export const selectTxnColumns = createSelector( ? localStorage["showColumns/TransactionPage"].split(",") : null, ); + +export const selectSortSetting = createSelector( + localStorageSelector, + localStorage => localStorage["sortSetting/TransactionsPage"], +); diff --git a/pkg/ui/workspaces/cluster-ui/src/transactionsPage/transactionsPage.stories.tsx b/pkg/ui/workspaces/cluster-ui/src/transactionsPage/transactionsPage.stories.tsx index e7f6d93c7b0f..a879289e3829 100644 --- a/pkg/ui/workspaces/cluster-ui/src/transactionsPage/transactionsPage.stories.tsx +++ b/pkg/ui/workspaces/cluster-ui/src/transactionsPage/transactionsPage.stories.tsx @@ -17,6 +17,7 @@ import { nodeRegions, routeProps, dateRange, + sortSetting, } from "./transactions.fixture"; import { TransactionsPage } from "."; @@ -38,6 +39,8 @@ storiesOf("Transactions Page", module) nodeRegions={nodeRegions} refreshData={noop} resetSQLStats={noop} + sortSetting={sortSetting} + onSortingChange={noop} /> )) .add("without data", () => { @@ -49,6 +52,8 @@ storiesOf("Transactions Page", module) nodeRegions={nodeRegions} refreshData={noop} resetSQLStats={noop} + sortSetting={sortSetting} + onSortingChange={noop} /> ); }) @@ -68,6 +73,8 @@ storiesOf("Transactions Page", module) refreshData={noop} history={history} resetSQLStats={noop} + sortSetting={sortSetting} + onSortingChange={noop} /> ); }) @@ -80,6 +87,8 @@ storiesOf("Transactions Page", module) nodeRegions={nodeRegions} refreshData={noop} resetSQLStats={noop} + sortSetting={sortSetting} + onSortingChange={noop} /> ); }) @@ -99,6 +108,8 @@ storiesOf("Transactions Page", module) } refreshData={noop} resetSQLStats={noop} + sortSetting={sortSetting} + onSortingChange={noop} /> ); }); diff --git a/pkg/ui/workspaces/cluster-ui/src/transactionsPage/transactionsPage.tsx b/pkg/ui/workspaces/cluster-ui/src/transactionsPage/transactionsPage.tsx index da33cb64bbe2..563a219026d2 100644 --- a/pkg/ui/workspaces/cluster-ui/src/transactionsPage/transactionsPage.tsx +++ b/pkg/ui/workspaces/cluster-ui/src/transactionsPage/transactionsPage.tsx @@ -69,7 +69,6 @@ type Timestamp = protos.google.protobuf.ITimestamp; const cx = classNames.bind(styles); interface TState { - sortSetting: SortSetting; pagination: ISortedTablePagination; search?: string; filters?: Filters; @@ -87,6 +86,7 @@ export interface TransactionsPageStateProps { pageSize?: number; isTenant?: UIConfigState["isTenant"]; columns: string[]; + sortSetting: SortSetting; } export interface TransactionsPageDispatchProps { @@ -94,6 +94,11 @@ export interface TransactionsPageDispatchProps { resetSQLStats: () => void; onDateRangeChange?: (start: Moment, end: Moment) => void; onColumnsChange?: (selectedColumns: string[]) => void; + onSortingChange?: ( + name: string, + columnTitle: string, + ascending: boolean, + ) => void; } export type TransactionsPageProps = TransactionsPageStateProps & @@ -113,33 +118,46 @@ export class TransactionsPage extends React.Component< TransactionsPageProps, TState > { + constructor(props: TransactionsPageProps) { + super(props); + const filters = getFiltersFromQueryString( + this.props.history.location.search, + ); + + const trxSearchParams = getSearchParams(this.props.history.location.search); + this.state = { + pagination: { + pageSize: this.props.pageSize || 20, + current: 1, + }, + search: trxSearchParams("q", "").toString(), + filters: filters, + aggregatedTs: null, + statementFingerprintIds: null, + transactionStats: null, + transactionFingerprintId: null, + }; + + const ascending = trxSearchParams("ascending", false).toString() === "true"; + const columnTitle = trxSearchParams("columnTitle", undefined); + if ( + this.props.onSortingChange && + columnTitle && + (this.props.sortSetting.columnTitle != columnTitle || + this.props.sortSetting.ascending != ascending) + ) { + this.props.onSortingChange( + "Transactions", + columnTitle.toString(), + ascending, + ); + } + } + static defaultProps: Partial = { isTenant: false, }; - trxSearchParams = getSearchParams(this.props.history.location.search); - filters = getFiltersFromQueryString(this.props.history.location.search); - state: TState = { - sortSetting: { - // Sort by Execution Count column as default option. - ascending: this.trxSearchParams("ascending", false).toString() === "true", - columnTitle: this.trxSearchParams( - "columnTitle", - "execution count", - ).toString(), - }, - pagination: { - pageSize: this.props.pageSize || 20, - current: 1, - }, - search: this.trxSearchParams("q", "").toString(), - filters: this.filters, - aggregatedTs: null, - statementFingerprintIds: null, - transactionStats: null, - transactionFingerprintId: null, - }; - refreshData = (): void => { const req = statementsRequestFromProps(this.props); this.props.refreshData(req); @@ -153,9 +171,6 @@ export class TransactionsPage extends React.Component< } onChangeSortSetting = (ss: SortSetting): void => { - this.setState({ - sortSetting: ss, - }); syncHistory( { ascending: ss.ascending.toString(), @@ -163,6 +178,9 @@ export class TransactionsPage extends React.Component< }, this.props.history, ); + if (this.props.onSortingChange) { + this.props.onSortingChange("Transactions", ss.columnTitle, ss.ascending); + } }; onChangePage = (current: number): void => { @@ -284,6 +302,7 @@ export class TransactionsPage extends React.Component< isTenant, onColumnsChange, columns: userSelectedColumnsToShow, + sortSetting, } = this.props; const { pagination, search, filters } = this.state; const { statements, internal_app_name_prefix } = data; @@ -435,7 +454,7 @@ export class TransactionsPage extends React.Component< ({ refreshData: (req?: StatementsRequest) => @@ -71,6 +74,18 @@ export const TransactionsPageConnected = withRouter( selectedColumns.length === 0 ? " " : selectedColumns.join(","), }), ), + onSortingChange: ( + tableName: string, + columnName: string, + ascending: boolean, + ) => { + dispatch( + localStorageActions.update({ + key: "sortSetting/TransactionsPage", + value: { columnTitle: columnName, ascending: ascending }, + }), + ); + }, }), )(TransactionsPage), ); diff --git a/pkg/ui/workspaces/db-console/src/views/transactions/transactionsPage.tsx b/pkg/ui/workspaces/db-console/src/views/transactions/transactionsPage.tsx index cdca22bcf004..e82bddd2a8f9 100644 --- a/pkg/ui/workspaces/db-console/src/views/transactions/transactionsPage.tsx +++ b/pkg/ui/workspaces/db-console/src/views/transactions/transactionsPage.tsx @@ -62,6 +62,12 @@ export const selectDateRange = createSelector( }, ); +export const sortSettingLocalSetting = new LocalSetting( + "sortSetting/TransactionsPage", + (state: AdminUIState) => state.localSettings, + { ascending: false, columnTitle: "executionCount" }, +); + export const transactionColumnsLocalSetting = new LocalSetting( "showColumns/TransactionPage", (state: AdminUIState) => state.localSettings, @@ -78,6 +84,7 @@ const TransactionsPageConnected = withRouter( error: selectLastError(state), nodeRegions: nodeRegionsByIDSelector(state), columns: transactionColumnsLocalSetting.selectorToArray(state), + sortSetting: sortSettingLocalSetting.selector(state), }), { refreshData: refreshStatements, @@ -91,6 +98,15 @@ const TransactionsPageConnected = withRouter( transactionColumnsLocalSetting.set( value.length === 0 ? " " : value.join(","), ), + onSortingChange: ( + _tableName: string, + columnName: string, + ascending: boolean, + ) => + sortSettingLocalSetting.set({ + ascending: ascending, + columnTitle: columnName, + }), }, )(TransactionsPage), ); From f606f150c132e9d4dfa1bc849b64d873d3f7ab08 Mon Sep 17 00:00:00 2001 From: Ricky Stewart Date: Tue, 16 Nov 2021 15:17:32 -0600 Subject: [PATCH 2/3] bazel: don't use different `gotags` for test and non-test scenarios In a couple different places in-tree we use the build tags `crdb_test` and `crdb_test_off` to support conditional compilation. Unfortunately, this results in low cache utilization when swapping between builds and tests, since recompiling with different `gotags` causes Bazel to recompile EVERYTHING, including the entire standard library, with these different tags. This means that you can't build `cockroach` and then run a quick test using cached build artifacts, for example. Fix this by adding a new configuration, `//build/toolchains:crdb_test`. We use `select()` in `pkg/util/buildutil/BUILD.bazel` to choose between `crdb_test_on.go` and `crdb_test_off.go` accordingly. Also add logic to `build/bazelutil/check.sh` to detect new uses of these build constraints and warn people that the logic also needs to be Bazelfied. Closes #71857. Release note: None --- .bazelrc | 4 +- BUILD.bazel | 5 +- build/bazelutil/check.sh | 21 ++++++++- build/toolchains/BUILD.bazel | 37 +++++++++++++++ pkg/BUILD.bazel | 1 + .../tenantcostserver/BUILD.bazel | 2 +- .../tenantcostserver/system_table.go | 4 +- pkg/col/coldata/BUILD.bazel | 1 + pkg/col/coldata/bytes.go | 4 +- pkg/sql/BUILD.bazel | 1 + pkg/sql/colexec/BUILD.bazel | 1 + pkg/sql/colexec/colbuilder/BUILD.bazel | 1 + pkg/sql/colexec/colbuilder/execplan.go | 9 ++-- pkg/sql/colexec/columnarizer.go | 6 +-- pkg/sql/colexec/invariants_checker.go | 4 +- pkg/sql/colflow/BUILD.bazel | 3 +- pkg/sql/colflow/stats.go | 4 +- pkg/sql/colflow/vectorized_flow.go | 13 ++--- .../colflow/vectorized_flow_planning_test.go | 6 +-- pkg/sql/conn_executor.go | 5 +- pkg/sql/execinfra/BUILD.bazel | 1 + pkg/sql/execinfra/processorsbase.go | 3 +- pkg/sql/execinfrapb/BUILD.bazel | 1 + pkg/sql/execinfrapb/data.go | 4 +- pkg/sql/execstats/BUILD.bazel | 1 + pkg/sql/execstats/traceanalyzer.go | 3 +- pkg/sql/explain_plan.go | 4 +- pkg/sql/instrumentation.go | 5 +- pkg/sql/opt/BUILD.bazel | 1 + pkg/sql/opt/colset.go | 3 +- pkg/sql/opt/exec/execbuilder/BUILD.bazel | 1 + pkg/sql/opt/exec/execbuilder/relational.go | 3 +- pkg/sql/opt/memo/BUILD.bazel | 3 +- pkg/sql/opt/memo/check_expr.go | 8 ++-- .../opt/memo/filters_expr_mutate_checker.go | 14 ++++-- .../memo/filters_expr_mutate_checker_skip.go | 26 ---------- pkg/sql/opt/memo/logical_props_builder.go | 4 +- pkg/sql/opt/norm/BUILD.bazel | 1 + pkg/sql/opt/norm/factory.go | 6 +-- pkg/sql/opt/ordering/BUILD.bazel | 2 +- pkg/sql/opt/ordering/ordering.go | 8 ++-- pkg/sql/opt/props/BUILD.bazel | 1 + pkg/sql/opt/props/verify.go | 19 ++++++-- pkg/sql/opt/table_meta.go | 4 +- pkg/sql/opt/xform/BUILD.bazel | 1 + pkg/sql/opt/xform/placeholder_fast_path.go | 4 +- pkg/util/BUILD.bazel | 3 +- pkg/util/buildutil/BUILD.bazel | 47 +++++++++++++++++++ pkg/util/buildutil/crdb_test_dyn.go | 31 ++++++++++++ pkg/util/{ => buildutil}/crdb_test_off.go | 2 +- pkg/util/{ => buildutil}/crdb_test_on.go | 2 +- .../buildutil/crdb_test_test.go} | 17 ++++--- pkg/util/constants.go | 3 +- 53 files changed, 262 insertions(+), 106 deletions(-) delete mode 100644 pkg/sql/opt/memo/filters_expr_mutate_checker_skip.go create mode 100644 pkg/util/buildutil/BUILD.bazel create mode 100644 pkg/util/buildutil/crdb_test_dyn.go rename pkg/util/{ => buildutil}/crdb_test_off.go (97%) rename pkg/util/{ => buildutil}/crdb_test_on.go (97%) rename pkg/{sql/opt/memo/check_expr_skip.go => util/buildutil/crdb_test_test.go} (55%) diff --git a/.bazelrc b/.bazelrc index 4ab6de70abb8..3d399c52abe7 100644 --- a/.bazelrc +++ b/.bazelrc @@ -1,9 +1,9 @@ try-import %workspace%/.bazelrc.user -build --symlink_prefix=_bazel/ --ui_event_filters=-DEBUG --define gotags=bazel,crdb_test_off,gss --experimental_proto_descriptor_sets_include_source_info --incompatible_strict_action_env +build --symlink_prefix=_bazel/ --ui_event_filters=-DEBUG --define gotags=bazel,gss --experimental_proto_descriptor_sets_include_source_info --incompatible_strict_action_env test --config=test build:with_ui --define cockroach_with_ui=y -build:test --define gotags=bazel,crdb_test,gss +build:test --define crdb_test=y build:race --@io_bazel_rules_go//go/config:race --test_env=GORACE=halt_on_error=1 --test_sharding_strategy=disabled test:test --test_env=TZ= query --ui_event_filters=-DEBUG diff --git a/BUILD.bazel b/BUILD.bazel index 82464631d122..fd152a261aba 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -18,7 +18,7 @@ load("@bazel_gazelle//:def.bzl", "gazelle") # # gazelle:prefix github.com/cockroachdb/cockroach # gazelle:build_file_name BUILD.bazel -# gazelle:build_tags bazel,crdb_test,crdb_test_off,fast_int_set_small,fast_int_set_large,gss +# gazelle:build_tags bazel,fast_int_set_small,fast_int_set_large,gss # Enable protobuf generation. # @@ -126,6 +126,9 @@ load("@bazel_gazelle//:def.bzl", "gazelle") # gazelle:exclude pkg/**/*_string.go # gazelle:exclude pkg/ui/distccl/distccl_no_bazel.go # gazelle:exclude pkg/ui/distoss/distoss_no_bazel.go +# gazelle:exclude pkg/util/buildutil/crdb_test_dyn.go +# gazelle:exclude pkg/util/buildutil/crdb_test_off.go +# gazelle:exclude pkg/util/buildutil/crdb_test_on.go # # Generally useful references: # diff --git a/build/bazelutil/check.sh b/build/bazelutil/check.sh index a11d2e10aec4..dc98d6731b38 100755 --- a/build/bazelutil/check.sh +++ b/build/bazelutil/check.sh @@ -48,6 +48,12 @@ pkg/cmd/roachtest/BUILD.bazel pkg/cmd/teamcity-trigger/BUILD.bazel " +EXISTING_CRDB_TEST_BUILD_CONSTRAINTS=" +pkg/util/buildutil/crdb_test_dyn.go://go:build bazel +pkg/util/buildutil/crdb_test_off.go://go:build !crdb_test || crdb_test_off +pkg/util/buildutil/crdb_test_on.go://go:build crdb_test && !crdb_test_off +" + git grep 'go:generate stringer' pkg | while read LINE; do dir=$(dirname $(echo $LINE | cut -d: -f1)) type=$(echo $LINE | grep -o -- '-type[= ][^ ]*' | sed 's/-type[= ]//g' | awk '{print tolower($0)}') @@ -85,4 +91,17 @@ git grep 'broken_in_bazel' pkg | grep BUILD.bazel: | grep -v pkg/BUILD.bazel | g echo "A new broken test in Bazel was added in $LINE" echo 'Ensure the test runs with Bazel, then remove the broken_in_bazel tag.' exit 1 -done \ No newline at end of file +done + +git grep '//go:build' pkg | grep crdb_test | while read LINE; do + if [[ "$EXISTING_CRDB_TEST_BUILD_CONSTRAINTS" == *"$LINE"* ]]; then + # Grandfathered. + continue + fi + echo "A new crdb_test/crdb_test_off build constraint was added in $LINE" + echo 'Make sure you port the conditional compilation logic to the Bazel build,' + echo 'which does not use the build tags in the same way.' + echo "Once you've done so, you can add the line to " + echo 'EXISTING_CRDB_TEST_BUILD_CONSTRAINTS in build/bazelutil/check.sh.' + exit 1 +done diff --git a/build/toolchains/BUILD.bazel b/build/toolchains/BUILD.bazel index b3f922d41b79..be404767d38b 100644 --- a/build/toolchains/BUILD.bazel +++ b/build/toolchains/BUILD.bazel @@ -86,6 +86,26 @@ platform( ], ) +config_setting( + name = "dbg_crdb_test", + define_values = { + "crdb_test": "y", + }, + values = { + "compilation_mode": "dbg", + }, +) + +config_setting( + name = "fastbuild_crdb_test", + define_values = { + "crdb_test": "y", + }, + values = { + "compilation_mode": "fastbuild", + }, +) + config_setting( name = "dev", define_values = { @@ -112,3 +132,20 @@ config_setting( "cockroach_cross": "y", }, ) + +config_setting( + name = "opt_crdb_test", + define_values = { + "crdb_test": "y", + }, + values = { + "compilation_mode": "opt", + }, +) + +config_setting( + name = "opt", + values = { + "compilation_mode": "opt", + }, +) diff --git a/pkg/BUILD.bazel b/pkg/BUILD.bazel index 3fba402f4f5d..0f09e34dd432 100644 --- a/pkg/BUILD.bazel +++ b/pkg/BUILD.bazel @@ -347,6 +347,7 @@ ALL_TESTS = [ "//pkg/util/admission:admission_test", "//pkg/util/binfetcher:binfetcher_test", "//pkg/util/bitarray:bitarray_test", + "//pkg/util/buildutil:buildutil_test", "//pkg/util/cache:cache_test", "//pkg/util/caller:caller_test", "//pkg/util/cgroups:cgroups_test", diff --git a/pkg/ccl/multitenantccl/tenantcostserver/BUILD.bazel b/pkg/ccl/multitenantccl/tenantcostserver/BUILD.bazel index 950ae76c9ba8..294e6ac7d278 100644 --- a/pkg/ccl/multitenantccl/tenantcostserver/BUILD.bazel +++ b/pkg/ccl/multitenantccl/tenantcostserver/BUILD.bazel @@ -25,7 +25,7 @@ go_library( "//pkg/sql/pgwire/pgerror", "//pkg/sql/sem/tree", "//pkg/sql/sessiondata", - "//pkg/util", + "//pkg/util/buildutil", "//pkg/util/log", "//pkg/util/metric", "//pkg/util/metric/aggmetric", diff --git a/pkg/ccl/multitenantccl/tenantcostserver/system_table.go b/pkg/ccl/multitenantccl/tenantcostserver/system_table.go index 263af840e4bf..0ff339fc3c61 100644 --- a/pkg/ccl/multitenantccl/tenantcostserver/system_table.go +++ b/pkg/ccl/multitenantccl/tenantcostserver/system_table.go @@ -23,7 +23,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/sql" "github.com/cockroachdb/cockroach/pkg/sql/sem/tree" "github.com/cockroachdb/cockroach/pkg/sql/sessiondata" - "github.com/cockroachdb/cockroach/pkg/util" + "github.com/cockroachdb/cockroach/pkg/util/buildutil" "github.com/cockroachdb/cockroach/pkg/util/log" "github.com/cockroachdb/cockroach/pkg/util/protoutil" "github.com/cockroachdb/errors" @@ -439,7 +439,7 @@ func (h *sysTableHelper) maybeCleanupStaleInstances( // maybeCheckInvariants checks the invariants for the system table with a random // probability and only if this is a test build. func (h *sysTableHelper) maybeCheckInvariants() error { - if util.CrdbTestBuild && rand.Intn(10) == 0 { + if buildutil.CrdbTestBuild && rand.Intn(10) == 0 { return h.checkInvariants() } return nil diff --git a/pkg/col/coldata/BUILD.bazel b/pkg/col/coldata/BUILD.bazel index 119f2cc8db11..f8fe780e140b 100644 --- a/pkg/col/coldata/BUILD.bazel +++ b/pkg/col/coldata/BUILD.bazel @@ -21,6 +21,7 @@ go_library( "//pkg/sql/memsize", "//pkg/sql/types", "//pkg/util", + "//pkg/util/buildutil", "//pkg/util/duration", "//pkg/util/json", "//pkg/util/uuid", diff --git a/pkg/col/coldata/bytes.go b/pkg/col/coldata/bytes.go index 4f3f607f673d..a78928628e20 100644 --- a/pkg/col/coldata/bytes.go +++ b/pkg/col/coldata/bytes.go @@ -19,7 +19,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/sql/colexecerror" "github.com/cockroachdb/cockroach/pkg/sql/memsize" "github.com/cockroachdb/cockroach/pkg/sql/types" - "github.com/cockroachdb/cockroach/pkg/util" + "github.com/cockroachdb/cockroach/pkg/util/buildutil" "github.com/cockroachdb/errors" ) @@ -135,7 +135,7 @@ func (b *Bytes) Get(i int) []byte { // This method will panic if i is less than maximum previously Set index. //gcassert:inline func (b *Bytes) getAppendTo(i int) []byte { - if util.CrdbTestBuild { + if buildutil.CrdbTestBuild { if b.isWindow { panic("getAppendTo is called on a window into Bytes") } diff --git a/pkg/sql/BUILD.bazel b/pkg/sql/BUILD.bazel index 4423149cdb21..5c6318c11407 100644 --- a/pkg/sql/BUILD.bazel +++ b/pkg/sql/BUILD.bazel @@ -382,6 +382,7 @@ go_library( "//pkg/util", "//pkg/util/admission", "//pkg/util/bitarray", + "//pkg/util/buildutil", "//pkg/util/cancelchecker", "//pkg/util/contextutil", "//pkg/util/ctxgroup", diff --git a/pkg/sql/colexec/BUILD.bazel b/pkg/sql/colexec/BUILD.bazel index d0eeccca566d..8586b09d9e3d 100644 --- a/pkg/sql/colexec/BUILD.bazel +++ b/pkg/sql/colexec/BUILD.bazel @@ -71,6 +71,7 @@ go_library( "//pkg/sql/sqltelemetry", # keep "//pkg/sql/types", "//pkg/util", + "//pkg/util/buildutil", "//pkg/util/duration", # keep "//pkg/util/encoding", # keep "//pkg/util/humanizeutil", diff --git a/pkg/sql/colexec/colbuilder/BUILD.bazel b/pkg/sql/colexec/colbuilder/BUILD.bazel index 1b4b378e2149..f05cf71b70ef 100644 --- a/pkg/sql/colexec/colbuilder/BUILD.bazel +++ b/pkg/sql/colexec/colbuilder/BUILD.bazel @@ -31,6 +31,7 @@ go_library( "//pkg/sql/sessiondatapb", "//pkg/sql/types", "//pkg/util", + "//pkg/util/buildutil", "//pkg/util/log", "//pkg/util/mon", "@com_github_cockroachdb_errors//:errors", diff --git a/pkg/sql/colexec/colbuilder/execplan.go b/pkg/sql/colexec/colbuilder/execplan.go index 481a4e11de59..6d0c8dfbb8b1 100644 --- a/pkg/sql/colexec/colbuilder/execplan.go +++ b/pkg/sql/colexec/colbuilder/execplan.go @@ -40,6 +40,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/sql/sessiondatapb" "github.com/cockroachdb/cockroach/pkg/sql/types" "github.com/cockroachdb/cockroach/pkg/util" + "github.com/cockroachdb/cockroach/pkg/util/buildutil" "github.com/cockroachdb/cockroach/pkg/util/log" "github.com/cockroachdb/cockroach/pkg/util/mon" "github.com/cockroachdb/errors" @@ -589,7 +590,7 @@ func (r opResult) createAndWrapRowSource( } r.Root = c r.Columnarizer = c - if util.CrdbTestBuild { + if buildutil.CrdbTestBuild { r.Root = colexec.NewInvariantsChecker(r.Root) } takeOverMetaInfo(&r.OpWithMetaInfo, inputs) @@ -606,7 +607,7 @@ func (r opResult) createAndWrapRowSource( // nil is returned. func MaybeRemoveRootColumnarizer(r colexecargs.OpWithMetaInfo) execinfra.RowSource { root := r.Root - if util.CrdbTestBuild { + if buildutil.CrdbTestBuild { // We might have an invariants checker as the root right now, we gotta // peek inside of it if so. root = colexec.MaybeUnwrapInvariantsChecker(root) @@ -1515,7 +1516,7 @@ func NewColOperator( } takeOverMetaInfo(&result.OpWithMetaInfo, inputs) - if util.CrdbTestBuild { + if buildutil.CrdbTestBuild { // Plan an invariants checker if it isn't already the root of the // tree. if i := colexec.MaybeUnwrapInvariantsChecker(r.Root); i == r.Root { @@ -1674,7 +1675,7 @@ func (r opResult) finishBufferedWindowerArgs( func (r opResult) finishScanPlanning(op colfetcher.ScanOperator, resultTypes []*types.T) { r.Root = op - if util.CrdbTestBuild { + if buildutil.CrdbTestBuild { r.Root = colexec.NewInvariantsChecker(r.Root) } r.KVReader = op diff --git a/pkg/sql/colexec/columnarizer.go b/pkg/sql/colexec/columnarizer.go index adc74175a033..a8d0d387c8ca 100644 --- a/pkg/sql/colexec/columnarizer.go +++ b/pkg/sql/colexec/columnarizer.go @@ -21,7 +21,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/sql/execinfrapb" "github.com/cockroachdb/cockroach/pkg/sql/rowenc" "github.com/cockroachdb/cockroach/pkg/sql/types" - "github.com/cockroachdb/cockroach/pkg/util" + "github.com/cockroachdb/cockroach/pkg/util/buildutil" "github.com/cockroachdb/errors" ) @@ -126,7 +126,7 @@ func newColumnarizer( // Close will call InternalClose(). Note that we don't return // any trailing metadata here because the columnarizers // propagate it in DrainMeta. - if err := c.Close(); util.CrdbTestBuild && err != nil { + if err := c.Close(); buildutil.CrdbTestBuild && err != nil { // Close never returns an error. colexecerror.InternalError(errors.AssertionFailedf("unexpected error %v from Columnarizer.Close", err)) } @@ -167,7 +167,7 @@ func (c *Columnarizer) Init(ctx context.Context) { // GetStats is part of the colexecop.VectorizedStatsCollector interface. func (c *Columnarizer) GetStats() *execinfrapb.ComponentStats { - if c.removedFromFlow && util.CrdbTestBuild { + if c.removedFromFlow && buildutil.CrdbTestBuild { colexecerror.InternalError(errors.AssertionFailedf( "unexpectedly the columnarizer was removed from the flow when stats are being collected", )) diff --git a/pkg/sql/colexec/invariants_checker.go b/pkg/sql/colexec/invariants_checker.go index 97548a7f738e..230e13c89d14 100644 --- a/pkg/sql/colexec/invariants_checker.go +++ b/pkg/sql/colexec/invariants_checker.go @@ -17,7 +17,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/sql/colexecerror" "github.com/cockroachdb/cockroach/pkg/sql/colexecop" "github.com/cockroachdb/cockroach/pkg/sql/execinfrapb" - "github.com/cockroachdb/cockroach/pkg/util" + "github.com/cockroachdb/cockroach/pkg/util/buildutil" "github.com/cockroachdb/errors" ) @@ -37,7 +37,7 @@ var _ colexecop.ClosableOperator = &invariantsChecker{} // NewInvariantsChecker creates a new invariantsChecker. func NewInvariantsChecker(input colexecop.Operator) colexecop.DrainableOperator { - if !util.CrdbTestBuild { + if !buildutil.CrdbTestBuild { colexecerror.InternalError(errors.AssertionFailedf( "an invariantsChecker is attempted to be created in non-test build", )) diff --git a/pkg/sql/colflow/BUILD.bazel b/pkg/sql/colflow/BUILD.bazel index 2f37f1090746..68d931945542 100644 --- a/pkg/sql/colflow/BUILD.bazel +++ b/pkg/sql/colflow/BUILD.bazel @@ -38,6 +38,7 @@ go_library( "//pkg/sql/types", "//pkg/util", "//pkg/util/admission", + "//pkg/util/buildutil", "//pkg/util/log", "//pkg/util/metric", "//pkg/util/mon", @@ -112,8 +113,8 @@ go_test( "//pkg/testutils/skip", "//pkg/testutils/sqlutils", "//pkg/testutils/testcluster", - "//pkg/util", "//pkg/util/admission", + "//pkg/util/buildutil", "//pkg/util/hlc", "//pkg/util/humanizeutil", "//pkg/util/leaktest", diff --git a/pkg/sql/colflow/stats.go b/pkg/sql/colflow/stats.go index f2d73d5b3dec..e1ffb1973824 100644 --- a/pkg/sql/colflow/stats.go +++ b/pkg/sql/colflow/stats.go @@ -21,7 +21,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/sql/colflow/colrpc" "github.com/cockroachdb/cockroach/pkg/sql/execinfra" "github.com/cockroachdb/cockroach/pkg/sql/execinfrapb" - "github.com/cockroachdb/cockroach/pkg/util" + "github.com/cockroachdb/cockroach/pkg/util/buildutil" "github.com/cockroachdb/cockroach/pkg/util/mon" "github.com/cockroachdb/cockroach/pkg/util/syncutil" "github.com/cockroachdb/cockroach/pkg/util/timeutil" @@ -287,7 +287,7 @@ func (nvsc *networkVectorizedStatsCollectorImpl) GetStats() *execinfrapb.Compone // specified. See comment on statsInvariantChecker for the kind of invariants // checked. func maybeAddStatsInvariantChecker(op *colexecargs.OpWithMetaInfo) { - if util.CrdbTestBuild { + if buildutil.CrdbTestBuild { c := &statsInvariantChecker{} op.StatsCollectors = append(op.StatsCollectors, c) op.MetadataSources = append(op.MetadataSources, c) diff --git a/pkg/sql/colflow/vectorized_flow.go b/pkg/sql/colflow/vectorized_flow.go index b2ac6905ac2e..907b79b66d98 100644 --- a/pkg/sql/colflow/vectorized_flow.go +++ b/pkg/sql/colflow/vectorized_flow.go @@ -41,6 +41,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/sql/types" "github.com/cockroachdb/cockroach/pkg/util" "github.com/cockroachdb/cockroach/pkg/util/admission" + "github.com/cockroachdb/cockroach/pkg/util/buildutil" "github.com/cockroachdb/cockroach/pkg/util/log" "github.com/cockroachdb/cockroach/pkg/util/metric" "github.com/cockroachdb/cockroach/pkg/util/mon" @@ -309,7 +310,7 @@ func (f *vectorizedFlow) Cleanup(ctx context.Context) { // This cleans up all the memory and disk monitoring of the vectorized flow. f.creator.cleanup(ctx) - if util.CrdbTestBuild && f.FlowBase.Started() { + if buildutil.CrdbTestBuild && f.FlowBase.Started() { // Check that all closers have been closed. Note that we don't check // this in case the flow was never started in the first place (it is ok // to not check this since closers haven't allocated any resources in @@ -746,7 +747,7 @@ func (s *vectorizedFlowCreator) setupRouter( foundLocalOutput := false for i, op := range outputs { - if util.CrdbTestBuild { + if buildutil.CrdbTestBuild { op = colexec.NewInvariantsChecker(op) } stream := &output.Streams[i] @@ -855,7 +856,7 @@ func (s *vectorizedFlowCreator) setupInput( s.addStreamEndpoint(inputStream.StreamID, inbox, s.waitGroup) op := colexecop.Operator(inbox) ms := colexecop.MetadataSource(inbox) - if util.CrdbTestBuild { + if buildutil.CrdbTestBuild { op = colexec.NewInvariantsChecker(op) ms = op.(colexecop.MetadataSource) } @@ -914,7 +915,7 @@ func (s *vectorizedFlowCreator) setupInput( // instead. statsInputs = nil } - if util.CrdbTestBuild { + if buildutil.CrdbTestBuild { opWithMetaInfo.Root = colexec.NewInvariantsChecker(opWithMetaInfo.Root) opWithMetaInfo.MetadataSources[0] = opWithMetaInfo.Root.(colexecop.MetadataSource) } @@ -1000,7 +1001,7 @@ func (s *vectorizedFlowCreator) setupOutput( // We need to use the row receiving output. if input != nil { // We successfully removed the columnarizer. - if util.CrdbTestBuild { + if buildutil.CrdbTestBuild { // That columnarizer was added as a closer, so we need to // decrement the number of expected closers. s.numClosers-- @@ -1127,7 +1128,7 @@ func (s *vectorizedFlowCreator) setupFlow( if flowCtx.EvalCtx.SessionData().TestingVectorizeInjectPanics { result.Root = newPanicInjector(result.Root) } - if util.CrdbTestBuild { + if buildutil.CrdbTestBuild { toCloseCopy := append(colexecop.Closers{}, result.ToClose...) for i := range toCloseCopy { func(idx int) { diff --git a/pkg/sql/colflow/vectorized_flow_planning_test.go b/pkg/sql/colflow/vectorized_flow_planning_test.go index ac55145240e6..958f93c7739a 100644 --- a/pkg/sql/colflow/vectorized_flow_planning_test.go +++ b/pkg/sql/colflow/vectorized_flow_planning_test.go @@ -16,7 +16,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/base" "github.com/cockroachdb/cockroach/pkg/testutils/testcluster" - "github.com/cockroachdb/cockroach/pkg/util" + "github.com/cockroachdb/cockroach/pkg/util/buildutil" "github.com/cockroachdb/cockroach/pkg/util/leaktest" "github.com/cockroachdb/cockroach/pkg/util/log" "github.com/stretchr/testify/require" @@ -34,9 +34,9 @@ func TestVectorizedPlanning(t *testing.T) { conn := tc.Conns[0] t.Run("no columnarizer-materializer", func(t *testing.T) { - if !util.CrdbTestBuild { + if !buildutil.CrdbTestBuild { // The expected output below assumes that the invariants checkers - // are present which are planned only when util.CrdbTestBuild is + // are present which are planned only when buildutil.CrdbTestBuild is // true; if it isn't, we skip this test. return } diff --git a/pkg/sql/conn_executor.go b/pkg/sql/conn_executor.go index f45aef6b06eb..7ba094655d7d 100644 --- a/pkg/sql/conn_executor.go +++ b/pkg/sql/conn_executor.go @@ -54,6 +54,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/sql/sqlstats/sslocal" "github.com/cockroachdb/cockroach/pkg/sql/stmtdiagnostics" "github.com/cockroachdb/cockroach/pkg/util" + "github.com/cockroachdb/cockroach/pkg/util/buildutil" "github.com/cockroachdb/cockroach/pkg/util/envutil" "github.com/cockroachdb/cockroach/pkg/util/errorutil" "github.com/cockroachdb/cockroach/pkg/util/fsm" @@ -1006,11 +1007,11 @@ func (ex *connExecutor) close(ctx context.Context, closeType closeType) { case stateCommitWait: ex.state.finishSQLTxn() default: - if util.CrdbTestBuild { + if buildutil.CrdbTestBuild { panic(errors.AssertionFailedf("unexpected state in conn executor after ApplyWithPayload %T", t)) } } - if util.CrdbTestBuild && ex.state.Ctx != nil { + if buildutil.CrdbTestBuild && ex.state.Ctx != nil { panic(errors.AssertionFailedf("txn span not closed in state %s", ex.machine.CurState())) } } else if closeType == externalTxnClose { diff --git a/pkg/sql/execinfra/BUILD.bazel b/pkg/sql/execinfra/BUILD.bazel index ad9158bb0b86..a66e7b4d930d 100644 --- a/pkg/sql/execinfra/BUILD.bazel +++ b/pkg/sql/execinfra/BUILD.bazel @@ -53,6 +53,7 @@ go_library( "//pkg/storage/fs", "//pkg/util", "//pkg/util/admission", + "//pkg/util/buildutil", "//pkg/util/log", "//pkg/util/log/logcrash", "//pkg/util/metric", diff --git a/pkg/sql/execinfra/processorsbase.go b/pkg/sql/execinfra/processorsbase.go index 4acec2fcbe50..b5a900de38b1 100644 --- a/pkg/sql/execinfra/processorsbase.go +++ b/pkg/sql/execinfra/processorsbase.go @@ -21,6 +21,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/sql/sessiondata" "github.com/cockroachdb/cockroach/pkg/sql/types" "github.com/cockroachdb/cockroach/pkg/util" + "github.com/cockroachdb/cockroach/pkg/util/buildutil" "github.com/cockroachdb/cockroach/pkg/util/log" "github.com/cockroachdb/cockroach/pkg/util/log/logcrash" "github.com/cockroachdb/cockroach/pkg/util/mon" @@ -670,7 +671,7 @@ func (pb *ProcessorBaseNoHelper) moveToTrailingMeta() { } } - if util.CrdbTestBuild && pb.Ctx == nil { + if buildutil.CrdbTestBuild && pb.Ctx == nil { panic( errors.AssertionFailedf( "unexpected nil ProcessorBase.Ctx when draining. Was StartInternal called?", diff --git a/pkg/sql/execinfrapb/BUILD.bazel b/pkg/sql/execinfrapb/BUILD.bazel index da4d250ad942..143551832df2 100644 --- a/pkg/sql/execinfrapb/BUILD.bazel +++ b/pkg/sql/execinfrapb/BUILD.bazel @@ -38,6 +38,7 @@ go_library( "//pkg/sql/sessiondata", "//pkg/sql/types", "//pkg/util", + "//pkg/util/buildutil", "//pkg/util/duration", "//pkg/util/encoding", "//pkg/util/hlc", diff --git a/pkg/sql/execinfrapb/data.go b/pkg/sql/execinfrapb/data.go index 6e63325412b0..b6c68a49ed59 100644 --- a/pkg/sql/execinfrapb/data.go +++ b/pkg/sql/execinfrapb/data.go @@ -17,7 +17,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/roachpb" "github.com/cockroachdb/cockroach/pkg/sql/catalog/colinfo" "github.com/cockroachdb/cockroach/pkg/sql/sem/tree" - "github.com/cockroachdb/cockroach/pkg/util" + "github.com/cockroachdb/cockroach/pkg/util/buildutil" "github.com/cockroachdb/cockroach/pkg/util/encoding" "github.com/cockroachdb/cockroach/pkg/util/tracing/tracingpb" "github.com/cockroachdb/errors" @@ -316,7 +316,7 @@ func LocalMetaToRemoteProducerMeta( rpm.Value = &RemoteProducerMetadata_Error{ Error: NewError(ctx, meta.Err), } - } else if util.CrdbTestBuild { + } else if buildutil.CrdbTestBuild { panic("unhandled field in local meta or all fields are nil") } return rpm diff --git a/pkg/sql/execstats/BUILD.bazel b/pkg/sql/execstats/BUILD.bazel index ac4f31df456c..8cd311dabde0 100644 --- a/pkg/sql/execstats/BUILD.bazel +++ b/pkg/sql/execstats/BUILD.bazel @@ -10,6 +10,7 @@ go_library( "//pkg/roachpb:with-mocks", "//pkg/sql/execinfrapb", "//pkg/util", + "//pkg/util/buildutil", "//pkg/util/tracing/tracingpb", "@com_github_cockroachdb_errors//:errors", ], diff --git a/pkg/sql/execstats/traceanalyzer.go b/pkg/sql/execstats/traceanalyzer.go index d72ccbe327cd..20ac2260c3b4 100644 --- a/pkg/sql/execstats/traceanalyzer.go +++ b/pkg/sql/execstats/traceanalyzer.go @@ -17,6 +17,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/roachpb" "github.com/cockroachdb/cockroach/pkg/sql/execinfrapb" "github.com/cockroachdb/cockroach/pkg/util" + "github.com/cockroachdb/cockroach/pkg/util/buildutil" "github.com/cockroachdb/cockroach/pkg/util/tracing/tracingpb" "github.com/cockroachdb/errors" ) @@ -74,7 +75,7 @@ func NewFlowsMetadata(flows map[roachpb.NodeID]*execinfrapb.FlowSpec) *FlowsMeta for nodeID, flow := range flows { if a.flowID.IsUnset() { a.flowID = flow.FlowID - } else if util.CrdbTestBuild && !a.flowID.Equal(flow.FlowID) { + } else if buildutil.CrdbTestBuild && !a.flowID.Equal(flow.FlowID) { panic( errors.AssertionFailedf( "expected the same FlowID to be used for all flows. UUID of first flow: %v, UUID of flow on node %s: %v", diff --git a/pkg/sql/explain_plan.go b/pkg/sql/explain_plan.go index 08217ce58314..ff59a3e66446 100644 --- a/pkg/sql/explain_plan.go +++ b/pkg/sql/explain_plan.go @@ -25,7 +25,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/sql/opt/exec/explain" "github.com/cockroachdb/cockroach/pkg/sql/sem/tree" "github.com/cockroachdb/cockroach/pkg/sql/sessiondatapb" - "github.com/cockroachdb/cockroach/pkg/util" + "github.com/cockroachdb/cockroach/pkg/util/buildutil" "github.com/cockroachdb/cockroach/pkg/util/errorutil" "github.com/cockroachdb/errors" ) @@ -164,7 +164,7 @@ func emitExplain( // manipulate locks. // Note that we don't catch anything in debug builds, so that failures are // more visible. - if ok, e := errorutil.ShouldCatch(r); ok && !util.CrdbTestBuild { + if ok, e := errorutil.ShouldCatch(r); ok && !buildutil.CrdbTestBuild { err = e } else { // Other panic objects can't be considered "safe" and thus are diff --git a/pkg/sql/instrumentation.go b/pkg/sql/instrumentation.go index bfe8ea239ba9..22be1f771b80 100644 --- a/pkg/sql/instrumentation.go +++ b/pkg/sql/instrumentation.go @@ -32,6 +32,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/sql/sqltelemetry" "github.com/cockroachdb/cockroach/pkg/sql/stmtdiagnostics" "github.com/cockroachdb/cockroach/pkg/util" + "github.com/cockroachdb/cockroach/pkg/util/buildutil" "github.com/cockroachdb/cockroach/pkg/util/log" "github.com/cockroachdb/cockroach/pkg/util/tracing" "github.com/cockroachdb/cockroach/pkg/util/tracing/tracingpb" @@ -193,7 +194,7 @@ func (ih *instrumentationHelper) Setup( return ctx, ih.collectBundle } } else { - if util.CrdbTestBuild { + if buildutil.CrdbTestBuild { panic(errors.AssertionFailedf("the context doesn't have a tracing span")) } } @@ -276,7 +277,7 @@ func (ih *instrumentationHelper) Finish( queryLevelStats, err := execstats.GetQueryLevelStats(trace, cfg.TestingKnobs.DeterministicExplain, flowsMetadata) if err != nil { const msg = "error getting query level stats for statement: %s: %+v" - if util.CrdbTestBuild { + if buildutil.CrdbTestBuild { panic(fmt.Sprintf(msg, ih.fingerprint, err)) } log.VInfof(ctx, 1, msg, ih.fingerprint, err) diff --git a/pkg/sql/opt/BUILD.bazel b/pkg/sql/opt/BUILD.bazel index e82718a7826f..458a4135921e 100644 --- a/pkg/sql/opt/BUILD.bazel +++ b/pkg/sql/opt/BUILD.bazel @@ -31,6 +31,7 @@ go_library( "//pkg/sql/sqltelemetry", "//pkg/sql/types", "//pkg/util", + "//pkg/util/buildutil", "//pkg/util/log", "@com_github_cockroachdb_errors//:errors", "@com_github_lib_pq//oid", diff --git a/pkg/sql/opt/colset.go b/pkg/sql/opt/colset.go index 747695263a89..6c73f973322a 100644 --- a/pkg/sql/opt/colset.go +++ b/pkg/sql/opt/colset.go @@ -12,6 +12,7 @@ package opt import ( "github.com/cockroachdb/cockroach/pkg/util" + "github.com/cockroachdb/cockroach/pkg/util/buildutil" "github.com/cockroachdb/errors" ) @@ -150,7 +151,7 @@ func TranslateColSet(colSetIn ColSet, from ColList, to ColList) ColSet { // TranslateColSetStrict is a version of TranslateColSet which requires that all // columns in the input set appear in the from list. func TranslateColSetStrict(colSetIn ColSet, from ColList, to ColList) ColSet { - if util.CrdbTestBuild && !colSetIn.SubsetOf(from.ToSet()) { + if buildutil.CrdbTestBuild && !colSetIn.SubsetOf(from.ToSet()) { panic(errors.AssertionFailedf("input set contains unknown columns")) } return TranslateColSet(colSetIn, from, to) diff --git a/pkg/sql/opt/exec/execbuilder/BUILD.bazel b/pkg/sql/opt/exec/execbuilder/BUILD.bazel index f68240ae1aa0..8ad510032d83 100644 --- a/pkg/sql/opt/exec/execbuilder/BUILD.bazel +++ b/pkg/sql/opt/exec/execbuilder/BUILD.bazel @@ -38,6 +38,7 @@ go_library( "//pkg/sql/sqltelemetry", "//pkg/sql/types", "//pkg/util", + "//pkg/util/buildutil", "//pkg/util/encoding", "//pkg/util/errorutil", "//pkg/util/errorutil/unimplemented", diff --git a/pkg/sql/opt/exec/execbuilder/relational.go b/pkg/sql/opt/exec/execbuilder/relational.go index d97daec885ee..1a5acc16d72b 100644 --- a/pkg/sql/opt/exec/execbuilder/relational.go +++ b/pkg/sql/opt/exec/execbuilder/relational.go @@ -36,6 +36,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/sql/sqltelemetry" "github.com/cockroachdb/cockroach/pkg/sql/types" "github.com/cockroachdb/cockroach/pkg/util" + "github.com/cockroachdb/cockroach/pkg/util/buildutil" "github.com/cockroachdb/cockroach/pkg/util/encoding" "github.com/cockroachdb/cockroach/pkg/util/errorutil/unimplemented" "github.com/cockroachdb/cockroach/pkg/util/log" @@ -351,7 +352,7 @@ func (b *Builder) buildRelational(e memo.RelExpr) (execPlan, error) { // In test builds, assert that the exec plan output columns match the opt // plan output columns. - if util.CrdbTestBuild { + if buildutil.CrdbTestBuild { optCols := e.Relational().OutputCols var execCols opt.ColSet ep.outputCols.ForEach(func(key, val int) { diff --git a/pkg/sql/opt/memo/BUILD.bazel b/pkg/sql/opt/memo/BUILD.bazel index b8b4ca311df5..330a0f2144b2 100644 --- a/pkg/sql/opt/memo/BUILD.bazel +++ b/pkg/sql/opt/memo/BUILD.bazel @@ -4,7 +4,6 @@ go_library( name = "memo", srcs = [ "check_expr.go", - "check_expr_skip.go", # keep "constraint_builder.go", "cost.go", "expr.go", @@ -12,7 +11,6 @@ go_library( "expr_name_gen.go", "extract.go", "filters_expr_mutate_checker.go", - "filters_expr_mutate_checker_skip.go", # keep "group.go", "interner.go", "logical_props_builder.go", @@ -40,6 +38,7 @@ go_library( "//pkg/sql/sem/tree", "//pkg/sql/types", "//pkg/util", + "//pkg/util/buildutil", "//pkg/util/duration", "//pkg/util/encoding", "//pkg/util/json", diff --git a/pkg/sql/opt/memo/check_expr.go b/pkg/sql/opt/memo/check_expr.go index f8ec4687d3cc..b38368c5d135 100644 --- a/pkg/sql/opt/memo/check_expr.go +++ b/pkg/sql/opt/memo/check_expr.go @@ -8,9 +8,6 @@ // by the Apache License, Version 2.0, included in the file // licenses/APL.txt. -//go:build crdb_test -// +build crdb_test - package memo import ( @@ -18,6 +15,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/sql/opt/cat" "github.com/cockroachdb/cockroach/pkg/sql/opt/props" "github.com/cockroachdb/cockroach/pkg/sql/sem/tree" + "github.com/cockroachdb/cockroach/pkg/util/buildutil" "github.com/cockroachdb/cockroach/pkg/util/log" "github.com/cockroachdb/errors" ) @@ -28,6 +26,10 @@ import ( // // This function does not assume that the expression has been fully normalized. func (m *Memo) CheckExpr(e opt.Expr) { + if !buildutil.CrdbTestBuild { + return + } + if m.disableCheckExpr { return } diff --git a/pkg/sql/opt/memo/filters_expr_mutate_checker.go b/pkg/sql/opt/memo/filters_expr_mutate_checker.go index 723876e31bbd..f2d44d904f8e 100644 --- a/pkg/sql/opt/memo/filters_expr_mutate_checker.go +++ b/pkg/sql/opt/memo/filters_expr_mutate_checker.go @@ -8,12 +8,12 @@ // by the Apache License, Version 2.0, included in the file // licenses/APL.txt. -//go:build crdb_test -// +build crdb_test - package memo -import "github.com/cockroachdb/errors" +import ( + "github.com/cockroachdb/cockroach/pkg/util/buildutil" + "github.com/cockroachdb/errors" +) // FiltersExprMutateChecker is used to check if a FiltersExpr has been // erroneously mutated. This code is called in crdb_test builds so that the @@ -25,6 +25,9 @@ type FiltersExprMutateChecker struct { // Init initializes a FiltersExprMutateChecker with the original filters. func (fmc *FiltersExprMutateChecker) Init(filters FiltersExpr) { + if !buildutil.CrdbTestBuild { + return + } // This initialization pattern ensures that fields are not unwittingly // reused. Field reuse must be explicit. *fmc = FiltersExprMutateChecker{} @@ -36,6 +39,9 @@ func (fmc *FiltersExprMutateChecker) Init(filters FiltersExpr) { // CheckForMutation panics if the given filters are not equal to the filters // passed for the previous Init function call. func (fmc *FiltersExprMutateChecker) CheckForMutation(filters FiltersExpr) { + if !buildutil.CrdbTestBuild { + return + } fmc.hasher.Init() fmc.hasher.HashFiltersExpr(filters) if fmc.hash != fmc.hasher.hash { diff --git a/pkg/sql/opt/memo/filters_expr_mutate_checker_skip.go b/pkg/sql/opt/memo/filters_expr_mutate_checker_skip.go deleted file mode 100644 index c925a5d24ae7..000000000000 --- a/pkg/sql/opt/memo/filters_expr_mutate_checker_skip.go +++ /dev/null @@ -1,26 +0,0 @@ -// 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. - -//go:build !crdb_test -// +build !crdb_test - -package memo - -// FiltersExprMutateChecker is used to check if a FiltersExpr has been -// erroneously mutated. The check is only done in crdb_test builds so that the -// overhead is not incurred for non-test builds. See -// filters_expr_mutate_checker.go. -type FiltersExprMutateChecker struct{} - -// Init is a no-op in non-test builds. -func (fmc *FiltersExprMutateChecker) Init(filters FiltersExpr) {} - -// CheckForMutation is a no-op in non-test builds. -func (fmc *FiltersExprMutateChecker) CheckForMutation(filters FiltersExpr) {} diff --git a/pkg/sql/opt/memo/logical_props_builder.go b/pkg/sql/opt/memo/logical_props_builder.go index 8899044921db..196d3d8d520f 100644 --- a/pkg/sql/opt/memo/logical_props_builder.go +++ b/pkg/sql/opt/memo/logical_props_builder.go @@ -20,7 +20,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/sql/opt/props" "github.com/cockroachdb/cockroach/pkg/sql/sem/tree" "github.com/cockroachdb/cockroach/pkg/sql/types" - "github.com/cockroachdb/cockroach/pkg/util" + "github.com/cockroachdb/cockroach/pkg/util/buildutil" "github.com/cockroachdb/cockroach/pkg/util/log" "github.com/cockroachdb/errors" ) @@ -1927,7 +1927,7 @@ func (b *logicalPropsBuilder) rejectNullCols(filters FiltersExpr) opt.ColSet { func (b *logicalPropsBuilder) addFiltersToFuncDep(filters FiltersExpr, fdset *props.FuncDepSet) { for i := range filters { filterProps := filters[i].ScalarProps() - if util.CrdbTestBuild && !filterProps.Populated { + if buildutil.CrdbTestBuild && !filterProps.Populated { panic(errors.AssertionFailedf("filter properties not populated")) } fdset.AddFrom(&filterProps.FuncDeps) diff --git a/pkg/sql/opt/norm/BUILD.bazel b/pkg/sql/opt/norm/BUILD.bazel index 992a17f4d196..6f87565590ae 100644 --- a/pkg/sql/opt/norm/BUILD.bazel +++ b/pkg/sql/opt/norm/BUILD.bazel @@ -46,6 +46,7 @@ go_library( "//pkg/sql/types", "//pkg/util", "//pkg/util/arith", + "//pkg/util/buildutil", "//pkg/util/encoding", "//pkg/util/errorutil", "//pkg/util/json", diff --git a/pkg/sql/opt/norm/factory.go b/pkg/sql/opt/norm/factory.go index ea2997759f39..9c8f16157f02 100644 --- a/pkg/sql/opt/norm/factory.go +++ b/pkg/sql/opt/norm/factory.go @@ -17,7 +17,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/sql/opt/props/physical" "github.com/cockroachdb/cockroach/pkg/sql/sem/tree" "github.com/cockroachdb/cockroach/pkg/sql/types" - "github.com/cockroachdb/cockroach/pkg/util" + "github.com/cockroachdb/cockroach/pkg/util/buildutil" "github.com/cockroachdb/cockroach/pkg/util/errorutil" "github.com/cockroachdb/cockroach/pkg/util/log" "github.com/cockroachdb/errors" @@ -302,7 +302,7 @@ func (f *Factory) AssignPlaceholders(from *memo.Memo) (err error) { // function returns. It is used to verify that the stack depth is correctly // decremented for each constructor function. func (f *Factory) CheckConstructorStackDepth() { - if util.CrdbTestBuild && f.constructorStackDepth != 0 { + if buildutil.CrdbTestBuild && f.constructorStackDepth != 0 { panic(errors.AssertionFailedf( "expected constructor stack depth %v to be 0", f.constructorStackDepth, @@ -318,7 +318,7 @@ func (f *Factory) onMaxConstructorStackDepthExceeded() { "optimizer factory constructor call stack exceeded max depth of %v", maxConstructorStackDepth, ) - if util.CrdbTestBuild { + if buildutil.CrdbTestBuild { panic(err) } errorutil.SendReport(f.evalCtx.Ctx(), &f.evalCtx.Settings.SV, err) diff --git a/pkg/sql/opt/ordering/BUILD.bazel b/pkg/sql/opt/ordering/BUILD.bazel index fe8163c29adb..d469a43e00fb 100644 --- a/pkg/sql/opt/ordering/BUILD.bazel +++ b/pkg/sql/opt/ordering/BUILD.bazel @@ -30,7 +30,7 @@ go_library( "//pkg/sql/opt/memo", "//pkg/sql/opt/props", "//pkg/sql/sem/tree", - "//pkg/util", + "//pkg/util/buildutil", "//pkg/util/log", "@com_github_cockroachdb_errors//:errors", ], diff --git a/pkg/sql/opt/ordering/ordering.go b/pkg/sql/opt/ordering/ordering.go index 53898367d64e..3542475cc6d3 100644 --- a/pkg/sql/opt/ordering/ordering.go +++ b/pkg/sql/opt/ordering/ordering.go @@ -14,7 +14,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/sql/opt" "github.com/cockroachdb/cockroach/pkg/sql/opt/memo" "github.com/cockroachdb/cockroach/pkg/sql/opt/props" - "github.com/cockroachdb/cockroach/pkg/util" + "github.com/cockroachdb/cockroach/pkg/util/buildutil" "github.com/cockroachdb/cockroach/pkg/util/log" "github.com/cockroachdb/errors" ) @@ -25,7 +25,7 @@ func CanProvide(expr memo.RelExpr, required *props.OrderingChoice) bool { if required.Any() { return true } - if util.CrdbTestBuild { + if buildutil.CrdbTestBuild { checkRequired(expr, required) } return funcMap[expr.Op()].canProvideOrdering(expr, required) @@ -38,7 +38,7 @@ func BuildChildRequired( parent memo.RelExpr, required *props.OrderingChoice, childIdx int, ) props.OrderingChoice { result := funcMap[parent.Op()].buildChildReqOrdering(parent, required, childIdx) - if util.CrdbTestBuild && !result.Any() { + if buildutil.CrdbTestBuild && !result.Any() { checkRequired(parent.Child(childIdx).(memo.RelExpr), &result) } return result @@ -65,7 +65,7 @@ func BuildProvided(expr memo.RelExpr, required *props.OrderingChoice) opt.Orderi } provided := funcMap[expr.Op()].buildProvidedOrdering(expr, required) - if util.CrdbTestBuild { + if buildutil.CrdbTestBuild { checkProvided(expr, required, provided) } diff --git a/pkg/sql/opt/props/BUILD.bazel b/pkg/sql/opt/props/BUILD.bazel index f88850baa337..3b83606a1552 100644 --- a/pkg/sql/opt/props/BUILD.bazel +++ b/pkg/sql/opt/props/BUILD.bazel @@ -25,6 +25,7 @@ go_library( "//pkg/sql/rowenc", "//pkg/sql/sem/tree", "//pkg/sql/types", + "//pkg/util/buildutil", "//pkg/util/encoding", "//pkg/util/log", "@com_github_cockroachdb_errors//:errors", diff --git a/pkg/sql/opt/props/verify.go b/pkg/sql/opt/props/verify.go index 768a3f123e47..586a8a25313a 100644 --- a/pkg/sql/opt/props/verify.go +++ b/pkg/sql/opt/props/verify.go @@ -8,12 +8,10 @@ // by the Apache License, Version 2.0, included in the file // licenses/APL.txt. -//go:build crdb_test -// +build crdb_test - package props import ( + "github.com/cockroachdb/cockroach/pkg/util/buildutil" "github.com/cockroachdb/cockroach/pkg/util/log" "github.com/cockroachdb/errors" ) @@ -26,6 +24,9 @@ import ( // 3. If Mutate is true, then VolatilitySet must contain Volatile. // func (s *Shared) Verify() { + if !buildutil.CrdbTestBuild { + return + } if !s.Populated { panic(errors.AssertionFailedf("properties are not populated")) } @@ -47,6 +48,10 @@ func (s *Shared) Verify() { // one row, then the cardinality reflects that as well. // func (r *Relational) Verify() { + if !buildutil.CrdbTestBuild { + return + } + r.Shared.Verify() r.FuncDeps.Verify() @@ -76,6 +81,10 @@ func (r *Relational) Verify() { // Used for testing (e.g. to cross-check derived properties from expressions in // the same group). func (r *Relational) VerifyAgainst(other *Relational) { + if !buildutil.CrdbTestBuild { + return + } + if !r.OutputCols.Equals(other.OutputCols) { panic(errors.AssertionFailedf("output cols mismatch: %s vs %s", log.Safe(r.OutputCols), log.Safe(other.OutputCols))) } @@ -96,6 +105,10 @@ func (r *Relational) VerifyAgainst(other *Relational) { // 1. Functional dependencies are internally consistent. // func (s *Scalar) Verify() { + if !buildutil.CrdbTestBuild { + return + } + s.Shared.Verify() s.FuncDeps.Verify() } diff --git a/pkg/sql/opt/table_meta.go b/pkg/sql/opt/table_meta.go index 332de2b1d81f..d4cf12bd882c 100644 --- a/pkg/sql/opt/table_meta.go +++ b/pkg/sql/opt/table_meta.go @@ -13,7 +13,7 @@ package opt import ( "github.com/cockroachdb/cockroach/pkg/sql/opt/cat" "github.com/cockroachdb/cockroach/pkg/sql/sem/tree" - "github.com/cockroachdb/cockroach/pkg/util" + "github.com/cockroachdb/cockroach/pkg/util/buildutil" "github.com/cockroachdb/errors" ) @@ -52,7 +52,7 @@ func (t TableID) IndexColumnID(idx cat.Index, idxOrd int) ColumnID { // NOTE: This method cannot do complete bounds checking, so it's up to the // caller to ensure that this column is really in the given base table. func (t TableID) ColumnOrdinal(id ColumnID) int { - if util.CrdbTestBuild && id < t.firstColID() { + if buildutil.CrdbTestBuild && id < t.firstColID() { panic(errors.AssertionFailedf("ordinal cannot be negative")) } return int(id - t.firstColID()) diff --git a/pkg/sql/opt/xform/BUILD.bazel b/pkg/sql/opt/xform/BUILD.bazel index d4bd8cf76a4c..36bb828274be 100644 --- a/pkg/sql/opt/xform/BUILD.bazel +++ b/pkg/sql/opt/xform/BUILD.bazel @@ -43,6 +43,7 @@ go_library( "//pkg/sql/sem/tree", "//pkg/sql/types", "//pkg/util", + "//pkg/util/buildutil", "//pkg/util/errorutil", "//pkg/util/log", "//pkg/util/treeprinter", diff --git a/pkg/sql/opt/xform/placeholder_fast_path.go b/pkg/sql/opt/xform/placeholder_fast_path.go index a562b2a124fe..9b89d219003d 100644 --- a/pkg/sql/opt/xform/placeholder_fast_path.go +++ b/pkg/sql/opt/xform/placeholder_fast_path.go @@ -15,7 +15,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/sql/opt/cat" "github.com/cockroachdb/cockroach/pkg/sql/opt/memo" "github.com/cockroachdb/cockroach/pkg/sql/opt/props/physical" - "github.com/cockroachdb/cockroach/pkg/util" + "github.com/cockroachdb/cockroach/pkg/util/buildutil" "github.com/cockroachdb/cockroach/pkg/util/errorutil" "github.com/cockroachdb/errors" ) @@ -215,7 +215,7 @@ func (o *Optimizer) TryPlaceholderFastPath() (_ opt.Expr, ok bool, err error) { o.mem.SetBestProps(placeholderScan, rootPhysicalProps, &physical.Provided{}, 1.0 /* cost */) o.mem.SetRoot(placeholderScan, rootPhysicalProps) - if util.CrdbTestBuild && !o.mem.IsOptimized() { + if buildutil.CrdbTestBuild && !o.mem.IsOptimized() { return nil, false, errors.AssertionFailedf("IsOptimized() should be true") } diff --git a/pkg/util/BUILD.bazel b/pkg/util/BUILD.bazel index 4d73a37ffdc5..388a1ee4e721 100644 --- a/pkg/util/BUILD.bazel +++ b/pkg/util/BUILD.bazel @@ -6,8 +6,6 @@ go_library( name = "util", srcs = [ "constants.go", - "crdb_test_off.go", - "crdb_test_on.go", # keep "every_n.go", "fast_int_map.go", "fast_int_set.go", # keep @@ -33,6 +31,7 @@ go_library( importpath = "github.com/cockroachdb/cockroach/pkg/util", visibility = ["//visibility:public"], deps = [ + "//pkg/util/buildutil", "//pkg/util/envutil", "//pkg/util/netutil/addr", "//pkg/util/randutil", diff --git a/pkg/util/buildutil/BUILD.bazel b/pkg/util/buildutil/BUILD.bazel new file mode 100644 index 000000000000..1dd985c3be7d --- /dev/null +++ b/pkg/util/buildutil/BUILD.bazel @@ -0,0 +1,47 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") + +# gazelle:exclude gen-crdb_test_off.go +# gazelle:exclude gen-crdb_test_on.go + +# keep +go_library( + name = "buildutil", + srcs = select({ + "//build/toolchains:opt_crdb_test": [":gen-crdb-test-on"], + "//build/toolchains:opt": [":gen-crdb-test-off"], + "//conditions:default": ["crdb_test_dyn.go"], + }), + importpath = "github.com/cockroachdb/cockroach/pkg/util/buildutil", + visibility = ["//visibility:public"], + x_defs = select({ + # opt builds will get either crdb_test_on.go or crdb_test_off.go. + # dbg and fastbuild builds will get crdb_test_dyn.go, in which case we + # want to set the crdbTestString variable at link-time. + "//build/toolchains:dbg_crdb_test": {"crdbTestString": "y"}, + "//build/toolchains:fastbuild_crdb_test": {"crdbTestString": "y"}, + "//conditions:default": {}, + }), +) + +REMOVE_GO_BUILD_CONSTRAINTS = "cat $< | grep -v '//go:build' | grep -v '// +build' > $@" + +genrule( + name = "gen-crdb-test-on", + srcs = ["crdb_test_on.go"], + outs = ["gen-crdb_test_on.go"], + cmd = REMOVE_GO_BUILD_CONSTRAINTS, +) + +genrule( + name = "gen-crdb-test-off", + srcs = ["crdb_test_off.go"], + outs = ["gen-crdb_test_off.go"], + cmd = REMOVE_GO_BUILD_CONSTRAINTS, +) + +go_test( + name = "buildutil_test", + srcs = ["crdb_test_test.go"], + embed = [":buildutil"], # keep + deps = ["@com_github_stretchr_testify//require"], +) diff --git a/pkg/util/buildutil/crdb_test_dyn.go b/pkg/util/buildutil/crdb_test_dyn.go new file mode 100644 index 000000000000..80a562f60e7b --- /dev/null +++ b/pkg/util/buildutil/crdb_test_dyn.go @@ -0,0 +1,31 @@ +// 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. + +//go:build bazel +// +build bazel + +package buildutil + +var ( + CrdbTestBuild bool + crdbTestString string +) + +// This version of the buildutil package is compiled only for `dbg` or +// `fastbuild` Bazel builds. The original Go version of the package uses build +// tags to accomplish the same thing, but switching between build tags thrashes +// the Bazel cache. For `opt` builds, we instead use `crdb_test_on.go` or +// `crdb_test_off.go`, which makes `CrdbTestBuild` a `const`. This gives the +// compiler more room to optimize out unreachable code. Here, for dev scenarios, +// we instead dynamically set the value of the variable at package init() time. +// This means you can swap between build and test requiring only a re-link. +func init() { + CrdbTestBuild = crdbTestString != "" +} diff --git a/pkg/util/crdb_test_off.go b/pkg/util/buildutil/crdb_test_off.go similarity index 97% rename from pkg/util/crdb_test_off.go rename to pkg/util/buildutil/crdb_test_off.go index 2d3f9d1d5d08..bde569cf2984 100644 --- a/pkg/util/crdb_test_off.go +++ b/pkg/util/buildutil/crdb_test_off.go @@ -11,7 +11,7 @@ //go:build !crdb_test || crdb_test_off // +build !crdb_test crdb_test_off -package util +package buildutil // CrdbTestBuild is a flag that is set to true if the binary was compiled // with the 'crdb_test' build tag (which is the case for all test targets). This diff --git a/pkg/util/crdb_test_on.go b/pkg/util/buildutil/crdb_test_on.go similarity index 97% rename from pkg/util/crdb_test_on.go rename to pkg/util/buildutil/crdb_test_on.go index 1939eb4217af..29163bda9b18 100644 --- a/pkg/util/crdb_test_on.go +++ b/pkg/util/buildutil/crdb_test_on.go @@ -11,7 +11,7 @@ //go:build crdb_test && !crdb_test_off // +build crdb_test,!crdb_test_off -package util +package buildutil // CrdbTestBuild is a flag that is set to true if the binary was compiled // with the 'crdb_test' build tag (which is the case for all test targets). This diff --git a/pkg/sql/opt/memo/check_expr_skip.go b/pkg/util/buildutil/crdb_test_test.go similarity index 55% rename from pkg/sql/opt/memo/check_expr_skip.go rename to pkg/util/buildutil/crdb_test_test.go index 47caa9820aa8..784d986b1004 100644 --- a/pkg/sql/opt/memo/check_expr_skip.go +++ b/pkg/util/buildutil/crdb_test_test.go @@ -1,4 +1,4 @@ -// Copyright 2019 The Cockroach Authors. +// Copyright 2021 The Cockroach Authors. // // Use of this software is governed by the Business Source License // included in the file licenses/BSL.txt. @@ -8,13 +8,16 @@ // by the Apache License, Version 2.0, included in the file // licenses/APL.txt. -//go:build !crdb_test -// +build !crdb_test +package buildutil -package memo +import ( + "testing" -import "github.com/cockroachdb/cockroach/pkg/sql/opt" + "github.com/stretchr/testify/require" +) -// CheckExpr is a no-op in non-test builds. -func (m *Memo) CheckExpr(e opt.Expr) { +func TestCrdbTestOn(t *testing.T) { + // Sanity-check: make sure CrdbTestBuild is set. This should be true for + // any test. + require.True(t, CrdbTestBuild) } diff --git a/pkg/util/constants.go b/pkg/util/constants.go index 87ec52cb3e8b..5111fdb36a0f 100644 --- a/pkg/util/constants.go +++ b/pkg/util/constants.go @@ -15,6 +15,7 @@ import ( "math/rand" "os" + "github.com/cockroachdb/cockroach/pkg/util/buildutil" "github.com/cockroachdb/cockroach/pkg/util/envutil" "github.com/cockroachdb/cockroach/pkg/util/randutil" ) @@ -83,7 +84,7 @@ var rng *rand.Rand const DisableMetamorphicEnvVar = "COCKROACH_INTERNAL_DISABLE_METAMORPHIC_TESTING" func init() { - if CrdbTestBuild { + if buildutil.CrdbTestBuild { disabled := envutil.EnvOrDefaultBool(DisableMetamorphicEnvVar, false) if !disabled { rng, _ = randutil.NewTestRand() From b2bf43cf8465278454b0e0a4333e0a9e3210981f Mon Sep 17 00:00:00 2001 From: Ricky Stewart Date: Thu, 18 Nov 2021 09:47:58 -0600 Subject: [PATCH 3/3] build/README: add more info about how to authenticate for mirroring Release note: None --- build/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/build/README.md b/build/README.md index 6574d5680e0d..a65ffe0f5575 100644 --- a/build/README.md +++ b/build/README.md @@ -169,7 +169,8 @@ file on your local branch, 2) push a commit containing this import to the `vendo 8. Run `./dev generate bazel --mirror` to regenerate DEPS.bzl with the updated Go dependency information. Note that you need engineer permissions to mirror dependencies; if you want to get the Bazel build working locally without mirroring, `./dev generate bazel` will work, but you won't be able to check - your changes in. + your changes in. (Assuming that you do have engineer permissions, you can run + `gcloud auth application-default login` to authenticate if you get a credentials error.) 9. Follow instructions for [pushing the dependency to the `vendored` submodule](#pushing-the-dependency-to-the-vendored-submodule) ### Updating a Dependency