diff --git a/ydb/core/tx/schemeshard/index/operation_alter_index.cpp b/ydb/core/tx/schemeshard/index/operation_alter_index.cpp index f01b32ab57786..9859f5a01e931 100644 --- a/ydb/core/tx/schemeshard/index/operation_alter_index.cpp +++ b/ydb/core/tx/schemeshard/index/operation_alter_index.cpp @@ -46,7 +46,7 @@ class TPropose: public TSubOperationState { Y_ABORT_UNLESS(context.SS->Indexes.contains(path->PathId)); auto indexData = context.SS->Indexes.at(path->PathId); context.SS->PersistTableIndex(db, path->PathId); - context.SS->Indexes.SetUntracked(path->PathId, indexData->AlterData); + context.SS->Indexes.Set(path->PathId, indexData->AlterData); context.SS->ClearDescribePathCaches(path); context.OnComplete.PublishToSchemeBoard(OperationId, path->PathId); @@ -193,10 +193,8 @@ class TAlterTableIndex: public TSubOperation { context.DbChanges.PersistAlterIndex(indexPath->PathId); context.DbChanges.PersistTxState(OperationId); + context.MemChanges.GrabIndex(context.SS, indexPath->PathId); auto indexData = context.SS->Indexes.Update(indexPath->PathId); - context.MemChanges.RecordUndo([indexData, previous = indexData->AlterData]() { - indexData->AlterData = previous; - }); TTableIndexInfo::TPtr newIndexData = indexData->CreateNextVersion(); Y_ABORT_UNLESS(newIndexData); newIndexData->State = tableIndexAlter.GetState(); diff --git a/ydb/core/tx/schemeshard/index/operation_create_index.cpp b/ydb/core/tx/schemeshard/index/operation_create_index.cpp index 69cd143eb8cfd..54ab66dad2933 100644 --- a/ydb/core/tx/schemeshard/index/operation_create_index.cpp +++ b/ydb/core/tx/schemeshard/index/operation_create_index.cpp @@ -50,7 +50,7 @@ class TPropose: public TSubOperationState { Y_ABORT_UNLESS(context.SS->Indexes.contains(path->PathId)); auto indexData = context.SS->Indexes.at(path->PathId); context.SS->PersistTableIndex(db, path->PathId); - context.SS->Indexes.SetUntracked(path->PathId, indexData->AlterData); + context.SS->Indexes.Set(path->PathId, indexData->AlterData); context.SS->ClearDescribePathCaches(path); context.OnComplete.PublishToSchemeBoard(OperationId, path->PathId); @@ -249,7 +249,8 @@ class TCreateTableIndex: public TSubOperation { newIndexPath->LastTxId = OperationId.GetTxId(); newIndexPath->PathType = TPathElement::EPathType::EPathTypeTableIndex; - context.SS->Indexes.Set({.Path = newIndexPath->PathId, .Value = newIndexData, .Changes = context.MemChanges}); + context.MemChanges.GrabNewIndex(context.SS, newIndexPath->PathId); + context.SS->Indexes.Set(newIndexPath->PathId, newIndexData); if (!acl.empty()) { newIndexPath->ApplyACL(acl); diff --git a/ydb/core/tx/schemeshard/index/operation_drop_index.cpp b/ydb/core/tx/schemeshard/index/operation_drop_index.cpp index 15e21a4fed907..4fd8319cdb31c 100644 --- a/ydb/core/tx/schemeshard/index/operation_drop_index.cpp +++ b/ydb/core/tx/schemeshard/index/operation_drop_index.cpp @@ -167,7 +167,7 @@ class TPropose: public TSubOperationState { TPathElement::TPtr path = context.SS->PathsById.at(pathId); Y_ABORT_UNLESS(context.SS->Tables.contains(pathId)); - auto& table = context.SS->Tables.UpdateUntracked(pathId); + auto& table = context.SS->Tables.Update(pathId); NIceDb::TNiceDb db(context.GetDB()); diff --git a/ydb/core/tx/schemeshard/index/operation_finalize_build_index.cpp b/ydb/core/tx/schemeshard/index/operation_finalize_build_index.cpp index 10bfc62c0122a..ff645cfbee9dd 100644 --- a/ydb/core/tx/schemeshard/index/operation_finalize_build_index.cpp +++ b/ydb/core/tx/schemeshard/index/operation_finalize_build_index.cpp @@ -154,7 +154,7 @@ class TPropose: public TSubOperationState { context.SS->PersistDropSnapshot(db, snapshotTxId, tableId); - auto& tableInfo = context.SS->Tables.UpdateUntracked(txState->TargetPathId); + auto& tableInfo = context.SS->Tables.Update(txState->TargetPathId); tableInfo->AlterVersion += 1; for(auto& column: tableInfo->Columns) { diff --git a/ydb/core/tx/schemeshard/index/operation_initiate_build_index.cpp b/ydb/core/tx/schemeshard/index/operation_initiate_build_index.cpp index c47676644ef86..058458867a89a 100644 --- a/ydb/core/tx/schemeshard/index/operation_initiate_build_index.cpp +++ b/ydb/core/tx/schemeshard/index/operation_initiate_build_index.cpp @@ -173,7 +173,7 @@ class TPropose: public TSubOperationState { context.SS->SnapshotsStepIds[OperationId.GetTxId()] = step; context.SS->PersistSnapshotStepId(db, OperationId.GetTxId(), step); - auto& tableInfo = context.SS->Tables.UpdateUntracked(txState->TargetPathId); + auto& tableInfo = context.SS->Tables.Update(txState->TargetPathId); tableInfo->AlterVersion += 1; context.SS->PersistTableAlterVersion(db, txState->TargetPathId, tableInfo); diff --git a/ydb/core/tx/schemeshard/index/operation_move_index.cpp b/ydb/core/tx/schemeshard/index/operation_move_index.cpp index b20e17ad7c73c..8e8f5fd396291 100644 --- a/ydb/core/tx/schemeshard/index/operation_move_index.cpp +++ b/ydb/core/tx/schemeshard/index/operation_move_index.cpp @@ -277,7 +277,7 @@ class TDeleteTableBarrier: public TSubOperationState { TPath path = TPath::Init(txState->TargetPathId, context.SS); - auto& table = context.SS->Tables.UpdateUntracked(txState->TargetPathId); + auto& table = context.SS->Tables.Update(txState->TargetPathId); Y_ABORT_UNLESS(txState->PlanStep); diff --git a/ydb/core/tx/schemeshard/index/operation_move_table_index.cpp b/ydb/core/tx/schemeshard/index/operation_move_table_index.cpp index 92d334e7f1ce4..18995080e7454 100644 --- a/ydb/core/tx/schemeshard/index/operation_move_table_index.cpp +++ b/ydb/core/tx/schemeshard/index/operation_move_table_index.cpp @@ -68,7 +68,7 @@ class TPropose: public TSubOperationState { auto indexData = context.SS->Indexes.at(dstPath.Base()->PathId); context.SS->PersistTableIndex(db, dstPath.Base()->PathId); - context.SS->Indexes.SetUntracked(dstPath.Base()->PathId, indexData->AlterData); + context.SS->Indexes.Set(dstPath.Base()->PathId, indexData->AlterData); dstPath->StepCreated = step; context.SS->PersistCreateStep(db, dstPath.Base()->PathId, step); @@ -513,7 +513,8 @@ class TMoveTableIndex: public TSubOperation { const auto srcIndexInfo = context.SS->Indexes.at(srcPath.Base()->PathId); auto newIndexData = TTableIndexInfo::NotExistedYet(srcIndexInfo->Type); - context.SS->Indexes.Set({.Path = dstPath.Base()->PathId, .Value = newIndexData, .Changes = context.MemChanges}); + context.MemChanges.GrabNewIndex(context.SS, dstPath.Base()->PathId); + context.SS->Indexes.Set(dstPath.Base()->PathId, newIndexData); newIndexData->AlterData = srcIndexInfo->GetNextVersion(); diff --git a/ydb/core/tx/schemeshard/index/operation_prepare_index_validation.cpp b/ydb/core/tx/schemeshard/index/operation_prepare_index_validation.cpp index 2459a642d36ff..3bb76eee4b2f7 100644 --- a/ydb/core/tx/schemeshard/index/operation_prepare_index_validation.cpp +++ b/ydb/core/tx/schemeshard/index/operation_prepare_index_validation.cpp @@ -140,7 +140,7 @@ class TPropose: public TSubOperationState { context.SS->SnapshotsStepIds[OperationId.GetTxId()] = step; context.SS->PersistSnapshotStepId(db, OperationId.GetTxId(), step); - auto& tableInfo = context.SS->Tables.UpdateUntracked(txState->TargetPathId); + auto& tableInfo = context.SS->Tables.Update(txState->TargetPathId); tableInfo->AlterVersion += 1; tableInfo->MutablePartitionConfig().ClearShadowData(); tableInfo->MutablePartitionConfig().MutableCompactionPolicy()->SetKeepEraseMarkers(false); diff --git a/ydb/core/tx/schemeshard/olap/operations/alter/in_store/object.cpp b/ydb/core/tx/schemeshard/olap/operations/alter/in_store/object.cpp index 178389bdfdc5c..ac52843743884 100644 --- a/ydb/core/tx/schemeshard/olap/operations/alter/in_store/object.cpp +++ b/ydb/core/tx/schemeshard/olap/operations/alter/in_store/object.cpp @@ -24,7 +24,7 @@ TConclusionStatus TInStoreTable::InitializeWithTableInfo(const TEntityInitializa } Y_ABORT_UNLESS(context.GetSSOperationContext()->SS->OlapStores.contains(storePathId)); - StoreInfo = context.GetSSOperationContext()->SS->OlapStores.UpdateUntracked(storePathId); + StoreInfo = context.GetSSOperationContext()->SS->OlapStores.Update(storePathId); TOlapSchema schema; schema.ParseFromLocalDB(GetTableSchemaProto().DetachResult()); TableSchema = std::move(schema); diff --git a/ydb/core/tx/schemeshard/olap/operations/alter_local_index.cpp b/ydb/core/tx/schemeshard/olap/operations/alter_local_index.cpp index 4d33a89e8d335..a2adfec3ea512 100644 --- a/ydb/core/tx/schemeshard/olap/operations/alter_local_index.cpp +++ b/ydb/core/tx/schemeshard/olap/operations/alter_local_index.cpp @@ -46,7 +46,7 @@ class TPropose: public TSubOperationState { auto indexData = context.SS->Indexes.at(path->PathId); Y_ABORT_UNLESS(indexData->AlterData, "AlterData must be valid after TTableIndexInfo::Create"); context.SS->PersistTableIndex(db, path->PathId); - context.SS->Indexes.SetUntracked(path->PathId, indexData->AlterData); + context.SS->Indexes.Set(path->PathId, indexData->AlterData); auto parentPath = TPath::Init(path->PathId, context.SS).Parent(); ++parentPath->DirAlterVersion; @@ -240,6 +240,7 @@ class TAlterLocalIndex: public TSubOperation { auto guard = context.DbGuard(); context.MemChanges.GrabPath(context.SS, indexPath.Base()->PathId); context.MemChanges.GrabNewTxState(context.SS, OperationId); + context.MemChanges.GrabIndex(context.SS, indexPath.Base()->PathId); context.DbChanges.PersistPath(indexPath.Base()->PathId); context.DbChanges.PersistAlterIndex(indexPath.Base()->PathId); diff --git a/ydb/core/tx/schemeshard/olap/operations/alter_store.cpp b/ydb/core/tx/schemeshard/olap/operations/alter_store.cpp index 5b69dc2a8e124..e260d33f6c610 100644 --- a/ydb/core/tx/schemeshard/olap/operations/alter_store.cpp +++ b/ydb/core/tx/schemeshard/olap/operations/alter_store.cpp @@ -215,7 +215,7 @@ class TPropose: public TSubOperationState { alterData->AlterBody.Clear(); alterData->ColumnTables = storeInfo->ColumnTables; alterData->ColumnTablesUnderOperation = storeInfo->ColumnTablesUnderOperation; - context.SS->OlapStores.SetUntracked(pathId, alterData); + context.SS->OlapStores.Set(pathId, alterData); context.SS->PersistOlapStoreAlterRemove(db, pathId); context.SS->PersistOlapStore(db, pathId, *alterData); @@ -514,7 +514,7 @@ class TAlterOlapStore: public TSubOperation { } Y_ABORT_UNLESS(context.SS->OlapStores.contains(path->PathId)); - auto storeInfo = context.SS->OlapStores.UpdateUntracked(path->PathId); + auto storeInfo = context.SS->OlapStores.Update(path->PathId); if (!storeInfo->ColumnTablesUnderOperation.empty()) { result->SetError(NKikimrScheme::StatusMultipleModifications, "Store has unfinished table operations"); diff --git a/ydb/core/tx/schemeshard/olap/operations/create_local_index.cpp b/ydb/core/tx/schemeshard/olap/operations/create_local_index.cpp index caa2d3a34b257..c28d02f4941eb 100644 --- a/ydb/core/tx/schemeshard/olap/operations/create_local_index.cpp +++ b/ydb/core/tx/schemeshard/olap/operations/create_local_index.cpp @@ -50,7 +50,7 @@ class TPropose: public TSubOperationState { auto indexData = context.SS->Indexes.at(path->PathId); Y_ABORT_UNLESS(indexData->AlterData, "AlterData must be valid after TTableIndexInfo::Create"); context.SS->PersistTableIndex(db, path->PathId); - context.SS->Indexes.SetUntracked(path->PathId, indexData->AlterData); + context.SS->Indexes.Set(path->PathId, indexData->AlterData); context.SS->ClearDescribePathCaches(path); context.OnComplete.PublishToSchemeBoard(OperationId, path->PathId); @@ -230,7 +230,8 @@ class TCreateLocalIndex: public TSubOperation { newIndexPath->LastTxId = OperationId.GetTxId(); newIndexPath->PathType = TPathElement::EPathType::EPathTypeTableIndex; - context.SS->Indexes.Set({.Path = newIndexPath->PathId, .Value = newIndexData, .Changes = context.MemChanges}); + context.MemChanges.GrabNewIndex(context.SS, newIndexPath->PathId); + context.SS->Indexes.Set(newIndexPath->PathId, newIndexData); context.OnComplete.ActivateTx(OperationId); diff --git a/ydb/core/tx/schemeshard/olap/operations/create_store.cpp b/ydb/core/tx/schemeshard/olap/operations/create_store.cpp index 0d73a688774fa..a445cc1d9dba1 100644 --- a/ydb/core/tx/schemeshard/olap/operations/create_store.cpp +++ b/ydb/core/tx/schemeshard/olap/operations/create_store.cpp @@ -164,7 +164,7 @@ class TPropose: public TSubOperationState { Y_ABORT_UNLESS(pending); TOlapStoreInfo::TPtr store = pending->AlterData; Y_ABORT_UNLESS(store); - context.SS->OlapStores.SetUntracked(pathId, store); + context.SS->OlapStores.Set(pathId, store); context.SS->PersistOlapStoreAlterRemove(db, pathId); context.SS->PersistOlapStore(db, pathId, *store); @@ -464,7 +464,8 @@ class TCreateOlapStore: public TSubOperation { TOlapStoreInfo::TPtr pending = std::make_shared(); pending->AlterData = storeInfo; - context.SS->OlapStores.Set({.Path = pathId, .Value = pending, .Changes = context.MemChanges}); + context.MemChanges.GrabNewOlapStore(context.SS, pathId); + context.SS->OlapStores.Set(pathId, pending); context.SS->PersistOlapStore(db, pathId, *pending); context.SS->PersistOlapStoreAlter(db, pathId, *storeInfo); diff --git a/ydb/core/tx/schemeshard/olap/operations/create_table.cpp b/ydb/core/tx/schemeshard/olap/operations/create_table.cpp index 20da88bea065a..6d00149e8859b 100644 --- a/ydb/core/tx/schemeshard/olap/operations/create_table.cpp +++ b/ydb/core/tx/schemeshard/olap/operations/create_table.cpp @@ -618,7 +618,7 @@ class TCreateColumnTable: public TSubOperation { } if (auto olapStorePath = parentPath.FindOlapStore()) { - storeInfo = context.SS->OlapStores.UpdateUntracked(olapStorePath->PathId); + storeInfo = context.SS->OlapStores.Update(olapStorePath->PathId); Y_ABORT_UNLESS(storeInfo, "Unexpected failure to find an tablestore info"); NSchemeShard::TPath::TChecker storeChecks = olapStorePath.Check(); diff --git a/ydb/core/tx/schemeshard/olap/operations/drop_table.cpp b/ydb/core/tx/schemeshard/olap/operations/drop_table.cpp index a5e7718c84d01..491f41f86d7b7 100644 --- a/ydb/core/tx/schemeshard/olap/operations/drop_table.cpp +++ b/ydb/core/tx/schemeshard/olap/operations/drop_table.cpp @@ -517,7 +517,7 @@ class TDropColumnTable: public TSubOperation { } Y_ABORT_UNLESS(context.SS->OlapStores.contains(storePathId)); - auto& storeInfo = context.SS->OlapStores.UpdateUntracked(storePathId); + auto& storeInfo = context.SS->OlapStores.Update(storePathId); Y_ABORT_UNLESS(storeInfo->ColumnTables.contains(path->PathId)); storeInfo->ColumnTablesUnderOperation.insert(path->PathId); diff --git a/ydb/core/tx/schemeshard/olap/operations/move_local_index.cpp b/ydb/core/tx/schemeshard/olap/operations/move_local_index.cpp index f975225a9a3aa..526d63adacd6a 100644 --- a/ydb/core/tx/schemeshard/olap/operations/move_local_index.cpp +++ b/ydb/core/tx/schemeshard/olap/operations/move_local_index.cpp @@ -96,7 +96,7 @@ class TPropose: public TSubOperationState { auto indexData = context.SS->Indexes.at(dstPathId); Y_ABORT_UNLESS(indexData->AlterData, "AlterData must be valid after TTableIndexInfo::Create"); context.SS->PersistTableIndex(db, dstPathId); - context.SS->Indexes.SetUntracked(dstPathId, indexData->AlterData); + context.SS->Indexes.Set(dstPathId, indexData->AlterData); } // Drop the source index path (stored in SourcePathId) @@ -354,7 +354,8 @@ class TMoveLocalIndex: public TSubOperation { srcPath.Base()->DropTxId = OperationId.GetTxId(); srcPath.Base()->LastTxId = OperationId.GetTxId(); - context.SS->Indexes.Set({.Path = newIndexPath->PathId, .Value = newIndexData, .Changes = context.MemChanges}); + context.MemChanges.GrabNewIndex(context.SS, newIndexPath->PathId); + context.SS->Indexes.Set(newIndexPath->PathId, newIndexData); context.OnComplete.ActivateTx(OperationId); diff --git a/ydb/core/tx/schemeshard/schemeshard__conditional_erase.cpp b/ydb/core/tx/schemeshard/schemeshard__conditional_erase.cpp index 3f674c360dcb0..e97b543bb28f0 100644 --- a/ydb/core/tx/schemeshard/schemeshard__conditional_erase.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__conditional_erase.cpp @@ -267,7 +267,7 @@ struct TSchemeShard::TTxRunConditionalErase: public TSchemeShard::TRwTxBase { auto mainPath = Self->PathsById.at(mainPathId); Y_ABORT_UNLESS(Self->Tables.contains(mainPathId)); - auto mainTable = Self->Tables.UpdateUntracked(mainPathId); + auto mainTable = Self->Tables.Update(mainPathId); for (const auto& [_, childPathId] : mainPath->GetChildren()) { Y_ABORT_UNLESS(Self->PathsById.contains(childPathId)); @@ -297,7 +297,7 @@ struct TSchemeShard::TTxRunConditionalErase: public TSchemeShard::TRwTxBase { TTableIndexInfo::TPtr GetIndex(TPathElement::TPtr indexPath) const { Y_ABORT_UNLESS(Self->Indexes.contains(indexPath->PathId)); - return Self->Indexes.UpdateUntracked(indexPath->PathId); + return Self->Indexes.Update(indexPath->PathId); } std::pair GetIndexImplTable(TPathElement::TPtr indexPath) const { @@ -309,7 +309,7 @@ struct TSchemeShard::TTxRunConditionalErase: public TSchemeShard::TRwTxBase { Y_ABORT_UNLESS(!childPath->Dropped()); Y_ABORT_UNLESS(Self->Tables.contains(indexImplPathId)); - return std::make_pair(indexImplPathId, Self->Tables.UpdateUntracked(indexImplPathId)); + return std::make_pair(indexImplPathId, Self->Tables.Update(indexImplPathId)); } Y_ABORT("Unreachable"); diff --git a/ydb/core/tx/schemeshard/schemeshard__init.cpp b/ydb/core/tx/schemeshard/schemeshard__init.cpp index 4d59354482231..c3d02dc7ca89c 100644 --- a/ydb/core/tx/schemeshard/schemeshard__init.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__init.cpp @@ -1637,7 +1637,7 @@ struct TSchemeShard::TTxInit : public TTransactionBase { rootDomainInfo->InitializeAsGlobal(Self->CreateRootProcessingParams(ctx)); - Self->SubDomains.SetUntracked(Self->RootPathId(), rootDomainInfo); + Self->SubDomains.Set(Self->RootPathId(), rootDomainInfo); } auto rowset = db.Table().Range().Select(); @@ -1666,7 +1666,7 @@ struct TSchemeShard::TTxInit : public TTransactionBase { planResolution, timeCastBuckets, resourcesDomainId); - Self->SubDomains.SetUntracked(pathId, domainInfo); + Self->SubDomains.Set(pathId, domainInfo); TTabletId sharedHiveId = rowset.GetValue(); domainInfo->SetSharedHive(sharedHiveId); @@ -1749,7 +1749,7 @@ struct TSchemeShard::TTxInit : public TTransactionBase { Y_VERIFY_S(path->IsDomainRoot(), "Path is not a subdomain, pathId: " << pathId); Y_ABORT_UNLESS(Self->SubDomains.contains(pathId)); - auto& subdomainInfo = Self->SubDomains.UpdateUntracked(pathId); + auto& subdomainInfo = Self->SubDomains.Update(pathId); Y_ABORT_UNLESS(!subdomainInfo->GetAlter()); TSubDomainInfo::TPtr alter; @@ -1851,7 +1851,7 @@ struct TSchemeShard::TTxInit : public TTransactionBase { TShardIdx shardIdx = Self->MakeLocalId(localShardIdx); Y_ABORT_UNLESS(Self->SubDomains.contains(pathId)); - Self->SubDomains.UpdateUntracked(pathId)->AddPrivateShard(shardIdx); + Self->SubDomains.Update(pathId)->AddPrivateShard(shardIdx); if (!rowset.Next()) return false; @@ -1870,7 +1870,7 @@ struct TSchemeShard::TTxInit : public TTransactionBase { TShardIdx shardIdx = Self->MakeLocalId(localShardIdx); Y_ABORT_UNLESS(Self->SubDomains.contains(pathId)); - auto& subdomainInfo = Self->SubDomains.UpdateUntracked(pathId); + auto& subdomainInfo = Self->SubDomains.Update(pathId); Y_ABORT_UNLESS(subdomainInfo->GetAlter()); subdomainInfo->GetAlter()->AddPrivateShard(shardIdx); @@ -1896,7 +1896,7 @@ struct TSchemeShard::TTxInit : public TTransactionBase { quota.Available = rowset.GetValue(); quota.LastUpdate = TInstant::MicroSeconds(rowset.GetValue()); quota.Dirty = false; - Self->SubDomains.UpdateUntracked(pathId)->AddSchemeQuota(quota); + Self->SubDomains.Update(pathId)->AddSchemeQuota(quota); } if (!rowset.Next()) @@ -2014,7 +2014,7 @@ struct TSchemeShard::TTxInit : public TTransactionBase { tableInfo->IsBackup = std::get<8>(rec); tableInfo->IsRestore = std::get<13>(rec); - Self->Tables.SetUntracked(pathId, tableInfo); + Self->Tables.Set(pathId, tableInfo); if (tableInfo->IsTTLEnabled()) { Self->TTLEnabledTables[pathId] = tableInfo; Self->TabletCounters->Simple()[COUNTER_TTL_ENABLED_TABLE_COUNT].Add(1); @@ -2046,7 +2046,7 @@ struct TSchemeShard::TTxInit : public TTransactionBase { TLocalPathId localPathId = rowset.GetValue(); TPathId pathId(ownerPathId, localPathId); - auto& externalTable = Self->ExternalTables.SetUntracked(pathId, new TExternalTableInfo()); + auto& externalTable = Self->ExternalTables.Set(pathId, new TExternalTableInfo()); externalTable->SourceType = rowset.GetValue(); externalTable->DataSourcePath = rowset.GetValue(); externalTable->Location = rowset.GetValue(); @@ -2069,7 +2069,7 @@ struct TSchemeShard::TTxInit : public TTransactionBase { TLocalPathId localPathId = rowset.GetValue(); TPathId pathId(ownerPathId, localPathId); - auto& externalDataSource = Self->ExternalDataSources.SetUntracked(pathId, new TExternalDataSourceInfo()); + auto& externalDataSource = Self->ExternalDataSources.Set(pathId, new TExternalDataSourceInfo()); externalDataSource->AlterVersion = rowset.GetValue(); externalDataSource->SourceType = rowset.GetValue(); externalDataSource->Location = rowset.GetValue(); @@ -2094,7 +2094,7 @@ struct TSchemeShard::TTxInit : public TTransactionBase { TLocalPathId localPathId = rowset.GetValue(); TPathId pathId(selfId, localPathId); - auto& view = Self->Views.SetUntracked(pathId, new TViewInfo()); + auto& view = Self->Views.Set(pathId, new TViewInfo()); view->AlterVersion = rowset.GetValue(); view->QueryText = rowset.GetValue(); Y_PROTOBUF_SUPPRESS_NODISCARD view->CapturedContext.ParseFromString( @@ -2118,7 +2118,7 @@ struct TSchemeShard::TTxInit : public TTransactionBase { TLocalPathId localPathId = rowset.GetValue(); TPathId pathId(selfId, localPathId); - auto& sysView = Self->SysViews.SetUntracked(pathId, new TSysViewInfo()); + auto& sysView = Self->SysViews.Set(pathId, new TSysViewInfo()); sysView->AlterVersion = rowset.GetValue(); sysView->Type = rowset.GetValue(); @@ -2140,7 +2140,7 @@ struct TSchemeShard::TTxInit : public TTransactionBase { TLocalPathId localPathId = rowset.GetValue(); TPathId pathId(ownerPathId, localPathId); - auto& resourcePool = Self->ResourcePools.SetUntracked(pathId, new TResourcePoolInfo()); + auto& resourcePool = Self->ResourcePools.Set(pathId, new TResourcePoolInfo()); resourcePool->AlterVersion = rowset.GetValue(); Y_PROTOBUF_SUPPRESS_NODISCARD resourcePool->Properties.ParseFromString(rowset.GetValue()); @@ -2162,7 +2162,7 @@ struct TSchemeShard::TTxInit : public TTransactionBase { TLocalPathId localPathId = rowset.GetValue(); TPathId pathId(ownerPathId, localPathId); - auto& backupCollection = Self->BackupCollections.SetUntracked(pathId, new TBackupCollectionInfo()); + auto& backupCollection = Self->BackupCollections.Set(pathId, new TBackupCollectionInfo()); backupCollection->AlterVersion = rowset.GetValue(); Y_PROTOBUF_SUPPRESS_NODISCARD backupCollection->Description.ParseFromString(rowset.GetValue()); Self->RegisterBackupCollectionTables(backupCollection); @@ -2185,7 +2185,7 @@ struct TSchemeShard::TTxInit : public TTransactionBase { const TLocalPathId localPathId = rowset.GetValue(); const TPathId pathId(ownerPathId, localPathId); - auto& streamingQuery = Self->StreamingQueries.SetUntracked(pathId, new TStreamingQueryInfo()); + auto& streamingQuery = Self->StreamingQueries.Set(pathId, new TStreamingQueryInfo()); streamingQuery->AlterVersion = rowset.GetValue(); Y_PROTOBUF_SUPPRESS_NODISCARD streamingQuery->Properties.ParseFromString(rowset.GetValue()); @@ -2299,7 +2299,7 @@ struct TSchemeShard::TTxInit : public TTransactionBase { Y_VERIFY_S(Self->Tables.FindPtr(pathId), "Table doesn't exist, pathId: " << pathId); - auto& tableInfo = Self->Tables.UpdateUntracked(pathId); + auto& tableInfo = Self->Tables.Update(pathId); tableInfo->InitAlterData(); if (colId >= tableInfo->AlterData->NextColumnId) { tableInfo->AlterData->NextColumnId = colId + 1; // calc next NextColumnId @@ -2463,7 +2463,7 @@ struct TSchemeShard::TTxInit : public TTransactionBase { if (prevTableId) { Y_ABORT_UNLESS(!partitions.empty()); Y_ABORT_UNLESS(Self->Tables.contains(prevTableId)); - auto tableInfo = Self->Tables.UpdateUntracked(prevTableId); + auto tableInfo = Self->Tables.Update(prevTableId); Self->SetPartitioning(prevTableId, tableInfo, std::move(partitions)); partitions.clear(); Self->TabletCounters->Simple()[COUNTER_FORMAT_POSITION_TABLE_COUNT].Add(1); @@ -2497,7 +2497,7 @@ struct TSchemeShard::TTxInit : public TTransactionBase { if (prevTableId) { Y_ABORT_UNLESS(!partitions.empty()); Y_ABORT_UNLESS(Self->Tables.contains(prevTableId)); - auto tableInfo = Self->Tables.UpdateUntracked(prevTableId); + auto tableInfo = Self->Tables.Update(prevTableId); Self->SetPartitioning(prevTableId, tableInfo, std::move(partitions)); partitions.clear(); Self->TabletCounters->Simple()[COUNTER_FORMAT_POSITION_TABLE_COUNT].Add(1); @@ -2520,7 +2520,7 @@ struct TSchemeShard::TTxInit : public TTransactionBase { } Y_ABORT_UNLESS(!partitions.empty(), "tablePathId %s", ToString(tablePathId).c_str()); Y_ABORT_UNLESS(Self->Tables.contains(tablePathId), "tablePathId %s", ToString(tablePathId).c_str()); - auto tableInfo = Self->Tables.UpdateUntracked(tablePathId); + auto tableInfo = Self->Tables.Update(tablePathId); Y_ABORT_UNLESS(!tableInfo->Columns.empty(), "tablePathId %s", ToString(tablePathId).c_str()); // tables must not have mixed format partitions Y_ABORT_UNLESS(tableInfo->GetPartitions().empty(), "tablePathId %s", ToString(tablePathId).c_str()); @@ -2661,7 +2661,7 @@ struct TSchemeShard::TTxInit : public TTransactionBase { } Y_ABORT_UNLESS(Self->Tables.contains(tableId)); - auto& tableInfo = Self->Tables.UpdateUntracked(tableId); + auto& tableInfo = Self->Tables.Update(tableId); const ui64 partitionId = rowSet.GetValue(); Y_ABORT_UNLESS(partitionId < tableInfo->GetPartitions().size()); @@ -2794,7 +2794,7 @@ struct TSchemeShard::TTxInit : public TTransactionBase { } continue; } - auto& tableInfo = Self->Tables.UpdateUntracked(tableId); + auto& tableInfo = Self->Tables.Update(tableId); if (!tableInfo->GetPartitionStore().contains(shardIdx)) { if (!rowSet.Next()) { return false; @@ -2918,7 +2918,7 @@ struct TSchemeShard::TTxInit : public TTransactionBase { const bool ok = pqGroup->FillKeySchema(pqGroup->TabletConfig); Y_ABORT_UNLESS(ok); - Self->Topics.SetUntracked(pathId, pqGroup); + Self->Topics.Set(pathId, pqGroup); auto it = pqBalancers.find(pathId); if (it != pqBalancers.end()) { @@ -3097,7 +3097,7 @@ struct TSchemeShard::TTxInit : public TTransactionBase { TLocalPathId localPathId = rowset.GetValue(); TPathId pathId(selfId, localPathId); - Self->RtmrVolumes.SetUntracked(pathId, new TRtmrVolumeInfo()); + Self->RtmrVolumes.Set(pathId, new TRtmrVolumeInfo()); if (!rowset.Next()) return false; @@ -3151,7 +3151,7 @@ struct TSchemeShard::TTxInit : public TTransactionBase { TSolomonVolumeInfo::TPtr solomon = new TSolomonVolumeInfo(version); solomon->Version = version; - Self->SolomonVolumes.SetUntracked(pathId, solomon); + Self->SolomonVolumes.Set(pathId, solomon); if (!rowset.Next()) return false; @@ -3201,7 +3201,7 @@ struct TSchemeShard::TTxInit : public TTransactionBase { ui64 version = rowset.GetValue(); Y_ABORT_UNLESS(Self->SolomonVolumes.contains(pathId)); - auto& solomon = Self->SolomonVolumes.UpdateUntracked(pathId); + auto& solomon = Self->SolomonVolumes.Update(pathId); Y_ABORT_UNLESS(solomon->AlterData == nullptr); solomon->AlterData = solomon->CreateAlter(version); @@ -3227,7 +3227,7 @@ struct TSchemeShard::TTxInit : public TTransactionBase { const ui64 partitionId = rowset.GetValue(); Y_ABORT_UNLESS(Self->SolomonVolumes.contains(pathId)); - auto& solomon = Self->SolomonVolumes.UpdateUntracked(pathId); + auto& solomon = Self->SolomonVolumes.Update(pathId); Y_ABORT_UNLESS(solomon->AlterData); if (solomon->Partitions.size() <= partitionId) { @@ -3280,7 +3280,7 @@ struct TSchemeShard::TTxInit : public TTransactionBase { << ", path type: " << NKikimrSchemeOp::EPathType_Name(path->PathType)); Y_ABORT_UNLESS(!Self->Indexes.contains(pathId)); - Self->Indexes.SetUntracked(pathId, new TTableIndexInfo(alterVersion, indexType, state, description)); + Self->Indexes.Set(pathId, new TTableIndexInfo(alterVersion, indexType, state, description)); } else { migratedAlteredIndexes.emplace_back(pathId, alterVersion); } @@ -3296,7 +3296,7 @@ struct TSchemeShard::TTxInit : public TTransactionBase { db.Table().Key(migratedIndexPathId.OwnerId, migratedIndexPathId.LocalPathId).Update( NIceDb::TUpdate(alterVersion) ); - Self->Indexes.UpdateUntracked(migratedIndexPathId)->AlterVersion = alterVersion; + Self->Indexes.Update(migratedIndexPathId)->AlterVersion = alterVersion; // remove record from Schema::TableIndex db.Table().Key(pathId.LocalPathId).Delete(); } @@ -3323,9 +3323,9 @@ struct TSchemeShard::TTxInit : public TTransactionBase { Y_VERIFY_S(path->IsTableIndex(), "Path is not a table index, pathId: " << pathId); if (!Self->Indexes.contains(pathId)) { - Self->Indexes.SetUntracked(pathId, TTableIndexInfo::NotExistedYet(indexType)); + Self->Indexes.Set(pathId, TTableIndexInfo::NotExistedYet(indexType)); } - auto& tableIndex = Self->Indexes.UpdateUntracked(pathId); + auto& tableIndex = Self->Indexes.Update(pathId); Y_ABORT_UNLESS(tableIndex->AlterData == nullptr); Y_ABORT_UNLESS(tableIndex->AlterVersion < alterVersion); tableIndex->AlterData = new TTableIndexInfo(alterVersion, indexType, state, description); @@ -3373,7 +3373,7 @@ struct TSchemeShard::TTxInit : public TTransactionBase { Y_VERIFY_S(path->IsTableIndex(), "Path is not a table index, pathId: " << pathId); Y_ABORT_UNLESS(Self->Indexes.contains(pathId)); - auto& tableIndex = Self->Indexes.UpdateUntracked(pathId); + auto& tableIndex = Self->Indexes.Update(pathId); Y_ABORT_UNLESS(keyId == tableIndex->IndexKeys.size()); tableIndex->IndexKeys.emplace_back(keyName); @@ -3391,7 +3391,7 @@ struct TSchemeShard::TTxInit : public TTransactionBase { Y_VERIFY_S(path->IsTableIndex(), "Path is not a table index, pathId: " << pathId); if (Self->Indexes.contains(pathId)) { - auto& tableIndex = Self->Indexes.UpdateUntracked(pathId); + auto& tableIndex = Self->Indexes.Update(pathId); Y_ABORT_UNLESS(dataId == tableIndex->IndexDataColumns.size()); tableIndex->IndexDataColumns.emplace_back(dataName); @@ -3426,7 +3426,7 @@ struct TSchemeShard::TTxInit : public TTransactionBase { Y_VERIFY_S(path->IsTableIndex(), "Path is not a table index, pathId: " << pathId); Y_ABORT_UNLESS(Self->Indexes.contains(pathId)); - auto& tableIndex = Self->Indexes.UpdateUntracked(pathId); + auto& tableIndex = Self->Indexes.Update(pathId); Y_ABORT_UNLESS(tableIndex->AlterData != nullptr); auto alterData = tableIndex->AlterData; @@ -3460,7 +3460,7 @@ struct TSchemeShard::TTxInit : public TTransactionBase { Y_VERIFY_S(path->IsTableIndex(), "Path is not a table index, pathId: " << pathId); if (Self->Indexes.contains(pathId)) { - auto& tableIndex = Self->Indexes.UpdateUntracked(pathId); + auto& tableIndex = Self->Indexes.Update(pathId); Y_ABORT_UNLESS(tableIndex->AlterData != nullptr); auto alterData = tableIndex->AlterData; @@ -3516,7 +3516,7 @@ struct TSchemeShard::TTxInit : public TTransactionBase { << ", path type: " << NKikimrSchemeOp::EPathType_Name(path->PathType)); Y_ABORT_UNLESS(!Self->CdcStreams.contains(pathId)); - const auto& stream = Self->CdcStreams.SetUntracked(pathId, new TCdcStreamInfo(alterVersion, std::move(settings))); + const auto& stream = Self->CdcStreams.Set(pathId, new TCdcStreamInfo(alterVersion, std::move(settings))); if (stream->State == NKikimrSchemeOp::ECdcStreamStateScan) { Y_VERIFY_S(Self->PathsById.contains(path->ParentPathId), "Parent path is not found" @@ -3564,10 +3564,10 @@ struct TSchemeShard::TTxInit : public TTransactionBase { if (!Self->CdcStreams.contains(pathId)) { Y_ABORT_UNLESS(alterVersion == 1); - Self->CdcStreams.SetUntracked(pathId, TCdcStreamInfo::New(settings)); + Self->CdcStreams.Set(pathId, TCdcStreamInfo::New(settings)); } - auto& stream = Self->CdcStreams.UpdateUntracked(pathId); + auto& stream = Self->CdcStreams.Update(pathId); Y_ABORT_UNLESS(stream->AlterData == nullptr); Y_ABORT_UNLESS(stream->AlterVersion < alterVersion); stream->AlterData = new TCdcStreamInfo(alterVersion, std::move(settings)); @@ -3611,7 +3611,7 @@ struct TSchemeShard::TTxInit : public TTransactionBase { Y_VERIFY_S(Self->CdcStreams.contains(pathId), "Cdc stream not found" << ": pathId# " << pathId); - auto& stream = Self->CdcStreams.UpdateUntracked(pathId); + auto& stream = Self->CdcStreams.Update(pathId); stream->ScanShards.emplace(shardIdx, status); if (status != NKikimrTxDataShard::TEvCdcStreamScanResponse::DONE) { @@ -3639,7 +3639,7 @@ struct TSchemeShard::TTxInit : public TTransactionBase { TString kind = rowset.GetValue(); Y_ABORT_UNLESS(Self->SubDomains.contains(pathId)); - Self->SubDomains.UpdateUntracked(pathId)->AddStoragePool(TStoragePool(name, kind)); + Self->SubDomains.Update(pathId)->AddStoragePool(TStoragePool(name, kind)); if (!rowset.Next()) return false; @@ -3659,7 +3659,7 @@ struct TSchemeShard::TTxInit : public TTransactionBase { TString kind = rowset.GetValue(); Y_ABORT_UNLESS(Self->SubDomains.contains(pathId)); - auto& subdomainInfo = Self->SubDomains.UpdateUntracked(pathId); + auto& subdomainInfo = Self->SubDomains.Update(pathId); Y_ABORT_UNLESS(subdomainInfo->GetAlter()); subdomainInfo->GetAlter()->AddStoragePool(TStoragePool(name, kind)); @@ -3689,7 +3689,7 @@ struct TSchemeShard::TTxInit : public TTransactionBase { } if (!Self->IsDomainSchemeShard && Self->SubDomains.contains(Self->RootPathId())) { - Self->SubDomains.UpdateUntracked(Self->RootPathId())->Initialize(Self->ShardInfos); + Self->SubDomains.Update(Self->RootPathId())->Initialize(Self->ShardInfos); } } @@ -3712,7 +3712,7 @@ struct TSchemeShard::TTxInit : public TTransactionBase { volume->AlterVersion = rowset.GetValue(); volume->MountToken = rowset.GetValue(); volume->TokenVersion = rowset.GetValue(); - Self->BlockStoreVolumes.SetUntracked(pathId, volume); + Self->BlockStoreVolumes.Set(pathId, volume); auto it = nbsVolumeShards.find(pathId); if (it != nbsVolumeShards.end()) { @@ -3808,7 +3808,7 @@ struct TSchemeShard::TTxInit : public TTransactionBase { Y_ABORT_UNLESS(parseOk); fs->Version = rowset.GetValueOrDefault(); } - Self->FileStoreInfos.SetUntracked(pathId, fs); + Self->FileStoreInfos.Set(pathId, fs); auto it = fileStoreShards.find(pathId); if (it != fileStoreShards.end()) { @@ -3875,7 +3875,7 @@ struct TSchemeShard::TTxInit : public TTransactionBase { Y_ABORT_UNLESS(parseOk); kesus->Version = version; } - Self->KesusInfos.SetUntracked(pathId, kesus); + Self->KesusInfos.Set(pathId, kesus); auto it = kesusShards.find(pathId); if (it != kesusShards.end()) { @@ -4046,7 +4046,7 @@ struct TSchemeShard::TTxInit : public TTransactionBase { // legacy, ??? Y_ABORT_UNLESS(Self->Tables.contains(tablePathId)); - TTableInfo::TPtr tableInfo = Self->Tables.UpdateUntracked(tablePathId); + TTableInfo::TPtr tableInfo = Self->Tables.Update(tablePathId); tableInfo->InitAlterData(); tableInfo->DeserializeAlterExtraData(extraData); } @@ -4186,8 +4186,8 @@ struct TSchemeShard::TTxInit : public TTransactionBase { TOlapStoreInfo::TPtr storeInfo = std::make_shared(alterVersion, std::move(sharding)); storeInfo->ParseFromLocalDB(description); - Self->OlapStores.SetUntracked(pathId, storeInfo); - Self->SetPartitioning(pathId, Self->OlapStores.UpdateUntracked(pathId)); + Self->OlapStores.Set(pathId, storeInfo); + Self->SetPartitioning(pathId, Self->OlapStores.Update(pathId)); if (!rowset.Next()) { return false; @@ -4219,7 +4219,7 @@ struct TSchemeShard::TTxInit : public TTransactionBase { TOlapStoreInfo::TPtr storeInfo = std::make_shared(alterVersion, std::move(sharding), std::move(alterBody)); storeInfo->ParseFromLocalDB(description); - Self->OlapStores.UpdateUntracked(pathId)->AlterData = storeInfo; + Self->OlapStores.Update(pathId)->AlterData = storeInfo; if (!rowset.Next()) { return false; @@ -4425,7 +4425,7 @@ struct TSchemeShard::TTxInit : public TTransactionBase { Y_ABORT_UNLESS(txState->SplitDescription); Y_ABORT_UNLESS(Self->Tables.contains(txState->TargetPathId)); - TTableInfo::TPtr tableInfo = Self->Tables.UpdateUntracked(txState->TargetPathId); + TTableInfo::TPtr tableInfo = Self->Tables.Update(txState->TargetPathId); tableInfo->RegisterSplitMergeOp(opId, *txState); for (ui32 i = 0; i < txState->SplitDescription->DestinationRangesSize(); ++i) { @@ -5831,7 +5831,7 @@ struct TSchemeShard::TTxInit : public TTransactionBase { Y_ABORT_UNLESS(sharding.ParseFromString(rowset.GetValue())); TSequenceInfo::TPtr sequenceInfo = new TSequenceInfo(alterVersion, std::move(description), std::move(sharding)); - Self->Sequences.SetUntracked(pathId, sequenceInfo); + Self->Sequences.Set(pathId, sequenceInfo); if (!rowset.Next()) { return false; @@ -5857,7 +5857,7 @@ struct TSchemeShard::TTxInit : public TTransactionBase { TSequenceInfo::TPtr alterData = new TSequenceInfo(alterVersion, std::move(description), std::move(sharding)); Y_VERIFY_S(Self->Sequences.contains(pathId), "Cannot load alter for sequence " << pathId); - Self->Sequences.UpdateUntracked(pathId)->AlterData = alterData; + Self->Sequences.Update(pathId)->AlterData = alterData; if (!rowset.Next()) { return false; @@ -5879,7 +5879,7 @@ struct TSchemeShard::TTxInit : public TTransactionBase { Y_ABORT_UNLESS(description.ParseFromString(rowset.GetValue())); TReplicationInfo::TPtr replicationInfo = new TReplicationInfo(alterVersion, std::move(description)); - Self->Replications.SetUntracked(pathId, replicationInfo); + Self->Replications.Set(pathId, replicationInfo); if (replicationControllers.contains(pathId)) { replicationInfo->ControllerShardIdx = replicationControllers.at(pathId); @@ -5907,7 +5907,7 @@ struct TSchemeShard::TTxInit : public TTransactionBase { TReplicationInfo::TPtr alterData = new TReplicationInfo(alterVersion, std::move(description)); Y_VERIFY_S(Self->Replications.contains(pathId), "Cannot load alter for replication " << pathId); - auto& replicationInfo = Self->Replications.UpdateUntracked(pathId); + auto& replicationInfo = Self->Replications.Update(pathId); alterData->ControllerShardIdx = replicationInfo->ControllerShardIdx; replicationInfo->AlterData = alterData; @@ -5935,7 +5935,7 @@ struct TSchemeShard::TTxInit : public TTransactionBase { Y_ABORT_UNLESS(success); auto blobDepot = MakeIntrusive(alterVersion, description); - Self->BlobDepots.SetUntracked(pathId, blobDepot); + Self->BlobDepots.Set(pathId, blobDepot); if (const auto it = blobDepotShards.find(pathId); it != blobDepotShards.end()) { blobDepot->BlobDepotShardIdx = it->second; @@ -5989,7 +5989,7 @@ struct TSchemeShard::TTxInit : public TTransactionBase { Y_PROTOBUF_SUPPRESS_NODISCARD testShardSetInfo->CmdInitialize.ParseFromString(serializedCmdInitialize); } - Self->TestShardSets.SetUntracked(pathId, testShardSetInfo); + Self->TestShardSets.Set(pathId, testShardSetInfo); Self->TabletCounters->Simple()[COUNTER_TEST_SHARD_SET_COUNT].Add(1); if (!rowset.Next()) { @@ -6441,7 +6441,7 @@ struct TSchemeShard::TTxInit : public TTransactionBase { Y_ABORT_UNLESS(description.ParseFromString(rowset.GetValue())); TSecretInfo::TPtr secretInfo = new TSecretInfo(version, std::move(description)); - Self->Secrets.SetUntracked(pathId, secretInfo); + Self->Secrets.Set(pathId, secretInfo); if (!rowset.Next()) { return false; @@ -6465,7 +6465,7 @@ struct TSchemeShard::TTxInit : public TTransactionBase { TSecretInfo::TPtr alterData = new TSecretInfo(version, std::move(description)); Y_VERIFY_S(Self->Secrets.contains(pathId), "Cannot load alter for secret " << pathId); - auto& secretInfo = Self->Secrets.UpdateUntracked(pathId); + auto& secretInfo = Self->Secrets.Update(pathId); secretInfo->AlterData = alterData; if (!rowset.Next()) { diff --git a/ydb/core/tx/schemeshard/schemeshard__init_root.cpp b/ydb/core/tx/schemeshard/schemeshard__init_root.cpp index 989763249e1c6..8b47fedcb42bc 100644 --- a/ydb/core/tx/schemeshard/schemeshard__init_root.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__init_root.cpp @@ -121,7 +121,7 @@ struct TSchemeShard::TTxInitRoot : public TSchemeShard::TRwTxBase { TSubDomainInfo::TPtr newDomain = new TSubDomainInfo(0, Self->RootPathId()); newDomain->InitializeAsGlobal(Self->CreateRootProcessingParams(ctx)); - Self->SubDomains.SetUntracked(Self->RootPathId(), newDomain); + Self->SubDomains.Set(Self->RootPathId(), newDomain); NACLib::TDiffACL diffAcl; for (const auto& defaultAccess : securityConfig.GetDefaultAccess()) { @@ -453,7 +453,7 @@ struct TSchemeShard::TTxInitTenantSchemeShard : public TSchemeShard::TRwTxBase { Self->PersistUpdateNextPathId(db); Self->PersistUpdateNextShardIdx(db); - Self->SubDomains.SetUntracked(Self->RootPathId(), subdomain); + Self->SubDomains.Set(Self->RootPathId(), subdomain); Self->InitState = initiateMigration ? TTenantInitState::Inprogress : TTenantInitState::Done; Self->PersistInitState(db); 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 f77adf52e77c8..242ed5049da64 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_alter_cdc_stream.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_alter_cdc_stream.cpp @@ -60,7 +60,7 @@ class TPropose: public TSubOperationState { NIceDb::TNiceDb db(context.GetDB()); context.SS->PersistCdcStream(db, pathId); - context.SS->CdcStreams.UpdateUntracked(pathId)->FinishAlter(); + context.SS->CdcStreams.Update(pathId)->FinishAlter(); context.SS->ClearDescribePathCaches(path); context.OnComplete.PublishToSchemeBoard(OperationId, pathId); @@ -161,6 +161,7 @@ class TAlterCdcStream: public TSubOperation { } Y_ABORT_UNLESS(context.SS->CdcStreams.contains(streamPath.Base()->PathId)); + context.MemChanges.GrabCdcStream(context.SS, streamPath.Base()->PathId); auto stream = context.SS->CdcStreams.Update(streamPath.Base()->PathId); TCdcStreamInfo::EState requiredState = TCdcStreamInfo::EState::ECdcStreamStateInvalid; @@ -201,9 +202,6 @@ class TAlterCdcStream: public TSubOperation { context.DbChanges.PersistAlterCdcStream(streamPath.Base()->PathId); context.DbChanges.PersistTxState(OperationId); - context.MemChanges.RecordUndo([stream, previous = stream->AlterData]() { - stream->AlterData = previous; - }); auto streamAlter = stream->CreateNextVersion(); Y_ABORT_UNLESS(streamAlter); streamAlter->State = newState; @@ -243,7 +241,7 @@ class TConfigurePartsAtTable: public NCdcStreamState::TConfigurePartsAtTable { auto path = context.SS->PathsById.at(pathId); Y_ABORT_UNLESS(context.SS->Tables.contains(pathId)); - auto& table = context.SS->Tables.UpdateUntracked(pathId); + auto& table = context.SS->Tables.Update(pathId); auto& notice = *tx.MutableAlterCdcStreamNotice(); pathId.ToProto(notice.MutablePathId()); diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_alter_external_data_source.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_alter_external_data_source.cpp index 2db57acbd24b2..b0e0b18614bd0 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_alter_external_data_source.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_alter_external_data_source.cpp @@ -226,7 +226,8 @@ class TAlterExternalDataSource : public TSubOperation { context.DbChanges.PersistExternalDataSource(externalDataSource->PathId); context.DbChanges.PersistTxState(OperationId); - context.SS->ExternalDataSources.Set({.Path = externalDataSource->PathId, .Value = externalDataSourceInfo, .Changes = context.MemChanges}); + context.MemChanges.GrabExternalDataSource(context.SS, externalDataSource->PathId); + context.SS->ExternalDataSources.Set(externalDataSource->PathId, externalDataSourceInfo); TTxState& txState = context.SS->CreateTx(OperationId, TTxState::TxAlterExternalDataSource, externalDataSource->PathId); txState.Shards.clear(); diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_alter_external_table.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_alter_external_table.cpp index d595afc26ac61..1360854c74ecb 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_alter_external_table.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_alter_external_table.cpp @@ -317,8 +317,10 @@ class TAlterExternalTable: public TSubOperation { context.MemChanges.GrabPath(context.SS, externalTable->PathId); context.MemChanges.GrabPath(context.SS, parentPath.Base()->PathId); + context.MemChanges.GrabExternalDataSource(context.SS, dataSourcePath.Base()->PathId); if (!IsSameDataSource) { context.MemChanges.GrabPath(context.SS, dataSourcePath.Base()->PathId); + context.MemChanges.GrabExternalDataSource(context.SS, OldDataSourcePathId); } context.MemChanges.GrabNewTxState(context.SS, OperationId); @@ -346,7 +348,8 @@ class TAlterExternalTable: public TSubOperation { } } - context.SS->ExternalTables.Set({.Path = externalTable->PathId, .Value = externalTableInfo, .Changes = context.MemChanges}); + context.MemChanges.GrabExternalTable(context.SS, externalTable->PathId); + context.SS->ExternalTables.Set(externalTable->PathId, externalTableInfo); TTxState& txState = context.SS->CreateTx(OperationId, TTxState::TxAlterExternalTable, externalTable->PathId, dataSourcePath.Base()->PathId); diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_alter_extsubdomain.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_alter_extsubdomain.cpp index 782ae922f896b..ddb59e9177b0c 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_alter_extsubdomain.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_alter_extsubdomain.cpp @@ -503,7 +503,7 @@ class TCreateHive: public TSubOperationState { // so that next stages would get extsubdomain's hive tablet id // by requesting on extsubdomain's path { - auto& subdomain = context.SS->SubDomains.UpdateUntracked(txState->TargetPathId); + auto& subdomain = context.SS->SubDomains.Update(txState->TargetPathId); subdomain->AddPrivateShard(shardIdx); subdomain->AddInternalShard(shardIdx, context.SS); diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_alter_fs.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_alter_fs.cpp index 8bba8ff056264..b020e3d323e11 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_alter_fs.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_alter_fs.cpp @@ -161,7 +161,7 @@ class TPropose: public TSubOperationState { Y_ABORT_UNLESS(txState->TxType == TTxState::TxAlterFileStore); TPathId pathId = txState->TargetPathId; - auto& fs = context.SS->FileStoreInfos.UpdateUntracked(pathId); + auto& fs = context.SS->FileStoreInfos.Update(pathId); Y_VERIFY_S(fs, "FileStore info is null. PathId: " << pathId); TPathElement::TPtr path = context.SS->PathsById.at(pathId); diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_alter_kesus.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_alter_kesus.cpp index 8cb78d92ba09d..04076701a1993 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_alter_kesus.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_alter_kesus.cpp @@ -182,7 +182,7 @@ class TPropose: public TSubOperationState { path->PathState = TPathElement::EPathState::EPathStateNoChanges; - auto& kesus = context.SS->KesusInfos.UpdateUntracked(pathId); + auto& kesus = context.SS->KesusInfos.Update(pathId); kesus->FinishAlter(); context.SS->PersistKesusInfo(db, pathId, kesus); context.SS->PersistRemoveKesusAlter(db, pathId); diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_alter_replication.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_alter_replication.cpp index 80f1fdaa1485a..e147aebb24ead 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_alter_replication.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_alter_replication.cpp @@ -240,7 +240,7 @@ class TPropose: public TSubOperationState { Y_ABORT_UNLESS(alterData); NIceDb::TNiceDb db(context.GetDB()); - context.SS->Replications.SetUntracked(pathId, alterData); + context.SS->Replications.Set(pathId, alterData); context.SS->PersistReplicationAlterRemove(db, pathId); context.SS->PersistReplication(db, pathId, *alterData); diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_alter_resource_pool.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_alter_resource_pool.cpp index 792ededa35d9e..3307c06bc757c 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_alter_resource_pool.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_alter_resource_pool.cpp @@ -161,7 +161,8 @@ class TAlterResourcePool : public TSubOperation { context.DbChanges.PersistResourcePool(resourcePool->PathId); context.DbChanges.PersistTxState(OperationId); - context.SS->ResourcePools.Set({.Path = resourcePool->PathId, .Value = resourcePoolInfo, .Changes = context.MemChanges}); + context.MemChanges.GrabResourcePool(context.SS, resourcePool->PathId); + context.SS->ResourcePools.Set(resourcePool->PathId, resourcePoolInfo); TTxState& txState = context.SS->CreateTx(OperationId, TTxState::TxAlterResourcePool, resourcePool->PathId); txState.Shards.clear(); diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_alter_secret.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_alter_secret.cpp index ecc83158244fa..5faee2ed13050 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_alter_secret.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_alter_secret.cpp @@ -59,7 +59,7 @@ class TPropose: public TSubOperationState { Y_ABORT_UNLESS(secretInfo->Description.GetVersion() + 1 == alterData->Description.GetVersion()); NIceDb::TNiceDb db(context.GetDB()); - context.SS->Secrets.SetUntracked(secretPathId, alterData); + context.SS->Secrets.Set(secretPathId, alterData); context.SS->PersistSecretAlterRemove(db, secretPathId); context.SS->PersistSecret(db, secretPathId, *alterData); @@ -152,6 +152,7 @@ class TAlterSecret: public TSubOperation { } Y_ABORT_UNLESS(context.SS->Secrets.contains(secretPath.Base()->PathId)); + context.MemChanges.GrabSecret(context.SS, secretPath.Base()->PathId); auto secretInfo = context.SS->Secrets.Update(secretPath.Base()->PathId); if (secretInfo->AlterVersion == 0) { @@ -195,9 +196,6 @@ class TAlterSecret: public TSubOperation { } } - context.MemChanges.RecordUndo([secretInfo, previous = secretInfo->AlterData]() { - secretInfo->AlterData = previous; - }); auto alterData = secretInfo->CreateNextVersion(); alterData->Description.SetValue(alterSecretProto.GetValue()); alterData->Description.SetVersion(secretInfo->AlterVersion); diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_alter_sequence.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_alter_sequence.cpp index 0ecae9679d25b..c5af5ccca531f 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_alter_sequence.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_alter_sequence.cpp @@ -198,7 +198,7 @@ class TPropose: public TSubOperationState { NIceDb::TNiceDb db(context.GetDB()); - context.SS->Sequences.SetUntracked(pathId, alterData); + context.SS->Sequences.Set(pathId, alterData); context.SS->PersistSequenceAlterRemove(db, pathId); context.SS->PersistSequence(db, pathId, *alterData); @@ -491,6 +491,7 @@ class TAlterSequence: public TSubOperation { } Y_ABORT_UNLESS(context.SS->Sequences.contains(dstPath->PathId)); + context.MemChanges.GrabSequence(context.SS, dstPath->PathId); auto sequenceInfo = context.SS->Sequences.Update(dstPath->PathId); Y_ABORT_UNLESS(!sequenceInfo->AlterData); @@ -503,9 +504,6 @@ class TAlterSequence: public TSubOperation { return result; } - context.MemChanges.RecordUndo([sequenceInfo, previous = sequenceInfo->AlterData]() { - sequenceInfo->AlterData = previous; - }); TSequenceInfo::TPtr alterData = sequenceInfo->CreateNextVersion(); Y_ABORT_UNLESS(alterData); alterData->Description = *description; diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_alter_solomon.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_alter_solomon.cpp index e674a391159e3..b95c0e875b892 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_alter_solomon.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_alter_solomon.cpp @@ -40,7 +40,7 @@ class TConfigureParts: public TSubOperationState { Y_ABORT_UNLESS(txState); Y_ABORT_UNLESS(txState->TxType == TTxState::TxAlterSolomonVolume); - auto& solomon = context.SS->SolomonVolumes.UpdateUntracked(txState->TargetPathId); + auto& solomon = context.SS->SolomonVolumes.Update(txState->TargetPathId); Y_VERIFY_S(solomon, "solomon volume is null. PathId: " << txState->TargetPathId); Y_VERIFY_S(solomon->AlterData, "solomon volume alter data is null. PathId: " << txState->TargetPathId); @@ -109,7 +109,7 @@ class TPropose: public TSubOperationState { context.SS->TabletCounters->Simple()[COUNTER_SOLOMON_PARTITIONS_COUNT].Add(solomon->AlterData->Partitions.size()); context.SS->PersistSolomonVolume(db, txState->TargetPathId, solomon->AlterData); - context.SS->SolomonVolumes.SetUntracked(txState->TargetPathId, solomon->AlterData); + context.SS->SolomonVolumes.Set(txState->TargetPathId, solomon->AlterData); context.SS->ClearDescribePathCaches(path); context.OnComplete.PublishToSchemeBoard(OperationId, pathId); diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_alter_streaming_query.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_alter_streaming_query.cpp index c0df1f9ae5743..6adc4a13eb367 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_alter_streaming_query.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_alter_streaming_query.cpp @@ -201,7 +201,8 @@ class TAlterStreamingQuery : public TSubOperation { streamingQuery->ApplyACL(acl); } - context.SS->StreamingQueries.Set({.Path = dstPath.Base()->PathId, .Value = queryInfo, .Changes = context.MemChanges}); + context.MemChanges.GrabStreamingQuery(context.SS, dstPath.Base()->PathId); + context.SS->StreamingQueries.Set(dstPath.Base()->PathId, queryInfo); } public: diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_alter_table.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_alter_table.cpp index c9bbb9e11bc56..4d4a835b51899 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_alter_table.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_alter_table.cpp @@ -475,7 +475,7 @@ class TPropose: public TSubOperationState { NIceDb::TNiceDb db(context.GetDB()); - auto& table = context.SS->Tables.UpdateUntracked(pathId); + auto& table = context.SS->Tables.Update(pathId); table->FinishAlter(); if (!table->IsAsyncReplica()) { @@ -701,6 +701,7 @@ class TAlterTable: public TSubOperation { } Y_ABORT_UNLESS(context.SS->Tables.contains(path.Base()->PathId)); + context.MemChanges.GrabTable(context.SS, path.Base()->PathId); auto table = context.SS->Tables.Update(path.Base()->PathId); if (context.SS->IsTableInBackupCollection(path.Base()->PathId)) { @@ -774,11 +775,6 @@ class TAlterTable: public TSubOperation { } } - // The schema change is staged in AlterData; undo only its attachment, - // without copying the table's partitioning or per-shard statistics. - context.MemChanges.RecordUndo([table, previousAlterData = table->AlterData]() { - table->AlterData = previousAlterData; - }); table->PrepareAlter(alterData); PrepareChanges(OperationId, path.Base(), table, bindingChanges, context); diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_blob_depot.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_blob_depot.cpp index 58e197f8bd971..ad2e3f0ef171c 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_blob_depot.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_blob_depot.cpp @@ -58,7 +58,7 @@ namespace NKikimr::NSchemeShard { auto path = TPath::Init(txState->TargetPathId, context.SS); Y_ABORT_UNLESS(path.IsResolved()); - auto& blobDepotInfo = context.SS->BlobDepots.UpdateUntracked(path->PathId); + auto& blobDepotInfo = context.SS->BlobDepots.Update(path->PathId); Y_ABORT_UNLESS(blobDepotInfo); for (auto& shard : txState->Shards) { @@ -357,7 +357,8 @@ namespace NKikimr::NSchemeShard { } context.SS->PersistPath(db, dstPath->PathId); - context.SS->BlobDepots.Set({.Path = pathId, .Value = blobDepot, .Changes = context.MemChanges}); + context.MemChanges.GrabNewBlobDepot(context.SS, pathId); + context.SS->BlobDepots.Set(pathId, blobDepot); context.SS->PersistBlobDepot(db, pathId, *blobDepot); context.SS->PersistTxState(db, OperationId); diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_common.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_common.cpp index cacf40cdad3d0..fa41efac39f56 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_common.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_common.cpp @@ -489,7 +489,7 @@ bool TDone::Process(TOperationContext& context) { if (!tableInfo->IsStandalone()) { const auto storePathId = tableInfo->GetOlapStorePathIdVerified(); if (context.SS->OlapStores.contains(storePathId)) { - auto& storeInfo = context.SS->OlapStores.UpdateUntracked(storePathId); + auto& storeInfo = context.SS->OlapStores.Update(storePathId); storeInfo->ColumnTablesUnderOperation.erase(pathId); } } @@ -804,7 +804,7 @@ void UpdatePartitioningForTableModification(TOperationId operationId, TTxState & Y_ABORT_UNLESS(txState.ShardsInProgress.empty()); Y_ABORT_UNLESS(context.SS->Tables.contains(txState.TargetPathId)); - TTableInfo::TPtr table = context.SS->Tables.UpdateUntracked(txState.TargetPathId); + TTableInfo::TPtr table = context.SS->Tables.Update(txState.TargetPathId); TTxState::ETxState commonShardOp = TTxState::CreateParts; if (txState.TxType == TTxState::TxAlterTable) { @@ -943,10 +943,10 @@ void UpdatePartitioningForCopyTable(TOperationId operationId, TTxState &txState, Y_ABORT_UNLESS(context.SS->PathsById.at(txState.SourcePathId)->PathState == TPathElement::EPathState::EPathStateCopying); Y_ABORT_UNLESS(context.SS->PathsById.contains(txState.TargetPathId)); auto dstPath = context.SS->PathsById.at(txState.TargetPathId); - auto& domainInfo = context.SS->SubDomains.UpdateUntracked(dstPath->DomainPathId); + auto& domainInfo = context.SS->SubDomains.Update(dstPath->DomainPathId); - auto& srcTableInfo = context.SS->Tables.UpdateUntracked(txState.SourcePathId); - auto& dstTableInfo = context.SS->Tables.UpdateUntracked(txState.TargetPathId); + auto& srcTableInfo = context.SS->Tables.Update(txState.SourcePathId); + auto& dstTableInfo = context.SS->Tables.Update(txState.TargetPathId); NIceDb::TNiceDb db(context.GetDB()); @@ -1455,7 +1455,7 @@ TVector SyncChildIndexVersions( if (!context.SS->Indexes.contains(childPathId)) { continue; } - auto& index = context.SS->Indexes.UpdateUntracked(childPathId); + auto& index = context.SS->Indexes.Update(childPathId); if (index->AlterVersion < targetVersion) { index->AlterVersion = targetVersion; // If there's ongoing alter operation, also update alterData version to converge diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_common_bsv.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_common_bsv.cpp index 9cf70b73e74fc..c4517d04e1f0c 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_common_bsv.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_common_bsv.cpp @@ -74,7 +74,7 @@ bool TConfigureParts::ProgressState(TOperationContext& context) { txState->ClearShardsInProgress(); - auto& volume = context.SS->BlockStoreVolumes.UpdateUntracked(txState->TargetPathId); + auto& volume = context.SS->BlockStoreVolumes.Update(txState->TargetPathId); Y_VERIFY_S(volume, "volume is null. PathId: " << txState->TargetPathId); ui64 version = volume->AlterVersion; @@ -158,7 +158,7 @@ bool TPropose::HandleReply(TEvPrivate::TEvOperationPlan::TPtr& ev, TOperationCon context.SS->PersistCreateStep(db, pathId, step); } - auto& volume = context.SS->BlockStoreVolumes.UpdateUntracked(pathId); + auto& volume = context.SS->BlockStoreVolumes.Update(pathId); auto oldVolumeSpace = volume->GetVolumeSpace(); volume->FinishAlter(); diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_common_cdc_stream.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_common_cdc_stream.cpp index a28919ade5cd2..5fc13482e06dd 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_common_cdc_stream.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_common_cdc_stream.cpp @@ -153,7 +153,7 @@ bool TProposeAtTable::HandleReply(TEvPrivate::TEvOperationPlan::TPtr& ev, TOpera auto path = context.SS->PathsById.at(pathId); Y_ABORT_UNLESS(context.SS->Tables.contains(pathId)); - auto& table = context.SS->Tables.UpdateUntracked(pathId); + auto& table = context.SS->Tables.Update(pathId); NIceDb::TNiceDb db(context.GetDB()); @@ -179,7 +179,7 @@ bool TProposeAtTable::HandleReply(TEvPrivate::TEvOperationPlan::TPtr& ev, TOpera if (versionCtx.IsIndexImplTable) { if (context.SS->Indexes.contains(versionCtx.ParentPathId)) { - auto& index = context.SS->Indexes.UpdateUntracked(versionCtx.ParentPathId); + auto& index = context.SS->Indexes.Update(versionCtx.ParentPathId); ui64 targetVersion = table->AlterVersion; if (index->AlterVersion < targetVersion) { index->AlterVersion = targetVersion; @@ -228,7 +228,7 @@ bool TProposeAtTable::HandleReply(TEvPrivate::TEvOperationPlan::TPtr& ev, TOpera if (!context.SS->Indexes.contains(childPathId)) { continue; } - auto& index = context.SS->Indexes.UpdateUntracked(childPathId); + auto& index = context.SS->Indexes.Update(childPathId); if (index->AlterVersion < targetVersion) { index->AlterVersion = targetVersion; if (index->AlterData && index->AlterData->AlterVersion < targetVersion) { diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_common_pq.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_common_pq.cpp index 3685923b705e2..c4eeb99afb8b3 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_common_pq.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_common_pq.cpp @@ -393,7 +393,7 @@ bool TConfigureParts::ProgressState(TOperationContext& context) { "topicName is empty" <<", pathId: " << txState->TargetPathId); - auto& pqGroup = context.SS->Topics.UpdateUntracked(txState->TargetPathId); + auto& pqGroup = context.SS->Topics.Update(txState->TargetPathId); Y_VERIFY_S(pqGroup, "pqGroup is null" << ", pathId " << txState->TargetPathId); @@ -768,7 +768,7 @@ void TPropose::PersistState(const TTxState& txState, context.SS->ClearDescribePathCaches(Path); context.OnComplete.PublishToSchemeBoard(OperationId, PathId); - auto& pqGroup = context.SS->Topics.UpdateUntracked(PathId); + auto& pqGroup = context.SS->Topics.Update(PathId); NKikimrPQ::TPQTabletConfig tabletConfig = pqGroup->GetTabletConfig(); NKikimrPQ::TPQTabletConfig newTabletConfig = pqGroup->AlterData->GetTabletConfig(); diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_common_subdomain.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_common_subdomain.cpp index 93b03fd5d8c1e..a1402e698f8c1 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_common_subdomain.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_common_subdomain.cpp @@ -326,7 +326,7 @@ bool TPropose::HandleReply(TEvPrivate::TEvOperationPlan::TPtr& ev, TOperationCon } Y_ABORT_UNLESS(context.SS->SubDomains.contains(pathId)); - auto& subDomain = context.SS->SubDomains.UpdateUntracked(pathId); + auto& subDomain = context.SS->SubDomains.Update(pathId); auto alter = subDomain->GetAlter(); Y_ABORT_UNLESS(alter); Y_VERIFY_S(subDomain->GetVersion() < alter->GetVersion(), "" << subDomain->GetVersion() << " and " << alter->GetVersion()); @@ -335,7 +335,7 @@ bool TPropose::HandleReply(TEvPrivate::TEvOperationPlan::TPtr& ev, TOperationCon /* isExternal */ path->PathType == TPathElement::EPathType::EPathTypeExtSubDomain, context.SS); - context.SS->SubDomains.SetUntracked(pathId, alter); + context.SS->SubDomains.Set(pathId, alter); context.SS->PersistSubDomain(db, pathId, *alter); context.SS->PersistSubDomainSchemeQuotas(db, pathId, *alter); diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_copy_sequence.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_copy_sequence.cpp index 6ea564376a557..5c62aa26b6a34 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_copy_sequence.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_copy_sequence.cpp @@ -178,7 +178,7 @@ class TPropose: public TSubOperationState { path->StepCreated = step; context.SS->PersistCreateStep(db, pathId, step); - context.SS->Sequences.SetUntracked(pathId, alterData); + context.SS->Sequences.Set(pathId, alterData); context.SS->PersistSequenceAlterRemove(db, pathId); context.SS->PersistSequence(db, pathId, *alterData); @@ -349,7 +349,7 @@ class TProposedCopySequence : public TSubOperationState { NIceDb::TNiceDb db(context.GetDB()); - auto& sequenceInfo = context.SS->Sequences.UpdateUntracked(pathId); + auto& sequenceInfo = context.SS->Sequences.Update(pathId); UpdateSequenceDescription(sequenceInfo->Description); context.SS->PersistSequence(db, pathId, *sequenceInfo); @@ -714,7 +714,8 @@ class TCopySequence: public TSubOperation { } context.SS->PersistPath(db, dstPath->PathId); - context.SS->Sequences.Set({.Path = pathId, .Value = sequenceInfo, .Changes = context.MemChanges}); + context.MemChanges.GrabNewSequence(context.SS, pathId); + context.SS->Sequences.Set(pathId, sequenceInfo); context.SS->PersistSequence(db, pathId, *sequenceInfo); context.SS->PersistSequenceAlter(db, pathId, *alterData); diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_copy_table.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_copy_table.cpp index 4525591782c12..7e2ebaca32c83 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_copy_table.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_copy_table.cpp @@ -141,7 +141,7 @@ class TConfigureParts: public TSubOperationState { FillSrcSnapshot(txState, ui64(dstDatashardId), *combined.MutableSendSnapshot()); // Get coordinated version from source table's AlterData (shared across both drop and create) - auto& srcTable = context.SS->Tables.UpdateUntracked(txState->SourcePathId); + auto& srcTable = context.SS->Tables.Update(txState->SourcePathId); srcTable->InitAlterData(OperationId); ui64 coordVersion = srcTable->AlterData->CoordinatedSchemaVersion.GetOrElse(srcTable->AlterVersion + 1); @@ -226,7 +226,7 @@ class TPropose: public TSubOperationState { path->StepCreated = step; context.SS->PersistCreateStep(db, pathId, step); - auto& table = context.SS->Tables.UpdateUntracked(pathId); + auto& table = context.SS->Tables.Update(pathId); Y_ABORT_UNLESS(table); table->AlterVersion = NEW_TABLE_ALTER_VERSION; context.SS->PersistTableCreated(db, pathId); @@ -234,7 +234,7 @@ class TPropose: public TSubOperationState { if (path->ParentPathId && context.SS->PathsById.contains(path->ParentPathId)) { auto dstParentPath = context.SS->PathsById.at(path->ParentPathId); if (dstParentPath->IsTableIndex() && context.SS->Indexes.contains(path->ParentPathId)) { - auto& dstIndex = context.SS->Indexes.UpdateUntracked(path->ParentPathId); + auto& dstIndex = context.SS->Indexes.Update(path->ParentPathId); if (dstIndex->AlterVersion < table->AlterVersion) { dstIndex->AlterVersion = table->AlterVersion; if (dstIndex->AlterData && dstIndex->AlterData->AlterVersion < table->AlterVersion) { @@ -304,7 +304,7 @@ class TPropose: public TSubOperationState { } if (hasCdcChanges && context.SS->Tables.contains(srcPathId)) { - auto& srcTable = context.SS->Tables.UpdateUntracked(srcPathId); + auto& srcTable = context.SS->Tables.Update(srcPathId); // Don't call InitAlterData() here - it was already called in ConfigureParts, // and calling it again after another subop's Done() updated AlterVersion @@ -325,7 +325,7 @@ class TPropose: public TSubOperationState { if (parentPathId && context.SS->PathsById.contains(parentPathId)) { auto parentPath = context.SS->PathsById.at(parentPathId); if (parentPath->IsTableIndex() && context.SS->Indexes.contains(parentPathId)) { - auto& index = context.SS->Indexes.UpdateUntracked(parentPathId); + auto& index = context.SS->Indexes.Update(parentPathId); if (index->AlterVersion < srcTable->AlterVersion) { index->AlterVersion = srcTable->AlterVersion; if (index->AlterData && index->AlterData->AlterVersion < srcTable->AlterVersion) { @@ -348,7 +348,7 @@ class TPropose: public TSubOperationState { continue; } if (context.SS->Indexes.contains(childPathId)) { - auto& index = context.SS->Indexes.UpdateUntracked(childPathId); + auto& index = context.SS->Indexes.Update(childPathId); if (index->AlterVersion < srcTable->AlterVersion) { index->AlterVersion = srcTable->AlterVersion; if (index->AlterData && index->AlterData->AlterVersion < srcTable->AlterVersion) { @@ -366,7 +366,7 @@ class TPropose: public TSubOperationState { context.OnComplete.PublishToSchemeBoard(OperationId, srcPathId); if (txState->CdcPathId != InvalidPathId && context.SS->CdcStreams.contains(txState->CdcPathId)) { - auto& stream = context.SS->CdcStreams.UpdateUntracked(txState->CdcPathId); + auto& stream = context.SS->CdcStreams.Update(txState->CdcPathId); if (stream->AlterData) { stream->FinishAlter(); context.SS->PersistCdcStream(db, txState->CdcPathId); @@ -864,7 +864,8 @@ class TCopyTable: public TSubOperation { Y_ABORT_UNLESS(tableInfo->GetPartitions().back()->EndOfRange.empty(), "End of last range must be +INF"); - context.SS->Tables.Set({.Path = newTable->PathId, .Value = tableInfo, .Changes = context.MemChanges}); + context.MemChanges.GrabNewTable(context.SS, newTable->PathId); + context.SS->Tables.Set(newTable->PathId, tableInfo); if (parent.Base()->HasActiveChanges()) { TTxId parentTxId = parent.Base()->PlannedToCreate() ? parent.Base()->CreateTxId : parent.Base()->LastTxId; diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_create_backup.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_create_backup.cpp index d95f2b4fd4812..881420e3f6c48 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_create_backup.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_create_backup.cpp @@ -140,7 +140,7 @@ struct TBackup { const ui64 ts = TAppData::TimeProvider->Now().Seconds(); Y_ABORT_UNLESS(context.SS->Tables.contains(txState.TargetPathId)); - TTableInfo::TPtr table = context.SS->Tables.UpdateUntracked(txState.TargetPathId); + TTableInfo::TPtr table = context.SS->Tables.Update(txState.TargetPathId); auto& backupInfo = table->BackupHistory[opId.GetTxId()]; @@ -178,7 +178,7 @@ struct TBackup { static void PersistTableTask(const TPathId& pathId, const TTxTransaction& tx, TOperationContext& context) { Y_ABORT_UNLESS(context.SS->Tables.contains(pathId)); - TTableInfo::TPtr table = context.SS->Tables.UpdateUntracked(pathId); + TTableInfo::TPtr table = context.SS->Tables.Update(pathId); table->BackupSettings = tx.GetBackup(); diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_create_backup_collection.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_create_backup_collection.cpp index 42eed6aefc967..05497fddb95af 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_create_backup_collection.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_create_backup_collection.cpp @@ -190,7 +190,8 @@ class TCreateBackupCollection : public TSubOperation { } auto backupCollection = TBackupCollectionInfo::Create(desc); - context.SS->BackupCollections.Set({.Path = allocatedPathId, .Value = backupCollection, .Changes = context.MemChanges}); + context.MemChanges.GrabNewBackupCollection(context.SS, allocatedPathId); + context.SS->BackupCollections.Set(allocatedPathId, backupCollection); context.SS->RegisterBackupCollectionTables(backupCollection); context.DbChanges.PersistBackupCollection(allocatedPathId, backupCollection); diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_create_bsv.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_create_bsv.cpp index 27d54bea9b4a7..9c4077c463253 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_create_bsv.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_create_bsv.cpp @@ -140,7 +140,8 @@ TTxState& PrepareChanges(TOperationId operationId, TPathElement::TPtr parentDir, TBlockStoreVolumeInfo::TPtr emptyVolume = new TBlockStoreVolumeInfo(); emptyVolume->Shards.swap(volume->Shards); emptyVolume->AlterData = volume; - context.SS->BlockStoreVolumes.Set({.Path = pathId, .Value = emptyVolume, .Changes = context.MemChanges}); + context.MemChanges.GrabNewBlockStoreVolume(context.SS, pathId); + context.SS->BlockStoreVolumes.Set(pathId, emptyVolume); context.SS->PersistBlockStoreVolume(db, pathId, emptyVolume); context.SS->PersistAddBlockStoreVolumeAlter(db, pathId, volume); 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 3762530df86c9..aa029fceb224b 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_create_cdc_stream.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_create_cdc_stream.cpp @@ -66,7 +66,7 @@ class TPropose: public TSubOperationState { context.SS->PersistCreateStep(db, pathId, step); context.SS->PersistCdcStream(db, pathId); - context.SS->CdcStreams.SetUntracked(pathId, stream->AlterData); + context.SS->CdcStreams.Set(pathId, stream->AlterData); context.SS->TabletCounters->Simple()[COUNTER_CDC_STREAMS_COUNT].Add(1); context.SS->ClearDescribePathCaches(path); @@ -330,7 +330,8 @@ class TNewCdcStream: public TSubOperation { streamPath.Base()->PathType = TPathElement::EPathType::EPathTypeCdcStream; streamPath.Base()->UserAttrs->AlterData = userAttrs; - context.SS->CdcStreams.Set({.Path = pathId, .Value = stream, .Changes = context.MemChanges}); + context.MemChanges.GrabNewCdcStream(context.SS, pathId); + context.SS->CdcStreams.Set(pathId, stream); streamPath.DomainInfo()->IncPathsInside(context.SS); IncAliveChildrenSafeWithUndo(OperationId, tablePath, context); // for correct discard of ChildrenExist prop @@ -363,7 +364,7 @@ class TConfigurePartsAtTable: public NCdcStreamState::TConfigurePartsAtTable { // Override table schema version with coordinated version from AlterData Y_ABORT_UNLESS(context.SS->Tables.contains(pathId)); - auto& table = context.SS->Tables.UpdateUntracked(pathId); + auto& table = context.SS->Tables.Update(pathId); table->InitAlterData(OperationId); notice.SetTableSchemaVersion(*table->AlterData->CoordinatedSchemaVersion); diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_create_external_data_source.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_create_external_data_source.cpp index 4d5d747f2861f..22acb25c15bc6 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_create_external_data_source.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_create_external_data_source.cpp @@ -219,7 +219,8 @@ class TCreateExternalDataSource : public TSubOperation { externalDataSource->PathState = TPathElement::EPathState::EPathStateCreate; externalDataSource->LastTxId = OperationId.GetTxId(); - context.SS->ExternalDataSources.Set({.Path = newPathId, .Value = externalDataSourceInfo, .Changes = context.MemChanges}); + context.MemChanges.GrabNewExternalDataSource(context.SS, newPathId); + context.SS->ExternalDataSources.Set(newPathId, externalDataSourceInfo); if (!acl.empty()) { externalDataSource->ApplyACL(acl); } diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_create_external_table.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_create_external_table.cpp index 07f4f97783964..f24daded447a2 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_create_external_table.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_create_external_table.cpp @@ -288,6 +288,7 @@ class TCreateExternalTable: public TSubOperation { context.MemChanges.GrabNewPath(context.SS, newPathId); context.MemChanges.GrabPath(context.SS, parentPath.Base()->PathId); context.MemChanges.GrabPath(context.SS, dataSourcePath.Base()->PathId); + context.MemChanges.GrabExternalDataSource(context.SS, dataSourcePath.Base()->PathId); context.MemChanges.GrabNewTxState(context.SS, OperationId); context.DbChanges.PersistPath(newPathId); @@ -309,7 +310,8 @@ class TCreateExternalTable: public TSubOperation { externalTable, dstPath); - context.SS->ExternalTables.Set({.Path = newPathId, .Value = externalTableInfo, .Changes = context.MemChanges}); + context.MemChanges.GrabNewExternalTable(context.SS, newPathId); + context.SS->ExternalTables.Set(newPathId, externalTableInfo); if (!acl.empty()) { externalTable->ApplyACL(acl); } diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_create_extsubdomain.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_create_extsubdomain.cpp index 9e70c06ce2344..720f2418f3aac 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_create_extsubdomain.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_create_extsubdomain.cpp @@ -245,7 +245,7 @@ class TCreateExtSubDomain: public TSubOperation { } Y_ABORT_UNLESS(!context.SS->SubDomains.contains(newNode->PathId)); - auto& subDomainInfo = context.SS->SubDomains.EmplaceUntracked(newNode->PathId); + auto& subDomainInfo = context.SS->SubDomains.Emplace(newNode->PathId); subDomainInfo = new TSubDomainInfo(); subDomainInfo->SetAlter(alter); diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_create_fs.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_create_fs.cpp index 2e862499d0b7a..0dae9d33fcb0c 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_create_fs.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_create_fs.cpp @@ -96,7 +96,7 @@ class TConfigureParts: public TSubOperationState { txState->ClearShardsInProgress(); - auto& fs = context.SS->FileStoreInfos.UpdateUntracked(txState->TargetPathId); + auto& fs = context.SS->FileStoreInfos.Update(txState->TargetPathId); Y_VERIFY_S(fs, "FileStore info is null. PathId: " << txState->TargetPathId); Y_ABORT_UNLESS(txState->Shards.size() == 1); @@ -517,7 +517,8 @@ TTxState& TCreateFileStore::PrepareChanges( } context.SS->PersistPath(db, fsPath->PathId); - context.SS->FileStoreInfos.Set({.Path = pathId, .Value = fs, .Changes = context.MemChanges}); + context.MemChanges.GrabNewFileStoreInfo(context.SS, pathId); + context.SS->FileStoreInfos.Set(pathId, fs); context.SS->PersistFileStoreInfo(db, pathId, fs); context.SS->PersistTxState(db, operationId); diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_create_kesus.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_create_kesus.cpp index 49e93a3cd663e..223e902b3e6bf 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_create_kesus.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_create_kesus.cpp @@ -56,7 +56,8 @@ TTxState& PrepareChanges(TOperationId operationId, TPathElement::TPtr parentDir, item->ApplyACL(acl); } context.SS->PersistPath(db, item->PathId); - context.SS->KesusInfos.Set({.Path = pathId, .Value = kesus, .Changes = context.MemChanges}); + context.MemChanges.GrabNewKesusInfo(context.SS, pathId); + context.SS->KesusInfos.Set(pathId, kesus); context.SS->PersistKesusInfo(db, pathId, kesus); context.SS->PersistTxState(db, operationId); @@ -139,7 +140,7 @@ class TConfigureParts: public TSubOperationState { txState->ClearShardsInProgress(); - auto& kesus = context.SS->KesusInfos.UpdateUntracked(txState->TargetPathId); + auto& kesus = context.SS->KesusInfos.Update(txState->TargetPathId); Y_VERIFY_S(kesus, "kesus is null. PathId: " << txState->TargetPathId); @@ -205,7 +206,7 @@ class TPropose: public TSubOperationState { TPathElement::TPtr path = context.SS->PathsById.at(pathId); Y_VERIFY_S(context.SS->KesusInfos.contains(pathId), "kesus has not found. PathId: " << pathId); - auto& kesus = context.SS->KesusInfos.UpdateUntracked(pathId); + auto& kesus = context.SS->KesusInfos.Update(pathId); Y_VERIFY_S(kesus, "kesus is null. PathId: " << pathId); NIceDb::TNiceDb db(context.GetDB()); diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_create_pq.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_create_pq.cpp index 2110bb8de58f6..af16ee7c5badb 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_create_pq.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_create_pq.cpp @@ -509,7 +509,8 @@ class TCreatePQ: public TSubOperation { emptyGroup->Shards.swap(pqGroup->Shards); emptyGroup->AlterData = pqGroup; - context.SS->Topics.Set({.Path = pathId, .Value = emptyGroup, .Changes = context.MemChanges}); + context.MemChanges.GrabNewTopic(context.SS, pathId); + context.SS->Topics.Set(pathId, emptyGroup); context.DbChanges.PersistPersQueueGroup(pathId, emptyGroup); context.DbChanges.PersistAddPersQueueGroupAlter(pathId, pqGroup); diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_create_replication.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_create_replication.cpp index a224634f47f53..da2596a7e2385 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_create_replication.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_create_replication.cpp @@ -286,7 +286,7 @@ class TPropose: public TSubOperationState { path->StepCreated = step; context.SS->PersistCreateStep(db, pathId, step); - context.SS->Replications.SetUntracked(pathId, alterData); + context.SS->Replications.Set(pathId, alterData); context.SS->PersistReplicationAlterRemove(db, pathId); context.SS->PersistReplication(db, pathId, *alterData); @@ -480,7 +480,8 @@ class TCreateReplication: public TSubOperation { desc.MutableState()->MutableStandBy(); auto replication = TReplicationInfo::Create(std::move(desc)); - context.SS->Replications.Set({.Path = path->PathId, .Value = replication, .Changes = context.MemChanges}); + context.MemChanges.GrabNewReplication(context.SS, path->PathId); + context.SS->Replications.Set(path->PathId, replication); context.SS->TabletCounters->Simple()[COUNTER_REPLICATION_COUNT].Add(1); replication->AlterData->ControllerShardIdx = context.SS->RegisterShardInfo( diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_create_resource_pool.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_create_resource_pool.cpp index 93ae90b384e27..b756e84a36863 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_create_resource_pool.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_create_resource_pool.cpp @@ -177,7 +177,8 @@ class TCreateResourcePool : public TSubOperation { resourcePool->PathState = TPathElement::EPathState::EPathStateCreate; resourcePool->LastTxId = OperationId.GetTxId(); - context.SS->ResourcePools.Set({.Path = newPathId, .Value = resourcePoolInfo, .Changes = context.MemChanges}); + context.MemChanges.GrabNewResourcePool(context.SS, newPathId); + context.SS->ResourcePools.Set(newPathId, resourcePoolInfo); if (!acl.empty()) { resourcePool->ApplyACL(acl); } diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_create_restore.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_create_restore.cpp index eb3914d1ffe7b..256d81c848577 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_create_restore.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_create_restore.cpp @@ -81,7 +81,7 @@ struct TRestore { const TPath sourcePath = TPath::Init(pathId, context.SS); if (sourcePath->IsTable()) { Y_ABORT_UNLESS(context.SS->Tables.contains(txState.TargetPathId)); - TTableInfo::TPtr table = context.SS->Tables.UpdateUntracked(txState.TargetPathId); + TTableInfo::TPtr table = context.SS->Tables.Update(txState.TargetPathId); return TableFinish(table, opId, txState, context); } else { Y_ABORT_UNLESS(context.SS->ColumnTables.contains(txState.TargetPathId)); @@ -121,7 +121,7 @@ struct TRestore { const TPath sourcePath = TPath::Init(pathId, context.SS); if (sourcePath->IsTable()) { Y_ABORT_UNLESS(context.SS->Tables.contains(pathId)); - TTableInfo::TPtr table = context.SS->Tables.UpdateUntracked(pathId); + TTableInfo::TPtr table = context.SS->Tables.Update(pathId); return PersistTableTask(table, pathId, tx, context); } else { Y_ABORT_UNLESS(context.SS->ColumnTables.contains(pathId)); diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_create_rtmr.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_create_rtmr.cpp index 7d28556e0963d..de4dc72d1c550 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_create_rtmr.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_create_rtmr.cpp @@ -84,7 +84,7 @@ class TConfigureParts: public TSubOperationState { Y_ABORT_UNLESS(txState); Y_ABORT_UNLESS(txState->TxType == TTxState::TxCreateRtmrVolume); - auto& rtmrVol = context.SS->RtmrVolumes.UpdateUntracked(txState->TargetPathId); + auto& rtmrVol = context.SS->RtmrVolumes.Update(txState->TargetPathId); Y_VERIFY_S(rtmrVol, "rtmr volume is null. PathId: " << txState->TargetPathId); Y_ABORT_UNLESS(rtmrVol->Partitions.size() == txState->Shards.size(), "%" PRIu64 "rtmr shards expected, %" PRIu64 " created", @@ -331,7 +331,8 @@ class TCreateRTMR: public TSubOperation { context.SS->ChangeTxState(db, OperationId, TTxState::CreateParts); context.OnComplete.ActivateTx(OperationId); - context.SS->RtmrVolumes.Set({.Path = newRtmrVolume->PathId, .Value = rtmrVolumeInfo, .Changes = context.MemChanges}); + context.MemChanges.GrabNewRtmrVolume(context.SS, newRtmrVolume->PathId); + context.SS->RtmrVolumes.Set(newRtmrVolume->PathId, rtmrVolumeInfo); context.SS->TabletCounters->Simple()[COUNTER_RTMR_VOLUME_COUNT].Add(1); context.SS->TabletCounters->Simple()[COUNTER_RTMR_PARTITIONS_COUNT].Add(rtmrVolumeInfo->Partitions.size()); diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_create_secret.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_create_secret.cpp index a8bbab5814d58..3855c2d4a60a7 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_create_secret.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_create_secret.cpp @@ -93,7 +93,7 @@ class TPropose : public TSubOperationState { secretPath->StepCreated = step; context.SS->PersistCreateStep(db, secretPathId, step); - context.SS->Secrets.SetUntracked(secretPathId, alterData); + context.SS->Secrets.Set(secretPathId, alterData); context.SS->PersistSecretAlterRemove(db, secretPathId); context.SS->PersistSecret(db, secretPathId, *alterData); @@ -281,7 +281,8 @@ class TCreateSecret : public TSubOperation { secretDescription.SetValue(createSecretProto.GetValue()); const auto secretInfo = TSecretInfo::Create(std::move(secretDescription)); - context.SS->Secrets.Set({.Path = secretPathId, .Value = secretInfo, .Changes = context.MemChanges}); + context.MemChanges.GrabNewSecret(context.SS, secretPathId); + context.SS->Secrets.Set(secretPathId, secretInfo); NIceDb::TNiceDb db(context.GetDB()); context.SS->PersistPath(db, dstPath->PathId); diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_create_sequence.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_create_sequence.cpp index 97daf0b1e3e66..0a01fc8eaa969 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_create_sequence.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_create_sequence.cpp @@ -212,7 +212,7 @@ class TPropose: public TSubOperationState { path->StepCreated = step; context.SS->PersistCreateStep(db, pathId, step); - context.SS->Sequences.SetUntracked(pathId, alterData); + context.SS->Sequences.Set(pathId, alterData); context.SS->PersistSequenceAlterRemove(db, pathId); context.SS->PersistSequence(db, pathId, *alterData); @@ -565,7 +565,8 @@ class TCreateSequence : public TSubOperation { } context.SS->PersistPath(db, dstPath->PathId); - context.SS->Sequences.Set({.Path = pathId, .Value = sequenceInfo, .Changes = context.MemChanges}); + context.MemChanges.GrabNewSequence(context.SS, pathId); + context.SS->Sequences.Set(pathId, sequenceInfo); context.SS->PersistSequence(db, pathId, *sequenceInfo); context.SS->PersistSequenceAlter(db, pathId, *alterData); diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_create_solomon.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_create_solomon.cpp index 61aba30bd724a..300843e3a85d7 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_create_solomon.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_create_solomon.cpp @@ -117,7 +117,7 @@ class TConfigureParts: public TSubOperationState { Y_ABORT_UNLESS(txState); Y_ABORT_UNLESS(txState->TxType == TTxState::TxCreateSolomonVolume); - auto& solomonVol = context.SS->SolomonVolumes.UpdateUntracked(txState->TargetPathId); + auto& solomonVol = context.SS->SolomonVolumes.Update(txState->TargetPathId); Y_VERIFY_S(solomonVol, "solomon volume is null. PathId: " << txState->TargetPathId); Y_ABORT_UNLESS(solomonVol->Partitions.size() == txState->Shards.size(), "%" PRIu64 "solomon shards expected, %" PRIu64 " created", @@ -367,7 +367,8 @@ class TCreateSolomon: public TSubOperation { return result; } - context.SS->SolomonVolumes.Set({.Path = newSolomon->PathId, .Value = solomonVolume, .Changes = context.MemChanges}); + context.MemChanges.GrabNewSolomonVolume(context.SS, newSolomon->PathId); + context.SS->SolomonVolumes.Set(newSolomon->PathId, solomonVolume); context.SS->TabletCounters->Simple()[COUNTER_SOLOMON_VOLUME_COUNT].Add(1); context.SS->TabletCounters->Simple()[COUNTER_SOLOMON_PARTITIONS_COUNT].Add(solomonVolume->Partitions.size()); diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_create_streaming_query.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_create_streaming_query.cpp index 249396335d211..c37374c32aafc 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_create_streaming_query.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_create_streaming_query.cpp @@ -205,7 +205,8 @@ class TCreateStreamingQuery : public TSubOperation { .AlterVersion = 1, .Properties = Transaction.GetCreateStreamingQuery().GetProperties(), }); - context.SS->StreamingQueries.Set({.Path = dstPath.Base()->PathId, .Value = streamingQueryInfo, .Changes = context.MemChanges}); + context.MemChanges.GrabNewStreamingQuery(context.SS, dstPath.Base()->PathId); + context.SS->StreamingQueries.Set(dstPath.Base()->PathId, streamingQueryInfo); } public: diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_create_subdomain.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_create_subdomain.cpp index fcbb4bb436b5f..a98f414b3355d 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_create_subdomain.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_create_subdomain.cpp @@ -321,7 +321,7 @@ class TCreateSubDomain: public TSubOperation { } Y_ABORT_UNLESS(!context.SS->SubDomains.contains(newNode->PathId)); - auto& subDomainInfo = context.SS->SubDomains.EmplaceUntracked(newNode->PathId); + auto& subDomainInfo = context.SS->SubDomains.Emplace(newNode->PathId); subDomainInfo = new TSubDomainInfo(); subDomainInfo->SetAlter(alter); diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_create_sysview.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_create_sysview.cpp index ce8577a3eb857..3f7bbc7a2a3d4 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_create_sysview.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_create_sysview.cpp @@ -215,7 +215,8 @@ class TCreateSysView : public TSubOperation { } TSysViewInfo::TPtr sysViewInfo = CreateSysView(sysViewDescription); - context.SS->SysViews.Set({.Path = sysViewPathId, .Value = sysViewInfo, .Changes = context.MemChanges}); + context.MemChanges.GrabNewSysView(context.SS, sysViewPathId); + context.SS->SysViews.Set(sysViewPathId, sysViewInfo); TTxState& txState = context.SS->CreateTx(OperationId, TTxState::TxCreateSysView, sysViewPathId); txState.State = TTxState::Propose; diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_create_table.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_create_table.cpp index 4aa1206ebdf11..9f28c22cbd092 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_create_table.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_create_table.cpp @@ -315,7 +315,7 @@ class TPropose: public TSubOperationState { path->StepCreated = step; context.SS->PersistCreateStep(db, pathId, step); - auto& table = context.SS->Tables.UpdateUntracked(pathId); + auto& table = context.SS->Tables.Update(pathId); Y_ABORT_UNLESS(table); table->AlterVersion = NEW_TABLE_ALTER_VERSION; @@ -746,7 +746,8 @@ class TCreateTable: public TSubOperation { newTable->SetIncrementalRestoreTable(); } - context.SS->Tables.Set({.Path = newTable->PathId, .Value = tableInfo, .Changes = context.MemChanges}); + context.MemChanges.GrabNewTable(context.SS, newTable->PathId); + context.SS->Tables.Set(newTable->PathId, tableInfo); context.SS->TabletCounters->Simple()[COUNTER_TABLE_COUNT].Add(1); if ((parentPath.Base()->IsDirectory() || parentPath.Base()->IsDomainRoot()) && parentPath.Base()->HasActiveChanges()) { diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_create_test_shard_set.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_create_test_shard_set.cpp index a8223d6d88329..4e5c8e5a85e84 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_create_test_shard_set.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_create_test_shard_set.cpp @@ -115,7 +115,7 @@ class TConfigureParts: public TSubOperationState { Y_ABORT_UNLESS(txState); Y_ABORT_UNLESS(txState->TxType == TTxState::TxCreateTestShardSet); - auto& testShardInfo = context.SS->TestShardSets.UpdateUntracked(txState->TargetPathId); + auto& testShardInfo = context.SS->TestShardSets.Update(txState->TargetPathId); Y_VERIFY_S(testShardInfo, "test shard info is null. PathId: " << txState->TargetPathId); txState->ClearShardsInProgress(); @@ -388,7 +388,8 @@ class TCreateTestShardSet: public TSubOperation { TTxState& txState = context.SS->CreateTx(OperationId, TTxState::TxCreateTestShardSet, newPath->PathId); auto testShardInfo = CreateTestShardSet(op, txState, context.SS); - context.SS->TestShardSets.Set({.Path = newPath->PathId, .Value = testShardInfo, .Changes = context.MemChanges}); + context.MemChanges.GrabNewTestShardSet(context.SS, newPath->PathId); + context.SS->TestShardSets.Set(newPath->PathId, testShardInfo); context.SS->TabletCounters->Simple()[COUNTER_TEST_SHARD_SET_COUNT].Add(1); // Count TestShardSet objects, not tablets TShardInfo shardInfo = TShardInfo::TestShardSetInfo(OperationId.GetTxId(), newPath->PathId); diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_create_view.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_create_view.cpp index 5f127bcfc4b79..2eb3b20ded36c 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_create_view.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_create_view.cpp @@ -215,7 +215,8 @@ class TCreateView: public TSubOperation { result->SetStatus(NKikimrScheme::StatusInvalidParameter); return result; } - context.SS->Views.Set({.Path = viewPathId, .Value = viewInfo, .Changes = context.MemChanges}); + context.MemChanges.GrabNewView(context.SS, viewPathId); + context.SS->Views.Set(viewPathId, viewInfo); TTxState& txState = context.SS->CreateTx(OperationId, TTxState::TxCreateView, viewPathId); txState.State = TTxState::Propose; 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 034195754380e..69bcb87406f9e 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_drop_cdc_stream.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_drop_cdc_stream.cpp @@ -227,7 +227,7 @@ class TConfigurePartsAtTable: public NCdcStreamState::TConfigurePartsAtTable { auto path = context.SS->PathsById.at(pathId); Y_ABORT_UNLESS(context.SS->Tables.contains(pathId)); - auto& table = context.SS->Tables.UpdateUntracked(pathId); + auto& table = context.SS->Tables.Update(pathId); auto& notice = *tx.MutableDropCdcStreamNotice(); pathId.ToProto(notice.MutablePathId()); diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_drop_external_table.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_drop_external_table.cpp index 3b386ad789ad3..fb35b06693e6c 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_drop_external_table.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_drop_external_table.cpp @@ -189,6 +189,7 @@ class TDropExternalTable: public TSubOperation { context.MemChanges.GrabPath(context.SS, pathId); context.MemChanges.GrabPath(context.SS, path->ParentPathId); context.MemChanges.GrabPath(context.SS, dataSourcePath->PathId); + context.MemChanges.GrabExternalDataSource(context.SS, dataSourcePath->PathId); context.DbChanges.PersistTxState(OperationId); context.DbChanges.PersistPath(pathId); diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_drop_extsubdomain.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_drop_extsubdomain.cpp index 89e3275b57cb1..1b1ea5032d9d7 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_drop_extsubdomain.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_drop_extsubdomain.cpp @@ -32,7 +32,7 @@ class TDeleteSubdomainSystemShards: public TSubOperationState { Y_ABORT_UNLESS(txState); Y_ABORT_UNLESS(txState->TxType == TTxState::TxForceDropExtSubDomain); - auto& subdomain = context.SS->SubDomains.UpdateUntracked(txState->TargetPathId); + auto& subdomain = context.SS->SubDomains.Update(txState->TargetPathId); Y_ABORT_UNLESS(subdomain); // Initiate asynchronous deletion of system shards @@ -140,7 +140,7 @@ class TDeleteExternalShards: public TSubOperationState { Y_ABORT_UNLESS(txState); Y_ABORT_UNLESS(txState->TxType == TTxState::TxForceDropExtSubDomain); - auto& domainInfo = context.SS->SubDomains.UpdateUntracked(txState->TargetPathId); + auto& domainInfo = context.SS->SubDomains.Update(txState->TargetPathId); domainInfo->Initialize(context.SS->ShardInfos); TTabletId tenantSchemeshard = domainInfo->GetTenantSchemeShardID(); diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_incremental_restore_finalize.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_incremental_restore_finalize.cpp index d35ff11052f36..53de462e5b415 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_incremental_restore_finalize.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_incremental_restore_finalize.cpp @@ -99,7 +99,7 @@ class TIncrementalRestoreFinalizeOp: public TSubOperationWithContext { continue; } - auto& table = context.SS->Tables.UpdateUntracked(tablePathId); + auto& table = context.SS->Tables.Update(tablePathId); // InitAlterData() sets AlterVersion = CurrentVersion + 1 and also sets CoordinatedSchemaVersion table->InitAlterData(OperationId); @@ -273,7 +273,7 @@ class TIncrementalRestoreFinalizeOp: public TSubOperationWithContext { continue; } - auto& table = context.SS->Tables.UpdateUntracked(implTablePathId); + auto& table = context.SS->Tables.Update(implTablePathId); if (!table->AlterData) { LOG_W("SyncIndexSchemaVersions: No AlterData for table: " << implTablePathId); continue; @@ -311,7 +311,7 @@ class TIncrementalRestoreFinalizeOp: public TSubOperationWithContext { ui64 targetVersion = coordVersion; if (context.SS->Indexes.at(indexPathId)->AlterVersion < targetVersion) { - auto& index = context.SS->Indexes.UpdateUntracked(indexPathId); + auto& index = context.SS->Indexes.Update(indexPathId); index->AlterVersion = targetVersion; if (index->AlterData && index->AlterData->AlterVersion < targetVersion) { index->AlterData->AlterVersion = targetVersion; diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_memory_changes.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_memory_changes.cpp index ca0091c0aa315..95749f01140a4 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_memory_changes.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_memory_changes.cpp @@ -2,30 +2,54 @@ #include "schemeshard_impl.h" -namespace NKikimr::NSchemeShard { +#include -TMemoryChanges::~TMemoryChanges() { - // Backstop: IgniteOperation disarms on every exit, so this normally has - // nothing to do. - Disarm(); -} +namespace NKikimr::NSchemeShard { -void TMemoryChanges::Arm(TSchemeShard* ss) { +void TMemoryChanges::Arm(TSchemeShard*) { + Y_ABORT_UNLESS(!Armed); Armed = true; - SS = ss; - ss->ArmedChanges = this; } void TMemoryChanges::Disarm() { Armed = false; - // Several instances coexist (init, stats, side effects); only the propose one - // arms, so withdraw only our own registration. - if (SS && SS->ArmedChanges == this) { - SS->ArmedChanges = nullptr; - } - SS = nullptr; } +namespace { + +template +void GrabNewReferenceEntry(TMemoryChanges& changes, TDbRefMap& map, const TPathId& pathId) { + Y_ABORT_UNLESS(changes.IsArmed()); + Y_ABORT_UNLESS(!map.contains(pathId)); + Y_ABORT_UNLESS(changes.IsPathTracked(pathId)); + changes.RecordUndo([&map, pathId]() { + map.RestoreMembershipWithoutRefcount(pathId, {}); + }); +} + +template +void GrabReferenceEntry(TMemoryChanges& changes, TDbRefMap>& map, const TPathId& pathId) { + Y_ABORT_UNLESS(changes.IsArmed()); + auto original = map.Update(pathId); + auto snapshot = [&]() { + if constexpr (std::is_same_v) { + return TTableInfo::DeepCopy(*original); + } else { + return MakeIntrusive(*original); + } + }(); + changes.RecordUndo([&map, pathId, original, snapshot]() { + if constexpr (std::is_same_v) { + original->RestoreSnapshot(*snapshot); + } else { + *original = *snapshot; + } + map.RestoreMembershipWithoutRefcount(pathId, original); + }); +} + +} // namespace + template static void GrabNew(const I& id, const C& cont, H& holder) { Y_ABORT_UNLESS(!cont.contains(id)); @@ -38,6 +62,146 @@ static void Grab(const I& id, const C& cont, H& holder) { holder.emplace(id, new T(*cont.at(id))); } +void TMemoryChanges::GrabNewTable(TSchemeShard* ss, const TPathId& pathId) { + GrabNewReferenceEntry(*this, ss->Tables, pathId); +} + +void TMemoryChanges::GrabTable(TSchemeShard* ss, const TPathId& pathId) { + GrabReferenceEntry(*this, ss->Tables, pathId); +} + +void TMemoryChanges::GrabNewIndex(TSchemeShard* ss, const TPathId& pathId) { + GrabNewReferenceEntry(*this, ss->Indexes, pathId); +} + +void TMemoryChanges::GrabIndex(TSchemeShard* ss, const TPathId& pathId) { + GrabReferenceEntry(*this, ss->Indexes, pathId); +} + +void TMemoryChanges::GrabNewSequence(TSchemeShard* ss, const TPathId& pathId) { + GrabNewReferenceEntry(*this, ss->Sequences, pathId); +} + +void TMemoryChanges::GrabSequence(TSchemeShard* ss, const TPathId& pathId) { + GrabReferenceEntry(*this, ss->Sequences, pathId); +} + +void TMemoryChanges::GrabNewCdcStream(TSchemeShard* ss, const TPathId& pathId) { + GrabNewReferenceEntry(*this, ss->CdcStreams, pathId); +} + +void TMemoryChanges::GrabCdcStream(TSchemeShard* ss, const TPathId& pathId) { + GrabReferenceEntry(*this, ss->CdcStreams, pathId); +} + +void TMemoryChanges::GrabNewReplication(TSchemeShard* ss, const TPathId& pathId) { + GrabNewReferenceEntry(*this, ss->Replications, pathId); +} + +void TMemoryChanges::GrabNewBlobDepot(TSchemeShard* ss, const TPathId& pathId) { + GrabNewReferenceEntry(*this, ss->BlobDepots, pathId); +} + +void TMemoryChanges::GrabNewTopic(TSchemeShard* ss, const TPathId& pathId) { + GrabNewReferenceEntry(*this, ss->Topics, pathId); +} + +void TMemoryChanges::GrabNewRtmrVolume(TSchemeShard* ss, const TPathId& pathId) { + GrabNewReferenceEntry(*this, ss->RtmrVolumes, pathId); +} + +void TMemoryChanges::GrabNewSolomonVolume(TSchemeShard* ss, const TPathId& pathId) { + GrabNewReferenceEntry(*this, ss->SolomonVolumes, pathId); +} + +void TMemoryChanges::GrabNewBlockStoreVolume(TSchemeShard* ss, const TPathId& pathId) { + GrabNewReferenceEntry(*this, ss->BlockStoreVolumes, pathId); +} + +void TMemoryChanges::GrabNewFileStoreInfo(TSchemeShard* ss, const TPathId& pathId) { + GrabNewReferenceEntry(*this, ss->FileStoreInfos, pathId); +} + +void TMemoryChanges::GrabNewKesusInfo(TSchemeShard* ss, const TPathId& pathId) { + GrabNewReferenceEntry(*this, ss->KesusInfos, pathId); +} + +void TMemoryChanges::GrabNewOlapStore(TSchemeShard* ss, const TPathId& pathId) { + GrabNewReferenceEntry(*this, ss->OlapStores, pathId); +} + +void TMemoryChanges::GrabNewExternalTable(TSchemeShard* ss, const TPathId& pathId) { + GrabNewReferenceEntry(*this, ss->ExternalTables, pathId); +} + +void TMemoryChanges::GrabExternalTable(TSchemeShard* ss, const TPathId& pathId) { + GrabReferenceEntry(*this, ss->ExternalTables, pathId); +} + +void TMemoryChanges::GrabNewExternalDataSource(TSchemeShard* ss, const TPathId& pathId) { + GrabNewReferenceEntry(*this, ss->ExternalDataSources, pathId); +} + +void TMemoryChanges::GrabExternalDataSource(TSchemeShard* ss, const TPathId& pathId) { + GrabReferenceEntry(*this, ss->ExternalDataSources, pathId); +} + +void TMemoryChanges::GrabNewView(TSchemeShard* ss, const TPathId& pathId) { + GrabNewReferenceEntry(*this, ss->Views, pathId); +} + +void TMemoryChanges::GrabView(TSchemeShard* ss, const TPathId& pathId) { + GrabReferenceEntry(*this, ss->Views, pathId); +} + +void TMemoryChanges::GrabNewResourcePool(TSchemeShard* ss, const TPathId& pathId) { + GrabNewReferenceEntry(*this, ss->ResourcePools, pathId); +} + +void TMemoryChanges::GrabResourcePool(TSchemeShard* ss, const TPathId& pathId) { + GrabReferenceEntry(*this, ss->ResourcePools, pathId); +} + +void TMemoryChanges::GrabNewBackupCollection(TSchemeShard* ss, const TPathId& pathId) { + GrabNewReferenceEntry(*this, ss->BackupCollections, pathId); +} + +void TMemoryChanges::GrabBackupCollection(TSchemeShard* ss, const TPathId& pathId) { + GrabReferenceEntry(*this, ss->BackupCollections, pathId); +} + +void TMemoryChanges::GrabNewSysView(TSchemeShard* ss, const TPathId& pathId) { + GrabNewReferenceEntry(*this, ss->SysViews, pathId); +} + +void TMemoryChanges::GrabSysView(TSchemeShard* ss, const TPathId& pathId) { + GrabReferenceEntry(*this, ss->SysViews, pathId); +} + +void TMemoryChanges::GrabNewSecret(TSchemeShard* ss, const TPathId& pathId) { + GrabNewReferenceEntry(*this, ss->Secrets, pathId); +} + +void TMemoryChanges::GrabSecret(TSchemeShard* ss, const TPathId& pathId) { + GrabReferenceEntry(*this, ss->Secrets, pathId); +} + +void TMemoryChanges::GrabNewStreamingQuery(TSchemeShard* ss, const TPathId& pathId) { + GrabNewReferenceEntry(*this, ss->StreamingQueries, pathId); +} + +void TMemoryChanges::GrabStreamingQuery(TSchemeShard* ss, const TPathId& pathId) { + GrabReferenceEntry(*this, ss->StreamingQueries, pathId); +} + +void TMemoryChanges::GrabNewTestShardSet(TSchemeShard* ss, const TPathId& pathId) { + GrabNewReferenceEntry(*this, ss->TestShardSets, pathId); +} + +void TMemoryChanges::GrabTestShardSet(TSchemeShard* ss, const TPathId& pathId) { + GrabReferenceEntry(*this, ss->TestShardSets, pathId); +} + void TMemoryChanges::GrabNewTxState(TSchemeShard* ss, const TOperationId& opId) { GrabNew(opId, ss->TxInFlight, TxStates); } @@ -214,7 +378,8 @@ void TMemoryChanges::UnDo(TSchemeShard* ss) { // Restore ss->SubDomains entries to saved copies of TSubDomainInfo objects. // No copy, simple pointer replacement. for (const auto& [id, savedState] : SubDomains) { - auto& subdomain = ss->SubDomains.UndoRestore(id, savedState); + ss->SubDomains.RestoreMembershipWithoutRefcount(id, savedState); + const auto& subdomain = ss->SubDomains.Update(id); if (ss->GetCurrentSubDomainPathId() == id) { subdomain->UpdateCounters(ss); } diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_memory_changes.h b/ydb/core/tx/schemeshard/schemeshard__operation_memory_changes.h index 4291ff1e58eab..de320b589912d 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_memory_changes.h +++ b/ydb/core/tx/schemeshard/schemeshard__operation_memory_changes.h @@ -20,7 +20,7 @@ class TSchemeShard; class TMemoryChanges: public TSimpleRefCount { using TPathState = std::pair; // Holds both GrabPath snapshots (non-null elem) and GrabNewPath markers (null elem). - // Subclassed to expose the underlying container for the debug-only scan below. + // Subclassed to check the snapshot required by a new reference-owning entry. struct TPathStack : TStack { bool Contains(const TPathId& id) const { for (const auto& [pid, elem] : this->c) { @@ -72,36 +72,60 @@ class TMemoryChanges: public TSimpleRefCount { using TSharedShardEntry = std::tuple>; TStack SharedShardEntries; - // Common LIFO stack for map membership changes and explicit field undo. + // Common LIFO stack for typed snapshots, new-entry markers and field undo. TStack> UndoActions; // Only the propose tx can roll back (UnDo runs only from AbortOperationPropose), // so only it records undos; other txs would just accumulate dead weight. bool Armed = false; - // Set by Arm(): the shard this armed instance is registered with, so the - // registration can be withdrawn on destruction. - TSchemeShard* SS = nullptr; - public: - // Withdraws the armed registration; see Arm(). - ~TMemoryChanges(); - - // Called from IgniteOperation. Publishes the armed window on the shard so - // undo-less mutators (TDbRefMap::erase) can assert they run outside it. + // The proposal coordinator scopes registration; containers do not know it. void Arm(TSchemeShard* ss); - - // Ends the armed window at the close of IgniteOperation, so the rest of the - // propose tx (side effects, Persist*) is not mistaken for the mutation phase. void Disarm(); - // True only inside an armed propose; tracked Set/Update are legal only then. + // Snapshot/undo registration is legal only inside a proposal. bool IsArmed() const { return Armed; } - // Debug: was this path grabbed (GrabPath/GrabNewPath) in this tx? A tracked Set() - // that acquires a ref on an ungrabbed path can't fully roll back. + // New membership requires a Paths snapshot to restore its reference count. bool IsPathTracked(const TPathId& id) const { return Paths.Contains(id); } + void GrabNewTable(TSchemeShard* ss, const TPathId& pathId); + void GrabTable(TSchemeShard* ss, const TPathId& pathId); + void GrabNewIndex(TSchemeShard* ss, const TPathId& pathId); + void GrabIndex(TSchemeShard* ss, const TPathId& pathId); + void GrabNewSequence(TSchemeShard* ss, const TPathId& pathId); + void GrabSequence(TSchemeShard* ss, const TPathId& pathId); + void GrabNewCdcStream(TSchemeShard* ss, const TPathId& pathId); + void GrabCdcStream(TSchemeShard* ss, const TPathId& pathId); + void GrabNewReplication(TSchemeShard* ss, const TPathId& pathId); + void GrabNewBlobDepot(TSchemeShard* ss, const TPathId& pathId); + void GrabNewTopic(TSchemeShard* ss, const TPathId& pathId); + void GrabNewRtmrVolume(TSchemeShard* ss, const TPathId& pathId); + void GrabNewSolomonVolume(TSchemeShard* ss, const TPathId& pathId); + void GrabNewBlockStoreVolume(TSchemeShard* ss, const TPathId& pathId); + void GrabNewFileStoreInfo(TSchemeShard* ss, const TPathId& pathId); + void GrabNewKesusInfo(TSchemeShard* ss, const TPathId& pathId); + void GrabNewOlapStore(TSchemeShard* ss, const TPathId& pathId); + void GrabNewExternalTable(TSchemeShard* ss, const TPathId& pathId); + void GrabExternalTable(TSchemeShard* ss, const TPathId& pathId); + void GrabNewExternalDataSource(TSchemeShard* ss, const TPathId& pathId); + void GrabExternalDataSource(TSchemeShard* ss, const TPathId& pathId); + void GrabNewView(TSchemeShard* ss, const TPathId& pathId); + void GrabView(TSchemeShard* ss, const TPathId& pathId); + void GrabNewResourcePool(TSchemeShard* ss, const TPathId& pathId); + void GrabResourcePool(TSchemeShard* ss, const TPathId& pathId); + void GrabNewBackupCollection(TSchemeShard* ss, const TPathId& pathId); + void GrabBackupCollection(TSchemeShard* ss, const TPathId& pathId); + void GrabNewSysView(TSchemeShard* ss, const TPathId& pathId); + void GrabSysView(TSchemeShard* ss, const TPathId& pathId); + void GrabNewSecret(TSchemeShard* ss, const TPathId& pathId); + void GrabSecret(TSchemeShard* ss, const TPathId& pathId); + void GrabNewStreamingQuery(TSchemeShard* ss, const TPathId& pathId); + void GrabStreamingQuery(TSchemeShard* ss, const TPathId& pathId); + void GrabNewTestShardSet(TSchemeShard* ss, const TPathId& pathId); + void GrabTestShardSet(TSchemeShard* ss, const TPathId& pathId); + void GrabNewTxState(TSchemeShard* ss, const TOperationId& op); void GrabNewPath(TSchemeShard* ss, const TPathId& pathId); @@ -134,9 +158,8 @@ class TMemoryChanges: public TSimpleRefCount { // Record map membership changes and explicit field undo on one LIFO stack, // so mutations are undone before an earlier insertion/replacement is undone. void RecordUndo(std::function undo) { - if (Armed) { - UndoActions.push(std::move(undo)); - } + Y_ABORT_UNLESS(Armed, "undo registration outside proposal"); + UndoActions.push(std::move(undo)); } void UnDo(TSchemeShard* ss); diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_move_sequence.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_move_sequence.cpp index 51ed1f09ff0e2..14452ef2a5ecf 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_move_sequence.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_move_sequence.cpp @@ -196,7 +196,7 @@ class TPropose: public TSubOperationState { txState->PlanStep = step; context.SS->PersistTxPlanStep(db, OperationId, step); - context.SS->Sequences.SetUntracked(pathId, alterData); + context.SS->Sequences.Set(pathId, alterData); context.SS->PersistSequenceAlterRemove(db, pathId); context.SS->PersistSequence(db, pathId, *alterData); @@ -435,7 +435,7 @@ class TProposedMoveSequence : public TSubOperationState { NIceDb::TNiceDb db(context.GetDB()); - auto& sequenceInfo = context.SS->Sequences.UpdateUntracked(pathId); + auto& sequenceInfo = context.SS->Sequences.Update(pathId); UpdateSequenceDescription(sequenceInfo->Description); context.SS->PersistSequence(db, pathId, *sequenceInfo); @@ -978,6 +978,7 @@ class TMoveSequence: public TSubOperation { txState.State = TTxState::CreateParts; Y_ABORT_UNLESS(context.SS->Sequences.contains(srcPath.Base()->PathId)); + context.MemChanges.GrabSequence(context.SS, srcPath.Base()->PathId); auto srcSequence = context.SS->Sequences.Update(srcPath.Base()->PathId); Y_ABORT_UNLESS(!srcSequence->Sharding.GetSequenceShards().empty()); @@ -985,9 +986,6 @@ class TMoveSequence: public TSubOperation { TShardIdx sequenceShard = FromProto(protoSequenceShard); TSequenceInfo::TPtr sequenceInfo = new TSequenceInfo(0); - context.MemChanges.RecordUndo([srcSequence, previous = srcSequence->AlterData]() { - srcSequence->AlterData = previous; - }); sequenceInfo->AlterData = srcSequence->CreateNextVersion(); txState.Shards.emplace_back(sequenceShard, ETabletType::SequenceShard, TTxState::ConfigureParts); @@ -1002,7 +1000,8 @@ class TMoveSequence: public TSubOperation { p->SetLocalId(ui64(sequenceShard.GetLocalId())); } - context.SS->Sequences.Set({.Path = dstPath.Base()->PathId, .Value = sequenceInfo, .Changes = context.MemChanges}); + context.MemChanges.GrabNewSequence(context.SS, dstPath.Base()->PathId); + context.SS->Sequences.Set(dstPath.Base()->PathId, sequenceInfo); IncParentDirAlterVersionWithRepublishSafeWithUndo(OperationId, dstPath, context.SS, context.OnComplete); diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_move_table.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_move_table.cpp index fd94686634236..f0d981766cd1d 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_move_table.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_move_table.cpp @@ -182,7 +182,7 @@ void MarkSrcDropped(NIceDb::TNiceDb& db, srcPath->SetDropped(txState.PlanStep, operationId.GetTxId()); context.SS->PersistDropStep(db, srcPath->PathId, txState.PlanStep, operationId); if (srcPath->IsTable()) { - context.SS->Tables.UpdateUntracked(srcPath->PathId)->DetachShardsStats(); + context.SS->Tables.Update(srcPath->PathId)->DetachShardsStats(); context.SS->PersistRemoveTable(db, srcPath->PathId, context.Ctx); } else if (srcPath->IsColumnTable()) { context.SS->PersistColumnTableRemove(db, srcPath->PathId, context.Ctx, /* skipStatsUpdate */ true); @@ -282,7 +282,7 @@ class TPropose: public TSubOperationState { tableInfo->AlterVersion += 1; // copy table info - context.SS->Tables.SetUntracked(dstPath.Base()->PathId, tableInfo); + context.SS->Tables.Set(dstPath.Base()->PathId, tableInfo); context.SS->PersistTable(db, dstPath.Base()->PathId); context.SS->PersistAllTablePartitionStats(db, dstPath.Base()->PathId, tableInfo); { @@ -506,7 +506,7 @@ class TDeleteTableBarrier: public TSubOperationState { MarkSrcDropped(db, context, OperationId, *txState, srcPath); if (srcPath->IsTable()) { Y_ABORT_UNLESS(context.SS->Tables.contains(dstPath.Base()->PathId)); - auto& tableInfo = context.SS->Tables.UpdateUntracked(dstPath.Base()->PathId); + auto& tableInfo = context.SS->Tables.Update(dstPath.Base()->PathId); if (tableInfo->IsTTLEnabled() && !context.SS->TTLEnabledTables.contains(dstPath.Base()->PathId)) { context.SS->TTLEnabledTables[dstPath.Base()->PathId] = tableInfo; diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_rotate_cdc_stream.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_rotate_cdc_stream.cpp index d8c1d09809777..e9d05776bee17 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_rotate_cdc_stream.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_rotate_cdc_stream.cpp @@ -69,11 +69,11 @@ class TPropose: public TSubOperationState { context.SS->PersistCreateStep(db, newStreamPathId, step); context.SS->PersistCdcStream(db, newStreamPathId); - context.SS->CdcStreams.SetUntracked(newStreamPathId, newStream->AlterData); + context.SS->CdcStreams.Set(newStreamPathId, newStream->AlterData); context.SS->TabletCounters->Simple()[COUNTER_CDC_STREAMS_COUNT].Add(1); context.SS->PersistCdcStream(db, oldStreamPathId); - context.SS->CdcStreams.UpdateUntracked(oldStreamPathId)->FinishAlter(); + context.SS->CdcStreams.Update(oldStreamPathId)->FinishAlter(); context.SS->ClearDescribePathCaches(oldStreamPath); context.SS->ClearDescribePathCaches(newStreamPath); @@ -221,6 +221,7 @@ class TRotateCdcStream: public TSubOperation { Y_ABORT_UNLESS(context.SS->CdcStreams.contains(oldStreamPath.Base()->PathId)); + context.MemChanges.GrabCdcStream(context.SS, oldStreamPath.Base()->PathId); auto oldStream = context.SS->CdcStreams.Update(oldStreamPath.Base()->PathId); TCdcStreamInfo::EState requiredState = TCdcStreamInfo::EState::ECdcStreamStateDisabled; @@ -372,9 +373,6 @@ class TRotateCdcStream: public TSubOperation { context.DbChanges.PersistAlterCdcStream(pathId); context.DbChanges.PersistTxState(OperationId); - context.MemChanges.RecordUndo([oldStream, previous = oldStream->AlterData]() { - oldStream->AlterData = previous; - }); auto streamAlter = oldStream->CreateNextVersion(); Y_ABORT_UNLESS(streamAlter); streamAlter->State = newState; @@ -400,7 +398,8 @@ class TRotateCdcStream: public TSubOperation { newStreamPath.Base()->PathType = TPathElement::EPathType::EPathTypeCdcStream; newStreamPath.Base()->UserAttrs->AlterData = userAttrs; - context.SS->CdcStreams.Set({.Path = pathId, .Value = newStream, .Changes = context.MemChanges}); + context.MemChanges.GrabNewCdcStream(context.SS, pathId); + context.SS->CdcStreams.Set(pathId, newStream); newStreamPath.DomainInfo()->IncPathsInside(context.SS); IncAliveChildrenSafeWithUndo(OperationId, tablePath, context); // for correct discard of ChildrenExist prop @@ -432,7 +431,7 @@ class TConfigurePartsAtTable: public NCdcStreamState::TConfigurePartsAtTable { auto path = context.SS->PathsById.at(pathId); Y_ABORT_UNLESS(context.SS->Tables.contains(pathId)); - auto& table = context.SS->Tables.UpdateUntracked(pathId); + auto& table = context.SS->Tables.Update(pathId); auto& notice = *tx.MutableRotateCdcStreamNotice(); pathId.ToProto(notice.MutablePathId()); diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_split_merge.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_split_merge.cpp index 394cd10e61394..53d3316fbf8d3 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_split_merge.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_split_merge.cpp @@ -1083,6 +1083,7 @@ class TSplitMerge: public TSubOperation { context.DbChanges.PersistShard(shard.Idx); } + context.MemChanges.GrabTable(context.SS, path->PathId); auto& mutableTableInfo = context.SS->Tables.Update(path->PathId); mutableTableInfo->RegisterSplitMergeOp(OperationId, op); @@ -1139,7 +1140,7 @@ class TSplitMerge: public TSubOperation { TPathId pathId = txState->TargetPathId; Y_ABORT_UNLESS(context.SS->Tables.contains(pathId)); - auto& tableInfo = context.SS->Tables.UpdateUntracked(pathId); + auto& tableInfo = context.SS->Tables.Update(pathId); Y_ABORT_UNLESS(tableInfo); // Undo the in-memory changes made by Propose() using inverse operations. diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_truncate_table.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_truncate_table.cpp index ace5a9622398c..aa2ac382d0f1f 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_truncate_table.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_truncate_table.cpp @@ -141,7 +141,7 @@ class TPropose: public TSubOperationState { const auto path = TPath::Init(txState->TargetPathId, context.SS); - auto& table = context.SS->Tables.UpdateUntracked(path.Base()->PathId); + auto& table = context.SS->Tables.Update(path.Base()->PathId); table->AlterVersion += 1; context.SS->PersistTableAlterVersion(db, path.Base()->PathId, table); diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_upgrade_subdomain.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_upgrade_subdomain.cpp index a1c20d60f02ea..c5fd8793605bb 100644 --- a/ydb/core/tx/schemeshard/schemeshard__operation_upgrade_subdomain.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__operation_upgrade_subdomain.cpp @@ -578,7 +578,7 @@ class TPublishGlobal: public TSubOperationState { context.SS->PersistPath(db, path->PathId); context.SS->ClearDescribePathCaches(path); - auto subDomain = context.SS->SubDomains.UpdateUntracked(pathId); + auto subDomain = context.SS->SubDomains.Update(pathId); subDomain->SetAlterPrivate(nullptr); context.SS->PersistSubDomain(db, pathId, *subDomain); context.SS->PersistSubDomainSchemeQuotas(db, pathId, *subDomain); @@ -610,9 +610,9 @@ class TPublishGlobal: public TSubOperationState { item->SwapChildren(HiddenChildren); //return back children item->PreSerializedChildrenListing.clear(); - // Copy, not a reference: the SetUntracked below reseats this slot, and + // Copy, not a reference: the Set below reseats this slot, and // *subDomain must still see the original object at PersistDeleteSubDomainAlter. - auto subDomain = context.SS->SubDomains.UpdateUntracked(pathId); + auto subDomain = context.SS->SubDomains.Update(pathId); Y_ABORT_UNLESS(subDomain); auto alterData = subDomain->GetAlter(); Y_ABORT_UNLESS(alterData); @@ -626,7 +626,7 @@ class TPublishGlobal: public TSubOperationState { subDomain->SetAlterPrivate(nullptr); alterData->SetVersion(alterData->GetVersion() + 1); - context.SS->SubDomains.SetUntracked(pathId, alterData); + context.SS->SubDomains.Set(pathId, alterData); context.SS->PersistSubDomainVersion(db, pathId, *alterData); context.SS->PersistSubDomainSchemeQuotas(db, pathId, *alterData); @@ -669,7 +669,7 @@ class TPublishGlobal: public TSubOperationState { item->PathType = TPathElement::EPathType::EPathTypeExtSubDomain; - auto subDomain = context.SS->SubDomains.UpdateUntracked(pathId); + auto subDomain = context.SS->SubDomains.Update(pathId); auto alterData = subDomain->GetAlter(); Y_ABORT_UNLESS(alterData); Y_ABORT_UNLESS(subDomain->GetVersion() < alterData->GetVersion()); @@ -679,7 +679,7 @@ class TPublishGlobal: public TSubOperationState { alterData->SetAlterPrivate(subDomain); subDomain->SetAlterPrivate(nullptr); - context.SS->SubDomains.SetUntracked(pathId, alterData); + context.SS->SubDomains.Set(pathId, alterData); item->SwapChildren(HiddenChildren); item->PreSerializedChildrenListing.clear(); diff --git a/ydb/core/tx/schemeshard/schemeshard__sync_update_tenants.cpp b/ydb/core/tx/schemeshard/schemeshard__sync_update_tenants.cpp index 1f39ab712457a..4b5a035068e5e 100644 --- a/ydb/core/tx/schemeshard/schemeshard__sync_update_tenants.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__sync_update_tenants.cpp @@ -95,7 +95,7 @@ struct TSchemeShard::TTxUpdateTenant : public TSchemeShard::TRwTxBase { MakeSync(); } - auto subdomain = Self->SubDomains.UpdateUntracked(Self->RootPathId()); + auto subdomain = Self->SubDomains.Update(Self->RootPathId()); if (record.GetSubdomainVersion() > subdomain->GetVersion()) { TStoragePools storagePools(record.GetStoragePools().begin(), record.GetStoragePools().end()); subdomain->SetStoragePools(storagePools, record.GetSubdomainVersion()); diff --git a/ydb/core/tx/schemeshard/schemeshard__table_stats.cpp b/ydb/core/tx/schemeshard/schemeshard__table_stats.cpp index 9ed9a21eefdb3..ca195492c4c3d 100644 --- a/ydb/core/tx/schemeshard/schemeshard__table_stats.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__table_stats.cpp @@ -363,7 +363,7 @@ bool TTxStoreTableStats::PersistSingleStats(const TPathId& pathId, return true; } - table = Self->Tables.UpdateUntracked(pathId); + table = Self->Tables.Update(pathId); table->UpdateShardStatsForFollower(followerId, shardIdx, newStats); // NOTE: For split-by-size and merge-by-load cases it is sufficient @@ -435,7 +435,7 @@ bool TTxStoreTableStats::PersistSingleStats(const TPathId& pathId, return true; } - table = Self->Tables.UpdateUntracked(pathId); + table = Self->Tables.Update(pathId); table->UpdateShardStats(&diskSpaceUsageDelta, shardIdx, newStats, now); if (!table->IsBackup) { @@ -462,7 +462,7 @@ bool TTxStoreTableStats::PersistSingleStats(const TPathId& pathId, return true; } - auto olapStore = Self->OlapStores.UpdateUntracked(pathId); + auto olapStore = Self->OlapStores.Update(pathId); const ui64 prevSmallBlobsBytes = olapStore->Stats.Aggregated.SmallBlobsVolumeBytes; const ui64 prevSmallBlobsCount = olapStore->Stats.Aggregated.SmallBlobsCount; olapStore->UpdateShardStats(&diskSpaceUsageDelta, shardIdx, newStats, now); diff --git a/ydb/core/tx/schemeshard/schemeshard__unmark_restore_tables.cpp b/ydb/core/tx/schemeshard/schemeshard__unmark_restore_tables.cpp index 2f19ba682332c..c66437429daa9 100644 --- a/ydb/core/tx/schemeshard/schemeshard__unmark_restore_tables.cpp +++ b/ydb/core/tx/schemeshard/schemeshard__unmark_restore_tables.cpp @@ -26,7 +26,7 @@ struct TSchemeShard::TTxUnmarkRestoreTables : public TTransactionBaseTables.contains(tableId)) { - auto table = Self->Tables.UpdateUntracked(tableId); + auto table = Self->Tables.Update(tableId); table->IsRestore = false; Self->PersistTableIsRestore(db, tableId, table); } diff --git a/ydb/core/tx/schemeshard/schemeshard_backup_incremental__progress.cpp b/ydb/core/tx/schemeshard/schemeshard_backup_incremental__progress.cpp index d177d9dd2e940..d07fd5cfa9b9d 100644 --- a/ydb/core/tx/schemeshard/schemeshard_backup_incremental__progress.cpp +++ b/ydb/core/tx/schemeshard/schemeshard_backup_incremental__progress.cpp @@ -129,7 +129,7 @@ struct TSchemeShard::TIncrementalBackup::TTxProgress: public NTabletFlatExecutor << " not found, likely dropped concurrently, ignoring offload status"); return; } - const auto& topic = Self->Topics.UpdateUntracked(shardInfo.PathId); + const auto& topic = Self->Topics.Update(shardInfo.PathId); if (!topic->Partitions.contains(partitionId)) { LOG_E("Partition with id# " << partitionId << " not found in topic with pathId# " << shardInfo.PathId); diff --git a/ydb/core/tx/schemeshard/schemeshard_cdc_stream_scan.cpp b/ydb/core/tx/schemeshard/schemeshard_cdc_stream_scan.cpp index 511a0fb3a06d9..3a093ef09b9d8 100644 --- a/ydb/core/tx/schemeshard/schemeshard_cdc_stream_scan.cpp +++ b/ydb/core/tx/schemeshard/schemeshard_cdc_stream_scan.cpp @@ -164,7 +164,7 @@ struct TSchemeShard::TCdcStreamScan::TTxProgress: public TTransactionBaseCdcStreams.UpdateUntracked(streamPathId); + auto streamInfo = Self->CdcStreams.Update(streamPathId); if (streamInfo->State != TCdcStreamInfo::EState::ECdcStreamStateScan) { LOG_W("Cannot run" << ": streamPathId# " << streamPathId @@ -246,7 +246,7 @@ struct TSchemeShard::TCdcStreamScan::TTxProgress: public TTransactionBaseCdcStreams.UpdateUntracked(streamPathId); + auto streamInfo = Self->CdcStreams.Update(streamPathId); if (streamInfo->State != TCdcStreamInfo::EState::ECdcStreamStateScan) { LOG_W("Cannot process response" << ": streamPathId# " << streamPathId @@ -341,7 +341,7 @@ struct TSchemeShard::TCdcStreamScan::TTxProgress: public TTransactionBaseCdcStreams.UpdateUntracked(streamPathId); + auto streamInfo = Self->CdcStreams.Update(streamPathId); if (streamInfo->State != TCdcStreamInfo::EState::ECdcStreamStateScan) { LOG_W("Cannot retry" << ": streamPathId# " << streamPathId @@ -379,7 +379,7 @@ struct TSchemeShard::TCdcStreamScan::TTxProgress: public TTransactionBaseResolvePathIdForDomain(pathId); Y_ABORT_UNLESS(Self->SubDomains.contains(domainPathId)); - auto domainInfo = Self->SubDomains.UpdateUntracked(domainPathId); + auto domainInfo = Self->SubDomains.Update(domainPathId); if (!Self->IsServerlessDomain(domainInfo)) { LOG_D("Unable to make a bill" diff --git a/ydb/core/tx/schemeshard/schemeshard_db_ref_map.h b/ydb/core/tx/schemeshard/schemeshard_db_ref_map.h index 4ddaaaf1596a0..48a52a30fdca4 100644 --- a/ydb/core/tx/schemeshard/schemeshard_db_ref_map.h +++ b/ydb/core/tx/schemeshard/schemeshard_db_ref_map.h @@ -1,7 +1,6 @@ #pragma once #include "schemeshard_path_db_ref.h" -#include "schemeshard__operation_memory_changes.h" #include @@ -39,9 +38,8 @@ class IDbRefMap { // THashMap holding a DbRefCount self-ref per entry: insert acquires, // erase releases. No operator[], so a missing-key read can't silently acquire. -// Set records membership undo; Update leaves mutation undo to its caller where -// proposal rollback is supported. Both belong to the armed propose phase. -// SetUntracked/UpdateUntracked/erase are for other phases (init, plan-step, progress, stats). +// Proposal rollback is coordinated at explicit Grab* call sites. The container +// itself only accounts for membership references. template class TDbRefMap : public IDbRefMap { using TInner = THashMap; @@ -52,13 +50,6 @@ class TDbRefMap : public IDbRefMap { using value_type = typename TInner::value_type; using TConstView = typename NDbRefDetail::TConstView::type; - // Designated-initializer args: Foo.Set({.Path=id, .Value=info, .Changes=ctx.MemChanges}). - struct TSetArgs { - TPathId Path; - V Value; - TMemoryChanges& Changes; - }; - // Self-registers at construction (registration can't be missed); `reason` // is the map's name, logged on each DbRefCount change. TDbRefMap(TRefLabel reason, TSchemeShard* ss, TVector& registry) @@ -81,27 +72,8 @@ class TDbRefMap : public IDbRefMap { return Map; } - // Insert/assign (acquires on new key) and record the matching undo. - V& Set(TSetArgs args) { - Y_VERIFY_DEBUG_S(args.Changes.IsArmed(), - "tracked Set on " << Reason.c_str() << " outside an armed propose; use SetUntracked"); - auto it = Map.find(args.Path); - if (it == Map.end()) { - Y_VERIFY_DEBUG_S(args.Changes.IsPathTracked(args.Path), - "Set(" << Reason.c_str() << ") acquires a ref on " << args.Path - << " but the path was not grabbed in this tx; GrabNewPath/GrabPath it first"); - args.Changes.RecordUndo([this, id = args.Path]() { UndoErase(id); }); - it = Map.emplace(args.Path, std::move(args.Value)).first; - AcquirePathDbRef(SS, args.Path, Reason); - } else { - args.Changes.RecordUndo([this, id = args.Path, old = it->second]() { UndoRestore(id, old); }); - it->second = std::move(args.Value); - } - return it->second; - } - - // Insert/assign, acquiring on new key, without recording undo (init restore, SubDomains). - V& SetUntracked(const TPathId& id, V value) { + // Insert/assign, acquiring exactly one reference on a new key. + V& Set(const TPathId& id, V value) { auto it = Map.find(id); if (it == Map.end()) { it = Map.emplace(id, std::move(value)).first; @@ -113,7 +85,7 @@ class TDbRefMap : public IDbRefMap { } // Acquires on new key, no undo. SubDomains-only. - V& EmplaceUntracked(const TPathId& id) { + V& Emplace(const TPathId& id) { auto it = Map.find(id); if (it == Map.end()) { it = Map.emplace(id, V{}).first; @@ -122,28 +94,14 @@ class TDbRefMap : public IDbRefMap { return it->second; } - // Mutable access during propose. This does NOT snapshot the object: callers - // supporting proposal rollback must record undo for the fields they change. - // Existing operations that prohibit proposal rollback keep that contract. - // Returns const V& so the pointee stays mutable (->Field), but replacing the - // slot still requires Set(). + // Mutable pointee access. Snapshotting is the caller's responsibility. + // The slot cannot be replaced through this reference. const V& Update(const TPathId& id) { - Y_VERIFY_DEBUG_S(IsProposeArmed(SS), - "Update on " << Reason.c_str() << " outside an armed propose; use UpdateUntracked"); - return Map.at(id); - } - - // Pointee-mutable access without undo, for non-transactional callers (init, stats). - // Const V& (no slot reseat); propose operations use Update(). - const V& UpdateUntracked(const TPathId& id) { return Map.at(id); } - // No undo: only legal outside an armed propose (an armed-propose erase can't roll back). + // Remove membership and release its reference. size_t erase(const TPathId& id) { - Y_VERIFY_DEBUG_S(!IsProposeArmed(SS), - "erase on " << Reason.c_str() << " during an armed propose is not reversible;" - " erase at plan step or later"); if (Map.contains(id)) { ReleasePathDbRef(SS, id, Reason); } @@ -156,7 +114,7 @@ class TDbRefMap : public IDbRefMap { // Read accessors are const-only: they never hand out a mutable slot, so a caller // can't reseat an entry (it->second = newPtr) and desync the self-ref. The // const_iterator/const V* still permit pointee mutation (->Field); the sanctioned - // mutation gates are Set/Update/UpdateUntracked. + // mutation gates are Set/Update. const_iterator find(const TPathId& id) const { return Map.find(id); } const V* FindPtr(const TPathId& id) const { return Map.FindPtr(id); } V Value(const TPathId& id, const V& def) const { return Map.Value(id, def); } @@ -184,23 +142,18 @@ class TDbRefMap : public IDbRefMap { } } -private: - // Undo is driven only by TMemoryChanges; ops must never call these. - friend class TMemoryChanges; - - // Set-undo: bring back the replaced value's original pointer (the Paths snapshot - // owns the counter). Used when Set() overwrote an existing entry. - V& UndoRestore(const TPathId& id, V value) { - auto& slot = Map[id]; - slot = std::move(value); - return slot; - } - - // Drop a tx-created entry without releasing (Paths owns the counter). - void UndoErase(const TPathId& id) { - Map.erase(id); + // Restore membership after an external snapshot has already restored path + // counters. Ordinary Set/erase would account for those references twice. + // A null value marks an entry that did not exist in the snapshot. + void RestoreMembershipWithoutRefcount(const TPathId& id, V value) { + if (value) { + Map[id] = std::move(value); + } else { + Map.erase(id); + } } +private: TRefLabel Reason; TSchemeShard* SS = nullptr; TInner Map; diff --git a/ydb/core/tx/schemeshard/schemeshard_impl.cpp b/ydb/core/tx/schemeshard/schemeshard_impl.cpp index da7bd618cecf7..ec064705c86f4 100644 --- a/ydb/core/tx/schemeshard/schemeshard_impl.cpp +++ b/ydb/core/tx/schemeshard/schemeshard_impl.cpp @@ -1018,12 +1018,12 @@ void TSchemeShard::ClearDescribePathCaches(const TPathElement::TPtr node, bool f if (node->PathType == NKikimrSchemeOp::EPathType::EPathTypePersQueueGroup) { Y_ABORT_UNLESS(Topics.contains(node->PathId)); - auto& pqGroup = Topics.UpdateUntracked(node->PathId); + auto& pqGroup = Topics.Update(node->PathId); pqGroup->PreSerializedPathDescription.clear(); pqGroup->PreSerializedPartitionsDescription.clear(); } else if (node->PathType == NKikimrSchemeOp::EPathType::EPathTypeTable) { Y_ABORT_UNLESS(Tables.contains(node->PathId)); - auto& tabletInfo = Tables.UpdateUntracked(node->PathId); + auto& tabletInfo = Tables.Update(node->PathId); tabletInfo->PreserializedTablePartitions.clear(); tabletInfo->PreserializedTablePartitionsNoKeys.clear(); tabletInfo->PreserializedTableSplitBoundaries.clear(); @@ -3069,7 +3069,7 @@ void TSchemeShard::PersistRemoveTx(NIceDb::TNiceDb& db, const TOperationId opId, void TSchemeShard::PersistTable(NIceDb::TNiceDb& db, const TPathId tableId) { Y_ABORT_UNLESS(Tables.contains(tableId)); - const auto tableInfo = Tables.UpdateUntracked(tableId); + const auto tableInfo = Tables.Update(tableId); PersistTableAltered(db, tableId, tableInfo); PersistTablePartitioning(db, tableId, tableInfo); @@ -3979,7 +3979,7 @@ void TSchemeShard::PersistBackupCollection(NIceDb::TNiceDb& db, TPathId pathId, void TSchemeShard::PersistRemoveBackupCollection(NIceDb::TNiceDb& db, TPathId pathId) { Y_ABORT_UNLESS(IsLocalId(pathId)); if (BackupCollections.contains(pathId)) { - UnregisterBackupCollectionTables(BackupCollections.UpdateUntracked(pathId)); + UnregisterBackupCollectionTables(BackupCollections.Update(pathId)); BackupCollections.erase(pathId); } @@ -4024,7 +4024,7 @@ void TSchemeShard::PersistSecret(NIceDb::TNiceDb& db, TPathId pathId) { TPathElement::TPtr elem = PathsById.at(pathId); Y_ABORT_UNLESS(Secrets.contains(pathId)); - auto& secretInfo = Secrets.UpdateUntracked(pathId); + auto& secretInfo = Secrets.Update(pathId); Y_ABORT_UNLESS(elem->IsSecret()); @@ -4041,7 +4041,7 @@ void TSchemeShard::PersistSecretRemove(NIceDb::TNiceDb& db, TPathId pathId) { } // Copy, not a reference: Secrets.erase(pathId) below destroys the slot. - auto secretInfo = Secrets.UpdateUntracked(pathId); + auto secretInfo = Secrets.Update(pathId); if (secretInfo->AlterData) { secretInfo->AlterData = nullptr; PersistSecretAlterRemove(db, pathId); @@ -4067,7 +4067,7 @@ void TSchemeShard::PersistSecretAlter(NIceDb::TNiceDb& db, TPathId pathId) { TPathElement::TPtr elem = PathsById.at(pathId); Y_ABORT_UNLESS(Secrets.contains(pathId)); - auto& secretInfo = Secrets.UpdateUntracked(pathId); + auto& secretInfo = Secrets.Update(pathId); Y_ABORT_UNLESS(elem->IsSecret()); @@ -4673,7 +4673,7 @@ void TSchemeShard::PersistOlapStoreRemove(NIceDb::TNiceDb& db, TPathId pathId, b return; } - auto& storeInfo = OlapStores.UpdateUntracked(pathId); + auto& storeInfo = OlapStores.Update(pathId); if (storeInfo->AlterData) { PersistOlapStoreAlterRemove(db, pathId); } @@ -4785,7 +4785,7 @@ void TSchemeShard::PersistColumnTableRemove(NIceDb::TNiceDb& db, TPathId pathId, // Unlink table from olap store if (!tableInfo.IsStandalone() && tableInfo.GetOlapStorePathIdVerified()) { Y_ABORT_UNLESS(OlapStores.contains(tableInfo.GetOlapStorePathIdVerified())); - auto& storeInfo = OlapStores.UpdateUntracked(tableInfo.GetOlapStorePathIdVerified()); + auto& storeInfo = OlapStores.Update(tableInfo.GetOlapStorePathIdVerified()); storeInfo->ColumnTablesUnderOperation.erase(pathId); storeInfo->ColumnTables.erase(pathId); } @@ -4842,7 +4842,7 @@ void TSchemeShard::PersistSequence(NIceDb::TNiceDb& db, TPathId pathId) TPathElement::TPtr elem = PathsById.at(pathId); Y_ABORT_UNLESS(Sequences.contains(pathId)); - auto& sequenceInfo = Sequences.UpdateUntracked(pathId); + auto& sequenceInfo = Sequences.Update(pathId); Y_ABORT_UNLESS(elem->IsSequence()); @@ -4859,7 +4859,7 @@ void TSchemeShard::PersistSequenceRemove(NIceDb::TNiceDb& db, TPathId pathId) return; } - auto& sequenceInfo = Sequences.UpdateUntracked(pathId); + auto& sequenceInfo = Sequences.Update(pathId); if (sequenceInfo->AlterData) { PersistSequenceAlterRemove(db, pathId); sequenceInfo->AlterData = nullptr; @@ -4890,7 +4890,7 @@ void TSchemeShard::PersistSequenceAlter(NIceDb::TNiceDb& db, TPathId pathId) TPathElement::TPtr elem = PathsById.at(pathId); Y_ABORT_UNLESS(Sequences.contains(pathId)); - auto& sequenceInfo = Sequences.UpdateUntracked(pathId); + auto& sequenceInfo = Sequences.Update(pathId); Y_ABORT_UNLESS(elem->IsSequence()); @@ -4925,7 +4925,7 @@ void TSchemeShard::PersistReplicationRemove(NIceDb::TNiceDb& db, TPathId pathId) return; } - auto& replicationInfo = Replications.UpdateUntracked(pathId); + auto& replicationInfo = Replications.Update(pathId); if (replicationInfo->AlterData) { replicationInfo->AlterData = nullptr; PersistReplicationAlterRemove(db, pathId); @@ -8367,7 +8367,7 @@ void TSchemeShard::FillTableDescriptionForShardIdx( bool rangeBeginInclusive, bool rangeEndInclusive, bool newTable) { Y_VERIFY_S(Tables.contains(tableId), "Unknown table id " << tableId); - auto& tinfo = Tables.UpdateUntracked(tableId); + auto& tinfo = Tables.Update(tableId); TPathElement::TPtr pinfo = *PathsById.FindPtr(tableId); TVector keyColumnIds = tinfo->FillDescriptionCache(pinfo); @@ -8429,7 +8429,7 @@ void TSchemeShard::FillTableDescriptionForShardIdx( switch (childPath->PathType) { case NKikimrSchemeOp::EPathTypeTableIndex: { Y_ABORT_UNLESS(Indexes.contains(childPathId)); - auto& info = Indexes.UpdateUntracked(childPathId); + auto& info = Indexes.Update(childPathId); DescribeTableIndex(childPathId, childName, newTable ? info->AlterData : info, false, false, *tableDescr->MutableTableIndexes()->Add() ); @@ -8440,7 +8440,7 @@ void TSchemeShard::FillTableDescriptionForShardIdx( Y_VERIFY_S(CdcStreams.contains(childPathId), "Cdc stream not found" << ": pathId# " << childPathId << ", name# " << childName); - auto& info = CdcStreams.UpdateUntracked(childPathId); + auto& info = CdcStreams.Update(childPathId); DescribeCdcStream(childPathId, childName, info, *tableDescr->MutableCdcStreams()->Add()); break; } @@ -8449,7 +8449,7 @@ void TSchemeShard::FillTableDescriptionForShardIdx( Y_VERIFY_S(Sequences.contains(childPathId), "Sequence not found" << ": path#d# " << childPathId << ", name# " << childName); - auto& info = Sequences.UpdateUntracked(childPathId); + auto& info = Sequences.Update(childPathId); DescribeSequence(childPathId, childName, info, *tableDescr->MutableSequences()->Add()); break; } @@ -9471,7 +9471,7 @@ void TSchemeShard::InitializeStatistics(const TActorContext& ctx) { } void TSchemeShard::ResolveSA() { - auto& subDomainInfo = SubDomains.UpdateUntracked(RootPathId()); + auto& subDomainInfo = SubDomains.Update(RootPathId()); if (IsServerlessDomain(subDomainInfo)) { auto resourcesDomainId = subDomainInfo->GetResourcesDomainId(); @@ -9627,7 +9627,7 @@ TDuration TSchemeShard::SendBaseStatsToSA() { << ", paths with incomplete stats: " << incompleteCount << ", at schemeshard: " << TabletID()); - if (IsServerlessDomain(SubDomains.UpdateUntracked(RootPathId()))) { + if (IsServerlessDomain(SubDomains.Update(RootPathId()))) { // In serverless subdomains several schemeshards send stats to a single SA // so we use a bigger interval with jitter. const auto max = TDuration::Seconds(SendStatsIntervalSecondsServerless); diff --git a/ydb/core/tx/schemeshard/schemeshard_impl.h b/ydb/core/tx/schemeshard/schemeshard_impl.h index 676edec304e98..a237fbb9f01e1 100644 --- a/ydb/core/tx/schemeshard/schemeshard_impl.h +++ b/ydb/core/tx/schemeshard/schemeshard_impl.h @@ -321,7 +321,7 @@ class TSchemeShard TDbRefMap Topics{"Topics", this, DbRefMaps}; TDbRefMap RtmrVolumes{"RtmrVolumes", this, DbRefMaps}; TDbRefMap SolomonVolumes{"SolomonVolumes", this, DbRefMaps}; - // Also mutated untracked in armed propose in a few places (extsubdomain dual-tracking). + // Domain snapshots are coordinated separately by GrabDomain. TDbRefMap SubDomains{"SubDomains", this, DbRefMaps}; TDbRefMap BlockStoreVolumes{"BlockStoreVolumes", this, DbRefMaps}; TDbRefMap FileStoreInfos{"FileStoreInfos", this, DbRefMaps}; @@ -350,8 +350,6 @@ class TSchemeShard THashMap Publications; THashMap TxInFlight; THashMap OwnDbRefs; // path's own type info record ref - // Non-null only inside an armed propose; undo-less mutators assert against it. - const TMemoryChanges* ArmedChanges = nullptr; THashMap LongIncrementalRestoreOps; // Simplified state tracking for sequential incremental restore diff --git a/ydb/core/tx/schemeshard/schemeshard_info_types.h b/ydb/core/tx/schemeshard/schemeshard_info_types.h index c3d777e43b006..10ba198dbb45f 100644 --- a/ydb/core/tx/schemeshard/schemeshard_info_types.h +++ b/ydb/core/tx/schemeshard/schemeshard_info_types.h @@ -1012,6 +1012,18 @@ struct TTableInfo : public TSimpleRefCount { return copy; } + // Keep the table object held by aliases such as TTLEnabledTables. Internal + // partition pointers must be rebound to the copied store on restoration. + void RestoreSnapshot(const TTableInfo& snapshot) { + Y_ABORT_UNLESS(this != &snapshot); + *this = snapshot; + for (ui64 i = 0; i < snapshot.Partitions.size(); ++i) { + Partitions[i] = PartitionStore.FindPtr(snapshot.Partitions[i]->ShardIdx); + Y_ABORT_UNLESS(Partitions[i]); + } + VerifyConsistency(); + } + struct TCreateAlterDataFeatureFlags { bool EnableTablePgTypes; bool EnableTableDatetime64; diff --git a/ydb/core/tx/schemeshard/schemeshard_path_db_ref.cpp b/ydb/core/tx/schemeshard/schemeshard_path_db_ref.cpp index f7ae7d9fed718..cc95b8745d03a 100644 --- a/ydb/core/tx/schemeshard/schemeshard_path_db_ref.cpp +++ b/ydb/core/tx/schemeshard/schemeshard_path_db_ref.cpp @@ -29,8 +29,4 @@ void ReleasePathDbRef(TSchemeShard* ss, const TPathId& pathId, TRefLabel reason) } } -bool IsProposeArmed(const TSchemeShard* ss) { - return ss && ss->ArmedChanges; -} - } // NKikimr::NSchemeShard diff --git a/ydb/core/tx/schemeshard/schemeshard_path_db_ref.h b/ydb/core/tx/schemeshard/schemeshard_path_db_ref.h index 60eacac30613f..b1df06fd2c650 100644 --- a/ydb/core/tx/schemeshard/schemeshard_path_db_ref.h +++ b/ydb/core/tx/schemeshard/schemeshard_path_db_ref.h @@ -111,8 +111,4 @@ static_assert(std::is_move_assignable_v); void AcquirePathDbRef(TSchemeShard* ss, const TPathId& pathId, TRefLabel reason); void ReleasePathDbRef(TSchemeShard* ss, const TPathId& pathId, TRefLabel reason); -// True inside an armed propose. Free function so headers holding only a forward -// declaration of TSchemeShard can assert on it. -bool IsProposeArmed(const TSchemeShard* ss); - } // NKikimr::NSchemeShard diff --git a/ydb/core/tx/schemeshard/schemeshard_path_describer.cpp b/ydb/core/tx/schemeshard/schemeshard_path_describer.cpp index b8bc13ce5af75..38da2f2f35ba9 100644 --- a/ydb/core/tx/schemeshard/schemeshard_path_describer.cpp +++ b/ydb/core/tx/schemeshard/schemeshard_path_describer.cpp @@ -1670,7 +1670,7 @@ void TSchemeShard::DescribeCdcStream(const TPathId& pathId, const TString& name, Y_VERIFY_S(CdcStreams.contains(pathId), "Cdc stream not found" << ": pathId# " << pathId << ", name# " << name); - DescribeCdcStream(pathId, name, CdcStreams.UpdateUntracked(pathId), desc); + DescribeCdcStream(pathId, name, CdcStreams.Update(pathId), desc); } void TSchemeShard::DescribeCdcStream(const TPathId& pathId, const TString& name, const TIntrusiveConstPtr& info, diff --git a/ydb/core/tx/schemeshard/ut_base/ut_db_ref_map.cpp b/ydb/core/tx/schemeshard/ut_base/ut_db_ref_map.cpp index 80e5d1034ba9b..2c78e9077e0f7 100644 --- a/ydb/core/tx/schemeshard/ut_base/ut_db_ref_map.cpp +++ b/ydb/core/tx/schemeshard/ut_base/ut_db_ref_map.cpp @@ -67,9 +67,9 @@ Y_UNIT_TEST_SUITE(TDbRefMapTest) { auto first = MakeIntrusive(); auto second = MakeIntrusive(); - ss.Tables.SetUntracked(pathId, first); + ss.Tables.Set(pathId, first); UNIT_ASSERT_VALUES_EQUAL(ss.PathsById.at(pathId)->DbRefCount, initialRefs + 1); - ss.Tables.SetUntracked(pathId, second); + ss.Tables.Set(pathId, second); UNIT_ASSERT_EQUAL(ss.Tables.at(pathId).Get(), second.Get()); UNIT_ASSERT_VALUES_EQUAL(ss.PathsById.at(pathId)->DbRefCount, initialRefs + 1); UNIT_ASSERT_VALUES_EQUAL(ss.Tables.erase(pathId), 1); @@ -90,10 +90,12 @@ Y_UNIT_TEST_SUITE(TDbRefMapTest) { TMemoryChanges changes; changes.Arm(&ss); changes.GrabPath(&ss, pathId); - ss.Tables.Set({.Path = pathId, .Value = first, .Changes = changes}); + changes.GrabNewTable(&ss, pathId); + ss.Tables.Set(pathId, first); changes.RecordUndo([first]() { first->AlterVersion = 10; }); first->AlterVersion = 11; - ss.Tables.Set({.Path = pathId, .Value = second, .Changes = changes}); + changes.GrabTable(&ss, pathId); + ss.Tables.Set(pathId, second); changes.RecordUndo([second]() { second->AlterVersion = 20; }); second->AlterVersion = 21; UNIT_ASSERT_VALUES_EQUAL(ss.PathsById.at(pathId)->DbRefCount, initialRefs + 1); @@ -115,7 +117,7 @@ Y_UNIT_TEST_SUITE(TDbRefMapTest) { auto second = MakeIntrusive(); first->AlterVersion = 10; second->AlterVersion = 20; - ss.Tables.SetUntracked(pathId, first); + ss.Tables.Set(pathId, first); const auto initialRefs = ss.PathsById.at(pathId)->DbRefCount; TMemoryChanges changes; @@ -123,7 +125,8 @@ Y_UNIT_TEST_SUITE(TDbRefMapTest) { changes.GrabPath(&ss, pathId); changes.RecordUndo([first]() { first->AlterVersion = 10; }); ss.Tables.Update(pathId)->AlterVersion = 11; - ss.Tables.Set({.Path = pathId, .Value = second, .Changes = changes}); + changes.GrabTable(&ss, pathId); + ss.Tables.Set(pathId, second); changes.RecordUndo([second]() { second->AlterVersion = 20; }); ss.Tables.Update(pathId)->AlterVersion = 21; @@ -143,7 +146,7 @@ Y_UNIT_TEST_SUITE(TDbRefMapTest) { table->SetPartitioning(MakeShards(2)); auto previous = MakeIntrusive(); table->AlterData = previous; - ss.Tables.SetUntracked(pathId, table); + ss.Tables.Set(pathId, table); const auto* alias = table.Get(); const auto* partition = table->GetPartitions().front(); const auto* stats = &table->GetStats().PartitionStats.at(partition->ShardIdx); @@ -169,13 +172,77 @@ Y_UNIT_TEST_SUITE(TDbRefMapTest) { }); } + Y_UNIT_TEST(GrabTableRestoresStateAndKeepsAliases) { + WithSchemeShard([](TSchemeShard& ss, const TPathId& pathId) { + auto table = MakeIntrusive(); + table->SetPartitioning(MakeShards(3)); + table->AlterVersion = 10; + auto previousAlter = MakeIntrusive(); + table->AlterData = previousAlter; + ss.Tables.Set(pathId, table); + ss.TTLEnabledTables[pathId] = table; + const auto initialRefs = ss.PathsById.at(pathId)->DbRefCount; + const auto initialOwners = table.RefCount(); + + TMemoryChanges changes; + changes.Arm(&ss); + changes.GrabTable(&ss, pathId); + table->AlterVersion = 20; + table->AlterData = MakeIntrusive(); + // Destroy the original storage. A shallow snapshot would retain + // pointers to those old partition nodes after rollback. + table->SetPartitioning(MakeShards(2, 2)); + ss.Tables.Set(pathId, MakeIntrusive()); + changes.UnDo(&ss); + changes.Disarm(); + + UNIT_ASSERT_EQUAL(ss.Tables.at(pathId).Get(), table.Get()); + UNIT_ASSERT_EQUAL(ss.TTLEnabledTables.at(pathId).Get(), table.Get()); + UNIT_ASSERT_VALUES_EQUAL(table.RefCount(), initialOwners); + UNIT_ASSERT_VALUES_EQUAL(table->AlterVersion, 10); + UNIT_ASSERT_EQUAL(table->AlterData.Get(), previousAlter.Get()); + UNIT_ASSERT_VALUES_EQUAL(table->GetPartitions().size(), 3); + for (ui32 i = 0; i < 3; ++i) { + UNIT_ASSERT_EQUAL(table->GetPartitions()[i]->ShardIdx, TShardIdx(1, i)); + } + // Both the snapshot and original storage are gone now. + table->VerifyConsistency(); + UNIT_ASSERT_VALUES_EQUAL(ss.PathsById.at(pathId)->DbRefCount, initialRefs); + ss.TTLEnabledTables.erase(pathId); + ss.Tables.erase(pathId); + }); + } + + Y_UNIT_TEST(RepeatedTypedSnapshotsRestoreInReverseOrder) { + WithSchemeShard([](TSchemeShard& ss, const TPathId& pathId) { + auto table = MakeIntrusive(); + table->SetPartitioning(MakeShards(2)); + table->AlterVersion = 10; + ss.Tables.Set(pathId, table); + + TMemoryChanges changes; + changes.Arm(&ss); + changes.GrabTable(&ss, pathId); + table->AlterVersion = 20; + changes.GrabTable(&ss, pathId); + table->AlterVersion = 30; + changes.UnDo(&ss); + changes.Disarm(); + + UNIT_ASSERT_EQUAL(ss.Tables.at(pathId).Get(), table.Get()); + UNIT_ASSERT_VALUES_EQUAL(table->AlterVersion, 10); + table->VerifyConsistency(); + ss.Tables.erase(pathId); + }); + } + Y_UNIT_TEST(UpdateDoesNotSnapshotTwoHundredThousandShards) { WithSchemeShard([](TSchemeShard& ss, const TPathId& pathId) { constexpr ui32 shardCount = 200000; auto table = MakeIntrusive(); table->SetPartitioning(MakeShards(shardCount)); table->AlterData = MakeIntrusive(); - ss.Tables.SetUntracked(pathId, table); + ss.Tables.Set(pathId, table); UNIT_ASSERT_VALUES_EQUAL(table->GetStats().PartitionStats.size(), shardCount); const auto* partition = table->GetPartitions().front(); const auto* stats = &table->GetStats().PartitionStats.at(partition->ShardIdx);