2
2
3
3
#include < ydb/core/wrappers/ut_helpers/s3_mock.h>
4
4
5
+ #include < ydb/public/api/protos/draft/ydb_replication.pb.h>
5
6
#include < ydb/public/api/protos/draft/ydb_view.pb.h>
6
7
#include < ydb/public/api/protos/ydb_rate_limiter.pb.h>
7
8
#include < ydb/public/lib/ydb_cli/common/recursive_list.h>
8
9
#include < ydb/public/lib/ydb_cli/dump/dump.h>
9
10
#include < ydb/public/lib/yson_value/ydb_yson_value.h>
10
11
#include < ydb-cpp-sdk/client/coordination/coordination.h>
12
+ #include < ydb-cpp-sdk/client/draft/ydb_replication.h>
11
13
#include < ydb-cpp-sdk/client/draft/ydb_view.h>
12
14
#include < ydb-cpp-sdk/client/export/export.h>
13
15
#include < ydb-cpp-sdk/client/import/import.h>
@@ -932,10 +934,65 @@ void TestCoordinationNodeResourcesArePreserved(
932
934
}
933
935
}
934
936
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 ();
935
991
}
936
992
937
- Y_UNIT_TEST_SUITE (BackupRestore) {
993
+ }
938
994
995
+ Y_UNIT_TEST_SUITE (BackupRestore) {
939
996
auto CreateBackupLambda (const TDriver& driver, const TFsPath& fsPath, const TString& dbPath = " /Root" ) {
940
997
return [&]() {
941
998
NDump::TClient backupClient (driver);
@@ -1321,34 +1378,49 @@ Y_UNIT_TEST_SUITE(BackupRestore) {
1321
1378
);
1322
1379
}
1323
1380
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
+
1324
1401
Y_UNIT_TEST_ALL_PROTO_ENUM_VALUES (TestAllSchemeObjectTypes, NKikimrSchemeOp::EPathType) {
1325
1402
using namespace NKikimrSchemeOp ;
1326
1403
1327
1404
switch (Value) {
1328
1405
case EPathTypeTable:
1329
- TestTableBackupRestore ();
1330
- break ;
1406
+ return TestTableBackupRestore ();
1331
1407
case EPathTypeTableIndex:
1332
- TestTableWithIndexBackupRestore ();
1333
- break ;
1408
+ return TestTableWithIndexBackupRestore ();
1334
1409
case EPathTypeSequence:
1335
- TestTableWithSerialBackupRestore ();
1336
- break ;
1410
+ return TestTableWithSerialBackupRestore ();
1337
1411
case EPathTypeDir:
1338
- TestDirectoryBackupRestore ();
1339
- break ;
1412
+ return TestDirectoryBackupRestore ();
1340
1413
case EPathTypePersQueueGroup:
1341
- TestTopicBackupRestoreWithoutData ();
1342
- break ;
1414
+ return TestTopicBackupRestoreWithoutData ();
1343
1415
case EPathTypeSubDomain:
1344
1416
case EPathTypeExtSubDomain:
1345
1417
break ; // https://github.com/ydb-platform/ydb/issues/10432
1346
1418
case EPathTypeView:
1347
- TestViewBackupRestore ();
1348
- break ;
1419
+ return TestViewBackupRestore ();
1349
1420
case EPathTypeCdcStream:
1350
1421
break ; // https://github.com/ydb-platform/ydb/issues/7054
1351
1422
case EPathTypeReplication:
1423
+ return TestReplicationBackupRestore ();
1352
1424
case EPathTypeTransfer:
1353
1425
break ; // https://github.com/ydb-platform/ydb/issues/10436
1354
1426
case EPathTypeExternalTable:
@@ -1358,8 +1430,7 @@ Y_UNIT_TEST_SUITE(BackupRestore) {
1358
1430
case EPathTypeResourcePool:
1359
1431
break ; // https://github.com/ydb-platform/ydb/issues/10440
1360
1432
case EPathTypeKesus:
1361
- TestKesusBackupRestore ();
1362
- break ;
1433
+ return TestKesusBackupRestore ();
1363
1434
case EPathTypeColumnStore:
1364
1435
case EPathTypeColumnTable:
1365
1436
break ; // https://github.com/ydb-platform/ydb/issues/10459
@@ -1384,8 +1455,7 @@ Y_UNIT_TEST_SUITE(BackupRestore) {
1384
1455
case EIndexTypeGlobal:
1385
1456
case EIndexTypeGlobalAsync:
1386
1457
case EIndexTypeGlobalVectorKmeansTree:
1387
- TestTableWithIndexBackupRestore (Value);
1388
- break ;
1458
+ return TestTableWithIndexBackupRestore (Value);
1389
1459
case EIndexTypeGlobalUnique:
1390
1460
break ; // https://github.com/ydb-platform/ydb/issues/10468
1391
1461
case EIndexTypeInvalid:
0 commit comments