支持Head获取对象元信息操作,支持从redis获取元信息;调整内部超时检查逻辑;
This commit is contained in:
58
cache/src/tango_cache_client.cpp
vendored
58
cache/src/tango_cache_client.cpp
vendored
@@ -17,6 +17,9 @@
|
||||
#include "tango_cache_transfer.h"
|
||||
#include "tango_cache_tools.h"
|
||||
#include "tango_cache_xml.h"
|
||||
#ifdef HEAD_OBJECT_FROM_REDIS
|
||||
#include "tango_cache_redis.h"
|
||||
#endif
|
||||
|
||||
int TANGO_CACHE_VERSION_20181009=0;
|
||||
|
||||
@@ -91,6 +94,8 @@ const char *tango_cache_get_errstring(const struct tango_cache_ctx *ctx)
|
||||
case CACHE_ERR_WIREDLB: return "wiredlb error";
|
||||
case CACHE_ERR_SOCKPAIR:return "socketpair error";
|
||||
case CACHE_ERR_INTERNAL:return "internal error";
|
||||
case CACHE_ERR_REDIS_JSON:return "parse redis json error";
|
||||
case CACHE_ERR_REDIS_CONNECT:return "redis is not connected";
|
||||
default: return ctx->error;
|
||||
}
|
||||
}
|
||||
@@ -137,6 +142,7 @@ static void update_statistics(struct tango_cache_ctx *ctx, struct cache_statisti
|
||||
}
|
||||
break;
|
||||
case CACHE_REQUEST_GET:
|
||||
case CACHE_REQUEST_HEAD:
|
||||
if(ctx->fail_state)
|
||||
{
|
||||
if(ctx->error_code == CACHE_CACHE_MISS || ctx->error_code == CACHE_TIMEOUT)
|
||||
@@ -204,6 +210,7 @@ void tango_cache_ctx_destroy(struct tango_cache_ctx *ctx)
|
||||
switch(ctx->method)
|
||||
{
|
||||
case CACHE_REQUEST_GET:
|
||||
case CACHE_REQUEST_HEAD:
|
||||
easy_string_destroy(&ctx->get.response_tag);
|
||||
break;
|
||||
|
||||
@@ -431,7 +438,7 @@ 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* f, struct tango_cache_meta_get *meta)
|
||||
struct tango_cache_ctx *tango_cache_fetch_prepare(struct tango_cache_instance *instance, enum CACHE_REQUEST_METHOD method, struct future* f, struct tango_cache_meta_get *meta)
|
||||
{
|
||||
struct tango_cache_ctx *ctx;
|
||||
char sha256[72];
|
||||
@@ -439,7 +446,7 @@ struct tango_cache_ctx *tango_cache_fetch_prepare(struct tango_cache_instance *i
|
||||
ctx = (struct tango_cache_ctx *)calloc(1, sizeof(struct tango_cache_ctx));
|
||||
ctx->instance = instance;
|
||||
ctx->future = f;
|
||||
ctx->method = CACHE_REQUEST_GET;
|
||||
ctx->method = method;
|
||||
ctx->get.state = GET_STATE_START;
|
||||
ctx->get.max_age = meta->get.max_age;
|
||||
ctx->get.min_fresh = meta->get.min_fresh;
|
||||
@@ -467,7 +474,7 @@ int tango_cache_fetch_object(struct tango_cache_instance *instance, struct futur
|
||||
{
|
||||
struct tango_cache_ctx *ctx;
|
||||
|
||||
ctx = tango_cache_fetch_prepare(instance, f, meta);
|
||||
ctx = tango_cache_fetch_prepare(instance, CACHE_REQUEST_GET, f, meta);
|
||||
if(ctx == NULL)
|
||||
{
|
||||
return -1;
|
||||
@@ -475,6 +482,22 @@ int tango_cache_fetch_object(struct tango_cache_instance *instance, struct futur
|
||||
return tango_cache_fetch_start(ctx);
|
||||
}
|
||||
|
||||
int tango_cache_head_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, CACHE_REQUEST_HEAD, f, meta);
|
||||
if(ctx == NULL)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
#ifdef HEAD_OBJECT_FROM_REDIS
|
||||
return tango_cache_head_redis(ctx);
|
||||
#else
|
||||
return tango_cache_fetch_start(ctx);
|
||||
#endif
|
||||
}
|
||||
|
||||
struct tango_cache_ctx *tango_cache_delete_prepare(struct tango_cache_instance *instance, struct future* f, const char *objkey)
|
||||
{
|
||||
struct tango_cache_ctx *ctx;
|
||||
@@ -585,6 +608,7 @@ static void check_multi_info(CURLM *multi)
|
||||
switch(ctx->method)
|
||||
{
|
||||
case CACHE_REQUEST_GET:
|
||||
case CACHE_REQUEST_HEAD:
|
||||
tango_cache_curl_get_done(ctx, res, res_code);
|
||||
break;
|
||||
case CACHE_REQUEST_PUT:
|
||||
@@ -732,7 +756,20 @@ static int load_local_configure(struct tango_cache_instance *instance, const cha
|
||||
MESA_load_profile_uint_def(profile_path, section, "MAX_USED_MEMORY_SIZE_MB", &intval, 5120);
|
||||
longval = intval;
|
||||
instance->cache_limit_size = longval * 1024 * 1024;
|
||||
MESA_load_profile_string_def(profile_path, section, "CACHE_BUCKET_NAME", instance->bucketname, 256, "openbucket");
|
||||
if(MESA_load_profile_string_nodef(profile_path, section, "CACHE_BUCKET_NAME", instance->bucketname, 256) < 0)
|
||||
{
|
||||
MESA_HANDLE_RUNTIME_LOGV2(instance->runtime_log, RLOG_LV_FATAL, "Load config %s [%s] CACHE_BUCKET_NAME not found.\n", profile_path, section);
|
||||
return -1;
|
||||
}
|
||||
#ifdef HEAD_OBJECT_FROM_REDIS
|
||||
MESA_load_profile_string_def(profile_path, section, "CACHE_REDIS_KEY", instance->redis_key, 256, instance->bucketname);
|
||||
if(MESA_load_profile_string_nodef(profile_path, section, "CACHE_REDIS_IP", instance->redis_ip, 256) < 0)
|
||||
{
|
||||
MESA_HANDLE_RUNTIME_LOGV2(instance->runtime_log, RLOG_LV_FATAL, "Load config %s [%s] CACHE_REDIS_IP not found.\n", profile_path, section);
|
||||
return -1;
|
||||
}
|
||||
MESA_load_profile_int_def(profile_path, section, "CACHE_REDIS_PORT", &instance->redis_port, 6379);
|
||||
#endif
|
||||
MESA_load_profile_uint_def(profile_path, section, "CACHE_OBJECT_KEY_HASH_SWITCH", &instance->hash_object_key, 1);
|
||||
MESA_load_profile_uint_def(profile_path, section, "MINIO_LISTEN_PORT", &instance->minio_port, 9000);
|
||||
if(MESA_load_profile_string_nodef(profile_path, section, "MINIO_IP_LIST", instance->minio_iplist, 4096) < 0)
|
||||
@@ -792,8 +829,19 @@ struct tango_cache_instance *tango_cache_instance_new(struct event_base* evbase,
|
||||
curl_multi_setopt(instance->multi_hd, CURLMOPT_TIMERFUNCTION, curl_timer_function_cb);
|
||||
curl_multi_setopt(instance->multi_hd, CURLMOPT_TIMERDATA, instance);
|
||||
|
||||
#ifdef HEAD_OBJECT_FROM_REDIS
|
||||
if(redis_asyn_connect_init(instance, instance->redis_ip, instance->redis_port))
|
||||
{
|
||||
MESA_HANDLE_RUNTIME_LOGV2(instance->runtime_log, RLOG_LV_FATAL, "redis_asyn_connect_init %s:%u failed.", instance->redis_ip, instance->redis_port);
|
||||
free(instance);
|
||||
return NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
MESA_HANDLE_RUNTIME_LOGV2(instance->runtime_log, RLOG_LV_FATAL, "redis_asyn_connect_init %s:%u success.", instance->redis_ip, instance->redis_port);
|
||||
}
|
||||
#endif
|
||||
evtimer_assign(&instance->timer_event, evbase, libevent_timer_event_cb, instance);
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user