Skip to content

Commit a521fe3

Browse files
feat(restore_test): reimplement TestRestoreFullAlternatorIntegration
1 parent c2b288c commit a521fe3

File tree

2 files changed

+77
-65
lines changed

2 files changed

+77
-65
lines changed

pkg/service/restore/restore_integration_test.go

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1454,6 +1454,83 @@ func TestRestoreTablesMethodIntegration(t *testing.T) {
14541454
}
14551455
}
14561456

1457+
func TestRestoreFullAlternatorIntegration(t *testing.T) {
1458+
h := newTestHelper(t, ManagedSecondClusterHosts(), ManagedClusterHosts())
1459+
1460+
ni, err := h.srcCluster.Client.AnyNodeInfo(context.Background())
1461+
if err != nil {
1462+
t.Fatal(err)
1463+
}
1464+
if ok, err := ni.SupportsAlternatorSchemaBackupFromAPI(); err != nil {
1465+
t.Fatal(err)
1466+
} else if !ok {
1467+
t.Skip("This test assumes that alternator tables are backed up and restored with alternator api")
1468+
}
1469+
1470+
Print("Prepare alternator schema")
1471+
altTab1 := "alt_full_1_" + AlternatorProblematicTableChars
1472+
altTab2 := "alt_full_2_" + AlternatorProblematicTableChars
1473+
altGSI1 := "gsi_1_" + AlternatorProblematicTableChars
1474+
altGSI2 := "gsi_2_" + AlternatorProblematicTableChars
1475+
CreateAlternatorTable(t, h.srcCluster.altClient, 2, altTab1, altTab2)
1476+
CreateAlternatorGSI(t, h.srcCluster.altClient, altTab1, altGSI1, altGSI2)
1477+
CreateAlternatorGSI(t, h.srcCluster.altClient, altTab2, altGSI1, altGSI2)
1478+
1479+
Print("Insert alternator rows")
1480+
const rowCnt = 100
1481+
InsertAlternatorTableData(t, h.srcCluster.altClient, rowCnt, altTab1, altTab2)
1482+
1483+
Print("Prepare simple clq schema")
1484+
ExecStmt(t, h.srcCluster.rootSession, "CREATE KEYSPACE cql_ks WITH replication = {'class': 'NetworkTopologyStrategy', 'dc1': 2} and tablets = {'enabled': false}")
1485+
createTable(t, h.srcCluster.rootSession, "cql_ks", "cql_tab")
1486+
CreateMaterializedView(t, h.srcCluster.rootSession, "cql_ks", "cql_tab", "cql_mv_1")
1487+
CreateMaterializedView(t, h.srcCluster.rootSession, "cql_ks", "cql_tab", "cql_mv_2")
1488+
CreateSecondaryIndex(t, h.srcCluster.rootSession, "cql_ks", "cql_tab", "cql_si_1")
1489+
1490+
Print("Insert simple cql rows")
1491+
fillTable(t, h.srcCluster.rootSession, rowCnt, "cql_ks", "cql_tab")
1492+
1493+
Print("Run backup")
1494+
loc := testLocation("alternator-full", "")
1495+
S3InitBucket(t, loc.Path)
1496+
backupProps := defaultTestBackupProperties(loc, "")
1497+
tag := h.runBackup(t, backupProps)
1498+
1499+
Print("Restore schema")
1500+
grantRestoreSchemaPermissions(t, h.dstCluster.rootSession, h.dstUser)
1501+
props := defaultTestProperties(loc, tag, false)
1502+
h.runRestore(t, props)
1503+
1504+
Print("Reset user permissions")
1505+
dropNonSuperUsers(t, h.dstCluster.rootSession)
1506+
createUser(t, h.dstCluster.rootSession, h.dstUser, h.dstPass)
1507+
1508+
Print("Restore data")
1509+
grantRestoreTablesPermissions(t, h.dstCluster.rootSession, nil, h.dstUser)
1510+
props = defaultTestProperties(loc, tag, true)
1511+
h.runRestore(t, props)
1512+
1513+
Print("Validate restored alternator data")
1514+
ValidateAlternatorTableData(t, h.dstCluster.altClient, rowCnt, 2, altTab1, altTab2)
1515+
ValidateAlternatorGSIData(t, h.dstCluster.altClient, rowCnt, altTab1, altGSI1, altGSI2)
1516+
ValidateAlternatorGSIData(t, h.dstCluster.altClient, rowCnt, altTab2, altGSI1, altGSI2)
1517+
1518+
Print("Validate restored simple cql data")
1519+
cqlTabs := []table{
1520+
{ks: "cql_ks", tab: "cql_tab"},
1521+
{ks: "cql_ks", tab: "cql_mv_1"},
1522+
{ks: "cql_ks", tab: "cql_mv_2"},
1523+
{ks: "cql_ks", tab: "cql_si_1_index"},
1524+
}
1525+
for _, tab := range cqlTabs {
1526+
srcCnt := rowCount(t, h.srcCluster.rootSession, tab.ks, tab.tab)
1527+
dstCnt := rowCount(t, h.dstCluster.rootSession, tab.ks, tab.tab)
1528+
if srcCnt != dstCnt {
1529+
t.Fatalf("Expected %d rows in cql table %q.%q, got %d", srcCnt, tab.ks, tab.tab, dstCnt)
1530+
}
1531+
}
1532+
}
1533+
14571534
func getDCFromRemoteSSTableDir(t *testing.T, remoteSSTableDir string) string {
14581535
t.Helper()
14591536
// hacky way of extracting value of dc_name from /dc/{dc_name}/node/

pkg/service/restore/service_restore_integration_test.go

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1480,71 +1480,6 @@ func restoreAllTables(t *testing.T, schemaTarget, tablesTarget Target, keyspace
14801480
dstH.validateRestoreSuccess(dstSession, srcSession, tablesTarget, toValidate)
14811481
}
14821482

1483-
func TestRestoreFullAlternatorIntegration(t *testing.T) {
1484-
testBucket, _, testUser := getBucketKeyspaceUser(t)
1485-
const (
1486-
testTable = "Tab_le-With1.da_sh2-aNd.d33ot.-"
1487-
testKeyspace = "alternator_" + testTable
1488-
testBatchSize = 1
1489-
testParallel = 3
1490-
testAlternatorPort = 8000
1491-
)
1492-
schemaTarget := defaultTestTarget("dc1", testBucket, "", testBatchSize, testParallel, false)
1493-
tablesTarget := defaultTestTarget("dc1", testBucket, "", testBatchSize, testParallel, true)
1494-
restoreAlternator(t, schemaTarget, tablesTarget, testKeyspace, testTable, testUser, testAlternatorPort)
1495-
}
1496-
1497-
func restoreAlternator(t *testing.T, schemaTarget, tablesTarget Target, testKeyspace, testTable, user string, alternatorPort int) {
1498-
var (
1499-
ctx = context.Background()
1500-
cfg = defaultTestConfig()
1501-
srcClientCfg = scyllaclient.TestConfig(ManagedSecondClusterHosts(), AgentAuthToken())
1502-
mgrSession = CreateScyllaManagerDBSession(t)
1503-
dstH = newRestoreTestHelper(t, mgrSession, cfg, schemaTarget.Location[0], nil, "", "")
1504-
srcH = newRestoreTestHelper(t, mgrSession, cfg, schemaTarget.Location[0], &srcClientCfg, "", "")
1505-
dstSession = CreateSessionAndDropAllKeyspaces(t, dstH.Client)
1506-
srcSession = CreateSessionAndDropAllKeyspaces(t, srcH.Client)
1507-
)
1508-
1509-
dstH.skipImpossibleSchemaTest()
1510-
// SM can't restore Alternator table schema via CQL.
1511-
// See https://github.com/scylladb/scylladb/issues/19112
1512-
dstH.skipCQLSchemaTestAssumingSSTables()
1513-
1514-
// Restore should be performed on user with limited permissions
1515-
dropNonSuperUsers(t, dstSession)
1516-
createUser(t, dstSession, user, "pass")
1517-
dstH = newRestoreTestHelper(t, mgrSession, cfg, schemaTarget.Location[0], nil, user, "pass")
1518-
1519-
accessKeyID, secretAccessKey := GetAlternatorCreds(t, srcSession, "")
1520-
client := CreateAlternatorClient(t, srcH.Client, ManagedSecondClusterHosts()[0], accessKeyID, secretAccessKey)
1521-
CreateAlternatorTable(t, client, testTable)
1522-
FillAlternatorTable(t, client, testTable, 100)
1523-
1524-
schemaTarget.SnapshotTag = srcH.simpleBackup(schemaTarget.Location[0])
1525-
1526-
Print("Restore schema on different cluster")
1527-
grantRestoreSchemaPermissions(t, dstSession, user)
1528-
if err := dstH.service.Restore(ctx, dstH.ClusterID, dstH.TaskID, dstH.RunID, dstH.targetToProperties(schemaTarget)); err != nil {
1529-
t.Fatal(err)
1530-
}
1531-
1532-
toValidate := []table{{ks: testKeyspace, tab: testTable}}
1533-
dstH.validateRestoreSuccess(dstSession, srcSession, schemaTarget, toValidate)
1534-
1535-
tablesTarget.SnapshotTag = schemaTarget.SnapshotTag
1536-
dstH.TaskID = uuid.MustRandom()
1537-
dstH.RunID = uuid.MustRandom()
1538-
grantRestoreTablesPermissions(t, dstSession, tablesTarget.Keyspace, user)
1539-
1540-
Print("Restore tables on different cluster")
1541-
if err := dstH.service.Restore(ctx, dstH.ClusterID, dstH.TaskID, dstH.RunID, dstH.targetToProperties(tablesTarget)); err != nil {
1542-
t.Fatal(err)
1543-
}
1544-
1545-
dstH.validateRestoreSuccess(dstSession, srcSession, tablesTarget, toValidate)
1546-
}
1547-
15481483
func (h *restoreTestHelper) targetToProperties(target Target) json.RawMessage {
15491484
props, err := json.Marshal(target)
15501485
if err != nil {

0 commit comments

Comments
 (0)