Skip to content

Commit

Permalink
schemeshard: fix Alter{Ext,}SubDomain compatibility (#9198)
Browse files Browse the repository at this point in the history
`TAlterExtSubDomain` suboperation should be able to accept `ESchemeOpAlterSubDomain` operation type.
(Notice ExtSubDomain vs SubDomain.)

This is special compatibility case for those old subdomains that went through migration to a separate tenants at some time. Console tablet holds records about types of the subdomains but they hadn't been updated at the time of migration. So Console still thinks that old subdomains are plain subdomains whereas they had been migrated to the extsubdomains. And Console tablet is the main source of the subdomains alters. This compatibility case should be upholded until Console records will be fixed.

KIKIMR-21965
  • Loading branch information
ijon authored Sep 13, 2024
1 parent 1765b09 commit b0a5850
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,7 @@ class TSyncHive: public TSubOperationState {
}

bool HandleReply(TEvHive::TEvUpdateDomainReply::TPtr& ev, TOperationContext& context) override {
const TTabletId hive = TTabletId(ev->Get()->Record.GetOrigin());
const TTabletId hive = TTabletId(ev->Get()->Record.GetOrigin());

LOG_I(DebugHint() << "HandleReply TEvUpdateDomainReply"
<< ", from hive: " << hive);
Expand Down Expand Up @@ -1084,7 +1084,13 @@ ISubOperation::TPtr CreateAlterExtSubDomain(TOperationId id, TTxState::ETxState
}

TVector<ISubOperation::TPtr> CreateCompatibleAlterExtSubDomain(TOperationId id, const TTxTransaction& tx, TOperationContext& context) {
Y_ABORT_UNLESS(tx.GetOperationType() == NKikimrSchemeOp::ESchemeOpAlterExtSubDomain);
//NOTE: Accepting ESchemeOpAlterSubDomain operation for an ExtSubDomain is a special compatibility case
// for those old subdomains that at the time went through migration to a separate tenants.
// Console tablet holds records about types of the subdomains but they hadn't been updated
// at the migration time. So Console still thinks that old subdomains are plain subdomains
// whereas they had been migrated to the extsubdomains.
// This compatibility case should be upholded until Console records would be updated.
Y_ABORT_UNLESS(tx.GetOperationType() == NKikimrSchemeOp::ESchemeOpAlterExtSubDomain || tx.GetOperationType() == NKikimrSchemeOp::ESchemeOpAlterSubDomain);

LOG_I("CreateCompatibleAlterExtSubDomain, opId " << id
<< ", feature flag EnableAlterDatabaseCreateHiveFirst " << context.SS->EnableAlterDatabaseCreateHiveFirst
Expand Down
108 changes: 108 additions & 0 deletions ydb/core/tx/schemeshard/ut_extsubdomain/ut_extsubdomain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,114 @@ Y_UNIT_TEST_SUITE(TSchemeShardExtSubDomainTest) {
NLs::UserAttrsEqual({{"user__attr_1", "value"}})});
}

Y_UNIT_TEST_FLAG(AlterWithPlainAlterSubdomain, AlterDatabaseCreateHiveFirst) {
TTestBasicRuntime runtime;
TTestEnv env(runtime, TTestEnvOptions().EnableAlterDatabaseCreateHiveFirst(AlterDatabaseCreateHiveFirst));
ui64 txId = 100;

// Create extsubdomain

TestCreateExtSubDomain(runtime, ++txId, "/MyRoot",
R"(Name: "USER_0")"
);
TestAlterExtSubDomain(runtime, ++txId, "/MyRoot",
R"(
Name: "USER_0"
ExternalSchemeShard: true
PlanResolution: 50
Coordinators: 1
Mediators: 1
TimeCastBucketsPerMediator: 2
StoragePools {
Name: "pool-1"
Kind: "hdd"
}
)"
);
env.TestWaitNotification(runtime, {txId, txId - 1});

// Altering extsubdomain but with plain altersubdomain should succeed
// (post tenant migration compatibility)

//NOTE: SubDomain and not ExtSubdomain
TestAlterSubDomain(runtime, ++txId, "/MyRoot",
R"(
Name: "USER_0"
ExternalSchemeShard: true
PlanResolution: 50
Coordinators: 1
Mediators: 1
TimeCastBucketsPerMediator: 2
StoragePools {
Name: "pool-1"
Kind: "hdd"
}
)"
);
env.TestWaitNotification(runtime, txId);
}

Y_UNIT_TEST_FLAG(AlterTwiceAndWithPlainAlterSubdomain, AlterDatabaseCreateHiveFirst) {
TTestBasicRuntime runtime;
TTestEnv env(runtime, TTestEnvOptions().EnableAlterDatabaseCreateHiveFirst(AlterDatabaseCreateHiveFirst));
ui64 txId = 100;

TestCreateExtSubDomain(runtime, ++txId, "/MyRoot",
R"(Name: "USER_0")"
);
TestAlterExtSubDomain(runtime, ++txId, "/MyRoot",
R"(
Name: "USER_0"
ExternalSchemeShard: true
PlanResolution: 50
Coordinators: 1
Mediators: 1
TimeCastBucketsPerMediator: 2
StoragePools {
Name: "pool-1"
Kind: "hdd"
}
)"
);
env.TestWaitNotification(runtime, {txId, txId - 1});

AsyncAlterExtSubDomain(runtime, ++txId, "/MyRoot",
R"(
Name: "USER_0"
ExternalSchemeShard: true
PlanResolution: 50
Coordinators: 1
Mediators: 1
TimeCastBucketsPerMediator: 2
StoragePools {
Name: "pool-1"
Kind: "hdd"
}
)"
);
// TestModificationResults(runtime, txId, {NKikimrScheme::StatusAccepted});
const auto firstAlterTxId = txId;

//NOTE: SubDomain vs ExtSubDomain
TestAlterSubDomain(runtime, ++txId, "/MyRoot",
R"(
Name: "USER_0"
ExternalSchemeShard: true
PlanResolution: 50
Coordinators: 1
Mediators: 1
TimeCastBucketsPerMediator: 2
StoragePools {
Name: "pool-1"
Kind: "hdd"
}
)",
{{NKikimrScheme::StatusMultipleModifications}}
);

env.TestWaitNotification(runtime, firstAlterTxId);
}

Y_UNIT_TEST(CreateWithOnlyDotsNotAllowed) {
TTestBasicRuntime runtime;
TTestEnv env(runtime);
Expand Down

0 comments on commit b0a5850

Please sign in to comment.