diff --git a/go/vt/vtorc/logic/topology_recovery_dao.go b/go/vt/vtorc/logic/topology_recovery_dao.go index d60c0fbfd5b..2bf5a9aa530 100644 --- a/go/vt/vtorc/logic/topology_recovery_dao.go +++ b/go/vt/vtorc/logic/topology_recovery_dao.go @@ -264,6 +264,7 @@ func RegisterBlockedRecoveries(analysisEntry *inst.ReplicationAnalysis, blocking ?, ?, ?, + ?, NOW(), ? ) diff --git a/go/vt/vtorc/logic/topology_recovery_dao_test.go b/go/vt/vtorc/logic/topology_recovery_dao_test.go index b977e9c4371..a89c28e7572 100644 --- a/go/vt/vtorc/logic/topology_recovery_dao_test.go +++ b/go/vt/vtorc/logic/topology_recovery_dao_test.go @@ -19,6 +19,7 @@ package logic import ( "testing" + "github.com/openark/golib/sqlutils" "github.com/stretchr/testify/require" "vitess.io/vitess/go/vt/vtorc/db" @@ -68,3 +69,39 @@ func TestTopologyRecovery(t *testing.T) { require.EqualValues(t, topologyRecovery.ID, recoveries[0].ID) }) } + +// TestBlockedRecoveryInsertion tests that we are able to insert into the blocked_recovery table. +func TestBlockedRecoveryInsertion(t *testing.T) { + orcDb, err := db.OpenVTOrc() + require.NoError(t, err) + defer func() { + _, err = orcDb.Exec("delete from blocked_topology_recovery") + require.NoError(t, err) + }() + + analysisEntry := &inst.ReplicationAnalysis{ + AnalyzedInstanceKey: inst.InstanceKey{ + Hostname: "localhost", + Port: 100, + }, + ClusterDetails: inst.ClusterInfo{ + Keyspace: "ks", + Shard: "0", + }, + Analysis: inst.DeadPrimaryAndSomeReplicas, + } + blockedRecovery := &TopologyRecovery{ + ID: 1, + } + err = RegisterBlockedRecoveries(analysisEntry, []*TopologyRecovery{blockedRecovery}) + require.NoError(t, err) + + totalBlockedRecoveries := 0 + err = db.QueryVTOrc("select count(*) as blocked_recoveries from blocked_topology_recovery", nil, func(rowMap sqlutils.RowMap) error { + totalBlockedRecoveries = rowMap.GetInt("blocked_recoveries") + return nil + }) + require.NoError(t, err) + // There should be 1 blocked recovery after insertion + require.Equal(t, 1, totalBlockedRecoveries) +}