【1】修复HTTP Expect头部缺失时POST卡顿的问题;
【2】TODO:尝试增加multiple delete objects API,尚未成功(AccessDenied);
This commit is contained in:
91
cache/tango_cache_client.cpp
vendored
91
cache/tango_cache_client.cpp
vendored
@@ -9,16 +9,34 @@
|
||||
#include <time.h>
|
||||
#include <string.h>
|
||||
#include <openssl/sha.h>
|
||||
#include <openssl/md5.h>
|
||||
|
||||
#include <MESA/MESA_prof_load.h>
|
||||
|
||||
#include "tango_cache_client_in.h"
|
||||
#include "tango_cache_transfer.h"
|
||||
#include "tango_cache_tools.h"
|
||||
#include "tango_cache_xml.h"
|
||||
|
||||
int TANGO_CACHE_VERSION_20180925=0;
|
||||
int TANGO_CACHE_VERSION_20181009=0;
|
||||
|
||||
static void caculate_sha256(const char *data, unsigned long len, char *result, u_int32_t size)
|
||||
static int caculate_base64_md5(const char *data, unsigned long len, unsigned char *result, unsigned int size)
|
||||
{
|
||||
MD5_CTX c;
|
||||
unsigned char md5[17]={0};
|
||||
|
||||
if(size < 33)
|
||||
return -1;
|
||||
|
||||
MD5_Init(&c);
|
||||
MD5_Update(&c, data, len);
|
||||
MD5_Final(md5, &c);
|
||||
|
||||
Base64_EncodeBlock(md5, 16, result);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void caculate_sha256(const char *data, unsigned long len, char *result, u_int32_t size)
|
||||
{
|
||||
SHA256_CTX c;
|
||||
unsigned char sha256[128];
|
||||
@@ -101,12 +119,12 @@ void tango_cache_get_object_path(const struct tango_cache_ctx *ctx, char *path,
|
||||
snprintf(path, pathsize, "http://%s/%s/%s", ctx->hostaddr, ctx->instance->bucketname, ctx->object_key);
|
||||
}
|
||||
|
||||
static void update_statistics(enum CACHE_REQUEST_METHOD method, bool fail_state, enum CACHE_ERR_CODE error_code, struct cache_statistics *statistic)
|
||||
static void update_statistics(struct tango_cache_ctx *ctx, struct cache_statistics *statistic)
|
||||
{
|
||||
switch(method)
|
||||
switch(ctx->method)
|
||||
{
|
||||
case CACHE_REQUEST_PUT:
|
||||
if(fail_state)
|
||||
if(ctx->fail_state)
|
||||
{
|
||||
statistic->put_error_num += 1;
|
||||
}
|
||||
@@ -116,9 +134,9 @@ static void update_statistics(enum CACHE_REQUEST_METHOD method, bool fail_state,
|
||||
}
|
||||
break;
|
||||
case CACHE_REQUEST_GET:
|
||||
if(fail_state)
|
||||
if(ctx->fail_state)
|
||||
{
|
||||
if(error_code == CACHE_ERR_CURL)
|
||||
if(ctx->error_code == CACHE_ERR_CURL)
|
||||
statistic->get_error_num += 1;
|
||||
else
|
||||
statistic->get_miss_num += 1;
|
||||
@@ -129,7 +147,7 @@ static void update_statistics(enum CACHE_REQUEST_METHOD method, bool fail_state,
|
||||
}
|
||||
break;
|
||||
case CACHE_REQUEST_DELETE:
|
||||
if(fail_state)
|
||||
if(ctx->fail_state)
|
||||
{
|
||||
statistic->del_error_num += 1;
|
||||
}
|
||||
@@ -138,6 +156,10 @@ static void update_statistics(enum CACHE_REQUEST_METHOD method, bool fail_state,
|
||||
statistic->del_succ_num += 1;
|
||||
}
|
||||
break;
|
||||
case CACHE_REQUEST_DELETE_MUL:
|
||||
statistic->del_succ_num += ctx->del.succ_num;
|
||||
statistic->del_error_num += ctx->del.fail_num;
|
||||
break;
|
||||
default:break;
|
||||
}
|
||||
}
|
||||
@@ -185,7 +207,6 @@ void tango_cache_ctx_destroy(struct tango_cache_ctx *ctx)
|
||||
case CACHE_REQUEST_PUT:
|
||||
if(ctx->put.uploadID != NULL) free(ctx->put.uploadID);
|
||||
if(ctx->put.combine_xml != NULL) free(ctx->put.combine_xml);
|
||||
if(ctx->headers != NULL) curl_slist_free_all(ctx->headers);
|
||||
if(ctx->put.evbuf!=NULL)
|
||||
{
|
||||
ctx->instance->statistic.memory_used -= evbuffer_get_length(ctx->put.evbuf);
|
||||
@@ -197,6 +218,11 @@ void tango_cache_ctx_destroy(struct tango_cache_ctx *ctx)
|
||||
free(etag->etag);
|
||||
free(etag);
|
||||
}//no break here
|
||||
case CACHE_REQUEST_DELETE_MUL:
|
||||
if(ctx->headers != NULL)
|
||||
{
|
||||
curl_slist_free_all(ctx->headers);
|
||||
}//no break here
|
||||
case CACHE_REQUEST_DELETE:
|
||||
if(ctx->future != NULL)
|
||||
{
|
||||
@@ -212,7 +238,7 @@ void tango_cache_ctx_destroy(struct tango_cache_ctx *ctx)
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
update_statistics(ctx->method, ctx->fail_state, ctx->error_code, &ctx->instance->statistic);
|
||||
update_statistics(ctx, &ctx->instance->statistic);
|
||||
free(ctx);
|
||||
}
|
||||
|
||||
@@ -333,7 +359,7 @@ struct tango_cache_ctx *tango_cache_update_prepare(struct tango_cache_instance *
|
||||
{
|
||||
ctx->headers = curl_slist_append(ctx->headers, "Content-Type:");
|
||||
}
|
||||
//ctx->headers = curl_slist_append(ctx->headers, "Expect:"); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӣ<EFBFBD>curl_multi_socket_action<EFBFBD>Ῠס
|
||||
ctx->headers = curl_slist_append(ctx->headers, "Expect:");//ע<EFBFBD><EFBFBD>POST<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Expect<EFBFBD><EFBFBD>ϵ<EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD>ȷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>CURLOPT_POSTFIELDSIZE
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD>GETʱ<54><CAB1>ԭ<EFBFBD><D4AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
if(meta->usertag_len>0 && meta->usertag_len<=USER_TAG_MAX_LEN)
|
||||
{
|
||||
@@ -484,6 +510,46 @@ int tango_cache_delete_object(struct tango_cache_instance *instance, struct futu
|
||||
return (cache_delete_minio_object(ctx)==1)?0:-1;
|
||||
}
|
||||
|
||||
struct tango_cache_ctx *tango_cache_multi_delete_prepare(struct tango_cache_instance *instance, struct future* future, char *objlist[], u_int32_t num)
|
||||
{
|
||||
struct tango_cache_ctx *ctx;
|
||||
char md5[48]={0}, content_md5[48];
|
||||
|
||||
ctx = (struct tango_cache_ctx *)calloc(1, sizeof(struct tango_cache_ctx));
|
||||
ctx->instance = instance;
|
||||
ctx->future = future;
|
||||
ctx->method = CACHE_REQUEST_DELETE_MUL;
|
||||
ctx->del.succ_num = num;
|
||||
|
||||
if(wired_load_balancer_lookup(instance->wiredlb, objlist[0], strlen(objlist[0]), ctx->hostaddr, 48))
|
||||
{
|
||||
instance->error_code = CACHE_ERR_WIREDLB;
|
||||
instance->statistic.totaldrop_num += num;
|
||||
free(ctx);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
construct_multiple_delete_xml(ctx->instance->bucketname, objlist, num, instance->hash_object_key, &ctx->response.buff, &ctx->response.size);
|
||||
caculate_base64_md5(ctx->response.buff, ctx->response.size, (unsigned char *)md5, 48);
|
||||
sprintf(content_md5, "Content-MD5: %s", md5);
|
||||
ctx->headers = curl_slist_append(ctx->headers, content_md5);
|
||||
ctx->headers = curl_slist_append(ctx->headers, "Content-Type: application/xml");
|
||||
return ctx;
|
||||
}
|
||||
|
||||
//TODO: AccessDenied
|
||||
int tango_cache_multi_delete(struct tango_cache_instance *instance, struct future* future, char *objlist[], u_int32_t num)
|
||||
{
|
||||
struct tango_cache_ctx *ctx;
|
||||
|
||||
ctx = tango_cache_multi_delete_prepare(instance, future, objlist, num);
|
||||
if(ctx == NULL)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return tango_cache_multi_delete_start(ctx);
|
||||
}
|
||||
|
||||
static void check_multi_info(CURLM *multi)
|
||||
{
|
||||
CURLMsg *msg;
|
||||
@@ -520,6 +586,9 @@ static void check_multi_info(CURLM *multi)
|
||||
case CACHE_REQUEST_DELETE:
|
||||
tango_cache_curl_del_done(ctx, res, res_code);
|
||||
break;
|
||||
case CACHE_REQUEST_DELETE_MUL:
|
||||
tango_cache_curl_muldel_done(ctx, res, res_code);
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user