Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test vnodes backup and tablets restore #3924

Merged
merged 5 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions pkg/scyllaclient/config_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,18 @@ func (c *ConfigClient) ConsistentClusterManagement(ctx context.Context) (bool, e
return resp.Payload, err
}

// EnableTablets returns true if tablets are enabled.
func (c *ConfigClient) EnableTablets(ctx context.Context) (bool, error) {
resp, err := c.client.Config.FindConfigEnableTablets(config.NewFindConfigEnableTabletsParamsWithContext(ctx))
if isStatusCode400(err) {
return false, nil
}
if err != nil {
return false, err
}
return resp.Payload, err
}

// AlternatorEnforceAuthorization returns whether alternator requires authorization.
func (c *ConfigClient) AlternatorEnforceAuthorization(ctx context.Context) (bool, error) {
resp, err := c.client.Config.FindConfigAlternatorEnforceAuthorization(config.NewFindConfigAlternatorEnforceAuthorizationParamsWithContext(ctx))
Expand Down Expand Up @@ -291,6 +303,7 @@ func (c *ConfigClient) NodeInfo(ctx context.Context) (*NodeInfo, error) {
{Field: &ni.AlternatorEnforceAuthorization, Fetcher: c.AlternatorEnforceAuthorization},
{Field: &ni.SstableUUIDFormat, Fetcher: c.UUIDSStableIdentifiers},
{Field: &ni.ConsistentClusterManagement, Fetcher: c.ConsistentClusterManagement},
{Field: &ni.EnableTablets, Fetcher: c.EnableTablets},
}

for i, ff := range ffb {
Expand Down
10 changes: 10 additions & 0 deletions pkg/scyllaclient/config_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,14 @@ func TestClientConfigReturnsResponseFromScylla(t *testing.T) {
},
Golden: true,
},
{
Name: "Tablets enabled",
ResponseFilePath: "testdata/scylla_api/v2_config_enable_tablets.json",
BindClientFunc: func(client *scyllaclient.ConfigClient) configClientFunc {
return convertBool(client.ConsistentClusterManagement)
},
Golden: true,
},
}

for i := range table {
Expand Down Expand Up @@ -183,6 +191,7 @@ func TestConfigClientPullsNodeInformationUsingScyllaAPI(t *testing.T) {
scyllaclienttest.PathFileMatcher("/v2/config/alternator_enforce_authorization", "testdata/scylla_api/v2_config_alternator_enforce_authorization.json"),
scyllaclienttest.PathFileMatcher("/v2/config/uuid_sstable_identifiers_enabled", "testdata/scylla_api/v2_config_uuid_sstable_identifiers_enabled.json"),
scyllaclienttest.PathFileMatcher("/v2/config/consistent_cluster_management", "testdata/scylla_api/v2_config_consistent_cluster_management.json"),
scyllaclienttest.PathFileMatcher("/v2/config/enable_tablets", "testdata/scylla_api/v2_config_enable_tablets.json"),
),
)
defer closeServer()
Expand Down Expand Up @@ -232,6 +241,7 @@ func TestConfigOptionIsNotSupported(t *testing.T) {
scyllaclienttest.PathFileMatcher("/v2/config/alternator_enforce_authorization", "testdata/scylla_api/v2_config_alternator_disabled.400.json"),
scyllaclienttest.PathFileMatcher("/v2/config/uuid_sstable_identifiers_enabled", "testdata/scylla_api/v2_config_uuid_sstable_identifiers_enabled.400.json"),
scyllaclienttest.PathFileMatcher("/v2/config/consistent_cluster_management", "testdata/scylla_api/v2_config_consistent_cluster_management.400.json"),
scyllaclienttest.PathFileMatcher("/v2/config/enable_tablets", "testdata/scylla_api/v2_config_enable_tablets.400.json"),
),
)
defer closeServer()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"message": "No such config entry: enable_tablets", "code": 400}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
true
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@
"rpc_address":"192.168.100.101",
"rpc_port":"9160",
"sstable_uuid_format":true,
"consistent_cluster_management":true
"consistent_cluster_management":true,
"enable_tablets":true
}
25 changes: 25 additions & 0 deletions pkg/service/restore/helper_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"context"
"encoding/json"
"fmt"
"maps"
"strings"
"testing"

Expand Down Expand Up @@ -316,6 +317,30 @@ func rowCount(t *testing.T, s gocqlx.Session, ks, tab string) int {
return cnt
}

