Skip to content

Commit da72c65

Browse files
committed
[improvement](be) Export file cache remote index byte metrics
Issue Number: None Related PR: None Problem Summary: File cache profile statistics already track `inverted_index_bytes_read_from_remote` and `segment_footer_index_bytes_read_from_remote`, but BE Doris metrics only exported aggregate cache, remote, and peer read bytes. That made these index-specific remote read costs visible in query profile only, not in the BE metrics endpoint. This change registers two new Doris metrics, extends the existing `FileCacheMetrics` aggregation path to accumulate them, and exports them through the normal metrics hook. The update also extends the existing file cache profile unit test helpers so segment footer index statistics are covered and adds a test for the new metric export path. Expose `inverted_index_bytes_read_from_remote` and `segment_footer_index_bytes_read_from_remote` in BE Doris metrics. - Test: Manual compile verification - Started `./run-be-ut.sh --run --filter=FileCacheProfileReporterTest.*`, but it triggered a large `doris_be_test` rebuild and was interrupted after the changed objects compiled successfully - Recompiled changed objects with `ninja -C be/ut_build_ASAN src/common/CMakeFiles/Common.dir/metrics/doris_metrics.cpp.o src/io/CMakeFiles/IO.dir/cache/block_file_cache_profile.cpp.o test/CMakeFiles/doris_be_test.dir/io/cache/block_file_cache_profile_reporter_test.cpp.o` - Behavior changed: Yes (adds two new BE metrics for file cache remote index bytes) - Does this need documentation: No
1 parent ab044d6 commit da72c65

6 files changed

Lines changed: 212 additions & 0 deletions

File tree

