aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIlnaz Nizametdinov <ilnaz@ydb.tech>2025-02-13 18:36:28 +0300
committerGitHub <noreply@github.com>2025-02-13 18:36:28 +0300
commit8af7595650a3d7370a517a3d597348520ec4e3ff (patch)
treebd9812def84729e94431d36a7284ed919af78a41
parentb62ee74dc98f015d3f1b2b58490be3e31cab3d3b (diff)
downloadydb-8af7595650a3d7370a517a3d597348520ec4e3ff.tar.gz
Async replication backup & restore test (#14544)
-rw-r--r--ydb/services/ydb/backup_ut/ydb_backup_ut.cpp104
1 files changed, 87 insertions, 17 deletions
diff --git a/ydb/services/ydb/backup_ut/ydb_backup_ut.cpp b/ydb/services/ydb/backup_ut/ydb_backup_ut.cpp
index 45fac0e085..d8ecba76c8 100644
--- a/ydb/services/ydb/backup_ut/ydb_backup_ut.cpp
+++ b/ydb/services/ydb/backup_ut/ydb_backup_ut.cpp
@@ -2,12 +2,14 @@
#include <ydb/core/wrappers/ut_helpers/s3_mock.h>
+#include <ydb/public/api/protos/draft/ydb_replication.pb.h>
#include <ydb/public/api/protos/draft/ydb_view.pb.h>
#include <ydb/public/api/protos/ydb_rate_limiter.pb.h>
#include <ydb/public/lib/ydb_cli/common/recursive_list.h>
#include <ydb/public/lib/ydb_cli/dump/dump.h>
#include <ydb/public/lib/yson_value/ydb_yson_value.h>
#include <ydb-cpp-sdk/client/coordination/coordination.h>
+#include <ydb-cpp-sdk/client/draft/ydb_replication.h>
#include <ydb-cpp-sdk/client/draft/ydb_view.h>
#include <ydb-cpp-sdk/client/export/export.h>
#include <ydb-cpp-sdk/client/import/import.h>
@@ -932,10 +934,65 @@ void TestCoordinationNodeResourcesArePreserved(
}
}
+void TestReplicationSettingsArePreserved(
+ const TString& endpoint,
+ NQuery::TSession& session,
+ NReplication::TReplicationClient& client,
+ TBackupFunction&& backup,
+ TRestoreFunction&& restore)
+{
+ ExecuteQuery(session, "CREATE OBJECT `secret` (TYPE SECRET) WITH (value = 'root@builtin');", true);
+ ExecuteQuery(session, "CREATE TABLE `/Root/table` (k Uint32, v Utf8, PRIMARY KEY (k));", true);
+ ExecuteQuery(session, Sprintf(R"(
+ CREATE ASYNC REPLICATION `/Root/replication` FOR
+ `/Root/table` AS `/Root/replica`
+ WITH (
+ CONNECTION_STRING = 'grpc://%s/?database=/Root',
+ TOKEN_SECRET_NAME = 'secret'
+ );)", endpoint.c_str()), true
+ );
+
+ auto waitReplicationInit = [&client]() {
+ int retry = 0;
+ do {
+ auto result = client.DescribeReplication("/Root/replication").ExtractValueSync();
+ const auto& desc = result.GetReplicationDescription();
+ if (desc.GetItems().empty()) {
+ Sleep(TDuration::Seconds(1));
+ } else {
+ break;
+ }
+ } while (++retry < 10);
+ UNIT_ASSERT(retry < 10);
+ };
+
+ auto checkDescription = [&client, &endpoint]() {
+ auto result = client.DescribeReplication("/Root/replication").ExtractValueSync();
+ const auto& desc = result.GetReplicationDescription();
+
+ const auto& params = desc.GetConnectionParams();
+ UNIT_ASSERT_VALUES_EQUAL(params.GetDiscoveryEndpoint(), endpoint);
+ UNIT_ASSERT_VALUES_EQUAL(params.GetDatabase(), "/Root");
+ UNIT_ASSERT_VALUES_EQUAL(params.GetOAuthCredentials().TokenSecretName, "secret");
+
+ const auto& items = desc.GetItems();
+ UNIT_ASSERT_VALUES_EQUAL(items.size(), 1);
+ UNIT_ASSERT_VALUES_EQUAL(items.at(0).SrcPath, "/Root/table");
+ UNIT_ASSERT_VALUES_EQUAL(items.at(0).DstPath, "/Root/replica");
+ };
+
+ waitReplicationInit();
+ checkDescription();
+ backup();
+ ExecuteQuery(session, "DROP ASYNC REPLICATION `/Root/replication` CASCADE;", true);
+ restore();
+ waitReplicationInit();
+ checkDescription();
}
-Y_UNIT_TEST_SUITE(BackupRestore) {
+}
+Y_UNIT_TEST_SUITE(BackupRestore) {
auto CreateBackupLambda(const TDriver& driver, const TFsPath& fsPath, const TString& dbPath = "/Root") {
return [&]() {
NDump::TClient backupClient(driver);
@@ -1321,34 +1378,49 @@ Y_UNIT_TEST_SUITE(BackupRestore) {
);
}
+ void TestReplicationBackupRestore() {
+ TKikimrWithGrpcAndRootSchema server;
+
+ const auto endpoint = Sprintf("localhost:%u", server.GetPort());
+ auto driver = TDriver(TDriverConfig().SetEndpoint(endpoint).SetAuthToken("root@builtin"));
+
+ NQuery::TQueryClient queryClient(driver);
+ auto session = queryClient.GetSession().ExtractValueSync().GetSession();
+ NReplication::TReplicationClient replicationClient(driver);
+
+ TTempDir tempDir;
+ const auto& pathToBackup = tempDir.Path();
+
+ TestReplicationSettingsArePreserved(
+ endpoint, session, replicationClient,
+ CreateBackupLambda(driver, pathToBackup),
+ CreateRestoreLambda(driver, pathToBackup)
+ );
+ }
+
Y_UNIT_TEST_ALL_PROTO_ENUM_VALUES(TestAllSchemeObjectTypes, NKikimrSchemeOp::EPathType) {
using namespace NKikimrSchemeOp;
switch (Value) {
case EPathTypeTable:
- TestTableBackupRestore();
- break;
+ return TestTableBackupRestore();
case EPathTypeTableIndex:
- TestTableWithIndexBackupRestore();
- break;
+ return TestTableWithIndexBackupRestore();
case EPathTypeSequence:
- TestTableWithSerialBackupRestore();
- break;
+ return TestTableWithSerialBackupRestore();
case EPathTypeDir:
- TestDirectoryBackupRestore();
- break;
+ return TestDirectoryBackupRestore();
case EPathTypePersQueueGroup:
- TestTopicBackupRestoreWithoutData();
- break;
+ return TestTopicBackupRestoreWithoutData();
case EPathTypeSubDomain:
case EPathTypeExtSubDomain:
break; // https://github.com/ydb-platform/ydb/issues/10432
case EPathTypeView:
- TestViewBackupRestore();
- break;
+ return TestViewBackupRestore();
case EPathTypeCdcStream:
break; // https://github.com/ydb-platform/ydb/issues/7054
case EPathTypeReplication:
+ return TestReplicationBackupRestore();
case EPathTypeTransfer:
break; // https://github.com/ydb-platform/ydb/issues/10436
case EPathTypeExternalTable:
@@ -1358,8 +1430,7 @@ Y_UNIT_TEST_SUITE(BackupRestore) {
case EPathTypeResourcePool:
break; // https://github.com/ydb-platform/ydb/issues/10440
case EPathTypeKesus:
- TestKesusBackupRestore();
- break;
+ return TestKesusBackupRestore();
case EPathTypeColumnStore:
case EPathTypeColumnTable:
break; // https://github.com/ydb-platform/ydb/issues/10459
@@ -1384,8 +1455,7 @@ Y_UNIT_TEST_SUITE(BackupRestore) {
case EIndexTypeGlobal:
case EIndexTypeGlobalAsync:
case EIndexTypeGlobalVectorKmeansTree:
- TestTableWithIndexBackupRestore(Value);
- break;
+ return TestTableWithIndexBackupRestore(Value);
case EIndexTypeGlobalUnique:
break; // https://github.com/ydb-platform/ydb/issues/10468
case EIndexTypeInvalid: