Skip to content

Commit 8af7595

Browse files
authored
Async replication backup & restore test (#14544)
1 parent b62ee74 commit 8af7595

File tree

1 file changed

+87
-17
lines changed

1 file changed

+87
-17
lines changed

ydb/services/ydb/backup_ut/ydb_backup_ut.cpp

Lines changed: 87 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22

33
#include <ydb/core/wrappers/ut_helpers/s3_mock.h>
44

5+
#include <ydb/public/api/protos/draft/ydb_replication.pb.h>
56
#include <ydb/public/api/protos/draft/ydb_view.pb.h>
67
#include <ydb/public/api/protos/ydb_rate_limiter.pb.h>
78
#include <ydb/public/lib/ydb_cli/common/recursive_list.h>
89
#include <ydb/public/lib/ydb_cli/dump/dump.h>
910
#include <ydb/public/lib/yson_value/ydb_yson_value.h>
1011
#include <ydb-cpp-sdk/client/coordination/coordination.h>
12+
#include <ydb-cpp-sdk/client/draft/ydb_replication.h>
1113
#include <ydb-cpp-sdk/client/draft/ydb_view.h>
1214
#include <ydb-cpp-sdk/client/export/export.h>
1315
#include <ydb-cpp-sdk/client/import/import.h>
@@ -932,10 +934,65 @@ void TestCoordinationNodeResourcesArePreserved(
932934
}
933935
}
934936

937+
void TestReplicationSettingsArePreserved(
938+
const TString& endpoint,
939+
NQuery::TSession& session,
940+
NReplication::TReplicationClient& client,
941+
TBackupFunction&& backup,
942+
TRestoreFunction&& restore)
943+
{
944+
ExecuteQuery(session, "CREATE OBJECT `secret` (TYPE SECRET) WITH (value = 'root@builtin');", true);
945+
ExecuteQuery(session, "CREATE TABLE `/Root/table` (k Uint32, v Utf8, PRIMARY KEY (k));", true);
946+
ExecuteQuery(session, Sprintf(R"(
947+
CREATE ASYNC REPLICATION `/Root/replication` FOR
948+
`/Root/table` AS `/Root/replica`
949+
WITH (
950+
CONNECTION_STRING = 'grpc://%s/?database=/Root',
951+
TOKEN_SECRET_NAME = 'secret'
952+
);)", endpoint.c_str()), true
953+
);
954+
955+
auto waitReplicationInit = [&client]() {
956+
int retry = 0;
957+
do {
958+
auto result = client.DescribeReplication("/Root/replication").ExtractValueSync();
959+
const auto& desc = result.GetReplicationDescription();
960+
if (desc.GetItems().empty()) {
961+
Sleep(TDuration::Seconds(1));
962+
} else {
963+
break;
964+
}
965+
} while (++retry < 10);
966+
UNIT_ASSERT(retry < 10);
967+
};
968+
969+
auto checkDescription = [&client, &endpoint]() {
970+
auto result = client.DescribeReplication("/Root/replication").ExtractValueSync();
971+
const auto& desc = result.GetReplicationDescription();
972+
973+
const auto& params = desc.GetConnectionParams();
974+
UNIT_ASSERT_VALUES_EQUAL(params.GetDiscoveryEndpoint(), endpoint);
975+
UNIT_ASSERT_VALUES_EQUAL(params.GetDatabase(), "/Root");
976+
UNIT_ASSERT_VALUES_EQUAL(params.GetOAuthCredentials().TokenSecretName, "secret");
977+
978+
const auto& items = desc.GetItems();
979+
UNIT_ASSERT_VALUES_EQUAL(items.size(), 1);
980+
UNIT_ASSERT_VALUES_EQUAL(items.at(0).SrcPath, "/Root/table");
981+
UNIT_ASSERT_VALUES_EQUAL(items.at(0).DstPath, "/Root/replica");
982+
};
983+
984+
waitReplicationInit();
985+
checkDescription();
986+
backup();
987+
ExecuteQuery(session, "DROP ASYNC REPLICATION `/Root/replication` CASCADE;", true);
988+
restore();
989+
waitReplicationInit();
990+
checkDescription();
935991
}
936992

937-
Y_UNIT_TEST_SUITE(BackupRestore) {
993+
}
938994

