Skip to content

Commit 7f51899

Browse files
authored
Merge a41e906 into 0c26a6d
2 parents 0c26a6d + a41e906 commit 7f51899

12 files changed

+332
-112
lines changed

ydb/core/kqp/ut/indexes/kqp_indexes_ut.cpp

Lines changed: 158 additions & 0 deletions
Large diffs are not rendered by default.

ydb/core/tx/schemeshard/schemeshard__operation_apply_build_index.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ ISubOperation::TPtr FinalizeIndexImplTable(TOperationContext& context, const TPa
3030
return CreateFinalizeBuildIndexImplTable(partId, transaction);
3131
}
3232

33-
ISubOperation::TPtr DropIndexImplTable(const TPath& index, const TOperationId& nextId, const TOperationId& partId, const TString& name, const TPathId& pathId, bool& rejected) {
33+
ISubOperation::TPtr DropIndexImplTable(const TPath& index, const TOperationId& nextId, const TOperationId& partId, const TString& name, const TPathId& pathId, const NKikimrSchemeOp::TLockGuard& lockGuard, bool& rejected) {
3434
TPath implTable = index.Child(name);
3535
Y_ABORT_UNLESS(implTable->PathId == pathId);
3636
Y_ABORT_UNLESS(implTable.LeafName() == name);
@@ -48,6 +48,9 @@ ISubOperation::TPtr DropIndexImplTable(const TPath& index, const TOperationId& n
4848
}
4949
rejected = false;
5050
auto transaction = TransactionTemplate(index.PathString(), NKikimrSchemeOp::EOperationType::ESchemeOpDropTable);
51+
if (implTable.IsLocked()) { // some impl tables may be not locked
52+
*transaction.MutableLockGuard() = lockGuard;
53+
}
5154
auto operation = transaction.MutableDrop();
5255
operation->SetName(name);
5356
return CreateDropTable(partId, transaction);
@@ -98,7 +101,7 @@ TVector<ISubOperation::TPtr> ApplyBuildIndex(TOperationId nextId, const TTxTrans
98101
const auto partId = NextPartId(nextId, result);
99102
if (NTableIndex::IsBuildImplTable(indexImplTableName)) {
100103
bool rejected = false;
101-
auto op = DropIndexImplTable(index, nextId, partId, indexImplTableName, indexChildItems.second, rejected);
104+
auto op = DropIndexImplTable(index, nextId, partId, indexImplTableName, indexChildItems.second, tx.GetLockGuard(), rejected);
102105
if (rejected) {
103106
return {std::move(op)};
104107
}
@@ -153,7 +156,7 @@ TVector<ISubOperation::TPtr> CancelBuildIndex(TOperationId nextId, const TTxTran
153156
for (auto& indexChildItems : index.Base()->GetChildren()) {
154157
const auto partId = NextPartId(nextId, result);
155158
bool rejected = false;
156-
auto op = DropIndexImplTable(index, nextId, partId, indexChildItems.first, indexChildItems.second, rejected);
159+
auto op = DropIndexImplTable(index, nextId, partId, indexChildItems.first, indexChildItems.second, tx.GetLockGuard(), rejected);
157160
if (rejected) {
158161
return {std::move(op)};
159162
}

ydb/core/tx/schemeshard/schemeshard__operation_create_lock.cpp

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ class TCreateLock: public TSubOperation {
9595
THolder<TProposeResponse> Propose(const TString&, TOperationContext& context) override {
9696
const auto& workingDir = Transaction.GetWorkingDir();
9797
const auto& op = Transaction.GetLockConfig();
98+
const auto lockTxId = Transaction.HasLockGuard() && Transaction.GetLockGuard().HasOwnerTxId()
99+
? TTxId(Transaction.GetLockGuard().GetOwnerTxId())
100+
: OperationId.GetTxId();
98101

99102
LOG_N("TCreateLock Propose"
100103
<< ": opId# " << OperationId
@@ -158,17 +161,19 @@ class TCreateLock: public TSubOperation {
158161
const auto pathId = tablePath.Base()->PathId;
159162
result->SetPathId(pathId.LocalPathId);
160163

161-
if (tablePath.LockedBy() == OperationId.GetTxId()) {
162-
result->SetError(NKikimrScheme::StatusAlreadyExists, TStringBuilder() << "path checks failed"
163-
<< ", path already locked by this operation"
164-
<< ", path: " << tablePath.PathString());
165-
return result;
166-
}
167-
168-
TString errStr;
169-
if (!context.SS->CheckLocks(pathId, Transaction, errStr)) {
170-
result->SetError(NKikimrScheme::StatusMultipleModifications, errStr);
171-
return result;
164+
if (auto lockedBy = tablePath.LockedBy(); lockedBy != InvalidTxId) {
165+
if (lockedBy == lockTxId) {
166+
result->SetError(NKikimrScheme::StatusAlreadyExists, TStringBuilder() << "path checks failed"
167+
<< ", path already locked by this operation"
168+
<< ", path: " << tablePath.PathString());
169+
return result;
170+
} else {
171+
result->SetError(NKikimrScheme::StatusMultipleModifications, TStringBuilder() << "path checks failed"
172+
<< ", path already locked by another operation"
173+
<< ", path: " << tablePath.PathString()
174+
<< ", locked by: " << lockedBy);
175+
return result;
176+
}
172177
}
173178

174179
auto guard = context.DbGuard();
@@ -177,7 +182,7 @@ class TCreateLock: public TSubOperation {
177182
context.MemChanges.GrabNewTxState(context.SS, OperationId);
178183

179184
context.DbChanges.PersistPath(pathId);
180-
context.DbChanges.PersistLongLock(pathId, OperationId.GetTxId());
185+
context.DbChanges.PersistLongLock(pathId, lockTxId);
181186
context.DbChanges.PersistTxState(OperationId);
182187

183188
Y_ABORT_UNLESS(!context.SS->FindTx(OperationId));
@@ -194,7 +199,7 @@ class TCreateLock: public TSubOperation {
194199
context.OnComplete.Dependence(splitOpId.GetTxId(), OperationId.GetTxId());
195200
}
196201

197-
context.SS->LockedPaths[pathId] = OperationId.GetTxId();
202+
context.SS->LockedPaths[pathId] = lockTxId;
198203
context.SS->TabletCounters->Simple()[COUNTER_LOCKS_COUNT].Add(1);
199204

200205
context.OnComplete.ActivateTx(OperationId);

ydb/core/tx/schemeshard/schemeshard__operation_drop_lock.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ class TDropLock: public TSubOperation {
164164
const auto pathId = dstPath.Base()->PathId;
165165
result->SetPathId(pathId.LocalPathId);
166166

167-
if (!dstPath.LockedBy()) {
167+
if (!dstPath.IsLocked()) {
168168
result->SetError(TEvSchemeShard::EStatus::StatusAlreadyExists, TStringBuilder() << "path checks failed"
169169
<< ", path already unlocked"
170170
<< ", path: " << dstPath.PathString());

ydb/core/tx/schemeshard/schemeshard__table_stats.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,12 @@ bool TTxStoreTableStats::PersistSingleStats(const TPathId& pathId,
509509
return true;
510510
}
511511

512+
if (auto lock = Self->LockedPaths.FindPtr(pathId); lock) {
513+
LOG_DEBUG_S(ctx, NKikimrServices::FLAT_TX_SCHEMESHARD,
514+
"Postpone split tablet " << datashardId << " because it is locked by " << *lock);
515+
return true;
516+
}
517+
512518
// Request histograms from the datashard
513519
LOG_DEBUG_S(ctx, NKikimrServices::FLAT_TX_SCHEMESHARD,
514520
"Requesting full tablet stats " << datashardId << " to split it");

ydb/core/tx/schemeshard/schemeshard__table_stats_histogram.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,12 @@ bool TTxPartitionHistogram::Execute(TTransactionContext& txc, const TActorContex
355355
return true;
356356
}
357357

358+
if (auto lock = Self->LockedPaths.FindPtr(tableId); lock) {
359+
LOG_DEBUG_S(ctx, NKikimrServices::FLAT_TX_SCHEMESHARD,
360+
"TTxPartitionHistogram Skip locked table tablet " << datashardId << " by " << *lock);
361+
return true;
362+
}
363+
358364
auto shardIdx = Self->TabletIdToShardIdx[datashardId];
359365
const auto forceShardSplitSettings = Self->SplitSettings.GetForceShardSplitSettings();
360366

0 commit comments

Comments
 (0)