summaryrefslogtreecommitdiff
path: root/cache
diff options
context:
space:
mode:
authorzhangchengwei <[email protected]>2018-10-15 16:38:22 +0800
committerzhangchengwei <[email protected]>2018-10-15 16:38:22 +0800
commitece26bbf602c649193e2b1c1da699cdbfe65fda5 (patch)
tree98abfff9a141f502e82c37299b6b749e16e11b84 /cache
parentfdde1fb3a8d2cd405d5a664696500cdd7d00a4be (diff)
修改GET/PUT对外接口;cache miss不算fail;
Diffstat (limited to 'cache')
-rw-r--r--cache/include/cache_evbase_client.h14
-rw-r--r--cache/include/tango_cache_client.h42
-rw-r--r--cache/src/cache_evbase_client.cpp30
-rw-r--r--cache/src/tango_cache_client.cpp56
-rw-r--r--cache/src/tango_cache_client_in.h11
-rw-r--r--cache/src/tango_cache_transfer.cpp141
-rw-r--r--cache/test/cache_evbase_test.cpp69
-rw-r--r--cache/test/cache_evbase_test_threads.cpp68
-rw-r--r--cache/test/tango_cache_test.c66
9 files changed, 264 insertions, 233 deletions
diff --git a/cache/include/cache_evbase_client.h b/cache/include/cache_evbase_client.h
index 538b6d7..15bf3c3 100644
--- a/cache/include/cache_evbase_client.h
+++ b/cache/include/cache_evbase_client.h
@@ -33,24 +33,24 @@ struct cache_evbase_instance *cache_evbase_instance_new(const char* profile_path
//GET�ӿڣ��ɹ�����0��ʧ�ܷ���-1��future�ص���������������߳���ִ�У���ͬ
-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�ӿ�
-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);
//һ�����ϴ��ӿ�
-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);
//��ʽ�ϴ��ӿ�
-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);
diff --git a/cache/include/tango_cache_client.h b/cache/include/tango_cache_client.h
index 5e3da6a..75c4e10 100644
--- a/cache/include/tango_cache_client.h
+++ b/cache/include/tango_cache_client.h
@@ -43,7 +43,7 @@ struct cache_statistics
long long put_error_num;//UPLOADʧ�ܵĴ���
long long del_recv_num; //����DELETE�Ĵ���
long long del_succ_num; //DELETE�ɹ��Ĵ���
- long long del_error_num;//DELETE�ɹ��Ĵ���
+ long long del_error_num;//DELETEʧ�ܵĴ���
long long totaldrop_num;//�ڴ����Լ�WiredLB����ʱDROP�Ĵ���
long long memory_used; //��ǰUPLOAD BODY��ռ�ڴ��С
long long session_num; //��ǰ���ڽ���GET/PUT��HTTP�Ự��
@@ -51,16 +51,19 @@ struct cache_statistics
enum CACHE_RESULT_TYPE
{
- RESULT_TYPE_HEADER=0, //ֻ����һ��
- RESULT_TYPE_USERTAG, //ֻ����һ��
+ RESULT_TYPE_HEADER=0, //���ֻ����һ��
+ RESULT_TYPE_USERTAG, //���ֻ����һ��
RESULT_TYPE_BODY, //���ܵ��ö��
+ RESULT_TYPE_END, //ȫ��������ֻ����һ�Σ�����������
+ RESULT_TYPE_MISS, //����δ���У����������ͻ��⣬ֻ����һ��(��END֮��)������������
};
//promise_success�Ľ��result
struct tango_cache_result
{
- const void *data_frag; //���typeΪRESULT_TYPE_HEADER��ÿ��ͷ��������һ������(HTTP1.1��ʽ)
+ const char *data_frag; //���typeΪRESULT_TYPE_HEADER��ÿ��ͷ��������һ������(HTTP1.1��ʽ)
size_t size;
+ size_t tlength; //������ܳ��ȣ��ص�ʱ����Ч
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; //����:URL���ǽṹ����־:�ļ�������󳤶�256�ֽ�
+ struct request_freshness get;
+};
+
+struct tango_cache_meta_put
+{
+ const char* url;
const char* std_hdr[HDR_CONTENT_NUM]; //����ͷ������"Content-Type: text/html"����Ҫ�������У�NULL��ʾû�и�ͷ����
const char* usertag; //�������������ݣ�GETʱ��ԭ������
size_t usertag_len; //��󳤶�USER_TAG_MAX_LEN��0��ʾû�и�ͷ��
- 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�ӿڵ�API*/
-//�ɹ�ʱ�ص�promise_success, resultΪNULLʱ��ʾ������
+//�ɹ�ʱ�ص�promise_success
//ʧ��ʱ�ص�promise_failed(��һ��)��ʹ��get_last_error��ȡ�����룻
//future������Ϊ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);
//��promise_success��result������ȡ���
-struct tango_cache_result *tango_cache_read_result(future_result_t *result);
+struct tango_cache_result *tango_cache_read_result(void *promise_result);
/* DELETE�ӿڵ�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�ӿڵ�API
@@ -121,17 +127,17 @@ int tango_cache_delete_object(struct tango_cache_instance *instance, struct futu
/*����һ���ϴ�API*/
//��path��Ϊ�գ����������Ĵ洢·��
//����ֵ: 0-�ɹ���<0ʧ�ܣ���ͬ
-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);
/*��ʽ�ϴ�API*/
//����ֵ: ��ΪNULL���ʾ����ʧ�ܣ�����tango_cache_ctx_error�鿴�������Ƿ���CACHE_OUTOF_MEMORY(�����������)��
-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);
//����ֵ: 0-�ɹ���<0ʧ�ܣ�����tango_cache_get_last_error�鿴�����룻
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);
diff --git a/cache/src/cache_evbase_client.cpp b/cache/src/cache_evbase_client.cpp
index 40de5c2..0f9059b 100644
--- a/cache/src/cache_evbase_client.cpp
+++ b/cache/src/cache_evbase_client.cpp
@@ -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);
diff --git a/cache/src/tango_cache_client.cpp b/cache/src/tango_cache_client.cpp
index 2038b35..140b7e0 100644
--- a/cache/src/tango_cache_client.cpp
+++ b/cache/src/tango_cache_client.cpp
@@ -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;
}
diff --git a/cache/src/tango_cache_client_in.h b/cache/src/tango_cache_client_in.h
index 12a2fee..879bd1e 100644
--- a/cache/src/tango_cache_client_in.h
+++ b/cache/src/tango_cache_client_in.h
@@ -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�ֶ��ϴ������С����
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
diff --git a/cache/src/tango_cache_transfer.cpp b/cache/src/tango_cache_transfer.cpp
index 55b0cb6..bf7eb20 100644
--- a/cache/src/tango_cache_transfer.cpp
+++ b/cache/src/tango_cache_transfer.cpp
@@ -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) //����ʧЧ��TODO relative_age�ĺ�����ɶ
+ if(time_gmt > ctx->get.expires)
{
tango_cache_set_fail_state(ctx, CACHE_TIMEOUT);
ctx->get.state = GET_STATE_DELETE; //����ʧЧʱ���������ʱ����ɾ������
+ 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)) //�״�Ӧ��ʱ�ȿ�Ӧ�����Ƿ���200
+ if(ctx->res_code == 0) //�״�Ӧ��ʱ�ȿ�Ӧ�����Ƿ���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;
diff --git a/cache/test/cache_evbase_test.cpp b/cache/test/cache_evbase_test.cpp
index f4b4ddd..9670cbc 100644
--- a/cache/test/cache_evbase_test.cpp
+++ b/cache/test/cache_evbase_test.cpp
@@ -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 //����
- {
- 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];
diff --git a/cache/test/cache_evbase_test_threads.cpp b/cache/test/cache_evbase_test_threads.cpp
index 20bc861..9d3827b 100644
--- a/cache/test/cache_evbase_test_threads.cpp
+++ b/cache/test/cache_evbase_test_threads.cpp
@@ -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 //����
- {
- 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));
diff --git a/cache/test/tango_cache_test.c b/cache/test/tango_cache_test.c
index b8102c0..36a2bc3 100644
--- a/cache/test/tango_cache_test.c
+++ b/cache/test/tango_cache_test.c
@@ -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");