Skip to content

Commit 680271e

Browse files
KIKIMR-20009: fix race condition on blobs removing (#1118)
1 parent fa1e847 commit 680271e

File tree

13 files changed

+43
-31
lines changed

13 files changed

+43
-31
lines changed

ydb/core/tx/columnshard/blob_manager.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -346,12 +346,15 @@ void TBlobManager::DoSaveBlobBatch(TBlobBatch&& blobBatch, IBlobManagerDb& db) {
346346
blobBatch.BatchInfo->GenStepRef.Reset();
347347
}
348348

349-
void TBlobManager::DeleteBlob(const TUnifiedBlobId& blobId, IBlobManagerDb& db) {
350-
++CountersUpdate.BlobsDeleted;
351-
349+
void TBlobManager::DeleteBlobOnExecute(const TUnifiedBlobId& blobId, IBlobManagerDb& db) {
352350
// Persist deletion intent
353351
db.AddBlobToDelete(blobId);
354-
AFL_DEBUG(NKikimrServices::TX_COLUMNSHARD)("to_delete", blobId);
352+
AFL_DEBUG(NKikimrServices::TX_COLUMNSHARD)("to_delete_on_execute", blobId);
353+
}
354+
355+
void TBlobManager::DeleteBlobOnComplete(const TUnifiedBlobId& blobId) {
356+
AFL_DEBUG(NKikimrServices::TX_COLUMNSHARD)("to_delete_on_complete", blobId);
357+
++CountersUpdate.BlobsDeleted;
355358

356359
// Check if the deletion needs to be delayed until the blob is no longer
357360
// used by in-flight requests

ydb/core/tx/columnshard/blob_manager.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ class IBlobManager {
9090
}
9191

9292
// Deletes the blob that was previously permanently saved
93-
virtual void DeleteBlob(const TUnifiedBlobId& blobId, IBlobManagerDb& db) = 0;
93+
virtual void DeleteBlobOnExecute(const TUnifiedBlobId& blobId, IBlobManagerDb& db) = 0;
94+
virtual void DeleteBlobOnComplete(const TUnifiedBlobId& blobId) = 0;
9495
};
9596

9697
// An interface for exporting and caching exported blobs out of ColumnShard index to external storages like S3.
@@ -218,7 +219,8 @@ class TBlobManager : public IBlobManager, public NOlap::TCommonBlobsTracker {
218219

219220
// Implementation of IBlobManager interface
220221
TBlobBatch StartBlobBatch(ui32 channel = BLOB_CHANNEL) override;
221-
void DeleteBlob(const TUnifiedBlobId& blobId, IBlobManagerDb& db) override;
222+
void DeleteBlobOnExecute(const TUnifiedBlobId& blobId, IBlobManagerDb& db) override;
223+
void DeleteBlobOnComplete(const TUnifiedBlobId& blobId) override;
222224
private:
223225
TGenStep FindNewGCBarrier();
224226

ydb/core/tx/columnshard/blobs_action/abstract/action.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,12 @@ class TStorageAction {
6464
}
6565
}
6666

67-
void OnCompleteTxAfterAction(NColumnShard::TColumnShard& self) {
67+
void OnCompleteTxAfterAction(NColumnShard::TColumnShard& self, const bool success) {
6868
if (Removing) {
69-
Removing->OnCompleteTxAfterRemoving(self);
69+
Removing->OnCompleteTxAfterRemoving(self, success);
7070
}
7171
if (Writing) {
72-
Writing->OnCompleteTxAfterWrite(self);
72+
Writing->OnCompleteTxAfterWrite(self, success);
7373
}
7474
}
7575
};
@@ -150,9 +150,9 @@ class TBlobsAction {
150150
}
151151
}
152152

153-
void OnCompleteTxAfterAction(NColumnShard::TColumnShard& self) {
153+
void OnCompleteTxAfterAction(NColumnShard::TColumnShard& self, const bool success) {
154154
for (auto&& i : StorageActions) {
155-
i.second.OnCompleteTxAfterAction(self);
155+
i.second.OnCompleteTxAfterAction(self, success);
156156
}
157157
}
158158

ydb/core/tx/columnshard/blobs_action/abstract/remove.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class IBlobsDeclareRemovingAction: public ICommonBlobsAction {
2020
protected:
2121
virtual void DoDeclareRemove(const TUnifiedBlobId& blobId) = 0;
2222
virtual void DoOnExecuteTxAfterRemoving(NColumnShard::TColumnShard& self, NColumnShard::TBlobManagerDb& dbBlobs, const bool success) = 0;
23-
virtual void DoOnCompleteTxAfterRemoving(NColumnShard::TColumnShard& self) = 0;
23+
virtual void DoOnCompleteTxAfterRemoving(NColumnShard::TColumnShard& self, const bool success) = 0;
2424
public:
2525
IBlobsDeclareRemovingAction(const TString& storageId)
2626
: TBase(storageId)
@@ -36,8 +36,8 @@ class IBlobsDeclareRemovingAction: public ICommonBlobsAction {
3636
void OnExecuteTxAfterRemoving(NColumnShard::TColumnShard& self, NColumnShard::TBlobManagerDb& dbBlobs, const bool success) {
3737
return DoOnExecuteTxAfterRemoving(self, dbBlobs, success);
3838
}
39-
void OnCompleteTxAfterRemoving(NColumnShard::TColumnShard& self) {
40-
return DoOnCompleteTxAfterRemoving(self);
39+
void OnCompleteTxAfterRemoving(NColumnShard::TColumnShard& self, const bool success) {
40+
return DoOnCompleteTxAfterRemoving(self, success);
4141
}
4242
};
4343

ydb/core/tx/columnshard/blobs_action/abstract/write.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class IBlobsWritingAction: public ICommonBlobsAction {
3131
virtual void DoOnBlobWriteResult(const TUnifiedBlobId& blobId, const NKikimrProto::EReplyStatus status) = 0;
3232

3333
virtual void DoOnExecuteTxAfterWrite(NColumnShard::TColumnShard& self, NColumnShard::TBlobManagerDb& dbBlobs, const bool success) = 0;
34-
virtual void DoOnCompleteTxAfterWrite(NColumnShard::TColumnShard& self) = 0;
34+
virtual void DoOnCompleteTxAfterWrite(NColumnShard::TColumnShard& self, const bool success) = 0;
3535

3636
virtual TUnifiedBlobId AllocateNextBlobId(const TString& data) = 0;
3737
public:
@@ -79,8 +79,8 @@ class IBlobsWritingAction: public ICommonBlobsAction {
7979
return DoOnExecuteTxAfterWrite(self, dbBlobs, success);
8080
}
8181

82-
void OnCompleteTxAfterWrite(NColumnShard::TColumnShard& self) {
83-
return DoOnCompleteTxAfterWrite(self);
82+
void OnCompleteTxAfterWrite(NColumnShard::TColumnShard& self, const bool success) {
83+
return DoOnCompleteTxAfterWrite(self, success);
8484
}
8585

8686
void SendWriteBlobRequest(const TString& data, const TUnifiedBlobId& blobId);

ydb/core/tx/columnshard/blobs_action/bs/remove.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,16 @@ class TDeclareRemovingAction: public IBlobsDeclareRemovingAction {
1818
virtual void DoOnExecuteTxAfterRemoving(NColumnShard::TColumnShard& /*self*/, NColumnShard::TBlobManagerDb& dbBlobs, const bool success) {
1919
if (success) {
2020
for (auto&& i : GetDeclaredBlobs()) {
21-
Manager->DeleteBlob(i, dbBlobs);
21+
Manager->DeleteBlobOnExecute(i, dbBlobs);
2222
}
2323
}
2424
}
25-
virtual void DoOnCompleteTxAfterRemoving(NColumnShard::TColumnShard& /*self*/) {
26-
25+
virtual void DoOnCompleteTxAfterRemoving(NColumnShard::TColumnShard& /*self*/, const bool success) {
26+
if (success) {
27+
for (auto&& i : GetDeclaredBlobs()) {
28+
Manager->DeleteBlobOnComplete(i);
29+
}
30+
}
2731
}
2832
public:
2933
TDeclareRemovingAction(const TString& storageId, NColumnShard::TBlobManager& manager)

ydb/core/tx/columnshard/blobs_action/bs/write.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class TWriteAction: public IBlobsWritingAction {
2929
}
3030

3131
virtual void DoOnExecuteTxAfterWrite(NColumnShard::TColumnShard& self, NColumnShard::TBlobManagerDb& dbBlobs, const bool success) override;
32-
virtual void DoOnCompleteTxAfterWrite(NColumnShard::TColumnShard& /*self*/) override {
32+
virtual void DoOnCompleteTxAfterWrite(NColumnShard::TColumnShard& /*self*/, const bool /*success*/) override {
3333

3434
}
3535
public:

ydb/core/tx/columnshard/blobs_action/memory.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class TMemoryWriteAction: public IBlobsWritingAction {
7171
virtual void DoOnExecuteTxAfterWrite(NColumnShard::TColumnShard& /*self*/, NColumnShard::TBlobManagerDb& /*dbBlobs*/, const bool /*success*/) override {
7272

7373
}
74-
virtual void DoOnCompleteTxAfterWrite(NColumnShard::TColumnShard& /*self*/) override {
74+
virtual void DoOnCompleteTxAfterWrite(NColumnShard::TColumnShard& /*self*/, const bool /*success*/) override {
7575

7676
}
7777
public:
@@ -106,7 +106,7 @@ class TMemoryDeclareRemovingAction: public IBlobsDeclareRemovingAction {
106106
Storage->DeclareDataForRemove(i);
107107
}
108108
}
109-
virtual void DoOnCompleteTxAfterRemoving(NColumnShard::TColumnShard& /*self*/) {
109+
virtual void DoOnCompleteTxAfterRemoving(NColumnShard::TColumnShard& /*self*/, const bool /*success*/) {
110110

111111
}
112112
public:

ydb/core/tx/columnshard/blobs_action/tier/remove.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ class TDeclareRemovingAction: public IBlobsDeclareRemovingAction {
2020
if (success) {
2121
for (auto&& i : GetDeclaredBlobs()) {
2222
dbBlobs.AddTierBlobToDelete(GetStorageId(), i);
23+
}
24+
}
25+
}
26+
virtual void DoOnCompleteTxAfterRemoving(NColumnShard::TColumnShard& /*self*/, const bool success) {
27+
if (success) {
28+
for (auto&& i : GetDeclaredBlobs()) {
2329
if (GCInfo->IsBlobInUsage(i)) {
2430
Y_ABORT_UNLESS(GCInfo->MutableBlobsToDeleteInFuture().emplace(i).second);
2531
} else {
@@ -28,9 +34,6 @@ class TDeclareRemovingAction: public IBlobsDeclareRemovingAction {
2834
}
2935
}
3036
}
31-
virtual void DoOnCompleteTxAfterRemoving(NColumnShard::TColumnShard& /*self*/) {
32-
33-
}
3437
public:
3538
TDeclareRemovingAction(const TString& storageId, const std::shared_ptr<TGCInfo>& gcInfo)
3639
: TBase(storageId)

ydb/core/tx/columnshard/blobs_action/tier/write.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class TWriteAction: public IBlobsWritingAction {
2727
}
2828

2929
virtual void DoOnExecuteTxAfterWrite(NColumnShard::TColumnShard& self, NColumnShard::TBlobManagerDb& dbBlobs, const bool success) override;
30-
virtual void DoOnCompleteTxAfterWrite(NColumnShard::TColumnShard& /*self*/) override {
30+
virtual void DoOnCompleteTxAfterWrite(NColumnShard::TColumnShard& /*self*/, const bool /*success*/) override {
3131

3232
}
3333
public:

ydb/core/tx/columnshard/blobs_action/transaction/tx_gc_insert_table.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ bool TTxInsertTableCleanup::Execute(TTransactionContext& txc, const TActorContex
2121
}
2222
void TTxInsertTableCleanup::Complete(const TActorContext& /*ctx*/) {
2323
Y_ABORT_UNLESS(BlobsAction);
24-
BlobsAction->OnCompleteTxAfterRemoving(*Self);
24+
BlobsAction->OnCompleteTxAfterRemoving(*Self, true);
2525
Self->EnqueueBackgroundActivities();
2626
}
2727

ydb/core/tx/columnshard/blobs_action/transaction/tx_write.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,10 @@ void TTxWrite::Complete(const TActorContext& ctx) {
102102
const auto now = TMonotonic::Now();
103103
const NOlap::TWritingBuffer& buffer = PutBlobResult->Get()->MutableWritesBuffer();
104104
for (auto&& i : buffer.GetAddActions()) {
105-
i->OnCompleteTxAfterWrite(*Self);
105+
i->OnCompleteTxAfterWrite(*Self, true);
106106
}
107107
for (auto&& i : buffer.GetRemoveActions()) {
108-
i->OnCompleteTxAfterRemoving(*Self);
108+
i->OnCompleteTxAfterRemoving(*Self, true);
109109
}
110110
AFL_VERIFY(buffer.GetAggregations().size() == Results.size());
111111
for (ui32 i = 0; i < buffer.GetAggregations().size(); ++i) {

ydb/core/tx/columnshard/blobs_action/transaction/tx_write_index.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ void TTxWriteIndex::Complete(const TActorContext& ctx) {
6464
Self->EnqueueBackgroundActivities(false, TriggerActivity);
6565
}
6666

67-
changes->MutableBlobsAction().OnCompleteTxAfterAction(*Self);
67+
changes->MutableBlobsAction().OnCompleteTxAfterAction(*Self, Ev->Get()->GetPutStatus() == NKikimrProto::OK);
6868
NYDBTest::TControllers::GetColumnShardController()->OnWriteIndexComplete(Self->TabletID(), changes->TypeString());
6969
}
7070

0 commit comments

Comments
 (0)