HEAD object元信息来源选择由宏定义改为配置文件。
This commit is contained in:
15
cache/src/cache_evbase_client.cpp
vendored
15
cache/src/cache_evbase_client.cpp
vendored
@@ -17,9 +17,7 @@
|
||||
#include "cache_evbase_client.h"
|
||||
#include "tango_cache_transfer.h"
|
||||
#include "tango_cache_tools.h"
|
||||
#ifdef HEAD_OBJECT_FROM_REDIS
|
||||
#include "tango_cache_redis.h"
|
||||
#endif
|
||||
|
||||
enum CACHE_ASYN_CMD
|
||||
{
|
||||
@@ -163,11 +161,14 @@ static void cache_asyn_ioevent_dispatch(struct databuffer *buffer)
|
||||
cache_asyn_ctx_destroy(ctx_asyn);
|
||||
break;
|
||||
case CACHE_ASYN_HEAD:
|
||||
#ifdef HEAD_OBJECT_FROM_REDIS
|
||||
tango_cache_head_redis(ctx_asyn->ctx);
|
||||
#else
|
||||
tango_cache_fetch_start(ctx_asyn->ctx);
|
||||
#endif
|
||||
if(ctx_asyn->instance_asyn->instance->head_meta_source == HEAD_META_FROM_REDIS)
|
||||
{
|
||||
tango_cache_head_redis(ctx_asyn->ctx);
|
||||
}
|
||||
else
|
||||
{
|
||||
tango_cache_fetch_start(ctx_asyn->ctx);
|
||||
}
|
||||
cache_asyn_ctx_destroy(ctx_asyn);
|
||||
break;
|
||||
|
||||
|
||||
54
cache/src/tango_cache_client.cpp
vendored
54
cache/src/tango_cache_client.cpp
vendored
@@ -17,9 +17,7 @@
|
||||
#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;
|
||||
|
||||
@@ -491,11 +489,15 @@ int tango_cache_head_object(struct tango_cache_instance *instance, struct future
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
#ifdef HEAD_OBJECT_FROM_REDIS
|
||||
return tango_cache_head_redis(ctx);
|
||||
#else
|
||||
return tango_cache_fetch_start(ctx);
|
||||
#endif
|
||||
|
||||
if(ctx->instance->head_meta_source == HEAD_META_FROM_REDIS)
|
||||
{
|
||||
return tango_cache_head_redis(ctx);
|
||||
}
|
||||
else
|
||||
{
|
||||
return tango_cache_fetch_start(ctx);
|
||||
}
|
||||
}
|
||||
|
||||
struct tango_cache_ctx *tango_cache_delete_prepare(struct tango_cache_instance *instance, struct future* f, const char *objkey)
|
||||
@@ -761,15 +763,18 @@ static int load_local_configure(struct tango_cache_instance *instance, const cha
|
||||
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_load_profile_int_def(profile_path, section, "CACHE_HEAD_FROM_SOURCE", &instance->head_meta_source, HEAD_META_FROM_MINIO);
|
||||
if(instance->head_meta_source == HEAD_META_FROM_REDIS)
|
||||
{
|
||||
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_string_def(profile_path, section, "CACHE_HEAD_REDIS_KEY", instance->redis_key, 256, instance->bucketname);
|
||||
if(MESA_load_profile_string_nodef(profile_path, section, "CACHE_HEAD_REDIS_IP", instance->redis_ip, 256) < 0)
|
||||
{
|
||||
MESA_HANDLE_RUNTIME_LOGV2(instance->runtime_log, RLOG_LV_FATAL, "Load config %s [%s] CACHE_HEAD_REDIS_IP not found.\n", profile_path, section);
|
||||
return -1;
|
||||
}
|
||||
MESA_load_profile_int_def(profile_path, section, "CACHE_HEAD_REDIS_PORT", &instance->redis_port, 6379);
|
||||
}
|
||||
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)
|
||||
@@ -829,18 +834,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))
|
||||
if(instance->head_meta_source == HEAD_META_FROM_REDIS)
|
||||
{
|
||||
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;
|
||||
if(redis_asyn_connect_init(instance))
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
10
cache/src/tango_cache_client_in.h
vendored
10
cache/src/tango_cache_client_in.h
vendored
@@ -6,9 +6,7 @@
|
||||
|
||||
#include <event2/event.h>
|
||||
#include <event.h>
|
||||
#ifdef HEAD_OBJECT_FROM_REDIS
|
||||
#include <hiredis/async.h>
|
||||
#endif
|
||||
|
||||
#include <MESA/wiredLB.h>
|
||||
#include "tango_cache_client.h"
|
||||
@@ -17,6 +15,9 @@
|
||||
#define RESPONSE_HDR_LAST_MOD 2
|
||||
#define RESPONSE_HDR_ALL 3
|
||||
|
||||
#define HEAD_META_FROM_MINIO 1
|
||||
#define HEAD_META_FROM_REDIS 2
|
||||
|
||||
enum CACHE_REQUEST_METHOD
|
||||
{
|
||||
CACHE_REQUEST_GET=0,
|
||||
@@ -71,13 +72,14 @@ 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;
|
||||
#ifdef HEAD_OBJECT_FROM_REDIS
|
||||
|
||||
int head_meta_source; //<2F><><EFBFBD>Դ<EFBFBD>MINIO<49><4F>REDIS<49><53>ȡԪ<C8A1><D4AA>Ϣ
|
||||
//Ԫ<><D4AA>Ϣ<EFBFBD><CFA2>ȡ<EFBFBD><C8A1>ʽRedis
|
||||
redisAsyncContext *redis_ac;
|
||||
char redis_key[256];
|
||||
char redis_ip[128];
|
||||
int redis_port;
|
||||
int redis_connecting;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct multipart_etag_list
|
||||
|
||||
10
cache/src/tango_cache_redis.cpp
vendored
10
cache/src/tango_cache_redis.cpp
vendored
@@ -70,9 +70,9 @@ void redis_asyn_connect_cb(const struct redisAsyncContext *ac, int status)
|
||||
}
|
||||
}
|
||||
|
||||
int redis_asyn_connect_init(struct tango_cache_instance *instance, const char *redisip, int redis_port)
|
||||
int redis_asyn_connect_init(struct tango_cache_instance *instance)
|
||||
{
|
||||
instance->redis_ac = redisAsyncConnect(redisip, redis_port);
|
||||
instance->redis_ac = redisAsyncConnect(instance->redis_ip, instance->redis_port);
|
||||
if(instance->redis_ac == NULL)
|
||||
{
|
||||
return -1;
|
||||
@@ -226,10 +226,10 @@ int tango_cache_head_redis(struct tango_cache_ctx *ctx)
|
||||
case CACHE_REDIS_CONNECTED:
|
||||
ret = redisAsyncCommand(ctx->instance->redis_ac, redis_hget_command_cb, ctx, "HGET %s %s/%s",
|
||||
ctx->instance->redis_key, ctx->instance->bucketname, ctx->object_key);
|
||||
if(ret < 0)
|
||||
if(ret != REDIS_OK)
|
||||
{
|
||||
//redisAsyncDisconnect(ctx->instance->redis_ac);
|
||||
redis_asyn_connect_init(ctx->instance, ctx->instance->redis_ip, ctx->instance->redis_port);
|
||||
redis_asyn_connect_init(ctx->instance);
|
||||
tango_cache_set_fail_state(ctx, CACHE_ERR_REDIS_CONNECT);
|
||||
promise_failed(future_to_promise(ctx->future), FUTURE_ERROR_CANCEL, tango_cache_get_errstring(ctx));
|
||||
tango_cache_ctx_destroy(ctx);
|
||||
@@ -237,7 +237,7 @@ int tango_cache_head_redis(struct tango_cache_ctx *ctx)
|
||||
break;
|
||||
case CACHE_REDIS_DISCONNECTED:
|
||||
case CACHE_REDIS_CONNECT_IDLE:
|
||||
redis_asyn_connect_init(ctx->instance, ctx->instance->redis_ip, ctx->instance->redis_port);
|
||||
redis_asyn_connect_init(ctx->instance);
|
||||
case CACHE_REDIS_CONNECTING:
|
||||
tango_cache_set_fail_state(ctx, CACHE_ERR_REDIS_CONNECT);
|
||||
promise_failed(future_to_promise(ctx->future), FUTURE_ERROR_CANCEL, tango_cache_get_errstring(ctx));
|
||||
|
||||
2
cache/src/tango_cache_redis.h
vendored
2
cache/src/tango_cache_redis.h
vendored
@@ -7,7 +7,7 @@
|
||||
#include "tango_cache_client_in.h"
|
||||
|
||||
int tango_cache_head_redis(struct tango_cache_ctx *ctx);
|
||||
int redis_asyn_connect_init(struct tango_cache_instance *instance, const char *redisip, int redis_port);
|
||||
int redis_asyn_connect_init(struct tango_cache_instance *instance);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user