Skip to content

Commit ce71c9a

Browse files
committed
schemeshard: remove unreasonable iteration over entire ShardInfos
PathShardsLimit() performs pedantic validation of the path's current shards count by recalculating it through iteration over ShardInfos of the entire database and matching them to the path (!). See CollectAllShards(). That is unreasonable and too slow for the hot spot that is PersistSingleStats(). (Though appropriate for slow paths like TSubOperation::Propose() etc.) Replacing PathShardsLimit() also eliminates aditional TPath construction and hashmap lookup.
1 parent 5b25abe commit ce71c9a

File tree

1 file changed

+30
-14
lines changed

1 file changed

+30
-14
lines changed

ydb/core/tx/schemeshard/schemeshard__table_stats.cpp

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -475,18 +475,32 @@ bool TTxStoreTableStats::PersistSingleStats(const TPathId& pathId,
475475
return true;
476476
}
477477

478-
auto path = TPath::Init(pathId, Self);
479-
auto checks = path.Check();
480-
constexpr ui64 deltaShards = 2;
481-
checks
482-
.PathShardsLimit(deltaShards)
483-
.ShardsLimit(deltaShards);
484-
if (!checks) {
485-
LOG_NOTICE_S(ctx, NKikimrServices::FLAT_TX_SCHEMESHARD,
486-
"Do not request full stats from datashard"
487-
<< ", datashard: " << datashardId
488-
<< ", reason: " << checks.GetError());
489-
return true;
478+
//NOTE: intentionally avoid using TPath.Check().{PathShardsLimit,ShardsLimit}() here.
479+
// PathShardsLimit() performs pedantic validation by recalculating shard count through
480+
// iteration over entire ShardInfos, which is too slow for this hot spot. It also performs
481+
// additional lookups we want to avoid.
482+
{
483+
constexpr ui64 deltaShards = 2;
484+
if ((pathElement->GetShardsInside() + deltaShards) > subDomainInfo->GetSchemeLimits().MaxShardsInPath) {
485+
LOG_NOTICE_S(ctx, NKikimrServices::FLAT_TX_SCHEMESHARD, "Do not request full stats from datashard " << datashardId
486+
<< ", reason: shards count limit exceeded (in path)"
487+
<< ", limit: " << subDomainInfo->GetSchemeLimits().MaxShardsInPath
488+
<< ", current: " << pathElement->GetShardsInside()
489+
<< ", delta: " << deltaShards
490+
);
491+
return true;
492+
}
493+
const auto currentShards = (subDomainInfo->GetShardsInside() - subDomainInfo->GetBackupShards());
494+
if ((currentShards + deltaShards) > subDomainInfo->GetSchemeLimits().MaxShards) {
495+
LOG_NOTICE_S(ctx, NKikimrServices::FLAT_TX_SCHEMESHARD, "Do not request full stats from datashard " << datashardId
496+
<< ", datashard: " << datashardId
497+
<< ", reason: shards count limit exceeded (in subdomain)"
498+
<< ", limit: " << subDomainInfo->GetSchemeLimits().MaxShards
499+
<< ", current: " << currentShards
500+
<< ", delta: " << deltaShards
501+
);
502+
return true;
503+
}
490504
}
491505

492506
if (newStats.HasBorrowedData) {
@@ -496,9 +510,11 @@ bool TTxStoreTableStats::PersistSingleStats(const TPathId& pathId,
496510
return true;
497511
}
498512

499-
if (path.IsLocked()) {
513+
// path.IsLocked() and path.LockedBy() equivalent
514+
if (const auto& found = Self->LockedPaths.find(pathId); found != Self->LockedPaths.end()) {
515+
const auto txId = found->second;
500516
LOG_DEBUG_S(ctx, NKikimrServices::FLAT_TX_SCHEMESHARD,
501-
"Postpone split tablet " << datashardId << " because it is locked by " << path.LockedBy());
517+
"Postpone split tablet " << datashardId << " because it is locked by " << txId);
502518
return true;
503519
}
504520

0 commit comments

Comments
 (0)