Skip to content

Commit f30c2a7

Browse files
Backport #66898 to 24.4: [CI Fest] Better processing of broken parts and their projections (fixes rare cases of lost forever)
1 parent 4bfa98d commit f30c2a7

File tree

3 files changed

+28
-18
lines changed

3 files changed

+28
-18
lines changed

src/Storages/MergeTree/DataPartsExchange.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
#include <Storages/StorageReplicatedMergeTree.h>
1616
#include <Storages/MergeTree/DataPartStorageOnDiskFull.h>
1717
#include <Storages/MergeTree/MergeTreeData.h>
18+
#include <Storages/MergeTree/MergeTreeSettings.h>
19+
#include <Storages/MergeTree/checkDataPart.h>
1820
#include <Common/CurrentMetrics.h>
1921
#include <Common/NetException.h>
2022
#include <Common/randomDelay.h>
@@ -223,14 +225,18 @@ void Service::processQuery(const HTMLForm & params, ReadBuffer & /*body*/, Write
223225
}
224226
catch (const Exception & e)
225227
{
226-
if (e.code() != ErrorCodes::ABORTED && e.code() != ErrorCodes::CANNOT_WRITE_TO_OSTREAM)
228+
if (e.code() != ErrorCodes::CANNOT_WRITE_TO_OSTREAM
229+
&& !isRetryableException(std::current_exception()))
230+
{
227231
report_broken_part();
232+
}
228233

229234
throw;
230235
}
231236
catch (...)
232237
{
233-
report_broken_part();
238+
if (!isRetryableException(std::current_exception()))
239+
report_broken_part();
234240
throw;
235241
}
236242
}

src/Storages/MergeTree/MergeTreeSequentialSource.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,11 @@
1414
#include <Processors/QueryPlan/FilterStep.h>
1515
#include <Common/logger_useful.h>
1616
#include <Processors/Merges/Algorithms/MergeTreePartLevelInfo.h>
17+
#include <Storages/MergeTree/checkDataPart.h>
1718

1819
namespace DB
1920
{
2021

21-
namespace ErrorCodes
22-
{
23-
extern const int MEMORY_LIMIT_EXCEEDED;
24-
}
25-
26-
2722
/// Lightweight (in terms of logic) stream for reading single part from
2823
/// MergeTree, used for merges and mutations.
2924
///
@@ -286,7 +281,7 @@ try
286281
catch (...)
287282
{
288283
/// Suspicion of the broken part. A part is added to the queue for verification.
289-
if (getCurrentExceptionCode() != ErrorCodes::MEMORY_LIMIT_EXCEEDED)
284+
if (!isRetryableException(std::current_exception()))
290285
storage.reportBrokenPart(data_part);
291286
throw;
292287
}

src/Storages/MergeTree/checkDataPart.cpp

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,13 @@ namespace ErrorCodes
3535
extern const int CANNOT_ALLOCATE_MEMORY;
3636
extern const int CANNOT_MUNMAP;
3737
extern const int CANNOT_MREMAP;
38+
extern const int CANNOT_SCHEDULE_TASK;
3839
extern const int UNEXPECTED_FILE_IN_DATA_PART;
3940
extern const int NO_FILE_IN_DATA_PART;
4041
extern const int NETWORK_ERROR;
4142
extern const int SOCKET_TIMEOUT;
4243
extern const int BROKEN_PROJECTION;
44+
extern const int ABORTED;
4345
}
4446

4547

@@ -84,7 +86,9 @@ bool isRetryableException(std::exception_ptr exception_ptr)
8486
{
8587
return isNotEnoughMemoryErrorCode(e.code())
8688
|| e.code() == ErrorCodes::NETWORK_ERROR
87-
|| e.code() == ErrorCodes::SOCKET_TIMEOUT;
89+
|| e.code() == ErrorCodes::SOCKET_TIMEOUT
90+
|| e.code() == ErrorCodes::CANNOT_SCHEDULE_TASK
91+
|| e.code() == ErrorCodes::ABORTED;
8892
}
8993
catch (const Poco::Net::NetException &)
9094
{
@@ -328,16 +332,21 @@ static IMergeTreeDataPart::Checksums checkDataPart(
328332
projections_on_disk.erase(projection_file);
329333
}
330334

331-
if (throw_on_broken_projection && !broken_projections_message.empty())
335+
if (throw_on_broken_projection)
332336
{
333-
throw Exception(ErrorCodes::BROKEN_PROJECTION, "{}", broken_projections_message);
334-
}
337+
if (!broken_projections_message.empty())
338+
{
339+
throw Exception(ErrorCodes::BROKEN_PROJECTION, "{}", broken_projections_message);
340+
}
335341

336-
if (require_checksums && !projections_on_disk.empty())
337-
{
338-
throw Exception(ErrorCodes::UNEXPECTED_FILE_IN_DATA_PART,
339-
"Found unexpected projection directories: {}",
340-
fmt::join(projections_on_disk, ","));
342+
/// This one is actually not broken, just redundant files on disk which
343+
/// MergeTree will never use.
344+
if (require_checksums && !projections_on_disk.empty())
345+
{
346+
throw Exception(ErrorCodes::UNEXPECTED_FILE_IN_DATA_PART,
347+
"Found unexpected projection directories: {}",
348+
fmt::join(projections_on_disk, ","));
349+
}
341350
}
342351

343352
if (is_cancelled())

0 commit comments

Comments
 (0)