Skip to content

Add metrics for part number in MergeTree in ClickHouse#17838

Merged
alexey-milovidov merged 17 commits intoClickHouse:masterfrom
weeds085490:dev/add_metrics_for_parts
Jan 7, 2021
Merged

Add metrics for part number in MergeTree in ClickHouse#17838
alexey-milovidov merged 17 commits intoClickHouse:masterfrom
weeds085490:dev/add_metrics_for_parts

Conversation

@weeds085490
Copy link
Copy Markdown
Contributor

@weeds085490 weeds085490 commented Dec 6, 2020

I hereby agree to the terms of the CLA available at: https://yandex.ru/legal/cla/?lang=en

Changelog category (leave one):

  • Improvement

Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):

Add metrics(Parts, PartsActive, PartsInactive) for part number in MergeTree in clickhouse

Detailed description / Documentation draft:

PartsActive corresponds to the commited parts.
PartsInactive corresponds to the parts which are not in commited status.
Parts corresponds to the total number of parts in clickhouse.

We need to deal with three scenarios to calculate PartsPartsInactivePartsInactive.

  • When the table is loaded, recount according to the parts status.
  • When the table is dropped, recount according to the parts status.
  • Handle the transfer of parts state.

details:
image

@robot-clickhouse robot-clickhouse added the pr-improvement Pull request with some product improvements label Dec 6, 2020
@sundy-li
Copy link
Copy Markdown
Contributor

sundy-li commented Dec 6, 2020

BTW, it's a summary metric, why not use system.parts, it has more detail metrics (per database, table ...).
And it's also a table in memory for statistics, clickhouse exporters (or custom HTTP metrics handler) work good with it.

@weeds085490
Copy link
Copy Markdown
Contributor Author

BTW, it's a summary metric, why not use system.parts, it has more detail metrics (per database, table ...).
And it's also a table in memory for statistics, clickhouse exporters (or custom HTTP metrics handler) work good with it.

When we are building the monitoring system of clickhouse, we find the number of parts is an important indicator of the overall situation of a cluster. We recommend adding this information to the default metrics just like PartMutationReplicatedFetch.

It is worth mentioning that it is indeed possible to collect monitoring data from system.parts through TCP or HTTP interface. We have two main considerations:

  • Every time you pull, the number of parts must be recalculated.
  • Since the growth state of parts is an important indicator of whether the cluster is normal, it should be added to the default metrics.

@weeds085490
Copy link
Copy Markdown
Contributor Author

BTW, it's a summary metric, why not use system.parts, it has more detail metrics (per database, table ...).
And it's also a table in memory for statistics, clickhouse exporters (or custom HTTP metrics handler) work good with it.

We can also get information about merge from system.merges, but we also need to add Merge to the default metrics

@weeds085490
Copy link
Copy Markdown
Contributor Author

@akuzm I have added functional tests for the code. Under normal circumstances, the number of Parts is the same as the data aggregated by system.parts. If we delete the table in the atomic database, the deletion of the table is lazy. At this time, the data may be temporarily inconsistent. PTAL.

@alexey-milovidov
Copy link
Copy Markdown
Member

@weeds085490 The code looks Ok but the tests deadlocked. I don't see the reason.
Could you please merge/rebase with master?

@weeds085490
Copy link
Copy Markdown
Contributor Author

@weeds085490 The code looks Ok but the tests deadlocked. I don't see the reason.
Could you please merge/rebase with master?

Thanks for reviewing. I have merged with master. PTAL

@weeds085490
Copy link
Copy Markdown
Contributor Author

@weeds085490 The code looks Ok but the tests deadlocked. I don't see the reason.
Could you please merge/rebase with master?

Thanks for reviewing. I have merged with master. PTAL

@alexey-milovidov DROP TABLE test_table in my function test still hung. It passed when test it locally.

@weeds085490
Copy link
Copy Markdown
Contributor Author

@weeds085490 The code looks Ok but the tests deadlocked. I don't see the reason.
Could you please merge/rebase with master?

Thanks for reviewing. I have merged with master. PTAL

@alexey-milovidov DROP TABLE test_table in my function test still hung. It passed when test it locally.

image

LOG_TRACE(log, "dropAllData: removing data from memory.");

DataPartsVector all_parts(data_parts_by_info.begin(), data_parts_by_info.end());
DataPartsVector committed_parts = getDataPartsVector({DataPartState::Committed});
Copy link
Copy Markdown
Member

@alexey-milovidov alexey-milovidov Dec 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't it involve recursive mutex locking (see a few lines above)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't it involve recursive mutex locking (see a few lines above)?

That did cause a deadlock. If I use an Ordinary database, the deadlock will definitely occur when dropping table.

