修改FETCH API函数名为tango_cache_fetch_object;增加DELETE API;调整ctx结构体内部结构;
This commit is contained in:
63
cache/cache_evbase_client.cpp
vendored
63
cache/cache_evbase_client.cpp
vendored
@@ -26,6 +26,7 @@ enum CACHE_ASYN_CMD
|
||||
CACHE_ASYN_UPLOAD_FRAG_DATA,
|
||||
CACHE_ASYN_UPLOAD_FRAG_EVBUF,
|
||||
CACHE_ASYN_UPLOAD_END,
|
||||
CACHE_ASYN_DELETE,
|
||||
};
|
||||
|
||||
struct databuffer
|
||||
@@ -157,6 +158,11 @@ static void cache_asyn_ioevent_dispatch(struct databuffer *buffer)
|
||||
cache_asyn_ctx_destroy(ctx_asyn);
|
||||
break;
|
||||
|
||||
case CACHE_ASYN_DELETE:
|
||||
cache_delete_minio_object(ctx_asyn->ctx);
|
||||
cache_asyn_ctx_destroy(ctx_asyn);
|
||||
break;
|
||||
|
||||
case CACHE_ASYN_UPLOAD_ONCE_DATA:
|
||||
tango_cache_upload_once_start_data(ctx_asyn->ctx, PUT_MEM_FREE, buffer->data, buffer->size);
|
||||
cache_asyn_ctx_destroy(ctx_asyn);
|
||||
@@ -234,23 +240,19 @@ void cache_evbase_update_end(struct cache_evbase_ctx *ctx_asyn)
|
||||
{
|
||||
struct databuffer *buffer;
|
||||
|
||||
if(ctx_asyn->ctx->fail_state)
|
||||
{
|
||||
tango_cache_ctx_destroy(ctx_asyn->ctx);
|
||||
cache_asyn_ctx_destroy(ctx_asyn);
|
||||
return;
|
||||
}
|
||||
|
||||
buffer = (struct databuffer *)malloc(sizeof(struct databuffer));
|
||||
buffer->ctx_asyn = ctx_asyn;
|
||||
buffer->cmd_type = CACHE_ASYN_UPLOAD_END;
|
||||
|
||||
if(iothread_notify_event(ctx_asyn->instance_asyn->notify_sendfd, &buffer, sizeof(void *), 0) != sizeof(void *))
|
||||
{
|
||||
ctx_asyn->ctx->fail_state = true;
|
||||
if(ctx_asyn->ctx->future != NULL)
|
||||
if(!ctx_asyn->ctx->fail_state)
|
||||
{
|
||||
promise_failed(future_to_promise(ctx_asyn->ctx->future), FUTURE_ERROR_CANCEL, "write sockpair error");
|
||||
ctx_asyn->ctx->fail_state = true;
|
||||
if(ctx_asyn->ctx->future != NULL)
|
||||
{
|
||||
promise_failed(future_to_promise(ctx_asyn->ctx->future), FUTURE_ERROR_CANCEL, "write sockpair error");
|
||||
}
|
||||
}
|
||||
tango_cache_ctx_destroy(ctx_asyn->ctx);
|
||||
cache_asyn_ctx_destroy(ctx_asyn);
|
||||
@@ -292,7 +294,6 @@ int cache_evbase_update_frag_data(struct cache_evbase_ctx *ctx_asyn, enum PUT_ME
|
||||
free(buffer);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -379,11 +380,6 @@ int cache_evbase_upload_once_data(struct cache_evbase_instance *instance, struct
|
||||
|
||||
if(iothread_notify_event(instance->notify_sendfd, &buffer, sizeof(void *), 0) != sizeof(void *))
|
||||
{
|
||||
ctx_asyn->ctx->fail_state = true;
|
||||
if(ctx_asyn->ctx->future != NULL)
|
||||
{
|
||||
promise_failed(future_to_promise(ctx_asyn->ctx->future), FUTURE_ERROR_CANCEL, "write sockpair error");
|
||||
}
|
||||
free(buffer->data);
|
||||
free(buffer);
|
||||
tango_cache_ctx_destroy(ctx);
|
||||
@@ -422,11 +418,6 @@ int cache_evbase_upload_once_evbuf(struct cache_evbase_instance *instance, struc
|
||||
|
||||
if(iothread_notify_event(instance->notify_sendfd, &buffer, sizeof(void *), 0) != sizeof(void *))
|
||||
{
|
||||
ctx_asyn->ctx->fail_state = true;
|
||||
if(ctx_asyn->ctx->future != NULL)
|
||||
{
|
||||
promise_failed(future_to_promise(ctx_asyn->ctx->future), FUTURE_ERROR_CANCEL, "write sockpair error");
|
||||
}
|
||||
evbuffer_free(buffer->evbuf);
|
||||
free(buffer);
|
||||
tango_cache_ctx_destroy(ctx);
|
||||
@@ -436,7 +427,7 @@ int cache_evbase_upload_once_evbuf(struct cache_evbase_instance *instance, struc
|
||||
return 0;
|
||||
}
|
||||
|
||||
int cache_evbase_fetch(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* future, struct tango_cache_meta *meta)
|
||||
{
|
||||
struct cache_evbase_ctx *ctx_asyn;
|
||||
struct databuffer *buffer;
|
||||
@@ -451,11 +442,29 @@ int cache_evbase_fetch(struct cache_evbase_instance *instance, struct future* fu
|
||||
|
||||
if(iothread_notify_event(instance->notify_sendfd, &buffer, sizeof(void *), 0) != sizeof(void *))
|
||||
{
|
||||
ctx_asyn->ctx->fail_state = true;
|
||||
if(ctx_asyn->ctx->future != NULL)
|
||||
{
|
||||
promise_failed(future_to_promise(ctx_asyn->ctx->future), FUTURE_ERROR_CANCEL, "write sockpair error");
|
||||
}
|
||||
tango_cache_ctx_destroy(ctx_asyn->ctx);
|
||||
cache_asyn_ctx_destroy(ctx_asyn);
|
||||
free(buffer);
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int cache_evbase_delete_object(struct cache_evbase_instance *instance, struct future* future, 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);
|
||||
|
||||
buffer = (struct databuffer *)malloc(sizeof(struct databuffer));
|
||||
buffer->ctx_asyn = ctx_asyn;
|
||||
buffer->cmd_type = CACHE_ASYN_DELETE;
|
||||
|
||||
if(iothread_notify_event(instance->notify_sendfd, &buffer, sizeof(void *), 0) != sizeof(void *))
|
||||
{
|
||||
tango_cache_ctx_destroy(ctx_asyn->ctx);
|
||||
cache_asyn_ctx_destroy(ctx_asyn);
|
||||
free(buffer);
|
||||
|
||||
Reference in New Issue
Block a user