修改GET/PUT对外接口;cache miss不算fail;
This commit is contained in:
14
cache/include/cache_evbase_client.h
vendored
14
cache/include/cache_evbase_client.h
vendored
@@ -33,24 +33,24 @@ struct cache_evbase_instance *cache_evbase_instance_new(const char* profile_path
|
||||
|
||||
|
||||
//GET<45>ӿڣ<D3BF><DAA3>ɹ<EFBFBD><C9B9><EFBFBD><EFBFBD><EFBFBD>0<EFBFBD><30>ʧ<EFBFBD>ܷ<EFBFBD><DCB7><EFBFBD>-1<><31>future<72>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD><DFB3><EFBFBD>ִ<EFBFBD>У<EFBFBD><D0A3><EFBFBD>ͬ
|
||||
int cache_evbase_fetch_object(struct cache_evbase_instance *instance, struct future* future, struct tango_cache_meta *meta);
|
||||
int cache_evbase_fetch_object(struct cache_evbase_instance *instance, struct future* f, struct tango_cache_meta_get *meta);
|
||||
struct tango_cache_result *cache_evbase_read_result(void *promise_result);
|
||||
|
||||
//DELETE<54>ӿ<EFBFBD>
|
||||
int cache_evbase_delete_object(struct cache_evbase_instance *instance, struct future* future, const char *objkey);
|
||||
int cache_evbase_delete_object(struct cache_evbase_instance *instance, struct future* f, const char *objkey);
|
||||
|
||||
//һ<><D2BB><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD><CFB4>ӿ<EFBFBD>
|
||||
int cache_evbase_upload_once_data(struct cache_evbase_instance *instance, struct future* future,
|
||||
int cache_evbase_upload_once_data(struct cache_evbase_instance *instance, struct future* f,
|
||||
enum PUT_MEMORY_COPY_WAY way, const char *data, size_t size,
|
||||
struct tango_cache_meta *meta,
|
||||
struct tango_cache_meta_put *meta,
|
||||
char *path/*OUT*/, size_t pathsize);
|
||||
int cache_evbase_upload_once_evbuf(struct cache_evbase_instance *instance, struct future* future,
|
||||
int cache_evbase_upload_once_evbuf(struct cache_evbase_instance *instance, struct future* f,
|
||||
struct evbuffer *evbuf,
|
||||
struct tango_cache_meta *meta,
|
||||
struct tango_cache_meta_put *meta,
|
||||
char *path/*OUT*/, size_t pathsize);
|
||||
|
||||
//<2F><>ʽ<EFBFBD>ϴ<EFBFBD><CFB4>ӿ<EFBFBD>
|
||||
struct cache_evbase_ctx *cache_evbase_update_start(struct cache_evbase_instance *instance, struct future* future, struct tango_cache_meta *meta);
|
||||
struct cache_evbase_ctx *cache_evbase_update_start(struct cache_evbase_instance *instance, struct future* f, struct tango_cache_meta_put *meta);
|
||||
int cache_evbase_update_frag_data(struct cache_evbase_ctx *ctx_asyn, enum PUT_MEMORY_COPY_WAY way, const char *data, size_t size);
|
||||
int cache_evbase_update_frag_evbuf(struct cache_evbase_ctx *ctx_asyn, struct evbuffer *evbuf);
|
||||
void cache_evbase_update_end(struct cache_evbase_ctx *ctx_asyn);
|
||||
|
||||
42
cache/include/tango_cache_client.h
vendored
42
cache/include/tango_cache_client.h
vendored
@@ -43,7 +43,7 @@ struct cache_statistics
|
||||
long long put_error_num;//UPLOADʧ<44>ܵĴ<DCB5><C4B4><EFBFBD>
|
||||
long long del_recv_num; //<2F><><EFBFBD><EFBFBD>DELETE<54>Ĵ<EFBFBD><C4B4><EFBFBD>
|
||||
long long del_succ_num; //DELETE<54>ɹ<EFBFBD><C9B9>Ĵ<EFBFBD><C4B4><EFBFBD>
|
||||
long long del_error_num;//DELETE<EFBFBD>ɹ<EFBFBD><EFBFBD>Ĵ<EFBFBD><EFBFBD><EFBFBD>
|
||||
long long del_error_num;//DELETEʧ<EFBFBD>ܵĴ<EFBFBD><EFBFBD><EFBFBD>
|
||||
long long totaldrop_num;//<2F>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD>Լ<EFBFBD>WiredLB<4C><42><EFBFBD><EFBFBD>ʱDROP<4F>Ĵ<EFBFBD><C4B4><EFBFBD>
|
||||
long long memory_used; //<2F><>ǰUPLOAD BODY<44><59>ռ<EFBFBD>ڴ<EFBFBD><DAB4><EFBFBD>С
|
||||
long long session_num; //<2F><>ǰ<EFBFBD><C7B0><EFBFBD>ڽ<EFBFBD><DABD><EFBFBD>GET/PUT<55><54>HTTP<54>Ự<EFBFBD><E1BBB0>
|
||||
@@ -51,16 +51,19 @@ struct cache_statistics
|
||||
|
||||
enum CACHE_RESULT_TYPE
|
||||
{
|
||||
RESULT_TYPE_HEADER=0, //ֻ<><D6BB><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>
|
||||
RESULT_TYPE_USERTAG, //ֻ<><D6BB><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>
|
||||
RESULT_TYPE_HEADER=0, //<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD>
|
||||
RESULT_TYPE_USERTAG, //<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD>
|
||||
RESULT_TYPE_BODY, //<2F><><EFBFBD>ܵ<EFBFBD><DCB5>ö<EFBFBD><C3B6><EFBFBD>
|
||||
RESULT_TYPE_END, //ȫ<><C8AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֻ<EFBFBD><D6BB><EFBFBD><EFBFBD>һ<EFBFBD>Σ<EFBFBD><CEA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
RESULT_TYPE_MISS, //<2F><><EFBFBD><EFBFBD>δ<EFBFBD><CEB4><EFBFBD>У<EFBFBD><D0A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͻ<EFBFBD><CDBB>⣬ֻ<E2A3AC><D6BB><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>(<28><>END֮<44><D6AE>)<29><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
};
|
||||
|
||||
//promise_success<73>Ľ<EFBFBD><C4BD><EFBFBD>result
|
||||
struct tango_cache_result
|
||||
{
|
||||
const void *data_frag; //<2F><><EFBFBD><EFBFBD>typeΪRESULT_TYPE_HEADER<45><52>ÿ<EFBFBD><C3BF>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(HTTP1.1<EFBFBD><EFBFBD>ʽ)
|
||||
const char *data_frag; //<2F><><EFBFBD><EFBFBD>typeΪRESULT_TYPE_HEADER<45><52>ÿ<EFBFBD><C3BF>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(HTTP1.1<EFBFBD><EFBFBD>ʽ)
|
||||
size_t size;
|
||||
size_t tlength; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܳ<EFBFBD><DCB3>ȣ<EFBFBD><C8A3>ص<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>Ч
|
||||
enum CACHE_RESULT_TYPE type;
|
||||
};
|
||||
|
||||
@@ -74,16 +77,19 @@ enum CACHE_HTTP_HDR_TYPE
|
||||
HDR_CONTENT_NUM,
|
||||
};
|
||||
|
||||
struct tango_cache_meta
|
||||
struct tango_cache_meta_get
|
||||
{
|
||||
const char* url; //<2F><><EFBFBD><EFBFBD>:URL<52><4C><EFBFBD>ǽṹ<C7BD><E1B9B9><EFBFBD><EFBFBD>־:<3A>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>256<35>ֽ<EFBFBD>
|
||||
struct request_freshness get;
|
||||
};
|
||||
|
||||
struct tango_cache_meta_put
|
||||
{
|
||||
const char* url;
|
||||
const char* std_hdr[HDR_CONTENT_NUM]; //<2F><><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"Content-Type: text/html"<22><><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD>NULL<4C><4C>ʾû<CABE>и<EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD>
|
||||
const char* usertag; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD>GETʱ<54><CAB1>ԭ<EFBFBD><D4AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
size_t usertag_len; //<2F><><EFBFBD><EFBFBD>USER_TAG_MAX_LEN<45><4E>0<EFBFBD><30>ʾû<CABE>и<EFBFBD>ͷ<EFBFBD><CDB7>
|
||||
union{
|
||||
struct response_freshness put;
|
||||
struct request_freshness get;
|
||||
};
|
||||
struct response_freshness put;
|
||||
};
|
||||
|
||||
struct tango_cache_instance;
|
||||
@@ -102,16 +108,16 @@ struct tango_cache_instance *tango_cache_instance_new(struct event_base* evbase,
|
||||
|
||||
|
||||
/* GET<45>ӿڵ<D3BF>API*/
|
||||
//<2F>ɹ<EFBFBD>ʱ<EFBFBD>ص<EFBFBD>promise_success, resultΪNULLʱ<4C><CAB1>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
//<2F>ɹ<EFBFBD>ʱ<EFBFBD>ص<EFBFBD>promise_success
|
||||
//ʧ<><CAA7>ʱ<EFBFBD>ص<EFBFBD>promise_failed(<28><>һ<EFBFBD><D2BB>)<29><>ʹ<EFBFBD><CAB9>get_last_error<6F><72>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD>룻
|
||||
//future<72><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ΪNULL
|
||||
int tango_cache_fetch_object(struct tango_cache_instance *instance, struct future* f, struct tango_cache_meta *meta);
|
||||
int tango_cache_fetch_object(struct tango_cache_instance *instance, struct future* f, struct tango_cache_meta_get *meta);
|
||||
//<2F><>promise_success<73><73>result<6C><74><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
|
||||
struct tango_cache_result *tango_cache_read_result(future_result_t *result);
|
||||
struct tango_cache_result *tango_cache_read_result(void *promise_result);
|
||||
|
||||
|
||||
/* DELETE<54>ӿڵ<D3BF>API*/
|
||||
int tango_cache_delete_object(struct tango_cache_instance *instance, struct future* future, const char *objkey);
|
||||
int tango_cache_delete_object(struct tango_cache_instance *instance, struct future* f, const char *objkey);
|
||||
|
||||
|
||||
/* UPLOAD<41>ӿڵ<D3BF>API
|
||||
@@ -121,17 +127,17 @@ int tango_cache_delete_object(struct tango_cache_instance *instance, struct futu
|
||||
/*<2A><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ϴ<EFBFBD>API*/
|
||||
//<2F><>path<74><68>Ϊ<EFBFBD>գ<EFBFBD><D5A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĵ洢·<E6B4A2><C2B7>
|
||||
//<2F><><EFBFBD><EFBFBD>ֵ: 0-<2D>ɹ<EFBFBD><C9B9><EFBFBD><0ʧ<30>ܣ<EFBFBD><DCA3><EFBFBD>ͬ
|
||||
int tango_cache_upload_once_data(struct tango_cache_instance *instance, struct future* future,
|
||||
int tango_cache_upload_once_data(struct tango_cache_instance *instance, struct future* f,
|
||||
enum PUT_MEMORY_COPY_WAY way, const char *data, size_t size,
|
||||
struct tango_cache_meta *meta,
|
||||
struct tango_cache_meta_put *meta,
|
||||
char *path/*OUT*/, size_t pathsize);
|
||||
int tango_cache_upload_once_evbuf(struct tango_cache_instance *instance, struct future* future,
|
||||
int tango_cache_upload_once_evbuf(struct tango_cache_instance *instance, struct future* f,
|
||||
enum EVBUFFER_COPY_WAY way, struct evbuffer *evbuf,
|
||||
struct tango_cache_meta *meta,
|
||||
struct tango_cache_meta_put *meta,
|
||||
char *path/*OUT*/, size_t pathsize);
|
||||
/*<2A><>ʽ<EFBFBD>ϴ<EFBFBD>API*/
|
||||
//<2F><><EFBFBD><EFBFBD>ֵ: <20><>ΪNULL<4C><4C><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD><DCA3><EFBFBD><EFBFBD><EFBFBD>tango_cache_ctx_error<6F>鿴<EFBFBD><E9BFB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD>CACHE_OUTOF_MEMORY(<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>)<29><>
|
||||
struct tango_cache_ctx *tango_cache_update_start(struct tango_cache_instance *instance, struct future* future, struct tango_cache_meta *meta);
|
||||
struct tango_cache_ctx *tango_cache_update_start(struct tango_cache_instance *instance, struct future* f, struct tango_cache_meta_put *meta);
|
||||
//<2F><><EFBFBD><EFBFBD>ֵ: 0-<2D>ɹ<EFBFBD><C9B9><EFBFBD><0ʧ<30>ܣ<EFBFBD><DCA3><EFBFBD><EFBFBD><EFBFBD>tango_cache_get_last_error<6F>鿴<EFBFBD><E9BFB4><EFBFBD><EFBFBD><EFBFBD>룻
|
||||
int tango_cache_update_frag_data(struct tango_cache_ctx *ctx, const char *data, size_t size);
|
||||
int tango_cache_update_frag_evbuf(struct tango_cache_ctx *ctx, enum EVBUFFER_COPY_WAY way, struct evbuffer *evbuf);
|
||||
|
||||
30
cache/src/cache_evbase_client.cpp
vendored
30
cache/src/cache_evbase_client.cpp
vendored
@@ -325,13 +325,13 @@ int cache_evbase_update_frag_evbuf(struct cache_evbase_ctx *ctx_asyn, struct evb
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct cache_evbase_ctx *cache_evbase_update_start(struct cache_evbase_instance *instance, struct future* future, struct tango_cache_meta *meta)
|
||||
struct cache_evbase_ctx *cache_evbase_update_start(struct cache_evbase_instance *instance, struct future* f, struct tango_cache_meta_put *meta)
|
||||
{
|
||||
struct cache_evbase_ctx *ctx_asyn;
|
||||
struct tango_cache_ctx *ctx;
|
||||
struct databuffer *buffer;
|
||||
|
||||
ctx = tango_cache_update_prepare(instance->instance, future, meta);
|
||||
ctx = tango_cache_update_prepare(instance->instance, f, meta);
|
||||
if(ctx == NULL)
|
||||
{
|
||||
return NULL;
|
||||
@@ -357,14 +357,14 @@ struct cache_evbase_ctx *cache_evbase_update_start(struct cache_evbase_instance
|
||||
return ctx_asyn;
|
||||
}
|
||||
|
||||
int cache_evbase_upload_once_data(struct cache_evbase_instance *instance, struct future* future,
|
||||
enum PUT_MEMORY_COPY_WAY way, const char *data, size_t size, struct tango_cache_meta *meta, char *path, size_t pathsize)
|
||||
int cache_evbase_upload_once_data(struct cache_evbase_instance *instance, struct future* f,
|
||||
enum PUT_MEMORY_COPY_WAY way, const char *data, size_t size, struct tango_cache_meta_put *meta, char *path, size_t pathsize)
|
||||
{
|
||||
struct cache_evbase_ctx *ctx_asyn;
|
||||
struct tango_cache_ctx *ctx;
|
||||
struct databuffer *buffer;
|
||||
|
||||
ctx = tango_cache_update_prepare(instance->instance, future, meta);
|
||||
ctx = tango_cache_update_prepare(instance->instance, f, meta);
|
||||
if(ctx == NULL)
|
||||
{
|
||||
return -1;
|
||||
@@ -404,14 +404,14 @@ int cache_evbase_upload_once_data(struct cache_evbase_instance *instance, struct
|
||||
return 0;
|
||||
}
|
||||
|
||||
int cache_evbase_upload_once_evbuf(struct cache_evbase_instance *instance, struct future* future,
|
||||
struct evbuffer *evbuf, struct tango_cache_meta *meta, char *path, size_t pathsize)
|
||||
int cache_evbase_upload_once_evbuf(struct cache_evbase_instance *instance, struct future* f,
|
||||
struct evbuffer *evbuf, struct tango_cache_meta_put *meta, char *path, size_t pathsize)
|
||||
{
|
||||
struct cache_evbase_ctx *ctx_asyn;
|
||||
struct tango_cache_ctx *ctx;
|
||||
struct databuffer *buffer;
|
||||
|
||||
ctx = tango_cache_update_prepare(instance->instance, future, meta);
|
||||
ctx = tango_cache_update_prepare(instance->instance, f, meta);
|
||||
if(ctx == NULL)
|
||||
{
|
||||
return -1;
|
||||
@@ -443,14 +443,14 @@ int cache_evbase_upload_once_evbuf(struct cache_evbase_instance *instance, struc
|
||||
return 0;
|
||||
}
|
||||
|
||||
int cache_evbase_fetch_object(struct cache_evbase_instance *instance, struct future* future, struct tango_cache_meta *meta)
|
||||
int cache_evbase_fetch_object(struct cache_evbase_instance *instance, struct future* f, struct tango_cache_meta_get *meta)
|
||||
{
|
||||
struct cache_evbase_ctx *ctx_asyn;
|
||||
struct databuffer *buffer;
|
||||
|
||||
ctx_asyn = (struct cache_evbase_ctx *)calloc(1, sizeof(struct cache_evbase_ctx));
|
||||
ctx_asyn->instance_asyn = instance;
|
||||
ctx_asyn->ctx = tango_cache_fetch_prepare(instance->instance, future, meta);
|
||||
ctx_asyn->ctx = tango_cache_fetch_prepare(instance->instance, f, meta);
|
||||
if(ctx_asyn->ctx == NULL)
|
||||
{
|
||||
free(ctx_asyn);
|
||||
@@ -464,7 +464,7 @@ int cache_evbase_fetch_object(struct cache_evbase_instance *instance, struct fut
|
||||
if(iothread_notify_event(instance->notify_sendfd, &buffer, sizeof(void *), 2) != sizeof(void *))
|
||||
{
|
||||
tango_cache_set_fail_state(ctx_asyn->ctx, CACHE_ERR_SOCKPAIR);
|
||||
promise_failed(future_to_promise(future), FUTURE_ERROR_CANCEL, tango_cache_get_errstring(ctx_asyn->ctx));
|
||||
promise_failed(future_to_promise(f), FUTURE_ERROR_CANCEL, tango_cache_get_errstring(ctx_asyn->ctx));
|
||||
tango_cache_ctx_destroy(ctx_asyn->ctx);
|
||||
cache_asyn_ctx_destroy(ctx_asyn);
|
||||
free(buffer);
|
||||
@@ -473,14 +473,14 @@ int cache_evbase_fetch_object(struct cache_evbase_instance *instance, struct fut
|
||||
return 0;
|
||||
}
|
||||
|
||||
int cache_evbase_delete_object(struct cache_evbase_instance *instance, struct future* future, const char *objkey)
|
||||
int cache_evbase_delete_object(struct cache_evbase_instance *instance, struct future* f, const char *objkey)
|
||||
{
|
||||
struct cache_evbase_ctx *ctx_asyn;
|
||||
struct databuffer *buffer;
|
||||
|
||||
ctx_asyn = (struct cache_evbase_ctx *)calloc(1, sizeof(struct cache_evbase_ctx));
|
||||
ctx_asyn->instance_asyn = instance;
|
||||
ctx_asyn->ctx = tango_cache_delete_prepare(instance->instance, future, objkey);
|
||||
ctx_asyn->ctx = tango_cache_delete_prepare(instance->instance, f, objkey);
|
||||
if(ctx_asyn->ctx == NULL)
|
||||
{
|
||||
free(ctx_asyn);
|
||||
@@ -495,9 +495,9 @@ int cache_evbase_delete_object(struct cache_evbase_instance *instance, struct fu
|
||||
if(iothread_notify_event(instance->notify_sendfd, &buffer, sizeof(void *), 2) != sizeof(void *))
|
||||
{
|
||||
tango_cache_set_fail_state(ctx_asyn->ctx, CACHE_ERR_SOCKPAIR);
|
||||
if(future != NULL)
|
||||
if(f != NULL)
|
||||
{
|
||||
promise_failed(future_to_promise(future), FUTURE_ERROR_CANCEL, tango_cache_get_errstring(ctx_asyn->ctx));
|
||||
promise_failed(future_to_promise(f), FUTURE_ERROR_CANCEL, tango_cache_get_errstring(ctx_asyn->ctx));
|
||||
}
|
||||
tango_cache_ctx_destroy(ctx_asyn->ctx);
|
||||
cache_asyn_ctx_destroy(ctx_asyn);
|
||||
|
||||
56
cache/src/tango_cache_client.cpp
vendored
56
cache/src/tango_cache_client.cpp
vendored
@@ -87,7 +87,7 @@ const char *tango_cache_get_errstring(const struct tango_cache_ctx *ctx)
|
||||
case CACHE_OUTOF_MEMORY:return "outof memory";
|
||||
case CACHE_ERR_WIREDLB: return "wiredlb error";
|
||||
case CACHE_ERR_SOCKPAIR:return "socketpair error";
|
||||
case CACHE_ERR_INTERNAL:return "cache Expires or x-amz-meta-lm not found";
|
||||
case CACHE_ERR_INTERNAL:return "internal error";
|
||||
default: return ctx->error;
|
||||
}
|
||||
}
|
||||
@@ -136,10 +136,10 @@ static void update_statistics(struct tango_cache_ctx *ctx, struct cache_statisti
|
||||
case CACHE_REQUEST_GET:
|
||||
if(ctx->fail_state)
|
||||
{
|
||||
if(ctx->error_code == CACHE_ERR_CURL)
|
||||
statistic->get_error_num += 1;
|
||||
else
|
||||
if(ctx->error_code == CACHE_CACHE_MISS || ctx->error_code == CACHE_TIMEOUT)
|
||||
statistic->get_miss_num += 1;
|
||||
else
|
||||
statistic->get_error_num += 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -297,7 +297,7 @@ int tango_cache_update_frag_evbuf(struct tango_cache_ctx *ctx, enum EVBUFFER_COP
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct tango_cache_ctx *tango_cache_update_prepare(struct tango_cache_instance *instance, struct future* future, struct tango_cache_meta *meta)
|
||||
struct tango_cache_ctx *tango_cache_update_prepare(struct tango_cache_instance *instance, struct future* f, struct tango_cache_meta_put *meta)
|
||||
{
|
||||
struct tango_cache_ctx *ctx;
|
||||
char buffer[256]={0};
|
||||
@@ -312,7 +312,7 @@ struct tango_cache_ctx *tango_cache_update_prepare(struct tango_cache_instance *
|
||||
|
||||
ctx = (struct tango_cache_ctx *)calloc(1, sizeof(struct tango_cache_ctx));
|
||||
ctx->instance = instance;
|
||||
ctx->future = future;
|
||||
ctx->future = f;
|
||||
ctx->method = CACHE_REQUEST_PUT;
|
||||
|
||||
if(instance->hash_object_key)
|
||||
@@ -375,11 +375,11 @@ struct tango_cache_ctx *tango_cache_update_prepare(struct tango_cache_instance *
|
||||
return ctx;
|
||||
}
|
||||
|
||||
struct tango_cache_ctx *tango_cache_update_start(struct tango_cache_instance *instance, struct future* future, struct tango_cache_meta *meta)
|
||||
struct tango_cache_ctx *tango_cache_update_start(struct tango_cache_instance *instance, struct future* f, struct tango_cache_meta_put *meta)
|
||||
{
|
||||
struct tango_cache_ctx *ctx;
|
||||
|
||||
ctx = tango_cache_update_prepare(instance, future, meta);
|
||||
ctx = tango_cache_update_prepare(instance, f, meta);
|
||||
if(ctx == NULL)
|
||||
{
|
||||
return NULL;
|
||||
@@ -389,12 +389,12 @@ struct tango_cache_ctx *tango_cache_update_start(struct tango_cache_instance *in
|
||||
return ctx;
|
||||
}
|
||||
|
||||
int tango_cache_upload_once_data(struct tango_cache_instance *instance, struct future* future,
|
||||
enum PUT_MEMORY_COPY_WAY way, const char *data, size_t size, struct tango_cache_meta *meta, char *path, size_t pathsize)
|
||||
int tango_cache_upload_once_data(struct tango_cache_instance *instance, struct future* f,
|
||||
enum PUT_MEMORY_COPY_WAY way, const char *data, size_t size, struct tango_cache_meta_put *meta, char *path, size_t pathsize)
|
||||
{
|
||||
struct tango_cache_ctx *ctx;
|
||||
|
||||
ctx = tango_cache_update_prepare(instance, future, meta);
|
||||
ctx = tango_cache_update_prepare(instance, f, meta);
|
||||
if(ctx == NULL)
|
||||
{
|
||||
return -1;
|
||||
@@ -407,12 +407,12 @@ int tango_cache_upload_once_data(struct tango_cache_instance *instance, struct f
|
||||
return tango_cache_upload_once_start_data(ctx, way, data, size);
|
||||
}
|
||||
|
||||
int tango_cache_upload_once_evbuf(struct tango_cache_instance *instance, struct future* future,
|
||||
enum EVBUFFER_COPY_WAY way, struct evbuffer *evbuf, struct tango_cache_meta *meta, char *path, size_t pathsize)
|
||||
int tango_cache_upload_once_evbuf(struct tango_cache_instance *instance, struct future* f,
|
||||
enum EVBUFFER_COPY_WAY way, struct evbuffer *evbuf, struct tango_cache_meta_put *meta, char *path, size_t pathsize)
|
||||
{
|
||||
struct tango_cache_ctx *ctx;
|
||||
|
||||
ctx = tango_cache_update_prepare(instance, future, meta);
|
||||
ctx = tango_cache_update_prepare(instance, f, meta);
|
||||
if(ctx == NULL)
|
||||
{
|
||||
return -1;
|
||||
@@ -425,14 +425,14 @@ int tango_cache_upload_once_evbuf(struct tango_cache_instance *instance, struct
|
||||
return tango_cache_upload_once_start_evbuf(ctx, way, evbuf);
|
||||
}
|
||||
|
||||
struct tango_cache_ctx *tango_cache_fetch_prepare(struct tango_cache_instance *instance, struct future* future, struct tango_cache_meta *meta)
|
||||
struct tango_cache_ctx *tango_cache_fetch_prepare(struct tango_cache_instance *instance, struct future* f, struct tango_cache_meta_get *meta)
|
||||
{
|
||||
struct tango_cache_ctx *ctx;
|
||||
char sha256[72]={0};
|
||||
|
||||
ctx = (struct tango_cache_ctx *)calloc(1, sizeof(struct tango_cache_ctx));
|
||||
ctx->instance = instance;
|
||||
ctx->future = future;
|
||||
ctx->future = f;
|
||||
ctx->method = CACHE_REQUEST_GET;
|
||||
ctx->get.state = GET_STATE_START;
|
||||
ctx->get.max_age = meta->get.max_age;
|
||||
@@ -457,11 +457,11 @@ struct tango_cache_ctx *tango_cache_fetch_prepare(struct tango_cache_instance *i
|
||||
return ctx;
|
||||
}
|
||||
|
||||
int tango_cache_fetch_object(struct tango_cache_instance *instance, struct future* future, struct tango_cache_meta *meta)
|
||||
int tango_cache_fetch_object(struct tango_cache_instance *instance, struct future* f, struct tango_cache_meta_get *meta)
|
||||
{
|
||||
struct tango_cache_ctx *ctx;
|
||||
|
||||
ctx = tango_cache_fetch_prepare(instance, future, meta);
|
||||
ctx = tango_cache_fetch_prepare(instance, f, meta);
|
||||
if(ctx == NULL)
|
||||
{
|
||||
return -1;
|
||||
@@ -469,14 +469,14 @@ int tango_cache_fetch_object(struct tango_cache_instance *instance, struct futur
|
||||
return tango_cache_fetch_start(ctx);
|
||||
}
|
||||
|
||||
struct tango_cache_ctx *tango_cache_delete_prepare(struct tango_cache_instance *instance, struct future* future, const char *objkey)
|
||||
struct tango_cache_ctx *tango_cache_delete_prepare(struct tango_cache_instance *instance, struct future* f, const char *objkey)
|
||||
{
|
||||
struct tango_cache_ctx *ctx;
|
||||
char sha256[72]={0};
|
||||
|
||||
ctx = (struct tango_cache_ctx *)calloc(1, sizeof(struct tango_cache_ctx));
|
||||
ctx->instance = instance;
|
||||
ctx->future = future;
|
||||
ctx->future = f;
|
||||
ctx->method = CACHE_REQUEST_DELETE;
|
||||
|
||||
if(instance->hash_object_key)
|
||||
@@ -498,11 +498,11 @@ struct tango_cache_ctx *tango_cache_delete_prepare(struct tango_cache_instance *
|
||||
return ctx;
|
||||
}
|
||||
|
||||
int tango_cache_delete_object(struct tango_cache_instance *instance, struct future* future, const char *objkey)
|
||||
int tango_cache_delete_object(struct tango_cache_instance *instance, struct future* f, const char *objkey)
|
||||
{
|
||||
struct tango_cache_ctx *ctx;
|
||||
|
||||
ctx = tango_cache_delete_prepare(instance, future, objkey);
|
||||
ctx = tango_cache_delete_prepare(instance, f, objkey);
|
||||
if(ctx == NULL)
|
||||
{
|
||||
return -1;
|
||||
@@ -510,14 +510,14 @@ 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 *tango_cache_multi_delete_prepare(struct tango_cache_instance *instance, struct future* f, 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->future = f;
|
||||
ctx->method = CACHE_REQUEST_DELETE_MUL;
|
||||
ctx->del.succ_num = num;
|
||||
|
||||
@@ -534,15 +534,16 @@ struct tango_cache_ctx *tango_cache_multi_delete_prepare(struct tango_cache_inst
|
||||
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");
|
||||
ctx->headers = curl_slist_append(ctx->headers, "Expect:");
|
||||
return ctx;
|
||||
}
|
||||
|
||||
//TODO: AccessDenied
|
||||
int tango_cache_multi_delete(struct tango_cache_instance *instance, struct future* future, char *objlist[], u_int32_t num)
|
||||
int tango_cache_multi_delete(struct tango_cache_instance *instance, struct future* f, char *objlist[], u_int32_t num)
|
||||
{
|
||||
struct tango_cache_ctx *ctx;
|
||||
|
||||
ctx = tango_cache_multi_delete_prepare(instance, future, objlist, num);
|
||||
ctx = tango_cache_multi_delete_prepare(instance, f, objlist, num);
|
||||
if(ctx == NULL)
|
||||
{
|
||||
return -1;
|
||||
@@ -752,9 +753,8 @@ static int load_local_configure(struct tango_cache_instance *instance, const cha
|
||||
MESA_load_profile_string_def(profile_path, section, "WIREDLB_GROUP", instance->wiredlb_group, 64, "KAZAKHSTAN");
|
||||
MESA_load_profile_string_def(profile_path, section, "WIREDLB_DATACENTER", instance->wiredlb_datacenter, 64, "ASTANA");
|
||||
MESA_load_profile_uint_def(profile_path, section, "WIREDLB_OVERRIDE", &instance->wiredlb_override, 1);
|
||||
|
||||
MESA_load_profile_uint_def(profile_path, section, "WIREDLB_HEALTH_PORT", &intval, 52100);
|
||||
instance->wiredlb_ha_port=(unsigned short)intval;
|
||||
instance->wiredlb_ha_port = (u_int16_t)intval;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
11
cache/src/tango_cache_client_in.h
vendored
11
cache/src/tango_cache_client_in.h
vendored
@@ -55,6 +55,7 @@ struct tango_cache_instance
|
||||
u_int32_t minio_port;
|
||||
u_int32_t wiredlb_override;
|
||||
u_int16_t wiredlb_ha_port;
|
||||
u_int32_t hash_object_key;
|
||||
struct event_base* evbase;
|
||||
struct event timer_event;
|
||||
struct cache_statistics statistic;
|
||||
@@ -66,7 +67,6 @@ struct tango_cache_instance
|
||||
long max_cnn_host;
|
||||
u_int32_t upload_block_size; //minio<69>ֶ<EFBFBD><D6B6>ϴ<EFBFBD><CFB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С<EFBFBD><D0A1><EFBFBD><EFBFBD>
|
||||
enum CACHE_ERR_CODE error_code;
|
||||
u_int32_t hash_object_key;
|
||||
};
|
||||
|
||||
struct multipart_etag_list
|
||||
@@ -78,13 +78,14 @@ struct multipart_etag_list
|
||||
|
||||
struct cache_ctx_data_get
|
||||
{
|
||||
time_t max_age;//Get
|
||||
time_t min_fresh;//Get
|
||||
time_t max_age;
|
||||
time_t min_fresh;
|
||||
time_t expires;
|
||||
time_t last_modify;
|
||||
u_int32_t need_hdrs;
|
||||
enum GET_OBJECT_STATE state;
|
||||
struct easy_string response_tag;
|
||||
struct tango_cache_result result;
|
||||
};
|
||||
|
||||
struct cache_ctx_data_put
|
||||
@@ -144,8 +145,8 @@ void tango_cache_ctx_destroy(struct tango_cache_ctx *ctx);
|
||||
void tango_cache_set_fail_state(struct tango_cache_ctx *ctx, enum CACHE_ERR_CODE error_code);
|
||||
const char *tango_cache_get_errstring(const struct tango_cache_ctx *ctx);
|
||||
|
||||
struct tango_cache_ctx *tango_cache_update_prepare(struct tango_cache_instance *instance, struct future* future, struct tango_cache_meta *meta);
|
||||
struct tango_cache_ctx *tango_cache_fetch_prepare(struct tango_cache_instance *instance, struct future* future, struct tango_cache_meta *meta);
|
||||
struct tango_cache_ctx *tango_cache_update_prepare(struct tango_cache_instance *instance, struct future* future, struct tango_cache_meta_put *meta);
|
||||
struct tango_cache_ctx *tango_cache_fetch_prepare(struct tango_cache_instance *instance, struct future* future, struct tango_cache_meta_get *meta);
|
||||
struct tango_cache_ctx *tango_cache_delete_prepare(struct tango_cache_instance *instance, struct future* future, const char *objkey);
|
||||
|
||||
#endif
|
||||
|
||||
141
cache/src/tango_cache_transfer.cpp
vendored
141
cache/src/tango_cache_transfer.cpp
vendored
@@ -647,48 +647,10 @@ int tango_cache_multi_delete_start(struct tango_cache_ctx *ctx)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void tango_cache_curl_get_done(struct tango_cache_ctx *ctx, CURLcode res, long res_code)
|
||||
{
|
||||
switch(ctx->get.state)
|
||||
{
|
||||
case GET_STATE_START:
|
||||
if(!ctx->fail_state)
|
||||
{
|
||||
if(res!=CURLE_OK || res_code!=200L)
|
||||
{
|
||||
tango_cache_set_fail_state(ctx, (res!=CURLE_OK)?CACHE_ERR_CURL:CACHE_CACHE_MISS);
|
||||
promise_failed(future_to_promise(ctx->future), FUTURE_ERROR_CANCEL, tango_cache_get_errstring(ctx));
|
||||
}
|
||||
else
|
||||
{
|
||||
promise_success(future_to_promise(ctx->future), NULL);
|
||||
}
|
||||
}
|
||||
tango_cache_ctx_destroy(ctx);
|
||||
break;
|
||||
|
||||
case GET_STATE_DELETE:
|
||||
if(cache_delete_minio_object(ctx))
|
||||
{
|
||||
ctx->get.state = GET_STATE_END;
|
||||
}
|
||||
else
|
||||
{
|
||||
tango_cache_ctx_destroy(ctx);
|
||||
}
|
||||
break;
|
||||
|
||||
case GET_STATE_END:
|
||||
tango_cache_ctx_destroy(ctx);
|
||||
break;
|
||||
default: assert(0);break;
|
||||
}
|
||||
}
|
||||
|
||||
static size_t curl_get_response_body_cb(void *ptr, size_t size, size_t count, void *userp)
|
||||
{
|
||||
struct tango_cache_ctx *ctx = (struct tango_cache_ctx *)userp;
|
||||
struct tango_cache_result result;
|
||||
|
||||
if(ctx->fail_state || ctx->get.state==GET_STATE_DELETE)
|
||||
{
|
||||
@@ -705,24 +667,24 @@ static size_t curl_get_response_body_cb(void *ptr, size_t size, size_t count, vo
|
||||
|
||||
if(ctx->get.response_tag.len > 0)
|
||||
{
|
||||
result.data_frag = ctx->get.response_tag.buff;
|
||||
result.size = ctx->get.response_tag.len;
|
||||
result.type = RESULT_TYPE_USERTAG;
|
||||
promise_success(future_to_promise(ctx->future), &result);
|
||||
ctx->get.result.data_frag = ctx->get.response_tag.buff;
|
||||
ctx->get.result.size = ctx->get.response_tag.len;
|
||||
ctx->get.result.type = RESULT_TYPE_USERTAG;
|
||||
promise_success(future_to_promise(ctx->future), &ctx->get.result);
|
||||
easy_string_destroy(&ctx->get.response_tag);
|
||||
}
|
||||
if(ctx->response.len > 0)
|
||||
{
|
||||
result.data_frag = ctx->response.buff;
|
||||
result.size = ctx->response.len;
|
||||
result.type = RESULT_TYPE_HEADER;
|
||||
promise_success(future_to_promise(ctx->future), &result);
|
||||
ctx->get.result.data_frag = ctx->response.buff;
|
||||
ctx->get.result.size = ctx->response.len;
|
||||
ctx->get.result.type = RESULT_TYPE_HEADER;
|
||||
promise_success(future_to_promise(ctx->future), &ctx->get.result);
|
||||
easy_string_destroy(&ctx->response);
|
||||
}
|
||||
result.data_frag = ptr;
|
||||
result.size = size * count;
|
||||
result.type = RESULT_TYPE_BODY;
|
||||
promise_success(future_to_promise(ctx->future), &result);
|
||||
ctx->get.result.data_frag = (const char *)ptr;
|
||||
ctx->get.result.size = size * count;
|
||||
ctx->get.result.type = RESULT_TYPE_BODY;
|
||||
promise_success(future_to_promise(ctx->future), &ctx->get.result);
|
||||
return size*count;
|
||||
}
|
||||
|
||||
@@ -733,12 +695,13 @@ static bool check_expires_header(struct tango_cache_ctx *ctx, const char *expire
|
||||
ctx->get.expires = expires_hdr2timestamp(expires_val, len);
|
||||
time_gmt = get_gmtime_timestamp(time(NULL));
|
||||
|
||||
if(time_gmt > ctx->get.expires) //<2F><><EFBFBD><EFBFBD>ʧЧ<CAA7><D0A7>TODO relative_age<67>ĺ<EFBFBD><C4BA><EFBFBD><EFBFBD><EFBFBD>ɶ
|
||||
if(time_gmt > ctx->get.expires)
|
||||
{
|
||||
tango_cache_set_fail_state(ctx, CACHE_TIMEOUT);
|
||||
ctx->get.state = GET_STATE_DELETE; //<2F><><EFBFBD><EFBFBD>ʧЧʱ<D0A7><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>ɾ<EFBFBD><C9BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
ctx->get.result.type = RESULT_TYPE_MISS;
|
||||
promise_success(future_to_promise(ctx->future), &ctx->get.result);
|
||||
easy_string_destroy(&ctx->response);
|
||||
promise_failed(future_to_promise(ctx->future), FUTURE_ERROR_CANCEL, tango_cache_get_errstring(ctx));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -755,24 +718,38 @@ static bool check_fresh_header(struct tango_cache_ctx *ctx)
|
||||
if(ctx->get.last_modify+ctx->get.max_age > now_gmt || now_gmt+ctx->get.min_fresh>ctx->get.expires)
|
||||
{
|
||||
tango_cache_set_fail_state(ctx, CACHE_TIMEOUT);
|
||||
ctx->get.result.type = RESULT_TYPE_MISS;
|
||||
promise_success(future_to_promise(ctx->future), &ctx->get.result);
|
||||
easy_string_destroy(&ctx->response);
|
||||
promise_failed(future_to_promise(ctx->future), FUTURE_ERROR_CANCEL, tango_cache_get_errstring(ctx));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool check_get_result_code(struct tango_cache_ctx *ctx)
|
||||
static bool check_get_result_code(struct tango_cache_ctx *ctx, CURLcode code, long res_code)
|
||||
{
|
||||
CURLcode code;
|
||||
|
||||
code = curl_easy_getinfo(ctx->curl, CURLINFO_RESPONSE_CODE, &ctx->res_code);
|
||||
if(code != CURLE_OK || ctx->res_code!=200L)
|
||||
if(code != CURLE_OK)
|
||||
{
|
||||
tango_cache_set_fail_state(ctx, (code!=CURLE_OK)?CACHE_ERR_CURL:CACHE_CACHE_MISS);
|
||||
tango_cache_set_fail_state(ctx, CACHE_ERR_CURL);
|
||||
promise_failed(future_to_promise(ctx->future), FUTURE_ERROR_CANCEL, tango_cache_get_errstring(ctx));
|
||||
return false;
|
||||
}
|
||||
|
||||
if(res_code != 200L)
|
||||
{
|
||||
if(res_code == 404L)
|
||||
{
|
||||
tango_cache_set_fail_state(ctx, CACHE_CACHE_MISS);
|
||||
ctx->get.result.type = RESULT_TYPE_MISS;
|
||||
promise_success(future_to_promise(ctx->future), &ctx->get.result);
|
||||
}
|
||||
else
|
||||
{
|
||||
tango_cache_set_fail_state(ctx, CACHE_ERR_INTERNAL);
|
||||
promise_failed(future_to_promise(ctx->future), FUTURE_ERROR_CANCEL, tango_cache_get_errstring(ctx));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -788,9 +765,13 @@ static size_t curl_get_response_header_cb(void *ptr, size_t size, size_t count,
|
||||
{
|
||||
return raw_len;
|
||||
}
|
||||
if(ctx->res_code==0 && !check_get_result_code(ctx)) //<2F>״<EFBFBD>Ӧ<EFBFBD><D3A6>ʱ<EFBFBD>ȿ<EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD>200
|
||||
if(ctx->res_code == 0) //<2F>״<EFBFBD>Ӧ<EFBFBD><D3A6>ʱ<EFBFBD>ȿ<EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD>200
|
||||
{
|
||||
return raw_len;
|
||||
CURLcode code = curl_easy_getinfo(ctx->curl, CURLINFO_RESPONSE_CODE, &ctx->res_code);
|
||||
if(!check_get_result_code(ctx, code, ctx->res_code))
|
||||
{
|
||||
return raw_len;
|
||||
}
|
||||
}
|
||||
pos_colon = (char*)memchr(start, ':', raw_len);
|
||||
if(pos_colon == NULL)
|
||||
@@ -831,9 +812,14 @@ static size_t curl_get_response_header_cb(void *ptr, size_t size, size_t count,
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 14:
|
||||
if(strcmp_one_word_mesa_equal_len("content-length", "CONTENT-LENGTH", start, 14))
|
||||
{
|
||||
sscanf(pos_colon+1, "%lu", &ctx->get.result.tlength);
|
||||
}
|
||||
break;
|
||||
case 11: if(strcmp_one_word_mesa_equal_len("content-md5", "CONTENT-MD5", start, 11)) easy_string_savedata(&ctx->response, (const char*)ptr, raw_len); break;
|
||||
case 12: if(strcmp_one_word_mesa_equal_len("content-type", "CONTENT-TYPE", start, 12)) easy_string_savedata(&ctx->response, (const char*)ptr, raw_len); break;
|
||||
case 14: if(strcmp_one_word_mesa_equal_len("content-length", "CONTENT-LENGTH", start, 14)) easy_string_savedata(&ctx->response, (const char*)ptr, raw_len); break;
|
||||
case 16: if(strcmp_one_word_mesa_equal_len("content-encoding", "CONTENT-ENCODING", start, 16)) easy_string_savedata(&ctx->response, (const char*)ptr, raw_len); break;
|
||||
case 19: if(strcmp_one_word_mesa_equal_len("content-disposition", "CONTENT-DISPOSITION", start, 19)) easy_string_savedata(&ctx->response, (const char*)ptr, raw_len); break;
|
||||
default: break;
|
||||
@@ -841,6 +827,37 @@ static size_t curl_get_response_header_cb(void *ptr, size_t size, size_t count,
|
||||
return raw_len;
|
||||
}
|
||||
|
||||
void tango_cache_curl_get_done(struct tango_cache_ctx *ctx, CURLcode res, long res_code)
|
||||
{
|
||||
switch(ctx->get.state)
|
||||
{
|
||||
case GET_STATE_START:
|
||||
if(!ctx->fail_state && check_get_result_code(ctx, res, res_code))
|
||||
{
|
||||
ctx->get.result.type = RESULT_TYPE_END;
|
||||
promise_success(future_to_promise(ctx->future), &ctx->get.result);
|
||||
}
|
||||
tango_cache_ctx_destroy(ctx);
|
||||
break;
|
||||
|
||||
case GET_STATE_DELETE:
|
||||
if(cache_delete_minio_object(ctx))
|
||||
{
|
||||
ctx->get.state = GET_STATE_END;
|
||||
}
|
||||
else
|
||||
{
|
||||
tango_cache_ctx_destroy(ctx);
|
||||
}
|
||||
break;
|
||||
|
||||
case GET_STATE_END:
|
||||
tango_cache_ctx_destroy(ctx);
|
||||
break;
|
||||
default: assert(0);break;
|
||||
}
|
||||
}
|
||||
|
||||
int tango_cache_fetch_start(struct tango_cache_ctx *ctx)
|
||||
{
|
||||
CURLMcode rc;
|
||||
|
||||
69
cache/test/cache_evbase_test.cpp
vendored
69
cache/test/cache_evbase_test.cpp
vendored
@@ -37,29 +37,28 @@ void get_future_success(future_result_t* result, void * user)
|
||||
struct future_pdata *pdata = (struct future_pdata *)user;
|
||||
char buffer[1024];
|
||||
|
||||
if(res != NULL)
|
||||
switch(res->type)
|
||||
{
|
||||
switch(res->type)
|
||||
{
|
||||
case RESULT_TYPE_BODY:
|
||||
fwrite(res->data_frag, res->size, 1, pdata->fp);
|
||||
break;
|
||||
|
||||
case RESULT_TYPE_USERTAG:
|
||||
case RESULT_TYPE_HEADER:
|
||||
memcpy(buffer, res->data_frag, res->size>=1024?1023:res->size);
|
||||
buffer[res->size] = '\0';
|
||||
printf("%s", buffer);
|
||||
break;
|
||||
default:break;
|
||||
}
|
||||
}
|
||||
else //<2F><><EFBFBD><EFBFBD>
|
||||
{
|
||||
future_destroy(pdata->future);
|
||||
fclose(pdata->fp);
|
||||
free(pdata);
|
||||
runing_over = 1;
|
||||
case RESULT_TYPE_USERTAG:
|
||||
case RESULT_TYPE_HEADER:
|
||||
memcpy(buffer, res->data_frag, res->size>=1024?1023:res->size);
|
||||
buffer[res->size] = '\0';
|
||||
printf("%s", buffer);
|
||||
break;
|
||||
case RESULT_TYPE_BODY:
|
||||
fwrite(res->data_frag, res->size, 1, pdata->fp);
|
||||
break;
|
||||
case RESULT_TYPE_MISS:
|
||||
printf("cache not hit/fresh\n");
|
||||
case RESULT_TYPE_END:
|
||||
if(res->type != RESULT_TYPE_MISS)
|
||||
printf("get cache over, total length: %ld\n", res->tlength);
|
||||
future_destroy(pdata->future);
|
||||
fclose(pdata->fp);
|
||||
free(pdata);
|
||||
runing_over = 1;
|
||||
break;
|
||||
default:break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -150,7 +149,8 @@ int main(int argc, char **argv)
|
||||
{
|
||||
int n, index=0;
|
||||
char method[16], filename_in[256], filename_out[256], *p;
|
||||
struct tango_cache_meta meta;
|
||||
struct tango_cache_meta_put putmeta;
|
||||
struct tango_cache_meta_get getmeta;
|
||||
struct future_pdata *pdata;
|
||||
struct cache_evbase_ctx *ctx;
|
||||
void *runtime_log;
|
||||
@@ -183,12 +183,15 @@ int main(int argc, char **argv)
|
||||
}
|
||||
if(strlen(filename_in) > 0)
|
||||
{
|
||||
memset(&meta, 0, sizeof(struct tango_cache_meta));
|
||||
meta.url = filename_in;
|
||||
meta.std_hdr[HDR_CONTENT_TYPE] = "Content-Type: maintype/subtype";
|
||||
meta.std_hdr[HDR_CONTENT_ENCODING] = "Content-Encoding: gzip";
|
||||
meta.usertag = "Etag: hgdkqkwdwqekdfjwjfjwelkjfkwfejwhf\r\n";
|
||||
meta.usertag_len = strlen(meta.usertag);
|
||||
memset(&putmeta, 0, sizeof(struct tango_cache_meta_put));
|
||||
memset(&getmeta, 0, sizeof(struct tango_cache_meta_get));
|
||||
putmeta.url = filename_in;
|
||||
putmeta.std_hdr[HDR_CONTENT_TYPE] = "Content-Type: maintype/subtype";
|
||||
putmeta.std_hdr[HDR_CONTENT_ENCODING] = "Content-Encoding: gzip";
|
||||
putmeta.usertag = "Etag: hgdkqkwdwqekdfjwjfjwelkjfkwfejwhf\r\n";
|
||||
putmeta.usertag_len = strlen(putmeta.usertag);
|
||||
|
||||
getmeta.url = filename_in;
|
||||
|
||||
p = method;
|
||||
while(*p=='\r'||*p=='\n') p++;
|
||||
@@ -201,7 +204,7 @@ int main(int argc, char **argv)
|
||||
promise_set_ctx(future_to_promise(pdata->future), NULL, NULL);
|
||||
pdata->fp = fopen(filename_out, "w");
|
||||
|
||||
cache_evbase_fetch_object(instance_asyn, pdata->future, &meta);
|
||||
cache_evbase_fetch_object(instance_asyn, pdata->future, &getmeta);
|
||||
}
|
||||
else if(!strcasecmp(p, "DEL"))
|
||||
{
|
||||
@@ -217,7 +220,7 @@ int main(int argc, char **argv)
|
||||
pdata->future = future_create(put_future_success, put_future_failed, pdata);
|
||||
promise_set_ctx(future_to_promise(pdata->future), NULL, NULL);
|
||||
|
||||
cache_evbase_upload_once_data(instance_asyn, pdata->future, PUT_MEM_FREE, p, filelen, &meta, pdata->filename, 256);
|
||||
cache_evbase_upload_once_data(instance_asyn, pdata->future, PUT_MEM_FREE, p, filelen, &putmeta, pdata->filename, 256);
|
||||
}
|
||||
else if(!strcasecmp(p, "PUTONCEEV"))
|
||||
{
|
||||
@@ -238,14 +241,14 @@ int main(int argc, char **argv)
|
||||
evbuffer_add(evbuf, buffer, readlen);
|
||||
}
|
||||
fclose(fp);
|
||||
cache_evbase_upload_once_evbuf(instance_asyn, pdata->future, evbuf, &meta, pdata->filename, 256);
|
||||
cache_evbase_upload_once_evbuf(instance_asyn, pdata->future, evbuf, &putmeta, pdata->filename, 256);
|
||||
}
|
||||
else
|
||||
{
|
||||
pdata->future = future_create(put_future_success, put_future_failed, pdata);
|
||||
promise_set_ctx(future_to_promise(pdata->future), NULL, NULL);
|
||||
|
||||
ctx = cache_evbase_update_start(instance_asyn, pdata->future, &meta);
|
||||
ctx = cache_evbase_update_start(instance_asyn, pdata->future, &putmeta);
|
||||
cache_evbase_get_object_path(ctx, pdata->filename, 256);
|
||||
|
||||
char buffer[1024];
|
||||
|
||||
68
cache/test/cache_evbase_test_threads.cpp
vendored
68
cache/test/cache_evbase_test_threads.cpp
vendored
@@ -38,29 +38,28 @@ void get_future_success(future_result_t* result, void * user)
|
||||
struct future_pdata *pdata = (struct future_pdata *)user;
|
||||
char buffer[1024];
|
||||
|
||||
if(res != NULL)
|
||||
switch(res->type)
|
||||
{
|
||||
switch(res->type)
|
||||
{
|
||||
case RESULT_TYPE_BODY:
|
||||
fwrite(res->data_frag, res->size, 1, pdata->fp);
|
||||
break;
|
||||
|
||||
case RESULT_TYPE_USERTAG:
|
||||
case RESULT_TYPE_HEADER:
|
||||
memcpy(buffer, res->data_frag, res->size>=1024?1023:res->size);
|
||||
buffer[res->size] = '\0';
|
||||
printf("%s", buffer);
|
||||
break;
|
||||
default:break;
|
||||
}
|
||||
}
|
||||
else //<2F><><EFBFBD><EFBFBD>
|
||||
{
|
||||
future_destroy(pdata->future);
|
||||
fclose(pdata->fp);
|
||||
free(pdata);
|
||||
runing_over = 1;
|
||||
case RESULT_TYPE_USERTAG:
|
||||
case RESULT_TYPE_HEADER:
|
||||
memcpy(buffer, res->data_frag, res->size>=1024?1023:res->size);
|
||||
buffer[res->size] = '\0';
|
||||
printf("%s", buffer);
|
||||
break;
|
||||
case RESULT_TYPE_BODY:
|
||||
fwrite(res->data_frag, res->size, 1, pdata->fp);
|
||||
break;
|
||||
case RESULT_TYPE_MISS:
|
||||
printf("cache not hit/fresh\n");
|
||||
case RESULT_TYPE_END:
|
||||
if(res->type != RESULT_TYPE_MISS)
|
||||
printf("get cache over, total length: %ld\n", res->tlength);
|
||||
future_destroy(pdata->future);
|
||||
fclose(pdata->fp);
|
||||
free(pdata);
|
||||
runing_over = 1;
|
||||
break;
|
||||
default:break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -158,7 +157,8 @@ void* thread_upload_download(void *arg)
|
||||
{
|
||||
int n;
|
||||
char method[16], filename_in[256], filename_out[256], *p;
|
||||
struct tango_cache_meta meta;
|
||||
struct tango_cache_meta_put putmeta;
|
||||
struct tango_cache_meta_get getmeta;
|
||||
struct future_pdata *pdata;
|
||||
struct cache_evbase_ctx *ctx;
|
||||
struct pthread_data *thread_data = (struct pthread_data *)arg;
|
||||
@@ -172,12 +172,14 @@ void* thread_upload_download(void *arg)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memset(&meta, 0, sizeof(struct tango_cache_meta));
|
||||
meta.url = filename_in;
|
||||
meta.std_hdr[HDR_CONTENT_TYPE] = "Content-Type: maintype/subtype";
|
||||
meta.std_hdr[HDR_CONTENT_ENCODING] = "Content-Encoding: gzip";
|
||||
meta.usertag = "Etag: hgdkqkwdwqekdfjwjfjwelkjfkwfejwhf\r\n";
|
||||
meta.usertag_len = strlen(meta.usertag);
|
||||
memset(&putmeta, 0, sizeof(struct tango_cache_meta_put));
|
||||
putmeta.url = filename_in;
|
||||
putmeta.std_hdr[HDR_CONTENT_TYPE] = "Content-Type: maintype/subtype";
|
||||
putmeta.std_hdr[HDR_CONTENT_ENCODING] = "Content-Encoding: gzip";
|
||||
putmeta.usertag = "Etag: hgdkqkwdwqekdfjwjfjwelkjfkwfejwhf\r\n";
|
||||
putmeta.usertag_len = strlen(putmeta.usertag);
|
||||
|
||||
getmeta.url = filename_in;
|
||||
|
||||
p = method;
|
||||
while(*p=='\r'||*p=='\n') p++;
|
||||
@@ -194,7 +196,7 @@ void* thread_upload_download(void *arg)
|
||||
promise_set_ctx(future_to_promise(pdata->future), NULL, NULL);
|
||||
pdata->fp = fopen(filename_out, "w");
|
||||
|
||||
cache_evbase_fetch_object(instance_asyn, pdata->future, &meta);
|
||||
cache_evbase_fetch_object(instance_asyn, pdata->future, &getmeta);
|
||||
}
|
||||
else if(!strcasecmp(p, "DEL"))
|
||||
{
|
||||
@@ -210,7 +212,7 @@ void* thread_upload_download(void *arg)
|
||||
pdata->future = future_create(put_future_success, put_future_failed, pdata);
|
||||
promise_set_ctx(future_to_promise(pdata->future), NULL, NULL);
|
||||
|
||||
if(cache_evbase_upload_once_data(instance_asyn, pdata->future, PUT_MEM_FREE, p, filelen, &meta, pdata->filename, 256))
|
||||
if(cache_evbase_upload_once_data(instance_asyn, pdata->future, PUT_MEM_FREE, p, filelen, &putmeta, pdata->filename, 256))
|
||||
{
|
||||
printf("cache_evbase_upload_once_data fail: %d\n", cache_evbase_ctx_error(instance_asyn));
|
||||
future_destroy(pdata->future);
|
||||
@@ -236,7 +238,7 @@ void* thread_upload_download(void *arg)
|
||||
evbuffer_add(evbuf, buffer, readlen);
|
||||
}
|
||||
fclose(fp);
|
||||
if(cache_evbase_upload_once_evbuf(instance_asyn, pdata->future, evbuf, &meta, pdata->filename, 256))
|
||||
if(cache_evbase_upload_once_evbuf(instance_asyn, pdata->future, evbuf, &putmeta, pdata->filename, 256))
|
||||
{
|
||||
printf("cache_evbase_upload_once_evbuf fail: %d\n", cache_evbase_ctx_error(instance_asyn));
|
||||
future_destroy(pdata->future);
|
||||
@@ -249,7 +251,7 @@ void* thread_upload_download(void *arg)
|
||||
pdata->future = future_create(put_future_success, put_future_failed, pdata);
|
||||
promise_set_ctx(future_to_promise(pdata->future), NULL, NULL);
|
||||
|
||||
ctx = cache_evbase_update_start(instance_asyn, pdata->future, &meta);
|
||||
ctx = cache_evbase_update_start(instance_asyn, pdata->future, &putmeta);
|
||||
if(ctx==NULL)
|
||||
{
|
||||
printf("cache_evbase_update_start fail: %d\n", cache_evbase_ctx_error(instance_asyn));
|
||||
|
||||
66
cache/test/tango_cache_test.c
vendored
66
cache/test/tango_cache_test.c
vendored
@@ -50,28 +50,27 @@ void get_future_success(future_result_t* result, void * user)
|
||||
struct future_pdata *pdata = (struct future_pdata *)user;
|
||||
char buffer[1024];
|
||||
|
||||
if(res != NULL)
|
||||
switch(res->type)
|
||||
{
|
||||
switch(res->type)
|
||||
{
|
||||
case RESULT_TYPE_BODY:
|
||||
fwrite(res->data_frag, res->size, 1, pdata->fp);
|
||||
break;
|
||||
|
||||
case RESULT_TYPE_USERTAG:
|
||||
case RESULT_TYPE_HEADER:
|
||||
memcpy(buffer, res->data_frag, res->size>=1024?1023:res->size);
|
||||
buffer[res->size] = '\0';
|
||||
printf("%s", buffer);
|
||||
break;
|
||||
default:break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
future_destroy(pdata->future);
|
||||
fclose(pdata->fp);
|
||||
free(pdata);
|
||||
case RESULT_TYPE_USERTAG:
|
||||
case RESULT_TYPE_HEADER:
|
||||
memcpy(buffer, res->data_frag, res->size>=1024?1023:res->size);
|
||||
buffer[res->size] = '\0';
|
||||
printf("%s", buffer);
|
||||
break;
|
||||
case RESULT_TYPE_BODY:
|
||||
fwrite(res->data_frag, res->size, 1, pdata->fp);
|
||||
break;
|
||||
case RESULT_TYPE_MISS:
|
||||
printf("cache not hit/fresh\n");
|
||||
case RESULT_TYPE_END:
|
||||
if(res->type != RESULT_TYPE_MISS)
|
||||
printf("get cache over, total length: %ld\n", res->tlength);
|
||||
future_destroy(pdata->future);
|
||||
fclose(pdata->fp);
|
||||
free(pdata);
|
||||
break;
|
||||
default:break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -166,7 +165,8 @@ static void dummy_accept_callback(evutil_socket_t fd, short events, void *arg)
|
||||
char *dellist[16];
|
||||
char *pstart, *save_ptr=NULL;
|
||||
int delnum=0;
|
||||
struct tango_cache_meta meta;
|
||||
struct tango_cache_meta_put putmeta;
|
||||
struct tango_cache_meta_get getmeta;
|
||||
struct future_pdata *pdata;
|
||||
|
||||
struct tango_cache_ctx *ctx;
|
||||
@@ -181,12 +181,14 @@ static void dummy_accept_callback(evutil_socket_t fd, short events, void *arg)
|
||||
{
|
||||
p = method;
|
||||
|
||||
memset(&meta, 0, sizeof(struct tango_cache_meta));
|
||||
meta.url = s;
|
||||
meta.std_hdr[HDR_CONTENT_TYPE] = "Content-Type: maintype/subtype";
|
||||
meta.std_hdr[HDR_CONTENT_ENCODING] = "Content-Encoding: gzip";
|
||||
meta.usertag = "Etag: hgdkqkwdwqekdfjwjfjwelkjfkwfejwhf\r\n";
|
||||
meta.usertag_len = strlen(meta.usertag);
|
||||
memset(&putmeta, 0, sizeof(struct tango_cache_meta_put));
|
||||
putmeta.url = s;
|
||||
putmeta.std_hdr[HDR_CONTENT_TYPE] = "Content-Type: maintype/subtype";
|
||||
putmeta.std_hdr[HDR_CONTENT_ENCODING] = "Content-Encoding: gzip";
|
||||
putmeta.usertag = "Etag: hgdkqkwdwqekdfjwjfjwelkjfkwfejwhf\r\n";
|
||||
putmeta.usertag_len = strlen(putmeta.usertag);
|
||||
|
||||
getmeta.url = s;
|
||||
|
||||
while(*p=='\r'||*p=='\n')p++;
|
||||
if(*p=='\0') continue;
|
||||
@@ -197,7 +199,7 @@ static void dummy_accept_callback(evutil_socket_t fd, short events, void *arg)
|
||||
pdata->future = future_create(get_future_success, get_future_failed, pdata);
|
||||
promise_set_ctx(future_to_promise(pdata->future), NULL, NULL);
|
||||
|
||||
tango_cache_fetch_object(tango_instance, pdata->future, &meta);
|
||||
tango_cache_fetch_object(tango_instance, pdata->future, &getmeta);
|
||||
}
|
||||
else if(!strcasecmp(p, "PUTONCE"))
|
||||
{
|
||||
@@ -206,7 +208,7 @@ static void dummy_accept_callback(evutil_socket_t fd, short events, void *arg)
|
||||
pdata->future = future_create(put_future_success, put_future_failed, pdata);
|
||||
promise_set_ctx(future_to_promise(pdata->future), NULL, NULL);
|
||||
|
||||
tango_cache_upload_once_data(tango_instance, pdata->future, PUT_MEM_FREE, p, filelen, &meta, pdata->filename, 256);
|
||||
tango_cache_upload_once_data(tango_instance, pdata->future, PUT_MEM_FREE, p, filelen, &putmeta, pdata->filename, 256);
|
||||
}
|
||||
else if(!strcasecmp(p, "PUTONCEEV"))
|
||||
{
|
||||
@@ -227,7 +229,7 @@ static void dummy_accept_callback(evutil_socket_t fd, short events, void *arg)
|
||||
evbuffer_add(evbuf, buffer, readlen);
|
||||
}
|
||||
fclose(fp);
|
||||
tango_cache_upload_once_evbuf(tango_instance, pdata->future, EVBUFFER_MOVE, evbuf, &meta, pdata->filename, 256);
|
||||
tango_cache_upload_once_evbuf(tango_instance, pdata->future, EVBUFFER_MOVE, evbuf, &putmeta, pdata->filename, 256);
|
||||
}
|
||||
else if(!strcasecmp(p, "DEL"))
|
||||
{
|
||||
@@ -253,7 +255,7 @@ static void dummy_accept_callback(evutil_socket_t fd, short events, void *arg)
|
||||
pdata->future = future_create(put_future_success, put_future_failed, pdata);
|
||||
promise_set_ctx(future_to_promise(pdata->future), NULL, NULL);
|
||||
|
||||
ctx = tango_cache_update_start(tango_instance, pdata->future, &meta);
|
||||
ctx = tango_cache_update_start(tango_instance, pdata->future, &putmeta);
|
||||
tango_cache_get_object_path(ctx, pdata->filename, 256);
|
||||
|
||||
FILE *fp = fopen(s, "r");
|
||||
|
||||
Reference in New Issue
Block a user