增加集群版redis作为元信息和对象缓存,去除Minio事件通知的redis元信息获取方式。

This commit is contained in:
zhangchengwei
2018-12-14 15:07:09 +08:00
committed by zhengchao
parent 08ae82932a
commit d24c57ce85
32 changed files with 1561 additions and 909 deletions

View File

@@ -12,6 +12,7 @@
#include "tango_cache_transfer.h"
#include "tango_cache_xml.h"
#include "tango_cache_tools.h"
#include "tango_cache_redis.h"
static inline void curl_set_common_options(CURL *curl, long transfer_timeout, char *errorbuf)
{
@@ -297,6 +298,11 @@ bool cache_kick_upload_minio_multipart(struct tango_cache_ctx *ctx, size_t block
switch(ctx->put.state)
{
case PUT_STATE_START:
if(sessions_exceeds_limit(ctx->instance, OBJECT_IN_MINIO))
{
tango_cache_set_fail_state(ctx, CACHE_OUTOF_SESSION);
return false;
}
ctx->put.state = PUT_STATE_WAIT_START;
ret = curl_get_minio_uploadID(ctx);
break;
@@ -343,20 +349,33 @@ static int http_put_complete_part_evbuf(struct tango_cache_ctx *ctx, bool callba
return ret;
}
void cache_kick_upload_minio_end(struct tango_cache_ctx *ctx)
int do_tango_cache_update_end(struct tango_cache_ctx *ctx, bool callback)
{
DBG_CACHE("state: %d, key: %s, curl %s NULL\n", ctx->put.state, ctx->object_key, (ctx->curl==NULL)?"is":"is not");
ctx->put.close_state = true;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬<D7B4><CCAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>رգ<D8B1><D5A3>ڲ<EFBFBD>״̬<D7B4><CCAC><EFBFBD><EFBFBD>ת<EFBFBD><D7AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٹر<D9B9>
if(ctx->fail_state)
{
tango_cache_ctx_destroy(ctx);
return;
tango_cache_ctx_destroy(ctx, callback);
return -1;
}
switch(ctx->put.state)
{
case PUT_STATE_START:
http_put_complete_part_evbuf(ctx, true);
case PUT_STATE_START: //<2F><>ʱ<EFBFBD><CAB1>ͬ<EFBFBD><CDAC><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD>
if(sessions_exceeds_limit(ctx->instance, ctx->locate))
{
tango_cache_set_fail_state(ctx, CACHE_OUTOF_SESSION);
tango_cache_ctx_destroy(ctx, callback);
return -1;
}
if(ctx->locate == OBJECT_IN_MINIO)
{
return http_put_complete_part_evbuf(ctx, callback);
}
else
{
return redis_put_complete_part_evbuf(ctx, ctx->put.object_size, callback);
}
break;
case PUT_STATE_PART:
@@ -373,6 +392,7 @@ void cache_kick_upload_minio_end(struct tango_cache_ctx *ctx)
{
tango_cache_set_fail_state(ctx, CACHE_ERR_CURL);
tango_cache_ctx_destroy(ctx);
return -1;
}
}
else if(http_put_bodypart_request_evbuf(ctx, false) <= 0)
@@ -385,6 +405,7 @@ void cache_kick_upload_minio_end(struct tango_cache_ctx *ctx)
else
{
tango_cache_ctx_destroy(ctx);
return -1;
}
}
}
@@ -394,6 +415,7 @@ void cache_kick_upload_minio_end(struct tango_cache_ctx *ctx)
case PUT_STATE_WAIT_START: //<2F><>ʱδ<CAB1><CEB4>ȡ<EFBFBD><C8A1>uploadId<49><64><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>޷<EFBFBD><DEB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD>
default: break;
}
return 0;
}
void tango_cache_curl_put_done(struct tango_cache_ctx *ctx, CURLcode res, long res_code)
@@ -417,7 +439,7 @@ void tango_cache_curl_put_done(struct tango_cache_ctx *ctx, CURLcode res, long r
ctx->put.state = PUT_STATE_PART;
if(ctx->put.close_state)
{
cache_kick_upload_minio_end(ctx);
do_tango_cache_update_end(ctx, true);
}
else
{
@@ -448,7 +470,7 @@ void tango_cache_curl_put_done(struct tango_cache_ctx *ctx, CURLcode res, long r
}
else if(ctx->put.close_state)
{
cache_kick_upload_minio_end(ctx);
do_tango_cache_update_end(ctx, true);
}
else
{
@@ -472,24 +494,30 @@ void tango_cache_curl_put_done(struct tango_cache_ctx *ctx, CURLcode res, long r
{
tango_cache_set_fail_state(ctx, CACHE_ERR_CURL);
}
tango_cache_ctx_destroy(ctx);
if(ctx->instance->param->object_store_way!=CACHE_ALL_MINIO && !ctx->fail_state)
{
redis_put_minio_object_meta(ctx, true);
}
else
{
tango_cache_ctx_destroy(ctx);
}
break;
default: break;
}
}
int tango_cache_upload_once_start_data(struct tango_cache_ctx *ctx, enum PUT_MEMORY_COPY_WAY way, const char *data, size_t size, bool callback)
int http_put_complete_part_data(struct tango_cache_ctx *ctx, enum PUT_MEMORY_COPY_WAY way, const char *data, size_t size, bool callback)
{
CURLMcode rc;
char minio_url[256];
ctx->instance->statistic.put_recv_num += 1;
ctx->instance->error_code = CACHE_OK;
if(NULL == (ctx->curl=curl_easy_init()))
{
tango_cache_set_fail_state(ctx, CACHE_ERR_CURL);
tango_cache_ctx_destroy(ctx, callback);
if(way == PUT_MEM_FREE) free((void *)data);
ctx->instance->statistic.memory_used -= size;
return -1;
}
ctx->put.state = PUT_STATE_END;
@@ -513,7 +541,6 @@ int tango_cache_upload_once_start_data(struct tango_cache_ctx *ctx, enum PUT_MEM
}
ctx->response.size = size;
ctx->response.len = 0;
ctx->instance->statistic.memory_used += size;
curl_easy_setopt(ctx->curl, CURLOPT_UPLOAD, 1L);
curl_easy_setopt(ctx->curl, CURLOPT_INFILESIZE, ctx->response.size);
curl_easy_setopt(ctx->curl, CURLOPT_READFUNCTION, curl_put_once_send_cb);
@@ -524,19 +551,34 @@ int tango_cache_upload_once_start_data(struct tango_cache_ctx *ctx, enum PUT_MEM
return 0;
}
int tango_cache_upload_once_start_evbuf(struct tango_cache_ctx *ctx, enum EVBUFFER_COPY_WAY way, struct evbuffer *evbuf, bool callback)
int do_tango_cache_upload_once_data(struct tango_cache_ctx *ctx, enum PUT_MEMORY_COPY_WAY way, const char *data, size_t size, bool callback)
{
ctx->instance->statistic.put_recv_num += 1;
ctx->instance->statistic.memory_used += size;
ctx->instance->error_code = CACHE_OK;
if(ctx->locate == OBJECT_IN_MINIO)
{
return http_put_complete_part_data(ctx, way, data, size, false);
}
else
{
return redis_put_complete_part_data(ctx, way, data, size, false);
}
}
int do_tango_cache_upload_once_evbuf(struct tango_cache_ctx *ctx, enum EVBUFFER_COPY_WAY way, struct evbuffer *evbuf, bool callback)
{
size_t size;
ctx->instance->statistic.put_recv_num += 1;
ctx->instance->error_code = CACHE_OK;
size = evbuffer_get_length(evbuf);
if(way == EVBUFFER_MOVE)
{
if(evbuffer_add_buffer(ctx->put.evbuf, evbuf))
{
tango_cache_set_fail_state(ctx, CACHE_OUTOF_MEMORY);
tango_cache_set_fail_state(ctx, CACHE_ERR_EVBUFFER);
tango_cache_ctx_destroy(ctx, callback);
return -1;
}
@@ -545,14 +587,22 @@ int tango_cache_upload_once_start_evbuf(struct tango_cache_ctx *ctx, enum EVBUFF
{
if(evbuffer_add_buffer_reference(ctx->put.evbuf, evbuf))
{
tango_cache_set_fail_state(ctx, CACHE_OUTOF_MEMORY);
tango_cache_set_fail_state(ctx, CACHE_ERR_EVBUFFER);
tango_cache_ctx_destroy(ctx, callback);
return -1;
}
}
size = evbuffer_get_length(ctx->put.evbuf);
ctx->instance->statistic.memory_used += size;
return http_put_complete_part_evbuf(ctx, callback);
if(ctx->locate == OBJECT_IN_MINIO)
{
return http_put_complete_part_evbuf(ctx, callback);
}
else
{
return redis_put_complete_part_evbuf(ctx, size, callback);
}
}
void tango_cache_curl_del_done(struct tango_cache_ctx *ctx, CURLcode res, long res_code)
@@ -594,7 +644,7 @@ void tango_cache_curl_muldel_done(struct tango_cache_ctx *ctx, CURLcode res, lon
tango_cache_ctx_destroy(ctx);
}
int tango_cache_multi_delete_start(struct tango_cache_ctx *ctx, bool callback)
int do_tango_cache_multi_delete(struct tango_cache_ctx *ctx, bool callback)
{
CURLMcode rc;
char minio_url[256];
@@ -754,6 +804,7 @@ static size_t curl_get_response_header_cb(void *ptr, size_t size, size_t count,
{
return raw_len;
}
ctx->get.result.location = OBJECT_IN_MINIO;
}
pos_colon = (char*)memchr(start, ':', raw_len);
if(pos_colon == NULL)
@@ -839,12 +890,11 @@ void tango_cache_curl_get_done(struct tango_cache_ctx *ctx, CURLcode res, long r
}
}
int tango_cache_fetch_start(struct tango_cache_ctx *ctx)
static int tango_cache_fetch_minio(struct tango_cache_ctx *ctx)
{
CURLMcode rc;
char minio_url[256];
ctx->instance->statistic.get_recv_num += 1;
if(NULL == (ctx->curl=curl_easy_init()))
{
tango_cache_ctx_destroy(ctx);
@@ -869,3 +919,52 @@ int tango_cache_fetch_start(struct tango_cache_ctx *ctx)
return 1;
}
static void redis_redirect_object2minio_cb(struct tango_cache_ctx *ctx)
{
struct promise *p = ctx->promise;
ctx->get.state = GET_STATE_START;
ctx->locate = OBJECT_IN_MINIO;
if(ctx->instance->statistic.session_http>=ctx->instance->param->maximum_sessions)
{
tango_cache_set_fail_state(ctx, CACHE_OUTOF_MEMORY);
promise_failed(p, FUTURE_ERROR_CANCEL, tango_cache_get_errstring(ctx));
tango_cache_ctx_destroy(ctx);
}
else if(tango_cache_fetch_minio(ctx) != 1)
{
promise_failed(p, FUTURE_ERROR_CANCEL, "tango_cache_fetch_minio failed");
}
}
int do_tango_cache_fetch_object(struct tango_cache_ctx *ctx, enum OBJECT_LOCATION where_to_get)
{
ctx->instance->statistic.get_recv_num += 1;
switch(where_to_get)
{
case OBJECT_IN_MINIO:
ctx->locate = OBJECT_IN_MINIO;
return (tango_cache_fetch_minio(ctx)==1)?0:-2;
case OBJECT_IN_REDIS:
ctx->locate = OBJECT_IN_REDIS;
return tango_cache_fetch_redis(ctx);
default:
ctx->get.redis_redirect_minio_cb = redis_redirect_object2minio_cb;
return tango_cache_try_fetch_redis(ctx);
}
return 0;
}
int do_tango_cache_head_object(struct tango_cache_ctx *ctx, enum OBJECT_LOCATION where_to_head)
{
ctx->instance->statistic.get_recv_num += 1;
if(where_to_head == OBJECT_IN_REDIS)
{
return tango_cache_head_redis(ctx);
}
else
{
return (tango_cache_fetch_minio(ctx)==1)?0:-1;
}
}