This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
pxz-hos-client-cpp-module/src/hos_client.cpp

1240 lines
49 KiB
C++
Raw Normal View History

2020-09-11 16:13:02 +08:00
/*************************************************************************
> File Name: hos_client_api.cpp
> Author: pxz
> Created Time: Thu 10 Sep 2020 03:00:23 PM CST
************************************************************************/
2020-09-21 19:19:18 +08:00
extern "C"
{
2021-04-23 09:57:58 +08:00
#include <string.h>
2020-10-20 17:20:27 +08:00
#include <sys/stat.h>
#include <unistd.h>
2020-09-21 19:19:18 +08:00
}
2020-09-11 16:13:02 +08:00
#include <aws/s3/model/PutObjectRequest.h>
#include <aws/s3/model/CreateBucketRequest.h>
#include <fstream>
2020-09-11 16:13:02 +08:00
#include <iostream>
2021-04-28 18:29:29 +08:00
#include <aws/external/gtest.h>
#include <aws/testing/platform/PlatformTesting.h>
#include <aws/testing/TestingEnvironment.h>
#include <aws/testing/MemoryTesting.h>
2021-05-26 11:10:59 +08:00
#ifdef HOS_MOCK
#include "mock/hos_mock.h"
#endif
2020-09-11 16:13:02 +08:00
#include "hos_client.h"
2021-04-23 09:57:58 +08:00
#include "MESA_handle_logger.h"
#include "MESA_prof_load.h"
2021-05-26 11:10:59 +08:00
#include "hos_common.h"
2021-05-26 11:10:59 +08:00
struct hos_instance_s g_hos_instance;
hos_client_handle_t g_hos_handle;//一个进程只允许有一个g_hos_handle
2021-04-23 09:57:58 +08:00
static std::mutex m_client_lock;
2021-05-26 11:10:59 +08:00
hos_fd_context_t **g_fd_context;
size_t (*g_fd_info)[MAX_HOS_CLIENT_FD_NUM + 1]; //fd 实际从3开始 fd[thread_id][0]记录register的fdfd[thread_id][1]记录inject的fd
2021-04-23 09:57:58 +08:00
static Aws::SDKOptions g_options;
2020-09-11 16:13:02 +08:00
2021-05-26 11:10:59 +08:00
static void *hos_fd_manage(void *ptr);
static inline size_t get_current_ms()
{
struct timespec timenow;
clock_gettime(CLOCK_MONOTONIC, &timenow);
return (timenow.tv_sec * 1000 + timenow.tv_nsec / 1000 / 1000 );
}
2020-10-09 14:20:39 +08:00
static size_t hash_get_min_free_fd(size_t thread_id)
2020-09-21 19:19:18 +08:00
{
size_t i = 0;
2020-12-01 16:12:41 +08:00
for (i = 3; i < MAX_HOS_CLIENT_FD_NUM + 1; i++)
2020-09-21 19:19:18 +08:00
{
2021-04-23 14:30:52 +08:00
if (!g_fd_info[thread_id][i])
2020-12-01 16:12:41 +08:00
{
2021-04-23 14:30:52 +08:00
g_fd_info[thread_id][i] = 1;
g_fd_info[thread_id][HOS_FD_REGISTER]++;
g_fd_info[thread_id][HOS_FD_FREE]--;
2020-12-01 16:12:41 +08:00
2020-09-21 19:19:18 +08:00
return i;
2020-12-01 16:12:41 +08:00
}
2020-09-21 19:19:18 +08:00
}
return 0;
}
static int hos_delete_fd(size_t fd, size_t thread_id)
{
if (fd == 0)
{
return HOS_PARAMETER_ERROR;
}
2021-04-23 14:30:52 +08:00
delete_context_by_fd(&g_fd_context[thread_id], fd);
g_fd_info[thread_id][fd] = 0;
g_fd_info[thread_id][HOS_FD_FREE]++;
g_fd_info[thread_id][HOS_FD_INJECT]--;
return HOS_CLIENT_OK;
}
2020-09-21 19:19:18 +08:00
static void PutObjectAsyncFinished(const Aws::S3::S3Client* S3Client,
2020-09-11 16:13:02 +08:00
const Aws::S3::Model::PutObjectRequest& request,
const Aws::S3::Model::PutObjectOutcome& outcome,
const std::shared_ptr<const Aws::Client::AsyncCallerContext>& context)
{
2020-09-21 19:19:18 +08:00
const char *error = NULL;
2021-04-23 09:57:58 +08:00
hos_fd_context_t *a_fd_context = NULL;
hos_func_thread_t *hos_func = &g_hos_handle.hos_func;
data_info_t *data_info = NULL;
2020-09-21 19:19:18 +08:00
const Aws::String& uuid = context->GetUUID();
2021-04-23 14:30:52 +08:00
size_t thread_id, fd, stream_len;
sscanf(uuid.c_str(), "%lu %lu %lu", &thread_id, &fd, &stream_len);
if (g_fd_info[thread_id][fd])
2020-10-09 14:20:39 +08:00
{
2021-04-23 14:30:52 +08:00
a_fd_context = find_context_by_fd(g_fd_context[thread_id], fd);
2020-10-09 14:20:39 +08:00
}
2021-04-23 09:57:58 +08:00
if (a_fd_context == NULL)
2020-10-09 14:20:39 +08:00
{
2021-04-23 09:57:58 +08:00
MESA_handle_runtime_log(g_hos_handle.log, RLOG_LV_FATAL, __FUNCTION__,
"Not find the info of [thread_id:%d fd:%d]", thread_id, fd);
2020-09-11 16:13:02 +08:00
2021-04-23 09:57:58 +08:00
if (hos_func->fs2_info[FS2_DATA_FLOW_STATE].fs2_handle && hos_func->fs2_info[FS2_DATA_FLOW_STATE].reserved)
{
data_info = (data_info_t *)hos_func->fs2_info[FS2_DATA_FLOW_STATE].reserved;
2021-04-23 14:30:52 +08:00
data_info->tx_failed_pkts[thread_id]++;
data_info->tx_failed_bytes[thread_id] += stream_len;
2021-04-23 09:57:58 +08:00
}
return ;
}
2021-04-23 09:57:58 +08:00
bool result = outcome.IsSuccess();
if (!result)
{
2021-04-23 09:57:58 +08:00
error = outcome.GetError().GetMessage().c_str();
MESA_handle_runtime_log(g_hos_handle.log, RLOG_LV_FATAL, __FUNCTION__,
"[%s:%s] upload failed. error:%s",a_fd_context->bucket, a_fd_context->object, error);
2021-04-23 09:57:58 +08:00
if (hos_func->fs2_info[FS2_DATA_FLOW_STATE].fs2_handle && hos_func->fs2_info[FS2_DATA_FLOW_STATE].reserved)
{
data_info = (data_info_t *)hos_func->fs2_info[FS2_DATA_FLOW_STATE].reserved;
2021-04-23 14:30:52 +08:00
data_info->tx_failed_pkts[thread_id]++;
data_info->tx_failed_bytes[thread_id] += stream_len;
2021-04-23 09:57:58 +08:00
}
}
2021-04-23 09:57:58 +08:00
else
{
2021-04-23 09:57:58 +08:00
if (hos_func->fs2_info[FS2_DATA_FLOW_STATE].fs2_handle && hos_func->fs2_info[FS2_DATA_FLOW_STATE].reserved)
{
data_info = (data_info_t *)hos_func->fs2_info[FS2_DATA_FLOW_STATE].reserved;
2021-04-23 14:30:52 +08:00
data_info->tx_pkts[thread_id]++;
data_info->tx_bytes[thread_id] += stream_len;
MESA_handle_runtime_log(g_hos_handle.log, RLOG_LV_DEBUG, __FUNCTION__,
"[%s:%s] upload success. tx_pkts:%d, tx_bytes:%d",
a_fd_context->bucket, a_fd_context->object,
data_info->tx_pkts[thread_id], data_info->tx_bytes[thread_id]);
}
else
{
MESA_handle_runtime_log(g_hos_handle.log, RLOG_LV_DEBUG, __FUNCTION__,
"[%s:%s] upload success. stream size:%d", a_fd_context->bucket, a_fd_context->object, stream_len);
2021-04-23 09:57:58 +08:00
}
2020-12-01 16:12:41 +08:00
}
2021-04-23 09:57:58 +08:00
put_finished_callback callback = (put_finished_callback)a_fd_context->callback;
callback(result, a_fd_context->bucket, a_fd_context->object, error, a_fd_context->userdata);
if (a_fd_context->mode & APPEND_MODE)
2021-04-06 13:47:47 +08:00
{
2021-04-23 09:57:58 +08:00
//APPEND MODE 保留fd
atomic_add(&(a_fd_context->recive_cnt), 1);
}
else
{
2021-04-23 09:57:58 +08:00
//完整上传 删除fd
hos_close_fd(fd, thread_id);
}
}
2021-04-23 09:57:58 +08:00
static void hos_client_create()
2020-09-11 16:13:02 +08:00
{
std::lock_guard<std::mutex> locker(m_client_lock);
2021-04-23 09:57:58 +08:00
hos_config_t *hos_conf = &g_hos_handle.hos_config;
void *log = g_hos_handle.log;
2020-11-23 11:01:49 +08:00
2021-04-26 13:59:36 +08:00
if (g_hos_handle.S3Client != NULL)
{
g_hos_handle.count++;
g_hos_instance.result = true;
return ;
}
Aws::InitAPI(g_options);
2020-09-11 16:13:02 +08:00
Aws::Client::ClientConfiguration config;
2021-04-23 09:57:58 +08:00
Aws::Auth::AWSCredentials credentials(hos_conf->accesskeyid, hos_conf->secretkey);
2020-09-11 16:13:02 +08:00
2020-09-27 11:58:23 +08:00
//初始化
2020-12-01 16:12:41 +08:00
char endpoint[128];
2021-04-23 09:57:58 +08:00
snprintf(endpoint, 128, "http://%s:%d/hos/", hos_conf->ip, hos_conf->port);
2020-09-11 16:13:02 +08:00
config.endpointOverride = endpoint;
config.verifySSL = false;
config.enableEndpointDiscovery = true;
2021-04-23 09:57:58 +08:00
if (hos_conf->pool_thread_size > 0)
{
//异步模式
config.executor = std::shared_ptr<Aws::Utils::Threading::PooledThreadExecutor>(std::make_shared<Aws::Utils::Threading::PooledThreadExecutor>(hos_conf->pool_thread_size, Aws::Utils::Threading::OverflowPolicy::REJECT_IMMEDIATELY)); //支持线程池
}
else
{
//同步模式
}
2020-09-11 16:13:02 +08:00
2021-05-26 11:10:59 +08:00
#ifndef HOS_MOCK
2021-04-23 09:57:58 +08:00
g_hos_handle.S3Client = new Aws::S3::S3Client(credentials, config, Aws::Client::AWSAuthV4Signer::PayloadSigningPolicy::Never, false);
2021-05-26 11:10:59 +08:00
#else
g_hos_handle.S3Client = new Aws::S3::S3ClientMock(credentials, config, Aws::Client::AWSAuthV4Signer::PayloadSigningPolicy::Never, false);
#endif
2020-09-21 19:19:18 +08:00
/* 获取当前用户的所有的buckets */
2021-04-23 09:57:58 +08:00
Aws::S3::Model::ListBucketsOutcome outcome = g_hos_handle.S3Client->ListBuckets();
2020-09-21 19:19:18 +08:00
if (!outcome.IsSuccess())
2020-09-21 19:19:18 +08:00
{
2021-04-23 09:57:58 +08:00
delete g_hos_handle.S3Client;
g_hos_handle.S3Client = NULL;
Aws::ShutdownAPI(g_options);
2021-04-23 09:57:58 +08:00
g_hos_instance.error_code = (size_t)outcome.GetError().GetErrorType() + 1;
snprintf(g_hos_instance.error_message, HOS_ERROR_MESSAGE_SIZE, outcome.GetError().GetMessage().c_str());
g_hos_instance.result = false;
MESA_handle_runtime_log(log, RLOG_LV_FATAL, "hos_client_create", g_hos_instance.error_message);
return;
}
g_hos_handle.buckets = outcome.GetResult().GetBuckets();
g_hos_handle.count++;
g_hos_handle.executor = std::dynamic_pointer_cast<Aws::Utils::Threading::PooledThreadExecutor>(config.executor);
2021-04-23 14:30:52 +08:00
g_fd_context = (hos_fd_context_t **)calloc(hos_conf->thread_num, sizeof(hos_fd_context_t *));
g_fd_info = (size_t (*)[MAX_HOS_CLIENT_FD_NUM + 1])calloc(hos_conf->thread_num, sizeof(size_t [MAX_HOS_CLIENT_FD_NUM + 1]));
2021-04-23 09:57:58 +08:00
for (size_t i = 0; i < hos_conf->thread_num; i++)
{
2021-04-23 14:30:52 +08:00
g_fd_info[i][0] = 65533;
2021-04-23 09:57:58 +08:00
}
MESA_handle_runtime_log(log, RLOG_LV_DEBUG, "hos_client_create", "hos s3client create success, url:%s.",endpoint);
g_hos_instance.result = true;
}
2021-04-28 18:29:29 +08:00
bool hos_verify_bucket(const char *bucket)
2021-04-23 09:57:58 +08:00
{
2021-04-28 18:29:29 +08:00
if (bucket == NULL)
{
MESA_handle_runtime_log(g_hos_handle.log, RLOG_LV_DEBUG, __FUNCTION__,
"bucket is null");
return false;
}
if (g_hos_instance.result != true || g_hos_handle.S3Client == NULL)
{
MESA_handle_runtime_log(g_hos_handle.log, RLOG_LV_DEBUG, __FUNCTION__,
"g_hos_instance.result:%s, g_hos_handle.S3Client:%s",
g_hos_instance.result, (g_hos_handle.S3Client==NULL)?(NULL):("not null"));
return false;
}
2021-04-23 09:57:58 +08:00
Aws::S3::Model::ListBucketsOutcome outcome = g_hos_handle.S3Client->ListBuckets();
if (outcome.IsSuccess())
{
g_hos_handle.buckets = outcome.GetResult().GetBuckets();
2020-12-01 16:12:41 +08:00
2021-04-23 09:57:58 +08:00
for (Aws::S3::Model::Bucket& new_bucket : g_hos_handle.buckets)
{
if (strcmp(new_bucket.GetName().c_str(), bucket) == 0)
{
MESA_handle_runtime_log(g_hos_handle.log, RLOG_LV_DEBUG, "hos_verify_bucket","bucket:%s exits", bucket);
return true;
}
}
}
else
{
MESA_handle_runtime_log(g_hos_handle.log, RLOG_LV_FATAL, "hos_verify_bucket","error:%s", outcome.GetError().GetMessage().c_str());
}
return false;
2020-09-11 16:13:02 +08:00
}
2020-10-20 17:20:27 +08:00
static void *fs2_statistics(void *ptr)
{
2020-12-01 16:12:41 +08:00
size_t i = 0;
2021-04-23 09:57:58 +08:00
size_t rx_pkts_sum = 0;
size_t rx_bytes_sum = 0;
size_t tx_pkts_sum = 0;
size_t tx_bytes_sum = 0;
size_t tx_failed_bytes_sum = 0;
2021-04-23 14:30:52 +08:00
size_t tx_failed_pkts_sum = 0;
2021-04-23 09:57:58 +08:00
size_t cache_sum = 0;
size_t rx_pkts_interval = 0;
size_t rx_bytes_interval = 0;
size_t tx_pkts_interval = 0;
size_t tx_bytes_interval = 0;
size_t tx_failed_bytes_interval = 0;
2021-04-23 14:30:52 +08:00
size_t tx_failed_pkts_interval = 0;
2021-04-23 09:57:58 +08:00
size_t cache_interval = 0;
2021-04-23 14:30:52 +08:00
size_t rx_pkts_last = 0;
size_t rx_bytes_last = 0;
size_t tx_pkts_last = 0;
size_t tx_bytes_last = 0;
size_t tx_failed_bytes_last = 0;
size_t tx_failed_pkts_last = 0;
size_t cache_last = 0;
2020-12-01 16:12:41 +08:00
fs2_info_t *fs2_info = NULL;
2021-04-23 09:57:58 +08:00
int PoolThread_state[3] = {0, 0, 0};//{PoolSize, Busy, TopBusy}
int *busy = &PoolThread_state[1];
int *top_busy = &PoolThread_state[2];
int pool_history_sum = 0;
2021-04-23 09:57:58 +08:00
hos_config_t *hos_conf = &g_hos_handle.hos_config;
hos_func_thread_t *hos_func = &g_hos_handle.hos_func;
2021-04-23 09:57:58 +08:00
PoolThread_state[0] = hos_conf->pool_thread_size;
2020-10-20 17:20:27 +08:00
while(1)
{
2021-04-23 09:57:58 +08:00
if (hos_func->fs2_status == HOS_FS2_STOP)
2020-10-20 17:20:27 +08:00
{
break;
}
2021-04-23 09:57:58 +08:00
//pkts and bytes info
2021-04-23 14:30:52 +08:00
rx_pkts_sum = 0;
rx_bytes_sum = 0;
tx_pkts_sum = 0;
tx_bytes_sum = 0;
tx_failed_bytes_sum = 0;
tx_failed_pkts_sum = 0;
cache_sum = 0;
2021-04-23 09:57:58 +08:00
fs2_info = &hos_func->fs2_info[0];
data_info_t *data_info = (data_info_t *)fs2_info->reserved;
2021-04-23 14:30:52 +08:00
for (i = 0; i < hos_conf->thread_num; i++)
{
rx_pkts_sum += data_info->rx_pkts[i];
rx_bytes_sum += data_info->rx_bytes[i];
tx_pkts_sum += data_info->tx_pkts[i];
tx_bytes_sum += data_info->tx_bytes[i];
tx_failed_bytes_sum += data_info->tx_failed_bytes[i];
tx_failed_pkts_sum += data_info->tx_failed_pkts[i];
cache_sum += data_info->cache[i];
}
rx_pkts_interval = rx_pkts_sum - rx_pkts_last;
rx_bytes_interval = rx_bytes_sum - rx_bytes_last;
tx_pkts_interval = tx_pkts_sum - tx_pkts_last;
tx_bytes_interval = tx_bytes_sum - tx_bytes_last;
tx_failed_pkts_interval = tx_failed_pkts_sum - tx_failed_pkts_last;
tx_failed_bytes_interval = tx_failed_bytes_sum - tx_failed_bytes_last;
cache_interval = cache_sum - cache_last;
rx_pkts_last = rx_pkts_sum;
rx_bytes_last = rx_bytes_sum;
tx_pkts_last = tx_pkts_sum;
tx_bytes_last = tx_bytes_sum;
tx_failed_bytes_last = tx_failed_bytes_sum;
tx_failed_pkts_last = tx_failed_pkts_sum;
cache_last = cache_sum;
2021-04-23 09:57:58 +08:00
FS_operate(fs2_info->fs2_handle, fs2_info->line_ids[0], fs2_info->column_ids[0], FS_OP_SET, rx_pkts_interval);
FS_operate(fs2_info->fs2_handle, fs2_info->line_ids[0], fs2_info->column_ids[1], FS_OP_SET, rx_bytes_interval);
FS_operate(fs2_info->fs2_handle, fs2_info->line_ids[0], fs2_info->column_ids[2], FS_OP_SET, tx_pkts_interval);
FS_operate(fs2_info->fs2_handle, fs2_info->line_ids[0], fs2_info->column_ids[3], FS_OP_SET, tx_bytes_interval);
2021-04-23 14:30:52 +08:00
FS_operate(fs2_info->fs2_handle, fs2_info->line_ids[0], fs2_info->column_ids[5], FS_OP_SET, tx_failed_pkts_interval);
2021-04-23 09:57:58 +08:00
FS_operate(fs2_info->fs2_handle, fs2_info->line_ids[0], fs2_info->column_ids[4], FS_OP_SET, tx_failed_bytes_interval);
2021-04-23 14:30:52 +08:00
FS_operate(fs2_info->fs2_handle, fs2_info->line_ids[0], fs2_info->column_ids[6], FS_OP_SET, cache_interval);
2021-04-23 09:57:58 +08:00
FS_operate(fs2_info->fs2_handle, fs2_info->line_ids[1], fs2_info->column_ids[0], FS_OP_SET, rx_pkts_sum);
FS_operate(fs2_info->fs2_handle, fs2_info->line_ids[1], fs2_info->column_ids[1], FS_OP_SET, rx_bytes_sum);
FS_operate(fs2_info->fs2_handle, fs2_info->line_ids[1], fs2_info->column_ids[2], FS_OP_SET, tx_pkts_sum);
FS_operate(fs2_info->fs2_handle, fs2_info->line_ids[1], fs2_info->column_ids[3], FS_OP_SET, tx_bytes_sum);
2021-04-23 14:30:52 +08:00
FS_operate(fs2_info->fs2_handle, fs2_info->line_ids[1], fs2_info->column_ids[4], FS_OP_SET, tx_failed_pkts_sum);
FS_operate(fs2_info->fs2_handle, fs2_info->line_ids[1], fs2_info->column_ids[5], FS_OP_SET, tx_failed_bytes_sum);
FS_operate(fs2_info->fs2_handle, fs2_info->line_ids[1], fs2_info->column_ids[6], FS_OP_SET, cache_sum);
2020-10-20 17:20:27 +08:00
2021-04-23 09:57:58 +08:00
//PoolThread State
2021-04-26 18:17:37 +08:00
if (hos_conf->pool_thread_size > 0)
{
2021-04-26 18:17:37 +08:00
*busy = g_hos_handle.executor->GetTaskSize();
*top_busy = (*busy) > (*top_busy) ? (*busy) : (*top_busy);
pool_history_sum += *busy;
fs2_info = &hos_func->fs2_info[FS2_POOL_THREAD_STATE];
for (i = 0; i < 3; i++)
{
FS_operate(fs2_info->fs2_handle, fs2_info->line_ids[0], fs2_info->column_ids[i], FS_OP_SET, PoolThread_state[i]);
}
}
2021-04-26 18:17:37 +08:00
2020-11-02 17:55:02 +08:00
sleep(1);
2020-10-20 17:20:27 +08:00
}
pthread_exit(NULL);
}
2021-04-26 18:17:37 +08:00
static screen_stat_handle_t hos_init_fs2(char *app_name, int app_name_size)
2020-10-20 17:20:27 +08:00
{
int value = 0;
2021-04-26 18:17:37 +08:00
screen_stat_handle_t fs2_handle = FS_create_handle();
2021-04-23 14:30:52 +08:00
hos_config_t *hos_conf = &g_hos_handle.hos_config;
2020-10-20 17:20:27 +08:00
2021-04-26 18:17:37 +08:00
FS_set_para(fs2_handle, APP_NAME, app_name, app_name_size + 1);
value = 1; //true
FS_set_para(fs2_handle, FLUSH_BY_DATE, &value, sizeof(value));
if (hos_conf->fs2_path != NULL)
{
FS_set_para(fs2_handle, OUTPUT_DEVICE, hos_conf->fs2_path, strlen(hos_conf->fs2_path) + 1);
}
value = 2;
FS_set_para(fs2_handle, PRINT_MODE, &value, sizeof(value));
value = 1;
FS_set_para(fs2_handle, CREATE_THREAD, &value, sizeof(value));
FS_set_para(fs2_handle, METRIS_FORMAT, &hos_conf->fs2_fmt, sizeof(hos_conf->fs2_fmt));
FS_set_para(fs2_handle, STAT_CYCLE, &value, sizeof(value));
value = 4096;
FS_set_para(fs2_handle, MAX_STAT_FIELD_NUM, &value, sizeof(value));
if (hos_conf->fs2_ip == NULL)
{
FS_set_para(fs2_handle, STATS_SERVER_IP, "127.0.0.1", strlen("127.0.0.1"));
}
else
2020-10-20 17:20:27 +08:00
{
2021-04-26 18:17:37 +08:00
FS_set_para(fs2_handle, STATS_SERVER_IP, hos_conf->fs2_ip, strlen(hos_conf->fs2_ip));
}
2020-12-01 16:12:41 +08:00
2021-04-26 18:17:37 +08:00
FS_set_para(fs2_handle, STATS_SERVER_PORT, &hos_conf->fs2_port, sizeof(hos_conf->fs2_port));
2020-12-01 16:12:41 +08:00
2021-04-26 18:17:37 +08:00
value = FS_OUTPUT_STATSD;
FS_set_para(fs2_handle, STATS_FORMAT, &value, sizeof(value));
2020-10-20 17:20:27 +08:00
2021-04-26 18:17:37 +08:00
return fs2_handle;
}
2020-10-20 17:20:27 +08:00
2021-04-26 18:17:37 +08:00
static void hos_expand_fs2()
{
fs2_info_t *fs2_info = NULL;
screen_stat_handle_t fs2_handle = NULL;
hos_config_t *hos_conf = &g_hos_handle.hos_config;
hos_func_thread_t *hos_func = &g_hos_handle.hos_func;
size_t i = 0;
2020-11-02 17:55:02 +08:00
2021-04-26 18:17:37 +08:00
if (hos_func->fs2_info[0].fs2_handle)
return;
2021-04-23 14:30:52 +08:00
//data info
/**********************************************************************************************************
* rx_pkts rx_bytes tx_pkts tx_bytes tx_failed_p tx_failed_b cache_bytes
* current 10 100 1 100 0 0 100
* total 100 1000 10 1000 0 0 100()
***********************************************************************************************************/
2021-04-26 18:17:37 +08:00
fs2_info = &hos_func->fs2_info[FS2_DATA_FLOW_STATE];
hos_func->fs2_info[FS2_DATA_FLOW_STATE].fs2_handle = hos_init_fs2((char *)"hos-data", strlen("hos-data"));
fs2_handle = hos_func->fs2_info[FS2_DATA_FLOW_STATE].fs2_handle;
fs2_info->line_ids = (int *)calloc(2, sizeof(int));
fs2_info->column_ids = (int *)calloc(7, sizeof(int));
const char *data_col[] = {"rx_pkts", "rx_bytes", "tx_pkts", "tx_bytes", "tx_failed_p", "tx_failed_b", "cache_bytes"};
2021-04-23 09:57:58 +08:00
for (i = 0; i < sizeof(data_col) / sizeof(const char *); i++)
2020-12-01 16:12:41 +08:00
{
2021-04-23 09:57:58 +08:00
fs2_info->column_ids[i] = FS_register(fs2_handle, FS_STYLE_COLUMN, FS_CALC_CURRENT, data_col[i]);
2020-12-01 16:12:41 +08:00
}
2021-04-23 09:57:58 +08:00
fs2_info->line_ids[0] = FS_register(fs2_handle, FS_STYLE_LINE, FS_CALC_CURRENT, "current");
fs2_info->line_ids[1] = FS_register(fs2_handle, FS_STYLE_LINE, FS_CALC_CURRENT, "total");
2020-12-01 16:12:41 +08:00
2021-04-23 09:57:58 +08:00
hos_func->fs2_status = HOS_FS2_START;
data_info_t *data_info = (data_info_t *)calloc(1, sizeof(data_info_t));
fs2_info->reserved = (void *)data_info;
data_info->tx_pkts = (size_t *)calloc(hos_conf->thread_num, sizeof(size_t));
data_info->tx_bytes = (size_t *)calloc(hos_conf->thread_num, sizeof(size_t));
data_info->rx_pkts = (size_t *)calloc(hos_conf->thread_num, sizeof(size_t));
data_info->rx_bytes = (size_t *)calloc(hos_conf->thread_num, sizeof(size_t));
2021-04-23 14:30:52 +08:00
data_info->tx_failed_pkts = (size_t *)calloc(hos_conf->thread_num, sizeof(size_t));
2021-04-23 09:57:58 +08:00
data_info->tx_failed_bytes = (size_t *)calloc(hos_conf->thread_num, sizeof(size_t));
2021-04-23 14:30:52 +08:00
data_info->cache = (size_t *)calloc(hos_conf->thread_num, sizeof(size_t));
2021-04-23 09:57:58 +08:00
FS_start(fs2_handle);
2020-10-20 17:20:27 +08:00
2021-04-26 18:17:37 +08:00
if (hos_conf->pool_thread_size > 0)
{
2021-04-26 18:17:37 +08:00
//PoolThread state
/*******************************************************
* PoolSize Busy TopBusy AveBusy
* ThreadNum 1000 500 800 650
********************************************************/
fs2_info = &hos_func->fs2_info[FS2_POOL_THREAD_STATE];
hos_func->fs2_info[FS2_POOL_THREAD_STATE].fs2_handle = hos_init_fs2((char *)"hos-poolthread", strlen("hos-poolthread"));
fs2_handle = hos_func->fs2_info[FS2_POOL_THREAD_STATE].fs2_handle;
fs2_info->line_ids = (int *)calloc(1, sizeof(int));
fs2_info->column_ids = (int *)calloc(3, sizeof(int));
2021-04-26 18:17:37 +08:00
const char *poolthread_col[3] = {"PoolSize", "Busy", "TopBusy"};
for (i = 0; i < sizeof(poolthread_col) / sizeof(const char *); i++)
{
fs2_info->column_ids[i] = FS_register(fs2_handle, FS_STYLE_COLUMN, FS_CALC_CURRENT, poolthread_col[i]);
}
fs2_info->line_ids[0] = FS_register(fs2_handle, FS_STYLE_LINE, FS_CALC_CURRENT, "ThreadNum");
FS_start(fs2_handle);
}
2021-04-23 09:57:58 +08:00
pthread_create(&hos_func->fs2_thread, NULL, fs2_statistics, NULL);
2020-10-20 17:20:27 +08:00
return ;
}
2021-04-28 18:29:29 +08:00
static int hos_putobject_async(Aws::S3::Model::PutObjectRequest& request, size_t stream_len,
2021-04-23 09:57:58 +08:00
size_t thread_id, size_t fd, const char *bucket, const char *object)
2020-09-21 19:19:18 +08:00
{
2021-04-23 09:57:58 +08:00
char buf[128];
int ret = 0;
hos_func_thread_t *hos_func = &g_hos_handle.hos_func;
data_info_t *data_info = NULL;
//设置回调函数
std::shared_ptr<Aws::Client::AsyncCallerContext> context =
Aws::MakeShared<Aws::Client::AsyncCallerContext>("");
2021-04-23 14:30:52 +08:00
sprintf(buf, "%lu %lu %lu", thread_id, fd, stream_len);
2021-04-23 09:57:58 +08:00
context->SetUUID(buf);
2020-09-21 19:19:18 +08:00
2021-05-26 11:10:59 +08:00
auto &S3Client = *(g_hos_handle.S3Client);
2021-04-23 09:57:58 +08:00
ret = S3Client.PutObjectAsync(request, PutObjectAsyncFinished, context);
if (ret)
{
//不算真正成功需要等到PutObjectAsyncFinished的结果
MESA_handle_runtime_log(g_hos_handle.log, RLOG_LV_DEBUG, __FUNCTION__,
"PutObjectAsync success. [%s:%s]", bucket, object);
2021-04-28 18:29:29 +08:00
return HOS_CLIENT_OK;
2021-04-23 09:57:58 +08:00
}
else
2020-09-21 19:19:18 +08:00
{
2021-04-23 09:57:58 +08:00
MESA_handle_runtime_log(g_hos_handle.log, RLOG_LV_DEBUG, __FUNCTION__,
"PutObjectAsync failed. [%s:%s]", bucket, object);
2020-09-21 19:19:18 +08:00
2021-04-23 09:57:58 +08:00
if (hos_func->fs2_info[0].fs2_handle)
2020-09-21 19:19:18 +08:00
{
2021-04-23 09:57:58 +08:00
if (hos_func->fs2_info[0].reserved)
2020-09-21 19:19:18 +08:00
{
2021-04-23 09:57:58 +08:00
data_info = (data_info_t *)hos_func->fs2_info[0].reserved;
2021-04-23 14:30:52 +08:00
data_info->tx_failed_pkts[thread_id]++;
data_info->tx_failed_bytes[thread_id] += stream_len;
2020-09-21 19:19:18 +08:00
}
}
2021-04-28 18:29:29 +08:00
return HOS_SEND_FAILED;
2020-09-21 19:19:18 +08:00
}
2021-04-23 09:57:58 +08:00
}
2021-04-28 18:29:29 +08:00
static int hos_putobject_sync(Aws::S3::Model::PutObjectRequest& request, size_t stream_len, size_t thread_id, size_t fd,
2021-04-23 09:57:58 +08:00
const char *bucket, const char *object)
{
hos_func_thread_t *hos_func = &g_hos_handle.hos_func;
data_info_t *data_info = NULL;
2021-05-26 11:10:59 +08:00
auto& S3Client = *(g_hos_handle.S3Client);
2021-04-23 09:57:58 +08:00
Aws::S3::Model::PutObjectOutcome Outcome = S3Client.PutObject(request);
if (Outcome.IsSuccess())
{
if (hos_func->fs2_info[FS2_DATA_FLOW_STATE].fs2_handle && hos_func->fs2_info[FS2_DATA_FLOW_STATE].reserved)
{
data_info = (data_info_t *)hos_func->fs2_info[FS2_DATA_FLOW_STATE].reserved;
2021-04-23 14:30:52 +08:00
data_info->tx_pkts[thread_id]++;
data_info->tx_bytes[thread_id] += stream_len;
MESA_handle_runtime_log(g_hos_handle.log, RLOG_LV_DEBUG, __FUNCTION__,
"PutObject success. [%s:%s] tx_pkts:%d, tx_bytes:%d",
bucket, object, data_info->tx_pkts[thread_id], data_info->tx_bytes[thread_id]);
}
else
{
MESA_handle_runtime_log(g_hos_handle.log, RLOG_LV_DEBUG, __FUNCTION__,
"PutObject success. [%s:%s]", bucket, object);
2021-04-23 09:57:58 +08:00
}
2021-04-28 18:29:29 +08:00
return HOS_CLIENT_OK;
2021-04-23 09:57:58 +08:00
}
else
{
MESA_handle_runtime_log(g_hos_handle.log, RLOG_LV_DEBUG, __FUNCTION__,
2021-04-28 18:29:29 +08:00
"PutObject failed. [%s:%s] cause:%s", bucket, object, Outcome.GetError().GetMessage().c_str());
2021-04-23 09:57:58 +08:00
if (hos_func->fs2_info[FS2_DATA_FLOW_STATE].fs2_handle && hos_func->fs2_info[FS2_DATA_FLOW_STATE].reserved)
{
data_info = (data_info_t *)hos_func->fs2_info[FS2_DATA_FLOW_STATE].reserved;
2021-04-23 14:30:52 +08:00
data_info->tx_failed_pkts[thread_id]++;
data_info->tx_failed_bytes[thread_id] += stream_len;
2021-04-23 09:57:58 +08:00
}
2021-04-28 18:29:29 +08:00
return (int)Outcome.GetError().GetErrorType() + 1;
2021-04-23 09:57:58 +08:00
}
2020-09-21 19:19:18 +08:00
}
2021-04-26 13:59:36 +08:00
hos_instance hos_get_instance()
{
if (g_hos_handle.S3Client != NULL)
{
g_hos_handle.count++;
g_hos_instance.result = true;
return &g_hos_instance;
}
2021-05-26 11:10:59 +08:00
memset(&g_hos_instance, 0, sizeof(g_hos_instance));
2021-04-26 13:59:36 +08:00
g_hos_instance.result = false;
return &g_hos_instance;
}
2021-04-23 09:57:58 +08:00
hos_instance hos_init_instance(const char *conf_path, const char *module, size_t thread_num, const char *bucket)
2020-09-11 16:13:02 +08:00
{
2021-04-23 09:57:58 +08:00
hos_config_t *hos_conf = &g_hos_handle.hos_config;
char hos_url[1024];
2021-04-28 18:29:29 +08:00
if (conf_path == NULL || thread_num == 0 || module == NULL || bucket == NULL)
{
2021-04-23 09:57:58 +08:00
g_hos_instance.result = false;
g_hos_instance.error_code = HOS_PARAMETER_ERROR;
2021-04-28 18:29:29 +08:00
snprintf(g_hos_instance.error_message, HOS_ERROR_MESSAGE_SIZE,
"param error:conf_path:%s, module:%s, thread_num:%lu, bucket:%s", conf_path, module, thread_num, bucket);
2021-04-23 09:57:58 +08:00
return &g_hos_instance;
}
MESA_load_profile_string_nodef(conf_path, module, "hos_serverip", hos_conf->ip, MAX_HOS_STRING_LEN);
MESA_load_profile_uint_nodef(conf_path, module, "hos_serverport", &hos_conf->port);
MESA_load_profile_string_nodef(conf_path, module, "hos_accesskeyid", hos_conf->accesskeyid, MAX_HOS_STRING_LEN);
MESA_load_profile_string_nodef(conf_path, module, "hos_secretkey", hos_conf->secretkey, MAX_HOS_STRING_LEN);
MESA_load_profile_string_def(conf_path, module, "hos_log_path", hos_conf->log_path, MAX_HOS_STRING_LEN, HOS_LOG_PATH);
MESA_load_profile_uint_def(conf_path, module, "hos_log_level", &hos_conf->log_level, 30);
MESA_load_profile_uint_def(conf_path, module, "hos_poolsize", &hos_conf->pool_thread_size, 0);
MESA_load_profile_uint_def(conf_path, module, "hos_cache_size", &hos_conf->cache_size, 102400);
MESA_load_profile_uint_def(conf_path, module, "hos_cache_count", &hos_conf->cache_count, 10);
MESA_load_profile_uint_def(conf_path, module, "hos_fd_live_time_ms", &hos_conf->timeout, 1000);
2021-04-26 13:59:36 +08:00
MESA_load_profile_string_nodef(conf_path, module, "hos_fs2_serverip", hos_conf->fs2_ip, INET6_ADDRSTRLEN);
2021-04-23 09:57:58 +08:00
MESA_load_profile_uint_nodef(conf_path, module, "hos_fs2_serverport", &hos_conf->fs2_port);
MESA_load_profile_string_def(conf_path, module, "hos_fs2_path", hos_conf->fs2_path, sizeof(hos_conf->fs2_path), "./hos_fs2.stat");
MESA_load_profile_uint_def(conf_path, module, "hos_fs2_format", &hos_conf->fs2_fmt, 0);
2021-04-26 13:59:36 +08:00
if (hos_conf->ip && hos_conf->port && strlen(hos_conf->accesskeyid) && strlen(hos_conf->secretkey))
2021-04-23 09:57:58 +08:00
{
g_hos_handle.log = MESA_create_runtime_log_handle(hos_conf->log_path, hos_conf->log_level);
if (log == NULL)
{
g_hos_instance.result = false;
g_hos_instance.error_code = HOS_RUNTIME_LOG_FAILED;
snprintf(g_hos_instance.error_message, HOS_ERROR_MESSAGE_SIZE, "runtime log create failed.");
return &g_hos_instance;
}
snprintf(hos_url, sizeof(hos_url), "http://%s:%d/hos/", hos_conf->ip, hos_conf->port);
2021-04-28 18:29:29 +08:00
hos_conf->thread_num = thread_num;
2021-04-23 09:57:58 +08:00
hos_client_create();
if (g_hos_instance.result == true)
{
if(hos_verify_bucket(bucket) == false)
{
MESA_handle_runtime_log(g_hos_handle.log, RLOG_LV_FATAL, __FUNCTION__, "bucket:%s not exist.", bucket);
hos_shutdown_instance();
2021-04-28 18:29:29 +08:00
g_hos_instance.result = false;
g_hos_instance.error_code = HOS_BUCKET_NOT_EXIST;
snprintf(g_hos_instance.error_message, HOS_ERROR_MESSAGE_SIZE, "bucket:%s not exits.", bucket);
2021-04-23 09:57:58 +08:00
return &g_hos_instance;
}
MESA_handle_runtime_log(g_hos_handle.log, RLOG_LV_DEBUG, __FUNCTION__, "Instance init completed");
if (hos_conf->fs2_ip && hos_conf->fs2_port)
{
2021-04-26 18:17:37 +08:00
hos_expand_fs2();
2021-04-23 09:57:58 +08:00
}
else
{
MESA_handle_runtime_log(g_hos_handle.log, RLOG_LV_FATAL, __FUNCTION__, "hos fs2 function not starup");
}
2021-04-28 18:29:29 +08:00
g_hos_instance.error_code = 0;
g_hos_instance.error_message[0]='\0';
g_hos_instance.hos_url_prefix = (const char *)calloc(1, strlen(hos_url) + 1);
memcpy((void *)g_hos_instance.hos_url_prefix, hos_url, strlen(hos_url));
2021-04-23 09:57:58 +08:00
}
return &g_hos_instance;
}
else
{
g_hos_instance.result = false;
g_hos_instance.error_code = HOS_CONF_ERROR;
snprintf(g_hos_instance.error_message, HOS_ERROR_MESSAGE_SIZE, "hos param error:hos ip:%s, hos port:%u, accesskeyid:%s, secretkey:%s",
hos_conf->ip, hos_conf->port, hos_conf->accesskeyid, hos_conf->secretkey);
MESA_destroy_runtime_log_handle(g_hos_handle.log);
return &g_hos_instance;
}
}
int hos_create_bucket(const char *bucket)
{
if ((bucket == NULL) || (g_hos_handle.S3Client == NULL))
{
MESA_handle_runtime_log(g_hos_handle.log, RLOG_LV_FATAL, "hos_create_bucket",
"error:bucket:%s, s3client:%s", bucket, g_hos_handle.S3Client?"not null":"null");
2020-09-21 19:19:18 +08:00
return HOS_PARAMETER_ERROR;
}
2021-05-26 11:10:59 +08:00
auto& S3Client = *g_hos_handle.S3Client;
2020-09-21 19:19:18 +08:00
/* 本地检查是否已经存在该bucket */
2021-04-23 09:57:58 +08:00
for (Aws::S3::Model::Bucket& new_bucket : g_hos_handle.buckets)
2020-09-21 19:19:18 +08:00
{
if (strcmp(new_bucket.GetName().c_str(), bucket) == 0)
{
2021-04-23 09:57:58 +08:00
MESA_handle_runtime_log(g_hos_handle.log, RLOG_LV_DEBUG, __FUNCTION__, "%s was exits", bucket);
2020-09-21 19:19:18 +08:00
return HOS_CLIENT_OK;
}
}
2020-09-11 16:13:02 +08:00
Aws::S3::Model::CreateBucketRequest createBucketRequest;
createBucketRequest.SetBucket(bucket);
2020-09-21 19:19:18 +08:00
Aws::S3::Model::CreateBucketOutcome createBucketOutcome = S3Client.CreateBucket(createBucketRequest);
2020-09-11 16:13:02 +08:00
if (!createBucketOutcome.IsSuccess())
{
Aws::S3::S3Errors errorcode = createBucketOutcome.GetError().GetErrorType();
if (errorcode != Aws::S3::S3Errors::BUCKET_ALREADY_OWNED_BY_YOU)
{
2021-04-23 09:57:58 +08:00
MESA_handle_runtime_log(g_hos_handle.log, RLOG_LV_FATAL, __FUNCTION__,"error: %s create failed. %s",
bucket, createBucketOutcome.GetError().GetMessage().c_str());
2020-09-21 19:19:18 +08:00
return (int)errorcode + 1;
}
2020-09-11 16:13:02 +08:00
}
2021-04-23 09:57:58 +08:00
MESA_handle_runtime_log(g_hos_handle.log, RLOG_LV_FATAL, __FUNCTION__, "%s create successful", bucket);
2020-09-11 16:13:02 +08:00
2020-09-21 19:19:18 +08:00
return HOS_CLIENT_OK;
2020-09-11 16:13:02 +08:00
}
2021-04-23 09:57:58 +08:00
static int hos_upload_stream(const char *bucket, const char *object, const char *data, size_t data_len,
put_finished_callback callback, void *userdata, size_t thread_id)
2020-09-11 16:13:02 +08:00
{
2020-12-01 16:12:41 +08:00
data_info_t *data_info = NULL;
2021-04-23 09:57:58 +08:00
hos_config_t *hos_conf = &g_hos_handle.hos_config;
hos_func_thread_t *hos_func = &g_hos_handle.hos_func;
2020-12-01 16:12:41 +08:00
int ret;
2021-04-23 09:57:58 +08:00
int mode = 0;
2020-09-11 16:13:02 +08:00
2021-04-23 09:57:58 +08:00
if ((g_hos_handle.S3Client == NULL) || (bucket == NULL) || (object == NULL) || (thread_id > hos_conf->thread_num))
2020-09-11 16:13:02 +08:00
{
2021-04-23 09:57:58 +08:00
MESA_handle_runtime_log(g_hos_handle.log, RLOG_LV_FATAL, "hos_upload_stream",
"s3client:%s, bucket:%s, object:%s, thread_id:%d, thread_num:%d",
g_hos_handle.S3Client?"not null":"null", bucket, object, thread_id, hos_conf->thread_num);
2020-09-21 19:19:18 +08:00
return HOS_PARAMETER_ERROR;
2020-09-11 16:13:02 +08:00
}
2021-04-23 09:57:58 +08:00
mode = data?1:0; // 1, file mode; 0 buf mode
2020-09-11 16:13:02 +08:00
// Create and configure the asynchronous put object request.
Aws::S3::Model::PutObjectRequest request;
request.SetBucket(bucket);
request.SetKey(object);
2020-09-21 19:19:18 +08:00
//设置上传数据类型
2021-04-23 09:57:58 +08:00
if (mode == 0)
2020-09-21 19:19:18 +08:00
{
//文件类型
const std::shared_ptr<Aws::IOStream> input_data =
2021-04-23 09:57:58 +08:00
Aws::MakeShared<Aws::FStream>("hos_upload_file_tag", object, std::ios_base::in | std::ios_base::binary);
2020-09-21 19:19:18 +08:00
request.SetBody(input_data);
}
else
{
//内存块
const std::shared_ptr<Aws::IOStream> input_data =
2021-04-23 09:57:58 +08:00
Aws::MakeShared<Aws::StringStream>("hos_upload_buf_tag");
2020-09-21 19:19:18 +08:00
Aws::String stream (data, data_len);
*input_data << stream;
request.SetBody(input_data);
}
2020-12-01 16:12:41 +08:00
//field_stat2 record
2021-04-23 09:57:58 +08:00
if (hos_func->fs2_info[0].fs2_handle)
2020-12-01 16:12:41 +08:00
{
2021-04-23 09:57:58 +08:00
if (hos_func->fs2_info[0].reserved)
2020-12-01 16:12:41 +08:00
{
2021-04-23 09:57:58 +08:00
data_info = (data_info_t *)hos_func->fs2_info[0].reserved;
2021-04-23 14:30:52 +08:00
data_info->rx_pkts[thread_id]++;
data_info->rx_bytes[thread_id] += data_len;
2020-12-01 16:12:41 +08:00
}
}
2020-09-21 19:19:18 +08:00
//设置回调函数
2020-12-01 16:12:41 +08:00
size_t fd = hash_get_min_free_fd(thread_id);
2020-09-21 19:19:18 +08:00
2021-04-23 09:57:58 +08:00
hos_fd_context_t info = {fd, 0, (char *)bucket, (char *)object, (void *)callback, userdata, NULL, 0, 0, 0 };
2021-04-23 14:30:52 +08:00
add_fd_context(&g_fd_context[thread_id], &info);
2020-09-21 19:19:18 +08:00
2021-05-26 11:10:59 +08:00
{
std::lock_guard<std::mutex> locker(m_client_lock);
if (g_hos_handle.hos_func.fd_thread == 0)
{
g_hos_handle.hos_func.fd_thread_status = 0;
pthread_create(&g_hos_handle.hos_func.fd_thread, NULL, hos_fd_manage, NULL);
}
}
2021-04-23 09:57:58 +08:00
if (hos_conf->pool_thread_size > 0)
{
ret = hos_putobject_async(request, data_len, thread_id, fd, bucket, object);
}
else
{
ret = hos_putobject_sync(request, data_len, thread_id, fd, bucket, object);
}
2021-04-28 18:29:29 +08:00
return ret;
2020-09-21 19:19:18 +08:00
}
2021-04-23 09:57:58 +08:00
int hos_upload_file(const char *bucket, const char *file_path, put_finished_callback callback, void *userdata, size_t thread_id)
2020-09-21 19:19:18 +08:00
{
2021-04-23 09:57:58 +08:00
struct stat buffer;
2021-04-28 18:29:29 +08:00
if (g_hos_instance.result == false || g_hos_handle.S3Client == NULL)
{
MESA_handle_runtime_log(g_hos_handle.log, RLOG_LV_FATAL, __FUNCTION__,
"error:g_hos_instance.result:%d, g_hos_handle.S3CLient:%s",
g_hos_instance.result, (g_hos_handle.S3Client == NULL)?(NULL):("not null"));
return HOS_INSTANCE_NOT_INIT;
}
2021-04-23 09:57:58 +08:00
2021-04-28 18:29:29 +08:00
if ((bucket == NULL) || (file_path == NULL) || (thread_id > g_hos_handle.hos_config.thread_num))
2021-04-23 09:57:58 +08:00
{
MESA_handle_runtime_log(g_hos_handle.log, RLOG_LV_FATAL, "hos_upload_file",
"s3client:%s, bucket:%s, file_path:%s, thread_id:%d, thread_num:%d",
2021-04-28 18:29:29 +08:00
bucket, file_path, thread_id, g_hos_handle.hos_config.thread_num);
2021-04-23 09:57:58 +08:00
return HOS_PARAMETER_ERROR;
}
if (stat(file_path, &buffer) == -1)
{
MESA_handle_runtime_log(g_hos_handle.log, RLOG_LV_FATAL, "hos_upload_file", "The file:%s not exist", file_path);
return HOS_FILE_NOT_EXIST;
}
return hos_upload_stream(bucket, file_path, NULL, buffer.st_size, callback, userdata, thread_id);
2020-09-21 19:19:18 +08:00
}
2021-04-23 09:57:58 +08:00
int hos_upload_buf(const char *bucket, const char *object, const char *buf, size_t buf_len, put_finished_callback callback, void *userdata, size_t thread_id)
2020-09-21 19:19:18 +08:00
{
2021-04-28 18:29:29 +08:00
if (g_hos_instance.result == false || g_hos_handle.S3Client == NULL)
{
MESA_handle_runtime_log(g_hos_handle.log, RLOG_LV_FATAL, __FUNCTION__,
"error:g_hos_instance.result:%d, g_hos_handle.S3CLient:%s",
g_hos_instance.result, (g_hos_handle.S3Client == NULL)?(NULL):("not null"));
return HOS_INSTANCE_NOT_INIT;
}
if ((bucket == NULL) || (object == NULL) || (buf == NULL) || (buf_len == 0)
2021-04-23 09:57:58 +08:00
|| (thread_id > g_hos_handle.hos_config.thread_num))
{
MESA_handle_runtime_log(g_hos_handle.log, RLOG_LV_FATAL, "hos_upload_buf",
2021-04-28 18:29:29 +08:00
"bucket:%s, object:%s, buf:%s, buf_len:%d, thread_id:%d, thread_num:%d",
bucket, object, buf?"not null":"null", buf_len, thread_id, g_hos_handle.hos_config.thread_num);
2021-04-23 09:57:58 +08:00
return HOS_PARAMETER_ERROR;
}
return hos_upload_stream(bucket, object, buf, buf_len, callback, userdata, thread_id);
2020-09-21 19:19:18 +08:00
}
static void *hos_fd_manage(void *ptr)
{
2021-04-23 09:57:58 +08:00
hos_fd_context_t *a_fd_context;
size_t thread_sum = g_hos_handle.hos_config.thread_num;
size_t thread_num;
size_t fd;
while(1)
{
2021-04-23 09:57:58 +08:00
if (g_hos_handle.hos_func.fd_thread_status)
break;
for (thread_num = 0; thread_num < thread_sum; thread_num++)
{
2020-12-01 16:12:41 +08:00
for(fd = 3; fd < MAX_HOS_CLIENT_FD_NUM + 1; fd++)
{
2021-04-23 14:30:52 +08:00
if (!g_fd_info[thread_num][fd])
2020-12-01 16:12:41 +08:00
continue;
2021-04-23 14:30:52 +08:00
a_fd_context = find_context_by_fd(g_fd_context[thread_num], fd);
2021-04-23 09:57:58 +08:00
if (!a_fd_context)
continue;
2021-04-23 09:57:58 +08:00
if (a_fd_context->fd_status == HOS_FD_INJECT)
2020-12-01 16:12:41 +08:00
{
2021-04-23 09:57:58 +08:00
if (a_fd_context->position == a_fd_context->recive_cnt)
{
MESA_handle_runtime_log(g_hos_handle.log, RLOG_LV_DEBUG, __FUNCTION__,
"[%s:%s] upload completed. [thread:%d fd:%d] delete",
a_fd_context->bucket, a_fd_context->object, thread_num, fd);
2020-12-01 16:12:41 +08:00
hos_delete_fd(fd, thread_num);
2021-04-23 09:57:58 +08:00
}
else if (a_fd_context->overtime <= get_current_ms())
{
MESA_handle_runtime_log(g_hos_handle.log, RLOG_LV_FATAL, __FUNCTION__,
"[%s:%s] upload not completed, but the live-time of [thread_id:%d fd:%d] is over.",
a_fd_context->bucket, a_fd_context->object, thread_num, fd);
hos_delete_fd(fd, thread_num);
}
2020-12-01 16:12:41 +08:00
}
}
}
usleep(500000);
}
pthread_exit(NULL);
}
2021-04-23 09:57:58 +08:00
int hos_open_fd(const char *bucket, const char *object, put_finished_callback callback, void *userdata, size_t thread_id, int mode)
2020-09-21 19:19:18 +08:00
{
2021-04-28 18:29:29 +08:00
if (g_hos_instance.result == false || g_hos_handle.S3Client == NULL)
{
MESA_handle_runtime_log(g_hos_handle.log, RLOG_LV_FATAL, __FUNCTION__,
"error:g_hos_instance.result:%d, g_hos_handle.S3CLient:%s",
2021-05-26 11:10:59 +08:00
g_hos_instance.result, (g_hos_handle.S3Client == NULL)?("null"):("not null"));
2021-04-28 18:29:29 +08:00
return HOS_INSTANCE_NOT_INIT;
}
if ((bucket == NULL) || (object == NULL) || (thread_id > g_hos_handle.hos_config.thread_num) || strlen(bucket) == 0 || strlen(object) == 0)
2020-09-21 19:19:18 +08:00
{
2021-04-23 09:57:58 +08:00
MESA_handle_runtime_log(g_hos_handle.log, RLOG_LV_FATAL, "hos_open_fd",
2021-05-26 11:10:59 +08:00
"bucket:%s, obejct:%s, thread_id:%d",
//(bucket == NULL)?"null":bucket, (object == NULL)?"null":object, thread_id);
2021-04-28 18:29:29 +08:00
bucket, object, thread_id);
2020-09-21 19:19:18 +08:00
return HOS_PARAMETER_ERROR;
}
2020-10-09 14:20:39 +08:00
size_t fd = hash_get_min_free_fd(thread_id);
2020-09-21 19:19:18 +08:00
if (fd == 0)
{
2021-04-23 09:57:58 +08:00
MESA_handle_runtime_log(g_hos_handle.log, RLOG_LV_FATAL, "hos_open_fd",
"error:fd not enough, thread_id:%d, fd free: %d, fd register:%d, fd inject:%d",
thread_id,
2021-04-23 14:30:52 +08:00
g_fd_info[thread_id][HOS_FD_FREE],
g_fd_info[thread_id][HOS_FD_REGISTER],
g_fd_info[thread_id][HOS_FD_INJECT]);
2021-04-23 09:57:58 +08:00
MESA_handle_runtime_log(g_hos_handle.log, RLOG_LV_DEBUG, "hos_open_fd", "thread_id:%d, fd:%d", thread_id, fd);
2020-09-21 19:19:18 +08:00
return HOS_FD_NOT_ENOUGH;
}
2021-04-23 09:57:58 +08:00
MESA_handle_runtime_log(g_hos_handle.log, RLOG_LV_DEBUG, "hos_open_fd", "thread_id:%d, fd:%d", thread_id, fd);
2020-09-21 19:19:18 +08:00
2021-04-23 09:57:58 +08:00
hos_fd_context_t info = {fd, mode, (char *)bucket, (char *)object, (void *)callback, userdata,
NULL,/*cache*/ g_hos_handle.hos_config.cache_count, 0,/*position*/ 0,/*recive_cnt*/
(long)g_hos_handle.hos_config.cache_size,/*cache_rest*/ HOS_FD_REGISTER,/*fd_status*/
0,/*overtime*/ g_hos_handle.hos_config.timeout,};
2021-04-23 14:30:52 +08:00
add_fd_context(&g_fd_context[thread_id], &info);
2021-04-23 09:57:58 +08:00
{
std::lock_guard<std::mutex> locker(m_client_lock);
2021-04-23 09:57:58 +08:00
if (g_hos_handle.hos_func.fd_thread == 0)
{
2021-04-23 09:57:58 +08:00
g_hos_handle.hos_func.fd_thread_status = 0;
pthread_create(&g_hos_handle.hos_func.fd_thread, NULL, hos_fd_manage, NULL);
}
}
2021-04-23 09:57:58 +08:00
2020-09-21 19:19:18 +08:00
return fd;
}
int hos_write(size_t fd, const char *stream, size_t stream_len, size_t thread_id)
2020-09-21 19:19:18 +08:00
{
struct stat buffer;
2021-04-23 09:57:58 +08:00
hos_fd_context_t *a_fd_context = NULL;
2020-09-27 11:58:23 +08:00
char num[128];
2020-10-20 17:20:27 +08:00
int ret = 0;
2020-12-01 16:12:41 +08:00
data_info_t *data_info = NULL;
2021-04-23 09:57:58 +08:00
hos_config_t *hos_conf = &g_hos_handle.hos_config;
hos_func_thread_t *hos_func = &g_hos_handle.hos_func;
size_t upload_len = 0;
2020-12-01 16:12:41 +08:00
2021-04-28 18:29:29 +08:00
if (g_hos_instance.result == false || g_hos_handle.S3Client == NULL)
{
MESA_handle_runtime_log(g_hos_handle.log, RLOG_LV_FATAL, __FUNCTION__,
"error:g_hos_instance.result:%d, g_hos_handle.S3CLient:%s",
g_hos_instance.result, (g_hos_handle.S3Client == NULL)?(NULL):("not null"));
return HOS_INSTANCE_NOT_INIT;
}
if ((fd < 3) || fd > MAX_HOS_CLIENT_FD_NUM || (stream == NULL) || (thread_id > hos_conf->thread_num))
2020-09-21 19:19:18 +08:00
{
2021-04-23 09:57:58 +08:00
MESA_handle_runtime_log(g_hos_handle.log, RLOG_LV_FATAL,
2021-05-26 11:10:59 +08:00
"hos_write", "error: fd:%d, stream:%s, stream_len:%d, thread_id:%d.",
2021-04-23 09:57:58 +08:00
fd, stream?"not null":"null", stream_len, thread_id);
2020-09-21 19:19:18 +08:00
return HOS_PARAMETER_ERROR;
}
2021-04-23 14:30:52 +08:00
if (g_fd_info[thread_id][fd])
2020-10-09 14:20:39 +08:00
{
2021-04-23 14:30:52 +08:00
a_fd_context = find_context_by_fd(g_fd_context[thread_id], fd);
2020-10-09 14:20:39 +08:00
}
2021-04-23 09:57:58 +08:00
if (a_fd_context == NULL)
2020-09-21 19:19:18 +08:00
{
2021-04-23 09:57:58 +08:00
MESA_handle_runtime_log(g_hos_handle.log, RLOG_LV_FATAL, __FUNCTION__, "fd info not find. thread_id:%d, fd:%d", thread_id, fd);
2020-09-21 19:19:18 +08:00
return HOS_HASH_NOT_FIND;
}
2021-04-23 09:57:58 +08:00
MESA_handle_runtime_log(g_hos_handle.log, RLOG_LV_DEBUG, __FUNCTION__, "Get fd_context, thread_id:%d, fd:%d", thread_id, fd);
2020-10-20 17:20:27 +08:00
//field_stat2 record
2021-04-23 09:57:58 +08:00
if (hos_func->fs2_info[0].fs2_handle)
2020-11-02 17:55:02 +08:00
{
2021-04-23 09:57:58 +08:00
if (hos_func->fs2_info[0].reserved)
2020-12-01 16:12:41 +08:00
{
2021-04-23 09:57:58 +08:00
data_info = (data_info_t *)hos_func->fs2_info[0].reserved;
2021-04-23 14:30:52 +08:00
data_info->rx_pkts[thread_id]++;
data_info->rx_bytes[thread_id] += stream_len;
2020-12-01 16:12:41 +08:00
}
2020-11-02 17:55:02 +08:00
}
2020-10-20 17:20:27 +08:00
// create and configure the asynchronous put object request.
2020-09-21 19:19:18 +08:00
Aws::S3::Model::PutObjectRequest request;
//设置上传数据类型
2021-04-23 09:57:58 +08:00
if (a_fd_context->mode & BUFF_MODE)
2020-09-21 19:19:18 +08:00
{
//BUFF_MODE
2021-04-23 09:57:58 +08:00
if (a_fd_context->mode & APPEND_MODE)
{
//APPEND_MODE
2021-04-23 09:57:58 +08:00
if (a_fd_context->cache == NULL)
{
2021-04-23 14:30:52 +08:00
//a_fd_context->cache = Aws::MakeShared<Aws::StringStream>("hos_write append mode");
a_fd_context->cache = std::make_shared<Aws::StringStream>();
}
2021-04-23 09:57:58 +08:00
Aws::String buffer(stream, stream_len);
*a_fd_context->cache << buffer;
a_fd_context->cache_rest -= stream_len;
2021-04-23 14:30:52 +08:00
data_info->cache[thread_id] += stream_len;
2021-04-23 09:57:58 +08:00
if (a_fd_context->cache_count == 0 || --a_fd_context->cache_count)
{
2021-04-23 09:57:58 +08:00
//cache_count == 0,不设置cache_count的情况
//cache_count > 0,设置cache_count的情况
if (a_fd_context->cache_rest > 0)
{
return HOS_CLIENT_OK;
}
}
2021-04-23 09:57:58 +08:00
request.SetBody(a_fd_context->cache);
// add headers
2021-04-23 09:57:58 +08:00
atomic_add(&(a_fd_context->position), 1);
snprintf(num, 128, "%lu", atomic_read(&(a_fd_context->position)));
Aws::Map<Aws::String, Aws::String> headers;
2021-04-23 09:57:58 +08:00
headers["x-hos-upload-type"] = "append";
headers["x-hos-position"] = num;
request.SetMetadata(headers);
2021-04-23 14:30:52 +08:00
a_fd_context->cache->seekg(0, std::ios_base::end);
upload_len = a_fd_context->cache->tellg();
a_fd_context->cache->seekg(0, std::ios_base::beg);
2021-04-23 09:57:58 +08:00
MESA_handle_runtime_log(g_hos_handle.log, RLOG_LV_DEBUG, __FUNCTION__, "x-hos-posotion:%s", num);
}
else
{
const std::shared_ptr<Aws::IOStream> input_data =
2021-04-23 09:57:58 +08:00
Aws::MakeShared<Aws::StringStream>("hos_write buffer mode");
2020-10-22 16:35:03 +08:00
Aws::String buffer (stream, stream_len);
*input_data << buffer;
request.SetBody(input_data);
2021-04-23 09:57:58 +08:00
upload_len = stream_len;
}
2020-09-21 19:19:18 +08:00
}
else
{
2020-10-14 15:23:01 +08:00
if (stat(stream, &buffer) == -1)
2020-09-21 19:19:18 +08:00
{
2021-04-23 09:57:58 +08:00
MESA_handle_runtime_log(g_hos_handle.log, RLOG_LV_FATAL, __FUNCTION__, "The file:%s not exist", stream);
return HOS_FILE_NOT_EXIST;
2020-09-21 19:19:18 +08:00
}
//文件类型
const std::shared_ptr<Aws::IOStream> input_data =
2021-04-23 09:57:58 +08:00
Aws::MakeShared<Aws::FStream>("hos_write file mode", a_fd_context->object, std::ios_base::in | std::ios_base::binary);
2020-09-21 19:19:18 +08:00
request.SetBody(input_data);
2021-04-23 09:57:58 +08:00
upload_len = buffer.st_size;
2020-09-21 19:19:18 +08:00
}
2020-09-11 16:13:02 +08:00
2021-04-23 09:57:58 +08:00
request.SetBucket(a_fd_context->bucket);
request.SetKey(a_fd_context->object);
2021-04-23 09:57:58 +08:00
if (hos_conf->pool_thread_size > 0)
{
ret = hos_putobject_async(request, upload_len, thread_id, fd, a_fd_context->bucket, a_fd_context->object);
}
else
{
ret = hos_putobject_sync(request, upload_len, thread_id, fd, a_fd_context->bucket, a_fd_context->object);
}
2020-12-01 16:12:41 +08:00
//恢复fd 的cache设置
2021-04-23 09:57:58 +08:00
if (a_fd_context->mode & APPEND_MODE)
{
2021-04-28 18:29:29 +08:00
data_info->cache[thread_id] -= upload_len;
2021-04-23 09:57:58 +08:00
a_fd_context->cache.reset();
a_fd_context->cache = NULL;
a_fd_context->cache_rest = hos_conf->cache_size;
a_fd_context->cache_count = hos_conf->cache_count;
}
2021-04-28 18:29:29 +08:00
return ret;
2020-09-21 19:19:18 +08:00
}
2020-09-21 19:19:18 +08:00
int hos_close_fd(size_t fd, size_t thread_id)
{
2021-04-23 09:57:58 +08:00
hos_fd_context_t *a_fd_context = NULL;
char num[128];
2021-04-23 09:57:58 +08:00
hos_config_t *hos_conf = &g_hos_handle.hos_config;
2021-04-23 14:30:52 +08:00
size_t upload_len = 0;
2020-12-01 16:12:41 +08:00
2021-04-28 18:29:29 +08:00
if (g_hos_instance.result == false || g_hos_handle.S3Client == NULL)
{
MESA_handle_runtime_log(g_hos_handle.log, RLOG_LV_FATAL, __FUNCTION__,
"error:g_hos_instance.result:%d, g_hos_handle.S3CLient:%s",
g_hos_instance.result, (g_hos_handle.S3Client == NULL)?(NULL):("not null"));
return HOS_INSTANCE_NOT_INIT;
}
if (fd < 3 || fd > 65533 || thread_id > hos_conf->thread_num)
2020-09-21 19:19:18 +08:00
{
2021-04-23 09:57:58 +08:00
MESA_handle_runtime_log(g_hos_handle.log, RLOG_LV_FATAL, "hos_close_fd",
"error:fd:%d, thread_id:%d, thread_sum:%d.",
fd, thread_id, hos_conf->thread_num);
2020-09-21 19:19:18 +08:00
return HOS_PARAMETER_ERROR;
}
2021-04-23 14:30:52 +08:00
if (g_fd_info[thread_id][fd])
{
2021-04-23 14:30:52 +08:00
a_fd_context = find_context_by_fd(g_fd_context[thread_id], fd);
}
2021-04-23 09:57:58 +08:00
if (a_fd_context == NULL)
{
2021-04-23 09:57:58 +08:00
MESA_handle_runtime_log(g_hos_handle.log, RLOG_LV_DEBUG,
"hos_close_fd", "not find the a_fd_context of [fd:%d thread:%d]",
fd, thread_id);
return HOS_CLIENT_OK;
}
//close fd 之前发送append的缓存中内容
2021-04-23 09:57:58 +08:00
if ((a_fd_context->mode & BUFF_MODE) && (a_fd_context->mode & APPEND_MODE))
{
2021-04-23 09:57:58 +08:00
if (a_fd_context->cache_rest != (long)hos_conf->cache_size && a_fd_context->cache != NULL)
{
// Create and configure the asynchronous put object request.
Aws::S3::Model::PutObjectRequest request;
2021-04-23 09:57:58 +08:00
request.SetBucket(a_fd_context->bucket);
request.SetKey(a_fd_context->object);
request.SetBody(a_fd_context->cache);
// add headers
2021-04-23 09:57:58 +08:00
atomic_add(&(a_fd_context->position), 1);
snprintf(num, 128, "%lu", atomic_read(&(a_fd_context->position)));
Aws::Map<Aws::String, Aws::String> headers;
headers["x-hos-upload-type"] = "append";
headers["x-hos-position"] = num;
request.SetMetadata(headers);
2021-04-23 14:30:52 +08:00
a_fd_context->cache->seekg(0, std::ios_base::end);
upload_len = a_fd_context->cache->tellg();
a_fd_context->cache->seekg(0, std::ios_base::beg);
2021-04-23 14:30:52 +08:00
if (hos_conf->pool_thread_size > 0)
2021-04-23 09:57:58 +08:00
{
2021-04-23 14:30:52 +08:00
hos_putobject_async(request, upload_len, thread_id, fd, a_fd_context->bucket, a_fd_context->object);
2021-04-23 09:57:58 +08:00
}
else
2020-12-01 16:12:41 +08:00
{
2021-04-23 14:30:52 +08:00
hos_putobject_sync(request, upload_len, thread_id, fd, a_fd_context->bucket, a_fd_context->object);
2020-12-01 16:12:41 +08:00
}
}
}
2021-04-23 09:57:58 +08:00
a_fd_context->fd_status = HOS_FD_INJECT;
a_fd_context->cache.reset();
a_fd_context->cache = NULL;
a_fd_context->overtime = get_current_ms() + a_fd_context->timeout;
a_fd_context->cache_rest = hos_conf->cache_size;
a_fd_context->cache_count = hos_conf->cache_count;
2020-09-21 19:19:18 +08:00
2021-04-23 14:30:52 +08:00
g_fd_info[thread_id][HOS_FD_REGISTER]--;
g_fd_info[thread_id][HOS_FD_INJECT]++;
2020-12-01 16:12:41 +08:00
2020-09-21 19:19:18 +08:00
return HOS_CLIENT_OK;
2020-09-11 16:13:02 +08:00
}
2021-04-23 09:57:58 +08:00
int hos_shutdown_instance()
2020-09-11 16:13:02 +08:00
{
std::lock_guard<std::mutex> locker(m_client_lock);
2020-09-22 17:22:21 +08:00
size_t i = 0;
2021-04-23 09:57:58 +08:00
hos_config_t *hos_conf = &g_hos_handle.hos_config;
hos_func_thread_t *hos_func = &g_hos_handle.hos_func;
if (g_hos_handle.S3Client == NULL)
2020-09-11 16:13:02 +08:00
{
2021-04-23 09:57:58 +08:00
MESA_handle_runtime_log(g_hos_handle.log, RLOG_LV_DEBUG, "hos_shutdown_instance", "There is no hos client.");
return HOS_CLIENT_OK;
2020-09-21 19:19:18 +08:00
}
2021-04-23 09:57:58 +08:00
if (g_hos_handle.count > 0 && --g_hos_handle.count)
{
2021-04-23 09:57:58 +08:00
MESA_handle_runtime_log(g_hos_handle.log, RLOG_LV_DEBUG, "hos_shutdown_instance", "hos client count:%d.", g_hos_handle.count);
return HOS_CLIENT_OK;
}
2021-04-23 09:57:58 +08:00
Aws::Vector<Aws::S3::Model::Bucket>().swap(g_hos_handle.buckets);
2020-09-23 19:06:09 +08:00
2021-04-23 09:57:58 +08:00
if (hos_func->fd_thread)
{
2021-04-23 09:57:58 +08:00
hos_func->fd_thread_status = 1;
pthread_join(hos_func->fd_thread, NULL);
}
2021-04-23 09:57:58 +08:00
if (hos_func->fs2_thread)
2020-10-20 17:20:27 +08:00
{
2021-04-23 09:57:58 +08:00
hos_func->fs2_status = HOS_FS2_STOP;
pthread_join(hos_func->fs2_thread, NULL);
for (i = 0; i < FS2_RECORD_EVENTS; i++)
2020-12-01 16:12:41 +08:00
{
2021-04-23 09:57:58 +08:00
screen_stat_handle_t *fs2_handle = &hos_func->fs2_info[i].fs2_handle;
2021-04-26 18:17:37 +08:00
if (*fs2_handle)
{
FS_stop(fs2_handle);
*fs2_handle = NULL;
}
2021-04-23 09:57:58 +08:00
if (hos_func->fs2_info[i].reserved)
2020-12-01 16:12:41 +08:00
{
if (i == 0)
{
2021-04-23 09:57:58 +08:00
data_info_t * data_info = (data_info_t *)hos_func->fs2_info[i].reserved;
2020-12-01 16:12:41 +08:00
if (data_info->rx_pkts)
free(data_info->rx_pkts);
if (data_info->rx_bytes)
free(data_info->rx_bytes);
if (data_info->tx_pkts)
free(data_info->tx_pkts);
if (data_info->tx_bytes)
free(data_info->tx_bytes);
2021-04-23 14:30:52 +08:00
if (data_info->tx_failed_bytes)
free(data_info->tx_failed_bytes);
if (data_info->tx_failed_pkts);
free(data_info->tx_failed_pkts);
if (data_info->cache)
free(data_info->cache);
}
2021-04-23 09:57:58 +08:00
free(hos_func->fs2_info[i].reserved);
2021-04-26 18:17:37 +08:00
hos_func->fs2_info[i].reserved = NULL;
2020-12-01 16:12:41 +08:00
}
2021-04-23 09:57:58 +08:00
if (hos_func->fs2_info[i].line_ids)
2021-04-26 18:17:37 +08:00
{
2021-04-23 09:57:58 +08:00
free(hos_func->fs2_info[i].line_ids);
2021-04-26 18:17:37 +08:00
hos_func->fs2_info[i].line_ids=NULL;
}
2021-04-23 09:57:58 +08:00
if (hos_func->fs2_info[i].column_ids)
2021-04-26 18:17:37 +08:00
{
2021-04-23 09:57:58 +08:00
free(hos_func->fs2_info[i].column_ids);
2021-04-26 18:17:37 +08:00
hos_func->fs2_info[i].column_ids=NULL;
}
2020-12-01 16:12:41 +08:00
}
}
2021-04-23 09:57:58 +08:00
delete g_hos_handle.S3Client;
g_hos_handle.S3Client = NULL;
MESA_handle_runtime_log(g_hos_handle.log, RLOG_LV_DEBUG, __FUNCTION__, "delete s3client.");
2020-12-01 16:34:33 +08:00
2021-04-23 14:30:52 +08:00
if (g_fd_info)
{
2021-04-23 14:30:52 +08:00
free(g_fd_info);
2021-04-26 18:17:37 +08:00
g_fd_info = NULL;
}
2021-04-23 09:57:58 +08:00
for (i = 0; i < hos_conf->thread_num; i++)
2020-12-01 16:12:41 +08:00
{
2021-04-23 14:30:52 +08:00
delete_all(&g_fd_context[i]);
2020-10-20 17:20:27 +08:00
}
2021-04-23 14:30:52 +08:00
if (g_fd_context)
{
2021-04-23 14:30:52 +08:00
free(g_fd_context);
2021-04-26 18:17:37 +08:00
g_fd_context = NULL;
}
Aws::ShutdownAPI(g_options);
2021-04-26 18:17:37 +08:00
MESA_destroy_runtime_log_handle(g_hos_handle.log);
g_hos_handle.log = NULL;
memset(&g_hos_handle, 0 , sizeof(g_hos_handle));
if (g_hos_instance.hos_url_prefix)
free((void *)g_hos_instance.hos_url_prefix);
2021-04-28 18:29:29 +08:00
memset(&g_hos_instance, 0, sizeof(g_hos_instance));
2020-11-23 11:01:49 +08:00
2020-09-21 19:19:18 +08:00
return HOS_CLIENT_OK;
2020-09-11 16:13:02 +08:00
}