summaryrefslogtreecommitdiff
path: root/src/inc/tango_cache_client.h
blob: c551e8ffb50f1802b034942093f358176896815f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#ifndef __TANGO_CACHE_CLIENT_H__
#define __TANGO_CACHE_CLIENT_H__

#include <event2/event.h>  
#include <event.h>

#include <tfe_future.h>
#include "tango_cache_pending.h"

#define USER_TAG_MAX_LEN 1518

enum CACHE_ERR_CODE
{
	CACHE_OK=0,
	CACHE_CACHE_MISS, //�������
	CACHE_TIMEOUT,	//���泬ʱ
	CACHE_OUTOF_MEMORY,//��ǰ�ڴ�ռ�ó������ƣ��鿴MAX_USED_MEMORY_SIZE_MB�Ƿ��С���ߵ�ǰ�ϴ����ʸ����ϵ����ߵ�����
	CACHE_ERR_CURL,
	CACHE_ERR_WIREDLB,
	CACHE_ERR_SOCKPAIR,
	CACHE_ERR_INTERNAL,
	CACHE_ERR_REDIS_JSON,
	CACHE_ERR_REDIS_CONNECT,
	CACHE_OUTOF_SESSION,
	CACHE_UPDATE_CANCELED,
};

enum PUT_MEMORY_COPY_WAY
{
	PUT_MEM_COPY=0, //��������ڴ�
	PUT_MEM_FREE,   //�������ڴ棬��������ɱ�����ģ���ͷŸ��ڴ�
};
enum EVBUFFER_COPY_WAY
{
	EVBUFFER_MOVE=0,//evbuffer_add_buffer
	EVBUFFER_COPY,  //evbuffer_add_buffer_reference
};

struct cache_statistics
{
	long long get_recv_num;	//����GET�Ĵ���
	long long get_succ_num;	//GET�ɹ��Ĵ���
	long long get_miss_num;	//GETδ���еĴ���
	long long get_error_num;//GETʧ�ܵĴ���
	long long put_recv_num;	//����UPLOAD�Ĵ���
	long long put_succ_num;	//UPLOAD�ɹ��Ĵ���
	long long put_error_num;//UPLOADʧ�ܵĴ���
	long long del_recv_num;	//����DELETE�Ĵ���
	long long del_succ_num;	//DELETE�ɹ��Ĵ���
	long long del_error_num;//DELETEʧ�ܵĴ���
	long long totaldrop_num;//�ڴ����Լ�WiredLB����ʱDROP�Ĵ���
	long long memory_used;	//��ǰUPLOAD BODY��ռ�ڴ��С
	long long session_num;	//��ǰ���ڽ���GET/PUT��HTTP�Ự��
};

enum CACHE_RESULT_TYPE
{
	RESULT_TYPE_HEADER=0, //���ֻ����һ��
	RESULT_TYPE_USERTAG,  //���ֻ����һ��
	RESULT_TYPE_BODY,     //���ܵ��ö��
	RESULT_TYPE_END,	  //ȫ��������ֻ����һ�Σ�����������
	RESULT_TYPE_MISS,	  //����δ���У����������ͻ��⣬ֻ����һ��(��END֮��)������������
};

//promise_success�Ľ��result
struct tango_cache_result
{
	const char *data_frag; //���typeΪRESULT_TYPE_HEADER��ÿ��ͷ��������һ������(HTTP1.1��ʽ)
	size_t size;
	size_t tlength; //������ܳ��ȣ��ص�ʱ����Ч
	enum CACHE_RESULT_TYPE type;
};

enum CACHE_HTTP_HDR_TYPE
{
	HDR_CONTENT_TYPE=0,
	HDR_CONTENT_ENCODING,
	HDR_CONTENT_DISPOSITION,
	HDR_CONTENT_MD5,
	
	HDR_CONTENT_NUM,
};

struct tango_cache_meta_get
{
	const char* url; //����:URL���ǽṹ����־:�ļ�·������CACHE_OBJECT_KEY_HASH_SWITCH=0ʱ��󳤶�256�ֽڣ�=1ʱ������
	struct request_freshness get;
};

