Skip to content

Commit cf78684

Browse files
authored
[Backport stable-25-3-1] PR #30261: Separate DeleteQueue to allow reusing only current-generation locators (#30272)
2 parents f05f5a7 + f24610f commit cf78684

File tree

4 files changed

+36
-12
lines changed

4 files changed

+36
-12
lines changed

ydb/core/blob_depot/data_load.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,16 @@ namespace NKikimr::NBlobDepot {
110110
if (!rows.IsReady()) {
111111
return false;
112112
}
113+
const ui32 generation = Self->Executor()->Generation();
113114
while (rows.IsValid()) {
114115
TS3Locator item{
115116
.Len = rows.GetValue<Schema::TrashS3::Len>(),
116117
.Generation = rows.GetValue<Schema::TrashS3::Generation>(),
117118
.KeyId = rows.GetValue<Schema::TrashS3::KeyId>(),
118119
};
120+
if (item.Generation == generation) {
121+
return true; // we don't want to read newly added items by this tablet's generation
122+
}
119123
if (item != from) {
120124
Self->S3Manager->AddTrashToCollect(item);
121125
from = item;

ydb/core/blob_depot/s3.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ namespace NKikimr::NBlobDepot {
6969
static constexpr ui32 MaxDeletesInFlight = 3;
7070
static constexpr size_t MaxObjectsToDeleteAtOnce = 10;
7171

72-
std::deque<TS3Locator> DeleteQueue; // items we are definitely going to delete (must be present in TrashS3)
72+
// items we are definitely going to delete (must be present in TrashS3)
73+
std::deque<TS3Locator> DeleteQueueInPrevGenerations;
74+
std::deque<TS3Locator> DeleteQueueInCurrentGeneration;
7375
THashSet<TActorId> ActiveDeleters;
7476
ui32 NumDeleteTxInFlight = 0;
7577
ui64 TotalS3TrashObjects = 0;

ydb/core/blob_depot/s3_delete.cpp

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -156,18 +156,28 @@ namespace NKikimr::NBlobDepot {
156156
STLOG(PRI_INFO, BLOB_DEPOT, BDTS06, "AddTrashToCollect", (Id, Self->GetLogId()), (Locator, locator));
157157
Self->TabletCounters->Simple()[NKikimrBlobDepot::COUNTER_TOTAL_S3_TRASH_OBJECTS] = ++TotalS3TrashObjects;
158158
Self->TabletCounters->Simple()[NKikimrBlobDepot::COUNTER_TOTAL_S3_TRASH_SIZE] = TotalS3TrashSize += locator.Len;
159-
DeleteQueue.push_back(locator);
159+
if (const ui32 generation = Self->Executor()->Generation(); locator.Generation < generation) {
160+
DeleteQueueInPrevGenerations.push_back(locator);
161+
} else {
162+
Y_DEBUG_ABORT_UNLESS(locator.Generation == generation);
163+
DeleteQueueInCurrentGeneration.push_back(locator);
164+
}
160165
RunDeletersIfNeeded();
161166
}
162167

163168
void TS3Manager::RunDeletersIfNeeded() {
164-
while (!DeleteQueue.empty() && NumDeleteTxInFlight + ActiveDeleters.size() < MaxDeletesInFlight) {
169+
while (NumDeleteTxInFlight + ActiveDeleters.size() < MaxDeletesInFlight) {
170+
// create list of locators we are going to delete during this operation
165171
THashMap<TString, TS3Locator> locators;
166-
167-
while (!DeleteQueue.empty() && locators.size() < MaxObjectsToDeleteAtOnce) {
168-
const TS3Locator& locator = DeleteQueue.front();
169-
locators.emplace(locator.MakeObjectName(BasePath), locator);
170-
DeleteQueue.pop_front();
172+
for (auto *queue : {&DeleteQueueInPrevGenerations, &DeleteQueueInCurrentGeneration}) {
173+
while (!queue->empty() && locators.size() < MaxObjectsToDeleteAtOnce) {
174+
const TS3Locator& locator = queue->front();
175+
locators.emplace(locator.MakeObjectName(BasePath), locator);
176+
queue->pop_front();
177+
}
178+
}
179+
if (!locators) {
180+
break;
171181
}
172182

173183
const TActorId actorId = Self->Register(new TDeleterActor(Self->SelfId(), locators, Self->GetLogId()));
@@ -218,7 +228,15 @@ namespace NKikimr::NBlobDepot {
218228
}
219229

220230
if (!msg.LocatorsError.empty()) {
221-
DeleteQueue.insert(DeleteQueue.end(), msg.LocatorsError.begin(), msg.LocatorsError.end());
231+
const ui32 generation = Self->Executor()->Generation();
232+
for (auto& locator : msg.LocatorsError) {
233+
if (locator.Generation < generation) {
234+
DeleteQueueInPrevGenerations.push_back(locator);
235+
} else {
236+
Y_DEBUG_ABORT_UNLESS(locator.Generation == generation);
237+
DeleteQueueInCurrentGeneration.push_back(locator);
238+
}
239+
}
222240
RunDeletersIfNeeded();
223241
}
224242
})

ydb/core/blob_depot/s3_write.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ namespace NKikimr::NBlobDepot {
9898
};
9999

100100
TS3Locator TS3Manager::AllocateS3Locator(ui32 len) {
101-
if (!DeleteQueue.empty()) {
102-
TS3Locator res = DeleteQueue.front();
103-
DeleteQueue.pop_front();
101+
if (!DeleteQueueInCurrentGeneration.empty()) {
102+
TS3Locator res = DeleteQueueInCurrentGeneration.front();
103+
DeleteQueueInCurrentGeneration.pop_front();
104104
Self->TabletCounters->Simple()[NKikimrBlobDepot::COUNTER_TOTAL_S3_TRASH_OBJECTS] = --TotalS3TrashObjects;
105105
Self->TabletCounters->Simple()[NKikimrBlobDepot::COUNTER_TOTAL_S3_TRASH_SIZE] = TotalS3TrashSize -= res.Len;
106106
res.Len = len;

0 commit comments

Comments
 (0)