Skip to content

Commit e3f8a97

Browse files
authored
Merge 85df583 into 8404d71
2 parents 8404d71 + 85df583 commit e3f8a97

12 files changed

+346
-129
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: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -484,22 +484,18 @@ bool TTxStoreTableStats::PersistSingleStats(const TPathId& pathId,
484484
return true;
485485
}
486486

487-
{
488-
auto path = TPath::Init(pathId, Self);
489-
auto checks = path.Check();
490-
491-
constexpr ui64 deltaShards = 2;
492-
checks
493-
.PathShardsLimit(deltaShards)
494-
.ShardsLimit(deltaShards);
495-
496-
if (!checks) {
497-
LOG_NOTICE_S(ctx, NKikimrServices::FLAT_TX_SCHEMESHARD,
498-
"Do not request full stats from datashard"
499-
<< ", datashard: " << datashardId
500-
<< ", reason: " << checks.GetError());
501-
return true;
502-
}
487+
auto path = TPath::Init(pathId, Self);
488+
auto checks = path.Check();
489+
constexpr ui64 deltaShards = 2;
490+
checks
491+
.PathShardsLimit(deltaShards)
492+
.ShardsLimit(deltaShards);
493+
if (!checks) {
494+
LOG_NOTICE_S(ctx, NKikimrServices::FLAT_TX_SCHEMESHARD,
495+
"Do not request full stats from datashard"
496+
<< ", datashard: " << datashardId
497+
<< ", reason: " << checks.GetError());
498+
return true;
503499
}
504500

505501
if (newStats.HasBorrowedData) {
@@ -509,6 +505,12 @@ bool TTxStoreTableStats::PersistSingleStats(const TPathId& pathId,
509505
return true;
510506
}
511507

508+
if (path.IsLocked()) {
509+
LOG_DEBUG_S(ctx, NKikimrServices::FLAT_TX_SCHEMESHARD,
510+
"Postpone split tablet " << datashardId << " because it is locked by " << path.LockedBy());
511+
return true;
512+
}
513+
512514
// Request histograms from the datashard
513515
LOG_DEBUG_S(ctx, NKikimrServices::FLAT_TX_SCHEMESHARD,
514516
"Requesting full tablet stats " << datashardId << " to split it");

ydb/core/tx/schemeshard/schemeshard__table_stats_histogram.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,7 @@ bool TTxPartitionHistogram::Execute(TTransactionContext& txc, const TActorContex
341341
}
342342

343343
TTableInfo::TPtr table = Self->Tables[tableId];
344+
auto path = TPath::Init(tableId, Self);
344345

345346
if (!Self->TabletIdToShardIdx.contains(datashardId)) {
346347
LOG_DEBUG_S(ctx, NKikimrServices::FLAT_TX_SCHEMESHARD,
@@ -355,6 +356,12 @@ bool TTxPartitionHistogram::Execute(TTransactionContext& txc, const TActorContex
355356
return true;
356357
}
357358

359+
if (path.IsLocked()) {
360+
LOG_DEBUG_S(ctx, NKikimrServices::FLAT_TX_SCHEMESHARD,
361+
"TTxPartitionHistogram Skip locked table tablet " << datashardId << " by " << path.LockedBy());
362+
return true;
363+
}
364+
358365
auto shardIdx = Self->TabletIdToShardIdx[datashardId];
359366
const auto forceShardSplitSettings = Self->SplitSettings.GetForceShardSplitSettings();
360367

0 commit comments

Comments
 (0)