func validateTableContent[K, V comparable](t *testing.T, src, dst gocqlx.Session, keyspace, tab, keyColumn, valueColumn string) {
srcM := selectTableAsMap[K, V](t, src, keyspace, tab, keyColumn, valueColumn)
dstM := selectTableAsMap[K, V](t, dst, keyspace, tab, keyColumn, valueColumn)
if !maps.Equal(srcM, dstM) {
t.Fatalf("tables have different contents\nsrc:\n%v\ndst:\n%v", srcM, dstM)
}
}

func selectTableAsMap[K, V comparable](t *testing.T, s gocqlx.Session, keyspace, tab, keyColumn, valueColumn string) map[K]V {
var (
k K
v V
out = make(map[K]V)
)
it := s.Session.Query(fmt.Sprintf("SELECT %s, %s FROM %q.%q", keyColumn, valueColumn, keyspace, tab)).Iter()
for it.Scan(&k, &v) {
out[k] = v
}
if err := it.Close(); err != nil {
t.Fatal(errors.Wrapf(err, "select rows %s, %s from %q.%q", keyColumn, valueColumn, keyspace, tab))
}
return out
}

func filteredTables(t *testing.T, s gocqlx.Session, filter []string) []string {
f, err := ksfilter.NewFilter(filter)
if err != nil {
Expand Down
59 changes: 59 additions & 0 deletions pkg/service/restore/restore_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package restore_test

import (
"context"
"fmt"
"strings"
"testing"
Expand Down Expand Up @@ -266,3 +267,61 @@ func TestRestoreSchemaDropAddColumnIntegration(t *testing.T) {

h.validateIdenticalTables(t, []table{{ks: ks, tab: tab}})
}

func TestRestoreTablesVnodeToTabletsIntegration(t *testing.T) {
h := newTestHelper(t, ManagedSecondClusterHosts(), ManagedClusterHosts())

ni, err := h.dstCluster.Client.AnyNodeInfo(context.Background())
if err != nil {
t.Fatal(errors.Wrap(err, "get any node info"))
}
if !ni.EnableTablets {
t.Skip("This test assumes that tablets are supported")
}

ks := randomizedName("vnode_to_tablet_")
tab := randomizedName("tab_")
c1 := "id"
c2 := "data"

Print(fmt.Sprintf("Create %q.%q with vnode replication", ks, tab))
ksStmt := "CREATE KEYSPACE %q WITH replication = {'class': 'NetworkTopologyStrategy', 'dc1': %d} AND tablets = {'enabled': '%v'}"
tabStmt := "CREATE TABLE %q.%q (%s int PRIMARY KEY, %s int)"
ExecStmt(t, h.srcCluster.rootSession, fmt.Sprintf(ksStmt, ks, 2, false))
ExecStmt(t, h.srcCluster.rootSession, fmt.Sprintf(tabStmt, ks, tab, c1, c2))

Print("Fill created table")
rowCnt := 100
stmt := fmt.Sprintf("INSERT INTO %q.%q (id, data) VALUES (?, ?)", ks, tab)
q := h.srcCluster.rootSession.Query(stmt, []string{c1, c2})
defer q.Release()
for i := 0; i < rowCnt; i++ {
if err := q.Bind(i, i).Exec(); err != nil {
t.Fatal(errors.Wrap(err, "fill table"))
}
}

Print("Run backup")
loc := []Location{testLocation("vnode-to-tablets", "")}
S3InitBucket(t, loc[0].Path)
ksFilter := []string{ks}
tag := h.runBackup(t, map[string]any{
"location": loc,
"keyspace": ksFilter,
})

Print("Manually recreate tablet schema")
ExecStmt(t, h.dstCluster.rootSession, fmt.Sprintf(ksStmt, ks, 3, true))
ExecStmt(t, h.dstCluster.rootSession, fmt.Sprintf(tabStmt, ks, tab, c1, c2))

Print("Run restore tables")
grantRestoreTablesPermissions(t, h.dstCluster.rootSession, ksFilter, h.dstUser)
h.runRestore(t, map[string]any{
"location": loc,
"keyspace": ksFilter,
"snapshot_tag": tag,
"restore_tables": true,
})

validateTableContent[int, int](t, h.srcCluster.rootSession, h.dstCluster.rootSession, ks, tab, c1, c2)
}
4 changes: 4 additions & 0 deletions swagger/agent.json
Original file line number Diff line number Diff line change
Expand Up @@ -1474,6 +1474,10 @@
"consistent_cluster_management": {
"description": "Whether Scylla uses RAFT for cluster management and DDL.",
"type": "boolean"
},
"enable_tablets": {
"description": "Whether tablets are enabled.",
"type": "boolean"
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions swagger/gen/agent/models/node_info.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions swagger/gen/scylla/v2/client/config/config_client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading