From 88a8dccbd099b7077df2a7a236cd985c6cfe6c84 Mon Sep 17 00:00:00 2001 From: pengxuanzheng Date: Fri, 15 Oct 2021 14:23:18 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(TSG-8029):=20hos=20=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=20max=20position=20=E9=99=90=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hos_client.cpp | 29 +++++++++++++++++++---------- src/hos_client.h | 5 ++--- src/hos_common.h | 1 + 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/hos_client.cpp b/src/hos_client.cpp index fcd9742b..6fc5d0f7 100644 --- a/src/hos_client.cpp +++ b/src/hos_client.cpp @@ -69,14 +69,14 @@ static int hos_delete_fd(size_t fd, size_t thread_id) { free(context->bucket); context->bucket = NULL; - } - if (context->object) - { - free(context->object); - context->object = NULL; - } - free(context); - + } + if (context->object) + { + free(context->object); + context->object = NULL; + } + free(context); + return HOS_CLIENT_OK; } @@ -699,6 +699,7 @@ hos_instance hos_init_instance(const char *conf_path, const char *module, size_t MESA_load_profile_uint_def(conf_path, module, "hos_request_num", &hos_conf->max_request_num, 100); MESA_load_profile_uint_def(conf_path, module, "hos_request_context", &hos_conf->max_request_context, 10240000); MESA_load_profile_uint_def(conf_path, module, "hos_reconnect_time", &hos_conf->reconnection_time, 1); + MESA_load_profile_uint_def(conf_path, module, "hos_max_position", &hos_conf->max_position, 100000); if (strlen(hos_conf->ip) && hos_conf->port && strlen(hos_conf->accesskeyid) && strlen(hos_conf->secretkey)) { g_hos_handle.log = MESA_create_runtime_log_handle(hos_conf->log_path, hos_conf->log_level); @@ -957,6 +958,14 @@ int hos_write(size_t fd, const char *stream, size_t stream_len) return HOS_PARAMETER_ERROR; } + if (a_fd_context->position >= hos_conf->max_position) + { + MESA_HANDLE_RUNTIME_LOG(g_hos_handle.log, RLOG_LV_FATAL, + __FUNCTION__, "error: [%s%s/%s] upload times over max times[%d] ", + g_hos_instance.hos_url_prefix, a_fd_context->bucket, a_fd_context->object, hos_conf->max_position); + + return HOS_FD_OVER_POSITION; + } // create and configure the asynchronous put object request. Aws::S3::Model::PutObjectRequest request; @@ -993,7 +1002,7 @@ int hos_write(size_t fd, const char *stream, size_t stream_len) request.SetBody(a_fd_context->cache); // add headers - atomic_add(&(a_fd_context->position), 100001); + atomic_add(&(a_fd_context->position), 1); snprintf(num, 128, "%lu", atomic_read(&(a_fd_context->position))); Aws::Map headers; headers["x-hos-upload-type"] = "append"; @@ -1073,7 +1082,7 @@ int hos_close_fd(size_t fd) request.SetBody(a_fd_context->cache); // add headers - atomic_add(&(a_fd_context->position), 100001); + atomic_add(&(a_fd_context->position), 1); snprintf(num, 128, "%lu", atomic_read(&(a_fd_context->position))); Aws::Map headers; headers["x-hos-upload-type"] = "append"; diff --git a/src/hos_client.h b/src/hos_client.h index 713fd51c..21d3fb37 100644 --- a/src/hos_client.h +++ b/src/hos_client.h @@ -29,7 +29,7 @@ enum hoserrors HOS_BUCKET_NOT_EXIST = -8, HOS_INSTANCE_NOT_INIT = -9, HOS_INSTANCE_NOT_ENABLE = -10, - + HOS_FD_OVER_POSITION = -11, }; /* s3 的错误码 */ @@ -142,9 +142,8 @@ long hos_open_fd(const char *bucket, const char *object, put_finished_callback c *************************************************************************************/ int hos_write(size_t fd, const char *stream, size_t stream_len); /************************************************************************************* - * 函数名: hos_close_fd + * 函数名: hos_disable_fd * 参数: size_t fd fd - * size_t thread_id 线程ID * 返回值 int 成功返回0,失败返回hoserros错误码 *************************************************************************************/ int hos_close_fd(size_t fd); diff --git a/src/hos_common.h b/src/hos_common.h index f4829919..54842cf0 100644 --- a/src/hos_common.h +++ b/src/hos_common.h @@ -84,6 +84,7 @@ typedef struct hos_config_s uint32_t max_request_num; uint32_t max_request_context; uint32_t reconnection_time; + uint32_t max_position; }hos_config_t; typedef struct hos_func_thread_s