Skip to content

Commit

Permalink
Merge #39721
Browse files Browse the repository at this point in the history
39721: serverutils: remove depency on kv r=andreimatei a=andreimatei

See individual commits

Co-authored-by: Andrei Matei <andrei@cockroachlabs.com>
  • Loading branch information
craig[bot] and andreimatei committed Aug 24, 2019
2 parents 7fd65c9 + 10d7f64 commit 497167b
Show file tree
Hide file tree
Showing 24 changed files with 113 additions and 61 deletions.
5 changes: 4 additions & 1 deletion pkg/ccl/backupccl/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/jobs"
"github.com/cockroachdb/cockroach/pkg/jobs/jobspb"
"github.com/cockroachdb/cockroach/pkg/keys"
"github.com/cockroachdb/cockroach/pkg/kv"
"github.com/cockroachdb/cockroach/pkg/roachpb"
"github.com/cockroachdb/cockroach/pkg/security"
"github.com/cockroachdb/cockroach/pkg/sql"
Expand Down Expand Up @@ -2196,7 +2197,9 @@ func TestRestoreAsOfSystemTimeGCBounds(t *testing.T) {
},
Threshold: tc.Server(0).Clock().Now(),
}
if _, err := client.SendWrapped(ctx, tc.Server(0).DistSender(), &gcr); err != nil {
if _, err := client.SendWrapped(
ctx, tc.Server(0).DistSenderI().(*kv.DistSender), &gcr,
); err != nil {
t.Fatal(err)
}

Expand Down
3 changes: 2 additions & 1 deletion pkg/ccl/changefeedccl/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"time"

"github.com/cockroachdb/cockroach/pkg/base"
"github.com/cockroachdb/cockroach/pkg/gossip"
"github.com/cockroachdb/cockroach/pkg/jobs/jobspb"
"github.com/cockroachdb/cockroach/pkg/roachpb"
"github.com/cockroachdb/cockroach/pkg/server"
Expand Down Expand Up @@ -205,7 +206,7 @@ func createBenchmarkChangefeed(
nil /* curCount */, nil /* maxHist */, math.MaxInt64, settings,
)
poller := makePoller(
settings, s.DB(), feedClock, s.Gossip(), spans, details, initialHighWater, buf,
settings, s.DB(), feedClock, s.GossipI().(*gossip.Gossip), spans, details, initialHighWater, buf,
leaseMgr, metrics, &mm,
)

Expand Down
4 changes: 3 additions & 1 deletion pkg/ccl/changefeedccl/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/cockroachdb/apd"
"github.com/cockroachdb/cockroach/pkg/base"
"github.com/cockroachdb/cockroach/pkg/ccl/changefeedccl/cdctest"
"github.com/cockroachdb/cockroach/pkg/kv"
"github.com/cockroachdb/cockroach/pkg/security"
"github.com/cockroachdb/cockroach/pkg/sql/distsqlrun"
"github.com/cockroachdb/cockroach/pkg/sql/sem/tree"
Expand Down Expand Up @@ -329,5 +330,6 @@ func forceTableGC(
database, table string,
) {
t.Helper()
serverutils.ForceTableGC(t, tsi, sqlDB.DB, database, table, tsi.Clock().Now())
sqlutils.ForceTableGC(
t, tsi.DistSenderI().(*kv.DistSender), sqlDB.DB, database, table, tsi.Clock().Now())
}
2 changes: 1 addition & 1 deletion pkg/kv/dist_sender_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1055,7 +1055,7 @@ func TestParallelSender(t *testing.T) {
}

getPSCount := func() int64 {
return s.DistSender().Metrics().AsyncSentCount.Count()
return s.DistSenderI().(*kv.DistSender).Metrics().AsyncSentCount.Count()
}
psCount := getPSCount()

Expand Down
2 changes: 1 addition & 1 deletion pkg/kv/txn_coord_sender_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func TestHeartbeatFindsOutAboutAbortedTransaction(t *testing.T) {
Clock: s.Clock(),
Stopper: s.Stopper(),
},
s.DistSender(),
s.DistSenderI().(*kv.DistSender),
)
db := client.NewDB(ambient, tsf, s.Clock())
txn := client.NewTxn(ctx, db, 0 /* gatewayNodeID */, client.RootTxn)
Expand Down
17 changes: 14 additions & 3 deletions pkg/server/testserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,12 @@ func (ts *TestServer) Stopper() *stop.Stopper {
return ts.stopper
}

