@@ -1187,17 +1187,15 @@ class TShardsInfo {
1187
1187
return insertIt->second ;
1188
1188
}
1189
1189
1190
- TVector<IShardedWriteController::TPendingShardInfo> GetPendingShards () const {
1191
- TVector<IShardedWriteController::TPendingShardInfo> result;
1190
+ void ForEachPendingShard (std::function<void (const IShardedWriteController::TPendingShardInfo&)>&& callback) const {
1192
1191
for (const auto & [id, shard] : ShardsInfo) {
1193
1192
if (!shard.IsEmpty () && shard.GetSendAttempts () == 0 ) {
1194
- result. push_back (IShardedWriteController::TPendingShardInfo{
1193
+ callback (IShardedWriteController::TPendingShardInfo{
1195
1194
.ShardId = id,
1196
1195
.HasRead = shard.HasRead (),
1197
1196
});
1198
1197
}
1199
1198
}
1200
- return result;
1201
1199
}
1202
1200
1203
1201
bool Has (ui64 shardId) const {
@@ -1382,6 +1380,18 @@ class TShardedWriteController : public IShardedWriteController {
1382
1380
}
1383
1381
}
1384
1382
1383
+ void CleanupClosedTokens () override {
1384
+ AFL_ENSURE (IsEmpty ());
1385
+ for (auto it = WriteInfos.begin (); it != WriteInfos.end ();) {
1386
+ if (it->second .Closed ) {
1387
+ AFL_ENSURE (it->second .Serializer ->IsFinished ());
1388
+ it = WriteInfos.erase (it);
1389
+ } else {
1390
+ ++it;
1391
+ }
1392
+ }
1393
+ }
1394
+
1385
1395
void FlushBuffers () override {
1386
1396
TVector<TWriteToken> writeTokensFoFlush;
1387
1397
for (const auto & [token, writeInfo] : WriteInfos) {
@@ -1420,8 +1430,14 @@ class TShardedWriteController : public IShardedWriteController {
1420
1430
}
1421
1431
}
1422
1432
1423
- TVector<TPendingShardInfo> GetPendingShards () const override {
1424
- return ShardsInfo.GetPendingShards ();
1433
+ void ForEachPendingShard (std::function<void (const TPendingShardInfo&)>&& callback) const override {
1434
+ ShardsInfo.ForEachPendingShard (std::move (callback));
1435
+ }
1436
+
1437
+ std::vector<TPendingShardInfo> ExtractShardUpdates () override {
1438
+ std::vector<TPendingShardInfo> shardUpdates;
1439
+ std::swap (shardUpdates, ShardUpdates);
1440
+ return shardUpdates;
1425
1441
}
1426
1442
1427
1443
TVector<ui64> GetShardsIds () const override {
@@ -1580,11 +1596,16 @@ class TShardedWriteController : public IShardedWriteController {
1580
1596
for (auto & [shardId, batches] : writeInfo.Serializer ->FlushBatchesForce ()) {
1581
1597
for (auto & batch : batches) {
1582
1598
if (batch && !batch->IsEmpty ()) {
1599
+ const bool hasRead = (writeInfo.Metadata .OperationType == NKikimrDataEvents::TEvWrite::TOperation::OPERATION_INSERT
1600
+ || writeInfo.Metadata .OperationType == NKikimrDataEvents::TEvWrite::TOperation::OPERATION_UPDATE);
1583
1601
ShardsInfo.GetShard (shardId).PushBatch (TBatchWithMetadata{
1584
1602
.Token = token,
1585
1603
.Data = std::move (batch),
1586
- .HasRead = (writeInfo.Metadata .OperationType == NKikimrDataEvents::TEvWrite::TOperation::OPERATION_INSERT
1587
- || writeInfo.Metadata .OperationType == NKikimrDataEvents::TEvWrite::TOperation::OPERATION_UPDATE),
1604
+ .HasRead = hasRead,
1605
+ });
1606
+ ShardUpdates.push_back (IShardedWriteController::TPendingShardInfo{
1607
+ .ShardId = shardId,
1608
+ .HasRead = hasRead,
1588
1609
});
1589
1610
}
1590
1611
}
@@ -1597,11 +1618,16 @@ class TShardedWriteController : public IShardedWriteController {
1597
1618
if (!batch || batch->IsEmpty ()) {
1598
1619
break ;
1599
1620
}
1621
+ const bool hasRead = (writeInfo.Metadata .OperationType == NKikimrDataEvents::TEvWrite::TOperation::OPERATION_INSERT
1622
+ || writeInfo.Metadata .OperationType == NKikimrDataEvents::TEvWrite::TOperation::OPERATION_UPDATE);
1600
1623
shard.PushBatch (TBatchWithMetadata{
1601
1624
.Token = token,
1602
1625
.Data = std::move (batch),
1603
- .HasRead = (writeInfo.Metadata .OperationType == NKikimrDataEvents::TEvWrite::TOperation::OPERATION_INSERT
1604
- || writeInfo.Metadata .OperationType == NKikimrDataEvents::TEvWrite::TOperation::OPERATION_UPDATE),
1626
+ .HasRead = hasRead,
1627
+ });
1628
+ ShardUpdates.push_back (IShardedWriteController::TPendingShardInfo{
1629
+ .ShardId = shardId,
1630
+ .HasRead = hasRead,
1605
1631
});
1606
1632
}
1607
1633
}
@@ -1615,6 +1641,7 @@ class TShardedWriteController : public IShardedWriteController {
1615
1641
shard.MakeNextBatches (1 );
1616
1642
} else {
1617
1643
shard.MakeNextBatches (std::nullopt);
1644
+ AFL_ENSURE (shard.GetBatchesInFlight () == shard.Size ());
1618
1645
}
1619
1646
}
1620
1647
}
@@ -1646,6 +1673,7 @@ class TShardedWriteController : public IShardedWriteController {
1646
1673
TWriteToken CurrentWriteToken = 0 ;
1647
1674
1648
1675
TShardsInfo ShardsInfo;
1676
+ std::vector<IShardedWriteController::TPendingShardInfo> ShardUpdates;
1649
1677
1650
1678
std::optional<NSchemeCache::TSchemeCacheNavigate::TEntry> SchemeEntry;
1651
1679
std::shared_ptr<const TVector<TKeyDesc::TPartitionInfo>> Partitioning;
0 commit comments