132 lines
3.0 KiB
C
132 lines
3.0 KiB
C
#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>
|
||
|
||
#include "tango_cache_client.h"
|
||
|
||
enum CACHE_REQUEST_METHOD
|
||
{
|
||
CACHE_REQUEST_GET=0,
|
||
CACHE_REQUEST_PUT,
|
||
};
|
||
|
||
enum GET_OBJECT_STATE
|
||
{
|
||
GET_STATE_START=0,
|
||
GET_STATE_DELETE,
|
||
GET_STATE_END,
|
||
};
|
||
|
||
enum PUT_OBJECT_STATE
|
||
{
|
||
PUT_STATE_START=0,
|
||
PUT_STATE_WAIT_START,
|
||
PUT_STATE_START_DONE,
|
||
PUT_STATE_PART,
|
||
PUT_STATE_END,
|
||
PUT_STATE_CANCEL,
|
||
};
|
||
|
||
struct easy_string
|
||
{
|
||
char* buff;
|
||
size_t len;
|
||
size_t size;
|
||
};
|
||
|
||
struct cache_buffer
|
||
{
|
||
char *buf;
|
||
size_t len;
|
||
size_t off;
|
||
TAILQ_ENTRY(cache_buffer) node;
|
||
};
|
||
|
||
struct tango_cache_instance
|
||
{
|
||
char minio_hostlist[4096];
|
||
char bucketname[256];
|
||
struct event_base* evbase;
|
||
struct event timer_event;
|
||
struct cache_statistics statistic;
|
||
CURLM *multi_hd;
|
||
void *runtime_log;
|
||
time_t relative_ttl; //缓存的相对有效期
|
||
u_int64_t cache_limit_size;
|
||
long max_cnn_host;
|
||
int host_index;
|
||
u_int32_t block_len; //申请buffercache内存的缓存块大小,每次update块大小最好不要超过该值,否则会增加拷贝次数
|
||
u_int32_t upload_block_size; //minio分段上传块的最小长度
|
||
enum CACHE_ERR_CODE error_code;
|
||
u_int32_t hash_object_key;
|
||
};
|
||
|
||
struct buffer_cache_list;
|
||
struct tango_cache_ctx
|
||
{
|
||
CURL *curl;
|
||
struct curl_slist *headers;
|
||
struct curl_slist *headers_puts;
|
||
|
||
struct future* future;
|
||
char error[CURL_ERROR_SIZE];
|
||
char file_key[72];
|
||
char hostport[24]; //相同ctx使用相同的IP,保证pipeline顺序性
|
||
|
||
u_int32_t host_index;
|
||
u_int32_t part_runing_num;
|
||
u_int32_t part_index;
|
||
enum CACHE_REQUEST_METHOD method;
|
||
enum CACHE_ERR_CODE error_code;
|
||
union{
|
||
enum PUT_OBJECT_STATE put_state;
|
||
enum GET_OBJECT_STATE get_state;
|
||
};
|
||
enum PUT_MEMORY_COPY_WAY way; //PUT ONCE时内存拷贝还是直接利用
|
||
bool fail_state;
|
||
bool close_state; //主动被调用关闭
|
||
bool expire_comes;
|
||
long res_code;
|
||
time_t relative_age;//Get时允许的最远缓存时间
|
||
|
||
char *uploadID;
|
||
char *combine_xml;
|
||
struct easy_string response;
|
||
TAILQ_HEAD(__cache_list_head, buffer_cache_list) cache_head;
|
||
struct buffer_cache_list *list_cur; //时刻分配空间,只有最后无数据时方可释放,用于判定上传结束
|
||
|
||
struct tango_cache_instance *instance;
|
||
};
|
||
|
||
struct buffer_cache_list
|
||
{
|
||
TAILQ_HEAD(__buffer_cache_node, cache_buffer) cache_list;
|
||
struct cache_buffer *cache_cur;
|
||
CURL *curl;
|
||
char *etag;
|
||
u_int32_t part_number;
|
||
u_int32_t length;
|
||
struct tango_cache_ctx *ctx;
|
||
TAILQ_ENTRY(buffer_cache_list) node;
|
||
};
|
||
|
||
struct curl_socket_data
|
||
{
|
||
struct event sock_event;
|
||
};
|
||
|
||
void response_buffer_destroy(struct easy_string *estr);
|
||
void buffer_cache_destroy(struct cache_buffer *cache, struct tango_cache_instance *instance);
|
||
void buffer_cache_list_destroy(struct buffer_cache_list *list, struct tango_cache_ctx *ctx);
|
||
void tango_cache_ctx_destroy(struct tango_cache_ctx *ctx);
|
||
struct tango_cache_ctx *tango_cache_update_prepare(struct tango_cache_instance *instance, struct future* future, struct tango_cache_meta *meta);
|
||
struct tango_cache_ctx *tango_cache_fetch_prepare(struct tango_cache_instance *instance, struct future* future, struct tango_cache_meta *meta);
|
||
|
||
#endif
|
||
|