// Gossip returns the gossip instance used by the TestServer.
// GossipI is part of TestServerInterface.
func (ts *TestServer) GossipI() interface{} {
return ts.Gossip()
}

// Gossip is like GossipI but returns the real type instead of interface{}.
func (ts *TestServer) Gossip() *gossip.Gossip {
if ts != nil {
return ts.gossip
Expand Down Expand Up @@ -590,11 +595,17 @@ func (ts *TestServer) GetNodeLiveness() *storage.NodeLiveness {
return ts.nodeLiveness
}

// DistSender exposes the Server's DistSender.
func (ts *TestServer) DistSender() *kv.DistSender {
// DistSenderI is part of DistSendeInterface.
func (ts *TestServer) DistSenderI() interface{} {
return ts.distSender
}

// DistSender is like DistSenderI(), but returns the real type instead of
// interface{}.
func (ts *TestServer) DistSender() *kv.DistSender {
return ts.DistSenderI().(*kv.DistSender)
}

// DistSQLServer is part of TestServerInterface.
func (ts *TestServer) DistSQLServer() interface{} {
return ts.distSQLServer
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/crdb_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestGossipAlertsTable(t *testing.T) {
defer s.Stopper().Stop(context.TODO())
ctx := context.TODO()

if err := s.Gossip().AddInfoProto(gossip.MakeNodeHealthAlertKey(456), &statuspb.HealthCheckResult{
if err := s.GossipI().(*gossip.Gossip).AddInfoProto(gossip.MakeNodeHealthAlertKey(456), &statuspb.HealthCheckResult{
Alerts: []statuspb.HealthAlert{{
StoreID: 123,
Category: statuspb.HealthAlert_METRICS,
Expand Down
5 changes: 4 additions & 1 deletion pkg/sql/create_stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"time"

"github.com/cockroachdb/cockroach/pkg/base"
"github.com/cockroachdb/cockroach/pkg/kv"
"github.com/cockroachdb/cockroach/pkg/security"
"github.com/cockroachdb/cockroach/pkg/sql/distsqlrun"
"github.com/cockroachdb/cockroach/pkg/testutils"
Expand Down Expand Up @@ -97,7 +98,9 @@ func TestStatsWithLowTTL(t *testing.T) {
return
}
// Force a table GC of values older than 1 second.
serverutils.ForceTableGC(t, s, db2, "test", "t", s.Clock().Now().Add(-int64(1*time.Second), 0))
sqlutils.ForceTableGC(
t, s.DistSenderI().(*kv.DistSender), db2,
"test", "t", s.Clock().Now().Add(-int64(1*time.Second), 0))
time.Sleep(10 * time.Millisecond)
}
}()
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/distsql_physical_planner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ func TestDistSQLRangeCachesIntegrationTest(t *testing.T) {
//
// TODO(andrei): This is super hacky. What this test really wants to do is to
// precisely control the contents of the range cache on node 4.
tc.Server(3).DistSender().DisableFirstRangeUpdates()
tc.Server(3).DistSenderI().(*kv.DistSender).DisableFirstRangeUpdates()
db3 := tc.ServerConn(3)
// Do a query on node 4 so that it populates the its cache with an initial
// descriptor containing all the SQL key space. If we don't do this, the state
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/distsql_running_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func TestDistSQLRunningInAbortedTxn(t *testing.T) {
Clock: s.Clock(),
Stopper: s.Stopper(),
},
s.DistSender(),
s.DistSenderI().(*kv.DistSender),
)
shortDB := client.NewDB(ambient, tsf, s.Clock())

Expand Down
7 changes: 4 additions & 3 deletions pkg/sql/distsqlplan/span_resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"time"

"github.com/cockroachdb/cockroach/pkg/base"
"github.com/cockroachdb/cockroach/pkg/gossip"
"github.com/cockroachdb/cockroach/pkg/internal/client"
"github.com/cockroachdb/cockroach/pkg/kv"
"github.com/cockroachdb/cockroach/pkg/roachpb"
Expand Down Expand Up @@ -83,7 +84,7 @@ func TestSpanResolverUsesCaches(t *testing.T) {

lr := distsqlplan.NewSpanResolver(
s3.Cfg.Settings,
s3.DistSender(), s3.Gossip(), s3.GetNode().Descriptor, nil,
s3.DistSenderI().(*kv.DistSender), s3.Gossip(), s3.GetNode().Descriptor, nil,
replicaoracle.BinPackingChoice)

var spans []spanWithDir
Expand Down Expand Up @@ -189,7 +190,7 @@ func TestSpanResolver(t *testing.T) {
rowRanges, tableDesc := setupRanges(db, s.(*server.TestServer), cdb, t)
lr := distsqlplan.NewSpanResolver(
s.(*server.TestServer).Cfg.Settings,
s.DistSender(), s.Gossip(),
s.DistSenderI().(*kv.DistSender), s.GossipI().(*gossip.Gossip),
s.(*server.TestServer).GetNode().Descriptor, nil,
replicaoracle.BinPackingChoice)

Expand Down Expand Up @@ -283,7 +284,7 @@ func TestMixedDirections(t *testing.T) {
rowRanges, tableDesc := setupRanges(db, s.(*server.TestServer), cdb, t)
lr := distsqlplan.NewSpanResolver(
s.(*server.TestServer).Cfg.Settings,
s.DistSender(), s.Gossip(),
s.DistSenderI().(*kv.DistSender), s.GossipI().(*gossip.Gossip),
s.(*server.TestServer).GetNode().Descriptor,
nil,
replicaoracle.BinPackingChoice)
Expand Down
3 changes: 2 additions & 1 deletion pkg/sql/distsqlrun/sample_aggregator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"testing"

"github.com/cockroachdb/cockroach/pkg/base"
"github.com/cockroachdb/cockroach/pkg/gossip"
"github.com/cockroachdb/cockroach/pkg/settings/cluster"
"github.com/cockroachdb/cockroach/pkg/sql/distsqlpb"
"github.com/cockroachdb/cockroach/pkg/sql/sem/tree"
Expand Down Expand Up @@ -48,7 +49,7 @@ func TestSampleAggregator(t *testing.T) {
Settings: st,
DB: kvDB,
Executor: server.InternalExecutor().(sqlutil.InternalExecutor),
Gossip: server.Gossip(),
Gossip: server.GossipI().(*gossip.Gossip),
},
}
// Override the default memory limit. If memLimitBytes is small but
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/distsqlrun/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func TestDistSQLServerGossipsVersion(t *testing.T) {
defer s.Stopper().Stop(context.TODO())

var v distsqlpb.DistSQLVersionGossipInfo
if err := s.Gossip().GetInfoProto(
if err := s.GossipI().(*gossip.Gossip).GetInfoProto(
gossip.MakeDistSQLNodeVersionKey(s.NodeID()), &v,
); err != nil {
t.Fatal(err)
Expand Down
3 changes: 2 additions & 1 deletion pkg/sql/schema_changer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/jobs"
"github.com/cockroachdb/cockroach/pkg/jobs/jobspb"
"github.com/cockroachdb/cockroach/pkg/keys"
"github.com/cockroachdb/cockroach/pkg/kv"
"github.com/cockroachdb/cockroach/pkg/roachpb"
"github.com/cockroachdb/cockroach/pkg/security"
"github.com/cockroachdb/cockroach/pkg/settings/cluster"
Expand Down Expand Up @@ -3387,7 +3388,7 @@ func TestIndexBackfillAfterGC(t *testing.T) {
RequestHeader: roachpb.RequestHeaderFromSpan(sp),
Threshold: tc.Server(0).Clock().Now(),
}
_, err := client.SendWrapped(ctx, tc.Server(0).DistSender(), &gcr)
_, err := client.SendWrapped(ctx, tc.Server(0).DistSenderI().(*kv.DistSender), &gcr)
if err != nil {
panic(err)
}
Expand Down
9 changes: 5 additions & 4 deletions pkg/sql/stats/automatic_stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"time"

"github.com/cockroachdb/cockroach/pkg/base"
"github.com/cockroachdb/cockroach/pkg/gossip"
"github.com/cockroachdb/cockroach/pkg/internal/client"
"github.com/cockroachdb/cockroach/pkg/settings/cluster"
"github.com/cockroachdb/cockroach/pkg/sql/sem/tree"
Expand Down Expand Up @@ -53,7 +54,7 @@ func TestMaybeRefreshStats(t *testing.T) {

executor := s.InternalExecutor().(sqlutil.InternalExecutor)
descA := sqlbase.GetTableDescriptor(s.DB(), "t", "a")
cache := NewTableStatisticsCache(10 /* cacheSize */, s.Gossip(), kvDB, executor)
cache := NewTableStatisticsCache(10 /* cacheSize */, s.GossipI().(*gossip.Gossip), kvDB, executor)
refresher := MakeRefresher(st, executor, cache, time.Microsecond /* asOfTime */)

// There should not be any stats yet.
Expand Down Expand Up @@ -123,7 +124,7 @@ func TestAverageRefreshTime(t *testing.T) {

executor := s.InternalExecutor().(sqlutil.InternalExecutor)
tableID := sqlbase.GetTableDescriptor(s.DB(), "t", "a").ID
cache := NewTableStatisticsCache(10 /* cacheSize */, s.Gossip(), kvDB, executor)
cache := NewTableStatisticsCache(10 /* cacheSize */, s.GossipI().(*gossip.Gossip), kvDB, executor)
refresher := MakeRefresher(st, executor, cache, time.Microsecond /* asOfTime */)

checkAverageRefreshTime := func(expected time.Duration) error {
Expand Down Expand Up @@ -339,7 +340,7 @@ func TestAutoStatsReadOnlyTables(t *testing.T) {
CREATE TABLE t.a (k INT PRIMARY KEY);`)

executor := s.InternalExecutor().(sqlutil.InternalExecutor)
cache := NewTableStatisticsCache(10 /* cacheSize */, s.Gossip(), kvDB, executor)
cache := NewTableStatisticsCache(10 /* cacheSize */, s.GossipI().(*gossip.Gossip), kvDB, executor)
refresher := MakeRefresher(st, executor, cache, time.Microsecond /* asOfTime */)

AutomaticStatisticsClusterMode.Override(&st.SV, true)
Expand Down Expand Up @@ -370,7 +371,7 @@ func TestNoRetryOnFailure(t *testing.T) {
defer evalCtx.Stop(ctx)

executor := s.InternalExecutor().(sqlutil.InternalExecutor)
cache := NewTableStatisticsCache(10 /* cacheSize */, s.Gossip(), kvDB, executor)
cache := NewTableStatisticsCache(10 /* cacheSize */, s.GossipI().(*gossip.Gossip), kvDB, executor)
r := MakeRefresher(st, executor, cache, time.Microsecond /* asOfTime */)

// Try to refresh stats on a table that doesn't exist.
Expand Down
3 changes: 2 additions & 1 deletion pkg/sql/stats/delete_stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"time"

"github.com/cockroachdb/cockroach/pkg/base"
"github.com/cockroachdb/cockroach/pkg/gossip"
"github.com/cockroachdb/cockroach/pkg/internal/client"
"github.com/cockroachdb/cockroach/pkg/sql/sqlbase"
"github.com/cockroachdb/cockroach/pkg/sql/sqlutil"
Expand All @@ -33,7 +34,7 @@ func TestDeleteOldStatsForColumns(t *testing.T) {
s, _, db := serverutils.StartServer(t, base.TestServerArgs{})
defer s.Stopper().Stop(ctx)
ex := s.InternalExecutor().(sqlutil.InternalExecutor)
cache := NewTableStatisticsCache(10 /* cacheSize */, s.Gossip(), db, ex)
cache := NewTableStatisticsCache(10 /* cacheSize */, s.GossipI().(*gossip.Gossip), db, ex)

// The test data must be ordered by CreatedAt DESC so the calculated set of
// expected deleted stats is correct.
Expand Down
3 changes: 2 additions & 1 deletion pkg/sql/stats/gossip_invalidation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"testing"

"github.com/cockroachdb/cockroach/pkg/base"
"github.com/cockroachdb/cockroach/pkg/gossip"
"github.com/cockroachdb/cockroach/pkg/sql/sqlbase"
"github.com/cockroachdb/cockroach/pkg/sql/sqlutil"
"github.com/cockroachdb/cockroach/pkg/sql/stats"
Expand All @@ -36,7 +37,7 @@ func TestGossipInvalidation(t *testing.T) {

sc := stats.NewTableStatisticsCache(
10, /* cacheSize */
tc.Server(0).Gossip(),
tc.Server(0).GossipI().(*gossip.Gossip),
tc.Server(0).DB(),
tc.Server(0).InternalExecutor().(sqlutil.InternalExecutor),
)
Expand Down
5 changes: 3 additions & 2 deletions pkg/sql/stats/stats_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"time"

"github.com/cockroachdb/cockroach/pkg/base"
"github.com/cockroachdb/cockroach/pkg/gossip"
"github.com/cockroachdb/cockroach/pkg/internal/client"
"github.com/cockroachdb/cockroach/pkg/sql/sem/tree"
"github.com/cockroachdb/cockroach/pkg/sql/sqlbase"
Expand Down Expand Up @@ -209,7 +210,7 @@ func TestCacheBasic(t *testing.T) {
// Create a cache and iteratively query the cache for each tableID. This
// will result in the cache getting populated. When the stats cache size is
// exceeded, entries should be evicted according to the LRU policy.
sc := NewTableStatisticsCache(2 /* cacheSize */, s.Gossip(), db, ex)
sc := NewTableStatisticsCache(2 /* cacheSize */, s.GossipI().(*gossip.Gossip), db, ex)
for _, tableID := range tableIDs {
if err := checkStatsForTable(ctx, sc, expectedStats[tableID], tableID); err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -263,7 +264,7 @@ func TestCacheWait(t *testing.T) {
}
sort.Sort(tableIDs)

sc := NewTableStatisticsCache(len(tableIDs), s.Gossip(), db, ex)
sc := NewTableStatisticsCache(len(tableIDs), s.GossipI().(*gossip.Gossip), db, ex)
for _, tableID := range tableIDs {
if err := checkStatsForTable(ctx, sc, expectedStats[tableID], tableID); err != nil {
t.Fatal(err)
Expand Down
3 changes: 2 additions & 1 deletion pkg/sqlmigrations/migrations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"time"

"github.com/cockroachdb/cockroach/pkg/base"
"github.com/cockroachdb/cockroach/pkg/gossip"
"github.com/cockroachdb/cockroach/pkg/internal/client"
"github.com/cockroachdb/cockroach/pkg/keys"
"github.com/cockroachdb/cockroach/pkg/roachpb"
Expand Down Expand Up @@ -601,7 +602,7 @@ func TestExpectedInitialRangeCount(t *testing.T) {
return errors.New("last migration has not completed")
}

sysCfg := s.Gossip().GetSystemConfig()
sysCfg := s.GossipI().(*gossip.Gossip).GetSystemConfig()
if sysCfg == nil {
return errors.New("gossipped system config not available")
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/storage/bulk/sst_batcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ func runTestImport(t *testing.T, batchSize uint64) {
if err != nil {
t.Fatal(err)
}
r, _, err := s.DistSender().RangeDescriptorCache().LookupRangeDescriptorWithEvictionToken(ctx, addr, nil, false)
r, _, err := s.DistSenderI().(*kv.DistSender).RangeDescriptorCache().LookupRangeDescriptorWithEvictionToken(
ctx, addr, nil, false)
if err != nil {
t.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/gossip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func TestGossipHandlesReplacedNode(t *testing.T) {
tc.StopServer(oldNodeIdx)
tc.AddServer(t, newServerArgs)

tc.WaitForStores(t, tc.Server(1).Gossip())
tc.WaitForStores(t, tc.Server(1).GossipI().(*gossip.Gossip))

// Ensure that all servers still running are responsive. If the two remaining
// original nodes don't refresh their connection to the address of the first
Expand Down
3 changes: 2 additions & 1 deletion pkg/storage/replica_rangefeed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"time"

"github.com/cockroachdb/cockroach/pkg/internal/client"
"github.com/cockroachdb/cockroach/pkg/kv"
"github.com/cockroachdb/cockroach/pkg/roachpb"
"github.com/cockroachdb/cockroach/pkg/storage"
"github.com/cockroachdb/cockroach/pkg/testutils"
Expand Down Expand Up @@ -695,7 +696,7 @@ func TestReplicaRangefeedNudgeSlowClosedTimestamp(t *testing.T) {
rangeFeedChs := make([]chan *roachpb.RangeFeedEvent, len(repls))
rangeFeedErrC := make(chan error, len(repls))
for i := range repls {
ds := tc.Server(i).DistSender()
ds := tc.Server(i).DistSenderI().(*kv.DistSender)
rangeFeedCh := make(chan *roachpb.RangeFeedEvent)
rangeFeedChs[i] = rangeFeedCh
go func() {
Expand Down
Loading

0 comments on commit 497167b

Please sign in to comment.