Skip to content

Commit

Permalink
Fix insert query of blocked_recovery table in VTOrc (vitessio#12091)
Browse files Browse the repository at this point in the history
* feat: add failing test and fix the query of insertion

Signed-off-by: Manan Gupta <manan@planetscale.com>

* empty-commit

Signed-off-by: Manan Gupta <manan@planetscale.com>

Signed-off-by: Manan Gupta <manan@planetscale.com>
  • Loading branch information
GuptaManan100 authored and timvaillancourt committed Mar 15, 2024
1 parent 3dde42a commit a1ae5b3
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions go/vt/vtorc/logic/topology_recovery_dao.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ func RegisterBlockedRecoveries(analysisEntry *inst.ReplicationAnalysis, blocking
?,
?,
?,
?,
NOW(),
?
)
Expand Down
37 changes: 37 additions & 0 deletions go/vt/vtorc/logic/topology_recovery_dao_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}

0 comments on commit a1ae5b3

Please sign in to comment.