2018-09-18 11:14:11 +08:00
|
|
|
|
#ifndef __TANGO_CACHE_CLIENT_IN_H__
|
|
|
|
|
|
#define __TANGO_CACHE_CLIENT_IN_H__
|
|
|
|
|
|
|
|
|
|
|
|
#include <curl/curl.h>
|
|
|
|
|
|
#include <sys/queue.h>
|
|
|
|
|
|
|
|
|
|
|
|
#include <event2/event.h>
|
|
|
|
|
|
#include <event.h>
|
2018-12-14 15:07:09 +08:00
|
|
|
|
#include <hiredis-vip/async.h>
|
|
|
|
|
|
#include <hiredis-vip/hircluster.h>
|
|
|
|
|
|
#include <cjson/cJSON.h>
|
2018-09-18 11:14:11 +08:00
|
|
|
|
|
2018-09-29 17:10:19 +08:00
|
|
|
|
#include <MESA/wiredLB.h>
|
2018-09-18 11:14:11 +08:00
|
|
|
|
#include "tango_cache_client.h"
|
|
|
|
|
|
|
2018-09-21 14:50:41 +08:00
|
|
|
|
#define RESPONSE_HDR_EXPIRES 1
|
|
|
|
|
|
#define RESPONSE_HDR_LAST_MOD 2
|
|
|
|
|
|
#define RESPONSE_HDR_ALL 3
|
|
|
|
|
|
|
2018-12-14 15:07:09 +08:00
|
|
|
|
#define CACHE_ALL_MINIO 0 //Ԫ<><D4AA>Ϣ<EFBFBD>Ͷ<EFBFBD><CDB6><EFBFBD><F3B6BCB4><EFBFBD>MINIO
|
|
|
|
|
|
#define CACHE_META_REDIS 1 //Ԫ<><D4AA>Ϣ<EFBFBD><CFA2>REDIS<49><53><EFBFBD><EFBFBD><EFBFBD><EFBFBD>MINIO
|
|
|
|
|
|
#define CACHE_SMALL_REDIS 2 //Ԫ<><D4AA>Ϣ<EFBFBD><CFA2>С<EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>REDIS<49><53><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>MINIO
|
2018-10-24 12:03:21 +08:00
|
|
|
|
|
2018-09-18 11:14:11 +08:00
|
|
|
|
enum CACHE_REQUEST_METHOD
|
|
|
|
|
|
{
|
|
|
|
|
|
CACHE_REQUEST_GET=0,
|
|
|
|
|
|
CACHE_REQUEST_PUT,
|
2018-09-27 15:04:56 +08:00
|
|
|
|
CACHE_REQUEST_DELETE,
|
2018-10-11 16:35:13 +08:00
|
|
|
|
CACHE_REQUEST_DELETE_MUL,
|
2018-10-23 20:26:06 +08:00
|
|
|
|
CACHE_REQUEST_HEAD,
|
2018-09-18 11:14:11 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
enum GET_OBJECT_STATE
|
|
|
|
|
|
{
|
|
|
|
|
|
GET_STATE_START=0,
|
|
|
|
|
|
GET_STATE_DELETE,
|
2018-12-14 15:07:09 +08:00
|
|
|
|
GET_STATE_REDIS_META,
|
|
|
|
|
|
GET_STATE_REDIS_ALL,
|
|
|
|
|
|
GET_STATE_REDIS_TRY,
|
2018-09-18 11:14:11 +08:00
|
|
|
|
GET_STATE_END,
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
enum PUT_OBJECT_STATE
|
|
|
|
|
|
{
|
|
|
|
|
|
PUT_STATE_START=0,
|
|
|
|
|
|
PUT_STATE_WAIT_START,
|
|
|
|
|
|
PUT_STATE_PART,
|
2018-11-25 13:49:39 +08:00
|
|
|
|
PUT_STATE_CANCEL,
|
2018-12-14 15:07:09 +08:00
|
|
|
|
PUT_STATE_REDIS_META,
|
|
|
|
|
|
PUT_STATE_REDIS_ALL,
|
|
|
|
|
|
PUT_STATE_END,
|
2018-09-18 11:14:11 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct easy_string
|
|
|
|
|
|
{
|
|
|
|
|
|
char* buff;
|
|
|
|
|
|
size_t len;
|
|
|
|
|
|
size_t size;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2018-11-07 15:05:55 +08:00
|
|
|
|
struct wiredlb_parameter
|
2018-09-18 11:14:11 +08:00
|
|
|
|
{
|
2018-12-14 15:07:09 +08:00
|
|
|
|
char wiredlb_topic[64];
|
|
|
|
|
|
char wiredlb_datacenter[64];
|
2018-09-29 17:10:19 +08:00
|
|
|
|
char wiredlb_group[64];
|
2018-12-14 15:07:09 +08:00
|
|
|
|
char iplist[4096];//minio<69>б<EFBFBD>
|
|
|
|
|
|
WLB_handle_t wiredlb;
|
|
|
|
|
|
u_int32_t wiredlb_override;
|
2018-11-07 15:05:55 +08:00
|
|
|
|
u_int32_t port;
|
|
|
|
|
|
short wiredlb_ha_port;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct tango_cache_parameter
|
|
|
|
|
|
{
|
|
|
|
|
|
char bucketname[256];
|
|
|
|
|
|
char redis_key[256];
|
2018-12-14 15:07:09 +08:00
|
|
|
|
long maximum_host_cnns;
|
2018-10-27 11:03:58 +08:00
|
|
|
|
long transfer_timeout;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2018-12-14 15:07:09 +08:00
|
|
|
|
long maximum_pipelines;
|
|
|
|
|
|
u_int64_t maximum_used_mem;
|
|
|
|
|
|
u_int32_t maximum_sessions;
|
2018-09-18 11:14:11 +08:00
|
|
|
|
u_int32_t upload_block_size; //minio<69>ֶ<EFBFBD><D6B6>ϴ<EFBFBD><CFB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С<EFBFBD><D0A1><EFBFBD><EFBFBD>
|
2018-11-07 15:05:55 +08:00
|
|
|
|
time_t relative_ttl; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч<EFBFBD><D0A7>
|
|
|
|
|
|
u_int32_t hash_object_key;
|
|
|
|
|
|
//wiredlb
|
2018-12-14 15:07:09 +08:00
|
|
|
|
int object_store_way; //<2F><>ȡobject<63><74>Ϣ<EFBFBD>ķ<EFBFBD>ʽ
|
2018-11-07 15:05:55 +08:00
|
|
|
|
struct wiredlb_parameter minio;
|
2018-12-14 15:07:09 +08:00
|
|
|
|
char redisaddrs[4096];
|
|
|
|
|
|
u_int32_t redis_object_maxsize;//С<>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>redisʱ<73><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С
|
2018-11-07 15:05:55 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct tango_cache_instance
|
|
|
|
|
|
{
|
|
|
|
|
|
struct event_base* evbase;
|
|
|
|
|
|
struct event timer_event;
|
|
|
|
|
|
CURLM *multi_hd;
|
|
|
|
|
|
enum CACHE_ERR_CODE error_code;
|
|
|
|
|
|
|
2018-10-23 20:26:06 +08:00
|
|
|
|
int redis_connecting;
|
2018-12-14 15:07:09 +08:00
|
|
|
|
redisClusterAsyncContext *redis_ac;
|
|
|
|
|
|
char redisaddr[128];
|
2018-11-07 15:05:55 +08:00
|
|
|
|
|
|
|
|
|
|
const struct tango_cache_parameter *param;
|
|
|
|
|
|
void *runtime_log;
|
|
|
|
|
|
struct cache_statistics statistic;
|
2018-09-18 11:14:11 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
2018-09-21 14:50:41 +08:00
|
|
|
|
struct multipart_etag_list
|
|
|
|
|
|
{
|
|
|
|
|
|
char *etag;
|
|
|
|
|
|
u_int32_t part_number;
|
|
|
|
|
|
TAILQ_ENTRY(multipart_etag_list) node;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2018-12-14 15:07:09 +08:00
|
|
|
|
typedef void (redisRedirectMinioCallback)(struct tango_cache_ctx *ctx);
|
|
|
|
|
|
|
2018-09-27 15:04:56 +08:00
|
|
|
|
struct cache_ctx_data_get
|
|
|
|
|
|
{
|
2018-10-15 16:38:22 +08:00
|
|
|
|
time_t max_age;
|
|
|
|
|
|
time_t min_fresh;
|
2018-09-27 15:04:56 +08:00
|
|
|
|
time_t expires;
|
|
|
|
|
|
time_t last_modify;
|
|
|
|
|
|
u_int32_t need_hdrs;
|
|
|
|
|
|
enum GET_OBJECT_STATE state;
|
|
|
|
|
|
struct easy_string response_tag;
|
2018-10-15 16:38:22 +08:00
|
|
|
|
struct tango_cache_result result;
|
2018-12-14 15:07:09 +08:00
|
|
|
|
redisRedirectMinioCallback *redis_redirect_minio_cb;
|
2018-09-27 15:04:56 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct cache_ctx_data_put
|
|
|
|
|
|
{
|
|
|
|
|
|
struct evbuffer *evbuf;
|
|
|
|
|
|
size_t upload_length;
|
|
|
|
|
|
size_t upload_offset;
|
|
|
|
|
|
char *uploadID;
|
|
|
|
|
|
char *combine_xml;
|
|
|
|
|
|
TAILQ_HEAD(__etag_list_head, multipart_etag_list) etag_head;
|
2018-12-14 15:07:09 +08:00
|
|
|
|
cJSON *object_meta;
|
2018-09-27 15:04:56 +08:00
|
|
|
|
enum PUT_OBJECT_STATE state;
|
|
|
|
|
|
u_int32_t part_index; //<2F><>RESPONSE_HDR_
|
2018-12-14 15:07:09 +08:00
|
|
|
|
u_int32_t object_ttl;
|
2018-09-27 15:04:56 +08:00
|
|
|
|
bool close_state; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ùر<C3B9>
|
2018-12-14 15:07:09 +08:00
|
|
|
|
size_t object_size;
|
2018-09-27 15:04:56 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
2018-10-11 16:35:13 +08:00
|
|
|
|
struct cache_ctx_multi_delete
|
|
|
|
|
|
{
|
|
|
|
|
|
u_int32_t succ_num;
|
|
|
|
|
|
u_int32_t fail_num;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2018-09-18 11:14:11 +08:00
|
|
|
|
struct tango_cache_ctx
|
|
|
|
|
|
{
|
|
|
|
|
|
CURL *curl;
|
|
|
|
|
|
struct curl_slist *headers;
|
2018-11-23 20:55:28 +08:00
|
|
|
|
struct promise* promise;
|
2018-09-18 11:14:11 +08:00
|
|
|
|
char error[CURL_ERROR_SIZE];
|
2018-09-23 15:35:13 +08:00
|
|
|
|
char object_key[256];
|
2018-09-29 17:10:19 +08:00
|
|
|
|
char hostaddr[48];
|
2018-09-21 14:50:41 +08:00
|
|
|
|
|
2018-09-18 11:14:11 +08:00
|
|
|
|
enum CACHE_REQUEST_METHOD method;
|
|
|
|
|
|
enum CACHE_ERR_CODE error_code;
|
2018-09-27 15:04:56 +08:00
|
|
|
|
struct easy_string response;
|
2018-09-21 14:50:41 +08:00
|
|
|
|
|
2018-09-23 15:35:13 +08:00
|
|
|
|
bool fail_state;
|
2018-12-14 15:07:09 +08:00
|
|
|
|
enum OBJECT_LOCATION locate; //<2F>ɳ<EFBFBD><C9B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>
|
2018-09-18 11:14:11 +08:00
|
|
|
|
long res_code;
|
|
|
|
|
|
|
2018-09-27 15:04:56 +08:00
|
|
|
|
union{
|
|
|
|
|
|
struct cache_ctx_data_put put;
|
|
|
|
|
|
struct cache_ctx_data_get get;
|
2018-10-11 16:35:13 +08:00
|
|
|
|
struct cache_ctx_multi_delete del;
|
2018-09-27 15:04:56 +08:00
|
|
|
|
};
|
2018-09-18 11:14:11 +08:00
|
|
|
|
struct tango_cache_instance *instance;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct curl_socket_data
|
|
|
|
|
|
{
|
|
|
|
|
|
struct event sock_event;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2018-10-11 16:35:13 +08:00
|
|
|
|
void caculate_sha256(const char *data, unsigned long len, char *result, u_int32_t size);
|
|
|
|
|
|
|
2018-09-21 14:50:41 +08:00
|
|
|
|
void easy_string_savedata(struct easy_string *estr, const char *data, size_t len);
|
|
|
|
|
|
void easy_string_destroy(struct easy_string *estr);
|
|
|
|
|
|
|
2018-10-27 11:03:58 +08:00
|
|
|
|
void tango_cache_ctx_destroy(struct tango_cache_ctx *ctx, bool callback=true);
|
2018-10-08 16:07:43 +08:00
|
|
|
|
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);
|
2018-09-21 14:50:41 +08:00
|
|
|
|
|
2018-12-14 15:07:09 +08:00
|
|
|
|
bool sessions_exceeds_limit(struct tango_cache_instance *instance, enum OBJECT_LOCATION where_to_get);
|
|
|
|
|
|
|
|
|
|
|
|
struct tango_cache_ctx *tango_cache_update_prepare(struct tango_cache_instance *instance,
|
|
|
|
|
|
struct future* f, struct tango_cache_meta_put *meta, enum OBJECT_LOCATION maybe_loc);
|
|
|
|
|
|
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, enum OBJECT_LOCATION where_to_get);
|
2018-12-15 13:50:48 +08:00
|
|
|
|
struct tango_cache_ctx *tango_cache_delete_prepare(struct tango_cache_instance *instance,
|
|
|
|
|
|
struct future* f, const char *objkey, const char *minio_addr, const char *bucket);
|
2018-12-14 15:07:09 +08:00
|
|
|
|
|
|
|
|
|
|
enum OBJECT_LOCATION tango_cache_object_locate(struct tango_cache_instance *instance, size_t object_size);
|
|
|
|
|
|
void tango_cache_get_object_path(struct tango_cache_ctx *ctx, char *path/*OUT*/, size_t pathsize);
|
|
|
|
|
|
struct tango_cache_ctx *tango_cache_update_once_prepare(struct tango_cache_instance *instance,
|
|
|
|
|
|
struct future* f, struct tango_cache_meta_put *meta, size_t object_size, char *path, size_t pathsize);
|
|
|
|
|
|
|
2018-09-18 11:14:11 +08:00
|
|
|
|
#endif
|
|
|
|
|
|
|