forked from alibaba/nginx-tfs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ngx_http_tfs_tair_helper.c
185 lines (140 loc) · 4.42 KB
/
ngx_http_tfs_tair_helper.c
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/*
* Copyright (C) 2010-2012 Alibaba Group Holding Limited
*/
#include <ngx_http_tfs_tair_helper.h>
#ifdef NGX_HTTP_TFS_USE_TAIR
ngx_int_t
ngx_http_tfs_tair_get_helper(ngx_http_tfs_tair_instance_t *instance,
ngx_pool_t *pool, ngx_log_t *log,
ngx_http_tair_data_t *key, ngx_http_tair_get_handler_pt callback,
void *data)
{
ngx_int_t rc;
if (instance == NULL || key == NULL) {
return NGX_ERROR;
}
rc = ngx_http_tair_get(instance->server, pool, log, *key,
instance->area, callback, data);
if (rc != NGX_OK) {
return NGX_ERROR;
}
return NGX_DECLINED;
}
ngx_int_t ngx_http_tfs_tair_mget_helper(ngx_http_tfs_tair_instance_t *instance,
ngx_pool_t *pool, ngx_log_t *log,
ngx_array_t *kvs, ngx_http_tair_mget_handler_pt callback, void *data)
{
ngx_int_t rc;
if (instance == NULL || kvs == NULL) {
return NGX_ERROR;
}
rc = ngx_http_tair_mget(instance->server, pool, log, kvs,
instance->area, callback, data);
if (rc != NGX_OK) {
return NGX_ERROR;
}
return NGX_DECLINED;
}
ngx_int_t
ngx_http_tfs_tair_put_helper(ngx_http_tfs_tair_instance_t *instance,
ngx_pool_t *pool, ngx_log_t *log,
ngx_http_tair_data_t *key, ngx_http_tair_data_t *value,
ngx_int_t expire, ngx_int_t version,
ngx_http_tair_handler_pt callback, void *data)
{
ngx_int_t rc;
if (instance == NULL || key == NULL || value == NULL) {
return NGX_ERROR;
}
rc = ngx_http_tair_put(instance->server, pool, log, *key,
*value, instance->area, 0/*nx*/, expire,
version, callback, data);
if (rc != NGX_OK) {
return NGX_ERROR;
}
return NGX_DECLINED;
}
ngx_int_t
ngx_http_tfs_tair_delete_helper(ngx_http_tfs_tair_instance_t *instance,
ngx_pool_t *pool, ngx_log_t *log,
ngx_array_t *keys, ngx_http_tair_handler_pt callback, void *data)
{
ngx_int_t rc;
if (instance == NULL || keys == NULL) {
return NGX_ERROR;
}
rc = ngx_http_tair_delete(instance->server, pool, log, keys,
instance->area, callback, data);
if (rc != NGX_OK) {
return NGX_ERROR;
}
return NGX_DECLINED;
}
#else
ngx_int_t
ngx_http_tfs_tair_get_helper(ngx_http_tfs_tair_instance_t *instance,
ngx_pool_t *pool, ngx_log_t *log,
ngx_http_tair_data_t *key, ngx_http_tair_get_handler_pt callback,
void *data)
{
return NGX_ERROR;
}
ngx_int_t ngx_http_tfs_tair_mget_helper(ngx_http_tfs_tair_instance_t *instance,
ngx_pool_t *pool, ngx_log_t *log,
ngx_array_t *kvs, ngx_http_tair_mget_handler_pt callback, void *data)
{
return NGX_ERROR;
}
ngx_int_t
ngx_http_tfs_tair_put_helper(ngx_http_tfs_tair_instance_t *instance,
ngx_pool_t *pool, ngx_log_t *log,
ngx_http_tair_data_t *key, ngx_http_tair_data_t *value,
ngx_int_t expire, ngx_int_t version,
ngx_http_tair_handler_pt callback, void *data)
{
return NGX_ERROR;
}
ngx_int_t
ngx_http_tfs_tair_delete_helper(ngx_http_tfs_tair_instance_t *instance,
ngx_pool_t *pool, ngx_log_t *log,
ngx_array_t *keys, ngx_http_tair_handler_pt callback, void *data)
{
return NGX_ERROR;
}
#endif
ngx_int_t
ngx_http_tfs_parse_tair_server_addr_info(ngx_http_tfs_tair_server_addr_info_t *info,
u_char *addr, uint32_t len, void *pool, uint8_t shared_memory)
{
u_char *temp, *p;
ssize_t info_size;
ngx_int_t i;
p = addr;
for (i = 0; i < NGX_HTTP_TFS_TAIR_SERVER_ADDR_PART_COUNT; i++) {
temp = ngx_strlchr(p, p + len, ';');
if (temp == NULL) {
return NGX_ERROR;
}
info_size = temp - p;
if (shared_memory) {
info->server[i].data = ngx_slab_alloc_locked((ngx_slab_pool_t *)pool, info_size);
} else {
info->server[i].data = ngx_pcalloc((ngx_pool_t *)pool, info_size);
}
if (info->server[i].data == NULL) {
return NGX_ERROR;
}
info->server[i].len = info_size;
memcpy(info->server[i].data, p, info_size);
p += info_size + 1;
len -= (info_size + 1);
if (len <= 0) {
return NGX_ERROR;
}
}
info->area = ngx_atoi(p, len);
if (info->area == NGX_ERROR) {
return NGX_ERROR;
}
return NGX_OK;
}