Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
Signed-off-by: Smith Cruise <[email protected]>
  • Loading branch information
Smith-Cruise committed Jul 19, 2024
1 parent 138eedf commit 94e38fa
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 20 deletions.
4 changes: 4 additions & 0 deletions be/src/block_cache/block_cache_hit_rate_counter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ class BlockCacheHitRateCounter {
ssize_t get_miss_bytes() const { return _miss_bytes.get_value(); }
ssize_t get_hit_bytes_last_minute() const { return _hit_bytes_last_minute.get_value(); }
ssize_t get_miss_bytes_last_minute() const { return _miss_bytes_last_minute.get_value(); }
void reset() {
_hit_bytes.reset();
_miss_bytes.reset();
}

private:
static double hit_rate_calculate(ssize_t hit_bytes, ssize_t miss_bytes) {
Expand Down
1 change: 1 addition & 0 deletions be/src/exec/hdfs_scanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include "exec/hdfs_scanner.h"

#include "block_cache/block_cache_hit_rate_counter.hpp"
#include "column/column_helper.h"
#include "exec/exec_node.h"
#include "fs/hdfs/fs_hdfs.h"
Expand Down
1 change: 1 addition & 0 deletions be/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@ set(EXEC_FILES
./storage/lake/replication_txn_manager_test.cpp
./storage/lake/persistent_index_sstable_test.cpp
./block_cache/datacache_utils_test.cpp
./block_cache/block_cache_hit_rate_counter_test.cpp
./util/thrift_rpc_helper_test.cpp
)

Expand Down
18 changes: 9 additions & 9 deletions be/test/block_cache/block_cache_hit_rate_counter_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ class BlockCacheHitRateCounterTest : public ::testing::Test {
};

TEST_F(BlockCacheHitRateCounterTest, app_hit_rate) {
BlockCacheHitRateCounter* counter = BlockCacheHitRateCounter::instance();
EXPECT_EQ(0, counter->hit_rate());
EXPECT_EQ(0, counter->get_hit_bytes_last_minute());
EXPECT_EQ(0, counter->get_miss_bytes_last_minute());
EXPECT_EQ(0, counter->hit_rate_last_minute());
BlockCacheHitRateCounter counter{};
EXPECT_EQ(0, counter.hit_rate());
EXPECT_EQ(0, counter.get_hit_bytes_last_minute());
EXPECT_EQ(0, counter.get_miss_bytes_last_minute());
EXPECT_EQ(0, counter.hit_rate_last_minute());

counter->update(3, 10);
counter.update(3, 10);

EXPECT_EQ(3, counter->get_hit_bytes());
EXPECT_EQ(10, counter->get_miss_bytes());
EXPECT_EQ(0.23, counter->hit_rate());
EXPECT_EQ(3, counter.get_hit_bytes());
EXPECT_EQ(10, counter.get_miss_bytes());
EXPECT_EQ(0.23, counter.hit_rate());
}
} // namespace starrocks
47 changes: 36 additions & 11 deletions be/test/http/datacache_action_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include <rapidjson/document.h>

#include "block_cache/block_cache.h"
#include "gen_cpp/FrontendService_types.h"
#include "block_cache/block_cache_hit_rate_counter.hpp"
#include "gen_cpp/HeartbeatService_types.h"
#include "http/http_channel.h"
#include "http/http_request.h"
Expand Down Expand Up @@ -101,23 +101,48 @@ TEST_F(DataCacheActionTest, stat_success) {
}

TEST_F(DataCacheActionTest, app_stat_success) {
BlockCacheHitRateCounter* counter = BlockCacheHitRateCounter::instance();
counter->reset();
auto cache = BlockCache::instance();
ASSERT_TRUE(init_datacache_instance("starcache", cache).ok());
_env._block_cache = cache;

DataCacheAction action(&_env);

HttpRequest request(_evhttp_req);
request._method = HttpMethod::GET;
request._params.emplace("action", "app_stat");
request.set_handler(&action);
action.on_header(&request);
action.handle(&request);

rapidjson::Document doc;
doc.Parse(k_response_str.c_str());
std::cout << doc["hit_bytes"].GetInt64();
{
HttpRequest request(_evhttp_req);
request._method = HttpMethod::GET;
request._params.emplace("action", "app_stat");
request.set_handler(&action);
action.on_header(&request);
action.handle(&request);

rapidjson::Document doc;
doc.Parse(k_response_str.c_str());
EXPECT_EQ(0, doc["hit_bytes"].GetInt64());
EXPECT_EQ(0, doc["miss_bytes"].GetInt64());
EXPECT_EQ(0, doc["hit_rate"].GetDouble());
EXPECT_EQ(0, doc["hit_bytes_last_minute"].GetInt64());
EXPECT_EQ(0, doc["miss_bytes_last_minute"].GetInt64());
EXPECT_EQ(0, doc["hit_rate_last_minute"].GetDouble());
}

counter->update(3, 10);

{
HttpRequest request(_evhttp_req);
request._method = HttpMethod::GET;
request._params.emplace("action", "app_stat");
request.set_handler(&action);
action.on_header(&request);
action.handle(&request);

rapidjson::Document doc;
doc.Parse(k_response_str.c_str());
EXPECT_EQ(3, doc["hit_bytes"].GetInt64());
EXPECT_EQ(10, doc["miss_bytes"].GetInt64());
EXPECT_EQ(0.23, doc["hit_rate"].GetDouble());
}
_env._block_cache = nullptr;
}

Expand Down

0 comments on commit 94e38fa

Please sign in to comment.