Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions ydb/core/tx/schemeshard/index/operation_alter_index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,7 @@ class TAlterTableIndex: public TSubOperation {
context.DbChanges.PersistAlterIndex(indexPath->PathId);
context.DbChanges.PersistTxState(OperationId);

auto indexData = context.SS->Indexes.Update(indexPath->PathId);
context.MemChanges.RecordUndo([indexData, previous = indexData->AlterData]() {
indexData->AlterData = previous;
});
auto& indexData = context.SS->Indexes.Update(indexPath->PathId, context.MemChanges);
TTableIndexInfo::TPtr newIndexData = indexData->CreateNextVersion();
Y_ABORT_UNLESS(newIndexData);
newIndexData->State = tableIndexAlter.GetState();
Expand Down
8 changes: 1 addition & 7 deletions ydb/core/tx/schemeshard/schemeshard__operation_alter_bsv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,6 @@ class TAlterBlockStoreVolume: public TSubOperation {
TBlockStorePartitionInfo::TPtr part = new TBlockStorePartitionInfo();
part->PartitionId = i + volume->DefaultPartitionCount;
part->AlterVersion = volume->AlterData->AlterVersion;
context.MemChanges.RecordUndo([volume, shardIdx]() {
volume->Shards.erase(shardIdx);
});
volume->Shards[shardIdx] = std::move(part);
}

Expand Down Expand Up @@ -442,7 +439,7 @@ class TAlterBlockStoreVolume: public TSubOperation {
}
}

auto volume = context.SS->BlockStoreVolumes.Update(path.Base()->PathId);
auto& volume = context.SS->BlockStoreVolumes.Update(path.Base()->PathId, context.MemChanges);
Y_ABORT_UNLESS(volume);

