summaryrefslogtreecommitdiff
path: root/plugin/business/pangu-http/src/pangu_web_cache.cpp
diff options
context:
space:
mode:
authorzhengchao <[email protected]>2018-11-25 14:14:42 +0800
committerzhengchao <[email protected]>2018-11-25 14:14:42 +0800
commita4bffe353b7dec866dabd2506fdbba31453e7b6c (patch)
tree6c2d815e13c55a50c7b28341b6625064ce5806a8 /plugin/business/pangu-http/src/pangu_web_cache.cpp
parentb53107e2983fe289a5c9e01077b7f7acfe8676a9 (diff)
业务层适配缓存上传取消。
Diffstat (limited to 'plugin/business/pangu-http/src/pangu_web_cache.cpp')
-rw-r--r--plugin/business/pangu-http/src/pangu_web_cache.cpp18
1 files changed, 17 insertions, 1 deletions
diff --git a/plugin/business/pangu-http/src/pangu_web_cache.cpp b/plugin/business/pangu-http/src/pangu_web_cache.cpp
index 5f7ff0d..21c8800 100644
--- a/plugin/business/pangu-http/src/pangu_web_cache.cpp
+++ b/plugin/business/pangu-http/src/pangu_web_cache.cpp
@@ -43,6 +43,7 @@ enum cache_stat_field
STAT_CACHE_UPLOAD_OVERRIDE,
STAT_CACHE_UPLOAD_FORBIDEN,
STAT_CACHE_UPLOAD_ABANDON,
+ STAT_CAHCE_UPLOAD_CANCEL,
STAT_CACHE_UPLOAD_ERR,
STAT_CACHE_UPLOAD_BYTES,
STAT_CACHE_UPLOADING,
@@ -126,6 +127,8 @@ struct cache_update_context
{
struct cache_handle* ref_cache_handle;
struct tango_cache_ctx * write_ctx;
+ size_t content_len;
+ size_t uploaded_len;
};
static void web_cache_stat_cb(evutil_socket_t fd, short what, void * arg)
{
@@ -233,6 +236,8 @@ const char* statsd_server_ip, int statsd_server_port, const char*histogram_bins)
set_stat_spec(&spec[STAT_CACHE_UPLOAD_OVERRIDE], "or_put",FS_STYLE_FIELD, FS_CALC_CURRENT);
set_stat_spec(&spec[STAT_CACHE_UPLOAD_FORBIDEN], "put_forbid",FS_STYLE_FIELD, FS_CALC_CURRENT);
set_stat_spec(&spec[STAT_CACHE_UPLOAD_ABANDON], "put_abandon",FS_STYLE_FIELD, FS_CALC_CURRENT);
+ set_stat_spec(&spec[STAT_CACHE_UPLOADING], "put_cancel",FS_STYLE_FIELD, FS_CALC_CURRENT);
+
set_stat_spec(&spec[STAT_CACHE_UPLOAD_ERR], "put_err",FS_STYLE_STATUS, FS_CALC_CURRENT);
set_stat_spec(&spec[STAT_CACHE_UPLOAD_BYTES], "put(MB)",FS_STYLE_FIELD, FS_CALC_CURRENT);
set_stat_spec(&spec[STAT_CACHE_UPLOADING], "putting",FS_STYLE_STATUS, FS_CALC_CURRENT);
@@ -1323,19 +1328,30 @@ struct cache_update_context* web_cache_update_start(struct cache_handle* handle,
update_ctx=ALLOC(struct cache_update_context, 1);
update_ctx->write_ctx=write_ctx;
update_ctx->ref_cache_handle=handle;
+ update_ctx->content_len=content_len;
+ update_ctx->uploaded_len=0;
return update_ctx;
}
void web_cache_update(struct cache_update_context* ctx, const unsigned char * body_frag, size_t frag_size)
{
tango_cache_update_frag_data(ctx->write_ctx, (const char*)body_frag, frag_size);
+ ctx->uploaded_len+=frag_size;
ATOMIC_ADD(&(ctx->ref_cache_handle->stat_val[STAT_CACHE_UPLOAD_BYTES]), frag_size);
return;
}
void web_cache_update_end(struct cache_update_context* ctx)
{
- tango_cache_update_end(ctx->write_ctx);
+ if(ctx->uploaded_len==ctx->content_len)
+ {
+ tango_cache_update_end(ctx->write_ctx);
+ }
+ else
+ {
+ tango_cache_update_cancel(ctx->write_ctx);
+ ATOMIC_INC(&(ctx->ref_cache_handle->stat_val[STAT_CACHE_UPLOADING]));
+ }
ATOMIC_DEC(&(ctx->ref_cache_handle->stat_val[STAT_CACHE_UPLOADING]));
ctx->write_ctx = NULL;