@@ -590,7 +590,8 @@ struct TSchemeShard::TIndexBuilder::TTxProgress: public TSchemeShard::TIndexBuil
590
590
ev->Record .SetId (ui64 (BuildId));
591
591
592
592
PathIdFromPathId (buildInfo.TablePathId , ev->Record .MutablePathId ());
593
- *ev->Record .MutableSettings () = std::get<1 >(buildInfo.SpecializedIndexDescription ).GetSettings ();
593
+ *ev->Record .MutableSettings () = std::get<NKikimrSchemeOp::TVectorIndexKmeansTreeDescription>(
594
+ buildInfo.SpecializedIndexDescription ).GetSettings ().settings ();
594
595
ev->Record .SetK (buildInfo.KMeans .K );
595
596
ev->Record .SetUpload (buildInfo.KMeans .GetUpload ());
596
597
ev->Record .SetState (NKikimrTxDataShard::TEvLocalKMeansRequest::SAMPLE);
@@ -690,7 +691,7 @@ struct TSchemeShard::TIndexBuilder::TTxProgress: public TSchemeShard::TIndexBuil
690
691
}
691
692
692
693
void ClearAfterFill (const TActorContext& ctx, TIndexBuildInfo& buildInfo) {
693
- buildInfo.DoneShardsSize = 0 ;
694
+ buildInfo.DoneShards = {} ;
694
695
buildInfo.InProgressShards = {};
695
696
buildInfo.ToUploadShards = {};
696
697
@@ -710,7 +711,7 @@ struct TSchemeShard::TIndexBuilder::TTxProgress: public TSchemeShard::TIndexBuil
710
711
}
711
712
712
713
bool FillTable (TIndexBuildInfo& buildInfo) {
713
- if (buildInfo.DoneShardsSize == 0 && buildInfo.ToUploadShards .empty () && buildInfo.InProgressShards .empty ()) {
714
+ if (buildInfo.DoneShards . empty () && buildInfo.ToUploadShards .empty () && buildInfo.InProgressShards .empty ()) {
714
715
for (const auto & [idx, status] : buildInfo.Shards ) {
715
716
switch (status.Status ) {
716
717
case NKikimrIndexBuilder::EBuildStatus::INVALID:
@@ -720,7 +721,7 @@ struct TSchemeShard::TIndexBuilder::TTxProgress: public TSchemeShard::TIndexBuil
720
721
buildInfo.ToUploadShards .emplace_back (idx);
721
722
break ;
722
723
case NKikimrIndexBuilder::EBuildStatus::DONE:
723
- ++ buildInfo.DoneShardsSize ;
724
+ buildInfo.DoneShards . emplace_back (idx) ;
724
725
break ;
725
726
case NKikimrIndexBuilder::EBuildStatus::BUILD_ERROR:
726
727
case NKikimrIndexBuilder::EBuildStatus::BAD_REQUEST:
@@ -729,11 +730,11 @@ struct TSchemeShard::TIndexBuilder::TTxProgress: public TSchemeShard::TIndexBuil
729
730
}
730
731
}
731
732
return SendToShards (buildInfo, [&](TShardIdx shardIdx) { SendBuildIndexRequest (shardIdx, buildInfo); }) &&
732
- buildInfo.DoneShardsSize == buildInfo.Shards .size ();
733
+ buildInfo.DoneShards . size () == buildInfo.Shards .size ();
733
734
}
734
735
735
736
void ComputeKMeansState (TIndexBuildInfo& buildInfo) {
736
- if (buildInfo.DoneShardsSize != 0 || !buildInfo.InProgressShards .empty () || !buildInfo.ToUploadShards .empty ()) {
737
+ if (! buildInfo.DoneShards . empty () || !buildInfo.InProgressShards .empty () || !buildInfo.ToUploadShards .empty ()) {
737
738
return ;
738
739
}
739
740
std::array<NScheme::TTypeInfo, 1 > typeInfos{NScheme::NTypeIds::Uint32};
@@ -754,14 +755,14 @@ struct TSchemeShard::TIndexBuilder::TTxProgress: public TSchemeShard::TIndexBuil
754
755
buildInfo.ToUploadShards .emplace_back (idx);
755
756
break ;
756
757
case NKikimrIndexBuilder::EBuildStatus::DONE:
757
- ++ buildInfo.DoneShardsSize ;
758
+ buildInfo.DoneShards . emplace_back (idx) ;
758
759
break ;
759
760
case NKikimrIndexBuilder::EBuildStatus::BUILD_ERROR:
760
761
case NKikimrIndexBuilder::EBuildStatus::BAD_REQUEST:
761
762
Y_ABORT (" Unreachable" );
762
763
}
763
764
}
764
- if (buildInfo.DoneShardsSize == 0 && buildInfo.ToUploadShards .size () == 1 ) {
765
+ if (buildInfo.DoneShards . empty () && buildInfo.ToUploadShards .size () == 1 ) {
765
766
buildInfo.KMeans .State = TIndexBuildInfo::TKMeans::Local;
766
767
}
767
768
}
@@ -799,12 +800,17 @@ struct TSchemeShard::TIndexBuilder::TTxProgress: public TSchemeShard::TIndexBuil
799
800
return true ;
800
801
}
801
802
802
- bool FillVectorIndex (TIndexBuildInfo& buildInfo) {
803
+ bool FillVectorIndex (TTransactionContext& txc, TIndexBuildInfo& buildInfo) {
803
804
ComputeKMeansState (buildInfo);
804
805
if (!SendVectorIndex (buildInfo)) {
805
806
return false ;
806
807
}
807
- buildInfo.DoneShardsSize = 0 ;
808
+ NIceDb::TNiceDb db{txc.DB };
809
+ for (const auto & idx : buildInfo.DoneShards ) {
810
+ auto & status = buildInfo.Shards .at (idx);
811
+ Self->PersistBuildIndexUploadReset (db, BuildId, idx, status);
812
+ }
813
+ buildInfo.DoneShards .clear ();
808
814
809
815
if (!buildInfo.Sample .Sent && !buildInfo.Sample .Rows .empty ()) {
810
816
SendUploadSampleKRequest (buildInfo);
@@ -843,7 +849,7 @@ struct TSchemeShard::TIndexBuilder::TTxProgress: public TSchemeShard::TIndexBuil
843
849
InitiateShards (db, buildInfo);
844
850
}
845
851
if (buildInfo.IsBuildVectorIndex ()) {
846
- return FillVectorIndex (buildInfo);
852
+ return FillVectorIndex (txc, buildInfo);
847
853
} else {
848
854
Y_ASSERT (buildInfo.IsBuildSecondaryIndex () || buildInfo.IsBuildColumns ());
849
855
return FillTable (buildInfo);
@@ -1089,14 +1095,16 @@ struct TSchemeShard::TIndexBuilder::TTxProgress: public TSchemeShard::TIndexBuil
1089
1095
auto tableColumns = NTableIndex::ExtractInfo (table); // skip dropped columns
1090
1096
TSerializedTableRange shardRange = InfiniteRange (tableColumns.Keys .size ());
1091
1097
1098
+ Y_ASSERT (buildInfo.Shards .empty ());
1092
1099
for (const auto & x: table->GetPartitions ()) {
1093
1100
Y_ABORT_UNLESS (Self->ShardInfos .contains (x.ShardIdx ));
1094
1101
TSerializedCellVec bound{x.EndOfRange };
1095
1102
shardRange.To = bound;
1096
- buildInfo.Shards .emplace (x.ShardIdx , TIndexBuildInfo::TShardStatus{std::move (shardRange), " " });
1103
+ auto [it, emplaced] = buildInfo.Shards .emplace (x.ShardIdx , TIndexBuildInfo::TShardStatus{std::move (shardRange), " " });
1104
+ Y_ASSERT (emplaced);
1097
1105
shardRange.From = std::move (bound);
1098
1106
1099
- Self->PersistBuildIndexUploadInitiate (db, buildInfo , x.ShardIdx );
1107
+ Self->PersistBuildIndexUploadInitiate (db, BuildId , x.ShardIdx , it-> second );
1100
1108
}
1101
1109
}
1102
1110
@@ -1316,33 +1324,21 @@ struct TSchemeShard::TIndexBuilder::TTxReplySampleK: public TSchemeShard::TIndex
1316
1324
NYql::TIssues issues;
1317
1325
NYql::IssuesFromMessage (record.GetIssues (), issues);
1318
1326
shardStatus.DebugMessage = issues.ToString ();
1319
-
1320
- NIceDb::TNiceDb db (txc.DB );
1321
- Self->PersistBuildIndexUploadProgress (db, buildInfo, shardIdx);
1322
1327
shardStatus.Status = record.GetStatus ();
1323
1328
1329
+ NIceDb::TNiceDb db (txc.DB );
1324
1330
switch (shardStatus.Status ) {
1325
1331
case NKikimrIndexBuilder::EBuildStatus::DONE:
1326
1332
if (buildInfo.InProgressShards .erase (shardIdx)) {
1327
- ++buildInfo.DoneShardsSize ;
1328
-
1329
- Self->IndexBuildPipes .Close (buildId, shardId, ctx);
1330
-
1331
- Progress (buildId);
1333
+ buildInfo.DoneShards .emplace_back (shardIdx);
1332
1334
}
1333
1335
break ;
1334
-
1335
1336
case NKikimrIndexBuilder::EBuildStatus::ABORTED:
1336
1337
// datashard gracefully rebooted, reschedule shard
1337
1338
if (buildInfo.InProgressShards .erase (shardIdx)) {
1338
1339
buildInfo.ToUploadShards .emplace_front (shardIdx);
1339
-
1340
- Self->IndexBuildPipes .Close (buildId, shardId, ctx);
1341
-
1342
- Progress (buildId);
1343
1340
}
1344
1341
break ;
1345
-
1346
1342
case NKikimrIndexBuilder::EBuildStatus::BAD_REQUEST:
1347
1343
buildInfo.Issue += TStringBuilder ()
1348
1344
<< " One of the shards report BAD_REQUEST at Filling stage, process has to be canceled"
@@ -1352,14 +1348,16 @@ struct TSchemeShard::TIndexBuilder::TTxReplySampleK: public TSchemeShard::TIndex
1352
1348
ChangeState (buildInfo.Id , TIndexBuildInfo::EState::Rejection_Applying);
1353
1349
1354
1350
Progress (buildId);
1355
- break ;
1356
-
1351
+ return true ;
1357
1352
case NKikimrIndexBuilder::EBuildStatus::INVALID:
1358
1353
case NKikimrIndexBuilder::EBuildStatus::ACCEPTED:
1359
1354
case NKikimrIndexBuilder::EBuildStatus::IN_PROGRESS:
1360
1355
case NKikimrIndexBuilder::EBuildStatus::BUILD_ERROR:
1361
1356
Y_ABORT (" Unreachable" );
1362
1357
}
1358
+ Self->PersistBuildIndexUploadProgress (db, buildId, shardIdx, shardStatus);
1359
+ Self->IndexBuildPipes .Close (buildId, shardId, ctx);
1360
+ Progress (buildId);
1363
1361
break ;
1364
1362
}
1365
1363
case TIndexBuildInfo::EState::AlterMainTable:
@@ -1379,8 +1377,8 @@ struct TSchemeShard::TIndexBuilder::TTxReplySampleK: public TSchemeShard::TIndex
1379
1377
case TIndexBuildInfo::EState::Rejection_Applying:
1380
1378
case TIndexBuildInfo::EState::Rejection_Unlocking:
1381
1379
case TIndexBuildInfo::EState::Rejected:
1382
- LOG_D (" TTxReply : TEvSampleKResponse"
1383
- << " superfluous message " << record.ShortDebugString ());
1380
+ LOG_D (" TTxReply : TEvSampleKResponse superfluous message "
1381
+ << record.ShortDebugString ());
1384
1382
break ;
1385
1383
}
1386
1384
@@ -1449,31 +1447,20 @@ struct TSchemeShard::TIndexBuilder::TTxReplyLocalKMeans: public TSchemeShard::TI
1449
1447
shardStatus.DebugMessage = issues.ToString ();
1450
1448
1451
1449
NIceDb::TNiceDb db (txc.DB );
1452
- Self->PersistBuildIndexUploadProgress (db, buildInfo, shardIdx);
1453
1450
shardStatus.Status = record.GetStatus ();
1454
1451
1455
1452
switch (shardStatus.Status ) {
1456
1453
case NKikimrIndexBuilder::EBuildStatus::DONE:
1457
1454
if (buildInfo.InProgressShards .erase (shardIdx)) {
1458
- ++buildInfo.DoneShardsSize ;
1459
-
1460
- Self->IndexBuildPipes .Close (buildId, shardId, ctx);
1461
-
1462
- Progress (buildId);
1455
+ buildInfo.DoneShards .emplace_back (shardIdx);
1463
1456
}
1464
1457
break ;
1465
-
1466
1458
case NKikimrIndexBuilder::EBuildStatus::ABORTED:
1467
1459
// datashard gracefully rebooted, reschedule shard
1468
1460
if (buildInfo.InProgressShards .erase (shardIdx)) {
1469
1461
buildInfo.ToUploadShards .emplace_front (shardIdx);
1470
-
1471
- Self->IndexBuildPipes .Close (buildId, shardId, ctx);
1472
-
1473
- Progress (buildId);
1474
1462
}
1475
1463
break ;
1476
-
1477
1464
case NKikimrIndexBuilder::EBuildStatus::BUILD_ERROR:
1478
1465
case NKikimrIndexBuilder::EBuildStatus::BAD_REQUEST:
1479
1466
buildInfo.Issue += TStringBuilder ()
@@ -1485,13 +1472,15 @@ struct TSchemeShard::TIndexBuilder::TTxReplyLocalKMeans: public TSchemeShard::TI
1485
1472
ChangeState (buildInfo.Id , TIndexBuildInfo::EState::Rejection_Applying);
1486
1473
1487
1474
Progress (buildId);
1488
- break ;
1489
-
1475
+ return true ;
1490
1476
case NKikimrIndexBuilder::EBuildStatus::INVALID:
1491
1477
case NKikimrIndexBuilder::EBuildStatus::ACCEPTED:
1492
1478
case NKikimrIndexBuilder::EBuildStatus::IN_PROGRESS:
1493
1479
Y_ABORT (" Unreachable" );
1494
1480
}
1481
+ Self->PersistBuildIndexUploadProgress (db, buildId, shardIdx, shardStatus);
1482
+ Self->IndexBuildPipes .Close (buildId, shardId, ctx);
1483
+ Progress (buildId);
1495
1484
break ;
1496
1485
}
1497
1486
case TIndexBuildInfo::EState::AlterMainTable:
@@ -1581,31 +1570,20 @@ struct TSchemeShard::TIndexBuilder::TTxReplyReshuffleKMeans: public TSchemeShard
1581
1570
shardStatus.DebugMessage = issues.ToString ();
1582
1571
1583
1572
NIceDb::TNiceDb db (txc.DB );
1584
- Self->PersistBuildIndexUploadProgress (db, buildInfo, shardIdx);
1585
1573
shardStatus.Status = record.GetStatus ();
1586
1574
1587
1575
switch (shardStatus.Status ) {
1588
1576
case NKikimrIndexBuilder::EBuildStatus::DONE:
1589
1577
if (buildInfo.InProgressShards .erase (shardIdx)) {
1590
- ++buildInfo.DoneShardsSize ;
1591
-
1592
- Self->IndexBuildPipes .Close (buildId, shardId, ctx);
1593
-
1594
- Progress (buildId);
1578
+ buildInfo.DoneShards .emplace_back (shardIdx);
1595
1579
}
1596
1580
break ;
1597
-
1598
1581
case NKikimrIndexBuilder::EBuildStatus::ABORTED:
1599
1582
// datashard gracefully rebooted, reschedule shard
1600
1583
if (buildInfo.InProgressShards .erase (shardIdx)) {
1601
1584
buildInfo.ToUploadShards .emplace_front (shardIdx);
1602
-
1603
- Self->IndexBuildPipes .Close (buildId, shardId, ctx);
1604
-
1605
- Progress (buildId);
1606
1585
}
1607
1586
break ;
1608
-
1609
1587
case NKikimrIndexBuilder::EBuildStatus::BUILD_ERROR:
1610
1588
case NKikimrIndexBuilder::EBuildStatus::BAD_REQUEST:
1611
1589
buildInfo.Issue += TStringBuilder ()
@@ -1615,15 +1593,16 @@ struct TSchemeShard::TIndexBuilder::TTxReplyReshuffleKMeans: public TSchemeShard
1615
1593
<< " , shardIdx: " << shardIdx;
1616
1594
Self->PersistBuildIndexIssue (db, buildInfo);
1617
1595
ChangeState (buildInfo.Id , TIndexBuildInfo::EState::Rejection_Applying);
1618
-
1619
1596
Progress (buildId);
1620
- break ;
1621
-
1597
+ return true ;
1622
1598
case NKikimrIndexBuilder::EBuildStatus::INVALID:
1623
1599
case NKikimrIndexBuilder::EBuildStatus::ACCEPTED:
1624
1600
case NKikimrIndexBuilder::EBuildStatus::IN_PROGRESS:
1625
1601
Y_ABORT (" Unreachable" );
1626
1602
}
1603
+ Self->PersistBuildIndexUploadProgress (db, buildId, shardIdx, shardStatus);
1604
+ Self->IndexBuildPipes .Close (buildId, shardId, ctx);
1605
+ Progress (buildId);
1627
1606
break ;
1628
1607
}
1629
1608
case TIndexBuildInfo::EState::AlterMainTable:
@@ -1824,38 +1803,25 @@ struct TSchemeShard::TIndexBuilder::TTxReplyProgress: public TSchemeShard::TInde
1824
1803
shardStatus.DebugMessage = issues.ToString ();
1825
1804
1826
1805
NIceDb::TNiceDb db (txc.DB );
1827
- Self->PersistBuildIndexUploadProgress (db, buildInfo, shardIdx);
1828
-
1829
1806
switch (shardStatus.Status ) {
1830
1807
case NKikimrIndexBuilder::EBuildStatus::INVALID:
1831
1808
Y_ABORT (" Unreachable" );
1832
-
1833
1809
case NKikimrIndexBuilder::EBuildStatus::ACCEPTED:
1834
1810
case NKikimrIndexBuilder::EBuildStatus::IN_PROGRESS:
1835
1811
// no oop, wait resolution. Progress key are persisted
1836
- break ;
1837
-
1812
+ Self-> PersistBuildIndexUploadProgress (db, buildId, shardIdx, shardStatus) ;
1813
+ return true ;
1838
1814
case NKikimrIndexBuilder::EBuildStatus::DONE:
1839
1815
if (buildInfo.InProgressShards .erase (shardIdx)) {
1840
- ++buildInfo.DoneShardsSize ;
1841
-
1842
- Self->IndexBuildPipes .Close (buildId, shardId, ctx);
1843
-
1844
- Progress (buildId);
1816
+ buildInfo.DoneShards .emplace_back (shardIdx);
1845
1817
}
1846
1818
break ;
1847
-
1848
1819
case NKikimrIndexBuilder::EBuildStatus::ABORTED:
1849
1820
// datashard gracefully rebooted, reschedule shard
1850
1821
if (buildInfo.InProgressShards .erase (shardIdx)) {
1851
1822
buildInfo.ToUploadShards .emplace_front (shardIdx);
1852
-
1853
- Self->IndexBuildPipes .Close (buildId, shardId, ctx);
1854
-
1855
- Progress (buildId);
1856
1823
}
1857
1824
break ;
1858
-
1859
1825
case NKikimrIndexBuilder::EBuildStatus::BUILD_ERROR:
1860
1826
case NKikimrIndexBuilder::EBuildStatus::BAD_REQUEST:
1861
1827
buildInfo.Issue += TStringBuilder ()
@@ -1865,11 +1831,12 @@ struct TSchemeShard::TIndexBuilder::TTxReplyProgress: public TSchemeShard::TInde
1865
1831
<< " , shardIdx: " << shardIdx;
1866
1832
Self->PersistBuildIndexIssue (db, buildInfo);
1867
1833
ChangeState (buildInfo.Id , TIndexBuildInfo::EState::Rejection_Applying);
1868
-
1869
1834
Progress (buildId);
1870
- break ;
1835
+ return true ;
1871
1836
}
1872
-
1837
+ Self->PersistBuildIndexUploadProgress (db, buildId, shardIdx, shardStatus);
1838
+ Self->IndexBuildPipes .Close (buildId, shardId, ctx);
1839
+ Progress (buildId);
1873
1840
break ;
1874
1841
}
1875
1842
case TIndexBuildInfo::EState::AlterMainTable:
0 commit comments