const auto* alterVolumeConfig = ParseParams(volume->VolumeConfig, alter, errStr);
Expand Down Expand Up @@ -600,9 +597,6 @@ class TAlterBlockStoreVolume: public TSubOperation {
alterData->DefaultPartitionCount =
TBlockStoreVolumeInfo::CalculateDefaultPartitionCount(alterData->VolumeConfig);
alterData->ExplicitChannelProfileCount = alterData->VolumeConfig.ExplicitChannelProfilesSize();
context.MemChanges.RecordUndo([volume, previous = volume->AlterData]() {
volume->AlterData = previous;
});
volume->PrepareAlter(alterData);

auto newVolumeSpace = volume->GetVolumeSpace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ class TAlterCdcStream: public TSubOperation {
}

Y_ABORT_UNLESS(context.SS->CdcStreams.contains(streamPath.Base()->PathId));
auto stream = context.SS->CdcStreams.Update(streamPath.Base()->PathId);
auto& stream = context.SS->CdcStreams.Update(streamPath.Base()->PathId, context.MemChanges);

TCdcStreamInfo::EState requiredState = TCdcStreamInfo::EState::ECdcStreamStateInvalid;
TCdcStreamInfo::EState newState = TCdcStreamInfo::EState::ECdcStreamStateInvalid;
Expand Down Expand Up @@ -201,9 +201,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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ struct TParamsDelta {
};

std::tuple<NKikimrScheme::EStatus, TString>
VerifyParams(TParamsDelta* delta, const TPathId pathId, const TIntrusiveConstPtr<TSubDomainInfo>& current,
VerifyParams(TParamsDelta* delta, const TPathId pathId, const TSubDomainInfo::TPtr& current,
const NKikimrSubDomains::TSubDomainSettings& input, const bool isServerlessExclusiveDynamicNodesEnabled) {
auto paramError = [](const TStringBuf& msg) {
return std::make_tuple(NKikimrScheme::EStatus::StatusInvalidParameter,
Expand Down Expand Up @@ -342,7 +342,7 @@ VerifyParams(TParamsDelta* delta, const TPathId pathId, const TIntrusiveConstPtr
}

void VerifyParams(TProposeResponse* result, TParamsDelta* delta, const TPathId pathId,
const TIntrusiveConstPtr<TSubDomainInfo>& current, const NKikimrSubDomains::TSubDomainSettings& input,
const TSubDomainInfo::TPtr& current, const NKikimrSubDomains::TSubDomainSettings& input,
const bool isServerlessExclusiveDynamicNodesEnabled) {
// TProposeRespose should come in assuming positive outcome (status NKikimrScheme::StatusAccepted, no errors)
Y_ABORT_UNLESS(result->IsAccepted());
Expand All @@ -354,7 +354,6 @@ void RegisterChanges(const TTxState& txState, const TTxId operationTxId, TOperat
const auto& basenameId = path.Base()->PathId;

context.MemChanges.GrabPath(context.SS, basenameId);
context.MemChanges.GrabDomain(context.SS, basenameId);

// Registering shards is a bit complicated as every shard should be registered
// in many places:
Expand Down Expand Up @@ -621,7 +620,7 @@ class TAlterExtSubDomainCreateHive: public TSubOperation {

// Get existing extsubdomain
Y_ABORT_UNLESS(context.SS->SubDomains.contains(basenameId));
auto subdomainInfo = context.SS->SubDomains.Update(basenameId);
auto& subdomainInfo = context.SS->SubDomains.Update(basenameId, context.MemChanges);
Y_ABORT_UNLESS(subdomainInfo);

auto result = MakeHolder<TProposeResponse>(NKikimrScheme::StatusAccepted, ui64(OperationId.GetTxId()), ui64(schemeshardTabletId));
Expand Down Expand Up @@ -873,7 +872,7 @@ class TAlterExtSubDomain: public TSubOperation {

// Get existing extsubdomain
Y_ABORT_UNLESS(context.SS->SubDomains.contains(basenameId));
auto subdomainInfo = context.SS->SubDomains.Update(basenameId);
auto& subdomainInfo = context.SS->SubDomains.Update(basenameId, context.MemChanges);
Y_ABORT_UNLESS(subdomainInfo);

auto result = MakeHolder<TProposeResponse>(NKikimrScheme::StatusAccepted, ui64(OperationId.GetTxId()), ui64(schemeshardTabletId));
Expand Down Expand Up @@ -1134,7 +1133,7 @@ TVector<ISubOperation::TPtr> CreateCompatibleAlterExtSubDomain(TOperationId id,
const auto& basenameId = path.Base()->PathId;

Y_ABORT_UNLESS(context.SS->SubDomains.contains(basenameId));
auto subdomainInfo = context.SS->SubDomains.at(basenameId);
auto& subdomainInfo = context.SS->SubDomains.Update(basenameId, context.MemChanges);
Y_ABORT_UNLESS(subdomainInfo);

if (subdomainInfo->GetAlter()) {
Expand Down
6 changes: 1 addition & 5 deletions ydb/core/tx/schemeshard/schemeshard__operation_alter_fs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ THolder<TProposeResponse> TAlterFileStore::Propose(

Y_ABORT_UNLESS(path.Base()->IsCreateFinished());

auto fs = context.SS->FileStoreInfos.Update(path.Base()->PathId);
auto& fs = context.SS->FileStoreInfos.Update(path.Base()->PathId, context.MemChanges);
Y_VERIFY_S(fs, "FileStore info is null. PathId: " << path.Base()->PathId);

if (fs->AlterConfig) {
Expand Down Expand Up @@ -397,10 +397,6 @@ THolder<TProposeResponse> TAlterFileStore::Propose(

const auto oldFileStoreSpace = fs->GetFileStoreSpace();

context.MemChanges.RecordUndo([fs, version = fs->AlterVersion]() {
fs->AlterConfig.Reset();
fs->AlterVersion = version;
});
fs->PrepareAlter(*alterConfig);

const auto newFileStoreSpace = fs->GetFileStoreSpace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ class TAlterKesus: public TSubOperation {
return result;
}

auto kesus = context.SS->KesusInfos.Update(path.Base()->PathId);
auto& kesus = context.SS->KesusInfos.Update(path.Base()->PathId, context.MemChanges);
Y_ABORT_UNLESS(kesus);
Y_ABORT_UNLESS(path.Base()->IsCreateFinished()); // checks.NotUnderOperation checks that path not under creation

Expand All @@ -331,10 +331,6 @@ class TAlterKesus: public TSubOperation {
return result;
}

context.MemChanges.RecordUndo([kesus, version = kesus->AlterVersion]() {
kesus->AlterConfig.Reset();
kesus->AlterVersion = version;
});
kesus->AlterConfig.Reset(new Ydb::Coordination::Config);
kesus->AlterConfig->CopyFrom(kesus->Config);
kesus->AlterConfig->MergeFrom(*alterConfig);
Expand Down
52 changes: 3 additions & 49 deletions ydb/core/tx/schemeshard/schemeshard__operation_alter_pq.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -400,9 +400,6 @@ class TAlterPQ: public TSubOperation {
TString prevBound;
for (size_t i = 0; i < partitions.size(); ++i) {
auto* partitionInfo = partitions[i].second;
context.MemChanges.RecordUndo([pqGroup, id = partitionInfo->PqId, previous = partitionInfo->KeyRange]() {
pqGroup->Partitions.at(id)->KeyRange = previous;
});
if (i) {
partitionInfo->KeyRange.ConstructInPlace();
partitionInfo->KeyRange->FromBound = prevBound;
Expand All @@ -422,24 +419,12 @@ class TAlterPQ: public TSubOperation {
for (auto& [shardIdx, tabletInfo] : pqGroup->Shards) {
for (const auto& partitionInfo : tabletInfo->Partitions) {
if (splitMergeWasDisabled) {
context.MemChanges.RecordUndo([pqGroup, id = partitionInfo->PqId,
status = partitionInfo->Status, keyRange = partitionInfo->KeyRange,
parents = partitionInfo->ParentPartitionIds, children = partitionInfo->ChildPartitionIds]() {
auto* partition = pqGroup->Partitions.at(id);
partition->Status = status;
partition->KeyRange = keyRange;
partition->ParentPartitionIds = parents;
partition->ChildPartitionIds = children;
});
// clear all splitmerge fields
partitionInfo->Status = NKikimrPQ::ETopicPartitionStatus::Active;
partitionInfo->KeyRange.Clear();
partitionInfo->ParentPartitionIds.clear();
partitionInfo->ChildPartitionIds.clear();
} else if (const auto* range = pqGroup->AlterData->KeyRangesToChange.FindPtr(partitionInfo->PqId)) {
context.MemChanges.RecordUndo([pqGroup, id = partitionInfo->PqId, previous = partitionInfo->KeyRange]() {
pqGroup->Partitions.at(id)->KeyRange = previous;
});
partitionInfo->KeyRange = *range;
}
context.SS->PersistPersQueue(db, item->PathId, shardIdx, *partitionInfo.Get());
Expand Down Expand Up @@ -556,17 +541,11 @@ class TAlterPQ: public TSubOperation {
txState.Shards.emplace_back(idx, ETabletType::PersQueue, TTxState::CreateParts);

context.SS->RegisterShardInfo(idx, defaultShardInfo);
context.MemChanges.RecordUndo([pqGroup, idx]() {
pqGroup->Shards.erase(idx);
});
pqGroup->Shards[idx] = new TTopicTabletInfo();
}

if (!hasBalancer) {
const auto idx = context.SS->NextShardIdx(startShardIdx, pqShardsToCreate);
context.MemChanges.RecordUndo([pqGroup, previous = pqGroup->BalancerShardIdx]() {
pqGroup->BalancerShardIdx = previous;
});
pqGroup->BalancerShardIdx = idx;
txState.Shards.emplace_back(idx, ETabletType::PersQueueReadBalancer, TTxState::CreateParts);
context.SS->RegisterShardInfo(idx,
Expand All @@ -585,12 +564,12 @@ class TAlterPQ: public TSubOperation {
<< " hasBalancer " << hasBalancer);

if (!pqGroup->AlterData->PartitionsToAdd.empty()) {
ReassignIds(pqGroup, context);
ReassignIds(pqGroup);
}
return shardsToCreate > 0;
}

void ReassignIds(TTopicInfo::TPtr pqGroup, TOperationContext& context) {
void ReassignIds(TTopicInfo::TPtr pqGroup) {
Y_ABORT_UNLESS(pqGroup->TotalPartitionCount >= pqGroup->TotalGroupCount);
ui32 numOld = pqGroup->TotalPartitionCount;
ui32 numNew = pqGroup->AlterData->PartitionsToAdd.size() + numOld;
Expand Down Expand Up @@ -620,34 +599,12 @@ class TAlterPQ: public TSubOperation {

for (const auto parentId : partition->ParentPartitionIds) {
auto* parent = pqGroup->Partitions[parentId];
context.MemChanges.RecordUndo([pqGroup, parentId, status = parent->Status, version = parent->AlterVersion]() {
auto* parent = pqGroup->Partitions.at(parentId);
parent->Status = status;
parent->AlterVersion = version;
});
parent->Status = NKikimrPQ::ETopicPartitionStatus::Inactive;
parent->AlterVersion = alterVersion;
}

context.MemChanges.RecordUndo([pqGroup, tablet = it->second,
id = partition->PqId, size = it->second->Partitions.size()]() {
pqGroup->Partitions.erase(id);
tablet->Partitions.resize(size);
});
pqGroup->AddPartition(it->first, partition.Release());
}
// InitSplitMergeGraph adds reverse edges, including edges on existing
// partition objects shared by the topic's lookup structures.
for (const auto& [id, partition] : pqGroup->Partitions) {
for (const auto parentId : partition->ParentPartitionIds) {
auto* parent = pqGroup->Partitions.at(parentId);
if (!parent->ChildPartitionIds.contains(id)) {
context.MemChanges.RecordUndo([pqGroup, parentId, id]() {
pqGroup->Partitions.at(parentId)->ChildPartitionIds.erase(id);
});
}
}
}
pqGroup->InitSplitMergeGraph();
}

Expand Down Expand Up @@ -703,7 +660,7 @@ class TAlterPQ: public TSubOperation {
}
}

auto topic = context.SS->Topics.Update(path.Base()->PathId);
auto& topic = context.SS->Topics.Update(path.Base()->PathId, context.MemChanges);
Y_ABORT_UNLESS(topic);

if (topic->AlterVersion == 0) {
Expand Down Expand Up @@ -1258,9 +1215,6 @@ class TAlterPQ: public TSubOperation {
pqChannelsBinding = tabletChannelsBinding;
}

context.MemChanges.RecordUndo([topic, previous = topic->AlterData]() {
topic->AlterData = previous;
});
topic->PrepareAlter(alterData);
const TTxState& txState = PrepareChanges(OperationId, path, topic, shardsToCreate, tabletChannelsBinding,
pqChannelsBinding, context, tabletConfig, newTabletConfig);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ class TAlterReplication: public TSubOperation {
}

Y_ABORT_UNLESS(context.SS->Replications.contains(path.Base()->PathId));
auto replication = context.SS->Replications.Update(path.Base()->PathId);
auto& replication = context.SS->Replications.Update(path.Base()->PathId, context.MemChanges);

if (replication->AlterVersion == 0) {
result->SetError(NKikimrScheme::StatusMultipleModifications, "Replication is not created yet");
Expand Down Expand Up @@ -442,9 +442,6 @@ class TAlterReplication: public TSubOperation {
return result;
}

context.MemChanges.RecordUndo([replication, previous = replication->AlterData]() {
replication->AlterData = previous;
});
auto alterData = replication->CreateNextVersion();

if (op.HasState()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ class TAlterSecret: public TSubOperation {
}

Y_ABORT_UNLESS(context.SS->Secrets.contains(secretPath.Base()->PathId));
auto secretInfo = context.SS->Secrets.Update(secretPath.Base()->PathId);
auto& secretInfo = context.SS->Secrets.Update(secretPath.Base()->PathId, context.MemChanges);

if (secretInfo->AlterVersion == 0) {
result->SetError(NKikimrScheme::StatusMultipleModifications, "Secret is not created yet");
Expand Down Expand Up @@ -195,9 +195,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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ class TAlterSequence: public TSubOperation {
}

Y_ABORT_UNLESS(context.SS->Sequences.contains(dstPath->PathId));
auto sequenceInfo = context.SS->Sequences.Update(dstPath->PathId);
auto& sequenceInfo = context.SS->Sequences.Update(dstPath->PathId, context.MemChanges);
Y_ABORT_UNLESS(!sequenceInfo->AlterData);

const NScheme::TTypeRegistry* typeRegistry = AppData()->TypeRegistry;
Expand All @@ -503,9 +503,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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ class TAlterSolomon: public TSubOperation {
}
}

auto solomon = context.SS->SolomonVolumes.Update(path.Base()->PathId);
auto& solomon = context.SS->SolomonVolumes.Update(path.Base()->PathId, context.MemChanges);

if (!alter.HasPartitionCount() && !alter.GetUpdateChannelsBinding()) {
result->SetError(NKikimrScheme::StatusInvalidParameter, "Empty alter");
Expand Down Expand Up @@ -322,9 +322,6 @@ class TAlterSolomon: public TSubOperation {
path.Base()->IncShardsInside(shardsToCreate);
}

context.MemChanges.RecordUndo([solomon, previous = solomon->AlterData]() {
solomon->AlterData = previous;
});
solomon->AlterData = alterSolomon;
context.SS->PersistAlterSolomonVolume(db, path.Base()->PathId, solomon);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class TAlterSubDomain: public TSubOperation {
TPathElement::TPtr subDomain = path.Base();

Y_ABORT_UNLESS(context.SS->SubDomains.contains(subDomain->PathId));
auto subDomainInfo = context.SS->SubDomains.Update(subDomain->PathId);
auto& subDomainInfo = context.SS->SubDomains.Update(subDomain->PathId, context.MemChanges);
Y_ABORT_UNLESS(subDomainInfo);

if (subDomainInfo->GetAlter()) {
Expand Down Expand Up @@ -340,7 +340,6 @@ class TAlterSubDomain: public TSubOperation {
PersistShards(db, txState, shardsToCreate, context.SS);
context.SS->PersistUpdateNextShardIdx(db);
}
context.MemChanges.GrabDomain(context.SS, subDomain->PathId);
subDomainInfo->SetAlter(alterData);
context.SS->PersistSubDomainAlter(db, subDomain->PathId, *alterData);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ class TAlterTable: public TSubOperation {
}

Y_ABORT_UNLESS(context.SS->Tables.contains(path.Base()->PathId));
auto table = context.SS->Tables.Update(path.Base()->PathId);
auto& table = context.SS->Tables.Update(path.Base()->PathId, context.MemChanges);

if (context.SS->IsTableInBackupCollection(path.Base()->PathId)) {
result->SetError(NKikimrScheme::StatusPreconditionFailed,
Expand Down Expand Up @@ -774,11 +774,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);

Expand Down
Loading