995+
Y_UNIT_TEST_SUITE(BackupRestore) {
939996
auto CreateBackupLambda(const TDriver& driver, const TFsPath& fsPath, const TString& dbPath = "/Root") {
940997
return [&]() {
941998
NDump::TClient backupClient(driver);
@@ -1321,34 +1378,49 @@ Y_UNIT_TEST_SUITE(BackupRestore) {
13211378
);
13221379
}
13231380

1381+
void TestReplicationBackupRestore() {
1382+
TKikimrWithGrpcAndRootSchema server;
1383+
1384+
const auto endpoint = Sprintf("localhost:%u", server.GetPort());
1385+
auto driver = TDriver(TDriverConfig().SetEndpoint(endpoint).SetAuthToken("root@builtin"));
1386+
1387+
NQuery::TQueryClient queryClient(driver);
1388+
auto session = queryClient.GetSession().ExtractValueSync().GetSession();
1389+
NReplication::TReplicationClient replicationClient(driver);
1390+
1391+
TTempDir tempDir;
1392+
const auto& pathToBackup = tempDir.Path();
1393+
1394+
TestReplicationSettingsArePreserved(
1395+
endpoint, session, replicationClient,
1396+
CreateBackupLambda(driver, pathToBackup),
1397+
CreateRestoreLambda(driver, pathToBackup)
1398+
);
1399+
}
1400+
13241401
Y_UNIT_TEST_ALL_PROTO_ENUM_VALUES(TestAllSchemeObjectTypes, NKikimrSchemeOp::EPathType) {
13251402
using namespace NKikimrSchemeOp;
13261403

13271404
switch (Value) {
13281405
case EPathTypeTable:
1329-
TestTableBackupRestore();
1330-
break;
1406+
return TestTableBackupRestore();
13311407
case EPathTypeTableIndex:
1332-
TestTableWithIndexBackupRestore();
1333-
break;
1408+
return TestTableWithIndexBackupRestore();
13341409
case EPathTypeSequence:
1335-
TestTableWithSerialBackupRestore();
1336-
break;
1410+
return TestTableWithSerialBackupRestore();
13371411
case EPathTypeDir:
1338-
TestDirectoryBackupRestore();
1339-
break;
1412+
return TestDirectoryBackupRestore();
13401413
case EPathTypePersQueueGroup:
1341-
TestTopicBackupRestoreWithoutData();
1342-
break;
1414+
return TestTopicBackupRestoreWithoutData();
13431415
case EPathTypeSubDomain:
13441416
case EPathTypeExtSubDomain:
13451417
break; // https://github.com/ydb-platform/ydb/issues/10432
13461418
case EPathTypeView:
1347-
TestViewBackupRestore();
1348-
break;
1419+
return TestViewBackupRestore();
13491420
case EPathTypeCdcStream:
13501421
break; // https://github.com/ydb-platform/ydb/issues/7054
13511422
case EPathTypeReplication:
1423+
return TestReplicationBackupRestore();
13521424
case EPathTypeTransfer:
13531425
break; // https://github.com/ydb-platform/ydb/issues/10436
13541426
case EPathTypeExternalTable:
@@ -1358,8 +1430,7 @@ Y_UNIT_TEST_SUITE(BackupRestore) {
13581430
case EPathTypeResourcePool:
13591431
break; // https://github.com/ydb-platform/ydb/issues/10440
13601432
case EPathTypeKesus:
1361-
TestKesusBackupRestore();
1362-
break;
1433+
return TestKesusBackupRestore();
13631434
case EPathTypeColumnStore:
13641435
case EPathTypeColumnTable:
13651436
break; // https://github.com/ydb-platform/ydb/issues/10459
@@ -1384,8 +1455,7 @@ Y_UNIT_TEST_SUITE(BackupRestore) {
13841455
case EIndexTypeGlobal:
13851456
case EIndexTypeGlobalAsync:
13861457
case EIndexTypeGlobalVectorKmeansTree:
1387-
TestTableWithIndexBackupRestore(Value);
1388-
break;
1458+
return TestTableWithIndexBackupRestore(Value);
13891459
case EIndexTypeGlobalUnique:
13901460
break; // https://github.com/ydb-platform/ydb/issues/10468
13911461
case EIndexTypeInvalid:

0 commit comments

Comments
 (0)