Skip to content

Commit

Permalink
allocatorimpl: carve out an allocator package
Browse files Browse the repository at this point in the history
Do the same for kvserver/replicastats, a type that's used as an input
for the allocator at various points (needed to break the dependency
between the allocatorimpl and kvserver). We take the same approach as
the last commit, exporting anything and everything needed to introduce a
hard package boundary.

Release note: None
  • Loading branch information
irfansharif committed Apr 22, 2022
1 parent a582830 commit 4f96b1b
Show file tree
Hide file tree
Showing 45 changed files with 1,823 additions and 1,562 deletions.
2 changes: 2 additions & 0 deletions pkg/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ ALL_TESTS = [
"//pkg/kv/kvnemesis:kvnemesis_test",
"//pkg/kv/kvprober:kvprober_test",
"//pkg/kv/kvserver/abortspan:abortspan_test",
"//pkg/kv/kvserver/allocator/allocatorimpl:allocatorimpl_test",
"//pkg/kv/kvserver/allocator/storepool:storepool_test",
"//pkg/kv/kvserver/apply:apply_test",
"//pkg/kv/kvserver/asim:asim_test",
Expand All @@ -159,6 +160,7 @@ ALL_TESTS = [
"//pkg/kv/kvserver/raftentry:raftentry_test",
"//pkg/kv/kvserver/rangefeed:rangefeed_test",
"//pkg/kv/kvserver/rditer:rditer_test",
"//pkg/kv/kvserver/replicastats:replicastats_test",
"//pkg/kv/kvserver/reports:reports_test",
"//pkg/kv/kvserver/spanlatch:spanlatch_test",
"//pkg/kv/kvserver/spanset:spanset_test",
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/allocsim/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ go_library(
"//pkg/acceptance/localcluster/tc",
"//pkg/cli",
"//pkg/cli/exit",
"//pkg/kv/kvserver",
"//pkg/kv/kvserver/allocator/allocatorimpl",
"//pkg/server/serverpb",
"//pkg/util/log",
"//pkg/util/randutil",
Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/allocsim/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/acceptance/localcluster/tc"
"github.com/cockroachdb/cockroach/pkg/cli"
"github.com/cockroachdb/cockroach/pkg/cli/exit"
"github.com/cockroachdb/cockroach/pkg/kv/kvserver"
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/allocator/allocatorimpl"
"github.com/cockroachdb/cockroach/pkg/server/serverpb"
"github.com/cockroachdb/cockroach/pkg/util/log"
"github.com/cockroachdb/cockroach/pkg/util/randutil"
Expand Down Expand Up @@ -403,7 +403,7 @@ func handleStart() bool {
// in the few minutes after allocsim starts up causes it to take a long time
// for leases to settle onto other nodes even when requests are skewed heavily
// onto them.
kvserver.MinLeaseTransferStatsDuration = 10 * time.Second
allocatorimpl.MinLeaseTransferStatsDuration = 10 * time.Second

cli.Main()
return true
Expand Down
15 changes: 6 additions & 9 deletions pkg/kv/kvserver/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ go_library(
name = "kvserver",
srcs = [
"addressing.go",
"allocator.go",
"allocator_scorer.go",
"compact_span_client.go",
"consistency_queue.go",
"debug_print.go",
Expand Down Expand Up @@ -70,7 +68,6 @@ go_library(
"replica_sideload_disk.go",
"replica_split_load.go",
"replica_sst_snapshot_storage.go",
"replica_stats.go",
"replica_tscache.go",
"replica_write.go",
"replicate_queue.go",
Expand Down Expand Up @@ -117,6 +114,7 @@ go_library(
"//pkg/kv/kvclient/rangecache",
"//pkg/kv/kvserver/abortspan",
"//pkg/kv/kvserver/allocator",
"//pkg/kv/kvserver/allocator/allocatorimpl",
"//pkg/kv/kvserver/allocator/storepool",
"//pkg/kv/kvserver/apply",
"//pkg/kv/kvserver/batcheval",
Expand All @@ -140,6 +138,7 @@ go_library(
"//pkg/kv/kvserver/rditer",
"//pkg/kv/kvserver/readsummary",
"//pkg/kv/kvserver/readsummary/rspb",
"//pkg/kv/kvserver/replicastats",
"//pkg/kv/kvserver/spanset",
"//pkg/kv/kvserver/split",
"//pkg/kv/kvserver/stateloader",
Expand Down Expand Up @@ -212,8 +211,7 @@ go_test(
size = "enormous",
srcs = [
"addressing_test.go",
"allocator_scorer_test.go",
"allocator_test.go",
"allocator_impl_test.go",
"batch_spanset_test.go",
"below_raft_protos_test.go",
"client_atomic_membership_change_test.go",
Expand All @@ -235,7 +233,6 @@ go_test(
"client_split_burst_test.go",
"client_split_test.go",
"client_status_test.go",
"client_store_pool_test.go",
"client_store_test.go",
"client_tenant_test.go",
"client_test.go",
Expand Down Expand Up @@ -284,7 +281,6 @@ go_test(
"replica_rankings_test.go",
"replica_sideload_test.go",
"replica_sst_snapshot_storage_test.go",
"replica_stats_test.go",
"replica_test.go",
"replica_tscache_test.go",
"replicate_queue_test.go",
Expand All @@ -298,6 +294,7 @@ go_test(
"split_queue_test.go",
"split_trigger_helper_test.go",
"stats_test.go",
"store_pool_test.go",
"store_rebalancer_test.go",
"store_replica_btree_test.go",
"store_test.go",
Expand All @@ -324,6 +321,7 @@ go_test(
"//pkg/kv/kvclient/rangefeed/rangefeedcache",
"//pkg/kv/kvserver/abortspan",
"//pkg/kv/kvserver/allocator",
"//pkg/kv/kvserver/allocator/allocatorimpl",
"//pkg/kv/kvserver/allocator/storepool",
"//pkg/kv/kvserver/apply",
"//pkg/kv/kvserver/batcheval",
Expand All @@ -333,7 +331,6 @@ go_test(
"//pkg/kv/kvserver/closedts/tracker",
"//pkg/kv/kvserver/concurrency",
"//pkg/kv/kvserver/concurrency/lock",
"//pkg/kv/kvserver/constraint",
"//pkg/kv/kvserver/gc",
"//pkg/kv/kvserver/intentresolver",
"//pkg/kv/kvserver/kvserverbase",
Expand All @@ -346,6 +343,7 @@ go_test(
"//pkg/kv/kvserver/raftentry",
"//pkg/kv/kvserver/rditer",
"//pkg/kv/kvserver/readsummary/rspb",
"//pkg/kv/kvserver/replicastats",
"//pkg/kv/kvserver/spanset",
"//pkg/kv/kvserver/split",
"//pkg/kv/kvserver/stateloader",
Expand Down Expand Up @@ -424,7 +422,6 @@ go_test(
"@com_github_jackc_pgx_v4//:pgx",
"@com_github_kr_pretty//:pretty",
"@com_github_lib_pq//:pq",
"@com_github_olekukonko_tablewriter//:tablewriter",
"@com_github_stretchr_testify//assert",
"@com_github_stretchr_testify//require",
"@io_etcd_go_etcd_raft_v3//:raft",
Expand Down
2 changes: 2 additions & 0 deletions pkg/kv/kvserver/allocator/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ go_library(
deps = [
"//pkg/kv/kvserver/constraint",
"//pkg/roachpb",
"//pkg/settings",
"@com_github_cockroachdb_errors//:errors",
],
)
71 changes: 71 additions & 0 deletions pkg/kv/kvserver/allocator/allocatorimpl/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")

go_library(
name = "allocatorimpl",
srcs = [
"allocator.go",
"allocator_scorer.go",
"test_helpers.go",
],
importpath = "github.com/cockroachdb/cockroach/pkg/kv/kvserver/allocator/allocatorimpl",
visibility = ["//visibility:public"],
deps = [
"//pkg/clusterversion",
"//pkg/gossip",
"//pkg/kv/kvserver/allocator",
"//pkg/kv/kvserver/allocator/storepool",
"//pkg/kv/kvserver/constraint",
"//pkg/kv/kvserver/liveness/livenesspb",
"//pkg/kv/kvserver/replicastats",
"//pkg/roachpb",
"//pkg/settings",
"//pkg/settings/cluster",
"//pkg/util/hlc",
"//pkg/util/log",
"//pkg/util/metric",
"//pkg/util/stop",
"//pkg/util/syncutil",
"@com_github_cockroachdb_errors//:errors",
"@io_etcd_go_etcd_raft_v3//:raft",
"@io_etcd_go_etcd_raft_v3//tracker",
],
)

go_test(
name = "allocatorimpl_test",
srcs = [
"allocator_scorer_test.go",
"allocator_test.go",
],
embed = [":allocatorimpl"],
deps = [
"//pkg/base",
"//pkg/config/zonepb",
"//pkg/gossip",
"//pkg/keys",
"//pkg/kv/kvserver/allocator",
"//pkg/kv/kvserver/allocator/storepool",
"//pkg/kv/kvserver/constraint",
"//pkg/kv/kvserver/liveness/livenesspb",
"//pkg/kv/kvserver/replicastats",
"//pkg/roachpb",
"//pkg/rpc",
"//pkg/settings/cluster",
"//pkg/testutils",
"//pkg/testutils/gossiputil",
"//pkg/util",
"//pkg/util/hlc",
"//pkg/util/leaktest",
"//pkg/util/log",
"//pkg/util/metric",
"//pkg/util/stop",
"//pkg/util/tracing",
"@com_github_cockroachdb_errors//:errors",
"@com_github_kr_pretty//:pretty",
"@com_github_olekukonko_tablewriter//:tablewriter",
"@com_github_stretchr_testify//assert",
"@com_github_stretchr_testify//require",
"@io_etcd_go_etcd_raft_v3//:raft",
"@io_etcd_go_etcd_raft_v3//tracker",
],
)
Loading

0 comments on commit 4f96b1b

Please sign in to comment.