@alexey-milovidov I have fixed it. PTAL.

@alexey-milovidov alexey-milovidov self-assigned this Dec 21, 2020
@weeds085490
Copy link
Copy Markdown
Contributor Author

weeds085490 commented Dec 23, 2020

@alexey-milovidov I have modified the code to make the monitored data consistent with the data obtained by the system.parts query.

  • The failed test: Functional stateless tests (release, wide parts enabled) may not related to my code.
  • The failed test: Functional stateless tests flaky check (address) may be caused by tempory temporary inconsistency.

image

It becomes consistent after the first query possibly caused by query_log. PTAL

@alexey-milovidov
Copy link
Copy Markdown
Member

@weeds085490
How this temporary inconsistency possible and how it is related to the query_log?

@weeds085490
Copy link
Copy Markdown
Contributor Author

@weeds085490
How this temporary inconsistency possible and how it is related to the query_log?

During the SQL execution of clickhouse, the input data is not based on the same snapshot. For the same filter, we may get two different data in the same SQL when other threads are inserting new data. Let‘s look at execution log of the failed test:
Functional stateless tests flaky check (address)

image

when executing the SQL:

SELECT COUNT(1) FROM (SELECT SUM(IF(metric = 'Parts', value, 0)) AS Parts, SUM(IF(metric = 'PartsActive', value, 0)) AS PartsActive, SUM(IF(metric = 'PartsInactive', value, 0)) AS PartsInactive FROM system.metrics) as a INNER JOIN (SELECT toInt64(SUM(1)) AS Parts, toInt64(SUM(IF(active = 1, 1, 0))) AS PartsActive, toInt64(SUM(IF(active = 0, 1, 0))) AS PartsInactive FROM system.parts ) as b USING (Parts,PartsActive,PartsInactive);

A new part: 202012_23_23_0 is inserted. So the different input stream may get different parts info.

Then I do another test:

Reducing the flush_interval_milliseconds and collect_interval_milliseconds of metric_log.
I can reproduce this short-term inconsistency stably.

image

If I close metric_log, then this short-term inconsistency will never reproduce.

@alexey-milovidov PTAL.

@weeds085490
Copy link
Copy Markdown
Contributor Author

@weeds085490
How this temporary inconsistency possible and how it is related to the query_log?

During the SQL execution of clickhouse, the input data is not based on the same snapshot. For the same filter, we may get two different data in the same SQL when other threads are inserting new data. Let‘s look at execution log of the failed test:
Functional stateless tests flaky check (address)

image

when executing the SQL:

SELECT COUNT(1) FROM (SELECT SUM(IF(metric = 'Parts', value, 0)) AS Parts, SUM(IF(metric = 'PartsActive', value, 0)) AS PartsActive, SUM(IF(metric = 'PartsInactive', value, 0)) AS PartsInactive FROM system.metrics) as a INNER JOIN (SELECT toInt64(SUM(1)) AS Parts, toInt64(SUM(IF(active = 1, 1, 0))) AS PartsActive, toInt64(SUM(IF(active = 0, 1, 0))) AS PartsInactive FROM system.parts ) as b USING (Parts,PartsActive,PartsInactive);

A new part: 202012_23_23_0 is inserted. So the different input stream may get different parts info.

Then I do another test:

Reducing the flush_interval_milliseconds and collect_interval_milliseconds of metric_log.
I can reproduce this short-term inconsistency stably.

image

If I close metric_log, then this short-term inconsistency will never reproduce.

@alexey-milovidov PTAL.

@alexey-milovidov Hi, PTAL

@alexey-milovidov
Copy link
Copy Markdown
Member

Ok but it means we need to rewrite the test in another way...

@weeds085490
Copy link
Copy Markdown
Contributor Author

@alexey-milovidov I have changed the test method. All functional tests have passed. PTAL

Copy link
Copy Markdown
Member

@alexey-milovidov alexey-milovidov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@alexey-milovidov alexey-milovidov merged commit f91626e into ClickHouse:master Jan 7, 2021
@alexey-milovidov
Copy link
Copy Markdown
Member

Sorry, the test is still flaky, I will revert this PR and we need to resubmit it.

) as b USING (Parts,PartsActive,PartsInactive)"

verify(){
for _ in $(seq 1 10)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexey-milovidov
Copy link
Copy Markdown
Member

It failed 4 out of 16 times.

@weeds085490
Copy link
Copy Markdown
Contributor Author

It failed 4 out of 16 times.

Ok. Let me take a look

@alexey-milovidov
Copy link
Copy Markdown
Member

I will try to revive changes in #18955

@alexey-milovidov
Copy link
Copy Markdown
Member

@weeds085490 See #19122.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-improvement Pull request with some product improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants