🐞 fix(TSG-9807): 修复cache_size设置为0导致的内存快速消耗

This commit is contained in:
“pengxuanzheng”
2022-03-02 10:35:26 +00:00
parent d4e8b149c8
commit 16d71d2fe6
22 changed files with 214 additions and 148 deletions

View File

@@ -4,21 +4,22 @@ aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR} SRCS)
include_directories("/opt/MESA/include")
include_directories("/opt/MESA/include/MESA")
include_directories("${CMAKE_BINARY_DIR}/support/GoogleTest/include/")
link_directories("/opt/MESA/lib")
link_directories("${CMAKE_BINARY_DIR}/support/GoogleTest/include/")
link_directories("${CMAKE_BINARY_DIR}/src/")
link_directories("${CMAKE_BINARY_DIR}/support/GoogleTest/lib/")
#link_libraries(hos-client-cpp gtest gtest_main pthread)
# coverage
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage -fPIE")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage -fPIE")
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage -fPIE")
add_definitions(-g -W -Wall -std=c++11)
add_definitions(-g -W -Wall -std=c++11 -fPIE)
#add_executable(gtest_hos_client gtest_hos_init_instance.cpp gtest_hos_get_instance.cpp gtest_hos_close_fd.cpp gtest_hos_open_fd.cpp)
#add_executable(gtest_hos_client CheckHosClient.cpp gtest_hos_init_instance.cpp)
add_executable(gtest_hos_client ${SRCS})
add_executable(gtest_hos_client gtest_hos_write.cpp CheckHosClient.cpp)
# add_executable(gtest_hos_client ${SRCS})
add_dependencies(gtest_hos_client ${lib_name}_shared gtest)
target_link_libraries(gtest_hos_client hos-client-cpp gtest gtest_main pthread)

View File

@@ -1,7 +1,7 @@
#ifndef __CHECKHOS_CLIENT_H__
#define __CHECKHOS_CLIENT_H__
#include <aws/external/gtest.h>
#include "gtest/gtest.h"
#include "../src/hos_client.h"
#include "../src/hos_common.h"

View File

@@ -68,26 +68,6 @@ hos_fs2_path="./log/hos_fs2_log"
hos_fs2_format=0
#default
[hos_default_conf]
hos_log_path="./hoslog"
#default
hos_log_level=30
#default
hos_poolsize=10
#default
hos_cache_size=102400
#default
hos_cache_count=10
#default
hos_fd_live_time_ms=1000
#default
hos_fs2_serverip=127.0.0.1
hos_fs2_serverport=10086
hos_fs2_path="./log/hos_fs2_log"
#default
hos_fs2_format=0
#default
[hos_error_server_conf]
hos_serverip=192.168.40.146
hos_serverport=9098
@@ -111,3 +91,27 @@ hos_fs2_path="./log/hos_fs2_log"
#default
hos_fs2_format=0
#default
[hos_cache_size_zero_conf]
hos_serverip=127.0.0.1
hos_serverport=9098
hos_accesskeyid="default"
hos_secretkey="default"
hos_log_path="./hoslog"
#default
hos_log_level=30
#default
hos_poolsize=10
#default
hos_cache_size=0
#default
hos_cache_count=10
#default
hos_fd_live_time_ms=1000
#default
hos_fs2_serverip=127.0.0.1
hos_fs2_serverport=10086
hos_fs2_path="./log/hos_fs2_log"
#default
hos_fs2_format=0
#defaul

View File

@@ -101,7 +101,6 @@ TEST(hos_close_fd, normal)
expect_hos_instance.hos_url_prefix = NULL;
CheckHosInstance(hos_instance, &expect_hos_instance);
Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets);
data_info_t *data_info = (data_info_t *)expect_hos_handle.hos_func.fs2_info.reserved;
free(data_info->cache);
free(data_info->rx_bytes);
@@ -147,7 +146,6 @@ TEST(hos_close_fd, paramer_error)
expect_hos_instance.hos_url_prefix = NULL;
CheckHosInstance(hos_instance, &expect_hos_instance);
Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets);
data_info_t *data_info = (data_info_t *)expect_hos_handle.hos_func.fs2_info.reserved;
free(data_info->cache);
free(data_info->rx_bytes);
@@ -191,7 +189,6 @@ TEST(hos_close_fd, fd_not_exits)
expect_hos_instance.hos_url_prefix = NULL;
CheckHosInstance(hos_instance, &expect_hos_instance);
Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets);
data_info_t *data_info = (data_info_t *)expect_hos_handle.hos_func.fs2_info.reserved;
free(data_info->cache);
free(data_info->rx_bytes);

View File

@@ -80,7 +80,6 @@ TEST(hos_get_instance, normal)
expect_hos_instance.hos_url_prefix = NULL;
CheckHosInstance(hos_instance, &expect_hos_instance);
Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets);
data_info_t *data_info = (data_info_t *)expect_hos_handle.hos_func.fs2_info.reserved;
free(data_info->cache);
free(data_info->rx_bytes);

View File

@@ -71,7 +71,6 @@ TEST(hos_init_instance, normal)
memset(&expect_hos_instance, 0, sizeof(expect_hos_instance));
CheckHosInstance(hos_instance, &expect_hos_instance);
Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets);
data_info_t *data_info = (data_info_t *)expect_hos_handle.hos_func.fs2_info.reserved;
free(data_info->cache);
free(data_info->rx_bytes);
@@ -133,7 +132,6 @@ TEST(hos_init_instance, server_conn_failed)
memset(&expect_hos_instance, 0, sizeof(expect_hos_instance));
CheckHosInstance(hos_instance, &expect_hos_instance);
Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets);
data_info_t *data_info = (data_info_t *)expect_hos_handle.hos_func.fs2_info.reserved;
free(data_info->cache);
free(data_info->rx_bytes);

View File

@@ -112,7 +112,6 @@ TEST(hos_open_fd, normal)
expect_hos_instance.hos_url_prefix = NULL;
CheckHosInstance(hos_instance, &expect_hos_instance);
Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets);
data_info_t *data_info = (data_info_t *)expect_hos_handle.hos_func.fs2_info.reserved;
free(data_info->cache);
free(data_info->rx_bytes);
@@ -148,7 +147,6 @@ TEST(hos_open_fd, paramer_error)
expect_hos_instance.hos_url_prefix = NULL;
CheckHosInstance(hos_instance, &expect_hos_instance);
Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets);
data_info_t *data_info = (data_info_t *)expect_hos_handle.hos_func.fs2_info.reserved;
free(data_info->cache);
free(data_info->rx_bytes);
@@ -184,7 +182,6 @@ TEST(hos_open_fd, over_threadnums)
expect_hos_instance.hos_url_prefix = NULL;
CheckHosInstance(hos_instance, &expect_hos_instance);
Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets);
data_info_t *data_info = (data_info_t *)expect_hos_handle.hos_func.fs2_info.reserved;
free(data_info->cache);
free(data_info->rx_bytes);

View File

@@ -72,7 +72,6 @@ TEST(hos_shutdown_instance, normal)
expect_hos_instance.hos_url_prefix = NULL;
CheckHosInstance(hos_instance, &expect_hos_instance);
Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets);
data_info_t *data_info = (data_info_t *)expect_hos_handle.hos_func.fs2_info.reserved;
free(data_info->cache);
free(data_info->rx_bytes);
@@ -108,7 +107,6 @@ TEST(hos_shutdown_instance, shutdown_more)
expect_hos_instance.hos_url_prefix = NULL;
CheckHosInstance(hos_instance, &expect_hos_instance);
Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets);
data_info_t *data_info = (data_info_t *)expect_hos_handle.hos_func.fs2_info.reserved;
free(data_info->cache);
free(data_info->rx_bytes);

View File

@@ -99,7 +99,6 @@ TEST(hos_upload_buff, normal)
expect_hos_instance.hos_url_prefix = NULL;
CheckHosInstance(hos_instance, &expect_hos_instance);
Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets);
free(data_info->cache);
free(data_info->rx_bytes);
free(data_info->rx_pkts);
@@ -139,7 +138,6 @@ TEST(hos_upload_buff, bucket_not_exits)
expect_hos_instance.hos_url_prefix = NULL;
CheckHosInstance(hos_instance, &expect_hos_instance);
Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets);
free(data_info->cache);
free(data_info->rx_bytes);
free(data_info->rx_pkts);
@@ -175,7 +173,6 @@ TEST(hos_upload_buff, param_error)
expect_hos_instance.hos_url_prefix = NULL;
CheckHosInstance(hos_instance, &expect_hos_instance);
Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets);
free(data_info->cache);
free(data_info->rx_bytes);
free(data_info->rx_pkts);

View File

@@ -101,7 +101,6 @@ TEST(hos_upload_file, normal)
expect_hos_instance.hos_url_prefix = NULL;
CheckHosInstance(hos_instance, &expect_hos_instance);
Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets);
free(data_info->cache);
free(data_info->rx_bytes);
free(data_info->rx_pkts);
@@ -137,7 +136,6 @@ TEST(hos_upload_file, param_error)
expect_hos_instance.hos_url_prefix = NULL;
CheckHosInstance(hos_instance, &expect_hos_instance);
Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets);
free(data_info->cache);
free(data_info->rx_bytes);
free(data_info->rx_pkts);
@@ -173,7 +171,6 @@ TEST(hos_upload_file, file_not_exits)
expect_hos_instance.hos_url_prefix = NULL;
CheckHosInstance(hos_instance, &expect_hos_instance);
Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets);
free(data_info->cache);
free(data_info->rx_bytes);
free(data_info->rx_pkts);
@@ -221,7 +218,6 @@ TEST(hos_upload_file, bucket_not_exits)
expect_hos_instance.hos_url_prefix = NULL;
CheckHosInstance(hos_instance, &expect_hos_instance);
Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets);
free(data_info->cache);
free(data_info->rx_bytes);
free(data_info->rx_pkts);

View File

