Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

24-3: schemeshard: fix crash on concurrent alter-extsubdomains #9201

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ydb/core/tx/schemeshard/schemeshard__operation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1263,7 +1263,7 @@ TVector<ISubOperation::TPtr> TOperation::ConstructParts(const TTxTransaction& tx
case NKikimrSchemeOp::EOperationType::ESchemeOpCreateSubDomain:
return {CreateSubDomain(NextPartId(), tx)};
case NKikimrSchemeOp::EOperationType::ESchemeOpAlterSubDomain:
return {CreateCompatibleSubdomainAlter(context.SS, NextPartId(), tx)};
return CreateCompatibleSubdomainAlter(NextPartId(), tx, context);
case NKikimrSchemeOp::EOperationType::ESchemeOpDropSubDomain:
return {CreateDropSubdomain(NextPartId(), tx)};
case NKikimrSchemeOp::EOperationType::ESchemeOpForceDropSubDomain:
Expand Down
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
6 changes: 3 additions & 3 deletions ydb/core/tx/schemeshard/schemeshard__operation_part.h
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ ISubOperation::TPtr CreateAlterSubDomain(TOperationId id, const TTxTransaction&
ISubOperation::TPtr CreateAlterSubDomain(TOperationId id, TTxState::ETxState state);

ISubOperation::TPtr CreateCompatibleSubdomainDrop(TSchemeShard* ss, TOperationId id, const TTxTransaction& tx);
ISubOperation::TPtr CreateCompatibleSubdomainAlter(TSchemeShard* ss, TOperationId id, const TTxTransaction& tx);
TVector<ISubOperation::TPtr> CreateCompatibleSubdomainAlter(TOperationId id, const TTxTransaction& tx, TOperationContext& context);

ISubOperation::TPtr CreateUpgradeSubDomain(TOperationId id, const TTxTransaction& tx);
ISubOperation::TPtr CreateUpgradeSubDomain(TOperationId id, TTxState::ETxState state);
Expand All @@ -514,10 +514,10 @@ ISubOperation::TPtr CreateExtSubDomain(TOperationId id, TTxState::ETxState state

// Alter
TVector<ISubOperation::TPtr> CreateCompatibleAlterExtSubDomain(TOperationId nextId, const TTxTransaction& tx, TOperationContext& context);
ISubOperation::TPtr CreateAlterExtSubDomain(TOperationId id, const TTxTransaction& tx);
ISubOperation::TPtr CreateAlterExtSubDomain(TOperationId id, TTxState::ETxState state);
ISubOperation::TPtr CreateAlterExtSubDomainCreateHive(TOperationId id, const TTxTransaction& tx);
ISubOperation::TPtr CreateAlterExtSubDomainCreateHive(TOperationId id, TTxState::ETxState state);
//NOTE: no variants to construct individual suboperations directly from TTxTransaction --
// -- it should be possible only through CreateCompatibleAlterExtSubDomain

// Drop
ISubOperation::TPtr CreateForceDropExtSubDomain(TOperationId id, const TTxTransaction& tx);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1530,13 +1530,13 @@ ISubOperation::TPtr CreateCompatibleSubdomainDrop(TSchemeShard* ss, TOperationId
return CreateForceDropSubDomain(id, tx);
}

ISubOperation::TPtr CreateCompatibleSubdomainAlter(TSchemeShard* ss, TOperationId id, const TTxTransaction& tx) {
TVector<ISubOperation::TPtr> CreateCompatibleSubdomainAlter(TOperationId id, const TTxTransaction& tx, TOperationContext& context) {
const auto& info = tx.GetSubDomain();

const TString& parentPathStr = tx.GetWorkingDir();
const TString& name = info.GetName();

TPath path = TPath::Resolve(parentPathStr, ss).Dive(name);
TPath path = TPath::Resolve(parentPathStr, context.SS).Dive(name);

{
TPath::TChecker checks = path.Check();
Expand All @@ -1546,15 +1546,16 @@ ISubOperation::TPtr CreateCompatibleSubdomainAlter(TSchemeShard* ss, TOperationI
.NotDeleted();

if (!checks) {
return CreateAlterSubDomain(id, tx);
return {CreateAlterSubDomain(id, tx)};
}
}

if (path.Base()->IsExternalSubDomainRoot()) {
return CreateAlterExtSubDomain(id, tx);
// plain subdomains don't have subdomain/tenant hives so only single operation should be returned here
return CreateCompatibleAlterExtSubDomain(id, tx, context);
}

return CreateAlterSubDomain(id, tx);
return {CreateAlterSubDomain(id, tx)};
}

}
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
Loading