|
| 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