diff options
author | svc <svc@yandex-team.ru> | 2022-06-06 14:52:32 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-06-06 14:52:32 +0300 |
commit | f69185e2f55ceae1a27ca243e3fe240489c3e3cb (patch) | |
tree | ddc5519c47755287191cb4817e604c92d0f8935e | |
parent | 1c9a9bebfd56f7648a7879824fa93adeab288978 (diff) | |
download | ydb-f69185e2f55ceae1a27ca243e3fe240489c3e3cb.tar.gz |
KIKIMR-14837 protect use txc when storage changes is applied
REVIEW: 2514746
REVIEW: 2518871
x-ydb-stable-ref: d81ad3a0914c8f77be026260abd780d16af13142
68 files changed, 331 insertions, 222 deletions
diff --git a/ydb/core/tx/schemeshard/schemeshard__operation.cpp b/ydb/core/tx/schemeshard/schemeshard__operation.cpp index cdd5f0ba73..4c6d5e5026 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation.cpp @@ -177,19 +177,28 @@ THolder<TProposeResponse> TSchemeShard::IgniteOperation(TProposeRequest& request //context.OnComplete.ActivateTx(pathOpId) ///TODO maybe it is good idea } else { - - if (!operation->Parts.empty()) { LOG_NOTICE_S(context.Ctx, NKikimrServices::FLAT_TX_SCHEMESHARD, "Abort operation: IgniteOperation fail to propose a part" << ", opId: " << pathOpId << ", at schemeshard: " << selfId - << ", already assepted parts: " << operation->Parts.size() + << ", already accepted parts: " << operation->Parts.size() << ", propose result status: " << NKikimrScheme::EStatus_Name(response->Record.GetStatus()) << ", with reason: " << response->Record.GetReason() << ", tx message: " << GetRecordForPrint(record).ShortDebugString()); } + Y_VERIFY_S(context.IsUndoChangesSafe(), + "Operation is aborted and all changes should be reverted" + << ", but context.IsUndoChangesSafe is false, which means some direct writes have been done" + << ", opId: " << pathOpId + << ", at schemeshard: " << selfId + << ", already accepted parts: " << operation->Parts.size() + << ", propose result status: " << NKikimrScheme::EStatus_Name(response->Record.GetStatus()) + << ", with reason: " << response->Record.GetReason() + << ", tx message: " << GetRecordForPrint(record).ShortDebugString()); + + context.OnComplete = {}; // recreate context.DbChanges = {}; @@ -198,7 +207,7 @@ THolder<TProposeResponse> TSchemeShard::IgniteOperation(TProposeRequest& request } context.MemChanges.UnDo(context.SS); - context.OnComplete.ApplyOnExecute(context.SS, context.Txc, context.Ctx); + context.OnComplete.ApplyOnExecute(context.SS, context.GetTxc(), context.Ctx); Operations.erase(operation->GetTxId()); return std::move(response); } @@ -489,7 +498,7 @@ TString JoinPath(const TString& workingDir, const TString& name) { << name; } -TOperation::TConsumeQuotaResult TOperation::ConsumeQuota(const TTxTransaction& tx, const TOperationContext& context) { +TOperation::TConsumeQuotaResult TOperation::ConsumeQuota(const TTxTransaction& tx, TOperationContext& context) { TConsumeQuotaResult result; // Internal operations never consume quota @@ -533,7 +542,7 @@ TOperation::TConsumeQuotaResult TOperation::ConsumeQuota(const TTxTransaction& t } // Even if operation fails later we want to persist updated/consumed quotas - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetTxc().DB); // write quotas directly in db even if operation fails context.SS->PersistSubDomainSchemeQuotas(db, domainId, *domainInfo); return result; } diff --git a/ydb/core/tx/schemeshard/schemeshard__operation.h b/ydb/core/tx/schemeshard/schemeshard__operation.h index 52f1848aa1..5d19d8edbd 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation.h +++ b/ydb/core/tx/schemeshard/schemeshard__operation.h @@ -64,7 +64,7 @@ struct TOperation: TSimpleRefCount<TOperation> { TTxId GetTxId() const { return TxId; } - static TConsumeQuotaResult ConsumeQuota(const TTxTransaction& tx, const TOperationContext& context); + static TConsumeQuotaResult ConsumeQuota(const TTxTransaction& tx, TOperationContext& context); static TSplitTransactionsResult SplitIntoTransactions(const TTxTransaction& tx, const TOperationContext& context); diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_alter_bsv.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_alter_bsv.cpp index 27455e4627..3e252342f4 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_alter_bsv.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_alter_bsv.cpp @@ -82,7 +82,7 @@ public: ui64 shardsToCreate, TOperationContext& context) { - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); item->LastTxId = operationId.GetTxId(); item->PathState = TPathElement::EPathState::EPathStateAlter; diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_alter_cdc_stream.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_alter_cdc_stream.cpp index d7027b570e..b8c2dbc973 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_alter_cdc_stream.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_alter_cdc_stream.cpp @@ -55,7 +55,7 @@ public: Y_VERIFY(context.SS->CdcStreams.contains(pathId)); auto stream = context.SS->CdcStreams.at(pathId); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); context.SS->PersistCdcStream(db, pathId); context.SS->CdcStreams[pathId] = stream->AlterData; @@ -173,6 +173,7 @@ public: } } + auto guard = context.DbGuard(); context.DbChanges.PersistAlterCdcStream(streamPath.Base()->PathId); context.DbChanges.PersistTxState(OperationId); diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_alter_extsubdomain.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_alter_extsubdomain.cpp index 463f3bb3cf..bcf5a3bc89 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_alter_extsubdomain.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_alter_extsubdomain.cpp @@ -391,7 +391,7 @@ public: alterData->SetDatabaseQuotas(settings.GetDatabaseQuotas()); } - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); subDomain->LastTxId = OperationId.GetTxId(); subDomain->PathState = TPathElement::EPathState::EPathStateAlter; diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_alter_fs.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_alter_fs.cpp index ee2a3fb3e5..285203b8f6 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_alter_fs.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_alter_fs.cpp @@ -69,7 +69,7 @@ public: context.OnComplete.UnbindMsgFromPipe(OperationId, tabletId, idx); if (txState->ShardsInProgress.empty()) { - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); context.SS->ChangeTxState(db, OperationId, TTxState::Propose); context.OnComplete.ActivateTx(OperationId); return true; @@ -162,7 +162,7 @@ public: path->PathState = TPathElement::EPathState::EPathStateNoChanges; path->StepCreated = step; - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); context.SS->PersistCreateStep(db, pathId, step); fs->FinishAlter(); @@ -448,7 +448,7 @@ TTxState& TAlterFileStore::PrepareChanges( const TChannelsBindings& channelBindings, TOperationContext& context) { - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); item->LastTxId = operationId.GetTxId(); item->PathState = TPathElement::EPathState::EPathStateAlter; diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_alter_index.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_alter_index.cpp index 3617728fbe..c4c3261740 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_alter_index.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_alter_index.cpp @@ -37,7 +37,7 @@ public: Y_VERIFY(txState->TxType == TTxState::TxAlterTableIndex); Y_VERIFY(txState->State == TTxState::Propose); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); TPathId pathId = txState->TargetPathId; TPathElement::TPtr path = context.SS->PathsById.at(pathId); @@ -212,8 +212,8 @@ public: return result; } + auto guard = context.DbGuard(); auto indexPath = dstPath.Base(); - context.MemChanges.GrabPath(context.SS, indexPath->PathId); context.MemChanges.GrabPath(context.SS, indexPath->ParentPathId); context.MemChanges.GrabNewTxState(context.SS, OperationId); diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_alter_kesus.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_alter_kesus.cpp index 38e5f74777..33240bada8 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_alter_kesus.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_alter_kesus.cpp @@ -17,7 +17,7 @@ void PrepareChanges(TOperationId operationId, TKesusInfo::TPtr kesus, TOperationContext& context) { - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); item->LastTxId = operationId.GetTxId(); item->PathState = TPathElement::EPathState::EPathStateAlter; @@ -96,7 +96,7 @@ public: context.OnComplete.UnbindMsgFromPipe(OperationId, tabletId, idx); if (txState->ShardsInProgress.empty()) { - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); context.SS->ChangeTxState(db, OperationId, TTxState::Propose); context.OnComplete.ActivateTx(OperationId); return true; @@ -180,7 +180,7 @@ public: TPathId pathId = txState->TargetPathId; TPathElement::TPtr path = context.SS->PathsById.at(pathId); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); path->PathState = TPathElement::EPathState::EPathStateNoChanges; diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_alter_login.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_alter_login.cpp index ecda4b08bf..278a6f08a7 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_alter_login.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_alter_login.cpp @@ -24,7 +24,7 @@ public: } THolder<TProposeResponse> Propose(const TString&, TOperationContext& context) override { - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetTxc().DB); // do not track is there are direct writes happen TTabletId ssId = context.SS->SelfTabletId(); auto result = MakeHolder<TProposeResponse>(OperationId.GetTxId(), ssId); if (Transaction.GetWorkingDir() != context.SS->LoginProvider.Audience) { diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_alter_olap_store.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_alter_olap_store.cpp index 7141c76ae7..d7701ca1dd 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_alter_olap_store.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_alter_olap_store.cpp @@ -370,7 +370,7 @@ public: TOlapStoreInfo::TPtr alterData = storeInfo->AlterData; Y_VERIFY(alterData); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); // TODO: make a new FinishPropose method or something like that alterData->AlterBody.Clear(); @@ -514,7 +514,7 @@ public: } bool UpdateTables(TOperationContext& context) { - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); ui32 updated = 0; while (!TablesToUpdate.empty() && updated < UpdateBatchSize) { @@ -555,7 +555,7 @@ public: Y_VERIFY(txState->TxType == TTxState::TxAlterOlapStore); if (txState->ShardsInProgress.empty() && TablesToUpdate.empty()) { - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); context.SS->ChangeTxState(db, OperationId, TTxState::Done); return true; } @@ -698,7 +698,7 @@ public: return result; } - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); TTxState& txState = context.SS->CreateTx(OperationId, TTxState::TxAlterOlapStore, path->PathId); txState.State = TTxState::ConfigureParts; diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_alter_olap_table.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_alter_olap_table.cpp index 2e89cad986..33c9c93ad7 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_alter_olap_table.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_alter_olap_table.cpp @@ -272,7 +272,7 @@ public: TPathId pathId = txState->TargetPathId; TPathElement::TPtr path = context.SS->PathsById.at(pathId); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); TOlapTableInfo::TPtr tableInfo = context.SS->OlapTables[pathId]; Y_VERIFY(tableInfo); @@ -548,7 +548,7 @@ public: Y_VERIFY(storeInfo->OlapTables.contains(path->PathId)); storeInfo->OlapTablesUnderOperation.insert(path->PathId); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); TTxState& txState = context.SS->CreateTx(OperationId, TTxState::TxAlterOlapTable, path->PathId); txState.State = TTxState::ConfigureParts; diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_alter_pq.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_alter_pq.cpp index 9bf454440d..44e2acbd09 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_alter_pq.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_alter_pq.cpp @@ -201,7 +201,7 @@ public: TOperationContext& context) { TPathElement::TPtr item = path.Base(); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); item->LastTxId = operationId.GetTxId(); item->PathState = TPathElement::EPathState::EPathStateAlter; diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_alter_solomon.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_alter_solomon.cpp index 1c17ee6095..805fa23a9c 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_alter_solomon.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_alter_solomon.cpp @@ -58,7 +58,7 @@ public: solomonPartition->TabletId = tabletId; } - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); context.SS->ChangeTxState(db, OperationId, TTxState::Propose); return true; } @@ -98,7 +98,7 @@ public: TPathId pathId = txState->TargetPathId; TPathElement::TPtr path = context.SS->PathsById.at(pathId); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); auto solomon = context.SS->SolomonVolumes[txState->TargetPathId]; Y_VERIFY_S(solomon, "solomon volume is null. PathId: " << txState->TargetPathId); @@ -261,6 +261,7 @@ public: if (alter.GetUpdateChannelsBinding() && !AppData()->FeatureFlags.GetAllowUpdateChannelsBindingOfSolomonPartitions()) { result->SetError(NKikimrScheme::StatusPreconditionFailed, "Updating of channels binding is not available"); + return result; } if (alter.HasPartitionCount()) { @@ -295,7 +296,7 @@ public: TSolomonVolumeInfo::TPtr alterSolomon = solomon->CreateAlter(); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); TTxState& txState = context.SS->CreateTx(OperationId, TTxState::TxAlterSolomonVolume, path.Base()->PathId); diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_alter_subdomain.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_alter_subdomain.cpp index dc1208bbb9..85f432738f 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_alter_subdomain.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_alter_subdomain.cpp @@ -321,7 +321,7 @@ public: alterData->SetDatabaseQuotas(settings.GetDatabaseQuotas()); } - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); subDomain->LastTxId = OperationId.GetTxId(); subDomain->PathState = TPathElement::EPathState::EPathStateAlter; diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_alter_table.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_alter_table.cpp index 1774dad9d2..33f05ffe89 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_alter_table.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_alter_table.cpp @@ -132,7 +132,7 @@ void PrepareChanges(TOperationId opId, TPathElement::TPtr path, TTableInfo::TPtr TTxState& txState = context.SS->CreateTx(opId, TTxState::TxAlterTable, path->PathId); txState.State = TTxState::CreateParts; - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); TTxState::ETxState commonShardOp = table->NeedRecreateParts() ? TTxState::CreateParts @@ -334,7 +334,7 @@ public: TPathId pathId = txState->TargetPathId; TPathElement::TPtr path = context.SS->PathsById.at(pathId); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); TTableInfo::TPtr table = context.SS->Tables.at(pathId); table->FinishAlter(); diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_alter_user_attrs.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_alter_user_attrs.cpp index 4f7dd3314e..96f7bca898 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_alter_user_attrs.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_alter_user_attrs.cpp @@ -84,7 +84,7 @@ public: return result; } - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); Y_VERIFY(!context.SS->FindTx(OperationId)); TTxState& txState = context.SS->CreateTx(OperationId, TTxState::TxAlterUserAttributes, path.Base()->PathId); @@ -144,7 +144,7 @@ public: TPathElement::TPtr path = context.SS->PathsById.at(pathId); context.OnComplete.ReleasePathState(OperationId, pathId, TPathElement::EPathState::EPathStateNoChanges); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); Y_VERIFY(path->UserAttrs); Y_VERIFY(path->UserAttrs->AlterData); diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_assign_bsv.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_assign_bsv.cpp index de1576f2b1..fdeee39c8f 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_assign_bsv.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_assign_bsv.cpp @@ -87,7 +87,7 @@ public: return result; } - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); volume->MountToken = mountToken; ++volume->TokenVersion; diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_backup_restore_common.h b/ydb/core/tx/schemeshard/schemeshard__operation_backup_restore_common.h index 640f5f1356..b068a54cca 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_backup_restore_common.h +++ b/ydb/core/tx/schemeshard/schemeshard__operation_backup_restore_common.h @@ -174,7 +174,7 @@ public: return; } - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); const auto& result = evRecord.GetOpResult(); if (!txState.ShardStatuses.contains(shardIdx)) { @@ -248,7 +248,7 @@ public: TTxState* txState = context.SS->FindTx(OperationId); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); txState->ClearShardsInProgress(); for (TTxState::TShardOperation& shard : txState->Shards) { @@ -319,7 +319,7 @@ public: txState->ClearShardsInProgress(); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); for (TTxState::TShardOperation& shard : txState->Shards) { if (shard.Operation < TTxState::ProposedWaitParts) { @@ -414,7 +414,7 @@ public: context.SS->ClearDescribePathCaches(path); context.OnComplete.PublishToSchemeBoard(OperationId, pathId); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); context.SS->ChangeTxState(db, OperationId, TTxState::ProposedWaitParts); return true; @@ -558,7 +558,7 @@ public: txState.Shards.emplace_back(shardIdx, ETabletType::DataShard, TTxState::ConfigureParts); } - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); context.SS->PersistTxState(db, OperationId); TKind::PersistTask(path->PathId, Transaction, context); diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_cancel_tx.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_cancel_tx.cpp index aceebc3786..b58badf13c 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_cancel_tx.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_cancel_tx.cpp @@ -54,7 +54,7 @@ public: return proposeResult; } - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); /* Let's abort at the final stage of the transaction */ txState.Cancel = true; diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_common.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_common.cpp index 1395e37aa3..1945d3cfed 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_common.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_common.cpp @@ -34,7 +34,7 @@ bool CollectProposeTxResults( return false; } - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); TTxState& txState = *context.SS->FindTx(operationId); @@ -175,7 +175,7 @@ bool NTableState::CollectSchemaChanged( if (txState.ShardsInProgress.empty()) { AckAllSchemaChanges(operationId, txState, context); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); context.SS->ChangeTxState(db, operationId, TTxState::Done); return true; } @@ -233,7 +233,7 @@ bool NTableState::CheckPartitioningChangedForTableModification(TTxState &txState void NTableState::UpdatePartitioningForTableModification(TOperationId operationId, TTxState &txState, TOperationContext &context) { Y_VERIFY(!txState.TxShardsListFinalized, "Rebuilding the list of shards must not happen twice"); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); THashSet<TShardIdx> prevAlterCreateParts; @@ -377,7 +377,7 @@ void NTableState::UpdatePartitioningForCopyTable(TOperationId operationId, TTxSt auto srcTableInfo = context.SS->Tables.at(txState.SourcePathId); auto dstTableInfo = context.SS->Tables.at(txState.TargetPathId); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); // Erase previous partitioning as we are going to generate new one context.SS->DeleteTablePartitioning(db, txState.TargetPathId, dstTableInfo); @@ -504,7 +504,7 @@ TSet<ui32> AllIncomingEvents() { } void NForceDrop::CollectShards(const THashSet<TPathId>& pathes, TOperationId operationId, TTxState *txState, TOperationContext &context) { - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); auto shards = context.SS->CollectAllShards(pathes); for (auto shardIdx: shards) { @@ -543,23 +543,30 @@ void NForceDrop::ValidateNoTrasactionOnPathes(TOperationId operationId, const TH } } -void IncParentDirAlterVersionWithRepublish(const TOperationId& opId, const TPath& path, TOperationContext &context) { - NIceDb::TNiceDb db(context.Txc.DB); - +void IncParentDirAlterVersionWithRepublishSafeWithUndo(const TOperationId& opId, const TPath& path, TSchemeShard* ss, TSideEffects& onComplete) { auto parent = path.Parent(); if (parent.Base()->IsDirectory() || parent.Base()->IsDomainRoot()) { ++parent.Base()->DirAlterVersion; - context.SS->PersistPathDirAlterVersion(db, parent.Base()); } if (parent.IsActive()) { - context.SS->ClearDescribePathCaches(parent.Base()); - context.OnComplete.PublishToSchemeBoard(opId, parent->PathId); + ss->ClearDescribePathCaches(parent.Base()); + onComplete.PublishToSchemeBoard(opId, parent->PathId); } if (path.IsActive()) { - context.SS->ClearDescribePathCaches(path.Base()); - context.OnComplete.PublishToSchemeBoard(opId, path->PathId); + ss->ClearDescribePathCaches(path.Base()); + onComplete.PublishToSchemeBoard(opId, path->PathId); + } +} + +void IncParentDirAlterVersionWithRepublish(const TOperationId& opId, const TPath& path, TOperationContext &context) { + IncParentDirAlterVersionWithRepublishSafeWithUndo(opId, path, context.SS, context.OnComplete); + + auto parent = path.Parent(); + if (parent.Base()->IsDirectory() || parent.Base()->IsDomainRoot()) { + NIceDb::TNiceDb db(context.GetDB()); + context.SS->PersistPathDirAlterVersion(db, parent.Base()); } } diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_common.h b/ydb/core/tx/schemeshard/schemeshard__operation_common.h index ca21214993..f3b4204422 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_common.h +++ b/ydb/core/tx/schemeshard/schemeshard__operation_common.h @@ -10,6 +10,7 @@ namespace NSchemeShard { TSet<ui32> AllIncomingEvents(); +void IncParentDirAlterVersionWithRepublishSafeWithUndo(const TOperationId& opId, const TPath& path, TSchemeShard* ss, TSideEffects& onComplete); void IncParentDirAlterVersionWithRepublish(const TOperationId& opId, const TPath& path, TOperationContext& context); namespace NTableState { @@ -91,7 +92,7 @@ public: TTxState* txState = context.SS->FindTx(OperationId); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); txState->ClearShardsInProgress(); for (TTxState::TShardOperation& shard : txState->Shards) { @@ -157,7 +158,7 @@ public: const auto& record = ev->Get()->Record; - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); TTabletId tabletId = TTabletId(record.GetTenantSchemeShard()); auto status = record.GetStatus(); @@ -213,7 +214,7 @@ public: const auto& record = ev->Get()->Record; - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); TTabletId tabletId = TTabletId(record.GetOnTabletId()); auto status = record.GetStatus(); @@ -269,7 +270,7 @@ public: txState->ClearShardsInProgress(); if (txState->Shards.empty()) { - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); context.SS->ChangeTxState(db, OperationId, TTxState::Propose); context.OnComplete.ActivateTx(OperationId); return true; @@ -401,7 +402,7 @@ public: Y_VERIFY(context.SS->PathsById.contains(pathId)); TPathElement::TPtr path = context.SS->PathsById.at(pathId); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); path->StepCreated = step; context.SS->PersistCreateStep(db, pathId, step); @@ -484,7 +485,7 @@ public: DebugHint() << " HandleReply TEvAdoptTablet" << ", message% " << DebugReply(ev)); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); const TString& explain = ev->Get()->Record.GetExplain(); TTabletId tabletId = TTabletId(ev->Get()->Record.GetTabletID()); // global id from hive @@ -551,7 +552,7 @@ public: DebugHint() << " HandleReply TEvCreateTabletReply" << ", message: " << DebugReply(ev)); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); auto shardIdx = TShardIdx(ev->Get()->Record.GetOwner(), TLocalShardIdx(ev->Get()->Record.GetOwnerIdx())); @@ -812,7 +813,7 @@ public: DebugHint() << " ProgressState" << " no shards to create, do next state"); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); context.SS->ChangeTxState(db, OperationId, TTxState::ConfigureParts); return true; } @@ -957,7 +958,7 @@ public: context.OnComplete.UnbindMsgFromPipe(OperationId, tabletId, idx); if (txState->ShardsInProgress.empty()) { - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); context.SS->ChangeTxState(db, OperationId, TTxState::Propose); return true; } @@ -1159,7 +1160,7 @@ public: TPathId pathId = txState->TargetPathId; TPathElement::TPtr path = context.SS->PathsById.at(pathId); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); path->StepCreated = step; context.SS->PersistCreateStep(db, pathId, step); @@ -1258,7 +1259,7 @@ public: context.OnComplete.UnbindMsgFromPipe(OperationId, tabletId, idx); if (txState->ShardsInProgress.empty()) { - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); context.SS->ChangeTxState(db, OperationId, TTxState::Propose); context.OnComplete.ActivateTx(OperationId); return true; @@ -1366,7 +1367,7 @@ public: TPathId pathId = txState->TargetPathId; TPathElement::TPtr path = context.SS->PathsById.at(pathId); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); path->StepCreated = step; context.SS->PersistCreateStep(db, pathId, step); @@ -1569,7 +1570,7 @@ public: table->AlterVersion += 1; - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); context.SS->PersistTableAlterVersion(db, pathId, table); context.SS->ClearDescribePathCaches(path); diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_copy_table.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_copy_table.cpp index 38a15b1e31..5d1e83187f 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_copy_table.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_copy_table.cpp @@ -181,7 +181,7 @@ public: TPathId pathId = txState->TargetPathId; TPathElement::TPtr path = context.SS->PathsById.at(pathId); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); path->StepCreated = step; context.SS->PersistCreateStep(db, pathId, step); @@ -540,6 +540,7 @@ public: } } + auto guard = context.DbGuard(); TPathId allocatedPathId = context.SS->AllocatePathId(); context.MemChanges.GrabNewPath(context.SS, allocatedPathId); context.MemChanges.GrabPath(context.SS, parent.Base()->PathId); diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_create_backup.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_create_backup.cpp index 4c0c967af0..caecc26c75 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_create_backup.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_create_backup.cpp @@ -77,7 +77,7 @@ struct TBackup { backupInfo.ShardStatuses = std::move(txState.ShardStatuses); backupInfo.DataTotalSize = txState.DataTotalSize; - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); context.SS->PersistCompletedBackup(db, opId.GetTxId(), txState, backupInfo); } @@ -87,12 +87,12 @@ struct TBackup { table->BackupSettings = tx.GetBackup(); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); context.SS->PersistBackupSettings(db, pathId, table->BackupSettings); } static void PersistDone(const TPathId& pathId, TOperationContext& context) { - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); context.SS->PersistBackupDone(db, pathId); } diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_create_bsv.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_create_bsv.cpp index b32fb7d969..10e6de9f02 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_create_bsv.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_create_bsv.cpp @@ -89,7 +89,7 @@ TTxState& PrepareChanges(TOperationId operationId, TPathElement::TPtr parentDir, ui64 shardsToCreate, TOperationContext& context) { - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); volumePath->CreateTxId = operationId.GetTxId(); volumePath->LastTxId = operationId.GetTxId(); @@ -382,7 +382,7 @@ public: const TTxState& txState = PrepareChanges(OperationId, parentPath.Base(), dstPath.Base(), volume, acl, partitionChannelsBinding, volumeChannelsBinding, shardsToCreate, context); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); ++parentPath.Base()->DirAlterVersion; context.SS->PersistPathDirAlterVersion(db, parentPath.Base()); context.SS->ClearDescribePathCaches(parentPath.Base()); diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_create_cdc_stream.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_create_cdc_stream.cpp index 9cbeb71280..1eeedabe17 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_create_cdc_stream.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_create_cdc_stream.cpp @@ -56,7 +56,7 @@ public: Y_VERIFY(context.SS->CdcStreams.contains(pathId)); auto stream = context.SS->CdcStreams.at(pathId); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); path->StepCreated = step; context.SS->PersistCreateStep(db, pathId, step); @@ -228,6 +228,7 @@ public: auto stream = TCdcStreamInfo::Create(streamDesc); Y_VERIFY(stream); + auto guard = context.DbGuard(); const auto pathId = context.SS->AllocatePathId(); context.MemChanges.GrabNewPath(context.SS, pathId); context.MemChanges.GrabPath(context.SS, tablePath.Base()->PathId); diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_create_extsubdomain.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_create_extsubdomain.cpp index 9b6b9a4960..8129ff50f9 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_create_extsubdomain.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_create_extsubdomain.cpp @@ -229,7 +229,7 @@ public: newNode->UserAttrs->AlterData = userAttrs; newNode->DirAlterVersion = 1; - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); context.SS->PersistPath(db, newNode->PathId); context.SS->ApplyAndPersistUserAttrs(db, newNode->PathId); diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_create_fs.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_create_fs.cpp index 6d908a55e8..9c94b2654f 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_create_fs.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_create_fs.cpp @@ -71,7 +71,7 @@ public: context.OnComplete.UnbindMsgFromPipe(OperationId, tabletId, idx); if (txState->ShardsInProgress.empty()) { - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); context.SS->ChangeTxState(db, OperationId, TTxState::Propose); context.OnComplete.ActivateTx(OperationId); return true; @@ -163,7 +163,7 @@ public: TPathElement::TPtr path = context.SS->PathsById.at(pathId); path->StepCreated = step; - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); context.SS->PersistCreateStep(db, pathId, step); auto parentDir = context.SS->PathsById.at(path->ParentPathId); @@ -443,7 +443,7 @@ THolder<TProposeResponse> TCreateFileStore::Propose( storeChannelBindings, context); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); ++parentPath.Base()->DirAlterVersion; context.SS->PersistPathDirAlterVersion(db, parentPath.Base()); context.SS->ClearDescribePathCaches(parentPath.Base()); @@ -497,7 +497,7 @@ TTxState& TCreateFileStore::PrepareChanges( const TChannelsBindings& tabletChannels, TOperationContext& context) { - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); fsPath->CreateTxId = operationId.GetTxId(); fsPath->LastTxId = operationId.GetTxId(); diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_create_index.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_create_index.cpp index 4713823eef..cfcec10af4 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_create_index.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_create_index.cpp @@ -37,7 +37,7 @@ public: Y_VERIFY(txState->TxType == TTxState::TxCreateTableIndex); Y_VERIFY(txState->State == TTxState::Propose); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); TPathId pathId = txState->TargetPathId; TPathElement::TPtr path = context.SS->PathsById.at(pathId); @@ -231,6 +231,7 @@ public: } } + auto guard = context.DbGuard(); TPathId allocatedPathId = context.SS->AllocatePathId(); context.MemChanges.GrabNewPath(context.SS, allocatedPathId); context.MemChanges.GrabPath(context.SS, parentPath.Base()->PathId); diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_create_kesus.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_create_kesus.cpp index c974b72c31..ae409a2178 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_create_kesus.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_create_kesus.cpp @@ -25,7 +25,7 @@ TTxState& PrepareChanges(TOperationId operationId, TPathElement::TPtr parentDir, const TChannelsBindings& tabletChannels, TOperationContext& context) { - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); item->CreateTxId = operationId.GetTxId(); item->LastTxId = operationId.GetTxId(); @@ -116,7 +116,7 @@ public: context.OnComplete.UnbindMsgFromPipe(OperationId, tabletId, idx); if (txState->ShardsInProgress.empty()) { - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); context.SS->ChangeTxState(db, OperationId, TTxState::Propose); context.OnComplete.ActivateTx(OperationId); return true; @@ -208,7 +208,7 @@ public: TKesusInfo::TPtr kesus = context.SS->KesusInfos.at(pathId); Y_VERIFY_S(kesus, "kesus is null. PathId: " << pathId); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); path->StepCreated = step; context.SS->PersistCreateStep(db, pathId, step); @@ -422,7 +422,7 @@ public: const TTxState& txState = PrepareChanges(OperationId, parentPath.Base(), dstPath.Base(), kesus, acl, kesusChannelsBindings, context); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); ++parentPath.Base()->DirAlterVersion; context.SS->PersistPathDirAlterVersion(db, parentPath.Base()); context.SS->ClearDescribePathCaches(parentPath.Base()); diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_create_lock.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_create_lock.cpp index e4a8cbb14f..b2a2e90320 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_create_lock.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_create_lock.cpp @@ -254,7 +254,7 @@ public: return result; } - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); pathEl->LastTxId = OperationId.GetTxId(); pathEl->PathState = NKikimrSchemeOp::EPathState::EPathStateAlter; diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_create_olap_store.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_create_olap_store.cpp index a3e6896b6f..74880e35b2 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_create_olap_store.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_create_olap_store.cpp @@ -393,7 +393,7 @@ public: TPathId pathId = txState->TargetPathId; TPathElement::TPtr path = context.SS->PathsById.at(pathId); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); path->StepCreated = step; context.SS->PersistCreateStep(db, pathId, step); @@ -730,7 +730,7 @@ public: OperationId.GetTxId(), pathId, storeInfo, metaChannelsBindings, channelsBindings, txState, context.SS); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); TOlapStoreInfo::TPtr pending = new TOlapStoreInfo; pending->AlterData = storeInfo; diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_create_olap_table.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_create_olap_table.cpp index 09f556c655..cf2e80090c 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_create_olap_table.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_create_olap_table.cpp @@ -463,7 +463,7 @@ public: TPathId pathId = txState->TargetPathId; TPathElement::TPtr path = context.SS->PathsById.at(pathId); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); path->StepCreated = step; context.SS->PersistCreateStep(db, pathId, step); @@ -783,7 +783,7 @@ public: dstPath.Base()->PathState = TPathElement::EPathState::EPathStateCreate; dstPath.Base()->PathType = TPathElement::EPathType::EPathTypeColumnTable; - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); TTxState& txState = context.SS->CreateTx(OperationId, TTxState::TxCreateOlapTable, pathId); txState.State = TTxState::ConfigureParts; diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_create_pq.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_create_pq.cpp index 22ba356eeb..c099850fcd 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_create_pq.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_create_pq.cpp @@ -475,7 +475,7 @@ public: ApplySharding(OperationId.GetTxId(), pathId, pqGroup, txState, tabletChannelsBinding, pqChannelsBinding, context.SS); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); for (auto& shard : pqGroup->Shards) { auto shardIdx = shard.first; diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_create_replication.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_create_replication.cpp index c6458f7aa5..98b4f5d2d5 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_create_replication.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_create_replication.cpp @@ -107,7 +107,7 @@ public: return false; } - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); context.SS->ChangeTxState(db, OperationId, TTxState::Propose); context.OnComplete.ActivateTx(OperationId); @@ -167,7 +167,7 @@ public: auto alterData = replication->AlterData; Y_VERIFY(alterData); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); path->StepCreated = step; context.SS->PersistCreateStep(db, pathId, step); @@ -398,7 +398,7 @@ public: context.OnComplete.Dependence(parentTxId, OperationId.GetTxId()); } - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); context.SS->PersistPath(db, path->PathId); if (!acl.empty()) { diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_create_restore.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_create_restore.cpp index 44b7a59e70..7a82fe3c2f 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_create_restore.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_create_restore.cpp @@ -82,7 +82,7 @@ struct TRestore { restoreInfo.ShardStatuses = std::move(txState.ShardStatuses); restoreInfo.DataTotalSize = txState.DataTotalSize; - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); context.SS->PersistCompletedRestore(db, opId.GetTxId(), txState, restoreInfo); } @@ -93,14 +93,14 @@ struct TRestore { TTableInfo::TPtr table = context.SS->Tables.at(pathId); table->RestoreSettings = restore; - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); db.Table<Schema::RestoreTasks>() .Key(pathId.OwnerId, pathId.LocalPathId) .Update(NIceDb::TUpdate<Schema::RestoreTasks::Task>(restore.SerializeAsString())); } static void PersistDone(const TPathId& pathId, TOperationContext& context) { - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); db.Table<Schema::RestoreTasks>() .Key(pathId.OwnerId, pathId.LocalPathId) .Delete(); diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_create_rtmr.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_create_rtmr.cpp index 648fcd3c4d..c041227669 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_create_rtmr.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_create_rtmr.cpp @@ -96,7 +96,7 @@ public: rtmrPartition->TabletId = tabletId; } - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); context.SS->ChangeTxState(db, OperationId, TTxState::Propose); return true; } @@ -134,7 +134,7 @@ public: auto pathId = txState->TargetPathId; TPathElement::TPtr path = context.SS->PathsById.at(pathId); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); path->StepCreated = step; context.SS->PersistCreateStep(db, pathId, step); @@ -346,7 +346,7 @@ public: TRtmrVolumeInfo::TPtr rtmrVolumeInfo = CreateRtmrVolume(rtmrVolumeDescription, txState, context.SS); Y_VERIFY(rtmrVolumeInfo); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); if (parentPath.Base()->HasActiveChanges()) { TTxId parentTxId = parentPath.Base()->PlannedToCreate() ? parentPath.Base()->CreateTxId : parentPath.Base()->LastTxId; diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_create_sequence.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_create_sequence.cpp index 3dbeecfb51..b8578bd228 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_create_sequence.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_create_sequence.cpp @@ -77,7 +77,7 @@ public: context.OnComplete.UnbindMsgFromPipe(OperationId, tabletId, txState->TargetPathId); if (txState->ShardsInProgress.empty()) { - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); context.SS->ChangeTxState(db, OperationId, TTxState::Propose); context.OnComplete.ActivateTx(OperationId); return true; @@ -203,7 +203,7 @@ public: TSequenceInfo::TPtr alterData = sequenceInfo->AlterData; Y_VERIFY(alterData); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); path->StepCreated = step; context.SS->PersistCreateStep(db, pathId, step); @@ -481,7 +481,7 @@ public: p->SetLocalId(ui64(sequenceShard.GetLocalId())); } - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); context.SS->ChangeTxState(db, OperationId, txState.State); context.OnComplete.ActivateTx(OperationId); diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_create_solomon.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_create_solomon.cpp index a821169854..4356554f2f 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_create_solomon.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_create_solomon.cpp @@ -129,7 +129,7 @@ public: solomonPartition->TabletId = tabletId; } - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); context.SS->ChangeTxState(db, OperationId, TTxState::Propose); return true; } @@ -169,19 +169,12 @@ public: TPathId pathId = txState->TargetPathId; TPathElement::TPtr path = context.SS->PathsById.at(pathId); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); path->StepCreated = step; context.SS->PersistCreateStep(db, pathId, step); - auto parentDir = context.SS->PathsById.at(path->ParentPathId); - ++parentDir->DirAlterVersion; - context.SS->PersistPathDirAlterVersion(db, parentDir); - context.SS->ClearDescribePathCaches(parentDir); - context.OnComplete.PublishToSchemeBoard(OperationId, parentDir->PathId); - - context.SS->ClearDescribePathCaches(path); - context.OnComplete.PublishToSchemeBoard(OperationId, pathId); + IncParentDirAlterVersionWithRepublish(OperationId, TPath::Init(pathId, context.SS), context); context.SS->ChangeTxState(db, OperationId, TTxState::Done); return true; @@ -403,7 +396,7 @@ public: adoptedShards[TTabletId(portion.GetTabletId())] = TAdoptedShard{portion.GetOwnerId(), TLocalShardIdx(portion.GetShardIdx())}; } - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); for (const auto& part: solomonVolume->Partitions) { TShardIdx shardIdx = part.first; @@ -442,15 +435,7 @@ public: context.SS->PersistUpdateNextPathId(db); context.SS->PersistUpdateNextShardIdx(db); - ++parentPath.Base()->DirAlterVersion; - context.SS->PersistPathDirAlterVersion(db, parentPath.Base()); - context.SS->ClearDescribePathCaches(parentPath.Base()); - context.OnComplete.PublishToSchemeBoard(OperationId, parentPath.Base()->PathId); - - context.SS->ClearDescribePathCaches(newSolomon); - context.OnComplete.PublishToSchemeBoard(OperationId, newSolomon->PathId); - - + IncParentDirAlterVersionWithRepublish(OperationId, dstPath, context); Y_VERIFY(shardsToCreate == txState.Shards.size()); dstPath.DomainInfo()->IncPathsInside(); diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_create_subdomain.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_create_subdomain.cpp index b46d7015cc..04714d4c8a 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_create_subdomain.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_create_subdomain.cpp @@ -284,7 +284,7 @@ public: newNode->UserAttrs->AlterData = userAttrs; newNode->DirAlterVersion = 1; - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); context.SS->PersistPath(db, newNode->PathId); context.SS->ApplyAndPersistUserAttrs(db, newNode->PathId); diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_create_table.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_create_table.cpp index 5d3a236194..69eb87bd37 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_create_table.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_create_table.cpp @@ -264,7 +264,7 @@ public: TPathId pathId = txState->TargetPathId; TPathElement::TPtr path = context.SS->PathsById.at(pathId); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); path->StepCreated = step; context.SS->PersistCreateStep(db, pathId, step); @@ -625,7 +625,7 @@ public: newTable->PathType = TPathElement::EPathType::EPathTypeTable; newTable->UserAttrs->AlterData = userAttrs; - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); TTxState& txState = context.SS->CreateTx(OperationId, TTxState::TxCreateTable, newTable->PathId); diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_drop_bsv.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_drop_bsv.cpp index e6f0322026..ffe49f67e7 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_drop_bsv.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_drop_bsv.cpp @@ -41,7 +41,7 @@ public: context.OnComplete.DeleteShard(shard.Idx); } - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); context.SS->ChangeTxState(db, OperationId, TTxState::Propose); return true; } @@ -81,7 +81,7 @@ public: auto path = context.SS->PathsById.at(pathId); auto parentDir = context.SS->PathsById.at(path->ParentPathId); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); Y_VERIFY(!path->Dropped()); path->SetDropped(step, OperationId.GetTxId()); @@ -253,7 +253,7 @@ public: txState.MinStep = TStepId(1); txState.State = TTxState::DeleteParts; - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); TBlockStoreVolumeInfo::TPtr volume = context.SS->BlockStoreVolumes.at(path.Base()->PathId); Y_VERIFY(volume); diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_drop_cdc_stream.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_drop_cdc_stream.cpp index 9d02b90e0d..c0d3dd5ba3 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_drop_cdc_stream.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_drop_cdc_stream.cpp @@ -53,7 +53,7 @@ public: Y_VERIFY(!path->Dropped()); path->SetDropped(step, OperationId.GetTxId()); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); context.SS->PersistDropStep(db, pathId, step, OperationId); context.SS->PersistRemoveCdcStream(db, pathId); @@ -181,6 +181,7 @@ public: } } + auto guard = context.DbGuard(); context.DbChanges.PersistTxState(OperationId); Y_VERIFY(!context.SS->FindTx(OperationId)); diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_drop_extsubdomain.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_drop_extsubdomain.cpp index c33f76ca93..9dd0dae03a 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_drop_extsubdomain.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_drop_extsubdomain.cpp @@ -40,7 +40,7 @@ public: context.OnComplete.DeleteShard(shard.Idx); } - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); context.SS->ChangeTxState(db, OperationId, TTxState::Done); return true; } @@ -95,7 +95,7 @@ public: TTabletId hive = TTabletId(record.GetOrigin()); context.OnComplete.UnbindMsgFromPipe(OperationId, hive, TPipeMessageId(0, 0)); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); context.SS->ChangeTxState(db, OperationId, TTxState::DeletePrivateShards); return true; @@ -119,7 +119,7 @@ public: TTabletId tenantSchemeshard = domainInfo->GetTenantSchemeShardID(); if (!tenantSchemeshard) { // ext_subdomain was't altered at all, and there has't been added tenantSchemeshard - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); context.SS->ChangeTxState(db, OperationId, TTxState::DeletePrivateShards); return true; } @@ -168,7 +168,7 @@ public: TPathId pathId = txState->TargetPathId; TPathElement::TPtr path = context.SS->PathsById.at(pathId); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); auto pathes = context.SS->ListSubThee(pathId, context.Ctx); context.SS->DropPathes(pathes, step, OperationId.GetTxId(), db, context.Ctx); @@ -332,7 +332,7 @@ public: txState.State = TTxState::Waiting; txState.MinStep = TStepId(1); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); auto relatedTx = context.SS->GetRelatedTransactions({path.Base()->PathId}, context.Ctx); diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_drop_fs.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_drop_fs.cpp index 4ba51deb84..1a41593ef8 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_drop_fs.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_drop_fs.cpp @@ -44,7 +44,7 @@ public: context.OnComplete.DeleteShard(shard.Idx); } - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); context.SS->ChangeTxState(db, OperationId, TTxState::Propose); return true; } @@ -91,7 +91,7 @@ public: auto path = context.SS->PathsById.at(pathId); auto parentDir = context.SS->PathsById.at(path->ParentPathId); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); Y_VERIFY(!path->Dropped()); path->SetDropped(step, OperationId.GetTxId()); @@ -306,7 +306,7 @@ THolder<TProposeResponse> TDropFileStore::Propose( txState.MinStep = TStepId(1); txState.State = TTxState::DeleteParts; - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); auto fs = context.SS->FileStoreInfos.at(path.Base()->PathId); Y_VERIFY_S(fs, "FileStore info is null. PathId: " << path.Base()->PathId); diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_drop_index.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_drop_index.cpp index a84868b77b..40dde95922 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_drop_index.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_drop_index.cpp @@ -176,7 +176,7 @@ public: Y_VERIFY(context.SS->Tables.contains(pathId)); TTableInfo::TPtr table = context.SS->Tables.at(pathId); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); table->AlterVersion += 1; context.SS->PersistTableAlterVersion(db, pathId, table); @@ -378,6 +378,7 @@ public: Y_VERIFY(!context.SS->FindTx(OperationId)); + auto guard = context.DbGuard(); context.MemChanges.GrabPath(context.SS, tablePath.Base()->PathId); context.MemChanges.GrabNewTxState(context.SS, OperationId); diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_drop_indexed_table.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_drop_indexed_table.cpp index 7064fabe1e..838013e661 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_drop_indexed_table.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_drop_indexed_table.cpp @@ -83,7 +83,7 @@ public: Y_VERIFY(txState->TxType == TTxState::TxDropTableIndex); Y_VERIFY(txState->State == TTxState::Propose); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); txState->PlanStep = step; context.SS->PersistTxPlanStep(db, OperationId, step); @@ -149,7 +149,7 @@ public: Y_VERIFY(ActivePathId == ev->Get()->PathId); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); context.SS->ChangeTxState(db, OperationId, TTxState::DeletePathBarrier); return true; } @@ -174,7 +174,7 @@ public: DebugHint() << " ProgressState" << ", no renaming has been detected for this operation"); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); context.SS->ChangeTxState(db, OperationId, TTxState::DeletePathBarrier); return true; } @@ -216,7 +216,7 @@ public: << ", msg: " << ev->Get()->ToString() << ", at tablet" << ssId); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); TTxState* txState = context.SS->FindTx(OperationId); Y_VERIFY(txState); @@ -378,6 +378,7 @@ public: Y_VERIFY(context.SS->Indexes.contains(index.Base()->PathId)); + auto guard = context.DbGuard(); context.MemChanges.GrabPath(context.SS, index.Base()->PathId); context.MemChanges.GrabNewTxState(context.SS, OperationId); diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_drop_kesus.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_drop_kesus.cpp index ad42e96de5..776814e95b 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_drop_kesus.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_drop_kesus.cpp @@ -41,7 +41,7 @@ public: context.OnComplete.DeleteShard(shard.Idx); } - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); context.SS->ChangeTxState(db, OperationId, TTxState::Propose); return true; } @@ -82,7 +82,7 @@ public: auto parentDir = context.SS->PathsById.at(path->ParentPathId); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); Y_VERIFY(!path->Dropped()); path->SetDropped(step, OperationId.GetTxId()); @@ -248,7 +248,7 @@ public: txState.MinStep = TStepId(1); txState.State = TTxState::DeleteParts; - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); TKesusInfo::TPtr kesus = context.SS->KesusInfos.at(path.Base()->PathId); Y_VERIFY(kesus); diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_drop_lock.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_drop_lock.cpp index 6fc10d0495..c99cc5664a 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_drop_lock.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_drop_lock.cpp @@ -153,7 +153,7 @@ public: return result; } - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); pathEl->LastTxId = OperationId.GetTxId(); pathEl->PathState = NKikimrSchemeOp::EPathState::EPathStateAlter; diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_drop_olap_store.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_drop_olap_store.cpp index ef1dafb905..9567113545 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_drop_olap_store.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_drop_olap_store.cpp @@ -37,7 +37,7 @@ public: Y_VERIFY(txState); Y_VERIFY(txState->TxType == TTxState::TxDropOlapStore); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); txState->ClearShardsInProgress(); @@ -86,7 +86,7 @@ public: "no parent with id: " << path->ParentPathId << " for node with id: " << path->PathId); auto parentDir = context.SS->PathsById.at(path->ParentPathId); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); Y_VERIFY(!path->Dropped()); path->SetDropped(step, OperationId.GetTxId()); @@ -168,7 +168,7 @@ public: } bool Finish(TOperationContext& context) { - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); context.SS->ChangeTxState(db, OperationId, TTxState::ProposedDeleteParts); return true; } @@ -243,7 +243,7 @@ public: Y_VERIFY(txState); Y_VERIFY(txState->TxType == TTxState::TxDropOlapStore); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); context.SS->PersistOlapStoreRemove(db, txState->TargetPathId); for (auto& shard : txState->Shards) { @@ -358,7 +358,7 @@ public: // Dirty hack: drop step must not be zero because 0 is treated as "hasn't been dropped" txState.MinStep = TStepId(1); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); for (auto shardIdx : storeInfo->ColumnShards) { Y_VERIFY_S(context.SS->ShardInfos.contains(shardIdx), "Unknown shardIdx " << shardIdx); diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_drop_olap_table.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_drop_olap_table.cpp index 02ca98d236..0370676572 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_drop_olap_table.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_drop_olap_table.cpp @@ -125,7 +125,7 @@ public: "no parent with id: " << path->ParentPathId << " for node with id: " << path->PathId); auto parentDir = context.SS->PathsById.at(path->ParentPathId); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); Y_VERIFY(!path->Dropped()); path->SetDropped(step, OperationId.GetTxId()); @@ -212,7 +212,7 @@ public: } bool Finish(TOperationContext& context) { - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); context.SS->ChangeTxState(db, OperationId, TTxState::ProposedDeleteParts); return true; } @@ -287,7 +287,7 @@ public: Y_VERIFY(txState); Y_VERIFY(txState->TxType == TTxState::TxDropOlapTable); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); context.SS->PersistOlapTableRemove(db, txState->TargetPathId); context.OnComplete.DoneOperation(OperationId); @@ -414,7 +414,7 @@ public: // Dirty hack: drop step must not be zero because 0 is treated as "hasn't been dropped" txState.MinStep = TStepId(1); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); // TODO: we need to know all shards where this table has ever been created for (ui64 columnShardId : tableInfo->ColumnShards) { diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_drop_pq.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_drop_pq.cpp index c338b4c358..a718dbaf91 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_drop_pq.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_drop_pq.cpp @@ -59,7 +59,7 @@ public: context.OnComplete.UnbindMsgFromPipe(OperationId, tabletId, idx); if (txState->ShardsInProgress.empty()) { - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); context.SS->ChangeTxState(db, OperationId, TTxState::DeleteParts); context.OnComplete.ActivateTx(OperationId); return true; @@ -108,7 +108,7 @@ public: txState->UpdateShardsInProgress(TTxState::DropParts); if (!haveWork) { - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); context.SS->ChangeTxState(db, OperationId, TTxState::DeleteParts); context.OnComplete.ActivateTx(OperationId); return true; @@ -150,7 +150,7 @@ public: context.OnComplete.DeleteShard(shard.Idx); } - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); context.SS->ChangeTxState(db, OperationId, TTxState::Propose); context.OnComplete.ActivateTx(OperationId); return true; @@ -192,7 +192,7 @@ public: auto path = context.SS->PathsById.at(pathId); auto parentDir = context.SS->PathsById.at(path->ParentPathId); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); Y_VERIFY(!path->Dropped()); path->SetDropped(step, OperationId.GetTxId()); @@ -472,7 +472,7 @@ public: // Dirty hack: drop step must not be zero because 0 is treated as "hasn't been dropped" txState.MinStep = TStepId(1); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); SetPQShards(pqGroup, txState, context); SetPQBalancer(pqGroup, txState, context); diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_drop_replication.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_drop_replication.cpp index b45abf97c5..a1693c8a35 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_drop_replication.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_drop_replication.cpp @@ -94,7 +94,7 @@ public: return false; } - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); context.SS->ChangeTxState(db, OperationId, TTxState::Propose); context.OnComplete.ActivateTx(OperationId); @@ -150,7 +150,7 @@ public: Y_VERIFY(context.SS->PathsById.contains(path->ParentPathId)); auto parentPath = context.SS->PathsById.at(path->ParentPathId); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); Y_VERIFY(!path->Dropped()); path->SetDropped(step, OperationId.GetTxId()); @@ -320,7 +320,7 @@ public: path->DropTxId = OperationId.GetTxId(); path->LastTxId = OperationId.GetTxId(); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); context.SS->PersistLastTxId(db, path.Base()); context.SS->PersistTxState(db, OperationId); diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_drop_sequence.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_drop_sequence.cpp index f9c8734073..3f0a2ca03e 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_drop_sequence.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_drop_sequence.cpp @@ -75,7 +75,7 @@ public: context.OnComplete.UnbindMsgFromPipe(OperationId, tabletId, txState->TargetPathId); if (txState->ShardsInProgress.empty()) { - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); context.SS->ChangeTxState(db, OperationId, TTxState::Propose); context.OnComplete.ActivateTx(OperationId); return true; @@ -164,7 +164,7 @@ public: "no parent with id: " << path->ParentPathId << " for node with id: " << path->PathId); auto parentDir = context.SS->PathsById.at(path->ParentPathId); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); Y_VERIFY(!path->Dropped()); path->SetDropped(step, OperationId.GetTxId()); @@ -368,7 +368,7 @@ public: // Dirty hack: drop step must not be zero because 0 is treated as "hasn't been dropped" txState.MinStep = TStepId(1); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); for (const auto& shardIdxProto : sequenceInfo->Sharding.GetSequenceShards()) { TShardIdx shardIdx = FromProto(shardIdxProto); diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_drop_solomon.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_drop_solomon.cpp index bdd9f953d4..2d4db56a29 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_drop_solomon.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_drop_solomon.cpp @@ -79,7 +79,7 @@ public: TPathId pathId = txState->TargetPathId; TPathElement::TPtr path = context.SS->PathsById.at(pathId); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); auto pathes = context.SS->ListSubThee(pathId, context.Ctx); Y_VERIFY(pathes.size() == 1); @@ -234,7 +234,7 @@ public: auto solomon = context.SS->SolomonVolumes.at(path.Base()->PathId); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); for (auto& part : solomon->Partitions) { auto shardIdx = part.first; diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_drop_subdomain.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_drop_subdomain.cpp index 832fd1df70..e29d217d9b 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_drop_subdomain.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_drop_subdomain.cpp @@ -78,7 +78,7 @@ public: TPathId pathId = txState->TargetPathId; TPathElement::TPtr path = context.SS->PathsById.at(pathId); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); auto pathes = context.SS->ListSubThee(pathId, context.Ctx); Y_VERIFY(pathes.size() == 1); @@ -233,7 +233,7 @@ public: txState.MinStep = TStepId(1); txState.State = TTxState::Propose; - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); Y_VERIFY(context.SS->SubDomains.contains(path.Base()->PathId)); auto subDomain = context.SS->SubDomains.at(path.Base()->PathId); diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_drop_table.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_drop_table.cpp index 45730be409..36b885caa0 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_drop_table.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_drop_table.cpp @@ -192,7 +192,7 @@ public: TPath path = TPath::Init(txState->TargetPathId, context.SS); Y_VERIFY(path.IsResolved()); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); txState->PlanStep = step; context.SS->PersistTxPlanStep(db, OperationId, step); @@ -277,7 +277,7 @@ public: Y_VERIFY(ActivePathId == ev->Get()->PathId); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); context.SS->ChangeTxState(db, OperationId, TTxState::DeletePathBarrier); return true; } @@ -301,7 +301,7 @@ public: DebugHint() << " ProgressState" << ", no renaming has been detected for this operation"); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); context.SS->ChangeTxState(db, OperationId, TTxState::DeletePathBarrier); return true; } @@ -359,7 +359,7 @@ public: TTxState* txState = context.SS->FindTx(OperationId); Y_VERIFY(txState); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); TPath path = TPath::Init(txState->TargetPathId, context.SS); DropPath(db, context, OperationId, *txState, path); @@ -431,7 +431,7 @@ public: Y_VERIFY(txState); Y_VERIFY(txState->TxType == TTxState::TxDropTable); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); context.SS->PersistRemoveTable(db, txState->TargetPathId, context.Ctx); @@ -606,6 +606,7 @@ public: return result; } + auto guard = context.DbGuard(); context.MemChanges.GrabNewTxState(context.SS, OperationId); context.MemChanges.GrabPath(context.SS, path.Base()->PathId); context.MemChanges.GrabPath(context.SS, parent.Base()->PathId); @@ -638,7 +639,7 @@ public: path.Base()->DropTxId = OperationId.GetTxId(); path.Base()->LastTxId = OperationId.GetTxId(); - IncParentDirAlterVersionWithRepublish(OperationId, path, context); + IncParentDirAlterVersionWithRepublishSafeWithUndo(OperationId, path, context.SS, context.OnComplete); for (auto splitTx: table->GetSplitOpsInFlight()) { context.OnComplete.Dependence(splitTx.GetTxId(), OperationId.GetTxId()); diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_drop_unsafe.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_drop_unsafe.cpp index a1a9f2ccfd..9f4d14e7fd 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_drop_unsafe.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_drop_unsafe.cpp @@ -81,7 +81,7 @@ public: TPathElement::TPtr path = context.SS->PathsById.at(pathId); auto pathes = context.SS->ListSubThee(pathId, context.Ctx); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); context.SS->DropPathes(pathes, step, OperationId.GetTxId(), db, context.Ctx); @@ -266,7 +266,7 @@ public: txState.State = TTxState::Waiting; txState.MinStep = TStepId(1); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); auto pathes = context.SS->ListSubThee(path.Base()->PathId, context.Ctx); diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_finalize_build_index.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_finalize_build_index.cpp index fe5416aa52..60b96ae464 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_finalize_build_index.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_finalize_build_index.cpp @@ -154,7 +154,7 @@ public: TTxState* txState = context.SS->FindTx(OperationId); Y_VERIFY(txState->TxType == TTxState::TxFinalizeBuildIndex); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); TPathId tableId = txState->TargetPathId; TTxId snapshotTxId = context.SS->TablesWithSnaphots.at(tableId); context.SS->SnapshotsStepIds.erase(snapshotTxId); @@ -241,7 +241,7 @@ public: } - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); context.SS->ChangeTxState(db, OperationId, TTxState::ConfigureParts); @@ -407,7 +407,7 @@ public: return result; } - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); pathEl->LastTxId = OperationId.GetTxId(); pathEl->PathState = NKikimrSchemeOp::EPathState::EPathStateAlter; diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_initiate_build_index.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_initiate_build_index.cpp index f8d5ca96c6..4d41f250b4 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_initiate_build_index.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_initiate_build_index.cpp @@ -176,7 +176,7 @@ public: TTxState* txState = context.SS->FindTx(OperationId); Y_VERIFY(txState->TxType == TTxState::TxInitializeBuildIndex); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); context.SS->SnapshotsStepIds[OperationId.GetTxId()] = step; context.SS->PersistSnapshotStepId(db, OperationId.GetTxId(), step); @@ -254,7 +254,7 @@ public: } - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); context.SS->ChangeTxState(db, OperationId, TTxState::ConfigureParts); @@ -426,7 +426,7 @@ public: return result; } - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); pathEl->LastTxId = OperationId.GetTxId(); pathEl->PathState = NKikimrSchemeOp::EPathState::EPathStateAlter; diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_mkdir.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_mkdir.cpp index a2afe4741a..fe3c0b867e 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_mkdir.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_mkdir.cpp @@ -40,7 +40,7 @@ public: context.SS->TabletCounters->Simple()[COUNTER_DIR_COUNT].Add(1); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); path.Base()->DirAlterVersion += 1; context.SS->PersistPathDirAlterVersion(db, path.Base()); @@ -222,6 +222,7 @@ public: return result; } + auto guard = context.DbGuard(); TPathId allocatedPathId = context.SS->AllocatePathId(); context.MemChanges.GrabNewPath(context.SS, allocatedPathId); context.MemChanges.GrabPath(context.SS, parentPath.Base()->PathId); @@ -255,7 +256,7 @@ public: context.OnComplete.Dependence(parentTxId, OperationId.GetTxId()); } - IncParentDirAlterVersionWithRepublish(OperationId, dstPath, context); + IncParentDirAlterVersionWithRepublishSafeWithUndo(OperationId, dstPath, context.SS, context.OnComplete); dstPath.DomainInfo()->IncPathsInside(); parentPath.Base()->IncAliveChildren(); diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_modify_acl.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_modify_acl.cpp index fac70a7704..2f90fb38e7 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_modify_acl.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_modify_acl.cpp @@ -68,7 +68,7 @@ public: return result; } - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); const TString owner = Transaction.GetModifyACL().GetNewOwner(); diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_move_table.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_move_table.cpp index 019069b16d..10761adf74 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_move_table.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_move_table.cpp @@ -64,7 +64,7 @@ public: Y_VERIFY(srcPath.IsResolved()); TTableInfo::TPtr srcTable = context.SS->Tables.at(srcPath->PathId); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); // txState catches table shards if (!txState->Shards) { @@ -205,7 +205,7 @@ public: auto srcPath = TPath::Init(txState->SourcePathId, context.SS); auto dstPath = TPath::Init(txState->TargetPathId, context.SS); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); txState->PlanStep = step; context.SS->PersistTxPlanStep(db, OperationId, step); @@ -327,7 +327,7 @@ public: Y_VERIFY(ActivePathId == ev->Get()->PathId); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); context.SS->ChangeTxState(db, OperationId, TTxState::DeletePathBarrier); return true; } @@ -351,7 +351,7 @@ public: DebugHint() << " ProgressState" << ", no renaming has been detected for this operation"); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); context.SS->ChangeTxState(db, OperationId, TTxState::DeletePathBarrier); return true; } @@ -406,7 +406,7 @@ public: << ", msg: " << ev->Get()->ToString() << ", at tablet" << ssId); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); TTxState* txState = context.SS->FindTx(OperationId); Y_VERIFY(txState); @@ -488,7 +488,7 @@ public: << ", at schemeshard: " << ssId); // clear resources on src - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); TPathElement::TPtr srcPath = context.SS->PathsById.at(txState->SourcePathId); context.OnComplete.ReleasePathState(OperationId, srcPath->PathId, TPathElement::EPathState::EPathStateNotExist); @@ -713,6 +713,7 @@ public: return result; } + auto guard = context.DbGuard(); TPathId allocatedPathId = context.SS->AllocatePathId(); context.MemChanges.GrabNewPath(context.SS, allocatedPathId); context.MemChanges.GrabPath(context.SS, dstParent.Base()->PathId); @@ -747,8 +748,8 @@ public: srcPath->PathState = TPathElement::EPathState::EPathStateMoving; srcPath->LastTxId = OperationId.GetTxId(); - IncParentDirAlterVersionWithRepublish(OperationId, dstPath, context); - IncParentDirAlterVersionWithRepublish(OperationId, srcPath, context); + IncParentDirAlterVersionWithRepublishSafeWithUndo(OperationId, dstPath, context.SS, context.OnComplete); + IncParentDirAlterVersionWithRepublishSafeWithUndo(OperationId, srcPath, context.SS, context.OnComplete); // wait splits TTableInfo::TPtr tableSrc = context.SS->Tables.at(srcPath.Base()->PathId); diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_move_table_index.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_move_table_index.cpp index 9d03d70c7c..db6a6f2892 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_move_table_index.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_move_table_index.cpp @@ -59,7 +59,7 @@ public: auto srcPath = TPath::Init(txState->SourcePathId, context.SS); auto dstPath = TPath::Init(txState->TargetPathId, context.SS); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); txState->PlanStep = step; context.SS->PersistTxPlanStep(db, OperationId, step); @@ -149,7 +149,7 @@ public: Y_VERIFY(ActivePathId == ev->Get()->PathId); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); context.SS->ChangeTxState(db, OperationId, TTxState::DeletePathBarrier); return true; } @@ -173,7 +173,7 @@ public: DebugHint() << " ProgressState" << ", no renaming has been detected for this operation"); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); context.SS->ChangeTxState(db, OperationId, TTxState::DeletePathBarrier); return true; } @@ -228,7 +228,7 @@ public: << ", msg: " << ev->Get()->ToString() << ", at tablet" << ssId); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); TTxState* txState = context.SS->FindTx(OperationId); Y_VERIFY(txState); @@ -295,7 +295,7 @@ public: << ", at schemeshard: " << ssId); // clear resources on src - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); TPathElement::TPtr srcPath = context.SS->PathsById.at(txState->SourcePathId); context.OnComplete.ReleasePathState(OperationId, srcPath->PathId, TPathElement::EPathState::EPathStateNotExist); @@ -537,6 +537,7 @@ public: return result; } + auto guard = context.DbGuard(); TPathId allocatedPathId = context.SS->AllocatePathId(); context.MemChanges.GrabNewPath(context.SS, allocatedPathId); context.MemChanges.GrabPath(context.SS, dstParentPath.Base()->PathId); @@ -577,8 +578,8 @@ public: context.SS->IncrementPathDbRefCount(dstPath.Base()->PathId); - IncParentDirAlterVersionWithRepublish(OperationId, dstPath, context); - IncParentDirAlterVersionWithRepublish(OperationId, srcPath, context); + IncParentDirAlterVersionWithRepublishSafeWithUndo(OperationId, dstPath, context.SS, context.OnComplete); + IncParentDirAlterVersionWithRepublishSafeWithUndo(OperationId, srcPath, context.SS, context.OnComplete); context.OnComplete.ActivateTx(OperationId); State = NextState(); diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_part.h b/ydb/core/tx/schemeshard/schemeshard__operation_part.h index 579b52a461..6841aebdf7 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_part.h +++ b/ydb/core/tx/schemeshard/schemeshard__operation_part.h @@ -77,14 +77,70 @@ namespace NSchemeShard { class TSchemeShard; struct TOperationContext { +public: TSchemeShard* SS; - NTabletFlatExecutor::TTransactionContext& Txc; const TActorContext& Ctx; TSideEffects& OnComplete; TMemoryChanges& MemChanges; TStorageChanges& DbChanges; + TAutoPtr<NACLib::TUserToken> UserToken = nullptr; bool IsAllowedPrivateTables = false; + +private: + NTabletFlatExecutor::TTransactionContext& Txc; + bool ProtectDB = false; + bool DirectAccessGranted = false; + +public: + TOperationContext( + TSchemeShard* ss, + NTabletFlatExecutor::TTransactionContext& txc, const TActorContext& ctx, + TSideEffects& onComplete, TMemoryChanges& memChanges, TStorageChanges& dbChange) + : SS(ss) + , Ctx(ctx) + , OnComplete(onComplete) + , MemChanges(memChanges) + , DbChanges(dbChange) + , Txc(txc) + {} + + NTable::TDatabase& GetDB() { + Y_VERIFY_S(ProtectDB == false, + "there is attempt to write to the DB when it is protected," + " in that case all writes slould be done over TStorageChanges" + " in order to maintain revert the changes"); + DirectAccessGranted = true; + return GetTxc().DB; + } + + NTabletFlatExecutor::TTransactionContext& GetTxc() const { + return Txc; + } + + bool IsUndoChangesSafe() const { + return !DirectAccessGranted; + } + + class TDbGuard { + bool PrevVal; + bool& Protect; + public: + TDbGuard(TOperationContext& ctx) + : PrevVal(ctx.ProtectDB) + , Protect(ctx.ProtectDB) + { + Protect = true; + } + + ~TDbGuard() { + Protect = PrevVal; + } + }; + + TDbGuard DbGuard() { + return TDbGuard(*this); + } }; using TProposeRequest = NKikimr::NSchemeShard::TEvSchemeShard::TEvModifySchemeTransaction; diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_rmdir.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_rmdir.cpp index f2dea8f26d..cde36e35e8 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_rmdir.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_rmdir.cpp @@ -77,7 +77,7 @@ public: return result; } - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); TTxState& txState = context.SS->CreateTx(OperationId, TTxState::TxRmDir, path.Base()->PathId); txState.State = TTxState::Propose; txState.MinStep = TStepId(1); @@ -149,7 +149,7 @@ public: return; } - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); TPathId pathId = txState->TargetPathId; auto path = context.SS->PathsById.at(pathId); diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_split_merge.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_split_merge.cpp index 92f91a0918..fde555580f 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_split_merge.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_split_merge.cpp @@ -35,7 +35,7 @@ public: << ", at schemeshard: " << ssId << " message# " << ev->Get()->Record.ShortDebugString()); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); TTxState* txState = context.SS->FindTx(OperationId); Y_VERIFY(txState); @@ -112,7 +112,7 @@ public: TString extraData; bool serializeRes = txState->SplitDescription->SerializeToString(&extraData); Y_VERIFY(serializeRes); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); db.Table<Schema::TxInFlightV2>().Key(OperationId.GetTxId(), OperationId.GetSubTxId()).Update( NIceDb::TUpdate<Schema::TxInFlightV2::ExtraBytes>(extraData)); @@ -204,7 +204,7 @@ public: << ", at schemeshard: " << ssId << ", message: " << ev->Get()->Record.ShortDebugString()); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); TTxState* txState = context.SS->FindTx(OperationId); Y_VERIFY(txState); @@ -954,6 +954,7 @@ public: /// Accept operation /// + auto guard = context.DbGuard(); context.MemChanges.GrabNewTxState(context.SS, OperationId); context.MemChanges.GrabDomain(context.SS, path.DomainId()); context.MemChanges.GrabPath(context.SS, path->PathId); diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_upgrade_subdomain.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_upgrade_subdomain.cpp index ad9c6808fc..da4912ee96 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_upgrade_subdomain.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_upgrade_subdomain.cpp @@ -63,7 +63,7 @@ public: } if (isDone) { - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); TPathId pathId = txState->TargetPathId; TPathElement::TPtr elem = context.SS->PathsById.at(pathId); @@ -144,7 +144,7 @@ public: auto next = NextMessage(context); if (!next) { // All tablets have replied so we can done this transaction - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); context.SS->ChangeTxState(db, OperationId, TTxState::PublishTenantReadOnly); context.OnComplete.ActivateTx(OperationId); return true; @@ -374,7 +374,7 @@ public: auto next = NextMessage(context); if (!next) { // All tablets have replied so we can done this transaction - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); context.SS->ChangeTxState(db, OperationId, TTxState::PublishTenantReadOnly); context.OnComplete.ActivateTx(OperationId); return true; @@ -465,7 +465,7 @@ public: Y_VERIFY(TTabletId(ev->Get()->Record.GetTenantSchemeShard()) == TenantSchemeShardId); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); context.SS->ChangeTxState(db, OperationId, TTxState::PublishGlobal); context.OnComplete.ActivateTx(OperationId); return true; @@ -553,7 +553,7 @@ public: context.SS->ClearDescribePathCaches(item); //something has changed let's show it } - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); Y_VERIFY(path->PathType == TPathElement::EPathType::EPathTypeExtSubDomain); context.SS->PersistPath(db, path->PathId); @@ -581,7 +581,7 @@ public: TTxState* txState = context.SS->FindTx(OperationId); Y_VERIFY(txState); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); TPathId pathId = txState->TargetPathId; TPathElement::TPtr item = context.SS->PathsById.at(pathId); @@ -701,7 +701,7 @@ public: bool ProgressState(TOperationContext& context) override { TTabletId ssId = context.SS->SelfTabletId(); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); LOG_INFO_S(context.Ctx, NKikimrServices::FLAT_TX_SCHEMESHARD, DebugHint() << " ProgressState" @@ -774,7 +774,7 @@ public: auto nextEvent = NextRequest(context); if (!nextEvent) { - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); context.SS->ChangeTxState(db, OperationId, TTxState::PublishTenant); context.OnComplete.ActivateTx(OperationId); return true; @@ -862,7 +862,7 @@ public: auto event = NextRequest(context); if (!event) { - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); context.SS->ChangeTxState(db, OperationId, TTxState::PublishTenant); context.OnComplete.ActivateTx(OperationId); return true; @@ -904,7 +904,7 @@ public: } bool HandleReply(TEvSchemeShard::TEvPublishTenantResult::TPtr& /*ev*/, TOperationContext& context) override { - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); context.SS->ChangeTxState(db, OperationId, TTxState::DoneMigrateTree); context.OnComplete.ActivateTx(OperationId); return true; @@ -991,7 +991,7 @@ public: Init(txState->TargetPathId, context); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); if (!ShardsToRememder.empty()) { const auto shardIdx = ShardsToRememder.back(); @@ -1249,7 +1249,7 @@ public: subDomain->SetAlter(alterData); - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); context.SS->PersistUpdateNextShardIdx(db); context.SS->PersistTxState(db, OperationId); @@ -1499,7 +1499,7 @@ public: TTxState& txState = context.SS->CreateTx(OperationId, TTxState::TxUpgradeSubDomainDecision, path.Base()->PathId); txState.State = TTxState::Waiting; - NIceDb::TNiceDb db(context.Txc.DB); + NIceDb::TNiceDb db(context.GetDB()); context.SS->PersistTxState(db, OperationId); diff --git a/ydb/core/tx/schemeshard/ut_reboots.cpp b/ydb/core/tx/schemeshard/ut_reboots.cpp index dce2c12712..2b43d81379 100644 --- a/ydb/core/tx/schemeshard/ut_reboots.cpp +++ b/ydb/core/tx/schemeshard/ut_reboots.cpp @@ -43,6 +43,44 @@ Y_UNIT_TEST_SUITE(IntermediateDirsReboots) { }); } + Y_UNIT_TEST(CreateTableWithIntermediateDirsAndRejectInSolomon) { + const TString validScheme = R"( + Name: "Valid/x/y/z" + PartitionCount: 2 + )"; + const TString invalidScheme = R"( + Name: "Invalid/a/b/c" + PartitionCount: 2 + ChannelProfileId: 30 + )"; + + const auto validStatus = NKikimrScheme::StatusAccepted; + const auto invalidStatus = NKikimrScheme::StatusInvalidParameter; + + CreateWithIntermediateDirs([&](TTestActorRuntime& runtime, ui64 txId, const TString& root, bool valid) { + TestCreateSolomon(runtime, txId, root, valid ? validScheme : invalidScheme, {valid ? validStatus : invalidStatus}); + }); + } + + Y_UNIT_TEST(CreateTableWithIntermediateDirsAndRejectInTable) { + const TString validScheme = R"( + Name: "Valid/x/y/z/table_name" + Columns { Name: "RowId" Type: "Uint64" } + KeyColumnNames: ["RowId"] + )"; + const TString invalidScheme = R"( + Name: "Invalid/a/b/c/table_name" + Columns { Name: "RowId" Type: "Uint64" } + KeyColumnNames: ["RowId_Invalid"] + )"; + const auto validStatus = NKikimrScheme::StatusAccepted; + const auto invalidStatus = NKikimrScheme::StatusSchemeError; + + CreateWithIntermediateDirs([&](TTestActorRuntime& runtime, ui64 txId, const TString& root, bool valid) { + TestCreateTable(runtime, txId, root, valid ? validScheme : invalidScheme, {valid ? validStatus : invalidStatus}); + }); + } + Y_UNIT_TEST(CreateKesusWithIntermediateDirs) { const TString validScheme = R"( Name: "Valid/x/y/z" @@ -144,7 +182,7 @@ Y_UNIT_TEST_SUITE(IntermediateDirsReboots) { Y_UNIT_TEST(CreateWithIntermediateDirs) { const TString validScheme = R"( Name: "Valid/x/y/z" - PartitionsCount: 0 + PartitionsCount: 1 )"; const TString invalidScheme = R"( Name: "Invalid/wr0ng n@me" |