Skip to content

Commit 6cd0f50

Browse files
authored
feature flags: enable EnableAlterDatabaseCreateHiveFirst (#14078)
This is a long awaited improvement in the dedicated database creation process. `EnableAlterDatabaseCreateHiveFirst` (`enable_alter_database_create_hive_first` in the config) feature flag affects how system tablets of the dedicated database are created (and than managed throughout their lifetime). System tablets (schemeshard, hive, coordinators/mediators, sysview-processor etc) are those that constitute and service the database itself. Without `EnableAlterDatabaseCreateHiveFirst`, creation of the new dedicated database leaves all it's system tablets in the custody of the main ("root") Hive of the cluster (all other tablets created afterwards live in the custody of the tenant Hive). Database with that separation of responsibilities works fine. The downside is that complete lack of common vision and coordination between two Hives (root and the tenant's) can lead to suboptimal results when database' tablets (both system and others) are balanced under the load. With `EnableAlterDatabaseCreateHiveFirst`, creation of the new dedicated database leaves all tenant tablets (except tenant Hive) in the custody of the tenant hive. Which alleviates problem with tablet balancing.
1 parent e76be64 commit 6cd0f50

File tree

4 files changed

+45
-15
lines changed

4 files changed

+45
-15
lines changed

ydb/core/protos/feature_flags.proto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ message TFeatureFlags {
104104
optional bool EnableDataShardGenericReadSets = 81 [default = false];
105105
// enable alter database operation to create subdomain's system tablets
106106
// directly in subdomain's hive
107-
optional bool EnableAlterDatabaseCreateHiveFirst = 82 [default = false];
107+
optional bool EnableAlterDatabaseCreateHiveFirst = 82 [default = true];
108108
reserved 83; // EnableKqpDataQuerySourceRead
109109
optional bool EnableSmallDiskOptimization = 84 [default = true];
110110
optional bool EnableDataShardVolatileTransactions = 85 [default = true];

ydb/core/tx/coordinator/coordinator_ut.cpp

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,21 @@
88
#include <library/cpp/testing/unittest/registar.h>
99
#include <library/cpp/threading/future/async.h>
1010

11+
// ad-hoc test parametrization support: only for single boolean flag
12+
// taken from ydb/core/ut/common/kqp_ut_common.h:Y_UNIT_TEST_TWIN
13+
//TODO: introduce general support for test parametrization?
14+
#define Y_UNIT_TEST_FLAG(N, OPT) \
15+
template<bool OPT> void N(NUnitTest::TTestContext&); \
16+
struct TTestRegistration##N { \
17+
TTestRegistration##N() { \
18+
TCurrentTest::AddTest(#N "-" #OPT "-false", static_cast<void (*)(NUnitTest::TTestContext&)>(&N<false>), false); \
19+
TCurrentTest::AddTest(#N "-" #OPT "-true", static_cast<void (*)(NUnitTest::TTestContext&)>(&N<true>), false); \
20+
} \
21+
}; \
22+
static TTestRegistration##N testRegistration##N; \
23+
template<bool OPT> \
24+
void N(NUnitTest::TTestContext&)
25+
1126
namespace NKikimr::NFlatTxCoordinator::NTest {
1227

1328
using namespace Tests;
@@ -379,7 +394,7 @@ namespace NKikimr::NFlatTxCoordinator::NTest {
379394
Ydb::Cms::CreateDatabaseRequest,
380395
Ydb::Cms::CreateDatabaseResponse>;
381396

382-
Y_UNIT_TEST(RestoreTenantConfiguration) {
397+
Y_UNIT_TEST_FLAG(RestoreTenantConfiguration, AlterDatabaseCreateHiveFirst) {
383398
struct TCoordinatorHooks : public ICoordinatorHooks {
384399
bool AllowPersistConfig_ = true;
385400
std::unordered_map<ui64, NKikimrSubDomains::TProcessingParams> PersistConfig_;
@@ -397,7 +412,8 @@ namespace NKikimr::NFlatTxCoordinator::NTest {
397412
.SetNodeCount(1)
398413
.SetDynamicNodeCount(4)
399414
.SetUseRealThreads(false)
400-
.AddStoragePoolType("ssd");
415+
.AddStoragePoolType("ssd")
416+
.SetEnableAlterDatabaseCreateHiveFirst(AlterDatabaseCreateHiveFirst);
401417

402418
Tests::TServer::TPtr server = new TServer(serverSettings);
403419

@@ -414,6 +430,8 @@ namespace NKikimr::NFlatTxCoordinator::NTest {
414430
hooks.AllowPersistConfig_ = false;
415431
hooks.PersistConfig_.clear();
416432

433+
const ui32 ExpectedProcessingParamsVersion = 2 + (AlterDatabaseCreateHiveFirst ? 1 : 0);
434+
417435
auto createDatabase = [&]() {
418436
Ydb::Cms::CreateDatabaseRequest request;
419437
request.set_path("/Root/db1");
@@ -445,8 +463,8 @@ namespace NKikimr::NFlatTxCoordinator::NTest {
445463
UNIT_ASSERT_C(hooks.PersistConfig_.size() > 0, "Expected coordinators to attempt to persist configs");
446464
std::vector<ui64> coordinators;
447465
for (auto& pr : hooks.PersistConfig_) {
448-
UNIT_ASSERT_C(pr.second.GetVersion() == 2,
449-
"Expected tenant coordinator to have a version 2 config:\n" << pr.second.DebugString());
466+
UNIT_ASSERT_C(pr.second.GetVersion() == ExpectedProcessingParamsVersion,
467+
"Expected tenant coordinator to have a version " << ExpectedProcessingParamsVersion << " config:\n" << pr.second.DebugString());
450468
coordinators.push_back(pr.first);
451469
}
452470

@@ -460,8 +478,8 @@ namespace NKikimr::NFlatTxCoordinator::NTest {
460478
runtime.SimulateSleep(TDuration::MilliSeconds(50));
461479
UNIT_ASSERT_C(hooks.PersistConfig_.size() == coordinators.size(), "Expected all coordinators to persist restored config");
462480
for (auto& pr : hooks.PersistConfig_) {
463-
UNIT_ASSERT_C(pr.second.GetVersion() == 2,
464-
"Expected tenant coordinator to restore a version 2 config:\n" << pr.second.DebugString());
481+
UNIT_ASSERT_C(pr.second.GetVersion() == ExpectedProcessingParamsVersion,
482+
"Expected tenant coordinator to restore a version " << ExpectedProcessingParamsVersion << " config:\n" << pr.second.DebugString());
465483
}
466484

467485
// runtime.SetLogPriority(NKikimrServices::TABLET_MAIN, NActors::NLog::PRI_DEBUG);

ydb/core/tx/schemeshard/ut_serverless/ut_serverless.cpp

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ Y_UNIT_TEST_SUITE(TSchemeShardServerLess) {
1313
Y_UNIT_TEST(Fake) {
1414
}
1515

16-
Y_UNIT_TEST(BaseCase) {
16+
Y_UNIT_TEST_FLAG(BaseCase, AlterDatabaseCreateHiveFirst) {
1717
TTestBasicRuntime runtime;
18-
TTestEnv env(runtime);
18+
TTestEnv env(runtime, TTestEnvOptions().EnableAlterDatabaseCreateHiveFirst(AlterDatabaseCreateHiveFirst));
1919
ui64 txId = 100;
2020

2121
TestCreateExtSubDomain(runtime, ++txId, "/MyRoot",
@@ -106,7 +106,17 @@ Y_UNIT_TEST_SUITE(TSchemeShardServerLess) {
106106
NLs::PathsInsideDomain(1),
107107
NLs::ShardsInsideDomain(0)});
108108

109-
ui64 sharedHiveTablets = TTestTxConfig::FakeHiveTablets + NKikimr::TFakeHiveState::TABLETS_PER_CHILD_HIVE;
109+
// Check that shards of ServerLess0 db are gone after its deletion.
110+
//
111+
// SharedDB contains:
112+
// - 3 of its own shards: SchemeShard, Coordinator, Mediator
113+
// - 4 of ServerLess0's shards: SchemeShard, Coordinator, Mediator, 1 x DataShard of the table0
114+
//
115+
116+
//NOTE: AlterDatabaseCreateHiveFirst create system tablets in a tenant hive, otherwise they are created in the root hive
117+
ui64 sharedHiveTablets = TTestTxConfig::FakeHiveTablets + (AlterDatabaseCreateHiveFirst ? TFakeHiveState::TABLETS_PER_CHILD_HIVE : 1)
118+
+ 3 // shards of SharedDB
119+
;
110120
env.TestWaitTabletDeletion(runtime, xrange(sharedHiveTablets, sharedHiveTablets + 4), sharedHive);
111121
}
112122

@@ -299,7 +309,7 @@ Y_UNIT_TEST_SUITE(TSchemeShardServerLess) {
299309
UNIT_ASSERT(sharedDbSchemeShard != 0
300310
&& sharedDbSchemeShard != (ui64)-1
301311
&& sharedDbSchemeShard != TTestTxConfig::SchemeShard);
302-
312+
303313
TestDescribeResult(DescribePath(runtime, sharedDbSchemeShard, "/MyRoot/SharedDB"),
304314
{NLs::PathExist,
305315
NLs::ServerlessComputeResourcesMode(EServerlessComputeResourcesModeUnspecified)});
@@ -308,7 +318,7 @@ Y_UNIT_TEST_SUITE(TSchemeShardServerLess) {
308318
R"(
309319
ResourcesDomainKey {
310320
SchemeShard: %lu
311-
PathId: 2
321+
PathId: 2
312322
}
313323
Name: "ServerLess0"
314324
)",
@@ -348,7 +358,7 @@ Y_UNIT_TEST_SUITE(TSchemeShardServerLess) {
348358
TestDescribeResult(DescribePath(runtime, tenantSchemeShard, "/MyRoot/ServerLess0"),
349359
{NLs::PathExist,
350360
NLs::ServerlessComputeResourcesMode(EServerlessComputeResourcesModeShared)});
351-
361+
352362
auto checkServerlessComputeResourcesMode = [&](EServerlessComputeResourcesMode serverlessComputeResourcesMode) {
353363
TString alterData = Sprintf(
354364
R"(
@@ -406,7 +416,7 @@ Y_UNIT_TEST_SUITE(TSchemeShardServerLess) {
406416
R"(
407417
ResourcesDomainKey {
408418
SchemeShard: %lu
409-
PathId: 2
419+
PathId: 2
410420
}
411421
Name: "ServerLess0"
412422
)",
@@ -487,7 +497,7 @@ Y_UNIT_TEST_SUITE(TSchemeShardServerLess) {
487497
R"(
488498
ResourcesDomainKey {
489499
SchemeShard: %lu
490-
PathId: 2
500+
PathId: 2
491501
}
492502
Name: "ServerLess0"
493503
)",

ydb/core/tx/schemeshard/ut_serverless/ya.make

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ FORK_SUBTESTS()
44

55
SIZE(MEDIUM)
66

7+
TIMEOUT(120)
8+
79
PEERDIR(
810
library/cpp/getopt
911
library/cpp/regex/pcre

0 commit comments

Comments
 (0)