@@ -202,7 +202,6 @@ TEST(hos_write, normal)
expect_hos_instance.hos_url_prefix = NULL;
CheckHosInstance(hos_instance, &expect_hos_instance);
Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets);
free(data_info->cache);
free(data_info->rx_bytes);
free(data_info->rx_pkts);
@@ -304,7 +303,6 @@ TEST(hos_write, bucket_not_exits)
expect_hos_instance.hos_url_prefix = NULL;
CheckHosInstance(hos_instance, &expect_hos_instance);
Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets);
free(data_info->cache);
free(data_info->rx_bytes);
free(data_info->rx_pkts);
@@ -401,7 +399,6 @@ TEST(hos_write, sync_mode)
expect_hos_instance.hos_url_prefix = NULL;
CheckHosInstance(hos_instance, &expect_hos_instance);
Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets);
free(data_info->cache);
free(data_info->rx_bytes);
free(data_info->rx_pkts);
@@ -481,14 +478,14 @@ TEST(hos_write, sync_mode_bucket_not_exits)
ASSERT_TRUE(((hos_fd_context_t *)fd1)->cache != NULL);
ret = hos_close_fd(fd);
ASSERT_EQ(ret, HOS_CLIENT_OK);
ASSERT_EQ(ret, HOS_FD_CLOSE_BUT_SEND_FAILED);
data_info->tx_failed_bytes[0] += data_info->cache[0];
data_info->tx_failed_pkts[0] += 1;
data_info->cache[0] = 0;
CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
ret = hos_close_fd(fd1);
ASSERT_EQ(ret, HOS_CLIENT_OK);
ASSERT_EQ(ret, HOS_FD_CLOSE_BUT_SEND_FAILED);
data_info->tx_failed_bytes[1] += data_info->cache[1];
data_info->tx_failed_pkts[1] += 1;
data_info->cache[1] = 0;
@@ -501,7 +498,6 @@ TEST(hos_write, sync_mode_bucket_not_exits)
expect_hos_instance.hos_url_prefix = NULL;
CheckHosInstance(hos_instance, &expect_hos_instance);
Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets);
free(data_info->cache);
free(data_info->rx_bytes);
free(data_info->rx_pkts);
@@ -546,7 +542,6 @@ TEST(hos_write, paramer_error)
expect_hos_instance.hos_url_prefix = NULL;
CheckHosInstance(hos_instance, &expect_hos_instance);
Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets);
data_info_t *data_info = (data_info_t *)expect_hos_handle.hos_func.fs2_info.reserved;
free(data_info->cache);
free(data_info->rx_bytes);
@@ -584,7 +579,6 @@ TEST(hos_write, fd_not_find)
expect_hos_instance.hos_url_prefix = NULL;
CheckHosInstance(hos_instance, &expect_hos_instance);
Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets);
data_info_t *data_info = (data_info_t *)expect_hos_handle.hos_func.fs2_info.reserved;
free(data_info->cache);
free(data_info->rx_bytes);
@@ -630,7 +624,6 @@ TEST(hos_write, over_threadnums)
expect_hos_instance.hos_url_prefix = NULL;
CheckHosInstance(hos_instance, &expect_hos_instance);
Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets);
data_info_t *data_info = (data_info_t *)expect_hos_handle.hos_func.fs2_info.reserved;
free(data_info->cache);
free(data_info->rx_bytes);
@@ -649,6 +642,65 @@ TEST(hos_write, not_init_instance)
ASSERT_EQ(ret, HOS_INSTANCE_NOT_ENABLE);
}
TEST(hos_write, cache_size_zero)
{
hos_instance_s expect_hos_instance;
hos_client_handle_t expect_hos_handle;
hos_fd_context_t expect_fd_info;
int thread_num = 1;
data_info_t *data_info = NULL;
hos_instance hos_instance = hos_init_instance(HOS_CONF, "hos_cache_size_zero_conf", thread_num);
gtest_hos_instance_init(&expect_hos_instance);
CheckHosInstance(hos_instance, &expect_hos_instance);
gtest_hos_handle_init(&expect_hos_handle, thread_num);
data_info = (data_info_t *)expect_hos_handle.hos_func.fs2_info.reserved;
expect_hos_handle.hos_config.cache_size = 0;
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
size_t fd = 0;
hos_open_fd(HOS_BUCKET, "object_buff", hos_write_append_cb, (void *)"object_buff", 0, &fd);
CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
gtest_hos_fd_init(&expect_fd_info);
expect_fd_info.object = (char *)"object_buff";
expect_fd_info.cache_rest = 0;
expect_fd_info.callback = (void *)hos_write_append_cb;
expect_fd_info.userdata = (void *)"object_buff";
CheckStructGHosFdContext((hos_fd_context_t *)fd, &expect_fd_info);
int ret = hos_write(fd, HOS_BUFF, strlen(HOS_BUFF));
ASSERT_EQ(ret, HOS_CLIENT_OK);
data_info->rx_bytes[0] += strlen(HOS_BUFF);
data_info->rx_pkts[0] += 1;
CheckHosInstance(hos_instance, &expect_hos_instance);
//CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
ret = hos_close_fd(fd);
ASSERT_EQ(ret, HOS_CLIENT_OK);
data_info->tx_bytes[0] += strlen(HOS_BUFF);
data_info->tx_pkts[0] += 1;
data_info->cache[0] = 0;
CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
ret = hos_shutdown_instance();
ASSERT_EQ(ret, HOS_CLIENT_OK);
expect_hos_instance.status = 0;
expect_hos_instance.hos_url_prefix = NULL;
CheckHosInstance(hos_instance, &expect_hos_instance);
free(data_info->cache);
free(data_info->rx_bytes);
free(data_info->rx_pkts);
free(data_info->tx_bytes);
free(data_info->tx_pkts);
free(data_info->tx_failed_bytes);
free(data_info->tx_failed_pkts);
memset(&expect_hos_handle, 0, sizeof(hos_client_handle_s));
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
}
static void read_file(char *path, char **content, int *len)
{
FILE *fp;
@@ -699,7 +751,7 @@ static void *hos_function(void *ptr)
{
snprintf(object[i], 1024, "object_%zu_%d", thread_id, i);
int err = hos_open_fd(HOS_BUCKET, object[i], hos_callback, object[i], 0, &fd[i]);
EXPECT_EQ(err, i + 1);
EXPECT_EQ(err, HOS_CLIENT_OK);
CheckHosInstance(hos_instance, &expect_hos_instance);
CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle);
gtest_hos_fd_init(&expect_fd_info[thread_id][i]);
@@ -746,7 +798,6 @@ static void *hos_function(void *ptr)
expect_hos_instance.hos_url_prefix = NULL;
CheckHosInstance(hos_instance, &expect_hos_instance);
Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets);
free(data_info->cache);
free(data_info->rx_bytes);
free(data_info->rx_pkts);
@@ -769,4 +820,4 @@ TEST(hos_write, mutil_thread)
{
pthread_create(&thread_num[i], NULL, hos_function, (void *)i);
}
}
}