Skip to content

Commit a299dad

Browse files
Backport #66898 to 24.7: [CI Fest] Better processing of broken parts and their projections (fixes rare cases of lost forever)
1 parent 111e3a2 commit a299dad

File tree

3 files changed

+27
-18
lines changed

3 files changed

+27
-18
lines changed

src/Storages/MergeTree/DataPartsExchange.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <Storages/MergeTree/DataPartStorageOnDiskFull.h>
1717
#include <Storages/MergeTree/MergeTreeData.h>
1818
#include <Storages/MergeTree/MergeTreeSettings.h>
19+
#include <Storages/MergeTree/checkDataPart.h>
1920
#include <Common/CurrentMetrics.h>
2021
#include <Common/NetException.h>
2122
#include <Common/randomDelay.h>
@@ -224,14 +225,18 @@ void Service::processQuery(const HTMLForm & params, ReadBuffer & /*body*/, Write
224225
}
225226
catch (const Exception & e)
226227
{
227-
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+
{
228231
report_broken_part();
232+
}
229233

230234
throw;
231235
}
232236
catch (...)
233237
{
234-
report_broken_part();
238+
if (!isRetryableException(std::current_exception()))
239+
report_broken_part();
235240
throw;
236241
}
237242
}

src/Storages/MergeTree/MergeTreeSequentialSource.cpp

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

1920
namespace DB
2021
{
2122

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

src/Storages/MergeTree/checkDataPart.cpp

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,13 @@ namespace ErrorCodes
3636
extern const int CANNOT_ALLOCATE_MEMORY;
3737
extern const int CANNOT_MUNMAP;
3838
extern const int CANNOT_MREMAP;
39+
extern const int CANNOT_SCHEDULE_TASK;
3940
extern const int UNEXPECTED_FILE_IN_DATA_PART;
4041
extern const int NO_FILE_IN_DATA_PART;
4142
extern const int NETWORK_ERROR;
4243
extern const int SOCKET_TIMEOUT;
4344
extern const int BROKEN_PROJECTION;
45+
extern const int ABORTED;
4446
}
4547

4648

@@ -85,7 +87,9 @@ bool isRetryableException(std::exception_ptr exception_ptr)
8587
{
8688
return isNotEnoughMemoryErrorCode(e.code())
8789
|| e.code() == ErrorCodes::NETWORK_ERROR
88-
|| e.code() == ErrorCodes::SOCKET_TIMEOUT;
90+
|| e.code() == ErrorCodes::SOCKET_TIMEOUT
91+
|| e.code() == ErrorCodes::CANNOT_SCHEDULE_TASK
92+
|| e.code() == ErrorCodes::ABORTED;
8993
}
9094
catch (const Poco::Net::NetException &)
9195
{
@@ -329,16 +333,21 @@ static IMergeTreeDataPart::Checksums checkDataPart(
329333
projections_on_disk.erase(projection_file);
330334
}
331335

332-
if (throw_on_broken_projection && !broken_projections_message.empty())
336+
if (throw_on_broken_projection)
333337
{
334-
throw Exception(ErrorCodes::BROKEN_PROJECTION, "{}", broken_projections_message);
335-
}
338+
if (!broken_projections_message.empty())
339+
{
340+
throw Exception(ErrorCodes::BROKEN_PROJECTION, "{}", broken_projections_message);
341+
}
336342

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

344353
if (is_cancelled())

0 commit comments

Comments
 (0)