From 3ccd64466a48f18cbd74fef846866c0792a8dd85 Mon Sep 17 00:00:00 2001 From: Konstantin Osipov <kostja@tarantool.org> Date: Mon, 24 Dec 2012 15:06:48 +0400 Subject: [PATCH] Cleanup, refactoring. Move Box API declarations to box.h. Make box.h a public header. Add comments to box functions. Rename fuctions accordingly. Make includes for connector/c more local. --- CMakeLists.txt | 1 - client/CMakeLists.txt | 2 + connector/c/CMakeLists.txt | 2 + include/box/box.h | 101 +++++++++++++++++++++++++++++ include/tarantool.h | 17 ----- src/admin.m | 111 ++++++++++++++++---------------- src/admin.rl | 5 +- src/box/box.h | 43 ------------- src/box/box.m | 60 ++++++++--------- src/box/box_lua.m | 4 +- src/fiber.m | 22 +++---- src/iproto.m | 14 ++-- src/lua/info.m | 5 +- src/memcached.m | 4 +- src/tarantool.m | 17 ++--- test/box/CMakeLists.txt | 2 + test/connector_c/CMakeLists.txt | 1 + 17 files changed, 229 insertions(+), 182 deletions(-) create mode 100644 include/box/box.h delete mode 100644 src/box/box.h diff --git a/CMakeLists.txt b/CMakeLists.txt index bf93570d76..ecb7f08fa2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -106,7 +106,6 @@ endif() include_directories("${PROJECT_SOURCE_DIR}") include_directories("${PROJECT_SOURCE_DIR}/include") include_directories("${PROJECT_BINARY_DIR}/include") -include_directories("${PROJECT_SOURCE_DIR}/connector/c/include") # # Specify prefixes # diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index 8a1808c004..691ee8424b 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -11,6 +11,8 @@ function(tarantool_client client_name) target_link_libraries (${client_name} ${client_libs}) endfunction() +include_directories("${PROJECT_SOURCE_DIR}/connector/c/include") + foreach (client ${TARANTOOL_CLIENTS}) add_subdirectory(${client}) endforeach() diff --git a/connector/c/CMakeLists.txt b/connector/c/CMakeLists.txt index df57af8b51..d2e18d8dbd 100644 --- a/connector/c/CMakeLists.txt +++ b/connector/c/CMakeLists.txt @@ -8,6 +8,8 @@ set(LIBTNT_VERSION_MINOR "1") set(LIBTNT_VERSION "${LIBTNT_VERSION_MAJOR}.${LIBTNT_VERSION_MINOR}") set(LIBTNT_SOVERSION "${LIBTNT_VERSION_MAJOR}") +include_directories("${PROJECT_SOURCE_DIR}/connector/c/include") + add_subdirectory(tnt) add_subdirectory(tntsql) add_subdirectory(tntnet) diff --git a/include/box/box.h b/include/box/box.h new file mode 100644 index 0000000000..6cd4096bc5 --- /dev/null +++ b/include/box/box.h @@ -0,0 +1,101 @@ +#ifndef INCLUDES_TARANTOOL_BOX_H +#define INCLUDES_TARANTOOL_BOX_H +/* + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * 1. Redistributions of source code must retain the above + * copyright notice, this list of conditions and the + * following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * <COPYRIGHT HOLDER> OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ +#include <util.h> +/* + * Box - data storage (spaces, indexes) and query + * processor (INSERT, UPDATE, DELETE, SELECT, Lua) + * subsystem of Tarantool/Box. + */ + +struct txn; +struct tbuf; +struct port; +struct fio_batch; +struct log_io; +struct tarantool_cfg; + +/** To be called at program start. */ +void box_init(void); +/** To be called at program end. */ +void box_free(void); + +/** + * The main entry point to the + * Box: callbacks into the request processor. + * These are function pointers since they can + * change when entering/leaving read-only mode + * (master->slave propagation). + */ +typedef void (*box_process_func)(struct port *, u32, struct tbuf *); +/** For read-write operations. */ +extern box_process_func box_process; +/** For read-only port. */ +extern box_process_func box_process_ro; + +/* + * Check storage-layer related options in the + * configuration file. + */ +i32 box_check_config(struct tarantool_cfg *conf); +/* + * Take into effect storage-layer related + * changes in the server configuration. + */ +i32 box_reload_config(struct tarantool_cfg *old_conf, struct tarantool_cfg *new_conf); +/** + * Ehm, this is a hack, shouldn't be here. + */ +int box_cat(const char *filename); +/** + * Iterate over all spaces and save them to the + * snapshot file. + */ +void box_snapshot(struct log_io *, struct fio_batch *batch); +/** + * Spit out some basic module status (master/slave, etc. + */ +void box_info(struct tbuf *out); +const char *box_status(void); +/** + * Issue a new session identifier - + * called by the networking layer + * when a new connection is established. + */ +uint32_t box_sid(); +/** + * Called to enter master or replica + * mode (depending on the configuration) after + * binding to the primary port. + */ +void +box_leave_local_standby_mode(void *data __attribute__((unused))); + +#endif /* INCLUDES_TARANTOOL_BOX_H */ diff --git a/include/tarantool.h b/include/tarantool.h index a24561673d..3812c783cd 100644 --- a/include/tarantool.h +++ b/include/tarantool.h @@ -36,23 +36,6 @@ struct tbuf; struct log_io; struct fio_batch; -void mod_init(void); -void mod_free(void); - -extern const char *mod_name; -i32 mod_check_config(struct tarantool_cfg *conf); -i32 mod_reload_config(struct tarantool_cfg *old_conf, struct tarantool_cfg *new_conf); -int mod_cat(const char *filename); -void mod_snapshot(struct log_io *, struct fio_batch *batch); -void mod_info(struct tbuf *out); -const char *mod_status(void); -/** - * Issue a new session identifier - - * called by the networking layer - * when a new connection is established. - */ -uint32_t mod_sid(); - extern int snapshot_pid; extern struct tarantool_cfg cfg; extern const char *cfg_filename; diff --git a/src/admin.m b/src/admin.m index 31c92d08ed..cac4900167 100644 --- a/src/admin.m +++ b/src/admin.m @@ -50,6 +50,7 @@ #include "lua.h" #include "lauxlib.h" #include "lualib.h" +#include "box/box.h" static const char *help = "available commands:" CRLF @@ -71,7 +72,7 @@ static const char *help = static const char *unknown_command = "unknown command. try typing help." CRLF; -#line 75 "src/admin.m" +#line 76 "src/admin.m" static const int admin_start = 1; static const int admin_first_final = 135; static const int admin_error = 0; @@ -79,7 +80,7 @@ static const int admin_error = 0; static const int admin_en_main = 1; -#line 74 "src/admin.rl" +#line 75 "src/admin.rl" struct salloc_stat_admin_cb_ctx { @@ -171,7 +172,7 @@ tarantool_info(struct tbuf *out) tbuf_printf(out, " recovery_last_update: %.3f" CRLF, recovery_state->remote ? recovery_state->remote->recovery_last_update_tstamp :0); - mod_info(out); + box_info(out); const char *path = cfg_filename_fullpath; if (path == NULL) path = cfg_filename; @@ -216,12 +217,12 @@ admin_dispatch(struct ev_io *coio, struct iobuf *iobuf, lua_State *L) p = in->pos; -#line 220 "src/admin.m" +#line 221 "src/admin.m" { cs = admin_start; } -#line 225 "src/admin.m" +#line 226 "src/admin.m" { if ( p == pe ) goto _test_eof; @@ -284,15 +285,15 @@ case 6: } goto st0; tr13: -#line 307 "src/admin.rl" +#line 308 "src/admin.rl" {slab_validate(); ok(out);} goto st135; tr20: -#line 295 "src/admin.rl" +#line 296 "src/admin.rl" {return -1;} goto st135; tr25: -#line 222 "src/admin.rl" +#line 223 "src/admin.rl" { start(out); tbuf_append(out, help, strlen(help)); @@ -300,9 +301,9 @@ tr25: } goto st135; tr36: -#line 281 "src/admin.rl" +#line 282 "src/admin.rl" {strend = p;} -#line 228 "src/admin.rl" +#line 229 "src/admin.rl" { strstart[strend-strstart]='\0'; start(out); @@ -311,7 +312,7 @@ tr36: } goto st135; tr43: -#line 235 "src/admin.rl" +#line 236 "src/admin.rl" { if (reload_cfg(err)) fail(out, err); @@ -320,11 +321,11 @@ tr43: } goto st135; tr67: -#line 305 "src/admin.rl" +#line 306 "src/admin.rl" {coredump(60); ok(out);} goto st135; tr76: -#line 242 "src/admin.rl" +#line 243 "src/admin.rl" { int ret = snapshot(NULL, 0); @@ -339,9 +340,9 @@ tr76: } goto st135; tr98: -#line 291 "src/admin.rl" +#line 292 "src/admin.rl" { state = false; } -#line 255 "src/admin.rl" +#line 256 "src/admin.rl" { strstart[strend-strstart] = '\0'; if (errinj_set_byname(strstart, state)) { @@ -353,9 +354,9 @@ tr98: } goto st135; tr101: -#line 290 "src/admin.rl" +#line 291 "src/admin.rl" { state = true; } -#line 255 "src/admin.rl" +#line 256 "src/admin.rl" { strstart[strend-strstart] = '\0'; if (errinj_set_byname(strstart, state)) { @@ -367,7 +368,7 @@ tr101: } goto st135; tr117: -#line 210 "src/admin.rl" +#line 211 "src/admin.rl" { start(out); show_cfg(out); @@ -375,15 +376,15 @@ tr117: } goto st135; tr131: -#line 298 "src/admin.rl" +#line 299 "src/admin.rl" {start(out); fiber_info(out); end(out);} goto st135; tr137: -#line 297 "src/admin.rl" +#line 298 "src/admin.rl" {start(out); tarantool_info(out); end(out);} goto st135; tr146: -#line 216 "src/admin.rl" +#line 217 "src/admin.rl" { start(out); errinj_info(out); @@ -391,33 +392,33 @@ tr146: } goto st135; tr152: -#line 301 "src/admin.rl" +#line 302 "src/admin.rl" {start(out); palloc_stat(out); end(out);} goto st135; tr160: -#line 300 "src/admin.rl" +#line 301 "src/admin.rl" {start(out); show_slab(out); end(out);} goto st135; tr164: -#line 302 "src/admin.rl" +#line 303 "src/admin.rl" {start(out); show_stat(out);end(out);} goto st135; st135: if ( ++p == pe ) goto _test_eof135; case 135: -#line 410 "src/admin.m" +#line 411 "src/admin.m" goto st0; tr14: -#line 307 "src/admin.rl" +#line 308 "src/admin.rl" {slab_validate(); ok(out);} goto st7; tr21: -#line 295 "src/admin.rl" +#line 296 "src/admin.rl" {return -1;} goto st7; tr26: -#line 222 "src/admin.rl" +#line 223 "src/admin.rl" { start(out); tbuf_append(out, help, strlen(help)); @@ -425,9 +426,9 @@ tr26: } goto st7; tr37: -#line 281 "src/admin.rl" +#line 282 "src/admin.rl" {strend = p;} -#line 228 "src/admin.rl" +#line 229 "src/admin.rl" { strstart[strend-strstart]='\0'; start(out); @@ -436,7 +437,7 @@ tr37: } goto st7; tr44: -#line 235 "src/admin.rl" +#line 236 "src/admin.rl" { if (reload_cfg(err)) fail(out, err); @@ -445,11 +446,11 @@ tr44: } goto st7; tr68: -#line 305 "src/admin.rl" +#line 306 "src/admin.rl" {coredump(60); ok(out);} goto st7; tr77: -#line 242 "src/admin.rl" +#line 243 "src/admin.rl" { int ret = snapshot(NULL, 0); @@ -464,9 +465,9 @@ tr77: } goto st7; tr99: -#line 291 "src/admin.rl" +#line 292 "src/admin.rl" { state = false; } -#line 255 "src/admin.rl" +#line 256 "src/admin.rl" { strstart[strend-strstart] = '\0'; if (errinj_set_byname(strstart, state)) { @@ -478,9 +479,9 @@ tr99: } goto st7; tr102: -#line 290 "src/admin.rl" +#line 291 "src/admin.rl" { state = true; } -#line 255 "src/admin.rl" +#line 256 "src/admin.rl" { strstart[strend-strstart] = '\0'; if (errinj_set_byname(strstart, state)) { @@ -492,7 +493,7 @@ tr102: } goto st7; tr118: -#line 210 "src/admin.rl" +#line 211 "src/admin.rl" { start(out); show_cfg(out); @@ -500,15 +501,15 @@ tr118: } goto st7; tr132: -#line 298 "src/admin.rl" +#line 299 "src/admin.rl" {start(out); fiber_info(out); end(out);} goto st7; tr138: -#line 297 "src/admin.rl" +#line 298 "src/admin.rl" {start(out); tarantool_info(out); end(out);} goto st7; tr147: -#line 216 "src/admin.rl" +#line 217 "src/admin.rl" { start(out); errinj_info(out); @@ -516,22 +517,22 @@ tr147: } goto st7; tr153: -#line 301 "src/admin.rl" +#line 302 "src/admin.rl" {start(out); palloc_stat(out); end(out);} goto st7; tr161: -#line 300 "src/admin.rl" +#line 301 "src/admin.rl" {start(out); show_slab(out); end(out);} goto st7; tr165: -#line 302 "src/admin.rl" +#line 303 "src/admin.rl" {start(out); show_stat(out);end(out);} goto st7; st7: if ( ++p == pe ) goto _test_eof7; case 7: -#line 535 "src/admin.m" +#line 536 "src/admin.m" if ( (*p) == 10 ) goto st135; goto st0; @@ -684,28 +685,28 @@ case 23: } goto tr33; tr33: -#line 281 "src/admin.rl" +#line 282 "src/admin.rl" {strstart = p;} goto st24; st24: if ( ++p == pe ) goto _test_eof24; case 24: -#line 695 "src/admin.m" +#line 696 "src/admin.m" switch( (*p) ) { case 10: goto tr36; case 13: goto tr37; } goto st24; tr34: -#line 281 "src/admin.rl" +#line 282 "src/admin.rl" {strstart = p;} goto st25; st25: if ( ++p == pe ) goto _test_eof25; case 25: -#line 709 "src/admin.m" +#line 710 "src/admin.m" switch( (*p) ) { case 10: goto tr36; case 13: goto tr37; @@ -1155,28 +1156,28 @@ case 73: goto tr91; goto st0; tr91: -#line 289 "src/admin.rl" +#line 290 "src/admin.rl" { strstart = p; } goto st74; st74: if ( ++p == pe ) goto _test_eof74; case 74: -#line 1166 "src/admin.m" +#line 1167 "src/admin.m" if ( (*p) == 32 ) goto tr92; if ( 33 <= (*p) && (*p) <= 126 ) goto st74; goto st0; tr92: -#line 289 "src/admin.rl" +#line 290 "src/admin.rl" { strend = p; } goto st75; st75: if ( ++p == pe ) goto _test_eof75; case 75: -#line 1180 "src/admin.m" +#line 1181 "src/admin.m" switch( (*p) ) { case 32: goto st75; case 111: goto st76; @@ -1868,7 +1869,7 @@ case 134: _out: {} } -#line 313 "src/admin.rl" +#line 314 "src/admin.rl" in->pos = pe; @@ -1888,7 +1889,7 @@ admin_handler(va_list ap) { struct ev_io coio = va_arg(ap, struct ev_io); struct iobuf *iobuf = va_arg(ap, struct iobuf *); - fiber_set_sid(fiber, mod_sid()); + fiber_set_sid(fiber, box_sid()); lua_State *L = lua_newthread(tarantool_L); int coro_ref = luaL_ref(tarantool_L, LUA_REGISTRYINDEX); @try { diff --git a/src/admin.rl b/src/admin.rl index 752a09a37e..357f7f9770 100644 --- a/src/admin.rl +++ b/src/admin.rl @@ -48,6 +48,7 @@ #include "lua.h" #include "lauxlib.h" #include "lualib.h" +#include "box/box.h" static const char *help = "available commands:" CRLF @@ -162,7 +163,7 @@ tarantool_info(struct tbuf *out) tbuf_printf(out, " recovery_last_update: %.3f" CRLF, recovery_state->remote ? recovery_state->remote->recovery_last_update_tstamp :0); - mod_info(out); + box_info(out); const char *path = cfg_filename_fullpath; if (path == NULL) path = cfg_filename; @@ -329,7 +330,7 @@ admin_handler(va_list ap) { struct ev_io coio = va_arg(ap, struct ev_io); struct iobuf *iobuf = va_arg(ap, struct iobuf *); - fiber_set_sid(fiber, mod_sid()); + fiber_set_sid(fiber, box_sid()); lua_State *L = lua_newthread(tarantool_L); int coro_ref = luaL_ref(tarantool_L, LUA_REGISTRYINDEX); @try { diff --git a/src/box/box.h b/src/box/box.h deleted file mode 100644 index 35a68f072c..0000000000 --- a/src/box/box.h +++ /dev/null @@ -1,43 +0,0 @@ -#ifndef INCLUDES_TARANTOOL_BOX_H -#define INCLUDES_TARANTOOL_BOX_H -/* - * Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * 1. Redistributions of source code must retain the above - * copyright notice, this list of conditions and the - * following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * <COPYRIGHT HOLDER> OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR - * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF - * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ -#include <util.h> -struct txn; -struct tbuf; -struct port; - -typedef void (*mod_process_func)(struct port *, u32, struct tbuf *); -extern mod_process_func mod_process; -extern mod_process_func mod_process_ro; - -void -mod_leave_local_standby_mode(void *data __attribute__((unused))); - -#endif /* INCLUDES_TARANTOOL_BOX_H */ diff --git a/src/box/box.m b/src/box/box.m index ffba2b7eb9..aad13d6062 100644 --- a/src/box/box.m +++ b/src/box/box.m @@ -26,7 +26,7 @@ * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ -#include "box.h" +#include "box/box.h" #include <arpa/inet.h> #include <cfg/warning.h> @@ -48,16 +48,14 @@ #include "request.h" #include "txn.h" -static void box_process_replica(struct port *port, - u32 op, struct tbuf *request_data); -static void box_process_ro(struct port *port, - u32 op, struct tbuf *request_data); -static void box_process_rw(struct port *port, - u32 op, struct tbuf *request_data); -mod_process_func mod_process = box_process_ro; -mod_process_func mod_process_ro = box_process_ro; - -const char *mod_name = "Box"; +static void process_replica(struct port *port, + u32 op, struct tbuf *request_data); +static void process_ro(struct port *port, + u32 op, struct tbuf *request_data); +static void process_rw(struct port *port, + u32 op, struct tbuf *request_data); +box_process_func box_process = process_ro; +box_process_func box_process_ro = process_ro; static char status[64] = "unknown"; @@ -85,8 +83,7 @@ port_send_tuple(struct port *port, struct txn *txn, u32 flags) } static void -box_process_rw(struct port *port, - u32 op, struct tbuf *data) +process_rw(struct port *port, u32 op, struct tbuf *data) { struct txn *txn = txn_begin(); ev_tstamp start = ev_now(), stop; @@ -111,22 +108,21 @@ box_process_rw(struct port *port, } static void -box_process_replica(struct port *port, u32 op, struct tbuf *request_data) +process_replica(struct port *port, u32 op, struct tbuf *request_data) { if (!request_is_select(op)) { tnt_raise(ClientError, :ER_NONMASTER, cfg.replication_source); } - return box_process_rw(port, op, request_data); + return process_rw(port, op, request_data); } static void -box_process_ro(struct port *port, - u32 op, struct tbuf *request_data) +process_ro(struct port *port, u32 op, struct tbuf *request_data) { if (!request_is_select(op)) tnt_raise(LoggedError, :ER_SECONDARY); - return box_process_rw(port, op, request_data); + return process_rw(port, op, request_data); } static void @@ -295,7 +291,7 @@ recover_row(void *param __attribute__((unused)), struct tbuf *t) recover_snap_row(t); } else if (tag == XLOG) { u16 op = read_u16(t); - box_process_rw(&port_null, op, t); + process_rw(&port_null, op, t); } else { say_error("unknown row tag: %i", (int)tag); return -1; @@ -314,7 +310,7 @@ static void box_enter_master_or_replica_mode(struct tarantool_cfg *conf) { if (conf->replication_source != NULL) { - mod_process = box_process_replica; + box_process = process_replica; recovery_wait_lsn(recovery_state, recovery_state->lsn); recovery_follow_remote(recovery_state, conf->replication_source); @@ -323,7 +319,7 @@ box_enter_master_or_replica_mode(struct tarantool_cfg *conf) conf->replication_source, custom_proc_title); title("replica/%s%s", conf->replication_source, custom_proc_title); } else { - mod_process = box_process_rw; + box_process = process_rw; memcached_start_expire(); @@ -335,7 +331,7 @@ box_enter_master_or_replica_mode(struct tarantool_cfg *conf) } void -mod_leave_local_standby_mode(void *data __attribute__((unused))) +box_leave_local_standby_mode(void *data __attribute__((unused))) { recovery_finalize(recovery_state); @@ -346,7 +342,7 @@ mod_leave_local_standby_mode(void *data __attribute__((unused))) } i32 -mod_check_config(struct tarantool_cfg *conf) +box_check_config(struct tarantool_cfg *conf) { /* replication & hot standby modes can not work together */ if (conf->replication_source != NULL && conf->local_hot_standby > 0) { @@ -406,7 +402,7 @@ mod_check_config(struct tarantool_cfg *conf) } i32 -mod_reload_config(struct tarantool_cfg *old_conf, struct tarantool_cfg *new_conf) +box_reload_config(struct tarantool_cfg *old_conf, struct tarantool_cfg *new_conf) { bool old_is_replica = old_conf->replication_source != NULL; bool new_is_replica = new_conf->replication_source != NULL; @@ -436,16 +432,16 @@ mod_reload_config(struct tarantool_cfg *old_conf, struct tarantool_cfg *new_conf } void -mod_free(void) +box_free(void) { space_free(); } void -mod_init(void) +box_init(void) { title("loading"); - atexit(mod_free); + atexit(box_free); /* initialization spaces */ space_init(); @@ -484,7 +480,7 @@ mod_init(void) } int -mod_cat(const char *filename) +box_cat(const char *filename) { return read_log(filename, xlog_print, snap_print, NULL); } @@ -520,7 +516,7 @@ snapshot_space(struct space *sp, void *udata) } void -mod_snapshot(struct log_io *l, struct fio_batch *batch) +box_snapshot(struct log_io *l, struct fio_batch *batch) { /* --init-storage switch */ if (primary_indexes_enabled == false) @@ -532,21 +528,21 @@ mod_snapshot(struct log_io *l, struct fio_batch *batch) } void -mod_info(struct tbuf *out) +box_info(struct tbuf *out) { tbuf_printf(out, " status: %s" CRLF, status); } const char * -mod_status(void) +box_status(void) { return status; } uint32_t -mod_sid() +box_sid() { static uint32_t sid = 1; return sid++; diff --git a/src/box/box_lua.m b/src/box/box_lua.m index cf8d8284c9..0cf0821e53 100644 --- a/src/box/box_lua.m +++ b/src/box/box_lua.m @@ -29,7 +29,7 @@ #include "box_lua.h" #include "lua/init.h" #include <fiber.h> -#include "box.h" +#include "box/box.h" #include "request.h" #include "txn.h" @@ -1125,7 +1125,7 @@ static int lbox_process(lua_State *L) size_t allocated_size = palloc_allocated(fiber->gc_pool); struct port *port_lua = port_lua_create(L); @try { - mod_process(port_lua, op, &req); + box_process(port_lua, op, &req); } @finally { /* * This only works as long as port_lua doesn't diff --git a/src/fiber.m b/src/fiber.m index 6fd21fd7e8..8bd36bd777 100644 --- a/src/fiber.m +++ b/src/fiber.m @@ -54,7 +54,7 @@ __thread struct fiber *fiber = &sched; static __thread struct fiber *call_stack[FIBER_CALL_STACK]; static __thread struct fiber **sp; static __thread uint32_t last_used_fid; -static __thread struct mh_i32ptr_t *fibers_registry; +static __thread struct mh_i32ptr_t *fiber_registry; static __thread struct rlist fibers, zombie_fibers, ready_fibers; static __thread ev_async ready_async; @@ -301,27 +301,27 @@ fiber_ready_async(void) struct fiber * fiber_find(int fid) { - mh_int_t k = mh_i32ptr_get(fibers_registry, fid); + mh_int_t k = mh_i32ptr_get(fiber_registry, fid); - if (k == mh_end(fibers_registry)) + if (k == mh_end(fiber_registry)) return NULL; - if (!mh_exist(fibers_registry, k)) + if (!mh_exist(fiber_registry, k)) return NULL; - return mh_value(fibers_registry, k); + return mh_value(fiber_registry, k); } static void register_fid(struct fiber *fiber) { int ret; - mh_i32ptr_put(fibers_registry, fiber->fid, fiber, &ret); + mh_i32ptr_put(fiber_registry, fiber->fid, fiber, &ret); } static void unregister_fid(struct fiber *fiber) { - mh_int_t k = mh_i32ptr_get(fibers_registry, fiber->fid); - mh_i32ptr_del(fibers_registry, k); + mh_int_t k = mh_i32ptr_get(fiber_registry, fiber->fid); + mh_i32ptr_del(fiber_registry, k); } void @@ -503,7 +503,7 @@ fiber_init(void) rlist_init(&fibers); rlist_init(&ready_fibers); rlist_init(&zombie_fibers); - fibers_registry = mh_i32ptr_init(); + fiber_registry = mh_i32ptr_init(); memset(&sched, 0, sizeof(sched)); sched.fid = 1; @@ -525,8 +525,8 @@ fiber_free(void) { ev_async_stop(&ready_async); /* Only clean up if initialized. */ - if (fibers_registry) { + if (fiber_registry) { fiber_destroy_all(); - mh_i32ptr_destroy(fibers_registry); + mh_i32ptr_destroy(fiber_registry); } } diff --git a/src/iproto.m b/src/iproto.m index bbaed4aaa8..2560c34812 100644 --- a/src/iproto.m +++ b/src/iproto.m @@ -252,7 +252,7 @@ struct iproto_session ssize_t parse_size; /** Current write position in the output buffer */ struct obuf_svp write_pos; - mod_process_func *handler; + box_process_func *handler; struct ev_io input; struct ev_io output; /** Mod session id. */ @@ -283,7 +283,7 @@ iproto_session_on_output(struct ev_io *watcher, int revents __attribute__((unused))); static struct iproto_session * -iproto_session_create(const char *name, int fd, mod_process_func *param) +iproto_session_create(const char *name, int fd, box_process_func *param) { struct iproto_session *session; if (SLIST_EMPTY(&iproto_session_cache)) { @@ -300,7 +300,7 @@ iproto_session_create(const char *name, int fd, mod_process_func *param) session->iobuf[1] = iobuf_create(name); session->parse_size = 0; session->write_pos = obuf_create_svp(&session->iobuf[0]->out); - session->sid = mod_sid(); + session->sid = box_sid(); return session; } @@ -581,7 +581,7 @@ iproto_reply_error(struct obuf *out, struct iproto_header *req, /** Stack a reply to a single request to the fiber's io vector. */ static inline void -iproto_reply(struct port_iproto *port, mod_process_func callback, +iproto_reply(struct port_iproto *port, box_process_func callback, struct obuf *out, struct iproto_header *header) { if (header->msg_code == msg_ping) @@ -684,9 +684,9 @@ iproto_init(const char *bind_ipaddr, int primary_port, static struct evio_service primary; evio_service_init(&primary, "primary", bind_ipaddr, primary_port, - iproto_on_accept, &mod_process); + iproto_on_accept, &box_process); evio_service_on_bind(&primary, - mod_leave_local_standby_mode, NULL); + box_leave_local_standby_mode, NULL); evio_service_start(&primary); } @@ -695,7 +695,7 @@ iproto_init(const char *bind_ipaddr, int primary_port, static struct evio_service secondary; evio_service_init(&secondary, "secondary", bind_ipaddr, secondary_port, - iproto_on_accept, &mod_process_ro); + iproto_on_accept, &box_process_ro); evio_service_start(&secondary); } /** diff --git a/src/lua/info.m b/src/lua/info.m index 8b6106f5e8..48f09a7622 100644 --- a/src/lua/info.m +++ b/src/lua/info.m @@ -34,10 +34,11 @@ #include "lauxlib.h" #include "lualib.h" -#include <tarantool.h> #include <say.h> #include <string.h> #include <recovery.h> +#include "tarantool.h" +#include "box/box.h" static int lbox_info_recovery_lag(struct lua_State *L) @@ -70,7 +71,7 @@ lbox_info_lsn(struct lua_State *L) static int lbox_info_status(struct lua_State *L) { - lua_pushstring(L, mod_status()); + lua_pushstring(L, box_status()); return 1; } diff --git a/src/memcached.m b/src/memcached.m index 166148745d..3bcb9d5e64 100644 --- a/src/memcached.m +++ b/src/memcached.m @@ -117,7 +117,7 @@ store(void *key, u32 exptime, u32 flags, u32 bytes, const char *data) * Use a box dispatch wrapper which handles correctly * read-only/read-write modes. */ - mod_process(&port_null, REPLACE, req); + box_process(&port_null, REPLACE, req); } static void @@ -132,7 +132,7 @@ delete(void *key) tbuf_append(req, &key_len, sizeof(key_len)); tbuf_append_field(req, key); - mod_process(&port_null, DELETE, req); + box_process(&port_null, DELETE, req); } static struct tuple * diff --git a/src/tarantool.m b/src/tarantool.m index e04d82251f..30e8e5ec6c 100644 --- a/src/tarantool.m +++ b/src/tarantool.m @@ -64,6 +64,7 @@ #include "tarantool_pthread.h" #include "lua/init.h" #include "memcached.h" +#include "box/box.h" static pid_t master_pid; @@ -162,7 +163,7 @@ load_cfg(struct tarantool_cfg *conf, i32 check_rdonly) if (replication_check_config(conf) != 0) return -1; - return mod_check_config(conf); + return box_check_config(conf); } static int @@ -260,7 +261,7 @@ reload_cfg(struct tbuf *out) return -1; /* Now pass the config to the module, to take action. */ - if (mod_reload_config(&cfg, &new_cfg) != 0) + if (box_reload_config(&cfg, &new_cfg) != 0) return -1; /* All OK, activate the config. */ swap_tarantool_cfg(&cfg, &new_cfg); @@ -354,7 +355,7 @@ snapshot(void *ev, int events __attribute__((unused))) * parent stdio buffers at exit(). */ close_all_xcpt(1, sayfd); - snapshot_save(recovery_state, mod_snapshot); + snapshot_save(recovery_state, box_snapshot); exit(EXIT_SUCCESS); return 0; @@ -675,7 +676,7 @@ main(int argc, char **argv) binary_filename = argv[0]; if (gopt(opt, 'V')) { - printf("Tarantool/%s %s\n", mod_name, tarantool_version()); + printf("Tarantool/Box %s\n", tarantool_version()); printf("Target: %s\n", BUILD_INFO); printf("Build options: %s\n", BUILD_OPTIONS); printf("Compiler: %s\n", COMPILER_INFO); @@ -700,7 +701,7 @@ main(int argc, char **argv) panic("access(\"%s\"): %s", cat_filename, strerror(errno)); exit(EX_OSFILE); } - return mod_cat(cat_filename); + return box_cat(cat_filename); } gopt_arg(opt, 'c', &cfg_filename); @@ -817,9 +818,9 @@ main(int argc, char **argv) if (gopt(opt, 'I')) { init_storage = true; initialize_minimal(); - mod_init(); + box_init(); set_lsn(recovery_state, 1); - snapshot_save(recovery_state, mod_snapshot); + snapshot_save(recovery_state, box_snapshot); exit(EXIT_SUCCESS); } @@ -859,7 +860,7 @@ main(int argc, char **argv) @try { tarantool_L = tarantool_lua_init(); - mod_init(); + box_init(); tarantool_lua_load_cfg(tarantool_L, &cfg); memcached_init(cfg.bind_ipaddr, cfg.memcached_port); /* diff --git a/test/box/CMakeLists.txt b/test/box/CMakeLists.txt index 40f4fa20ed..559ff400c2 100644 --- a/test/box/CMakeLists.txt +++ b/test/box/CMakeLists.txt @@ -1,2 +1,4 @@ +include_directories("${PROJECT_SOURCE_DIR}/connector/c/include") + tarantool_client("protocol" protocol.c) diff --git a/test/connector_c/CMakeLists.txt b/test/connector_c/CMakeLists.txt index c3ab224098..019345e0d9 100644 --- a/test/connector_c/CMakeLists.txt +++ b/test/connector_c/CMakeLists.txt @@ -1,4 +1,5 @@ include_directories("${PROJECT_SOURCE_DIR}/test/unit") +include_directories("${PROJECT_SOURCE_DIR}/connector/c/include") tarantool_client("tt" tt.c) tarantool_client("update" update.c) tarantool_client("xlog" xlog.c) -- GitLab