Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

return grandchildren flag #13307

Merged
merged 1 commit into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ydb/core/protos/flat_scheme_op.proto
Original file line number Diff line number Diff line change
Expand Up @@ -1862,6 +1862,7 @@ message TDirEntry {
optional uint64 PathVersion = 13;
optional EPathSubType PathSubType = 14;
optional TPathVersion Version = 15;
optional bool ChildrenExist = 16;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Это не будет работать, потому что при добавлении потомка мы публикуем родителя, но не прародителя. Так например добавляем в директории A директорию B, на директории B у A будет ChildrenExist==false, но при добавлении потомка в директории B директория A останется в кешах и не обновится, в итоге флаг будет неправильный.


optional uint64 BalancerTabletID = 999; //temporary optimization for old PQ read/write protocol. Must be removed later
}
Expand Down
2 changes: 1 addition & 1 deletion ydb/core/tx/schemeshard/olap/operations/create_store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ class TCreateOlapStore: public TSubOperation {
dstPath.DomainInfo()->IncPathsInside();
dstPath.DomainInfo()->AddInternalShards(txState);
dstPath.Base()->IncShardsInside(shardsToCreate);
parentPath.Base()->IncAliveChildren();
IncAliveChildrenDirect(OperationId, parentPath, context); // for correct discard of ChildrenExist prop

SetState(NextState());
return result;
Expand Down
2 changes: 1 addition & 1 deletion ydb/core/tx/schemeshard/olap/operations/create_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,7 @@ class TCreateColumnTable: public TSubOperation {
dstPath.DomainInfo()->AddInternalShards(txState);
dstPath.Base()->IncShardsInside(tableInfo->GetOwnedColumnShardsVerified().size());
}
parentPath.Base()->IncAliveChildren();
IncAliveChildrenDirect(OperationId, parentPath, context); // for correct discard of ChildrenExist prop

SetState(NextState(!!storeInfo));
return result;
Expand Down
2 changes: 1 addition & 1 deletion ydb/core/tx/schemeshard/olap/operations/drop_store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class TPropose: public TSubOperationState {

auto domainInfo = context.SS->ResolveDomainInfo(pathId);
domainInfo->DecPathsInside();
parentDir->DecAliveChildren();
DecAliveChildrenDirect(OperationId, parentDir, context); // for correct discard of ChildrenExist prop

context.SS->TabletCounters->Simple()[COUNTER_USER_ATTRIBUTES_COUNT].Sub(path->UserAttrs->Size());
context.SS->PersistUserAttributes(db, path->PathId, path->UserAttrs, nullptr);
Expand Down
2 changes: 1 addition & 1 deletion ydb/core/tx/schemeshard/olap/operations/drop_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class TPropose: public TSubOperationState {

auto domainInfo = context.SS->ResolveDomainInfo(pathId);
domainInfo->DecPathsInside();
parentDir->DecAliveChildren();
DecAliveChildrenDirect(OperationId, parentDir, context); // for correct discard of ChildrenExist prop

context.SS->TabletCounters->Simple()[COUNTER_USER_ATTRIBUTES_COUNT].Sub(path->UserAttrs->Size());
context.SS->PersistUserAttributes(db, path->PathId, path->UserAttrs, nullptr);
Expand Down
2 changes: 1 addition & 1 deletion ydb/core/tx/schemeshard/schemeshard__init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4112,7 +4112,7 @@ struct TSchemeShard::TTxInit : public TTransactionBase<TSchemeShard> {

if (!path->IsRoot()) {
const bool isBackupTable = Self->IsBackupTable(item.first);
parent->IncAliveChildren(1, isBackupTable);
parent->IncAliveChildrenPrivate(isBackupTable);
inclusiveDomainInfo->IncPathsInside(1, isBackupTable);
}

Expand Down
6 changes: 3 additions & 3 deletions ydb/core/tx/schemeshard/schemeshard__operation_blob_depot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ namespace NKikimr::NSchemeShard {

return !txState->ShardsInProgress;
}

TString DebugHint() const override {
return TStringBuilder() << "TConfigureBlobDepotParts id# " << OperationId;
}
Expand Down Expand Up @@ -377,10 +377,10 @@ namespace NKikimr::NSchemeShard {
dstPath.DomainInfo()->IncPathsInside();
dstPath.DomainInfo()->AddInternalShards(txState);
dstPath->IncShardsInside();
parentPath->IncAliveChildren();
IncAliveChildrenDirect(OperationId, parentPath, context); // for correct discard of ChildrenExist prop

SetState(TTxState::CreateParts);

auto resp = MakeHolder<TProposeResponse>(NKikimrScheme::StatusAccepted, txId, ssId);
resp->SetPathId(pathId.LocalPathId);
return resp;
Expand Down
48 changes: 48 additions & 0 deletions ydb/core/tx/schemeshard/schemeshard__operation_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1170,6 +1170,54 @@ void IncParentDirAlterVersionWithRepublish(const TOperationId& opId, const TPath
}
}

void IncAliveChildrenSafeWithUndo(const TOperationId& opId, const TPath& parentPath, TOperationContext& context, bool isBackup) {
parentPath.Base()->IncAliveChildrenPrivate(isBackup);
if (parentPath.Base()->GetAliveChildren() == 1 && !parentPath.Base()->IsDomainRoot()) {
auto grandParent = parentPath.Parent();
if (grandParent.Base()->IsLikeDirectory()) {
++grandParent.Base()->DirAlterVersion;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Как я понял в случае изменения parentPath мы закладываемся на то, что вызывающий код уже вызвал на нём context.MemChanges.GrabPath (хорошо бы кстати это как-то валидировать). А каким образом обеспечивается SafeWithUndo, если на этот grandParent вызывающий код скорее всего ничего такого не сделал?

context.MemChanges.GrabPath(context.SS, grandParent.Base()->PathId);
context.DbChanges.PersistPath(grandParent.Base()->PathId);
}

if (grandParent.IsActive()) {
context.SS->ClearDescribePathCaches(grandParent.Base());
context.OnComplete.PublishToSchemeBoard(opId, grandParent->PathId);
}
}
}

void IncAliveChildrenDirect(const TOperationId& opId, const TPath& parentPath, TOperationContext& context, bool isBackup) {
parentPath.Base()->IncAliveChildrenPrivate(isBackup);
if (parentPath.Base()->GetAliveChildren() == 1 && !parentPath.Base()->IsDomainRoot()) {
auto grandParent = parentPath.Parent();
if (grandParent.Base()->IsLikeDirectory()) {
++grandParent.Base()->DirAlterVersion;
NIceDb::TNiceDb db(context.GetDB());
context.SS->PersistPathDirAlterVersion(db, grandParent.Base());
}

if (grandParent.IsActive()) {
context.SS->ClearDescribePathCaches(grandParent.Base());
context.OnComplete.PublishToSchemeBoard(opId, grandParent->PathId);
}
}
}

void DecAliveChildrenDirect(const TOperationId& opId, TPathElement::TPtr parentPath, TOperationContext& context, bool isBackup) {
parentPath->DecAliveChildrenPrivate(isBackup);
if (parentPath->GetAliveChildren() == 0 && !parentPath->IsDomainRoot()) {
auto grandParentDir = context.SS->PathsById.at(parentPath->ParentPathId);
if (grandParentDir->IsLikeDirectory()) {
++grandParentDir->DirAlterVersion;
NIceDb::TNiceDb db(context.GetDB());
context.SS->PersistPathDirAlterVersion(db, grandParentDir);
context.SS->ClearDescribePathCaches(grandParentDir);
context.OnComplete.PublishToSchemeBoard(opId, grandParentDir->PathId);
}
}
}

NKikimrSchemeOp::TModifyScheme MoveTableTask(NKikimr::NSchemeShard::TPath& src, NKikimr::NSchemeShard::TPath& dst) {
NKikimrSchemeOp::TModifyScheme scheme;

Expand Down
5 changes: 5 additions & 0 deletions ydb/core/tx/schemeshard/schemeshard__operation_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ TSet<ui32> AllIncomingEvents();
void IncParentDirAlterVersionWithRepublishSafeWithUndo(const TOperationId& opId, const TPath& path, TSchemeShard* ss, TSideEffects& onComplete);
void IncParentDirAlterVersionWithRepublish(const TOperationId& opId, const TPath& path, TOperationContext& context);

void IncAliveChildrenSafeWithUndo(const TOperationId& opId, const TPath& parentPath, TOperationContext& context, bool isBackup = false);
void IncAliveChildrenDirect(const TOperationId& opId, const TPath& parentPath, TOperationContext& context, bool isBackup = false);
void DecAliveChildrenDirect(const TOperationId& opId, TPathElement::TPtr parentPath, TOperationContext& context, bool isBackup = false);


NKikimrSchemeOp::TModifyScheme MoveTableTask(NKikimr::NSchemeShard::TPath& src, NKikimr::NSchemeShard::TPath& dst);
NKikimrSchemeOp::TModifyScheme MoveTableIndexTask(NKikimr::NSchemeShard::TPath& src, NKikimr::NSchemeShard::TPath& dst);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,7 @@ class TCopySequence: public TSubOperation {
context.OnComplete.PublishToSchemeBoard(OperationId, dstPath->PathId);

domainInfo->IncPathsInside();
parentPath->IncAliveChildren();
IncAliveChildrenDirect(OperationId, parentPath, context); // for correct discard of ChildrenExist prop

SetState(NextState());
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ class TCopyTable: public TSubOperation {
dstPath.DomainInfo()->IncPathsInside(1, isBackup);
dstPath.DomainInfo()->AddInternalShards(txState, isBackup);
dstPath.Base()->IncShardsInside(shardsToCreate);
parent.Base()->IncAliveChildren(1, isBackup);
IncAliveChildrenSafeWithUndo(OperationId, parent, context, isBackup);

LOG_TRACE_S(context.Ctx, NKikimrServices::FLAT_TX_SCHEMESHARD,
"TCopyTable Propose creating new table"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,6 @@ class TCreateBackupCollection : public TSubOperation {
return backupCollection;
}

static void UpdatePathSizeCounts(const TPath& parentPath, const TPath& dstPath) {
dstPath.DomainInfo()->IncPathsInside();
parentPath.Base()->IncAliveChildren();
}

public:
using TSubOperation::TSubOperation;

Expand Down Expand Up @@ -177,7 +172,7 @@ class TCreateBackupCollection : public TSubOperation {
AddPathInSchemeShard(result, dstPath, owner);
auto pathEl = CreateBackupCollectionPathElement(dstPath);

rootPath->IncAliveChildren();
adameat marked this conversation as resolved.
Show resolved Hide resolved
IncAliveChildrenDirect(OperationId, rootPath, context); // for correct discard of ChildrenExist prop
rootPath.DomainInfo()->IncPathsInside();

auto backupCollection = TBackupCollectionInfo::Create(desc);
Expand Down Expand Up @@ -220,8 +215,6 @@ class TCreateBackupCollection : public TSubOperation {
context.SS,
context.OnComplete);

UpdatePathSizeCounts(rootPath, dstPath);

SetState(NextState());
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ class TCreateBlockStoreVolume: public TSubOperation {
dstPath.DomainInfo()->IncPathsInside();
dstPath.DomainInfo()->AddInternalShards(txState);
dstPath.Base()->IncShardsInside(shardsToCreate);
parentPath.Base()->IncAliveChildren();
IncAliveChildrenDirect(OperationId, parentPath, context); // for correct discard of ChildrenExist prop

SetState(NextState());
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ class TNewCdcStream: public TSubOperation {
context.SS->IncrementPathDbRefCount(pathId);

streamPath.DomainInfo()->IncPathsInside();
tablePath.Base()->IncAliveChildren();
IncAliveChildrenSafeWithUndo(OperationId, tablePath, context); // for correct discard of ChildrenExist prop

context.OnComplete.ActivateTx(OperationId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,6 @@ class TCreateExternalDataSource : public TSubOperation {
context.SS->PersistTxState(db, OperationId);
}

static void UpdatePathSizeCounts(const TPath& parentPath, const TPath& dstPath) {
dstPath.DomainInfo()->IncPathsInside();
parentPath.Base()->IncAliveChildren();
}

public:
using TSubOperation::TSubOperation;

Expand Down Expand Up @@ -283,7 +278,8 @@ class TCreateExternalDataSource : public TSubOperation {
context.SS,
context.OnComplete);

UpdatePathSizeCounts(parentPath, dstPath);
dstPath.DomainInfo()->IncPathsInside();
IncAliveChildrenDirect(OperationId, parentPath, context); // for correct discard of ChildrenExist prop

SetState(NextState());
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,12 +285,6 @@ class TCreateExternalTable: public TSubOperation {
context.SS->PersistTxState(db, OperationId);
}

static void UpdatePathSizeCounts(const TPath& parentPath,
const TPath& dstPath) {
dstPath.DomainInfo()->IncPathsInside();
parentPath.Base()->IncAliveChildren();
}

public:
using TSubOperation::TSubOperation;

Expand Down Expand Up @@ -376,7 +370,8 @@ class TCreateExternalTable: public TSubOperation {
context.SS,
context.OnComplete);

UpdatePathSizeCounts(parentPath, dstPath);
dstPath.DomainInfo()->IncPathsInside();
IncAliveChildrenDirect(OperationId, parentPath, context); // for correct discard of ChildrenExist prop

SetState(NextState());
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ class TCreateExtSubDomain: public TSubOperation {

Y_ABORT_UNLESS(0 == txState.Shards.size());
parentPath.DomainInfo()->IncPathsInside();
parentPath.Base()->IncAliveChildren();
IncAliveChildrenDirect(OperationId, parentPath, context); // for correct discard of ChildrenExist prop

SetState(NextState());
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ THolder<TProposeResponse> TCreateFileStore::Propose(
dstPath.DomainInfo()->IncPathsInside();
dstPath.DomainInfo()->AddInternalShards(txState);
dstPath.Base()->IncShardsInside(shardsToCreate);
parentPath.Base()->IncAliveChildren();
IncAliveChildrenDirect(OperationId, parentPath, context); // for correct discard of ChildrenExist prop

SetState(NextState());
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ class TCreateTableIndex: public TSubOperation {
context.OnComplete.ActivateTx(OperationId);

dstPath.DomainInfo()->IncPathsInside();
parentPath.Base()->IncAliveChildren();
IncAliveChildrenSafeWithUndo(OperationId, parentPath, context); // for correct discard of ChildrenExist prop

SetState(NextState());
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ class TCreateKesus: public TSubOperation {
dstPath.DomainInfo()->AddInternalShards(txState);

dstPath.Base()->IncShardsInside();
parentPath.Base()->IncAliveChildren();
IncAliveChildrenDirect(OperationId, parentPath, context); // for correct discard of ChildrenExist prop

SetState(NextState());
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ class TCreatePQ: public TSubOperation {
context.SS->TabletCounters->Simple()[COUNTER_STREAM_SHARDS_COUNT].Add(StreamShardsCountChange);

dstPath.Base()->IncShardsInside(shardsToCreate);
parentPath.Base()->IncAliveChildren();
IncAliveChildrenSafeWithUndo(OperationId, parentPath, context); // for correct discard of ChildrenExist prop

SetState(NextState());
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ class TCreateReplication: public TSubOperation {
result->SetPathId(path->PathId.LocalPathId);

context.SS->IncrementPathDbRefCount(path->PathId);
parentPath->IncAliveChildren();
IncAliveChildrenDirect(OperationId, parentPath, context); // for correct discard of ChildrenExist prop
parentPath.DomainInfo()->IncPathsInside();

if (desc.GetConfig().GetSrcConnectionParams().GetCredentialsCase() == NKikimrReplication::TConnectionParams::CREDENTIALS_NOT_SET) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,6 @@ class TCreateResourcePool : public TSubOperation {
return resourcePool;
}

static void UpdatePathSizeCounts(const TPath& parentPath, const TPath& dstPath) {
dstPath.DomainInfo()->IncPathsInside();
parentPath.Base()->IncAliveChildren();
}

public:
using TSubOperation::TSubOperation;

Expand Down Expand Up @@ -187,7 +182,8 @@ class TCreateResourcePool : public TSubOperation {

IncParentDirAlterVersionWithRepublishSafeWithUndo(OperationId, dstPath, context.SS, context.OnComplete);

UpdatePathSizeCounts(parentPath, dstPath);
dstPath.DomainInfo()->IncPathsInside();
IncAliveChildrenDirect(OperationId, parentPath, context); // for correct discard of ChildrenExist prop

SetState(NextState());
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ class TCreateRTMR: public TSubOperation {
dstPath.DomainInfo()->AddInternalShards(txState);

dstPath.Base()->IncShardsInside(shardsToCreate);
parentPath.Base()->IncAliveChildren();
IncAliveChildrenDirect(OperationId, parentPath, context); // for correct discard of ChildrenExist prop

SetState(NextState());
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ class TCreateSequence : public TSubOperation {
context.OnComplete.PublishToSchemeBoard(OperationId, dstPath->PathId);

domainInfo->IncPathsInside();
parentPath->IncAliveChildren();
IncAliveChildrenDirect(OperationId, parentPath, context); // for correct discard of ChildrenExist prop

SetState(NextState());
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ class TCreateSolomon: public TSubOperation {
dstPath.DomainInfo()->AddInternalShards(txState);

dstPath.Base()->IncShardsInside(shardsToCreate);
parentPath.Base()->IncAliveChildren();
IncAliveChildrenDirect(OperationId, parentPath, context); // for correct discard of ChildrenExist prop

SetState(NextState());
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ class TCreateSubDomain: public TSubOperation {
dstPath.DomainInfo()->AddInternalShards(txState);

dstPath.Base()->IncShardsInside(shardsToCreate);
parentPath.Base()->IncAliveChildren();
IncAliveChildrenDirect(OperationId, parentPath, context); // for correct discard of ChildrenExist prop

SetState(NextState());
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,7 @@ class TCreateTable: public TSubOperation {
dstPath.DomainInfo()->AddInternalShards(txState);

dstPath.Base()->IncShardsInside(shardsToCreate);
parentPath.Base()->IncAliveChildren();
IncAliveChildrenDirect(OperationId, parentPath, context); // for correct discard of ChildrenExist prop

LOG_TRACE_S(context.Ctx, NKikimrServices::FLAT_TX_SCHEMESHARD,
"TCreateTable Propose creating new table"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,8 @@ class TCreateView: public TSubOperation {

dstPath.MaterializeLeaf(owner, viewPathId);
dstPath.DomainInfo()->IncPathsInside();
parentPath.Base()->IncAliveChildren();
IncAliveChildrenSafeWithUndo(OperationId, parentPath, context); // for correct discard of ChildrenExist prop

result->SetPathId(viewPathId.LocalPathId);

TPathElement::TPtr viewPath = dstPath.Base();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class TPropose : public TSubOperationState {

auto domainInfo = context.SS->ResolveDomainInfo(pathId);
domainInfo->DecPathsInside();
parentDirPtr->DecAliveChildren();
DecAliveChildrenDirect(OperationId, parentDirPtr, context); // for correct discard of ChildrenExist prop
context.SS->TabletCounters->Simple()[COUNTER_BACKUP_COLLECTION_COUNT].Sub(1);

++parentDirPtr->DirAlterVersion;
Expand Down
Loading
Loading