Skip to content

Commit

Permalink
Add reinit step for build vector index (#9176)
Browse files Browse the repository at this point in the history
  • Loading branch information
MBkkt authored Sep 20, 2024
1 parent 06f4e89 commit 07fc231
Show file tree
Hide file tree
Showing 15 changed files with 307 additions and 70 deletions.
2 changes: 1 addition & 1 deletion ydb/core/protos/flat_scheme_op.proto
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ message TMkDir {

enum EDropWaitPolicy {
EDropFailOnChanges = 0;
EDropAbortChanges = 1; //depricated
EDropAbortChanges = 1; //deprecated
EDropWaitChanges = 2;
}

Expand Down
2 changes: 1 addition & 1 deletion ydb/core/protos/flat_tx_scheme.proto
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ message TEvModifySchemeTransaction {
optional uint64 TxId = 2;
optional uint64 TabletId = 3;
optional string Owner = 5;
optional bool FailOnExist = 6; // depricated, TModifyScheme.FailOnExist is recomended
optional bool FailOnExist = 6; // deprecated, TModifyScheme.FailOnExist is recomended
optional string UserToken = 7 [(Ydb.sensitive) = true]; // serialized NACLib::TUserToken
optional string PeerName = 8;
}
Expand Down
2 changes: 1 addition & 1 deletion ydb/core/tx/schemeshard/schemeshard__operation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1335,7 +1335,7 @@ TVector<ISubOperation::TPtr> TOperation::ConstructParts(const TTxTransaction& tx
Y_ABORT("multipart operations are handled before, also they require transaction details");

case NKikimrSchemeOp::EOperationType::ESchemeOpInitiateBuildIndexImplTable:
Y_ABORT("multipart operations are handled before, also they require transaction details");
return {CreateInitializeBuildIndexImplTable(NextPartId(), tx)};
case NKikimrSchemeOp::EOperationType::ESchemeOpFinalizeBuildIndexImplTable:
Y_ABORT("multipart operations are handled before, also they require transaction details");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ ISubOperation::TPtr FinalizeIndexImplTable(TOperationContext& context, const TPa
return CreateFinalizeBuildIndexImplTable(partId, transaction);
}

ISubOperation::TPtr DropIndexImplTable(TOperationContext& /*context*/, const TPath& index, const TOperationId& nextId, const TOperationId& partId, const TString& name, const TPathId& pathId) {
ISubOperation::TPtr DropIndexImplTable(const TPath& index, const TOperationId& nextId, const TOperationId& partId, const TString& name, const TPathId& pathId, bool& rejected) {
TPath implTable = index.Child(name);
Y_ABORT_UNLESS(implTable->PathId == pathId);
Y_ABORT_UNLESS(implTable.LeafName() == name);
Expand All @@ -41,8 +41,10 @@ ISubOperation::TPtr DropIndexImplTable(TOperationContext& /*context*/, const TPa
.NotUnderDeleting()
.NotUnderOperation();
if (!checks) {
return {CreateReject(nextId, checks.GetStatus(), checks.GetError())};
rejected = true;
return CreateReject(nextId, checks.GetStatus(), checks.GetError());
}
rejected = false;
auto transaction = TransactionTemplate(index.PathString(), NKikimrSchemeOp::EOperationType::ESchemeOpDropTable);
auto operation = transaction.MutableDrop();
operation->SetName(name);
Expand Down Expand Up @@ -93,7 +95,12 @@ TVector<ISubOperation::TPtr> ApplyBuildIndex(TOperationId nextId, const TTxTrans
const auto& indexImplTableName = indexChildItems.first;
const auto partId = NextPartId(nextId, result);
if (NTableIndex::IsTmpImplTable(indexImplTableName)) {
result.push_back(DropIndexImplTable(context, index, nextId, partId, indexImplTableName, indexChildItems.second));
bool rejected = false;
auto op = DropIndexImplTable(index, nextId, partId, indexImplTableName, indexChildItems.second, rejected);
if (rejected) {
return {std::move(op)};
}
result.push_back(std::move(op));
} else {
result.push_back(FinalizeIndexImplTable(context, index, partId, indexImplTableName, indexChildItems.second));
}
Expand Down Expand Up @@ -143,7 +150,12 @@ TVector<ISubOperation::TPtr> CancelBuildIndex(TOperationId nextId, const TTxTran
Y_ABORT_UNLESS(index.Base()->GetChildren().size() >= 1);
for (auto& indexChildItems : index.Base()->GetChildren()) {
const auto partId = NextPartId(nextId, result);
result.push_back(DropIndexImplTable(context, index, nextId, partId, indexChildItems.first, indexChildItems.second));
bool rejected = false;
auto op = DropIndexImplTable(index, nextId, partId, indexChildItems.first, indexChildItems.second, rejected);
if (rejected) {
return {std::move(op)};
}
result.push_back(std::move(op));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ TVector<ISubOperation::TPtr> CreateBuildIndex(TOperationId opId, const TTxTransa
.NotResolved();
}

// TODO(mbkkt) less than necessary for vector index
checks
.IsValidLeafName()
.PathsLimit(2) // index and impl-table
Expand Down
11 changes: 8 additions & 3 deletions ydb/core/tx/schemeshard/schemeshard__operation_create_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -447,9 +447,14 @@ class TCreateTable: public TSubOperation {

if (checks) {
if (parentPath.Base()->IsTableIndex()) {
checks.IsInsideTableIndexPath()
.IsUnderCreating(NKikimrScheme::StatusNameConflict)
.IsUnderTheSameOperation(OperationId.GetTxId()); //allow only as part of creating base table
checks.IsInsideTableIndexPath();
// Not tmp index impl tables can be created only as part of create index
// tmp index impl tables created multiple times during index construction
if (!NTableIndex::IsTmpImplTable(name)) {
checks
.IsUnderCreating(NKikimrScheme::StatusNameConflict)
.IsUnderTheSameOperation(OperationId.GetTxId());
}
} else if (!Transaction.GetAllowAccessToPrivatePaths()) {
checks.IsCommonSensePath()
.IsLikeDirectory();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -396,11 +396,10 @@ TVector<ISubOperation::TPtr> CreateDropIndexedTable(TOperationId nextId, const T
auto dropOperation = tx.GetDrop();

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

TPath table = dropOperation.HasId()
? TPath::Init(TPathId(context.SS->TabletID(), dropOperation.GetId()), context.SS)
: TPath::Resolve(parentPathStr, context.SS).Dive(name);
: TPath::Resolve(parentPathStr, context.SS).Dive(dropOperation.GetName());

{
TPath::TChecker checks = table.Check();
Expand All @@ -425,8 +424,10 @@ TVector<ISubOperation::TPtr> CreateDropIndexedTable(TOperationId nextId, const T
checks
.IsTable()
.NotUnderDeleting()
.NotUnderOperation()
.IsCommonSensePath();
.NotUnderOperation();
if (!table.Parent()->IsTableIndex() || !NTableIndex::IsTmpImplTable(table.LeafName())) {
checks.IsCommonSensePath();
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,7 @@ class TDropTable: public TSubOperation {
.IsTableIndex()
.IsInsideTableIndexPath();
// Not tmp index impl tables can be dropped only as part of drop index
// tmp index impl tables dropped multiple times during index construction
if (!NTableIndex::IsTmpImplTable(name)) {
checks
.IsUnderDeleting()
Expand Down
Loading

0 comments on commit 07fc231

Please sign in to comment.