From 996dda3f63b8207e9bc349c48c9b573288954f7e Mon Sep 17 00:00:00 2001 From: morningman Date: Thu, 29 Aug 2024 09:57:03 +0800 Subject: [PATCH 1/2] [fix](file-cache) change metric_value column to string --- .../schema_scanner/schema_file_cache_statistics.cpp | 2 +- be/src/io/cache/block/block_file_cache_factory.cpp | 13 +------------ .../java/org/apache/doris/catalog/SchemaTable.java | 2 +- 3 files changed, 3 insertions(+), 14 deletions(-) diff --git a/be/src/exec/schema_scanner/schema_file_cache_statistics.cpp b/be/src/exec/schema_scanner/schema_file_cache_statistics.cpp index f47961002de172..d1ae0bd9a29fc4 100644 --- a/be/src/exec/schema_scanner/schema_file_cache_statistics.cpp +++ b/be/src/exec/schema_scanner/schema_file_cache_statistics.cpp @@ -32,7 +32,7 @@ std::vector SchemaFileCacheStatisticsScanner::_s_tbls {"BE_IP", TYPE_VARCHAR, sizeof(StringRef), false}, {"CACHE_PATH", TYPE_VARCHAR, sizeof(StringRef), false}, {"METRIC_NAME", TYPE_VARCHAR, sizeof(StringRef), false}, - {"METRIC_VALUE", TYPE_DOUBLE, sizeof(double), false}}; + {"METRIC_VALUE", TYPE_STRING, sizeof(StringRef), false}}; SchemaFileCacheStatisticsScanner::SchemaFileCacheStatisticsScanner() : SchemaScanner(_s_tbls_columns, TSchemaTableType::SCH_FILE_CACHE_STATISTICS) {} diff --git a/be/src/io/cache/block/block_file_cache_factory.cpp b/be/src/io/cache/block/block_file_cache_factory.cpp index 017e733c5e0754..362f42d49e6804 100644 --- a/be/src/io/cache/block/block_file_cache_factory.cpp +++ b/be/src/io/cache/block/block_file_cache_factory.cpp @@ -131,17 +131,6 @@ void FileCacheFactory::get_cache_stats_block(vectorized::Block* block) { nullable_column->get_null_map_data().emplace_back(0); }; - auto insert_double_value = [&](int col_index, double double_val, vectorized::Block* block) { - vectorized::MutableColumnPtr mutable_col_ptr; - mutable_col_ptr = std::move(*block->get_by_position(col_index).column).assume_mutable(); - auto* nullable_column = - reinterpret_cast(mutable_col_ptr.get()); - vectorized::IColumn* col_ptr = &nullable_column->get_nested_column(); - reinterpret_cast*>(col_ptr)->insert_value( - double_val); - nullable_column->get_null_map_data().emplace_back(0); - }; - auto insert_string_value = [&](int col_index, std::string str_val, vectorized::Block* block) { vectorized::MutableColumnPtr mutable_col_ptr; mutable_col_ptr = std::move(*block->get_by_position(col_index).column).assume_mutable(); @@ -160,7 +149,7 @@ void FileCacheFactory::get_cache_stats_block(vectorized::Block* block) { insert_string_value(1, be_ip, block); // be ip insert_string_value(2, cache->get_base_path(), block); // cache path insert_string_value(3, k, block); // metric name - insert_double_value(4, v, block); // metric value + insert_string_value(4, std::to_string(v), block); // metric value } } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/SchemaTable.java b/fe/fe-core/src/main/java/org/apache/doris/catalog/SchemaTable.java index b106ab9d79693c..8fb071feb96de9 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/catalog/SchemaTable.java +++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/SchemaTable.java @@ -524,7 +524,7 @@ public class SchemaTable extends Table { .column("BE_IP", ScalarType.createVarchar(256)) .column("CACHE_PATH", ScalarType.createVarchar(256)) .column("METRIC_NAME", ScalarType.createVarchar(256)) - .column("METRIC_VALUE", ScalarType.createType(PrimitiveType.DOUBLE)) + .column("METRIC_VALUE", ScalarType.createStringType()) .build())) .put("workload_group_privileges", new SchemaTable(SystemIdGenerator.getNextId(), "workload_group_privileges", TableType.SCHEMA, From 8e5fedf71cf659bd261d59efa488774e120f8843 Mon Sep 17 00:00:00 2001 From: morningman Date: Thu, 29 Aug 2024 12:09:33 +0800 Subject: [PATCH 2/2] 3 --- .../cache/block/block_file_cache_factory.cpp | 3 +++ .../system/test_file_cache_statistics.groovy | 24 +++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 regression-test/suites/query_p0/system/test_file_cache_statistics.groovy diff --git a/be/src/io/cache/block/block_file_cache_factory.cpp b/be/src/io/cache/block/block_file_cache_factory.cpp index 362f42d49e6804..abe6a38c198e4f 100644 --- a/be/src/io/cache/block/block_file_cache_factory.cpp +++ b/be/src/io/cache/block/block_file_cache_factory.cpp @@ -115,6 +115,9 @@ std::vector FileCacheFactory::get_qu } void FileCacheFactory::get_cache_stats_block(vectorized::Block* block) { + if (!config::enable_file_cache) { + return; + } // std::shared_lock read_lock(_qs_ctx_map_lock); TBackend be = BackendOptions::get_local_backend(); int64_t be_id = be.id; diff --git a/regression-test/suites/query_p0/system/test_file_cache_statistics.groovy b/regression-test/suites/query_p0/system/test_file_cache_statistics.groovy new file mode 100644 index 00000000000000..682ba3d4d0136e --- /dev/null +++ b/regression-test/suites/query_p0/system/test_file_cache_statistics.groovy @@ -0,0 +1,24 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +suite("test_file_cache_statistics") { + // not able to test result because the file cache may not be enabled + // in regression test. + // only execute the statement to make sure it won't fail. + sql "select * from information_schema.file_cache_statistics" + sql "select * from internal.information_schema.file_cache_statistics" +}