Skip to content

Commit 79015e3

Browse files
authored
Merge pull request ClickHouse#79228 from ClickHouse/failing-merges-metrics
metrics on failing merges
2 parents 661ea2a + 62a39e3 commit 79015e3

File tree

2 files changed

+37
-40
lines changed

2 files changed

+37
-40
lines changed

src/Storages/MergeTree/MergeTask.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ namespace ProfileEvents
7777
namespace CurrentMetrics
7878
{
7979
extern const Metric TemporaryFilesForMerge;
80+
extern const Metric NonAbortedMergeFailures;
81+
extern const Metric TotalMergeFailures;
8082
}
8183

8284
namespace DB
@@ -1473,6 +1475,7 @@ bool MergeTask::VerticalMergeStage::executeVerticalMergeForAllColumns() const
14731475

14741476

14751477
bool MergeTask::execute()
1478+
try
14761479
{
14771480
chassert(stages_iterator != stages.end());
14781481
const auto & current_stage = *stages_iterator;
@@ -1503,6 +1506,16 @@ bool MergeTask::execute()
15031506
(*stages_iterator)->setRuntimeContext(std::move(next_stage_context), global_ctx);
15041507
return true;
15051508
}
1509+
catch (...)
1510+
{
1511+
const auto error_code = getCurrentExceptionCode();
1512+
if (error_code != ErrorCodes::ABORTED)
1513+
{
1514+
CurrentMetrics::add(CurrentMetrics::NonAbortedMergeFailures);
1515+
}
1516+
CurrentMetrics::add(CurrentMetrics::TotalMergeFailures);
1517+
throw;
1518+
}
15061519

15071520
void MergeTask::cancel() noexcept
15081521
{

src/Storages/MergeTree/MutateTask.cpp

Lines changed: 24 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#include <DataTypes/ObjectUtils.h>
44
#include <Disks/SingleDiskVolume.h>
55
#include <IO/HashingWriteBuffer.h>
6-
#include <Common/CurrentMetrics.h>
76
#include <Common/logger_useful.h>
87
#include <Common/escapeForFileName.h>
98
#include <Core/Settings.h>
@@ -55,8 +54,6 @@ namespace ProfileEvents
5554
namespace CurrentMetrics
5655
{
5756
extern const Metric PartMutation;
58-
extern const Metric TotalMergeFailures;
59-
extern const Metric NonAbortedMergeFailures;
6057
}
6158

6259
namespace DB
@@ -2099,50 +2096,37 @@ bool MutateTask::execute()
20992096
Stopwatch watch;
21002097
SCOPE_EXIT({ ctx->execute_elapsed_ns += watch.elapsedNanoseconds(); });
21012098

2102-
try
2099+
switch (state)
21032100
{
2104-
switch (state)
2101+
case State::NEED_PREPARE:
21052102
{
2106-
case State::NEED_PREPARE:
2107-
{
2108-
if (!prepare())
2109-
return false;
2110-
2111-
state = State::NEED_EXECUTE;
2112-
return true;
2113-
}
2114-
case State::NEED_EXECUTE:
2115-
{
2116-
ctx->checkOperationIsNotCanceled();
2117-
2118-
if (task->executeStep())
2119-
return true;
2120-
2121-
// The `new_data_part` is a shared pointer and must be moved to allow
2122-
// part deletion in case it is needed in `MutateFromLogEntryTask::finalize`.
2123-
//
2124-
// `tryRemovePartImmediately` requires `std::shared_ptr::unique() == true`
2125-
// to delete the part timely. When there are multiple shared pointers,
2126-
// only the part state is changed to `Deleting`.
2127-
//
2128-
// Fetching a byte-identical part (in case of checksum mismatches) will fail with
2129-
// `Part ... should be deleted after previous attempt before fetch`.
2130-
promise.set_value(std::move(ctx->new_data_part));
2103+
if (!prepare())
21312104
return false;
2132-
}
2105+
2106+
state = State::NEED_EXECUTE;
2107+
return true;
21332108
}
2134-
return false;
2135-
}
2136-
catch (...)
2137-
{
2138-
const auto error_code = getCurrentExceptionCode();
2139-
if (error_code != ErrorCodes::ABORTED)
2109+
case State::NEED_EXECUTE:
21402110
{
2141-
CurrentMetrics::add(CurrentMetrics::NonAbortedMergeFailures);
2111+
ctx->checkOperationIsNotCanceled();
2112+
2113+
if (task->executeStep())
2114+
return true;
2115+
2116+
// The `new_data_part` is a shared pointer and must be moved to allow
2117+
// part deletion in case it is needed in `MutateFromLogEntryTask::finalize`.
2118+
//
2119+
// `tryRemovePartImmediately` requires `std::shared_ptr::unique() == true`
2120+
// to delete the part timely. When there are multiple shared pointers,
2121+
// only the part state is changed to `Deleting`.
2122+
//
2123+
// Fetching a byte-identical part (in case of checksum mismatches) will fail with
2124+
// `Part ... should be deleted after previous attempt before fetch`.
2125+
promise.set_value(std::move(ctx->new_data_part));
2126+
return false;
21422127
}
2143-
CurrentMetrics::add(CurrentMetrics::TotalMergeFailures);
2144-
throw;
21452128
}
2129+
return false;
21462130
}
21472131

21482132
void MutateTask::cancel() noexcept

0 commit comments

Comments
 (0)