Skip to content

Commit 1a5b3f4

Browse files
committed
Add tests + add abstractions
1 parent 845427f commit 1a5b3f4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+2018
-310
lines changed

memcached/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@ execute_process(COMMAND ${CMAKE_COMMAND} -E touch_nocreate
1818
# PROPERTIES HEADER_FILE_ONLY true)
1919

2020
add_library(internalso SHARED
21+
"internal/constants.c"
2122
"internal/utils.c"
2223
"internal/proto_binary.c"
2324
"internal/proto_text_parser.c"
24-
"internal/constants.c"
25+
"internal/proto_text.c"
2526
"internal/network.c"
2627
"internal/memcached_layer.c"
2728
"internal/memcached.c"

memcached/internal/alloc.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef TARANTOOL_BOX_MEMCACHED_PERSISTENT_H_INCLUDED
2-
#define TARANTOOL_BOX_MEMCACHED_PERSISTENT_H_INCLUDED
1+
#ifndef ALLOC_H_INCLUDED
2+
#define ALLOC_H_INCLUDED
33

44
void *
55
box_persistent_malloc(size_t len, size_t *total);
@@ -19,4 +19,4 @@ box_persistent_strdup(const void *str, size_t *total);
1919
void *
2020
box_persistent_strndup(const void *str, size_t len, size_t *total);
2121

22-
#endif /* TARANTOOL_BOX_MEMCACHED_PERSISTENT_H_INCLUDED */
22+
#endif /* ALLOC_H_INCLUDED */

memcached/internal/constants.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef TARANTOOL_BOX_MEMCACHED_CONSTANTS_H_INCLUDED
2-
#define TARANTOOL_BOX_MEMCACHED_CONSTANTS_H_INCLUDED
1+
#ifndef CONSTANTS_H_INCLUDED
2+
#define CONSTANTS_H_INCLUDED
33

44
enum memcached_text_cmd {
55
MEMCACHED_TXT_CMD_SET = 0x00,
@@ -197,4 +197,4 @@ struct memcached_body {
197197
const char *val;
198198
};
199199

200-
#endif /* TARANTOOL_BOX_MEMCACHED_CONSTANTS_H_INCLUDED */
200+
#endif /* CONSTANTS_H_INCLUDED */

memcached/internal/error.h

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#ifndef ERROR_H_INCLUDED
2+
#define ERROR_H_INCLUDED
3+
4+
#define memcached_error_ENOMEM(_bytes, _place, _for) \
5+
box_error_raise(box_error_code_MAX + MEMCACHED_RES_ENOMEM, \
6+
"Failed to allocate %u bytes in '%s' for %s", \
7+
(_bytes), (_place), (_for))
8+
9+
#define memcached_error_KEY_ENOENT() \
10+
box_error_raise(box_error_code_MAX + MEMCACHED_RES_KEY_ENOENT, \
11+
memcached_binary_res_title[MEMCACHED_RES_KEY_ENOENT])
12+
13+
#define memcached_error_KEY_EEXISTS() \
14+
box_error_raise(box_error_code_MAX + MEMCACHED_RES_KEY_EEXISTS, \
15+
memcached_binary_res_title[MEMCACHED_RES_KEY_EEXISTS])
16+
17+
#define memcached_error_E2BIG() \
18+
box_error_raise(box_error_code_MAX + MEMCACHED_RES_E2BIG, \
19+
memcached_binary_res_title[MEMCACHED_RES_E2BIG])
20+
21+
#define memcached_error_EINVALS(_error) \
22+
box_error_raise(box_error_code_MAX + MEMCACHED_RES_EINVAL, (_error))
23+
24+
#define memcached_error_EINVAL() \
25+
box_error_raise(box_error_code_MAX + MEMCACHED_RES_EINVAL, \
26+
memcached_binary_res_title[MEMCACHED_RES_EINVAL])
27+
28+
#define memcached_error_NOT_STORED() \
29+
box_error_raise(box_error_code_MAX + MEMCACHED_RES_NOT_STORED, \
30+
memcached_binary_res_title[MEMCACHED_RES_NOT_STORED])
31+
32+
#define memcached_error_DELTA_BADVAL() \
33+
box_error_raise(box_error_code_MAX + MEMCACHED_RES_DELTA_BADVAL, \
34+
memcached_binary_res_title[MEMCACHED_RES_DELTA_BADVAL])
35+
36+
#define memcached_error_AUTH_ERROR() \
37+
box_error_raise(box_error_code_MAX + MEMCACHED_RES_AUTH_ERROR, \
38+
memcached_binary_res_title[MEMCACHED_RES_AUTH_ERROR])
39+
40+
#define memcached_error_AUTH_CONTINUE() \
41+
box_error_raise(box_error_code_MAX + MEMCACHED_RES_AUTH_CONTINUE, \
42+
memcached_binary_res_title[MEMCACHED_RES_AUTH_CONTINUE])
43+
44+
#define memcached_error_UNKNOWN_COMMAND(code) do { \
45+
box_error_raise(box_error_code_MAX + \
46+
MEMCACHED_RES_UNKNOWN_COMMAND, \
47+
"Unknown command with opcode 0x%.2x", (code)); \
48+
say_error("Unknown command with opcode 0x%.2x", (code)); \
49+
} while (0)
50+
51+
#define memcached_error_NOT_SUPPORTED(op) do { \
52+
box_error_raise(box_error_code_MAX + \
53+
MEMCACHED_RES_NOT_SUPPORTED, \
54+
"Unsupported command '%s'", (op)); \
55+
say_error("Unsupported command '%s'", (op)); \
56+
} while (0)
57+
58+
#define memcached_error_SERVER_ERROR(fmtstr, ...) do { \
59+
box_error_raise(box_error_code_MAX + \
60+
MEMCACHED_RES_SERVER_ERROR, \
61+
(fmtstr), ##__VA_ARGS__); \
62+
say_error((fmtstr), ##__VA_ARGS__); \
63+
} while (0)
64+
65+
#endif /* ERROR_H_INCLUDED */

memcached/internal/memcached.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,10 @@
3939
#include "memcached.h"
4040
#include "memcached_layer.h"
4141

42+
#include "error.h"
4243
#include "network.h"
4344
#include "proto_binary.h"
45+
#include "proto_text.h"
4446

4547
static inline int
4648
memcached_skip_request(struct memcached_connection *con) {
@@ -183,7 +185,8 @@ memcached_handler(struct memcached_service *p, int fd)
183185
/* read-write cycle */
184186
con.cfg->stat.curr_conns++;
185187
con.cfg->stat.total_conns++;
186-
memcached_set_binary(&con);
188+
// memcached_set_binary(&con);
189+
memcached_set_text(&con);
187190
memcached_loop(&con);
188191
con.cfg->stat.curr_conns--;
189192
close(con.fd);

memcached/internal/memcached.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef TARANTOOL_MEMCACHED_H_INCLUDED
2-
#define TARANTOOL_MEMCACHED_H_INCLUDED
1+
#ifndef MEMCACHED_H_INCLUDED
2+
#define MEMCACHED_H_INCLUDED
33

44
/*
55
** Old text memcached API
@@ -174,4 +174,4 @@ void memcached_handler(struct memcached_service *p, int fd);
174174
}
175175
#endif /* defined(__cplusplus) */
176176

177-
#endif
177+
#endif /* MEMCACHED_H_INCLUDED */

memcached/internal/memcached_layer.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <msgpuck/msgpuck.h>
1313
#include <small/obuf.h>
1414

15+
#include "error.h"
1516
#include "memcached.h"
1617
#include "memcached_layer.h"
1718
#include "utils.h"
Lines changed: 3 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef TARANTOOL_BOX_MEMCACHED_LAYER_H_INCLUDED
2-
#define TARANTOOL_BOX_MEMCACHED_LAYER_H_INCLUDED
1+
#ifndef MEMCACHED_LAYER_H_INCLUDED
2+
#define MEMCACHED_LAYER_H_INCLUDED
33

44
struct memcached_connection;
55

@@ -21,66 +21,6 @@ memcached_process_unknown(struct memcached_connection *con);
2121
int
2222
is_expired_tuple(struct memcached_service *p, box_tuple_t *tuple);
2323

24-
#define memcached_error_ENOMEM(_bytes, _place, _for) \
25-
box_error_raise(box_error_code_MAX + MEMCACHED_RES_ENOMEM, \
26-
"Failed to allocate %u bytes in '%s' for %s", \
27-
(_bytes), (_place), (_for))
28-
29-
#define memcached_error_KEY_ENOENT() \
30-
box_error_raise(box_error_code_MAX + MEMCACHED_RES_KEY_ENOENT, \
31-
memcached_binary_res_title[MEMCACHED_RES_KEY_ENOENT])
32-
33-
#define memcached_error_KEY_EEXISTS() \
34-
box_error_raise(box_error_code_MAX + MEMCACHED_RES_KEY_EEXISTS, \
35-
memcached_binary_res_title[MEMCACHED_RES_KEY_EEXISTS])
36-
37-
#define memcached_error_E2BIG() \
38-
box_error_raise(box_error_code_MAX + MEMCACHED_RES_E2BIG, \
39-
memcached_binary_res_title[MEMCACHED_RES_E2BIG])
40-
41-
#define memcached_error_EINVAL() \
42-
box_error_raise(box_error_code_MAX + MEMCACHED_RES_EINVAL, \
43-
memcached_binary_res_title[MEMCACHED_RES_EINVAL])
44-
45-
#define memcached_error_NOT_STORED() \
46-
box_error_raise(box_error_code_MAX + MEMCACHED_RES_NOT_STORED, \
47-
memcached_binary_res_title[MEMCACHED_RES_NOT_STORED])
48-
49-
#define memcached_error_DELTA_BADVAL() \
50-
box_error_raise(box_error_code_MAX + MEMCACHED_RES_DELTA_BADVAL, \
51-
memcached_binary_res_title[MEMCACHED_RES_DELTA_BADVAL])
52-
53-
#define memcached_error_AUTH_ERROR() \
54-
box_error_raise(box_error_code_MAX + MEMCACHED_RES_AUTH_ERROR, \
55-
memcached_binary_res_title[MEMCACHED_RES_AUTH_ERROR])
56-
57-
#define memcached_error_AUTH_CONTINUE() \
58-
box_error_raise(box_error_code_MAX + MEMCACHED_RES_AUTH_CONTINUE, \
59-
memcached_binary_res_title[MEMCACHED_RES_AUTH_CONTINUE])
60-
61-
#define memcached_error_UNKNOWN_COMMAND(code) do { \
62-
box_error_raise(box_error_code_MAX + \
63-
MEMCACHED_RES_UNKNOWN_COMMAND, \
64-
"Unknown command with opcode 0x%.2x", (code)); \
65-
say_error("Unknown command with opcode 0x%.2x", (code)); \
66-
} while (0)
67-
68-
#define memcached_error_NOT_SUPPORTED(op) do { \
69-
box_error_raise(box_error_code_MAX + \
70-
MEMCACHED_RES_NOT_SUPPORTED, \
71-
"Unsupported command '%s'", (op)); \
72-
say_error("Unsupported command '%s'", (op)); \
73-
} while (0)
74-
75-
#define memcached_error_SERVER_ERROR(fmtstr, ...) do { \
76-
box_error_raise(box_error_code_MAX + \
77-
MEMCACHED_RES_SERVER_ERROR, \
78-
(fmtstr), ##__VA_ARGS__); \
79-
say_error((fmtstr), ##__VA_ARGS__); \
80-
} while (0)
81-
82-
83-
8424
int
8525
memcached_bin_process_set(struct memcached_connection *con);
8626
int
@@ -106,4 +46,4 @@ memcached_bin_process_quit(struct memcached_connection *con);
10646
int
10747
memcached_bin_process_stat(struct memcached_connection *con);
10848

109-
#endif /* TARANTOOL_BOX_MEMCACHED_LAYER_H_INCLUDED */
49+
#endif /* MEMCACHED_LAYER_H_INCLUDED */

memcached/internal/network.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef TARANTOOL_MEMCACHED_NETWORK_H_INCLUDED
2-
#define TARANTOOL_MEMCACHED_NETWORK_H_INCLUDED
1+
#ifndef NETWORK_H_INCLUDED
2+
#define NETWORK_H_INCLUDED
33

44
#define TIMEOUT_INFINITY 365*86400*100.0
55

@@ -52,4 +52,4 @@ obuf_new();
5252
void
5353
iobuf_delete(struct ibuf *ibuf, struct obuf *obuf);
5454

55-
#endif /* TARANTOOL_MEMCACHED_NETWORK_H_INCLUDED */
55+
#endif /* NETWORK_H_INCLUDED */

memcached/internal/proto_binary.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@
44
#include <tarantool.h>
55
#include <msgpuck/msgpuck.h>
66

7+
#include "error.h"
78
#include "memcached.h"
89
#include "constants.h"
910
#include "memcached_layer.h"
1011

12+
#include "proto_binary.h"
13+
1114
#include <small/ibuf.h>
1215
#include <small/obuf.h>
1316

@@ -144,7 +147,8 @@ memcached_binary_ntxn(struct memcached_connection *con)
144147
};
145148

146149
int
147-
memcached_binary_process(struct memcached_connection *con) {
150+
memcached_binary_process(struct memcached_connection *con)
151+
{
148152
int rv = 0;
149153
/* Process message */
150154
con->noreply = false;
@@ -299,20 +303,20 @@ int memcached_bin_errori(struct memcached_connection *con)
299303
int rv = 0;
300304
switch(errcode) {
301305
case ER_MEMORY_ISSUE:
302-
errcode = MEMCACHED_RES_ENOMEM;
306+
errcode = MEMCACHED_BIN_RES_ENOMEM;
303307
errstr = NULL;
304308
rv = -1;
305309
break;
306310
case ER_TUPLE_NOT_FOUND:
307-
errcode = MEMCACHED_RES_KEY_ENOENT;
311+
errcode = MEMCACHED_BIN_RES_KEY_ENOENT;
308312
errstr = NULL;
309313
break;
310314
case ER_TUPLE_FOUND:
311-
errcode = MEMCACHED_RES_KEY_EEXISTS;
315+
errcode = MEMCACHED_BIN_RES_KEY_EEXISTS;
312316
errstr = NULL;
313317
break;
314318
default:
315-
errcode = MEMCACHED_RES_SERVER_ERROR;
319+
errcode = MEMCACHED_BIN_RES_SERVER_ERROR;
316320
snprintf(errfstr, 256, "SERVER ERROR '%s'", errstr);
317321
errstr = errfstr;
318322
rv = -1;

0 commit comments

Comments
 (0)