be/src/common/metrics/doris_metrics.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,9 @@ DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(num_io_bytes_read_total, MetricUnit::OPERAT
243243
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(num_io_bytes_read_from_cache, MetricUnit::OPERATIONS);
244244
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(num_io_bytes_read_from_remote, MetricUnit::OPERATIONS);
245245
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(num_io_bytes_read_from_peer, MetricUnit::OPERATIONS);
246+
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(inverted_index_bytes_read_from_remote, MetricUnit::BYTES);
247+
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(segment_footer_index_bytes_read_from_remote,
248+
MetricUnit::BYTES);
246249

247250
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(udf_close_bthread_count, MetricUnit::OPERATIONS);
248251

@@ -427,6 +430,8 @@ DorisMetrics::DorisMetrics() : _metric_registry(_s_registry_name) {
427430
INT_COUNTER_METRIC_REGISTER(_server_metric_entity, num_io_bytes_read_from_cache);
428431
INT_COUNTER_METRIC_REGISTER(_server_metric_entity, num_io_bytes_read_from_remote);
429432
INT_COUNTER_METRIC_REGISTER(_server_metric_entity, num_io_bytes_read_from_peer);
433+
INT_COUNTER_METRIC_REGISTER(_server_metric_entity, inverted_index_bytes_read_from_remote);
434+
INT_COUNTER_METRIC_REGISTER(_server_metric_entity, segment_footer_index_bytes_read_from_remote);
430435

431436
INT_COUNTER_METRIC_REGISTER(_server_metric_entity, udf_close_bthread_count);
432437

be/src/common/metrics/doris_metrics.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,8 @@ class DorisMetrics {
258258
IntCounter* num_io_bytes_read_from_cache = nullptr;
259259
IntCounter* num_io_bytes_read_from_remote = nullptr;
260260
IntCounter* num_io_bytes_read_from_peer = nullptr;
261+
IntCounter* inverted_index_bytes_read_from_remote = nullptr;
262+
IntCounter* segment_footer_index_bytes_read_from_remote = nullptr;
261263

262264
IntCounter* udf_close_bthread_count = nullptr;
263265

be/src/io/cache/block_file_cache_profile.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ std::shared_ptr<AtomicStatistics> FileCacheMetrics::report() {
3131
output_stats->num_io_bytes_read_from_cache += _statistics->num_io_bytes_read_from_cache;
3232
output_stats->num_io_bytes_read_from_remote += _statistics->num_io_bytes_read_from_remote;
3333
output_stats->num_io_bytes_read_from_peer += _statistics->num_io_bytes_read_from_peer;
34+
output_stats->inverted_index_bytes_read_from_remote +=
35+
_statistics->inverted_index_bytes_read_from_remote;
36+
output_stats->segment_footer_index_bytes_read_from_remote +=
37+
_statistics->segment_footer_index_bytes_read_from_remote;
3438
return output_stats;
3539
}
3640

@@ -45,6 +49,10 @@ void FileCacheMetrics::update(FileCacheStatistics* input_stats) {
4549
_statistics->num_io_bytes_read_from_cache += input_stats->bytes_read_from_local;
4650
_statistics->num_io_bytes_read_from_remote += input_stats->bytes_read_from_remote;
4751
_statistics->num_io_bytes_read_from_peer += input_stats->bytes_read_from_peer;
52+
_statistics->inverted_index_bytes_read_from_remote +=
53+
input_stats->inverted_index_bytes_read_from_remote;
54+
_statistics->segment_footer_index_bytes_read_from_remote +=
55+
input_stats->segment_footer_index_bytes_read_from_remote;
4856
}
4957

5058
void FileCacheMetrics::register_entity() {
@@ -63,6 +71,10 @@ void FileCacheMetrics::update_metrics_callback() {
6371
DorisMetrics::instance()->num_io_bytes_read_total->set_value(
6472
stats->num_io_bytes_read_from_cache + stats->num_io_bytes_read_from_remote +
6573
stats->num_io_bytes_read_from_peer);
74+
DorisMetrics::instance()->inverted_index_bytes_read_from_remote->set_value(
75+
stats->inverted_index_bytes_read_from_remote);
76+
DorisMetrics::instance()->segment_footer_index_bytes_read_from_remote->set_value(
77+
stats->segment_footer_index_bytes_read_from_remote);
6678
}
6779

6880
FileCacheStatistics diff_file_cache_statistics(const FileCacheStatistics& current,

be/src/io/cache/block_file_cache_profile.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ struct AtomicStatistics {
3838
std::atomic<int64_t> num_io_bytes_read_from_cache = 0;
3939
std::atomic<int64_t> num_io_bytes_read_from_remote = 0;
4040
std::atomic<int64_t> num_io_bytes_read_from_peer = 0;
41+
std::atomic<int64_t> inverted_index_bytes_read_from_remote = 0;
42+
std::atomic<int64_t> segment_footer_index_bytes_read_from_remote = 0;
4143
};
4244
class FileCacheMetrics {
4345
public:

be/test/util/doris_metrics_test.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,29 @@
2121
#include <gtest/gtest-test-part.h>
2222

2323
#include "gtest/gtest_pred_impl.h"
24+
#include "io/cache/block_file_cache_profile.h"
2425

2526
namespace doris {
27+
namespace {
28+
29+
struct IndexRemoteMetricSnapshot {
30+
int64_t inverted_index_remote = 0;
31+
int64_t segment_footer_index_remote = 0;
32+
};
33+
34+
IndexRemoteMetricSnapshot get_index_remote_metric_snapshot() {
35+
io::FileCacheStatistics empty_stats;
36+
io::FileCacheMetrics::instance().update(&empty_stats);
37+
DorisMetrics::instance()->server_entity()->trigger_hook_unlocked(true);
38+
return {
39+
.inverted_index_remote =
40+
DorisMetrics::instance()->inverted_index_bytes_read_from_remote->value(),
41+
.segment_footer_index_remote =
42+
DorisMetrics::instance()->segment_footer_index_bytes_read_from_remote->value(),
43+
};
44+
}
45+
46+
} // namespace
2647

2748
class DorisMetricsTest : public testing::Test {
2849
public:
@@ -191,4 +212,19 @@ TEST_F(DorisMetricsTest, Normal) {
191212
}
192213
}
193214

215+
TEST_F(DorisMetricsTest, FileCacheMetricsExportRemoteIndexBytes) {
216+
const auto before = get_index_remote_metric_snapshot();
217+
218+
io::FileCacheStatistics stats;
219+
stats.inverted_index_bytes_read_from_remote = 23;
220+
stats.segment_footer_index_bytes_read_from_remote = 33;
221+
io::FileCacheMetrics::instance().update(&stats);
222+
223+
const auto after = get_index_remote_metric_snapshot();
224+
EXPECT_EQ(after.inverted_index_remote - before.inverted_index_remote,
225+
stats.inverted_index_bytes_read_from_remote);
226+
EXPECT_EQ(after.segment_footer_index_remote - before.segment_footer_index_remote,
227+
stats.segment_footer_index_bytes_read_from_remote);
228+
}
229+
194230
} // namespace doris
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
import org.apache.doris.regression.suite.ClusterOptions
19+
import org.apache.doris.regression.util.Http
20+
21+
suite("test_file_cache_remote_index_byte_metrics", "docker") {
22+
23+
final String remoteClusterName = "remote_metrics_cluster"
24+
final String invertedMetric = "doris_be_inverted_index_bytes_read_from_remote"
25+
final String segmentMetric = "doris_be_segment_footer_index_bytes_read_from_remote"
26+
27+
def options = new ClusterOptions()
28+
options.feConfigs += [
29+
'cloud_cluster_check_interval_second=1',
30+
'heartbeat_interval_second=1',
31+
'auto_check_statistics_in_minutes=60',
32+
'sys_log_verbose_modules=org',
33+
]
34+
options.beConfigs += [
35+
'report_tablet_interval_seconds=1',
36+
'schedule_sync_tablets_interval_s=18000',
37+
'disable_auto_compaction=true',
38+
'enable_file_cache=true',
39+
'enable_cache_read_from_peer=false',
40+
'enable_peer_s3_race=false',
41+
'enable_packed_file=false',
42+
'file_cache_each_block_size=4096',
43+
'file_cache_enter_disk_resource_limit_mode_percent=99',
44+
'file_cache_exit_disk_resource_limit_mode_percent=98',
45+
'file_cache_enter_need_evict_cache_in_advance_percent=99',
46+
'file_cache_exit_need_evict_cache_in_advance_percent=98',
47+
'JEMALLOC_CONF="percpu_arena:percpu,background_thread:true,metadata_thp:auto,muzzy_decay_ms:5000,dirty_decay_ms:5000,oversize_threshold:0,prof:false,prof_active:false,lg_prof_interval:-1,lg_extent_max_active_fit:8"',
48+
]
49+
options.extraHosts += [
50+
'host.docker.internal:host-gateway',
51+
'metrics-test-bucket.host.docker.internal:host-gateway',
52+
]
53+
options.setFeNum(1)
54+
options.setBeNum(1)
55+
options.cloudMode = true
56+
57+
def readMetric = { String host, Object httpPort, String metricName ->
58+
def metricsText = Http.GET("http://${host}:${httpPort}/metrics", false, false).toString()
59+
def matcher = metricsText =~ ('(?m)^' + java.util.regex.Pattern.quote(metricName) + '\\s+(\\d+)$')
60+
assertTrue(matcher.find(), "metric not found: ${metricName}")
61+
return matcher.group(1).toLong()
62+
}
63+
64+
def clearFileCache = { String host, Object httpPort ->
65+
def result = Http.GET("http://${host}:${httpPort}/api/file_cache?op=clear&sync=true", true, false)
66+
assertEquals("OK", result.status)
67+
}
68+
69+
def findBackendByClusterName = { rows, String clusterName ->
70+
return rows.find { row ->
71+
def tag = (row.Tag ?: "").toString()
72+
tag.contains("\"compute_group_name\"") && tag.contains("\"${clusterName}\"")
73+
}
74+
}
75+
76+
def firstInsert = (1..24).collect { i ->
77+
def body = (i % 6 == 0 || i % 7 == 0) ?
78+
"quick brown profile needlequick row ${i}" :
79+
"quick brown profile ordinarytoken row ${i}"
80+
return "(${i}, ${200 - i}, 'title_${i}', '${body}', 'payload_${i}_abcdefghijklmnopqrstuvwxyz')"
81+
}.join(",\n")
82+
83+
def secondInsert = (25..48).collect { i ->
84+
def body = (i % 6 == 0 || i % 7 == 0) ?
85+
"quick brown profile needlequick row ${i}" :
86+
"quick brown profile ordinarytoken row ${i}"
87+
return "(${i}, ${200 - i}, 'title_${i}', '${body}', 'payload_${i}_abcdefghijklmnopqrstuvwxyz')"
88+
}.join(",\n")
89+
90+
docker(options) {
91+
def tableName = "test_file_cache_remote_index_byte_metrics_tbl"
92+
93+
sql "use @compute_cluster"
94+
sql """ DROP TABLE IF EXISTS ${tableName} FORCE """
95+
sql """
96+
CREATE TABLE ${tableName} (
97+
id INT,
98+
sort_key INT,
99+
title VARCHAR(128),
100+
body STRING,
101+
payload STRING,
102+
INDEX body_idx(body) USING INVERTED PROPERTIES("parser" = "english") COMMENT ''
103+
)
104+
DUPLICATE KEY(id)
105+
DISTRIBUTED BY HASH(id) BUCKETS 4
106+
PROPERTIES (
107+
"replication_num" = "1",
108+
"disable_auto_compaction" = "true",
109+
"inverted_index_storage_format" = "V2"
110+
)
111+
"""
112+
sql """ INSERT INTO ${tableName} VALUES ${firstInsert} """
113+
sql """ INSERT INTO ${tableName} VALUES ${secondInsert} """
114+
sql """ SYNC """
115+
116+
cluster.addBackend(1, remoteClusterName)
117+
awaitUntil(60) {
118+
findBackendByClusterName(sql_return_maparray("show backends"), remoteClusterName) != null
119+
}
120+
121+
def remoteBe = findBackendByClusterName(sql_return_maparray("show backends"), remoteClusterName)
122+
assertNotNull(remoteBe)
123+
def remoteBeHost = remoteBe.Host.toString()
124+
def remoteBeHttpPort = remoteBe.HttpPort
125+
126+
sql "use @${remoteClusterName}"
127+
128+
clearFileCache(remoteBeHost, remoteBeHttpPort)
129+
long segmentBefore = readMetric(remoteBeHost, remoteBeHttpPort, segmentMetric)
130+
def fullScanResult = sql """ SELECT id FROM ${tableName} ORDER BY id """
131+
assertEquals(48, fullScanResult.size())
132+
awaitUntil(30) {
133+
readMetric(remoteBeHost, remoteBeHttpPort, segmentMetric) > segmentBefore
134+
}
135+
long segmentAfter = readMetric(remoteBeHost, remoteBeHttpPort, segmentMetric)
136+
assertTrue(segmentAfter > segmentBefore,
137+
"${segmentMetric} should increase after remote full scan, before=${segmentBefore}, after=${segmentAfter}")
138+
139+
clearFileCache(remoteBeHost, remoteBeHttpPort)
140+
long invertedBefore = readMetric(remoteBeHost, remoteBeHttpPort, invertedMetric)
141+
def invertedQueryResult = sql """
142+
SELECT id
143+
FROM ${tableName}
144+
WHERE body MATCH_ALL 'needlequick'
145+
ORDER BY id
146+
"""
147+
assertTrue(invertedQueryResult.size() > 0)
148+
awaitUntil(30) {
149+
readMetric(remoteBeHost, remoteBeHttpPort, invertedMetric) > invertedBefore
150+
}
151+
long invertedAfter = readMetric(remoteBeHost, remoteBeHttpPort, invertedMetric)
152+
assertTrue(invertedAfter > invertedBefore,
153+
"${invertedMetric} should increase after remote inverted index query, before=${invertedBefore}, after=${invertedAfter}")
154+
}
155+
}

0 commit comments

Comments
 (0)