@@ -259,18 +259,38 @@ void TColumnShard::LoadLongTxWrite(TWriteId writeId, const ui32 writePartId, con
259
259
}
260
260
261
261
bool TColumnShard::RemoveLongTxWrite (NIceDb::TNiceDb& db, const TWriteId writeId, const ui64 txId) {
262
- auto * lw = LongTxWrites.FindPtr (writeId);
263
- AFL_VERIFY (lw)(" write_id" , (ui64)writeId)(" tx_id" , txId);
264
- const ui64 prepared = lw->PreparedTxId ;
265
- AFL_VERIFY (!prepared || txId == prepared)(" tx" , txId)(" prepared" , prepared);
266
- Schema::EraseLongTxWrite (db, writeId);
267
- auto & ltxParts = LongTxWritesByUniqueId[lw->LongTxId .UniqueId ];
268
- ltxParts.erase (lw->WritePartId );
269
- if (ltxParts.empty ()) {
270
- AFL_VERIFY (LongTxWritesByUniqueId.erase (lw->LongTxId .UniqueId ));
271
- }
272
- LongTxWrites.erase (writeId);
273
- return true ;
262
+ if (auto * lw = LongTxWrites.FindPtr (writeId)) {
263
+ ui64 prepared = lw->PreparedTxId ;
264
+ if (!prepared || txId == prepared) {
265
+ Schema::EraseLongTxWrite (db, writeId);
266
+ auto & ltxParts = LongTxWritesByUniqueId[lw->LongTxId .UniqueId ];
267
+ ltxParts.erase (lw->WritePartId );
268
+ if (ltxParts.empty ()) {
269
+ LongTxWritesByUniqueId.erase (lw->LongTxId .UniqueId );
270
+ }
271
+ LongTxWrites.erase (writeId);
272
+ return true ;
273
+ }
274
+ }
275
+ return false ;
276
+ }
277
+
278
+ void TColumnShard::TryAbortWrites (NIceDb::TNiceDb& db, NOlap::TDbWrapper& dbTable, THashSet<TWriteId>&& writesToAbort) {
279
+ std::vector<TWriteId> failedAborts;
280
+ for (auto & writeId : writesToAbort) {
281
+ if (!RemoveLongTxWrite (db, writeId, 0 )) {
282
+ failedAborts.push_back (writeId);
283
+ }
284
+ }
285
+ if (failedAborts.size ()) {
286
+ AFL_TRACE (NKikimrServices::TX_COLUMNSHARD)(" event" , " failed_aborts" )(" count" , failedAborts.size ())(" writes_count" , writesToAbort.size ());
287
+ }
288
+ for (auto & writeId : failedAborts) {
289
+ writesToAbort.erase (writeId);
290
+ }
291
+ if (!writesToAbort.empty ()) {
292
+ InsertTable->Abort (dbTable, writesToAbort);
293
+ }
274
294
}
275
295
276
296
void TColumnShard::UpdateSchemaSeqNo (const TMessageSeqNo& seqNo, NTabletFlatExecutor::TTransactionContext& txc) {
@@ -455,7 +475,9 @@ void TColumnShard::RunDropTable(const NKikimrTxColumnShard::TDropTable& dropProt
455
475
// TODO: Allow to read old snapshots after DROP
456
476
TBlobGroupSelector dsGroupSelector (Info ());
457
477
NOlap::TDbWrapper dbTable (txc.DB , &dsGroupSelector);
458
- InsertTable->DropPath (dbTable, pathId);
478
+ THashSet<TWriteId> writesToAbort = InsertTable->DropPath (dbTable, pathId);
479
+
480
+ TryAbortWrites (db, dbTable, std::move (writesToAbort));
459
481
}
460
482
461
483
void TColumnShard::RunAlterStore (const NKikimrTxColumnShard::TAlterStore& proto, const NOlap::TSnapshot& version,
@@ -827,21 +849,22 @@ void TColumnShard::Handle(TEvPrivate::TEvGarbageCollectionFinished::TPtr& ev, co
827
849
}
828
850
829
851
void TColumnShard::SetupCleanupInsertTable () {
852
+ auto writeIdsToCleanup = InsertTable->OldWritesToAbort (AppData ()->TimeProvider ->Now ());
853
+
830
854
if (BackgroundController.IsCleanupInsertTableActive ()) {
831
855
ACFL_DEBUG (" background" , " cleanup_insert_table" )(" skip_reason" , " in_progress" );
832
856
return ;
833
857
}
834
858
835
- if (!InsertTable->GetAborted ().size ()) {
859
+ if (!InsertTable->GetAborted ().size () && !writeIdsToCleanup. size () ) {
836
860
return ;
837
861
}
838
- AFL_INFO (NKikimrServices::TX_COLUMNSHARD)(" event" , " cleanup_started" )(" aborted" , InsertTable->GetAborted ().size ());
862
+ AFL_INFO (NKikimrServices::TX_COLUMNSHARD)(" event" , " cleanup_started" )(" aborted" , InsertTable->GetAborted ().size ())( " to_cleanup " , writeIdsToCleanup. size ()) ;
839
863
BackgroundController.StartCleanupInsertTable ();
840
- Execute (new TTxInsertTableCleanup (this ), TActorContext::AsActorContext ());
864
+ Execute (new TTxInsertTableCleanup (this , std::move (writeIdsToCleanup) ), TActorContext::AsActorContext ());
841
865
}
842
866
843
867
void TColumnShard::Die (const TActorContext& ctx) {
844
- // TODO
845
868
CleanupActors (ctx);
846
869
NTabletPipe::CloseAndForgetClient (SelfId (), StatsReportPipe);
847
870
UnregisterMediatorTimeCast ();
0 commit comments