Skip to content

Commit

Permalink
Cleanup unused vtorc code
Browse files Browse the repository at this point in the history
This was found with `deadcode`, probably after the cleanup done in
#15580.

Signed-off-by: Dirkjan Bussink <[email protected]>
  • Loading branch information
dbussink committed Mar 29, 2024
1 parent aa52fbd commit 0a3e6f4
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 186 deletions.
73 changes: 0 additions & 73 deletions go/vt/vtorc/inst/instance_dao.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,6 @@ func RegisterStats() {
})
}

// ReadTopologyInstance collects information on the state of a MySQL
// server and writes the result synchronously to the vtorc
// backend.
func ReadTopologyInstance(tabletAlias string) (*Instance, error) {
return ReadTopologyInstanceBufferable(tabletAlias, nil)
}

// ReadTopologyInstanceBufferable connects to a topology MySQL instance
// and collects information on the server and its replication state.
// It writes the information retrieved into vtorc's backend.
Expand Down Expand Up @@ -629,35 +622,6 @@ func ReadInstance(tabletAlias string) (*Instance, bool, error) {
return instances[0], true, nil
}

// ReadReplicaInstances reads replicas of a given primary
func ReadReplicaInstances(primaryHost string, primaryPort int) ([](*Instance), error) {
condition := `
source_host = ?
and source_port = ?
`
return readInstancesByCondition(condition, sqlutils.Args(primaryHost, primaryPort), "")
}

// ReadReplicaInstancesIncludingBinlogServerSubReplicas returns a list of direct slves including any replicas
// of a binlog server replica
func ReadReplicaInstancesIncludingBinlogServerSubReplicas(primaryHost string, primaryPort int) ([](*Instance), error) {
replicas, err := ReadReplicaInstances(primaryHost, primaryPort)
if err != nil {
return replicas, err
}
for _, replica := range replicas {
replica := replica
if replica.IsBinlogServer() {
binlogServerReplicas, err := ReadReplicaInstancesIncludingBinlogServerSubReplicas(replica.Hostname, replica.Port)
if err != nil {
return replicas, err
}
replicas = append(replicas, binlogServerReplicas...)
}
}
return replicas, err
}

// ReadProblemInstances reads all instances with problems
func ReadProblemInstances(keyspace string, shard string) ([](*Instance), error) {
condition := `
Expand Down Expand Up @@ -1156,43 +1120,6 @@ func SnapshotTopologies() error {
return ExecDBWriteFunc(writeFunc)
}

// RecordStaleInstanceBinlogCoordinates snapshots the binlog coordinates of instances
func RecordStaleInstanceBinlogCoordinates(tabletAlias string, binlogCoordinates *BinlogCoordinates) error {
args := sqlutils.Args(
tabletAlias,
binlogCoordinates.LogFile, binlogCoordinates.LogPos,
)
_, err := db.ExecVTOrc(`
delete from
database_instance_stale_binlog_coordinates
where
alias = ?
and (
binary_log_file != ?
or binary_log_pos != ?
)
`,
args...,
)
if err != nil {
log.Error(err)
return err
}
_, err = db.ExecVTOrc(`
insert ignore into
database_instance_stale_binlog_coordinates (
alias, binary_log_file, binary_log_pos, first_seen
)
values (
?, ?, ?, NOW()
)`,
args...)
if err != nil {
log.Error(err)
}
return err
}

func ExpireStaleInstanceBinlogCoordinates() error {
expireSeconds := config.Config.ReasonableReplicationLagSeconds * 2
if expireSeconds < config.StaleInstanceCoordinatesExpireSeconds {
Expand Down
47 changes: 0 additions & 47 deletions go/vt/vtorc/inst/instance_dao_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,53 +196,6 @@ func TestReadInstance(t *testing.T) {
}
}

// TestReadReplicaInstances is used to test the functionality of ReadReplicaInstances and verify its failure modes and successes.
func TestReadReplicaInstances(t *testing.T) {
tests := []struct {
name string
tabletPort int
replicasLen int
}{
{
name: "Read success - Multiple replicas",
// This tabletPort corresponds to zone1-0000000101. That is the primary for the data inserted.
// Check initialSQL for more details.
tabletPort: 6714,
replicasLen: 3,
}, {
name: "Unknown tablet",
// This tabletPort corresponds to none of the tablets.
// Check initialSQL for more details.
tabletPort: 343,
replicasLen: 0,
}, {
name: "Read success - No replicas",
// This tabletPort corresponds to zone1-0000000100. That is a replica tablet, with no replicas of its own.
// Check initialSQL for more details.
tabletPort: 6711,
replicasLen: 0,
},
}

// Clear the database after the test. The easiest way to do that is to run all the initialization commands again.
defer func() {
db.ClearVTOrcDatabase()
}()
for _, query := range initialSQL {
_, err := db.ExecVTOrc(query)
require.NoError(t, err)
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {

instances, err := ReadReplicaInstances("localhost", tt.tabletPort)
require.NoError(t, err)
require.EqualValues(t, tt.replicasLen, len(instances))
})
}
}

// TestReadProblemInstances is used to test the functionality of ReadProblemInstances and verify its failure modes and successes.
func TestReadProblemInstances(t *testing.T) {
// The test is intended to be used as follows. The initial data is stored into the database. Following this, some specific queries are run that each individual test specifies to get the desired state.
Expand Down
30 changes: 0 additions & 30 deletions go/vt/vtorc/inst/instance_topology_dao.go

This file was deleted.

36 changes: 0 additions & 36 deletions go/vt/vtorc/logic/tablet_discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import (
"vitess.io/vitess/go/vt/topo"
"vitess.io/vitess/go/vt/topo/topoproto"
"vitess.io/vitess/go/vt/topotools"
"vitess.io/vitess/go/vt/vtctl/reparentutil"
"vitess.io/vitess/go/vt/vtorc/config"
"vitess.io/vitess/go/vt/vtorc/db"
"vitess.io/vitess/go/vt/vtorc/inst"
Expand Down Expand Up @@ -338,38 +337,3 @@ func shardPrimary(keyspace string, shard string) (primary *topodatapb.Tablet, er
}
return primary, err
}

// restartsReplication restarts the replication on the provided replicaKey. It also sets the correct semi-sync settings when it starts replication
func restartReplication(replicaAlias string) error {
replicaTablet, err := inst.ReadTablet(replicaAlias)
if err != nil {
log.Info("Could not read tablet - %+v", replicaAlias)
return err
}

primaryTablet, err := shardPrimary(replicaTablet.Keyspace, replicaTablet.Shard)
if err != nil {
log.Info("Could not compute primary for %v/%v", replicaTablet.Keyspace, replicaTablet.Shard)
return err
}

durabilityPolicy, err := inst.GetDurabilityPolicy(replicaTablet.Keyspace)
if err != nil {
log.Info("Could not read the durability policy for %v/%v", replicaTablet.Keyspace, replicaTablet.Shard)
return err
}

ctx, cancel := context.WithTimeout(context.Background(), time.Duration(config.Config.WaitReplicasTimeoutSeconds)*time.Second)
defer cancel()
err = tmc.StopReplication(ctx, replicaTablet)
if err != nil {
log.Info("Could not stop replication on %v", replicaAlias)
return err
}
err = tmc.StartReplication(ctx, replicaTablet, reparentutil.IsReplicaSemiSync(durabilityPolicy, primaryTablet, replicaTablet))
if err != nil {
log.Info("Could not start replication on %v", replicaAlias)
return err
}
return nil
}

0 comments on commit 0a3e6f4

Please sign in to comment.