summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpixcc <[email protected]>2023-11-17 08:37:33 +0300
committerpixcc <[email protected]>2023-11-17 09:00:36 +0300
commit1bd96dde93b8acb80dff78cfec49e136200db630 (patch)
treebd5eeb3a79037240a59d8f8453184bbf7629daf4
parent591b2e71e69c8a2124ab0e0aae4803422c18a9c4 (diff)
Add local registration in shared hive KIKIMR-20108
Add local registration in shared hive KIKIMR-20108
-rw-r--r--ydb/core/mind/hive/hive_ut.cpp79
-rw-r--r--ydb/core/mind/local.cpp16
-rw-r--r--ydb/core/protos/subdomains.proto1
-rw-r--r--ydb/core/tx/schemeshard/schemeshard_path_describer.cpp4
-rw-r--r--ydb/core/tx/schemeshard/ut_helpers/ls_checks.cpp13
-rw-r--r--ydb/core/tx/schemeshard/ut_helpers/ls_checks.h3
-rw-r--r--ydb/core/tx/schemeshard/ut_helpers/test_env.cpp8
-rw-r--r--ydb/core/tx/schemeshard/ut_helpers/test_env.h8
-rw-r--r--ydb/core/tx/schemeshard/ut_serverless/ut_serverless.cpp15
9 files changed, 130 insertions, 17 deletions
diff --git a/ydb/core/mind/hive/hive_ut.cpp b/ydb/core/mind/hive/hive_ut.cpp
index 7fe1b2f585b..938c367b0d8 100644
--- a/ydb/core/mind/hive/hive_ut.cpp
+++ b/ydb/core/mind/hive/hive_ut.cpp
@@ -5742,6 +5742,85 @@ Y_UNIT_TEST_SUITE(THiveTest) {
WaitForTabletIsUp(runtime, tablet, 1);
}
}
+
+ Y_UNIT_TEST(TestLocalRegistrationInSharedHive) {
+ TTestBasicRuntime runtime(2, false);
+ Setup(runtime, true);
+
+ const ui64 hiveTablet = MakeDefaultHiveID(0);
+ const ui64 testerTablet = MakeDefaultHiveID(1);
+ CreateTestBootstrapper(runtime, CreateTestTabletInfo(hiveTablet, TTabletTypes::Hive), &CreateDefaultHive);
+ CreateTestBootstrapper(runtime, CreateTestTabletInfo(TTestTxConfig::SchemeShard, TTabletTypes::SchemeShard), &CreateFlatTxSchemeShard);
+ MakeSureTabletIsUp(runtime, hiveTablet, 0); // root hive good
+ MakeSureTabletIsUp(runtime, TTestTxConfig::SchemeShard, 0); // root ss good
+
+ TActorId sender = runtime.AllocateEdgeActor(0);
+ InitSchemeRoot(runtime, sender);
+
+ // Create subdomain
+ ui32 txId = 100;
+ TSubDomainKey subdomainKey;
+ do {
+ auto modifyScheme = MakeHolder<NSchemeShard::TEvSchemeShard::TEvModifySchemeTransaction>();
+ modifyScheme->Record.SetTxId(++txId);
+ auto* transaction = modifyScheme->Record.AddTransaction();
+ transaction->SetWorkingDir("/dc-1");
+ transaction->SetOperationType(NKikimrSchemeOp::ESchemeOpCreateExtSubDomain);
+ auto* subdomain = transaction->MutableSubDomain();
+ subdomain->SetName("tenant1");
+ runtime.SendToPipe(TTestTxConfig::SchemeShard, sender, modifyScheme.Release());
+ TAutoPtr<IEventHandle> handle;
+ auto reply = runtime.GrabEdgeEventRethrow<NSchemeShard::TEvSchemeShard::TEvModifySchemeTransactionResult>(handle, TDuration::MilliSeconds(100));
+ if (reply) {
+ subdomainKey = TSubDomainKey(reply->Record.GetSchemeshardId(), reply->Record.GetPathId());
+ UNIT_ASSERT_VALUES_EQUAL(reply->Record.GetStatus(), NKikimrScheme::EStatus::StatusAccepted);
+ break;
+ }
+ } while (true);
+
+ // Create shared hive
+ THolder<TEvHive::TEvCreateTablet> createSharedHive = MakeHolder<TEvHive::TEvCreateTablet>(testerTablet, 0, TTabletTypes::Hive, BINDED_CHANNELS);
+ createSharedHive->Record.AddAllowedDomains();
+ createSharedHive->Record.MutableAllowedDomains(0)->SetSchemeShard(TTestTxConfig::SchemeShard);
+ createSharedHive->Record.MutableAllowedDomains(0)->SetPathId(1);
+ ui64 sharedHiveTablet = SendCreateTestTablet(runtime, hiveTablet, testerTablet, std::move(createSharedHive), 0, false);
+ MakeSureTabletIsUp(runtime, sharedHiveTablet, 0); // shared hive good
+
+ // Setup resolving shared hive for subdomain
+ runtime.SetObserverFunc([&](TAutoPtr<IEventHandle>& event) {
+ if (event->GetTypeRewrite() == NSchemeShard::TEvSchemeShard::EvDescribeSchemeResult) {
+ auto* record = event->Get<NSchemeShard::TEvSchemeShard::TEvDescribeSchemeResult>()->MutableRecord();
+ TSubDomainKey resolvingSubdomainKey(record->GetPathOwnerId(), record->GetPathId());
+ if (resolvingSubdomainKey == subdomainKey) {
+ record->MutablePathDescription()->MutableDomainDescription()->SetSharedHive(sharedHiveTablet);
+ }
+ }
+ return TTestActorRuntime::EEventAction::PROCESS;
+ });
+
+ // Start local for subdomain
+ SendKillLocal(runtime, 1);
+ CreateLocalForTenant(runtime, 1, "/dc-1/tenant1");
+
+ bool seenLocalRegistrationInSharedHive = false;
+ TTestActorRuntime::TEventObserver prevObserverFunc;
+ prevObserverFunc = runtime.SetObserverFunc([&](TAutoPtr<IEventHandle>& event) {
+ if (event->GetTypeRewrite() == TEvLocal::EvRegisterNode) {
+ const auto& record = event->Get<TEvLocal::TEvRegisterNode>()->Record;
+ if (record.GetHiveId() == sharedHiveTablet
+ && !record.GetServicedDomains().empty()
+ && TSubDomainKey(record.GetServicedDomains().Get(0)) == subdomainKey) {
+ seenLocalRegistrationInSharedHive = true;
+ }
+ }
+ return prevObserverFunc(event);
+ });
+
+ TDispatchOptions options;
+ options.FinalEvents.emplace_back(TEvLocal::EvRegisterNode, 2);
+ runtime.DispatchEvents(options);
+ UNIT_ASSERT(seenLocalRegistrationInSharedHive);
+ }
}
}
diff --git a/ydb/core/mind/local.cpp b/ydb/core/mind/local.cpp
index 53fd20f7c03..647b837181d 100644
--- a/ydb/core/mind/local.cpp
+++ b/ydb/core/mind/local.cpp
@@ -1224,25 +1224,29 @@ class TDomainLocal : public TActorBootstrapped<TDomainLocal> {
return;
}
Y_ABORT_UNLESS(rec.GetPathDescription().HasDomainDescription());
- Y_ABORT_UNLESS(rec.GetPathDescription().GetDomainDescription().GetDomainKey().GetSchemeShard() == SchemeRoot);
+ const auto &domainDesc = rec.GetPathDescription().GetDomainDescription();
+ Y_ABORT_UNLESS(domainDesc.GetDomainKey().GetSchemeShard() == SchemeRoot);
TVector<TTabletId> hiveIds(HiveIds);
- TString path = rec.GetPath();
-
- TTabletId hiveId = rec.GetPathDescription().GetDomainDescription().GetProcessingParams().GetHive();
+ TTabletId hiveId = domainDesc.GetProcessingParams().GetHive();
if (hiveId) {
hiveIds.emplace_back(hiveId);
}
+ TTabletId sharedHiveId = domainDesc.GetSharedHive();
+ if (sharedHiveId) {
+ hiveIds.emplace_back(sharedHiveId);
+ }
RegisterAsSubDomain(rec, task, hiveIds, ctx);
+ const TString &path = rec.GetPath();
auto itTenant = RunningTenants.find(path);
if (itTenant != RunningTenants.end()) {
TTenantInfo& tenant = itTenant->second;
tenant.HiveIds = hiveIds;
- SendStatus(rec.GetPath(), task.Senders, ctx);
- ResolveTasks.erase(rec.GetPath());
+ SendStatus(path, task.Senders, ctx);
+ ResolveTasks.erase(path);
// subscribe for schema updates
const auto& domains = *AppData()->DomainsInfo;
diff --git a/ydb/core/protos/subdomains.proto b/ydb/core/protos/subdomains.proto
index 88e6d0f564c..52e1f2ad985 100644
--- a/ydb/core/protos/subdomains.proto
+++ b/ydb/core/protos/subdomains.proto
@@ -101,6 +101,7 @@ message TDomainDescription {
optional NLoginProto.TSecurityState SecurityState = 20;
optional TAuditSettings AuditSettings = 21;
+ optional fixed64 SharedHive = 22;
}
message TSchemeQuotas {
diff --git a/ydb/core/tx/schemeshard/schemeshard_path_describer.cpp b/ydb/core/tx/schemeshard/schemeshard_path_describer.cpp
index 333b3e81c4f..b7abb4fbc34 100644
--- a/ydb/core/tx/schemeshard/schemeshard_path_describer.cpp
+++ b/ydb/core/tx/schemeshard/schemeshard_path_describer.cpp
@@ -712,6 +712,10 @@ void TPathDescriber::DescribeDomainRoot(TPathElement::TPtr pathEl) {
if (const auto& auditSettings = subDomainInfo->GetAuditSettings()) {
entry->MutableAuditSettings()->CopyFrom(*auditSettings);
}
+
+ if (TTabletId sharedHive = subDomainInfo->GetSharedHive()) {
+ entry->SetSharedHive(sharedHive.GetValue());
+ }
}
void TPathDescriber::DescribeDomainExtra(TPathElement::TPtr pathEl) {
diff --git a/ydb/core/tx/schemeshard/ut_helpers/ls_checks.cpp b/ydb/core/tx/schemeshard/ut_helpers/ls_checks.cpp
index 881813906a2..9865e71fab3 100644
--- a/ydb/core/tx/schemeshard/ut_helpers/ls_checks.cpp
+++ b/ydb/core/tx/schemeshard/ut_helpers/ls_checks.cpp
@@ -212,6 +212,19 @@ TCheckFunc StoragePoolsEqual(TSet<TString> poolNames) {
};
}
+TCheckFunc SharedHive(ui64 sharedHiveId) {
+ return [=] (const NKikimrScheme::TEvDescribeSchemeResult& record) {
+ UNIT_ASSERT_C(IsGoodDomainStatus(record.GetStatus()), "Unexpected status: " << record.GetStatus());
+
+ const auto& domainDesc = record.GetPathDescription().GetDomainDescription();
+ if (sharedHiveId) {
+ UNIT_ASSERT_VALUES_EQUAL(domainDesc.GetSharedHive(), sharedHiveId);
+ } else {
+ UNIT_ASSERT(!domainDesc.HasSharedHive());
+ }
+ };
+}
+
TCheckFunc DomainCoordinators(TVector<ui64> coordinators) {
return [=] (const NKikimrScheme::TEvDescribeSchemeResult& record) {
UNIT_ASSERT_C(IsGoodDomainStatus(record.GetStatus()), "Unexpected status: " << record.GetStatus());
diff --git a/ydb/core/tx/schemeshard/ut_helpers/ls_checks.h b/ydb/core/tx/schemeshard/ut_helpers/ls_checks.h
index 7c849a7c53e..caaf236410f 100644
--- a/ydb/core/tx/schemeshard/ut_helpers/ls_checks.h
+++ b/ydb/core/tx/schemeshard/ut_helpers/ls_checks.h
@@ -148,7 +148,8 @@ namespace NLs {
TCheckFunc KesusConfigIs(ui64 self_check_period_millis, ui64 session_grace_period_millis);
TCheckFunc DatabaseQuotas(ui64 dataStreamShards);
-
+ TCheckFunc SharedHive(ui64 sharedHiveId);
+
template<class TCheck>
void PerformAllChecks(const NKikimrScheme::TEvDescribeSchemeResult& result, TCheck&& check) {
check(result);
diff --git a/ydb/core/tx/schemeshard/ut_helpers/test_env.cpp b/ydb/core/tx/schemeshard/ut_helpers/test_env.cpp
index aa1058317b6..72358593e96 100644
--- a/ydb/core/tx/schemeshard/ut_helpers/test_env.cpp
+++ b/ydb/core/tx/schemeshard/ut_helpers/test_env.cpp
@@ -746,13 +746,13 @@ void NSchemeShardUT_Private::TTestEnv::TestWaitNotification(NActors::TTestActorR
TestWaitNotification(runtime, ids, schemeshardId);
}
-void NSchemeShardUT_Private::TTestEnv::TestWaitTabletDeletion(NActors::TTestActorRuntime &runtime, TSet<ui64> tabletIds) {
+void NSchemeShardUT_Private::TTestEnv::TestWaitTabletDeletion(NActors::TTestActorRuntime &runtime, TSet<ui64> tabletIds, ui64 hive) {
TActorId sender = runtime.AllocateEdgeActor();
for (ui64 tabletId : tabletIds) {
Cerr << "wait until " << tabletId << " is deleted" << Endl;
auto ev = new TEvFakeHive::TEvSubscribeToTabletDeletion(tabletId);
- ForwardToTablet(runtime, TTestTxConfig::Hive, sender, ev);
+ ForwardToTablet(runtime, hive, sender, ev);
}
TAutoPtr<IEventHandle> handle;
@@ -768,8 +768,8 @@ void NSchemeShardUT_Private::TTestEnv::TestWaitTabletDeletion(NActors::TTestActo
}
}
-void NSchemeShardUT_Private::TTestEnv::TestWaitTabletDeletion(NActors::TTestActorRuntime &runtime, ui64 tabletId) {
- TestWaitTabletDeletion(runtime, TSet<ui64>{tabletId});
+void NSchemeShardUT_Private::TTestEnv::TestWaitTabletDeletion(NActors::TTestActorRuntime &runtime, ui64 tabletId, ui64 hive) {
+ TestWaitTabletDeletion(runtime, TSet<ui64>{tabletId}, hive);
}
void NSchemeShardUT_Private::TTestEnv::TestWaitShardDeletion(NActors::TTestActorRuntime &runtime, ui64 schemeShard, TSet<TShardIdx> shardIds) {
diff --git a/ydb/core/tx/schemeshard/ut_helpers/test_env.h b/ydb/core/tx/schemeshard/ut_helpers/test_env.h
index 036ed4bebc5..d726c73a78f 100644
--- a/ydb/core/tx/schemeshard/ut_helpers/test_env.h
+++ b/ydb/core/tx/schemeshard/ut_helpers/test_env.h
@@ -98,12 +98,12 @@ namespace NSchemeShardUT_Private {
void TestWaitNotification(TTestActorRuntime& runtime, ui64 txId, ui64 schemeshardId = TTestTxConfig::SchemeShard);
template <class TContainer>
- void TestWaitTabletDeletion(TTestActorRuntime& runtime, TContainer tabletIds) {
+ void TestWaitTabletDeletion(TTestActorRuntime& runtime, const TContainer& tabletIds, ui64 hive = TTestTxConfig::Hive) {
TSet<ui64> set(tabletIds.begin(), tabletIds.end());
- TestWaitTabletDeletion(runtime, std::move(set));
+ TestWaitTabletDeletion(runtime, std::move(set), hive);
}
- void TestWaitTabletDeletion(TTestActorRuntime& runtime, TSet<ui64> tabletIds);
- void TestWaitTabletDeletion(TTestActorRuntime& runtime, ui64 tabletId);
+ void TestWaitTabletDeletion(TTestActorRuntime& runtime, TSet<ui64> tabletIds, ui64 hive = TTestTxConfig::Hive);
+ void TestWaitTabletDeletion(TTestActorRuntime& runtime, ui64 tabletId, ui64 hive = TTestTxConfig::Hive);
void TestWaitShardDeletion(TTestActorRuntime& runtime, TSet<ui64> localIds);
void TestWaitShardDeletion(TTestActorRuntime& runtime, ui64 schemeShard, TSet<ui64> localIds);
diff --git a/ydb/core/tx/schemeshard/ut_serverless/ut_serverless.cpp b/ydb/core/tx/schemeshard/ut_serverless/ut_serverless.cpp
index 7239a7562ce..d4ce2472590 100644
--- a/ydb/core/tx/schemeshard/ut_serverless/ut_serverless.cpp
+++ b/ydb/core/tx/schemeshard/ut_serverless/ut_serverless.cpp
@@ -34,10 +34,19 @@ Y_UNIT_TEST_SUITE(TSchemeShardServerLess) {
"Mediators: 1 "
"TimeCastBucketsPerMediator: 2 "
"ExternalSchemeShard: true "
- "ExternalHive: false " // ExternalHive is impossible in that environment yet
+ "ExternalHive: true "
"Name: \"SharedDB\"");
env.TestWaitNotification(runtime, txId);
+ ui64 sharedHive = 0;
+ TestDescribeResult(DescribePath(runtime, "/MyRoot/SharedDB"),
+ {NLs::PathExist,
+ NLs::IsExternalSubDomain("SharedDB"),
+ NLs::ExtractDomainHive(&sharedHive)});
+ UNIT_ASSERT(sharedHive != 0
+ && sharedHive != (ui64)-1
+ && sharedHive != TTestTxConfig::Hive);
+
TString createData = TStringBuilder()
<< "ResourcesDomainKey { SchemeShard: " << TTestTxConfig::SchemeShard << " PathId: " << 2 << " } "
<< "Name: \"ServerLess0\"";
@@ -63,6 +72,7 @@ Y_UNIT_TEST_SUITE(TSchemeShardServerLess) {
TestDescribeResult(DescribePath(runtime, "/MyRoot/ServerLess0"),
{NLs::PathExist,
NLs::IsExternalSubDomain("ServerLess0"),
+ NLs::SharedHive(sharedHive),
NLs::ExtractTenantSchemeshard(&tenantSchemeShard)});
UNIT_ASSERT(tenantSchemeShard != 0
@@ -94,7 +104,8 @@ Y_UNIT_TEST_SUITE(TSchemeShardServerLess) {
NLs::PathsInsideDomain(1),
NLs::ShardsInsideDomain(0)});
- env.TestWaitTabletDeletion(runtime, xrange(TTestTxConfig::FakeHiveTablets + 3, TTestTxConfig::FakeHiveTablets + 10));
+ ui64 sharedHiveTablets = TTestTxConfig::FakeHiveTablets + NKikimr::TFakeHiveState::TABLETS_PER_CHILD_HIVE;
+ env.TestWaitTabletDeletion(runtime, xrange(sharedHiveTablets, sharedHiveTablets + 4), sharedHive);
}
Y_UNIT_TEST(StorageBilling) {