struct tango_cache_meta_put
{
	const char* url;
	const char* std_hdr[HDR_CONTENT_NUM]; //����ͷ������"Content-Type: text/html"����Ҫ�������У�NULL��ʾû�и�ͷ����
	const char* usertag; //�������������ݣ�GETʱ��ԭ������
	size_t usertag_len;  //��󳤶�USER_TAG_MAX_LEN��0��ʾû�и�ͷ��
	struct response_freshness put;
};

struct tango_cache_parameter;
struct tango_cache_instance;
struct tango_cache_ctx;

enum CACHE_ERR_CODE tango_cache_get_last_error(const struct tango_cache_ctx *ctx);
enum CACHE_ERR_CODE tango_cache_ctx_error(const struct tango_cache_instance *instance);
void tango_cache_get_statistics(const struct tango_cache_instance *instance, struct cache_statistics *out);

/*ÿ������ִ��һ�γ�ʼ��*/
void tango_cache_global_init(void);

//ÿ��minio��Ⱥ��bucket����һ��parameter�����instance�ɹ���һ��parameter
struct tango_cache_parameter *tango_cache_parameter_new(const char* profile_path, const char* section, void *runtimelog);
/*��������API�̲߳���ȫ*/
//ÿ�������̴߳���һ��instance
struct tango_cache_instance *tango_cache_instance_new(struct tango_cache_parameter *param, struct event_base* evbase, void *runtimelog);


/* GET�ӿڵ�API*/
//�ɹ�ʱ�ص�promise_success
//ʧ��ʱ�ص�promise_failed(��һ��)��ʹ��get_last_error��ȡ�����룻
//future������ΪNULL
int tango_cache_fetch_object(struct tango_cache_instance *instance, struct future* f, struct tango_cache_meta_get *meta);
int tango_cache_head_object(struct tango_cache_instance *instance, struct future* f, struct tango_cache_meta_get *meta);
//��promise_success��result������ȡ���
struct tango_cache_result *tango_cache_read_result(future_result_t *promise_result);


/* DELETE�ӿڵ�API*/
int tango_cache_delete_object(struct tango_cache_instance *instance, struct future* f, const char *objkey);


/* UPLOAD�ӿڵ�API
 * ע��: UPLOAD�ӿڵ�API����future��ΪNULL�������ϴ�����ʱ�����֪ͨ�ص����������򲻵��ã�
 */

/*����һ���ϴ�API*/
//��path��Ϊ�գ����������Ĵ洢·��
//����ֵ: 0-�ɹ���<0ʧ�ܣ���ͬ
int tango_cache_upload_once_data(struct tango_cache_instance *instance, struct future* f, 
                                            enum PUT_MEMORY_COPY_WAY way, const char *data, size_t size, 
                                            struct tango_cache_meta_put *meta, 
                                            char *path/*OUT*/, size_t pathsize);
int tango_cache_upload_once_evbuf(struct tango_cache_instance *instance, struct future* f, 
                                            enum EVBUFFER_COPY_WAY way, struct evbuffer *evbuf, 
                                            struct tango_cache_meta_put *meta, 
                                            char *path/*OUT*/, size_t pathsize);
/*��ʽ�ϴ�API*/
//����ֵ: ��ΪNULL���ʾ����ʧ�ܣ�����tango_cache_ctx_error�鿴�������Ƿ���CACHE_OUTOF_MEMORY(�����������)��
struct tango_cache_ctx *tango_cache_update_start(struct tango_cache_instance *instance, struct future* f, struct tango_cache_meta_put *meta);
//����ֵ: 0-�ɹ���<0ʧ�ܣ�����tango_cache_get_last_error�鿴�����룻
int tango_cache_update_frag_data(struct tango_cache_ctx *ctx, const char *data, size_t size);
int tango_cache_update_frag_evbuf(struct tango_cache_ctx *ctx, enum EVBUFFER_COPY_WAY way, struct evbuffer *evbuf);
void tango_cache_update_end(struct tango_cache_ctx *ctx);
//����cancel�󲻻��������ص�����������ʧ��
void tango_cache_update_cancel(struct tango_cache_ctx *ctx);

//��ȡ����keyֵ����CACHE_OBJECT_KEY_HASH_SWITCH=1������URL/�ļ�����ϣʱ����
void tango_cache_get_object_path(const struct tango_cache_ctx *ctx, char *path/*OUT*/, size_t pathsize);

#endif