From 22ffa2d410c8651d46fd099249f3270c3ca1299a Mon Sep 17 00:00:00 2001 From: Dmitry Simonenko <pmwkaa@gmail.com> Date: Fri, 11 Apr 2014 16:17:22 +0400 Subject: [PATCH] remove obsolete client and connector directories. --- .gitmodules | 3 - CMakeLists.txt | 16 - client/CMakeLists.txt | 19 - client/tarancheck/CMakeLists.txt | 29 - client/tarancheck/tc_config.c | 64 - client/tarancheck/tc_config.h | 6 - client/tarancheck/tc_file.c | 228 ---- client/tarancheck/tc_file.h | 9 - client/tarancheck/tc_generate.c | 510 -------- client/tarancheck/tc_generate.h | 7 - client/tarancheck/tc_hash.h | 39 - client/tarancheck/tc_key.h | 18 - client/tarancheck/tc_main.c | 99 -- client/tarancheck/tc_options.c | 108 -- client/tarancheck/tc_options.h | 28 - client/tarancheck/tc_space.c | 200 --- client/tarancheck/tc_space.h | 41 - client/tarancheck/tc_verify.c | 220 ---- client/tarancheck/tc_verify.h | 6 - client/tarantar/CMakeLists.txt | 30 - client/tarantar/compat.c | 71 -- client/tarantar/config.c | 64 - client/tarantar/config.h | 6 - client/tarantar/cursor.c | 100 -- client/tarantar/cursor.h | 19 - client/tarantar/hash.h | 39 - client/tarantar/indexate.c | 435 ------- client/tarantar/indexate.h | 6 - client/tarantar/key.h | 13 - client/tarantar/main.c | 216 ---- client/tarantar/options.c | 126 -- client/tarantar/options.h | 32 - client/tarantar/ref.c | 51 - client/tarantar/ref.h | 20 - client/tarantar/snapshot.c | 258 ---- client/tarantar/snapshot.h | 6 - client/tarantar/space.c | 370 ------ client/tarantar/space.h | 66 - client/tarantar/ts.h | 21 - client/tarantar/update.cc | 119 -- client/tarantar/update.h | 6 - client/tarantool/CMakeLists.txt | 24 - client/tarantool/buf.c | 149 --- client/tarantool/buf.h | 55 - client/tarantool/cli.c | 474 ------- client/tarantool/cli.h | 34 - client/tarantool/main.c | 194 --- client/tarantool/main.h | 72 -- client/tarantool/opt.c | 214 ---- client/tarantool/opt.h | 77 -- client/tarantool/pager.c | 87 -- client/tarantool/pager.h | 36 - client/tarantool/print.c | 230 ---- client/tarantool/print.h | 47 - client/tarantool/print_snap.c | 66 - client/tarantool/print_snap.h | 37 - client/tarantool/print_xlog.c | 207 --- client/tarantool/print_xlog.h | 37 - client/tarantool/query.c | 150 --- client/tarantool/query.h | 57 - client/tarantool/store.c | 224 ---- client/tarantool/store.h | 33 - connector/CMakeLists.txt | 1 - connector/c/CMakeLists.txt | 19 - connector/c/README | 9 - connector/c/include/CMakeLists.txt | 6 - connector/c/include/tarantool/tnt.h | 60 - connector/c/include/tarantool/tnt_buf.h | 49 - connector/c/include/tarantool/tnt_call.h | 36 - connector/c/include/tarantool/tnt_delete.h | 36 - connector/c/include/tarantool/tnt_dir.h | 58 - connector/c/include/tarantool/tnt_enc.h | 37 - connector/c/include/tarantool/tnt_insert.h | 37 - connector/c/include/tarantool/tnt_io.h | 46 - connector/c/include/tarantool/tnt_iob.h | 52 - connector/c/include/tarantool/tnt_iter.h | 153 --- connector/c/include/tarantool/tnt_lex.h | 118 -- connector/c/include/tarantool/tnt_log.h | 119 -- connector/c/include/tarantool/tnt_mem.h | 41 - connector/c/include/tarantool/tnt_net.h | 89 -- connector/c/include/tarantool/tnt_opt.h | 69 - connector/c/include/tarantool/tnt_ping.h | 35 - connector/c/include/tarantool/tnt_proto.h | 83 -- connector/c/include/tarantool/tnt_queue.h | 553 -------- connector/c/include/tarantool/tnt_reply.h | 53 - connector/c/include/tarantool/tnt_request.h | 110 -- connector/c/include/tarantool/tnt_rpl.h | 47 - connector/c/include/tarantool/tnt_select.h | 39 - connector/c/include/tarantool/tnt_snapshot.h | 50 - connector/c/include/tarantool/tnt_sql.h | 36 - connector/c/include/tarantool/tnt_stream.h | 58 - connector/c/include/tarantool/tnt_tuple.h | 68 - connector/c/include/tarantool/tnt_update.h | 77 -- connector/c/include/tarantool/tnt_utf8.h | 52 - connector/c/include/tarantool/tnt_xlog.h | 50 - connector/c/include/tp.h | 1107 ----------------- connector/c/tb | 1 - connector/c/tnt/CMakeLists.txt | 78 -- connector/c/tnt/tnt_buf.c | 179 --- connector/c/tnt/tnt_call.c | 94 -- connector/c/tnt/tnt_delete.c | 75 -- connector/c/tnt/tnt_enc.c | 103 -- connector/c/tnt/tnt_insert.c | 76 -- connector/c/tnt/tnt_iter.c | 389 ------ connector/c/tnt/tnt_mem.c | 66 - connector/c/tnt/tnt_ping.c | 64 - connector/c/tnt/tnt_reply.c | 216 ---- connector/c/tnt/tnt_request.c | 507 -------- connector/c/tnt/tnt_select.c | 110 -- connector/c/tnt/tnt_stream.c | 97 -- connector/c/tnt/tnt_tuple.c | 407 ------ connector/c/tnt/tnt_update.c | 262 ---- connector/c/tntnet/CMakeLists.txt | 70 -- connector/c/tntnet/tnt_io.c | 428 ------- connector/c/tntnet/tnt_iob.c | 67 - connector/c/tntnet/tnt_net.c | 313 ----- connector/c/tntnet/tnt_opt.c | 112 -- connector/c/tntrpl/CMakeLists.txt | 69 - connector/c/tntrpl/tnt_dir.c | 173 --- connector/c/tntrpl/tnt_log.c | 329 ----- connector/c/tntrpl/tnt_rpl.c | 200 --- connector/c/tntrpl/tnt_snapshot.c | 163 --- connector/c/tntrpl/tnt_xlog.c | 163 --- connector/c/tntsql/CMakeLists.txt | 71 -- connector/c/tntsql/tnt_lex.c | 354 ------ connector/c/tntsql/tnt_sql.c | 531 -------- connector/c/tntsql/tnt_utf8.c | 159 --- connector/java/pom.xml | 25 - .../main/java/tarantool/common/ByteUtil.java | 179 --- .../connector/RequestResponseFormatter.java | 210 ---- .../tarantool/connector/TarantoolCommand.java | 89 -- .../connector/TarantoolConnector.java | 58 - .../connector/TarantoolConnectorConfig.java | 36 - .../connector/TarantoolConnectorImpl.java | 344 ----- .../connector/TarantoolResponse.java | 20 - .../connector/TarantoolServerErrorCode.java | 86 -- .../TarantoolConnectorException.java | 13 - .../TarantoolUnavailableException.java | 13 - .../socketpool/AbstractSocketPool.java | 173 --- .../socketpool/DynamicSocketPool.java | 267 ---- .../connector/socketpool/SocketPool.java | 11 - .../socketpool/SocketPoolConfig.java | 116 -- .../socketpool/SocketPoolFactory.java | 21 - .../socketpool/SocketPoolStateMachine.java | 77 -- .../connector/socketpool/SocketPoolType.java | 7 - .../socketpool/StaticSocketPool.java | 130 -- .../exception/SocketPoolClosedException.java | 13 - .../exception/SocketPoolException.java | 13 - .../exception/SocketPoolTimeOutException.java | 13 - .../SocketPoolUnavailableException.java | 13 - .../worker/ChannelSocketWorker.java | 81 -- .../socketpool/worker/FactoryType.java | 34 - .../socketpool/worker/PlainSocketWorker.java | 95 -- .../socketpool/worker/SocketFactory.java | 8 - .../socketpool/worker/SocketWorker.java | 10 - .../worker/SocketWorkerInternal.java | 58 - .../tarantool/sample/TarantoolSample.java | 64 - connector/python/README.rst | 13 - connector/ruby/README | 2 - 159 files changed, 17899 deletions(-) delete mode 100644 client/CMakeLists.txt delete mode 100644 client/tarancheck/CMakeLists.txt delete mode 100644 client/tarancheck/tc_config.c delete mode 100644 client/tarancheck/tc_config.h delete mode 100644 client/tarancheck/tc_file.c delete mode 100644 client/tarancheck/tc_file.h delete mode 100644 client/tarancheck/tc_generate.c delete mode 100644 client/tarancheck/tc_generate.h delete mode 100644 client/tarancheck/tc_hash.h delete mode 100644 client/tarancheck/tc_key.h delete mode 100644 client/tarancheck/tc_main.c delete mode 100644 client/tarancheck/tc_options.c delete mode 100644 client/tarancheck/tc_options.h delete mode 100644 client/tarancheck/tc_space.c delete mode 100644 client/tarancheck/tc_space.h delete mode 100644 client/tarancheck/tc_verify.c delete mode 100644 client/tarancheck/tc_verify.h delete mode 100644 client/tarantar/CMakeLists.txt delete mode 100644 client/tarantar/compat.c delete mode 100644 client/tarantar/config.c delete mode 100644 client/tarantar/config.h delete mode 100644 client/tarantar/cursor.c delete mode 100644 client/tarantar/cursor.h delete mode 100644 client/tarantar/hash.h delete mode 100644 client/tarantar/indexate.c delete mode 100644 client/tarantar/indexate.h delete mode 100644 client/tarantar/key.h delete mode 100644 client/tarantar/main.c delete mode 100644 client/tarantar/options.c delete mode 100644 client/tarantar/options.h delete mode 100644 client/tarantar/ref.c delete mode 100644 client/tarantar/ref.h delete mode 100644 client/tarantar/snapshot.c delete mode 100644 client/tarantar/snapshot.h delete mode 100644 client/tarantar/space.c delete mode 100644 client/tarantar/space.h delete mode 100644 client/tarantar/ts.h delete mode 100644 client/tarantar/update.cc delete mode 100644 client/tarantar/update.h delete mode 100644 client/tarantool/CMakeLists.txt delete mode 100644 client/tarantool/buf.c delete mode 100644 client/tarantool/buf.h delete mode 100644 client/tarantool/cli.c delete mode 100644 client/tarantool/cli.h delete mode 100644 client/tarantool/main.c delete mode 100644 client/tarantool/main.h delete mode 100644 client/tarantool/opt.c delete mode 100644 client/tarantool/opt.h delete mode 100644 client/tarantool/pager.c delete mode 100644 client/tarantool/pager.h delete mode 100644 client/tarantool/print.c delete mode 100644 client/tarantool/print.h delete mode 100644 client/tarantool/print_snap.c delete mode 100644 client/tarantool/print_snap.h delete mode 100644 client/tarantool/print_xlog.c delete mode 100644 client/tarantool/print_xlog.h delete mode 100644 client/tarantool/query.c delete mode 100644 client/tarantool/query.h delete mode 100644 client/tarantool/store.c delete mode 100644 client/tarantool/store.h delete mode 100644 connector/CMakeLists.txt delete mode 100644 connector/c/CMakeLists.txt delete mode 100644 connector/c/README delete mode 100644 connector/c/include/CMakeLists.txt delete mode 100644 connector/c/include/tarantool/tnt.h delete mode 100644 connector/c/include/tarantool/tnt_buf.h delete mode 100644 connector/c/include/tarantool/tnt_call.h delete mode 100644 connector/c/include/tarantool/tnt_delete.h delete mode 100644 connector/c/include/tarantool/tnt_dir.h delete mode 100644 connector/c/include/tarantool/tnt_enc.h delete mode 100644 connector/c/include/tarantool/tnt_insert.h delete mode 100644 connector/c/include/tarantool/tnt_io.h delete mode 100644 connector/c/include/tarantool/tnt_iob.h delete mode 100644 connector/c/include/tarantool/tnt_iter.h delete mode 100644 connector/c/include/tarantool/tnt_lex.h delete mode 100644 connector/c/include/tarantool/tnt_log.h delete mode 100644 connector/c/include/tarantool/tnt_mem.h delete mode 100644 connector/c/include/tarantool/tnt_net.h delete mode 100644 connector/c/include/tarantool/tnt_opt.h delete mode 100644 connector/c/include/tarantool/tnt_ping.h delete mode 100644 connector/c/include/tarantool/tnt_proto.h delete mode 100644 connector/c/include/tarantool/tnt_queue.h delete mode 100644 connector/c/include/tarantool/tnt_reply.h delete mode 100644 connector/c/include/tarantool/tnt_request.h delete mode 100644 connector/c/include/tarantool/tnt_rpl.h delete mode 100644 connector/c/include/tarantool/tnt_select.h delete mode 100644 connector/c/include/tarantool/tnt_snapshot.h delete mode 100644 connector/c/include/tarantool/tnt_sql.h delete mode 100644 connector/c/include/tarantool/tnt_stream.h delete mode 100644 connector/c/include/tarantool/tnt_tuple.h delete mode 100644 connector/c/include/tarantool/tnt_update.h delete mode 100644 connector/c/include/tarantool/tnt_utf8.h delete mode 100644 connector/c/include/tarantool/tnt_xlog.h delete mode 100644 connector/c/include/tp.h delete mode 160000 connector/c/tb delete mode 100644 connector/c/tnt/CMakeLists.txt delete mode 100644 connector/c/tnt/tnt_buf.c delete mode 100644 connector/c/tnt/tnt_call.c delete mode 100644 connector/c/tnt/tnt_delete.c delete mode 100644 connector/c/tnt/tnt_enc.c delete mode 100644 connector/c/tnt/tnt_insert.c delete mode 100644 connector/c/tnt/tnt_iter.c delete mode 100644 connector/c/tnt/tnt_mem.c delete mode 100644 connector/c/tnt/tnt_ping.c delete mode 100644 connector/c/tnt/tnt_reply.c delete mode 100644 connector/c/tnt/tnt_request.c delete mode 100644 connector/c/tnt/tnt_select.c delete mode 100644 connector/c/tnt/tnt_stream.c delete mode 100644 connector/c/tnt/tnt_tuple.c delete mode 100644 connector/c/tnt/tnt_update.c delete mode 100644 connector/c/tntnet/CMakeLists.txt delete mode 100644 connector/c/tntnet/tnt_io.c delete mode 100644 connector/c/tntnet/tnt_iob.c delete mode 100644 connector/c/tntnet/tnt_net.c delete mode 100644 connector/c/tntnet/tnt_opt.c delete mode 100644 connector/c/tntrpl/CMakeLists.txt delete mode 100644 connector/c/tntrpl/tnt_dir.c delete mode 100644 connector/c/tntrpl/tnt_log.c delete mode 100644 connector/c/tntrpl/tnt_rpl.c delete mode 100644 connector/c/tntrpl/tnt_snapshot.c delete mode 100644 connector/c/tntrpl/tnt_xlog.c delete mode 100644 connector/c/tntsql/CMakeLists.txt delete mode 100644 connector/c/tntsql/tnt_lex.c delete mode 100644 connector/c/tntsql/tnt_sql.c delete mode 100644 connector/c/tntsql/tnt_utf8.c delete mode 100644 connector/java/pom.xml delete mode 100644 connector/java/src/main/java/tarantool/common/ByteUtil.java delete mode 100644 connector/java/src/main/java/tarantool/connector/RequestResponseFormatter.java delete mode 100644 connector/java/src/main/java/tarantool/connector/TarantoolCommand.java delete mode 100644 connector/java/src/main/java/tarantool/connector/TarantoolConnector.java delete mode 100644 connector/java/src/main/java/tarantool/connector/TarantoolConnectorConfig.java delete mode 100644 connector/java/src/main/java/tarantool/connector/TarantoolConnectorImpl.java delete mode 100644 connector/java/src/main/java/tarantool/connector/TarantoolResponse.java delete mode 100644 connector/java/src/main/java/tarantool/connector/TarantoolServerErrorCode.java delete mode 100644 connector/java/src/main/java/tarantool/connector/exception/TarantoolConnectorException.java delete mode 100644 connector/java/src/main/java/tarantool/connector/exception/TarantoolUnavailableException.java delete mode 100644 connector/java/src/main/java/tarantool/connector/socketpool/AbstractSocketPool.java delete mode 100644 connector/java/src/main/java/tarantool/connector/socketpool/DynamicSocketPool.java delete mode 100644 connector/java/src/main/java/tarantool/connector/socketpool/SocketPool.java delete mode 100644 connector/java/src/main/java/tarantool/connector/socketpool/SocketPoolConfig.java delete mode 100644 connector/java/src/main/java/tarantool/connector/socketpool/SocketPoolFactory.java delete mode 100644 connector/java/src/main/java/tarantool/connector/socketpool/SocketPoolStateMachine.java delete mode 100644 connector/java/src/main/java/tarantool/connector/socketpool/SocketPoolType.java delete mode 100644 connector/java/src/main/java/tarantool/connector/socketpool/StaticSocketPool.java delete mode 100644 connector/java/src/main/java/tarantool/connector/socketpool/exception/SocketPoolClosedException.java delete mode 100644 connector/java/src/main/java/tarantool/connector/socketpool/exception/SocketPoolException.java delete mode 100644 connector/java/src/main/java/tarantool/connector/socketpool/exception/SocketPoolTimeOutException.java delete mode 100644 connector/java/src/main/java/tarantool/connector/socketpool/exception/SocketPoolUnavailableException.java delete mode 100644 connector/java/src/main/java/tarantool/connector/socketpool/worker/ChannelSocketWorker.java delete mode 100644 connector/java/src/main/java/tarantool/connector/socketpool/worker/FactoryType.java delete mode 100644 connector/java/src/main/java/tarantool/connector/socketpool/worker/PlainSocketWorker.java delete mode 100644 connector/java/src/main/java/tarantool/connector/socketpool/worker/SocketFactory.java delete mode 100644 connector/java/src/main/java/tarantool/connector/socketpool/worker/SocketWorker.java delete mode 100644 connector/java/src/main/java/tarantool/connector/socketpool/worker/SocketWorkerInternal.java delete mode 100644 connector/java/src/main/java/tarantool/sample/TarantoolSample.java delete mode 100644 connector/python/README.rst delete mode 100644 connector/ruby/README diff --git a/.gitmodules b/.gitmodules index 6afb7a5c39..0effb378ae 100644 --- a/.gitmodules +++ b/.gitmodules @@ -13,9 +13,6 @@ [submodule "src/lib/msgpuck"] path = src/lib/msgpuck url = https://github.com/tarantool/msgpuck.git -[submodule "connector/c/tb"] - path = connector/c/tb - url = https://github.com/tarantool/tarantool-c [submodule "third_party/sophia"] path = third_party/sophia url = git://github.com/tarantool/sophia.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 659f610e7f..965c970fba 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,6 @@ project(tarantool C CXX) set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH}) set(CMAKE_INCLUDE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${CMAKE_INCLUDE_PATH}) - include(CheckLibraryExists) include(CheckIncludeFile) include(CheckCCompilerFlag) @@ -25,14 +24,9 @@ find_program(JING jing) find_program(LYNX lynx) find_program(CAT cat) find_program(GIT git) -find_program(RAGEL ragel) find_program(LD ld) find_program(POD2MAN pod2man) - -# Disable tarancheck and tarantar for 1.6 -# set (TARANTOOL_CLIENTS "tarancheck" "tarantar") -set (TARANTOOL_CLIENTS "") # Define PACKAGE macro in tarantool/config.h set (PACKAGE "Tarantool") @@ -173,11 +167,6 @@ message(STATUS "Module package.cpath: ${MODULE_LIBPATH}") # option(ENABLE_DOC "Enable building of documentation" OFF) -option(ENABLE_CLIENT "Enable building of console client" OFF) -if (ENABLE_CLIENT) - set (TARANTOOL_CLIENTS ${TARANTOOL_CLIENTS} "tarantool") -endif() - option(ENABLE_TRACE "Enable debug trace of tarantool_box execution to a file specified in TARANTOOL_TRACE environment variable" ON) @@ -334,11 +323,8 @@ include (cmake/package.cmake) # include (cmake/rpm.cmake) -# Disable connector_c for 1.6 -add_subdirectory(connector) add_subdirectory(src) add_subdirectory(extra) -add_subdirectory(client) add_subdirectory(test) add_subdirectory(doc) @@ -351,7 +337,6 @@ install (FILES README.md LICENSE doc/box-protocol.txt set(TARANTOOL_OPTIONS "-DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}") set(TARANTOOL_OPTIONS "${TARANTOOL_OPTIONS} -DENABLE_STATIC=${ENABLE_STATIC}") set(TARANTOOL_OPTIONS "${TARANTOOL_OPTIONS} -DENABLE_TRACE=${ENABLE_TRACE} -DENABLE_BACKTRACE=${ENABLE_BACKTRACE}") -set(TARANTOOL_OPTIONS "${TARANTOOL_OPTIONS} -DENABLE_CLIENT=${ENABLE_CLIENT}") set(TARANTOOL_BUILD "${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}-${CMAKE_BUILD_TYPE}") set(TARANTOOL_C_COMPILER ${CMAKE_C_COMPILER}) set(TARANTOOL_CXX_COMPILER ${CMAKE_CXX_COMPILER}) @@ -384,7 +369,6 @@ message (STATUS "ENABLE_GCOV: ${ENABLE_GCOV}") message (STATUS "ENABLE_GPROF: ${ENABLE_GPROF}") message (STATUS "ENABLE_TRACE: ${ENABLE_TRACE}") message (STATUS "ENABLE_BACKTRACE: ${ENABLE_BACKTRACE} (symbol resolve: ${HAVE_BFD})") -message (STATUS "ENABLE_CLIENT: ${ENABLE_CLIENT}") message (STATUS "ENABLE_BUNDLED_LUAJIT: ${ENABLE_BUNDLED_LUAJIT}") message (STATUS "ENABLE_BUNDLED_LIBEV: ${ENABLE_BUNDLED_LIBEV}") message (STATUS "ENABLE_BUNDLED_LIBEIO: ${ENABLE_BUNDLED_LIBEIO}") diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt deleted file mode 100644 index 1874b5d548..0000000000 --- a/client/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ - -enable_tnt_compile_flags() - -# function to build tarantool clients that use connector/c -# -function(tarantool_client client_name) - set (client_sources ${ARGV}) - list(REMOVE_ITEM client_sources ${client_name}) - add_executable(${client_name} ${client_sources} - ${CMAKE_SOURCE_DIR}/src/errcode.c) - set (client_libs tntrpl tntnet tntsql tnt) - target_link_libraries (${client_name} ${client_libs}) -endfunction() - -include_directories("${PROJECT_SOURCE_DIR}/connector/c/tb") - -foreach (client ${TARANTOOL_CLIENTS}) - add_subdirectory(${client}) -endforeach() diff --git a/client/tarancheck/CMakeLists.txt b/client/tarancheck/CMakeLists.txt deleted file mode 100644 index 57b4995cbb..0000000000 --- a/client/tarancheck/CMakeLists.txt +++ /dev/null @@ -1,29 +0,0 @@ -project(tnt_checksum) - -set (util_checksum "tarancheck") -set (util_checksum_sources tc_main.c tc_options.c tc_config.c tc_space.c tc_file.c tc_generate.c tc_verify.c) -set (util_checksum_libs tntrpl tntnet tnt gopt) - -set_source_files_properties(${CMAKE_SOURCE_DIR}/cfg/tarantool_box_cfg.c - ${CMAKE_SOURCE_DIR}/cfg/prscfg.c PROPERTIES COMPILE_FLAGS - "-Wno-unused-parameter" - GENERATED True) - -set_source_files_properties(${util_checksum_sources} PROPERTIES OBJECT_DEPENDS - ${CMAKE_SOURCE_DIR}/cfg/tarantool_box_cfg.h) - -list(APPEND util_checksum_sources - ${CMAKE_SOURCE_DIR}/cfg/tarantool_box_cfg.c - ${CMAKE_SOURCE_DIR}/cfg/prscfg.c) - -list(APPEND util_checksum_sources - ${CMAKE_SOURCE_DIR}/third_party/PMurHash.c) - -set_source_files_compile_flags( - ${util_checksum_sources}) -add_executable(${util_checksum} ${util_checksum_sources}) - - -target_link_libraries (${util_checksum} ${util_checksum_libs}) - -install (TARGETS ${util_checksum} DESTINATION bin) diff --git a/client/tarancheck/tc_config.c b/client/tarancheck/tc_config.c deleted file mode 100644 index 925a05ed91..0000000000 --- a/client/tarancheck/tc_config.c +++ /dev/null @@ -1,64 +0,0 @@ - -/* - * 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 <stdlib.h> -#include <stdarg.h> -#include <stdint.h> -#include <stdio.h> -#include <string.h> - -#include <cfg/prscfg.h> -#include <cfg/tarantool_box_cfg.h> - -#include "tc_options.h" -#include "tc_config.h" - -int tc_config_load(struct tc_options *opts) -{ - FILE *f = fopen(opts->file_config, "r"); - if (f == NULL) { - printf("failed to open config file: %s\n", opts->file_config); - return -1; - } - int accepted = 0, - skipped = 0, - optional = 0; - int rc = parse_cfg_file_tarantool_cfg(&opts->cfg, f, 0, - &accepted, - &skipped, - &optional); - fclose(f); - if (rc == -1) - return -1; - rc = check_cfg_tarantool_cfg(&opts->cfg); - if (rc == -1) - return -1; - return 0; -} diff --git a/client/tarancheck/tc_config.h b/client/tarancheck/tc_config.h deleted file mode 100644 index 10d14ce323..0000000000 --- a/client/tarancheck/tc_config.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef TC_CONFIG_H_INCLUDED -#define TC_CONFIG_H_INCLUDED - -int tc_config_load(struct tc_options *opts); - -#endif diff --git a/client/tarancheck/tc_file.c b/client/tarancheck/tc_file.c deleted file mode 100644 index 5c19bd1757..0000000000 --- a/client/tarancheck/tc_file.c +++ /dev/null @@ -1,228 +0,0 @@ - -/* - * 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 <stdlib.h> -#include <stdarg.h> -#include <stdint.h> -#include <inttypes.h> -#include <stdio.h> -#include <string.h> -#include <assert.h> - -#include <connector/c/include/tarantool/tnt.h> -#include <connector/c/include/tarantool/tnt_xlog.h> -#include <connector/c/include/tarantool/tnt_snapshot.h> -#include <connector/c/include/tarantool/tnt_dir.h> - -#include <cfg/prscfg.h> -#include <cfg/tarantool_box_cfg.h> - -#include "tc_key.h" -#include "tc_hash.h" -#include "tc_options.h" -#include "tc_config.h" -#include "tc_space.h" -#include "tc_file.h" - -struct tc_file_header { - uint32_t magic; - uint32_t version; - uint64_t last_xlog_lsn; - uint64_t last_snap_lsn; - uint32_t spaces; - uint32_t data_offset; -}; - -struct tc_file_header_space { - uint32_t space; - uint64_t count_log; - uint64_t count_snap; - uint32_t data_offset; -}; - -int tc_file_save_space(struct tc_space *s, FILE *f) -{ - struct tc_file_header_space h = { - .space = s->id, - .count_log = s->hash_log->size, - .count_snap = s->hash_snap->size, - .data_offset = 0 - }; - - fwrite(&h, sizeof(struct tc_file_header_space), 1, f); - - mh_int_t pos = 0; - while (pos != mh_end(s->hash_log)) { - if (mh_exist((s->hash_log), pos)) { - const struct tc_key *k = *mh_pk_node(s->hash_log, pos); - if (fwrite((char*)k, sizeof(struct tc_key) + k->size, 1, f) != 1) - return -1; - } - pos++; - } - pos = 0; - while (pos != mh_end(s->hash_snap)) { - if (mh_exist((s->hash_snap), pos)) { - const struct tc_key *k = *mh_pk_node(s->hash_snap, pos); - if (fwrite((char*)k, sizeof(struct tc_key) + k->size, 1, f) != 1) - return -1; - } - pos++; - } - - return 0; -} - -#define TC_FILE_MAGIC 0x123456 - -int tc_file_save(struct tc_spaces *s, - uint64_t last_snap_lsn, - uint64_t last_xlog_lsn, char *file) -{ - struct tc_file_header h = { - .magic = TC_FILE_MAGIC, - .version = 1, - .last_xlog_lsn = last_xlog_lsn, - .last_snap_lsn = last_snap_lsn, - .spaces = s->t->size, - .data_offset = 0 - }; - - FILE *f = fopen(file, "w+"); - if (f == NULL) - return -1; - - fwrite(&h, sizeof(struct tc_file_header), 1, f); - - mh_int_t pos = 0; - while (pos != mh_end(s->t)) { - if (mh_exist((s->t), pos)) { - struct tc_space *space = mh_u32ptr_node(s->t, pos)->val; - int rc = tc_file_save_space(space, f); - if (rc == -1) { - fclose(f); - return -1; - } - } - pos++; - } - - fclose(f); - return 0; -} - -struct tc_key *tc_file_load_key(FILE *f) -{ - struct tc_key kh; - if (fread(&kh, sizeof(struct tc_key), 1, f) != 1) - return NULL; - struct tc_key *k = malloc(sizeof(struct tc_key) + kh.size); - if (k == NULL) - return NULL; - memcpy(k, &kh, sizeof(struct tc_key)); - if (fread((char*)k + sizeof(struct tc_key), kh.size, 1, f) != 1) { - free(k); - return NULL; - } - return k; -} - -int tc_file_load(struct tc_spaces *s, char *file, - uint64_t *last_xlog_lsn, uint64_t *last_snap_lsn) -{ - struct tc_file_header h; - memset(&h, 0, sizeof(h)); - - FILE *f = fopen(file, "r"); - if (f == NULL) - return -1; - if (fread(&h, sizeof(struct tc_file_header), 1, f) != 1) { - fclose(f); - return -1; - } - if (h.magic != TC_FILE_MAGIC) { - fclose(f); - return -1; - } - - int i = 0; - for (; i < h.spaces; i++) { - struct tc_file_header_space sh; - if (fread(&sh, sizeof(struct tc_file_header_space), 1, f) != 1) { - fclose(f); - return -1; - } - struct tc_space *space = tc_space_match(s, sh.space); - if (space == NULL) { - fclose(f); - return -1; - } - - uint64_t c = 0; - while (c < sh.count_log) { - struct tc_key *k = tc_file_load_key(f); - if (k == NULL) { - fclose(f); - return -1; - } - const struct tc_key *node = k; - mh_int_t pos = mh_pk_put(space->hash_log, &node, NULL, - space); - if (pos == mh_end(space->hash_log)) { - fclose(f); - return -1; - } - c++; - } - - c = 0; - while (c < sh.count_snap) { - struct tc_key *k = tc_file_load_key(f); - if (k == NULL) { - fclose(f); - return -1; - } - const struct tc_key *node = k; - mh_int_t pos = mh_pk_put(space->hash_snap, &node, - NULL, space); - if (pos == mh_end(space->hash_log)) { - fclose(f); - return -1; - } - c++; - } - } - - *last_xlog_lsn = h.last_xlog_lsn; - *last_snap_lsn = h.last_snap_lsn; - - fclose(f); - return 0; -} diff --git a/client/tarancheck/tc_file.h b/client/tarancheck/tc_file.h deleted file mode 100644 index edfde9333f..0000000000 --- a/client/tarancheck/tc_file.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef TC_FILE_H_INCLUDED -#define TC_FILE_H_INCLUDED - -int tc_file_save(struct tc_spaces *s, uint64_t last_snap_lsn , uint64_t last_xlog_lsn, char *file); -int tc_file_load(struct tc_spaces *s, char *file, - uint64_t *last_xlog_lsn, - uint64_t *last_snap_lsn); - -#endif diff --git a/client/tarancheck/tc_generate.c b/client/tarancheck/tc_generate.c deleted file mode 100644 index b478c4623f..0000000000 --- a/client/tarancheck/tc_generate.c +++ /dev/null @@ -1,510 +0,0 @@ - -/* - * 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 <stdlib.h> -#include <stdarg.h> -#include <stdint.h> -#include <stdio.h> -#include <string.h> -#include <assert.h> - -#include <connector/c/include/tarantool/tnt.h> -#include <connector/c/include/tarantool/tnt_xlog.h> -#include <connector/c/include/tarantool/tnt_snapshot.h> -#include <connector/c/include/tarantool/tnt_dir.h> - -#include <cfg/prscfg.h> -#include <cfg/tarantool_box_cfg.h> - -#include <third_party/PMurHash.h> -#include <third_party/crc32.h> - -#include "tc_key.h" -#include "tc_hash.h" -#include "tc_options.h" -#include "tc_config.h" -#include "tc_space.h" -#include "tc_generate.h" -#include "tc_file.h" - -uint32_t -search_hash(const struct tc_key *k, struct tc_space *s) -{ - uint32_t h = 13; - int i; - for (i = 0; i < s->pk.count; i++) { - switch (s->pk.fields[i].type) { - case TC_SPACE_KEY_NUM: { - assert(TC_KEY_SIZE(k, i) == 4); - uint32_t a32 = *(uint32_t *)TC_KEY_DATA(k, i); - h = (h << 9) ^ (h >> 23) ^ a32; - break; - } - case TC_SPACE_KEY_NUM64: { - uint64_t a64 = *(uint64_t *) (TC_KEY_DATA(k, i)); - h = (h << 9) ^ (h >> 23) ^ (uint32_t) (a64); - h = (h << 9) ^ (h >> 23) ^ (uint32_t) (a64 >> 32); - break; - } - case TC_SPACE_KEY_STRING: - h = PMurHash32(h, TC_KEY_DATA(k, i), TC_KEY_SIZE(k, i)); - break; - case TC_SPACE_KEY_UNKNOWN: - assert(1); - break; - } - } - - return h; -} - -int -search_equal(const struct tc_key *a, - const struct tc_key *b, struct tc_space *s) -{ - if (a->size != b->size) - return 0; - - int i; - for (i = 0; i < s->pk.count; i++) { - switch (s->pk.fields[i].type) { - case TC_SPACE_KEY_NUM: { - assert(TC_KEY_SIZE(a, i) == 4); - assert(TC_KEY_SIZE(b, i) == 4); - uint32_t av = *((uint32_t *) TC_KEY_DATA(a, i)); - uint32_t bv = *((uint32_t *) TC_KEY_DATA(b, i)); - if (av != bv) - return 0; - break; - } - case TC_SPACE_KEY_NUM64: { - assert(TC_KEY_SIZE(a, i) == 8); - assert(TC_KEY_SIZE(b, i) == 8); - uint64_t av = *((uint64_t *) TC_KEY_DATA(a, i)); - uint64_t bv = *((uint64_t *) TC_KEY_DATA(b, i)); - if (av != bv) - return 0; - break; - } - case TC_SPACE_KEY_STRING: - if (TC_KEY_SIZE(a, i) != TC_KEY_SIZE(b, i)) - return 0; - if (memcmp(TC_KEY_DATA(a, i), TC_KEY_DATA(b, i), - TC_KEY_SIZE(a, i)) != 0) - return 0; - break; - case TC_SPACE_KEY_UNKNOWN: - assert(1); - break; - } - } - return 1; -} - -static inline int -tc_generate_of(struct tnt_request *r, uint32_t *ns, struct tnt_tuple **t) -{ - switch (r->h.type) { - case TNT_OP_INSERT: - *ns = r->r.insert.h.ns; - *t = &r->r.insert.t; - return 0; - case TNT_OP_UPDATE: - *ns = r->r.update.h.ns; - *t = &r->r.update.t; - return 0; - case TNT_OP_DELETE: - *ns = r->r.del.h.ns; - *t = &r->r.del.t; - return 0; - } - return -1; -} - -struct tc_key* -tc_generate_key(struct tc_space *s, struct tnt_tuple *t) -{ - size_t size = 0; - - /* calculate total key size */ - int i; - for (i = 0; i < s->pk.count; i++) { - struct tnt_iter it; - tnt_iter(&it, t); - if (tnt_field(&it, t, s->pk.fields[i].n) == NULL) - return NULL; - if (it.status != TNT_ITER_OK) - return NULL; - size += TNT_IFIELD_SIZE(&it); - } - - /* allocate key */ - size_t off = s->pk.count * sizeof(struct tc_key_field); - size = off + size; - - struct tc_key *k = malloc(sizeof(struct tc_key) + size); - if (k == NULL) - return NULL; - k->size = size; - k->crc = 0; - - /* initialize key */ - for (i = 0; i < s->pk.count; i++) { - struct tnt_iter it; - tnt_iter(&it, t); - if (tnt_field(&it, t, s->pk.fields[i].n) == NULL) { - free(k); - tnt_iter_free(&it); - return NULL; - } - if (it.status != TNT_ITER_OK) { - free(k); - tnt_iter_free(&it); - return NULL; - } - k->i[i].size = TNT_IFIELD_SIZE(&it); - k->i[i].offset = off; - - memcpy((char*)k + sizeof(struct tc_key) + off, - TNT_IFIELD_DATA(&it), - TNT_IFIELD_SIZE(&it)); - - off += TNT_IFIELD_SIZE(&it); - tnt_iter_free(&it); - } - - return k; -} - -static int -tc_generate_entry(struct tc_spaces *s, struct tnt_request *r) -{ - /* 1. match space */ - uint32_t ns = 0; - struct tnt_tuple *t = NULL; - if (tc_generate_of(r, &ns, &t) == -1) { - printf("bad xlog operation %d\n", r->h.type); - return -1; - } - struct tc_space *space = tc_space_match(s, ns); - if (space == NULL) { - printf("space %d is not defined\n", ns); - return -1; - } - /* 2. create key */ - struct tc_key *k = tc_generate_key(space, t); - if (k == NULL) { - printf("failed to create key\n"); - return -1; - } - /* 3. put into hash */ - const struct tc_key *node = k; - mh_int_t pos = mh_pk_put(space->hash_log, &node, NULL, space); - if (pos == mh_end(space->hash_log)) { - free(k); - return -1; - } - return 0; -} - -static int -tc_generate_xlog(struct tc_spaces *s, char *wal_dir, uint64_t file_lsn, - uint64_t start, - uint64_t *last) -{ - char path[1024]; - snprintf(path, sizeof(path), "%s/%020llu.xlog", wal_dir, - (unsigned long long) file_lsn); - - printf("(xlog) %020llu.xlog\r", - (unsigned long long) file_lsn); - fflush(stdout); - - struct tnt_stream st; - tnt_xlog(&st); - if (tnt_xlog_open(&st, path) == -1) { - printf("failed to open xlog file\n"); - tnt_stream_free(&st); - return -1; - } - - struct tnt_iter i; - tnt_iter_request(&i, &st); - int count = 0; - int rc = 0; - while (tnt_next(&i)) { - struct tnt_request *r = TNT_IREQUEST_PTR(&i); - struct tnt_stream_xlog *xs = - TNT_SXLOG_CAST(TNT_IREQUEST_STREAM(&i)); - if (xs->log.current.hdr.lsn > *last) - *last = xs->log.current.hdr.lsn; - if (xs->log.current.hdr.lsn <= start) - continue; - rc = tc_generate_entry(s, r); - if (rc == -1) - goto done; - if (count % 10000 == 0) { - printf("(xlog) %020llu.xlog %.3fM processed\r", - (unsigned long long) file_lsn, - (float)count / 1000000); - fflush(stdout); - } - count++; - } - printf("\n"); - if (i.status == TNT_ITER_FAIL) { - printf("xlog parsing failed: %s\n", tnt_xlog_strerror(&st)); - rc = -1; - } -done: - tnt_iter_free(&i); - tnt_stream_free(&st); - return rc; -} - -static int -tc_generate_waldir_xlog(struct tc_spaces *s, struct tnt_dir *wal_dir, - uint64_t snap_lsn, uint64_t *last, - int i) -{ - int rc; - if (i < wal_dir->count) { - rc = tc_generate_xlog(s, wal_dir->path, wal_dir->files[i].lsn, - snap_lsn, last); - if (rc == -1) - return -1; - } - for (i++; i < wal_dir->count; i++) { - rc = tc_generate_xlog(s, wal_dir->path, wal_dir->files[i].lsn, 0, - last); - if (rc == -1) - return -1; - } - return 0; -} - -static int -tc_generate_waldir(struct tc_spaces *s, uint64_t last_snap_lsn, - uint64_t *last_xlog_lsn, char *path) -{ - /* get latest existing lsn after snapshot */ - struct tnt_dir wal_dir; - tnt_dir_init(&wal_dir, TNT_DIR_XLOG); - - int rc = tnt_dir_scan(&wal_dir, path); - if (rc == -1) { - printf("failed to open wal directory\n"); - tnt_dir_free(&wal_dir); - return -1; - } - - /* match xlog file containling latest snapshot lsn record */ - if (last_snap_lsn == 1) { - rc = tc_generate_waldir_xlog(s, &wal_dir, last_snap_lsn, last_xlog_lsn, 0); - if (rc == -1) { - tnt_dir_free(&wal_dir); - return -1; - } - goto done; - } - uint64_t xlog_inc = 0; - rc = tnt_dir_match_inc(&wal_dir, last_snap_lsn, &xlog_inc); - if (rc == -1) { - printf("failed to match xlog with snapshot lsn\n"); - tnt_dir_free(&wal_dir); - return -1; - } - - /* index all xlog records from xlog file (a:last_snap_lsn) to - * latest existing xlog lsn */ - int i = 0; - while (i < wal_dir.count && wal_dir.files[i].lsn != xlog_inc) - i++; - - rc = tc_generate_waldir_xlog(s, &wal_dir, last_snap_lsn, last_xlog_lsn, i); - if (rc == -1) { - tnt_dir_free(&wal_dir); - return -1; - } -done: - tnt_dir_free(&wal_dir); - return 0; -} - -static int -tc_generate_snaprow(struct tc_spaces *s, struct tnt_iter_storage *is, - struct tnt_stream_snapshot *ss) -{ - struct tc_space *space = tc_space_match(s, ss->log.current.row_snap.space); - - struct tc_key *k = tc_generate_key(space, &is->t); - if (k == NULL) { - printf("failed to create key\n"); - return -1; - } - - /* foreach snapshot row which does not exist in index dump: - * calculate crc and add to the index */ - const struct tc_key *node = k; - mh_int_t pos = mh_pk_get(space->hash_log, &node, space); - const struct tc_key *v = NULL; - if (pos != mh_end(space->hash_log)) - v = *mh_pk_node(space->hash_log, pos); - if (v == NULL) { - k->crc = crc32c(0, (unsigned char*)is->t.data, is->t.size); - const struct tc_key *node = k; - mh_int_t pos = mh_pk_put(space->hash_snap, &node, NULL, - space); - if (pos == mh_end(space->hash_snap)) { - free(k); - return -1; - } - } else { - free(k); - } - - return 0; -} - -static int -tc_generate_snapshot(struct tc_spaces *s, uint64_t lsn, char *snap_dir) -{ - char path[1024]; - snprintf(path, sizeof(path), "%s/%020llu.snap", snap_dir, - (unsigned long long) lsn); - printf("(snapshot) %020llu.snap\n", - (unsigned long long) lsn); - - struct tnt_stream st; - tnt_snapshot(&st); - if (tnt_snapshot_open(&st, path) == -1) { - printf("failed to open snapshot file\n"); - tnt_stream_free(&st); - return -1; - } - struct tnt_iter i; - tnt_iter_storage(&i, &st); - int rc = 0; - while (tnt_next(&i)) { - struct tnt_iter_storage *is = TNT_ISTORAGE(&i); - struct tnt_stream_snapshot *ss = - TNT_SSNAPSHOT_CAST(TNT_IREQUEST_STREAM(&i)); - rc = tc_generate_snaprow(s, is, ss); - if (rc == -1) - goto done; - } - if (i.status == TNT_ITER_FAIL) { - printf("snapshot parsing failed: %s\n", tnt_snapshot_strerror(&st)); - rc = -1; - } -done: - tnt_iter_free(&i); - tnt_stream_free(&st); - return rc; -} - -int tc_generate(struct tc_options *opts) -{ - printf(">>> Signature file generation\n"); - - /* 1. create spaces according to a configuration file */ - struct tc_spaces s; - int rc = tc_space_init(&s); - if (rc == -1) - return -1; -#if 0 - rc = tc_space_fill(&s, opts); - if (rc == -1) { - tc_space_free(&s); - return -1; - } -#endif - printf("configured spaces: %d\n", mh_size(s.t)); - printf("snap_dir: %s\n", opts->cfg.snap_dir); - printf("wal_dir: %s\n", opts->cfg.wal_dir); - - /* 2. find newest snapshot lsn */ - struct tnt_dir snap_dir; - tnt_dir_init(&snap_dir, TNT_DIR_SNAPSHOT); - - if (opts->cfg.snap_dir == NULL) { - printf("snapshot directory is not specified\n"); - tc_space_free(&s); - return -1; - } - if (opts->cfg.wal_dir == NULL) { - printf("xlog directory is not specified\n"); - tc_space_free(&s); - return -1; - } - rc = tnt_dir_scan(&snap_dir, opts->cfg.snap_dir); - if (rc == -1) { - printf("failed to open snapshot directory\n"); - goto error; - } - uint64_t last_snap_lsn = 0; - rc = tnt_dir_match_gt(&snap_dir, &last_snap_lsn); - if (rc == -1) { - printf("failed to match greatest snapshot lsn\n"); - goto error; - } - printf("last snapshot lsn: %llu\n", - (unsigned long long) last_snap_lsn); - - /* 3. - * a. get latest existing lsn after snapshot - * b. index all xlogs from newest snapshot lsn to latest xlog lsn - */ - uint64_t last_xlog_lsn = 0; - rc = tc_generate_waldir(&s, last_snap_lsn, &last_xlog_lsn, opts->cfg.wal_dir); - if (rc == -1) - goto error; - printf("last xlog lsn: %llu\n", (unsigned long long) last_xlog_lsn); - - /* 4. build index on each snapshot row which doesnt not exist in - * index dump (2) - */ - rc = tc_generate_snapshot(&s, last_snap_lsn, opts->cfg.snap_dir); - if (rc == -1) - goto error; - /* 5. save signature file with both 2 and 3 indexes */ - printf("(signature) saving %s\n", opts->file); - rc = tc_file_save(&s, last_snap_lsn, last_xlog_lsn, (char*)opts->file); - if (rc == -1) - goto error; - - tnt_dir_free(&snap_dir); - tc_space_free(&s); - return 0; -error: - tnt_dir_free(&snap_dir); - tc_space_free(&s); - return -1; -} diff --git a/client/tarancheck/tc_generate.h b/client/tarancheck/tc_generate.h deleted file mode 100644 index 761b5a0dba..0000000000 --- a/client/tarancheck/tc_generate.h +++ /dev/null @@ -1,7 +0,0 @@ -#ifndef TC_GENERATE_H_INCLUDED -#define TC_GENERATE_H_INCLUDED - -struct tc_key *tc_generate_key(struct tc_space *s, struct tnt_tuple *t); -int tc_generate(struct tc_options *opts); - -#endif diff --git a/client/tarancheck/tc_hash.h b/client/tarancheck/tc_hash.h deleted file mode 100644 index 23b1030660..0000000000 --- a/client/tarancheck/tc_hash.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef TC_HASH_H_INCLUDED -#define TC_HASH_H_INCLUDED - -#if !MH_SOURCE -#define MH_UNDEF -#endif - -#include <stdint.h> - -#define mh_name _u32ptr -struct mh_u32ptr_node_t { - uint32_t key; - void *val; -}; - -#define mh_node_t struct mh_u32ptr_node_t -#define mh_arg_t void * -#define mh_hash(a, arg) (a->key) -#define mh_eq(a, b, arg) ((a->key) == (b->key)) -#include <mhash.h> - - -struct tc_space; - -uint32_t -search_hash(const struct tc_key *k, struct tc_space *s); - -int -search_equal(const struct tc_key *a, const struct tc_key *b, - struct tc_space *s); - -#define mh_name _pk -#define mh_node_t struct tc_key * -#define mh_arg_t struct tc_space * -#define mh_hash(a, arg) search_hash(*(a), arg) -#define mh_eq(a, b, arg) search_equal(*(a), *(b), arg) -#include <mhash.h> - -#endif diff --git a/client/tarancheck/tc_key.h b/client/tarancheck/tc_key.h deleted file mode 100644 index 739785f62f..0000000000 --- a/client/tarancheck/tc_key.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef TC_KEY_H_INCLUDED -#define TC_KEY_H_INCLUDED - -struct tc_key_field { - int offset; - int size; -}; - -struct tc_key { - uint32_t crc; - size_t size; - struct tc_key_field i[]; -}; - -#define TC_KEY_DATA(K, I) ((char*)(K) + sizeof(struct tc_key) + (K)->i[(I)].offset) -#define TC_KEY_SIZE(K, I) ((K)->i[(I)].size) - -#endif diff --git a/client/tarancheck/tc_main.c b/client/tarancheck/tc_main.c deleted file mode 100644 index 29501519fd..0000000000 --- a/client/tarancheck/tc_main.c +++ /dev/null @@ -1,99 +0,0 @@ - -/* - * 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 <stdlib.h> -#include <stdarg.h> -#include <stdint.h> -#include <stdio.h> -#include <string.h> - -#include <connector/c/include/tarantool/tnt.h> -#include <connector/c/include/tarantool/tnt_xlog.h> -#include <connector/c/include/tarantool/tnt_snapshot.h> -#include <connector/c/include/tarantool/tnt_dir.h> - -#include <third_party/gopt/gopt.h> - -#include <cfg/prscfg.h> -#include <cfg/tarantool_box_cfg.h> - -#include "tc_key.h" -#define MH_SOURCE 1 -#include "tc_hash.h" -#include "tc_options.h" -#include "tc_config.h" -#include "tc_space.h" -#include "tc_generate.h" -#include "tc_verify.h" - -void out_warning(ConfettyError v, char *format, ...) { - (void)v; - va_list ap; - va_start(ap, format); - vprintf(format, ap); - printf("\n"); - va_end(ap); -} - -int main(int argc, char *argv[]) -{ - struct tc_options opts; - tc_options_init(&opts); - - int rc; - enum tc_options_mode mode = tc_options_process(&opts, argc, argv); - switch (mode) { - case TC_MODE_USAGE: - return tc_options_usage(); - break; - case TC_MODE_VERSION: - return tc_options_version(); - break; - case TC_MODE_VERIFY: - rc = tc_config_load(&opts); - if (rc == -1) - return 1; - rc = tc_verify(&opts); - if (rc == -1) - break; - break; - case TC_MODE_GENERATE: - rc = tc_config_load(&opts); - if (rc == -1) - return 1; - rc = tc_generate(&opts); - if (rc == -1) - break; - break; - } - - tc_options_free(&opts); - return 0; -} diff --git a/client/tarancheck/tc_options.c b/client/tarancheck/tc_options.c deleted file mode 100644 index 03ae44182d..0000000000 --- a/client/tarancheck/tc_options.c +++ /dev/null @@ -1,108 +0,0 @@ - -/* - * 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 <stdlib.h> -#include <stdarg.h> -#include <stdint.h> -#include <stdio.h> -#include <string.h> - -#include <third_party/gopt/gopt.h> - -#include <cfg/prscfg.h> -#include <cfg/tarantool_box_cfg.h> - -#include "tc_options.h" - -static const void *opts_def = gopt_start( - gopt_option('G', GOPT_ARG, gopt_shorts('G'), - gopt_longs("generate"), " <file>", "generate signature file"), - gopt_option('W', GOPT_ARG, gopt_shorts('W'), - gopt_longs("verify"), " <file>", "verify signature file"), - gopt_option('?', 0, gopt_shorts('?'), gopt_longs("help"), - NULL, "display this help and exit"), - gopt_option('V', 0, gopt_shorts('V'), gopt_longs("version"), - NULL, "display version information and exit") -); - -void tc_options_init(struct tc_options *opts) { - memset(opts, 0, sizeof(struct tc_options)); - init_tarantool_cfg(&opts->cfg); -} - -void tc_options_free(struct tc_options *opts) { - destroy_tarantool_cfg(&opts->cfg); -} - -int tc_options_usage(void) -{ - printf("Tarantool checksum: checksum master and replica logs.\n"); - printf("usage: tarancheck <options> <tarantool_config>\n\n"); - gopt_help(opts_def); - return 1; -} - -int tc_options_version(void) -{ - printf("tarancheck client, version %s.%s\n", - TC_VERSION_MAJOR, - TC_VERSION_MINOR); - return 1; -} - -enum tc_options_mode -tc_options_process(struct tc_options *opts, int argc, char **argv) -{ - void *opt = gopt_sort(&argc, (const char**)argv, opts_def); - /* usage */ - if (gopt(opt, '?')) { - opts->mode = TC_MODE_USAGE; - goto done; - } - /* version */ - if (gopt(opt, 'V')) { - opts->mode = TC_MODE_VERSION; - goto done; - } - /* generate or verify */ - if (gopt_arg(opt, 'G', &opts->file)) { - opts->mode = TC_MODE_GENERATE; - } else - if (gopt_arg(opt, 'W', &opts->file)) { - opts->mode = TC_MODE_VERIFY; - } else { - opts->mode = TC_MODE_USAGE; - goto done; - } - opts->file_config = argv[1]; -done: - gopt_free(opt); - return opts->mode; -} diff --git a/client/tarancheck/tc_options.h b/client/tarancheck/tc_options.h deleted file mode 100644 index 4c1078d264..0000000000 --- a/client/tarancheck/tc_options.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef TC_OPTIONS_H_INCLUDED -#define TC_OPTIONS_H_INCLUDED - -enum tc_options_mode { - TC_MODE_USAGE, - TC_MODE_VERSION, - TC_MODE_GENERATE, - TC_MODE_VERIFY -}; - -#define TC_VERSION_MINOR "1" -#define TC_VERSION_MAJOR "0" - -struct tc_options { - enum tc_options_mode mode; - const char *file; - const char *file_config; - struct tarantool_cfg cfg; -}; - -void tc_options_init(struct tc_options *opts); -void tc_options_free(struct tc_options *opts); - -enum tc_options_mode tc_options_process(struct tc_options *opts, int argc, char **argv); -int tc_options_usage(void); -int tc_options_version(void); - -#endif diff --git a/client/tarancheck/tc_space.c b/client/tarancheck/tc_space.c deleted file mode 100644 index 9635d6742b..0000000000 --- a/client/tarancheck/tc_space.c +++ /dev/null @@ -1,200 +0,0 @@ - -/* - * 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 <stdlib.h> -#include <stdarg.h> -#include <stdint.h> -#include <stdio.h> -#include <string.h> - -#include <cfg/prscfg.h> -#include <cfg/tarantool_box_cfg.h> - -#include "tc_key.h" -#include "tc_hash.h" -#include "tc_options.h" -#include "tc_space.h" - -int tc_space_init(struct tc_spaces *s) { - s->t = mh_u32ptr_new(); - if (s->t == NULL) - return -1; - return 0; -} - -void tc_space_free(struct tc_spaces *s) -{ - while (mh_size(s->t) > 0) { - mh_int_t i = mh_first(s->t); - - struct tc_space *space = mh_u32ptr_node(s->t, i)->val; - mh_u32ptr_del(s->t, i, NULL); - - mh_int_t pos = 0; - while (pos != mh_end(space->hash_log)) { - if (mh_exist((space->hash_log), pos)) { - struct tc_key *k = - *mh_pk_node(space->hash_log, pos); - free(k); - } - pos++; - } - pos = 0; - while (pos != mh_end(space->hash_snap)) { - if (mh_exist((space->hash_snap), pos)) { - struct tc_key *k = - *mh_pk_node(space->hash_snap, pos); - free(k); - } - pos++; - } - - mh_pk_delete(space->hash_log); - mh_pk_delete(space->hash_snap); - - free(space->pk.fields); - free(space); - } - mh_u32ptr_delete(s->t); -} - -struct tc_space *tc_space_create(struct tc_spaces *s, uint32_t id) { - struct tc_space *space = malloc(sizeof(struct tc_space)); - if (space == NULL) - return NULL; - memset(space, 0, sizeof(struct tc_space)); - space->id = id; - space->hash_log = mh_pk_new(); - space->hash_snap = mh_pk_new(); - - const struct mh_u32ptr_node_t node = { .key = space->id, .val = space }; - mh_u32ptr_put(s->t, &node, NULL, space); - return space; -} - -struct tc_space *tc_space_match(struct tc_spaces *s, uint32_t id) { - const struct mh_u32ptr_node_t node = { .key = id }; - mh_int_t k = mh_u32ptr_get(s->t, &node, NULL); - struct tc_space *space = NULL; - if (k != mh_end(s->t)) - space = mh_u32ptr_node(s->t, k)->val; - return space; -} - -enum tc_space_key_type -tc_space_key_typeof(char *name) -{ - if (strcmp(name, "NUM") == 0) - return TC_SPACE_KEY_NUM; - else - if (strcmp(name, "NUM64") == 0) - return TC_SPACE_KEY_NUM64; - else - if (strcmp(name, "STR") == 0) - return TC_SPACE_KEY_STRING; - return TC_SPACE_KEY_UNKNOWN; -} - -#if 0 -static int -tc_space_key_init(struct tc_space *s, tarantool_cfg_space *cs) -{ - struct tarantool_cfg_space_index *primary = cs->index[0]; - - /* calculate primary key part count */ - while (primary->key_field[s->pk.count]) { - tarantool_cfg_space_index_key_field *ck = primary->key_field[s->pk.count]; - if (ck->fieldno == -1) - break; - s->pk.count++; - } - - /* allocate key fields */ - size_t size = sizeof(struct tc_space_key_field) * s->pk.count; - s->pk.fields = malloc(size); - if (s->pk.fields == NULL) { - printf("can't allocate key fields\n"); - return -1; - } - memset(s->pk.fields, 0, size); - - /* init key fields */ - int kn = 0; - while (primary->key_field[kn]) { - struct tc_space_key_field *k = &s->pk.fields[kn]; - tarantool_cfg_space_index_key_field *ck = primary->key_field[kn]; - if (ck->fieldno == -1) - break; - k->n = ck->fieldno; - k->type = tc_space_key_typeof(ck->type); - kn++; - } - - return 0; -} - -int tc_space_fillof(struct tc_spaces *s, int n, tarantool_cfg_space *cs) -{ - struct tc_space *space = tc_space_match(s, n); - if (space) { - printf("space %i is already defined\n", n); - return -1; - } - space = tc_space_create(s, n); - if (space == NULL) { - printf("failed to create space %d\n", n); - return -1; - } - if (cs->index[0] == NULL) { - printf("primary index is not defined\n"); - return -1; - } - memset(&space->pk, 0, sizeof(space->pk)); - - int rc = tc_space_key_init(space, cs); - if (rc == -1) - return -1; - return 0; -} - -int tc_space_fill(struct tc_spaces *s, struct tc_options *opts) -{ - int i = 0; - for (; opts->cfg.space[i]; i++) { - tarantool_cfg_space *cs = opts->cfg.space[i]; - if (!CNF_STRUCT_DEFINED(cs) || !cs->enabled) - continue; - int rc = tc_space_fillof(s, i, cs); - if (rc == -1) - return -1; - } - return 0; -} -#endif diff --git a/client/tarancheck/tc_space.h b/client/tarancheck/tc_space.h deleted file mode 100644 index 6ec7ddea4a..0000000000 --- a/client/tarancheck/tc_space.h +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef TC_SPACE_H_INCLUDED -#define TC_SPACE_H_INCLUDED - -enum tc_space_key_type { - TC_SPACE_KEY_UNKNOWN = -1, - TC_SPACE_KEY_NUM = 0, - TC_SPACE_KEY_NUM64, - TC_SPACE_KEY_STRING -}; - -struct tc_space_key_field { - enum tc_space_key_type type; - int n; -}; - -struct tc_space_key { - struct tc_space_key_field *fields; - int count; -}; - -struct tc_space { - uint32_t id; - struct mh_pk_t *hash_log; - struct mh_pk_t *hash_snap; - struct tc_space_key pk; -}; - -struct tc_spaces { - struct mh_u32ptr_t *t; -}; - -int tc_space_init(struct tc_spaces *s); -void tc_space_free(struct tc_spaces *s); - -struct tc_space *tc_space_create(struct tc_spaces *s, uint32_t id); -struct tc_space *tc_space_match(struct tc_spaces *s, uint32_t id); - -#if 0 -int tc_space_fill(struct tc_spaces *s, struct tc_options *opts); -#endif -#endif diff --git a/client/tarancheck/tc_verify.c b/client/tarancheck/tc_verify.c deleted file mode 100644 index cfa8c71011..0000000000 --- a/client/tarancheck/tc_verify.c +++ /dev/null @@ -1,220 +0,0 @@ - -/* - * 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 <stdlib.h> -#include <stdarg.h> -#include <stdint.h> -#include <inttypes.h> -#include <stdio.h> -#include <string.h> -#include <assert.h> - -#include <connector/c/include/tarantool/tnt.h> -#include <connector/c/include/tarantool/tnt_xlog.h> -#include <connector/c/include/tarantool/tnt_snapshot.h> -#include <connector/c/include/tarantool/tnt_dir.h> - -#include <cfg/prscfg.h> -#include <cfg/tarantool_box_cfg.h> - -#include <third_party/crc32.h> - -#include "tc_key.h" -#include "tc_hash.h" -#include "tc_options.h" -#include "tc_config.h" -#include "tc_space.h" -#include "tc_generate.h" -#include "tc_verify.h" -#include "tc_file.h" - -int tc_verify_cmp(struct tc_spaces *s, - uint64_t lsn, - struct tnt_iter_storage *is, - struct tnt_stream_snapshot *ss) -{ - struct tc_space *space = - tc_space_match(s, ss->log.current.row_snap.space); - if (space == NULL) - return -1; - int rc = 0; - struct tc_key *k = tc_generate_key(space, &is->t); - if (k == NULL) { - printf("failed to create key\n"); - rc = -1; - goto done; - } - - /* 1. check in hash, if found then skip */ - const struct tc_key *node = k; - mh_int_t pos = mh_pk_get(space->hash_log, &node, space); - const struct tc_key *v = NULL; - if (pos != mh_end(space->hash_log)) - v = *mh_pk_node(space->hash_log, pos); - if (v) { - rc = 0; - goto done; - } - - /* 2. if key was not found in xlog hash, then try snapshot hash */ - node = k; - pos = mh_pk_get(space->hash_snap, &node, space); - v = NULL; - if (pos != mh_end(space->hash_snap)) - v = *mh_pk_node(space->hash_snap, pos); - if (v) { - /* generate and compare checksum */ - uint32_t crc = crc32c(0, (unsigned char*)is->t.data, is->t.size); - if (crc != v->crc) { - printf("(snapshot %"PRIu64") checksum missmatch\n", lsn); - rc = -1; - } - } else { - /* not found */ - printf("(snapshot %"PRIu64") key missed\n", lsn); - rc = -1; - } -done: - free(k); - return rc; -} - -int tc_verify_process(struct tc_spaces *s, uint64_t lsn, char *snap_dir) -{ - char path[1024]; - snprintf(path, sizeof(path), "%s/%020llu.snap", snap_dir, - (long long unsigned)lsn); - - printf("(snapshot) %s\n", path); - - struct tnt_stream st; - tnt_snapshot(&st); - if (tnt_snapshot_open(&st, path) == -1) { - printf("failed to open snapshot file\n"); - tnt_stream_free(&st); - return -1; - } - - struct tnt_iter i; - tnt_iter_storage(&i, &st); - int errors = 0; - int rc = 0; - while (tnt_next(&i)) { - struct tnt_iter_storage *is = TNT_ISTORAGE(&i); - struct tnt_stream_snapshot *ss = - TNT_SSNAPSHOT_CAST(TNT_IREQUEST_STREAM(&i)); - int result = tc_verify_cmp(s, lsn, is, ss); - if (result == -1) - errors++; - } - if (i.status == TNT_ITER_FAIL) { - printf("snapshot parsing failed: %s\n", tnt_snapshot_strerror(&st)); - rc = -1; - } - if (errors) - rc = -1; - tnt_iter_free(&i); - tnt_stream_free(&st); - return rc; -} - -int tc_verify_match(struct tc_spaces *ss, uint64_t last_xlog_lsn, - uint64_t last_snap_lsn, - char *path) -{ - struct tnt_dir snap_dir; - tnt_dir_init(&snap_dir, TNT_DIR_SNAPSHOT); - - int rc = tnt_dir_scan(&snap_dir, path); - if (rc == -1) { - printf("failed to open snap directory\n"); - tnt_dir_free(&snap_dir); - return -1; - } - int i; - for (i = 0; i < snap_dir.count; i++) { - if (snap_dir.files[i].lsn >= last_snap_lsn && - snap_dir.files[i].lsn <= last_xlog_lsn) - break; - } - if (i == snap_dir.count) { - printf("no suitable snapshot found (lsn >= %"PRIu64" && lsn <= %"PRIu64")\n", - last_snap_lsn, last_xlog_lsn); - tnt_dir_free(&snap_dir); - return -1; - } - - rc = tc_verify_process(ss, snap_dir.files[i].lsn, path); - - tnt_dir_free(&snap_dir); - return rc; -} - -int tc_verify(struct tc_options *opts) -{ - printf(">>> Signature file verification\n"); - - /* 1. create spaces according to a configuration file */ - struct tc_spaces ss; - int rc = tc_space_init(&ss); - if (rc == -1) - return -1; -#if 0 - rc = tc_space_fill(&ss, opts); - if (rc == -1) - goto error; - -#endif - /* 2. load signature file */ - uint64_t last_xlog_lsn = 0; - uint64_t last_snap_lsn = 0; - rc = tc_file_load(&ss, (char*)opts->file, &last_xlog_lsn, - &last_snap_lsn); - if (rc == -1) - goto error; - - printf("(signature) loading %s\n", opts->file); - - printf("configured spaces: %"PRIu32"\n", mh_size(ss.t)); - printf("last xlog lsn: %"PRIu64"\n", last_xlog_lsn); - printf("last snapshot lsn: %"PRIu64"\n", last_snap_lsn); - - /* 3. start verification process */ - rc = tc_verify_match(&ss, last_xlog_lsn, last_snap_lsn, - opts->cfg.snap_dir); - - printf("%s\n", (rc == 0) ? "OK": "FAILED"); - - tc_space_free(&ss); - return rc; -error: - tc_space_free(&ss); - return -1; -} diff --git a/client/tarancheck/tc_verify.h b/client/tarancheck/tc_verify.h deleted file mode 100644 index 03a8c46184..0000000000 --- a/client/tarancheck/tc_verify.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef TC_VERIFY_H_INCLUDED -#define TC_VERIFY_H_INCLUDED - -int tc_verify(struct tc_options *opts); - -#endif diff --git a/client/tarantar/CMakeLists.txt b/client/tarantar/CMakeLists.txt deleted file mode 100644 index d9a3af369a..0000000000 --- a/client/tarantar/CMakeLists.txt +++ /dev/null @@ -1,30 +0,0 @@ -project(tnt_snap) - -set (util_snap "tarantar") -set (util_snap_sources sha1.c main.c config.c space.c options.c indexate.c ref.c cursor.c snapshot.c update.cc compat.c) -set (util_snap_libs tntrpl tntnet tnt) - -list(APPEND util_snap_sources - ${CMAKE_SOURCE_DIR}/third_party/crc32.c - ${CMAKE_SOURCE_DIR}/cfg/tarantool_box_cfg.c - ${CMAKE_SOURCE_DIR}/cfg/prscfg.c - ${CMAKE_SOURCE_DIR}/src/errcode.c - ${CMAKE_SOURCE_DIR}/src/exception.cc - ${CMAKE_SOURCE_DIR}/src/rope.c - ${CMAKE_SOURCE_DIR}/src/pickle.cc - ${CMAKE_SOURCE_DIR}/src/box/tuple_update.cc ) - -set_source_files_properties(${CMAKE_SOURCE_DIR}/cfg/tarantool_box_cfg.c - ${CMAKE_SOURCE_DIR}/cfg/prscfg.c PROPERTIES COMPILE_FLAGS - "-Wno-unused-parameter" - GENERATED True) - -set_source_files_properties(${util_snap_sources} PROPERTIES OBJECT_DEPENDS - ${CMAKE_SOURCE_DIR}/cfg/tarantool_box_cfg.h) - -set_source_files_compile_flags(${util_snap_sources}) -add_executable(${util_snap} ${util_snap_sources}) - -target_link_libraries (${util_snap} ${util_snap_libs} gopt small msgpuck) - -install (TARGETS ${util_snap} DESTINATION bin) diff --git a/client/tarantar/compat.c b/client/tarantar/compat.c deleted file mode 100644 index f2c8c62641..0000000000 --- a/client/tarantar/compat.c +++ /dev/null @@ -1,71 +0,0 @@ - -/* - * 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 <stdlib.h> -#include <stdarg.h> -#include <stdint.h> -#include <stdio.h> -#include <string.h> - -#include <cfg/prscfg.h> -#include <cfg/tarantool_box_cfg.h> -#include <say.h> - -#include "options.h" -#include "config.h" - -void out_warning(ConfettyError v, char *format, ...) { - (void)v; - va_list ap; - va_start(ap, format); - vprintf(format, ap); - printf("\n"); - va_end(ap); -} - -void say_snap(int level, const char *filename, int line, const char *error, - const char *format, ...) { - (void)level; - (void)filename; - (void)line; - (void)error; - (void)format; -} - -sayfunc_t _say = say_snap; - -void assert_fail(const char *assertion, const char *file, unsigned int line, - const char *function) -{ - (void)function; - fflush(NULL); - printf("assert: %s:%d %s\n", file, line, assertion); - exit(1); -} diff --git a/client/tarantar/config.c b/client/tarantar/config.c deleted file mode 100644 index 6923b93a9f..0000000000 --- a/client/tarantar/config.c +++ /dev/null @@ -1,64 +0,0 @@ - -/* - * 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 <stdlib.h> -#include <stdarg.h> -#include <stdint.h> -#include <stdio.h> -#include <string.h> - -#include <cfg/prscfg.h> -#include <cfg/tarantool_box_cfg.h> - -#include "options.h" -#include "config.h" - -int ts_config_load(struct ts_options *opts) -{ - FILE *f = fopen(opts->file_config, "r"); - if (f == NULL) { - printf("failed to open config file: %s\n", opts->file_config); - return -1; - } - int accepted = 0, - skipped = 0, - optional = 0; - int rc = parse_cfg_file_tarantool_cfg(&opts->cfg, f, 0, - &accepted, - &skipped, - &optional); - fclose(f); - if (rc == -1) - return -1; - rc = check_cfg_tarantool_cfg(&opts->cfg); - if (rc == -1) - return -1; - return 0; -} diff --git a/client/tarantar/config.h b/client/tarantar/config.h deleted file mode 100644 index e64b1f568d..0000000000 --- a/client/tarantar/config.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef TS_CONFIG_H_INCLUDED -#define TS_CONFIG_H_INCLUDED - -int ts_config_load(struct ts_options *opts); - -#endif diff --git a/client/tarantar/cursor.c b/client/tarantar/cursor.c deleted file mode 100644 index 8abd26c6f1..0000000000 --- a/client/tarantar/cursor.c +++ /dev/null @@ -1,100 +0,0 @@ - -#include <stdlib.h> -#include <stdarg.h> -#include <stdint.h> -#include <inttypes.h> -#include <stdio.h> -#include <string.h> -#include <assert.h> - -#include <third_party/crc32.h> - -#include <connector/c/include/tarantool/tnt.h> -#include <connector/c/include/tarantool/tnt_xlog.h> -#include <connector/c/include/tarantool/tnt_snapshot.h> -#include <connector/c/include/tarantool/tnt_dir.h> - -#include <cfg/prscfg.h> -#include <cfg/tarantool_box_cfg.h> - -#include <lib/small/region.h> - -#include "key.h" -#include "hash.h" -#include "options.h" -#include "space.h" -#include "sha1.h" -#include "ref.h" -#include "ts.h" -#include "cursor.h" - -extern struct ts tss; - -int -ts_cursor_open(struct ts_cursor *c, struct ts_key *k) -{ - c->k = k; - c->r = ts_reftable_map(&tss.rt, k->file); - - int rc = tnt_log_open(&c->current, c->r->file, - (c->r->is_snap ? TNT_LOG_SNAPSHOT : TNT_LOG_XLOG)); - if (rc == -1) { - printf("failed to open file: %s\n", c->r->file); - return -1; - } - rc = tnt_log_seek(&c->current, k->offset); - if (rc == -1) { - printf("failed to seek for: %s:%"PRIu64"\n", c->r->file, k->offset); - tnt_log_close(&c->current); - return -1; - } - if (tnt_log_next(&c->current) == NULL) { - printf("failed to read: %s:%"PRIu64"\n", c->r->file, k->offset); - tnt_log_close(&c->current); - return -1; - } - return 0; -} - -struct tnt_tuple* -ts_cursor_tuple(struct ts_cursor *c) -{ - struct tnt_tuple *t = NULL; - - if (c->r->is_snap) { - t = &c->current.current_value.t; - } else { - struct tnt_request *rp = &c->current.current_value.r; - switch (rp->h.type) { - case TNT_OP_INSERT: - t = &rp->r.insert.t; - break; - case TNT_OP_DELETE_1_3: - t = &rp->r.del_1_3.t; - return t; - case TNT_OP_DELETE: - t = &rp->r.del.t; - return t; - case TNT_OP_UPDATE: - assert(0); - break; - default: - assert(0); - break; - } - } - return t; -} - -void -ts_cursor_close(struct ts_cursor *c) -{ - if (c->r == NULL) - return; - if (c->r->is_snap) { - tnt_tuple_free(&c->current.current_value.t); - } else { - tnt_request_free(&c->current.current_value.r); - } - tnt_log_close(&c->current); -} diff --git a/client/tarantar/cursor.h b/client/tarantar/cursor.h deleted file mode 100644 index bb6f3d229c..0000000000 --- a/client/tarantar/cursor.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef TS_CURSOR_H_INCLUDED -#define TS_CURSOR_H_INCLUDED - -struct ts_cursor { - struct ts_ref *r; - struct ts_key *k; - struct tnt_log current; -}; - -int -ts_cursor_open(struct ts_cursor *c, struct ts_key *k); - -struct tnt_tuple* -ts_cursor_tuple(struct ts_cursor *c); - -void -ts_cursor_close(struct ts_cursor *c); - -#endif diff --git a/client/tarantar/hash.h b/client/tarantar/hash.h deleted file mode 100644 index b4ca707563..0000000000 --- a/client/tarantar/hash.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef TC_HASH_H_INCLUDED -#define TC_HASH_H_INCLUDED - -#if !MH_SOURCE -#define MH_UNDEF -#endif - -#include <stdint.h> - -#define mh_name _u32ptr -struct mh_u32ptr_node_t { - uint32_t key; - void *val; -}; - -#define mh_node_t struct mh_u32ptr_node_t -#define mh_arg_t void * -#define mh_hash(a, arg) (a->key) -#define mh_eq(a, b, arg) ((a->key) == (b->key)) -#include <mhash.h> - - -struct ts_space; - -uint32_t -search_hash(const struct ts_key *k, struct ts_space *s); - -int -search_equal(const struct ts_key *a, const struct ts_key *b, - struct ts_space *s); - -#define mh_name _pk -#define mh_node_t struct ts_key * -#define mh_arg_t struct ts_space * -#define mh_hash(a, arg) search_hash(*(a), arg) -#define mh_eq(a, b, arg) search_equal(*(a), *(b), arg) -#include <mhash.h> - -#endif diff --git a/client/tarantar/indexate.c b/client/tarantar/indexate.c deleted file mode 100644 index e53ae6f51a..0000000000 --- a/client/tarantar/indexate.c +++ /dev/null @@ -1,435 +0,0 @@ - -#include <stdlib.h> -#include <stdarg.h> -#include <stdint.h> -#include <inttypes.h> -#include <stdio.h> -#include <string.h> -#include <assert.h> - -#include <connector/c/include/tarantool/tnt.h> -#include <connector/c/include/tarantool/tnt_xlog.h> -#include <connector/c/include/tarantool/tnt_snapshot.h> -#include <connector/c/include/tarantool/tnt_dir.h> - -#include <cfg/prscfg.h> -#include <cfg/tarantool_box_cfg.h> - -#include <lib/small/region.h> - -#include "key.h" -#include "hash.h" -#include "options.h" -#include "space.h" -#include "sha1.h" -#include "ref.h" -#include "ts.h" -#include "indexate.h" -#include "update.h" -#include "cursor.h" - -extern struct ts tss; - -inline uint32_t -search_hash(const struct ts_key *k, struct ts_space *s) -{ - register uint32_t *v = (uint32_t*)k->key; - switch (s->key_div) { - case 5: - return v[0] ^ v[1] ^ v[2] ^ v[3] ^ v[4]; - case 4: - return v[0] ^ v[1] ^ v[2] ^ v[3]; - case 3: - return v[0] ^ v[1] ^ v[2]; - case 2: - return v[0] ^ v[1]; - case 1: - return v[0]; - } - return 0; -} - -inline int -search_equal(const struct ts_key *a, - const struct ts_key *b, struct ts_space *s) -{ - return memcmp(a->key, b->key, s->key_size) == 0; -} - -static int -snapshot_process_row(struct ts_spaces *s, int fileid, uint64_t offset, - struct tnt_iter_storage *is, - struct tnt_stream_snapshot *ss) -{ - struct ts_space *space = - ts_space_match(s, ss->log.current.row_snap.space); - struct ts_key *k = ts_space_keyalloc(space, &is->t, fileid, offset, 0); - if (k == NULL) { - printf("failed to create key\n"); - return -1; - } - - const struct ts_key *node = k; - - /* make sure that there is no collisions possible */ - assert(mh_pk_get(space->index, &node, space) == mh_end(space->index)); - - mh_int_t pos = mh_pk_put(space->index, &node, NULL, space); - if (pos == mh_end(space->index)) { - ts_space_keyfree(space, k); - return -1; - } - return 0; -} - -static int -snapshot_process(void) -{ - char path[1024]; - snprintf(path, sizeof(path), "%s/%020llu.snap", tss.snap_dir, - (unsigned long long) tss.last_snap_lsn); - - int fileid = ts_reftable_add(&tss.rt, path, 1); - if (fileid == -1) - return -1; - - struct tnt_stream st; - tnt_snapshot(&st); - if (tnt_snapshot_open(&st, path) == -1) { - printf("failed to open snapshot file\n"); - tnt_stream_free(&st); - return -1; - } - struct tnt_iter i; - tnt_iter_storage(&i, &st); - int rc = 0; - int count = 0; - while (tnt_next(&i)) { - struct tnt_iter_storage *is = TNT_ISTORAGE(&i); - struct tnt_stream_snapshot *ss = - TNT_SSNAPSHOT_CAST(TNT_IREQUEST_STREAM(&i)); - rc = snapshot_process_row(&tss.s, fileid, ss->log.current_offset, is, ss); - if (rc == -1) - goto done; - if (count % 10000 == 0) { - printf("(snapshot) %020llu.snap %.3fM processed\r", - (unsigned long long) tss.last_snap_lsn, - (float)count / 1000000); - fflush(stdout); - } - count++; - } - - printf("\n"); - if (i.status == TNT_ITER_FAIL) { - printf("snapshot parsing failed: %s\n", tnt_snapshot_strerror(&st)); - rc = -1; - } -done: - tnt_iter_free(&i); - tnt_stream_free(&st); - return rc; -} - -static inline int -snapdir_process(void) -{ - /* open snapshot directory */ - struct tnt_dir snap_dir; - tnt_dir_init(&snap_dir, TNT_DIR_SNAPSHOT); - - int rc = tnt_dir_scan(&snap_dir, (char *)tss.snap_dir); - if (rc == -1) { - printf("failed to open snapshot directory\n"); - goto error; - } - - /* find newest snapshot lsn */ - rc = tnt_dir_match_gt(&snap_dir, &tss.last_snap_lsn); - if (rc == -1) { - printf("failed to match greatest snapshot lsn\n"); - goto error; - } - printf("last snapshot lsn: %"PRIu64"\n", tss.last_snap_lsn); - - /* process snapshot */ - rc = snapshot_process(); - if (rc == -1) - goto error; - return 0; -error: - tnt_dir_free(&snap_dir); - return -1; -} - -static int -xlog_process_row(struct ts_spaces *s, int fileid, uint64_t offset, - struct tnt_request *r) -{ - /* validate operation */ - uint32_t ns = 0; - struct tnt_tuple *t = NULL; - - switch (r->h.type) { - case TNT_OP_INSERT: - ns = r->r.insert.h.ns; - t = &r->r.insert.t; - break; - case TNT_OP_DELETE: - ns = r->r.del.h.ns; - t = &r->r.del.t; - break; - case TNT_OP_DELETE_1_3: - ns = r->r.del_1_3.h.ns; - t = &r->r.del_1_3.t; - break; - case TNT_OP_UPDATE: - ns = r->r.update.h.ns; - t = &r->r.update.t; - break; - default: - assert(0); - break; - } - - /* match space */ - struct ts_space *space = ts_space_match(s, ns); - if (space == NULL) { - printf("space %d is not defined\n", ns); - return -1; - } - - /* create key */ - struct ts_key *k = ts_space_keyalloc(space, t, fileid, offset, 0); - if (k == NULL) { - printf("failed to create key\n"); - return -1; - } - - /* place to the index */ - const struct ts_key *node = k; - mh_int_t pos; - - switch (r->h.type) { - case TNT_OP_INSERT: - pos = mh_pk_put(space->index, &node, NULL, space); - if (pos == mh_end(space->index)) { - ts_space_keyfree(space, k); - return -1; - } - ts_oomcheck(); - break; - case TNT_OP_DELETE_1_3: - case TNT_OP_DELETE: { - pos = mh_pk_get(space->index, &node, space); - assert(pos != mh_end(space->index)); - struct ts_key *key = *mh_pk_node(space->index, pos); - mh_pk_del(space->index, pos, space); - ts_space_keyfree(space, key); - ts_space_keyfree(space, k); - break; - } - case TNT_OP_UPDATE: { - /* read old tuple, check index first - it may contain tuple from a - * previous update */ - pos = mh_pk_get(space->index, &node, space); - assert(pos != mh_end(space->index)); - struct ts_key *key = *mh_pk_node(space->index, pos); - struct tnt_tuple *old = NULL; - struct ts_cursor cursor; - memset(&cursor, 0, sizeof(cursor)); - - if (key->flags & TS_KEY_WITH_DATA) { - uint32_t size = *(uint32_t*)(key->key + space->key_size); - - old = tnt_tuple_set(NULL, key->key + space->key_size + sizeof(uint32_t), size); - if (old == NULL) { - ts_space_keyfree(space, k); - return -1; - } - } else { - /* load from file */ - if (ts_cursor_open(&cursor, key)) { - ts_space_keyfree(space, k); - return -1; - } - old = ts_cursor_tuple(&cursor); - } - - /* remove key tuple from index, due to possibility of the key - * being changed by update */ - mh_pk_del(space->index, pos, space); - ts_space_keyfree(space, k); - ts_space_keyfree(space, key); - - /* free old key */ - struct tnt_tuple *n = ts_update(r, old); - if (n == NULL) { - return -1; - } - - /* free old tuple */ - tnt_tuple_free(old); - - /* close file */ - ts_cursor_close(&cursor); - - /* create new key with new tuple */ - k = ts_space_keyalloc(space, n, fileid, offset, 1); - if (k == NULL) { - printf("failed to create key\n"); - tnt_tuple_free(n); - return -1; - } - tnt_tuple_free(n); - node = k; - pos = mh_pk_put(space->index, &node, NULL, space); - if (pos == mh_end(space->index)) { - ts_space_keyfree(space, k); - return -1; - } - break; - } - default: - break; - } - - return 0; -} - -static int -xlog_process(struct ts_spaces *s, char *wal_dir, uint64_t file_lsn, - uint64_t start, uint64_t *last) -{ - char path[1024]; - snprintf(path, sizeof(path), "%s/%020llu.xlog", wal_dir, - (unsigned long long) file_lsn); - - int fileid = ts_reftable_add(&tss.rt, path, 0); - if (fileid == -1) - return -1; - - struct tnt_stream st; - tnt_xlog(&st); - if (tnt_xlog_open(&st, path) == -1) { - printf("failed to open xlog file\n"); - tnt_stream_free(&st); - return -1; - } - - struct tnt_iter i; - tnt_iter_request(&i, &st); - int count = 0; - int rc = 0; - while (tnt_next(&i)) { - struct tnt_request *r = TNT_IREQUEST_PTR(&i); - struct tnt_stream_xlog *xs = - TNT_SXLOG_CAST(TNT_IREQUEST_STREAM(&i)); - if (xs->log.current.hdr.lsn > *last) - *last = xs->log.current.hdr.lsn; - if (xs->log.current.hdr.lsn <= start) - continue; - if (tss.opts.to_lsn_set && xs->log.current.hdr.lsn > tss.opts.to_lsn) { - rc = 1; - goto done; - } - rc = xlog_process_row(s, fileid, xs->log.current_offset, r); - if (rc == -1) - goto done; - if (count % 10000 == 0) { - printf("(xlog) %020llu.xlog %.3fM processed\r", - (unsigned long long) file_lsn, - (float)count / 1000000); - fflush(stdout); - } - count++; - } - - printf("\n"); - if (i.status == TNT_ITER_FAIL) { - printf("xlog parsing failed: %s\n", tnt_xlog_strerror(&st)); - rc = -1; - } -done: - tnt_iter_free(&i); - tnt_stream_free(&st); - return rc; -} - -static int -waldir_processof(struct ts_spaces *s, struct tnt_dir *wal_dir, int i) -{ - int rc = 0; - if (i < wal_dir->count) { - rc = xlog_process(s, wal_dir->path, wal_dir->files[i].lsn, - tss.last_snap_lsn, &tss.last_xlog_lsn); - if (rc == -1 || rc == -1) - return rc; - } - for (i++; i < wal_dir->count; i++) { - rc = xlog_process(s, wal_dir->path, wal_dir->files[i].lsn, - 0, &tss.last_xlog_lsn); - if (rc == -1) - return -1; - } - return rc; -} - -static int -waldir_process(void) -{ - /* get latest existing lsn after snapshot */ - struct tnt_dir wal_dir; - tnt_dir_init(&wal_dir, TNT_DIR_XLOG); - - int rc = tnt_dir_scan(&wal_dir, (char *)tss.wal_dir); - if (rc == -1) { - printf("failed to open wal directory\n"); - tnt_dir_free(&wal_dir); - return -1; - } - - /* match xlog file containling latest snapshot lsn record */ - if (tss.last_snap_lsn == 1) { - rc = waldir_processof(&tss.s, &wal_dir, 0); - if (rc == -1) { - tnt_dir_free(&wal_dir); - return -1; - } - goto done; - } - uint64_t xlog_inc = 0; - rc = tnt_dir_match_inc(&wal_dir, tss.last_snap_lsn, &xlog_inc); - if (rc == -1) { - printf("failed to match xlog with snapshot lsn\n"); - tnt_dir_free(&wal_dir); - return -1; - } - - /* index all xlog records from xlog file (a:last_snap_lsn) to - * latest existing xlog lsn */ - int i = 0; - while (i < wal_dir.count && wal_dir.files[i].lsn != xlog_inc) - i++; - - rc = waldir_processof(&tss.s, &wal_dir, i); - if (rc == -1) { - tnt_dir_free(&wal_dir); - return -1; - } -done: - tnt_dir_free(&wal_dir); - return 0; -} - -int -ts_indexate(void) -{ - int rc = snapdir_process(); - if (rc == -1) - return -1; - rc = waldir_process(); - if (rc == -1) - return -1; - return 0; -} diff --git a/client/tarantar/indexate.h b/client/tarantar/indexate.h deleted file mode 100644 index 46668100c1..0000000000 --- a/client/tarantar/indexate.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef TS_INDEXATE_H_INCLUDED -#define TS_INDEXATE_H_INCLUDED - -int ts_indexate(void); - -#endif diff --git a/client/tarantar/key.h b/client/tarantar/key.h deleted file mode 100644 index 7660e3c9af..0000000000 --- a/client/tarantar/key.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef TS_KEY_H_INCLUDED -#define TS_KEY_H_INCLUDED - -#define TS_KEY_WITH_DATA 1 - -struct ts_key { - uint16_t file; - uint64_t offset; - uint8_t flags; - unsigned char key[]; -} __attribute__((packed)); - -#endif diff --git a/client/tarantar/main.c b/client/tarantar/main.c deleted file mode 100644 index 01f0d51855..0000000000 --- a/client/tarantar/main.c +++ /dev/null @@ -1,216 +0,0 @@ - -/* - * 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 <stdlib.h> -#include <stdarg.h> -#include <stdint.h> -#include <stdio.h> -#include <string.h> -#include <time.h> -#include <unistd.h> -#include <errno.h> -#include <limits.h> -#ifdef __linux__ -# include <malloc.h> -#endif - -#include <connector/c/include/tarantool/tnt.h> - -#include <cfg/prscfg.h> -#include <cfg/tarantool_box_cfg.h> - -#include <lib/small/region.h> - -#define MH_SOURCE 1 -#include "key.h" -#include "hash.h" -#include "options.h" -#include "config.h" -#include "space.h" -#include "ref.h" -#include "ts.h" -#include "indexate.h" -#include "snapshot.h" - -struct ts tss; - -static void -ts_init(void) -{ - ts_options_init(&tss.opts); - memset(&tss.s, 0, sizeof(tss.s)); - memset(&tss.ra, 0, sizeof(tss.ra)); - memset(&tss.sc, 0, sizeof(tss.sc)); -} - -static int -ts_prepare(void) -{ - int rc = ts_reftable_init(&tss.rt); - if (rc == -1) - return -1; - tss.last_snap_lsn = 0; - tss.last_xlog_lsn = 0; - slab_cache_create(&tss.sc); - region_create(&tss.ra, &tss.sc); - return 0; -} - -static void -ts_free(void) -{ - ts_reftable_free(&tss.rt); - region_free(&tss.ra); - slab_cache_destroy(&tss.sc); -} - -static void -ts_shutdown(void) -{ - ts_space_free(&tss.s); - ts_options_free(&tss.opts); - ts_free(); -} - -void -ts_oomcheck(void) -{ -#ifdef __linux__ - struct mallinfo mi = mallinfo(); - if (tss.opts.limit > 0 && mi.uordblks > tss.opts.limit) { - printf("\nmemory limit reached (%"PRIu64")\n", tss.opts.limit); - exit(2); - } - return; -#else - if (tss.opts.limit > 0 && tss.alloc > tss.opts.limit) { - printf("\nmemory limit reached (%"PRIu64")\n", tss.opts.limit); - exit(2); - } -#endif -} - -int main(int argc, char *argv[]) -{ - ts_init(); - /* parse arguments */ - switch (ts_options_process(&tss.opts, argc, argv)) { - case TS_MODE_USAGE: - ts_options_free(&tss.opts); - return ts_options_usage(); - case TS_MODE_VERSION: - ts_options_free(&tss.opts); - return ts_options_version(); - case TS_MODE_CREATE: - break; - } - - /* load configuration file */ - int rc = ts_config_load(&tss.opts); - if (rc == -1) { - ts_options_free(&tss.opts); - return 1; - } - - char workdir[PATH_MAX]; - char snapdir[PATH_MAX], waldir[PATH_MAX]; - - tss.snap_dir = snapdir; - tss.wal_dir = waldir; - - if (tss.opts.cfg.work_dir != NULL) - snprintf(workdir, sizeof(workdir), "%s", tss.opts.cfg.work_dir); - else - getcwd(workdir, PATH_MAX); - - if (tss.opts.cfg.snap_dir != NULL) { - if (tss.opts.cfg.snap_dir[0] == '/') - tss.snap_dir = tss.opts.cfg.snap_dir; - else { - snprintf(snapdir, sizeof(snapdir), "%s/%s", workdir, - tss.opts.cfg.snap_dir); - } - } else { - snprintf(snapdir, sizeof(snapdir), "%s", workdir); - } - if (tss.opts.cfg.wal_dir != NULL) { - if (tss.opts.cfg.wal_dir[0] == '/') - tss.wal_dir = tss.opts.cfg.wal_dir; - else - snprintf(waldir, sizeof(waldir), "%s/%s", workdir, - tss.opts.cfg.wal_dir); - } else { - snprintf(waldir, sizeof(waldir), "%s", workdir); - } - - /* create spaces */ - rc = ts_space_init(&tss.s); - if (rc == -1) { - ts_space_free(&tss.s); - ts_options_free(&tss.opts); - return 1; - } -#if 0 - rc = ts_space_fill(&tss.s, &tss.opts); - if (rc == -1) { - ts_space_free(&tss.s); - ts_options_free(&tss.opts); - return 1; - } -#endif - - printf("snap_dir: %s\n", tss.snap_dir); - printf("wal_dir: %s\n", tss.wal_dir); - printf("spaces: %d\n", mh_size(tss.s.t)); - printf("interval: %d\n", tss.opts.interval); - printf("memory_limit: %dM\n", (int)(tss.opts.limit / 1024 / 1024)); - - do { - time_t tm = time(NULL); - printf("\nSTART SNAPSHOTTING %s\n", ctime(&tm)); - rc = ts_prepare(); - if (rc == -1) - goto done; - /* indexate snapshot and xlog data */ - rc = ts_indexate(); - if (rc == -1) - goto done; - /* write snapshot */ - rc = ts_snapshot_create(); - if (rc == -1) - goto done; - ts_free(); - ts_space_recycle(&tss.s); - sleep(tss.opts.interval); - } while (tss.opts.interval > 0); -done: - ts_shutdown(); - return (rc == -1 ? 1 : 0); -} diff --git a/client/tarantar/options.c b/client/tarantar/options.c deleted file mode 100644 index c27488e97f..0000000000 --- a/client/tarantar/options.c +++ /dev/null @@ -1,126 +0,0 @@ - -/* - * 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 <stdlib.h> -#include <stdarg.h> -#include <stdint.h> -#include <stdio.h> -#include <string.h> - -#include <third_party/gopt/gopt.h> - -#include <cfg/prscfg.h> -#include <cfg/tarantool_box_cfg.h> - -#include "options.h" - -static const void *opts_def = gopt_start( - gopt_option('c', 0, gopt_shorts('c'), - gopt_longs("create"), NULL, "create snapshot file"), - gopt_option('i', GOPT_ARG, gopt_shorts('i'), - gopt_longs("interval"), " <sec>", "periodically create snapshot"), - gopt_option('n', GOPT_ARG, gopt_shorts('n'), - gopt_longs("lsn"), " <u64>", "snapshot lsn (latest by default)"), - gopt_option('l', GOPT_ARG, gopt_shorts('l'), - gopt_longs("limit"), " <limit>", "memory limit (bytes)"), - gopt_option('?', 0, gopt_shorts('?'), gopt_longs("help"), - NULL, "display this help and exit"), - gopt_option('V', 0, gopt_shorts('V'), gopt_longs("version"), - NULL, "display version information and exit") -); - -void ts_options_init(struct ts_options *opts) { - memset(opts, 0, sizeof(struct ts_options)); - init_tarantool_cfg(&opts->cfg); -} - -void ts_options_free(struct ts_options *opts) { - destroy_tarantool_cfg(&opts->cfg); -} - -int ts_options_usage(void) -{ - printf("Tarantool xlog compression utility.\n\n"); - printf("Usage: tarantar <options> <tarantool_config>\n"); - gopt_help(opts_def); - return 1; -} - -int ts_options_version(void) -{ - printf("tarantar client, version %s.%s\n", - TT_VERSION_MAJOR, - TT_VERSION_MINOR); - return 1; -} - - -enum ts_options_mode -ts_options_process(struct ts_options *opts, int argc, char **argv) -{ - void *opt = gopt_sort(&argc, (const char**)argv, opts_def); - /* usage */ - if (gopt(opt, '?')) { - opts->mode = TS_MODE_USAGE; - goto done; - } - /* version */ - if (gopt(opt, 'V')) { - opts->mode = TS_MODE_VERSION; - goto done; - } - - /* lsn */ - const char *arg = NULL; - if (gopt_arg(opt, 'n', &arg)) { - opts->to_lsn = atoll(arg); - opts->to_lsn_set = 1; - } - - /* limit */ - if (gopt_arg(opt, 'l', &arg)) - opts->limit = strtoll(arg, NULL, 10); - - /* sleep */ - if (gopt_arg(opt, 'i', &arg)) - opts->interval = atoi(arg); - - /* generate or verify */ - if (gopt(opt, 'c')) { - opts->mode = TS_MODE_CREATE; - } else { - opts->mode = TS_MODE_USAGE; - goto done; - } - opts->file_config = argv[1]; -done: - gopt_free(opt); - return opts->mode; -} diff --git a/client/tarantar/options.h b/client/tarantar/options.h deleted file mode 100644 index 045267409a..0000000000 --- a/client/tarantar/options.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef TS_OPTIONS_H_INCLUDED -#define TS_OPTIONS_H_INCLUDED - -enum ts_options_mode { - TS_MODE_USAGE, - TS_MODE_VERSION, - TS_MODE_CREATE -}; - -#define TT_VERSION_MINOR "1" -#define TT_VERSION_MAJOR "0" - -struct ts_options { - uint64_t limit; - enum ts_options_mode mode; - int to_lsn_set; - int interval; - uint64_t to_lsn; - const char *file_config; - struct tarantool_cfg cfg; -}; - -void ts_options_init(struct ts_options *opts); -void ts_options_free(struct ts_options *opts); - -enum ts_options_mode -ts_options_process(struct ts_options *opts, int argc, char **argv); - -int ts_options_usage(void); -int ts_options_version(void); - -#endif diff --git a/client/tarantar/ref.c b/client/tarantar/ref.c deleted file mode 100644 index a3f5e49c49..0000000000 --- a/client/tarantar/ref.c +++ /dev/null @@ -1,51 +0,0 @@ - -#include <stdlib.h> -#include <stdarg.h> -#include <stdint.h> -#include <stdio.h> -#include <string.h> -#include <assert.h> - -#include "ref.h" - -int ts_reftable_init(struct ts_reftable *t) -{ - t->count = 0; - t->top = 16; - t->r = malloc(sizeof(struct ts_ref) * t->top); - if (t == NULL) - return -1; - return 0; -} - -void ts_reftable_free(struct ts_reftable *t) -{ - if (t->r) { - free(t->r); - t->r = NULL; - } -} - -int ts_reftable_add(struct ts_reftable *t, char *file, int is_snap) -{ - if (t->count == t->top) { - t->top *= 2; - void *p = realloc(t->r, sizeof(struct ts_ref) * t->top); - if (p == NULL) - return -1; - t->r = p; - } - int id = t->count; - t->r[id].file = strdup(file); - t->r[id].is_snap = is_snap; - if (t->r[id].file == NULL) - return -1; - t->count++; - return id; -} - -struct ts_ref *ts_reftable_map(struct ts_reftable *t, int id) -{ - assert(id < t->count); - return &t->r[id]; -} diff --git a/client/tarantar/ref.h b/client/tarantar/ref.h deleted file mode 100644 index 9120c69b1e..0000000000 --- a/client/tarantar/ref.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef TS_REF_H_INCLUDED -#define TS_REF_H_INCLUDED - -struct ts_ref { - char *file; - int is_snap; -}; - -struct ts_reftable { - struct ts_ref *r; - int count; - int top; -}; - -int ts_reftable_init(struct ts_reftable *t); -void ts_reftable_free(struct ts_reftable *t); -int ts_reftable_add(struct ts_reftable *t, char *file, int is_snap); -struct ts_ref *ts_reftable_map(struct ts_reftable *t, int id); - -#endif diff --git a/client/tarantar/snapshot.c b/client/tarantar/snapshot.c deleted file mode 100644 index b85e77d61e..0000000000 --- a/client/tarantar/snapshot.c +++ /dev/null @@ -1,258 +0,0 @@ - -#include <stdlib.h> -#include <stdarg.h> -#include <stdint.h> -#include <inttypes.h> -#include <stdio.h> -#include <string.h> -#include <assert.h> -#include <unistd.h> - -#include <third_party/crc32.h> - -#include <connector/c/include/tarantool/tnt.h> -#include <connector/c/include/tarantool/tnt_xlog.h> -#include <connector/c/include/tarantool/tnt_snapshot.h> -#include <connector/c/include/tarantool/tnt_dir.h> - -#include <cfg/prscfg.h> -#include <cfg/tarantool_box_cfg.h> - -#include <lib/small/region.h> - -#include "key.h" -#include "hash.h" -#include "options.h" -#include "space.h" -#include "sha1.h" -#include "ref.h" -#include "ts.h" -#include "indexate.h" -#include "snapshot.h" - -extern struct ts tss; - -static int -ts_snapshot_write(FILE *snapshot, uint32_t space, uint64_t lsn, struct tnt_tuple *t) -{ - /* write snapshot row */ - if (fwrite(&tnt_log_marker_v11, sizeof(tnt_log_marker_v11), 1, snapshot) != 1) { - printf("failed to write row\n"); - return -1; - } - - struct { - struct tnt_log_header_v11 h; - struct tnt_log_row_snap_v11 row; - } h = { - .h = { - .crc32_hdr = 0, - .lsn = lsn, - .tm = 0.0, - .len = sizeof(struct tnt_log_row_snap_v11) + t->size - sizeof(uint32_t), - .crc32_data = 0 - }, - .row = { - .tag = 65535, /* snapshot */ - .cookie = 0, - .space = space, - .tuple_size = t->cardinality, - .data_size = t->size - sizeof(uint32_t) - } - }; - - /* calculate checksum */ - h.h.crc32_data = crc32c(0, (unsigned char*)&h.row, sizeof(h.row)); - h.h.crc32_data = crc32c(h.h.crc32_data, - (unsigned char*)t->data + sizeof(uint32_t), - t->size - sizeof(uint32_t)); - h.h.crc32_hdr = crc32c(0, (unsigned char*)&h.h, sizeof(h.h)); - - if (fwrite(&h, sizeof(h), 1, snapshot) != 1) { - printf("failed to write row\n"); - return -1; - } - if (fwrite(t->data + sizeof(uint32_t), - t->size - sizeof(uint32_t), 1, snapshot) != 1) { - printf("failed to write row\n"); - return -1; - } - - return 0; -} - -static int -ts_snapshot_xfer(FILE *snapshot, struct tnt_log *current, - struct ts_ref *r, - struct ts_key *k, uint32_t space, uint64_t lsn) -{ - int rc = tnt_log_seek(current, k->offset); - if (rc == -1) { - printf("failed to seek for: %s:%"PRIu64"\n", r->file, k->offset); - return -1; - } - if (tnt_log_next(current) == NULL) { - printf("failed to read: %s:%"PRIu64"\n", r->file, k->offset); - return -1; - } - - struct tnt_tuple *t = NULL; - - if (r->is_snap) { - t = ¤t->current_value.t; - } else { - struct tnt_request *rp = ¤t->current_value.r; - switch (rp->h.type) { - case TNT_OP_INSERT: - t = &rp->r.insert.t; - break; - case TNT_OP_DELETE_1_3: - case TNT_OP_DELETE: - /* skip */ - //t = &rp->r.del.t; - return 0; - case TNT_OP_UPDATE: - assert(0); - break; - default: - assert(0); - break; - } - } - - /* write snapshot row */ - if (ts_snapshot_write(snapshot, space, lsn, t) != 0) - return -1; - - if (r->is_snap) { - tnt_tuple_free(t); - } else { - tnt_request_free(¤t->current_value.r); - } - return 0; -} - -int ts_snapshot_create(void) -{ - /* TODO: - * - * index can be sorted by file:offset to reduce io overhead, but - * will have unsorted index on disk. */ - - unsigned long long snap_lsn = tss.last_xlog_lsn; - - if (snap_lsn == 0 || tss.last_snap_lsn == snap_lsn) { - printf("snapshot exists, skip.\n"); - return 0; - } - - char path[1024]; - snprintf(path, sizeof(path), "%s/%020llu.snap.inprocess", tss.snap_dir, - (unsigned long long) snap_lsn); - - FILE *snapshot = fopen(path, "a"); - if (snapshot == NULL) { - printf("failed to create snapshot: %s\n", path); - return -1; - } - - fputs(TNT_LOG_MAGIC_SNAP, snapshot); - fputs(TNT_LOG_VERSION, snapshot); - fputs("\n", snapshot); - - char *current_file = NULL; - struct tnt_log current; - memset(¤t, 0, sizeof(current)); - - int count = 0; - int rc; - mh_int_t i; - mh_foreach(tss.s.t, i) { - struct ts_space *space = mh_u32ptr_node(tss.s.t, i)->val; - - mh_int_t pos = 0; - while (pos != mh_end(space->index)) { - if (mh_exist((space->index), pos)) { - struct ts_key *k = *mh_pk_node(space->index, pos); - struct ts_ref *r = ts_reftable_map(&tss.rt, k->file); - - if (count % 10000 == 0) { - printf("( >> ) %020llu.snap %.3fM processed\r", - (unsigned long long) snap_lsn, - (float)count / 1000000); - fflush(stdout); - } - count++; - - /* first, check if key has a data */ - if (k->flags & TS_KEY_WITH_DATA) { - uint32_t size = *(uint32_t*)(k->key + space->key_size); - - struct tnt_tuple *t = - tnt_tuple_set(NULL, k->key + space->key_size + sizeof(uint32_t), size); - if (t == NULL) { - printf("failed to allocate tuple\n"); - goto error; - } - - rc = ts_snapshot_write(snapshot, space->id, snap_lsn, t); - if (rc == -1) - goto error; - pos++; - continue; - } - - /* otherwise, load from snapshot or xlog */ - if (current_file != r->file) { - tnt_log_close(¤t); - rc = tnt_log_open(¤t, r->file, - (r->is_snap ? TNT_LOG_SNAPSHOT : TNT_LOG_XLOG)); - if (rc == -1) { - printf("failed to open file: %s\n", r->file); - goto error; - } - current_file = r->file; - } - - /* transfer from file to snapshot */ - rc = ts_snapshot_xfer(snapshot, ¤t, r, k, space->id, snap_lsn); - if (rc == -1) - goto error; - - } - pos++; - } - } - - /* write eof */ - if (fwrite(&tnt_log_marker_eof_v11, - sizeof(tnt_log_marker_eof_v11), 1, snapshot) != 1) { - printf("failed to write row\n"); - goto error; - } - if (fflush(snapshot) != 0) { - printf("flush failed\n"); - goto error; - } - if (fsync(fileno(snapshot)) != 0) { - printf("sync failed\n"); - goto error; - } - if (fclose(snapshot) != 0) { - printf("failed to write row\n"); - } - - char newpath[1024]; - strncpy(newpath, path, sizeof(newpath)); - char *ext = strrchr(newpath, '.'); - *ext = 0; - rename(path, newpath); - - tnt_log_close(¤t); - printf("\n"); - return 0; -error: - tnt_log_close(¤t); - fclose(snapshot); - return -1; -} diff --git a/client/tarantar/snapshot.h b/client/tarantar/snapshot.h deleted file mode 100644 index 4f5ad74cfd..0000000000 --- a/client/tarantar/snapshot.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef TS_SNAPSHOT_H_INCLUDED -#define TS_SNAPSHOT_H_INCLUDED - -int ts_snapshot_create(void); - -#endif diff --git a/client/tarantar/space.c b/client/tarantar/space.c deleted file mode 100644 index e58d5f42fa..0000000000 --- a/client/tarantar/space.c +++ /dev/null @@ -1,370 +0,0 @@ - -/* - * 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 <stdlib.h> -#include <stdarg.h> -#include <stdint.h> -#include <stdio.h> -#include <string.h> - -#include <connector/c/include/tarantool/tnt.h> - -#include <cfg/prscfg.h> -#include <cfg/tarantool_box_cfg.h> - -#include <lib/small/region.h> - -#include "key.h" -#include "hash.h" -#include "options.h" -#include "config.h" -#include "space.h" -#include "ref.h" -#include "ts.h" -#include "sha1.h" -#include "indexate.h" -#include "snapshot.h" - -extern struct ts tss; - -int ts_space_init(struct ts_spaces *s) { - s->t = mh_u32ptr_new(); - if (s->t == NULL) - return -1; - return 0; -} - -void ts_space_recycle(struct ts_spaces *s) -{ - mh_int_t i; - mh_foreach(s->t, i) { - struct ts_space *space = mh_u32ptr_node(s->t, i)->val; - mh_int_t pos = 0; - while (pos != mh_end(space->index)) { - if (mh_exist((space->index), pos)) { - struct ts_key *k = - *mh_pk_node(space->index, pos); - free(k); - } - pos++; - } - mh_pk_delete(space->index); - space->index = mh_pk_new(); - } -} - -void ts_space_free(struct ts_spaces *s) -{ - mh_int_t i; - mh_foreach(s->t, i) { - struct ts_space *space = mh_u32ptr_node(s->t, i)->val; - mh_u32ptr_del(s->t, i, NULL); - - mh_int_t pos = 0; - while (pos != mh_end(space->index)) { - if (mh_exist((space->index), pos)) { - struct ts_key *k = - *mh_pk_node(space->index, pos); - free(k); - } - pos++; - } - - mh_pk_delete(space->index); - free(space->pk.fields); - free(space); - } - mh_u32ptr_delete(s->t); -} - -struct ts_space *ts_space_create(struct ts_spaces *s, uint32_t id) { - struct ts_space *space = malloc(sizeof(struct ts_space)); - if (space == NULL) - return NULL; - memset(space, 0, sizeof(struct ts_space)); - space->id = id; - space->index = mh_pk_new(); - - const struct mh_u32ptr_node_t node = { .key = space->id, .val = space }; - mh_u32ptr_put(s->t, &node, NULL, space); - return space; -} - -struct ts_space *ts_space_match(struct ts_spaces *s, uint32_t id) { - const struct mh_u32ptr_node_t node = { .key = id }; - mh_int_t k = mh_u32ptr_get(s->t, &node, NULL); - struct ts_space *space = NULL; - if (k != mh_end(s->t)) - space = mh_u32ptr_node(s->t, k)->val; - return space; -} - -enum ts_space_key_type -ts_space_key_typeof(char *name) -{ - if (strcmp(name, "NUM") == 0) - return TS_SPACE_KEY_NUM; - else - if (strcmp(name, "NUM64") == 0) - return TS_SPACE_KEY_NUM64; - else - if (strcmp(name, "STR") == 0) - return TS_SPACE_KEY_STRING; - return TS_SPACE_KEY_UNKNOWN; -} - -#if 0 -static int -ts_space_key_init(struct ts_space *s, tarantool_cfg_space *cs) -{ - struct tarantool_cfg_space_index *primary = cs->index[0]; - - /* calculate primary key part count */ - while (primary->key_field[s->pk.count]) { - struct tarantool_cfg_space_index_key_field *ck = - primary->key_field[s->pk.count]; - /*typeof(primary->key_field[s->pk.count]) ck = primary->key_field[s->pk.count];*/ - if (ck->fieldno == -1) - break; - s->pk.count++; - } - - /* allocate key fields */ - size_t size = sizeof(struct ts_space_key_field) * s->pk.count; - s->pk.fields = malloc(size); - if (s->pk.fields == NULL) { - printf("can't allocate key fields\n"); - return -1; - } - memset(s->pk.fields, 0, size); - - int key_has_string = 0; - int key_size = 0; - - /* init key fields */ - int kn = 0; - while (primary->key_field[kn]) { - struct ts_space_key_field *k = &s->pk.fields[kn]; - struct tarantool_cfg_space_index_key_field *ck = primary->key_field[kn]; - /*typeof(primary->key_field[s->pk.count]) ck = primary->key_field[kn];*/ - if (ck->fieldno == -1) - break; - k->n = ck->fieldno; - k->type = ts_space_key_typeof(ck->type); - if (key_has_string) { - kn++; - continue; - } - switch (k->type) { - case TS_SPACE_KEY_STRING: - key_has_string = 1; - break; - case TS_SPACE_KEY_NUM: - key_size += 4; - break; - case TS_SPACE_KEY_NUM64: - key_size += 8; - break; - default: - printf("bad key type\n"); - return -1; - } - kn++; - } - - /* decide key compaction type */ - if (key_has_string || key_size > 20) { - s->c = TS_SPACE_COMPACT_CHECKSUM; - s->key_size = 20; - s->key_div = 5; - } else { - s->c = TS_SPACE_COMPACT_SPARSE; - s->key_size = key_size; - s->key_div = key_size / 4; - } - - return 0; -} - -int ts_space_fillof(struct ts_spaces *s, int n, tarantool_cfg_space *cs) -{ - struct ts_space *space = ts_space_match(s, n); - if (space) { - printf("space %i is already defined\n", n); - return -1; - } - space = ts_space_create(s, n); - if (space == NULL) { - printf("failed to create space %d\n", n); - return -1; - } - if (cs->index[0] == NULL) { - printf("primary index is not defined\n"); - return -1; - } - memset(&space->pk, 0, sizeof(space->pk)); - - int rc = ts_space_key_init(space, cs); - if (rc == -1) - return -1; - return 0; -} - -int ts_space_fill(struct ts_spaces *s, struct ts_options *opts) -{ - if (opts->cfg.space == NULL) - return 0; - int i = 0; - for (; opts->cfg.space[i]; i++) { - tarantool_cfg_space *cs = opts->cfg.space[i]; - if (!CNF_STRUCT_DEFINED(cs) || !cs->enabled) - continue; - int rc = ts_space_fillof(s, i, cs); - if (rc == -1) - return -1; - } - return 0; -} -#endif - -static inline struct ts_key* -ts_space_keyalloc_sha(struct ts_space *s, struct tnt_tuple *t, int fileid, - uint64_t offset, int attach) -{ - int size = sizeof(struct ts_key) + s->key_size; - if (attach) - size += sizeof(uint32_t) + t->size; - struct ts_key *k = malloc(size); - if (k == NULL) - return NULL; - k->file = fileid; - k->offset = offset; - k->flags = 0; - - SHA1_CTX ctx; - SHA1Init(&ctx); - int i = 0; - while (i < s->pk.count) { - struct tnt_iter it; - tnt_iter(&it, t); - if (tnt_field(&it, t, s->pk.fields[i].n) == NULL) { - free(k); - tnt_iter_free(&it); - return NULL; - } - if (it.status != TNT_ITER_OK) { - free(k); - tnt_iter_free(&it); - return NULL; - } - SHA1Update(&ctx, (const unsigned char*)TNT_IFIELD_DATA(&it), - TNT_IFIELD_SIZE(&it)); - tnt_iter_free(&it); - i++; - } - SHA1Final(k->key, &ctx); - - if (attach) { - k->flags = TS_KEY_WITH_DATA; - memcpy(k->key + s->key_size, &t->size, sizeof(uint32_t)); - memcpy(k->key + s->key_size + sizeof(uint32_t), t->data, t->size); - } - return k; -} - -static inline struct ts_key* -ts_space_keyalloc_sparse(struct ts_space *s, struct tnt_tuple *t, int fileid, - uint64_t offset, int attach) -{ - int size = sizeof(struct ts_key) + s->key_size; - if (attach) - size += sizeof(uint32_t) + t->size; - struct ts_key *k = malloc(size); - if (k == NULL) - return NULL; - memset(k, 0, size); - k->file = fileid; - k->offset = offset; - k->flags = 0; - - int off = 0; - int i = 0; - while (i < s->pk.count) { - struct tnt_iter it; - tnt_iter(&it, t); - if (tnt_field(&it, t, s->pk.fields[i].n) == NULL) { - free(k); - tnt_iter_free(&it); - return NULL; - } - if (it.status != TNT_ITER_OK) { - free(k); - tnt_iter_free(&it); - return NULL; - } - memcpy(k->key + off, TNT_IFIELD_DATA(&it), TNT_IFIELD_SIZE(&it)); - off += TNT_IFIELD_SIZE(&it); - - tnt_iter_free(&it); - i++; - } - if (attach) { - k->flags = TS_KEY_WITH_DATA; - memcpy(k->key + s->key_size, &t->size, sizeof(uint32_t)); - memcpy(k->key + s->key_size + sizeof(uint32_t), t->data, t->size); - } - return k; -} - -struct ts_key* -ts_space_keyalloc(struct ts_space *s, struct tnt_tuple *t, int fileid, - uint64_t offset, int attach) -{ - struct ts_key *k = NULL; - switch (s->c) { - case TS_SPACE_COMPACT_CHECKSUM: - k = ts_space_keyalloc_sha(s, t, fileid, offset, attach); - break; - case TS_SPACE_COMPACT_SPARSE: - k = ts_space_keyalloc_sparse(s, t, fileid, offset, attach); - break; - } - if (k == NULL) - return NULL; - tss.alloc += ts_space_keysize(s, k); - ts_oomcheck(); - return k; -} - -void -ts_space_keyfree(struct ts_space *s, struct ts_key *k) { - tss.alloc -= ts_space_keysize(s, k); - free(k); -} diff --git a/client/tarantar/space.h b/client/tarantar/space.h deleted file mode 100644 index b028c65c1c..0000000000 --- a/client/tarantar/space.h +++ /dev/null @@ -1,66 +0,0 @@ -#ifndef TS_SPACE_H_INCLUDED -#define TS_SPACE_H_INCLUDED - -enum ts_space_key_type { - TS_SPACE_KEY_UNKNOWN = -1, - TS_SPACE_KEY_NUM = 0, - TS_SPACE_KEY_NUM64, - TS_SPACE_KEY_STRING -}; - -enum ts_space_compact { - TS_SPACE_COMPACT_CHECKSUM, - TS_SPACE_COMPACT_SPARSE -}; - -struct ts_space_key_field { - enum ts_space_key_type type; - int n; -}; - -struct ts_space_key { - struct ts_space_key_field *fields; - int count; -}; - -struct ts_space { - enum ts_space_compact c; - int key_size; - int key_div; - - uint32_t id; - struct mh_pk_t *index; - struct ts_space_key pk; -}; - -struct ts_spaces { - struct mh_u32ptr_t *t; -}; - -int ts_space_init(struct ts_spaces *s); -void ts_space_free(struct ts_spaces *s); -void ts_space_recycle(struct ts_spaces *s); - -struct ts_space *ts_space_create(struct ts_spaces *s, uint32_t id); -struct ts_space *ts_space_match(struct ts_spaces *s, uint32_t id); - -#if 0 -int ts_space_fill(struct ts_spaces *s, struct ts_options *opts); -#endif - -struct ts_key* -ts_space_keyalloc(struct ts_space *s, struct tnt_tuple *t, int fileid, - uint64_t offset, int attach); - -void -ts_space_keyfree(struct ts_space *s, struct ts_key *k); - -static inline size_t -ts_space_keysize(struct ts_space *s, struct ts_key *k) { - size_t size = sizeof(struct ts_key) + s->key_size; - if (k->flags == TS_KEY_WITH_DATA) - size += sizeof(uint32_t) + *(uint32_t*)(k->key + s->key_size); - return size; -} - -#endif diff --git a/client/tarantar/ts.h b/client/tarantar/ts.h deleted file mode 100644 index 1502ec13d5..0000000000 --- a/client/tarantar/ts.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef TS_H_INCLUDED -#define TS_H_INCLUDED - -struct ts { - struct ts_options opts; - struct ts_spaces s; - struct ts_reftable rt; - uint64_t last_snap_lsn; - uint64_t last_xlog_lsn; - int to_lsn_set; - uint64_t alloc; - uint64_t to_lsn; - struct slab_cache sc; - struct region ra; - const char* snap_dir; - const char* wal_dir; -}; - -void ts_oomcheck(void); - -#endif diff --git a/client/tarantar/update.cc b/client/tarantar/update.cc deleted file mode 100644 index 36cc671ecd..0000000000 --- a/client/tarantar/update.cc +++ /dev/null @@ -1,119 +0,0 @@ -/* - * 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 <stdlib.h> -#include <stdarg.h> -#include <stdint.h> -#include <inttypes.h> -#include <stdio.h> -#include <string.h> - -#include <exception.h> -#include <pickle.h> -#include <src/box/tuple_update.h> - -extern "C" { - -#include <cfg/prscfg.h> -#include <cfg/tarantool_box_cfg.h> -#include <lib/small/region.h> - -#include <connector/c/include/tarantool/tnt.h> - -#include "key.h" -#include "hash.h" -#include "options.h" -#include "space.h" -#include "sha1.h" -#include "ref.h" -#include "ts.h" -#include "indexate.h" - -extern struct ts tss; - -static inline void* -_alloc(void *arg, unsigned int size) { - (void)arg; - return region_alloc(&tss.ra, size); -} - -struct tnt_tuple* -ts_update(struct tnt_request *r, struct tnt_tuple *old) -{ - (void) r; - (void) old; - /* TODO: MessagePack */ -#if 0 - void *buf = NULL; - uint32_t new_size = 0; - uint32_t new_count = 0; - try { - struct tuple_update *u = - tuple_update_prepare((region_alloc_func)_alloc, NULL, - (const char*)(r->r.update.ops), - (const char*)(r->r.update.ops + r->r.update.ops_size), - (const char*)(old->data + sizeof(uint32_t)), - (const char*)(old->data + sizeof(uint32_t) + old->size - sizeof(uint32_t)), - old->cardinality, - &new_size, - &new_count); - if (u == NULL) - return NULL; - - buf = tnt_mem_alloc(new_size); - if (buf == NULL) { - region_reset(&tss.ra); - return NULL; - } - memset(buf, 0, new_size); - - tuple_update_execute(u, (char*)buf); - } catch (Exception *e) { - if (buf) - free(buf); - region_reset(&tss.ra); - fflush(NULL); - printf("update failed\n"); - return NULL; - } - - region_reset(&tss.ra); - struct tnt_tuple *n = tnt_tuple_set_as(NULL, buf, new_size, new_count); - if (n == NULL) { - free(buf); - return NULL; - } - - free(buf); - return n; -#endif - return NULL; -} - -} // extern "C" diff --git a/client/tarantar/update.h b/client/tarantar/update.h deleted file mode 100644 index 0e5a624898..0000000000 --- a/client/tarantar/update.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef TS_UPDATE_H_INCLUDED -#define TS_UPDATE_H_INCLUDED - -struct tnt_tuple *ts_update(struct tnt_request *r, struct tnt_tuple *old); - -#endif diff --git a/client/tarantool/CMakeLists.txt b/client/tarantool/CMakeLists.txt deleted file mode 100644 index 563c03041a..0000000000 --- a/client/tarantool/CMakeLists.txt +++ /dev/null @@ -1,24 +0,0 @@ - -set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/" ${CMAKE_MODULE_PATH}) -include(FindReadline) - -if (NOT READLINE_FOUND) - message(FATAL_ERROR "readline library not found.") -endif() - -set(cli "tarantool") -set(cli_sources main.c opt.c query.c print.c buf.c cli.c pager.c store.c) -set(cli_libs gopt ${READLINE_LIBRARIES} tb) - -include_directories(${READLINE_INCLUDE_DIR}) - -add_definitions("-DTB_LOCAL=${PROJECT_SOURCE_DIR}/connector/c/tb/lib") - -list(APPEND cli_sources ${CMAKE_SOURCE_DIR}/src/errcode.c) - -add_executable(${cli} ${cli_sources}) -set_source_files_compile_flags("TARANTOOL" ${cli_sources}) -target_link_libraries (${cli} ${cli_libs}) - -install(TARGETS ${cli} DESTINATION bin) - diff --git a/client/tarantool/buf.c b/client/tarantool/buf.c deleted file mode 100644 index d8aad7eb2c..0000000000 --- a/client/tarantool/buf.c +++ /dev/null @@ -1,149 +0,0 @@ -/* - * 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 <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <stddef.h> -#include <ctype.h> - -#include "client/tarantool/buf.h" - -/* Strip trailing ws from (char*) */ -size_t strip_end_ws(char *str) { - size_t last = 0; - for (size_t i = 0; str[i] != 0; ++i) { - if (!isspace(str[i])) - last = i + 1; - } - str[last] = '\0'; - return last; -} - -/* Init membuf */ -int tc_buf(struct tc_buf *buf) { - buf->size = TC_BUF_INIT_SIZE; - buf->used = 0; - buf->data = (char *)malloc(buf->size); - if (buf->data == NULL) { - return -1; - } - return 0; -} - -/* Append len bytes of memory from str pointed memory */ -int tc_buf_append(struct tc_buf *buf, void *str, size_t len) { - if (buf->size - buf->used < len) { - if (buf->size < len) { - buf->size = len; - } - buf->size *= TC_BUF_MULTIPLIER; - char *nd = (char *)realloc(buf->data, buf->size); - if (nd == NULL) - return -1; - buf->data = nd; - } - memcpy(buf->data + buf->used, str, len); - buf->used += len; - return 0; -} - -/* Remove last "num" symbols */ -size_t tc_buf_delete(struct tc_buf *buf, size_t num) { - if (buf->used > num) { - buf->used -= num; - } else { - num = buf->used; - buf->used = 0; - } - return num; -} - -inline int tc_buf_isempty(struct tc_buf *buf) { - return (buf->used == 0); -} - -inline void tc_buf_clear(struct tc_buf *buf) { - buf->used = 0; -} - -/* Free membuffer */ -void tc_buf_free(struct tc_buf *buf) { - if (buf->data) - free(buf->data); -} - -/* Init buffer as STR */ -int tc_buf_str(struct tc_buf *buf) { - if (tc_buf(buf)) - return -1; - return tc_buf_append(buf, (void *)"\0", 1); -} - -/* Append str to STR */ -int tc_buf_str_append(struct tc_buf *buf, char *str, size_t len) { - tc_buf_delete(buf, 1); - if (tc_buf_append(buf, (void *)str, len)) - return -1; - if (tc_buf_append(buf, (void *)"\0", 1)) - return -1; - return 0; -} - -/* Remove last num symbols from STR */ -size_t tc_buf_str_delete(struct tc_buf *buf, size_t len) { - size_t ret = tc_buf_delete(buf, len + 1); /* Remove '\0' + len */ - if (tc_buf_append(buf, (void *)"\0", 1)) - return 0; - return ret; -} - -/* - * Make admin command from multiline command - * and delete delimiter (last num bytes) - */ -void tc_buf_cmdfy(struct tc_buf *buf, size_t num) { - tc_buf_str_delete(buf, num); - for (int i = 0; i < buf->used; ++i) { - if (buf->data[i] == '\n') - buf->data[i] = ' '; - } -} - -/* Remove trailing ws from STR */ -int tc_buf_str_stripws(struct tc_buf *buf) { - if (buf->data) { - buf->used = 1 + strip_end_ws(buf->data); - return 0; - } - return -1; -} - -inline int tc_buf_str_isempty(struct tc_buf *buf) { - return (buf->used == 1 ? 1 : 0) || (tc_buf_isempty(buf)); -} diff --git a/client/tarantool/buf.h b/client/tarantool/buf.h deleted file mode 100644 index fd1ad2e47d..0000000000 --- a/client/tarantool/buf.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * 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. - */ - -#define TC_BUF_INIT_SIZE 4096 -#define TC_BUF_MULTIPLIER 2 - -size_t strip_end_ws(char *str); - -struct tc_buf { - size_t size; - size_t used; - char *data; -}; - -int tc_buf(struct tc_buf *buf); -void *tc_buf_realloc(void *data, size_t size); -int tc_buf_append(struct tc_buf *buf, void *str, size_t len); -size_t tc_buf_delete(struct tc_buf *buf, size_t num); -int tc_buf_isempty(struct tc_buf *buf); -void tc_buf_clear(struct tc_buf *buf); -void tc_buf_free(struct tc_buf *buf); - -int tc_buf_str(struct tc_buf *buf); -int tc_buf_str_append(struct tc_buf *buf, char *str, size_t len); -size_t tc_buf_str_delete(struct tc_buf *buf, size_t num); -int tc_buf_str_stripws(struct tc_buf *buf); -int tc_buf_str_isempty(struct tc_buf *buf); - -void tc_buf_cmdfy(struct tc_buf *buf, size_t num); diff --git a/client/tarantool/cli.c b/client/tarantool/cli.c deleted file mode 100644 index 42017f44c0..0000000000 --- a/client/tarantool/cli.c +++ /dev/null @@ -1,474 +0,0 @@ -/* - * 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 <lib/tarantool.h> -#include <ctype.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <unistd.h> -#include <fcntl.h> -#include <signal.h> -#include <wchar.h> - -#include <readline/readline.h> -#include <readline/history.h> - -#include <client/tarantool/opt.h> -#include <client/tarantool/main.h> -#include <client/tarantool/pager.h> -#include <client/tarantool/query.h> -#include <client/tarantool/cli.h> -#include <client/tarantool/print.h> -#include <client/tarantool/buf.h> - -extern struct tarantool_client tc; - -static inline int tc_clierror(char *e) { - if (e) - tc_printf("%s\n", e); - return 1; -} - -static int tc_clireconnect(void) -{ - tb_sesclose(&tc.console); - int rc = tb_sesconnect(&tc.console); - if (rc == -1) { - tc_printf("reconnect: admin console connection failed\n"); - return 1; - } - tc_printf("reconnected\n"); - return 0; -} - -static int -tc_cliquery(char *cmd, int exit) -{ - tc_query_t cb = (exit) ? NULL : tc_printer; - if (!exit) - tc_pager_start(); - if (tc_query(cmd, cb) == -1) - return tc_clierror("failed to send admin query"); - if (!exit) - tc_pager_stop(); - return 0; -} - -enum tc_keywords { - TC_EXIT = TB_TCUSTOM + 1, - TC_LOADFILE, - TC_HELP, - TC_SETOPT, - TC_SETOPT_DELIM, - TC_SETOPT_PAGER -}; - -static struct tbkeyword tc_keywords[] = -{ - { "exit", 4, TC_EXIT }, - { "quit", 4, TC_EXIT }, - { "help", 4, TC_HELP }, - { "loadfile", 8, TC_LOADFILE }, - { "setopt", 6, TC_SETOPT }, - { "delimiter", 9, TC_SETOPT_DELIM }, - { "pager", 5, TC_SETOPT_PAGER }, - { NULL, 0, TB_TNONE } -}; - -enum tc_cliret { - TC_CLI_OK, - TC_CLI_ERROR, - TC_CLI_EXIT -}; - -static void -tc_cmdusage(void) -{ - char usage[] = - "---\n" - " - console client commands\n" - " - help\n" - " - loadfile 'path'\n" - " - setopt key=val\n" - " - - delimiter = \'string\'\n" - " - pager = \'command\'\n" - "...\n"; - tc_printf("%s", usage); -} - -#if 0 -static int -tc_cmddostring(char *buf, size_t size, int *reconnect) -{ -#if 0 - struct tnt_tuple args; - tnt_tuple_init(&args); - tnt_tuple_add(&args, buf, size); - int rc = tnt_call(tc.net, 0, "box.dostring", &args); - if (rc < 0) - goto error; - rc = tnt_flush(tc.net); - if (rc < 0) - goto error; - tnt_tuple_free(&args); - char *e = NULL; - tc_pager_start(); - if (tc_query_foreach(tc_query_printer, NULL, &e) == -1) { - *reconnect = tc_cl_error(e); - return -1; - } - tc_pager_stop(); - return 0; -error: - tc_printf("error: %s\n", tnt_strerror(tc.net)); - tnt_tuple_free(&args); - return -1; -#endif - (void)buf; - (void)size; - (void)reconnect; - return 0; -} - -static int -tc_cmd_loadfile(char *path, int *reconnect) -{ - struct stat st; - if (stat(path, &st) == -1) { - tc_printf("error: stat(): %s\n", strerror(errno)); - return -1; - } - int fd = open(path, O_RDONLY); - if (fd == -1) - return -1; - char *buf = (char *)malloc(st.st_size); - if (buf == NULL) { - tc_printf(TC_ALLOCATION_ERROR, - st.st_size); - return -1; - } - size_t off = 0; - do { - ssize_t r = read(fd, buf + off, st.st_size - off); - if (r == -1) { - close(fd); - free(buf); - tc_printf("error: read(): %s\n", strerror(errno)); - return -1; - } - off += r; - } while (off != st.st_size); - close(fd); - - int rc = tc_cmd_dostring(buf, st.st_size, reconnect); - free(buf); - return rc; -} -#endif - -static void -tc_strip(char *cmd) -{ - int len = strlen(cmd); - int offset = 0; - for (int i = 0; i < len - 1; ++i) - if (cmd[i] == '\\' && cmd[i + 1] == 'n') - cmd[i++ - offset++] = '\n'; - else if (offset != 0) - cmd[i - offset] = cmd[i]; - cmd[len - offset] = '\0'; -} - -static void -tc_setopt(struct tblex *lex) -{ - struct tbtoken *tk; - switch (tb_lex(lex, &tk)) { - case TC_SETOPT_DELIM: - if (tb_lex(lex, &tk) != '=') - tb_lexpush(lex, tk); - if (tb_lex(lex, &tk) != TB_TSTRING) { - tc_printf("---\n"); - tc_printf(" - Expected delimiter='string'\n"); - tc_printf("---\n"); - break; - } - if (! tk->v.s.size) { - if (tc.opt.delim) - free(tc.opt.delim); - tc.opt.delim = NULL; - tc.opt.delim_len = 0; - break; - } - char *temp = tc_malloc(tk->v.s.size + 1); - strncpy(temp, (const char*)tk->v.s.data, tk->v.s.size + 1); - temp[tk->v.s.size] = '\0'; - tc_strip(temp); - tc.opt.delim = temp; - tc.opt.delim_len = strlen(tc.opt.delim); - break; - case TC_SETOPT_PAGER: - if (tb_lex(lex, &tk) == '=' && - tb_lex(lex, &tk) == TB_TSTRING) { - if (! tk->v.s.size) { - if (tc.opt.pager) - free(tc.opt.pager); - tc.opt.pager = NULL; - break; - } - char *temp = (char *)malloc(tk->v.s.size + 1); - if (temp == NULL) - tc_oom(); - strncpy(temp, (const char *)tk->v.s.data, tk->v.s.size + 1); - temp[tk->v.s.size] = '\0'; - tc.opt.pager = temp; - } else { - tc_printf("---\n"); - tc_printf(" - Expected pager='command'\n"); - tc_printf("---\n"); - } - break; - default: - tc_printf("---\n"); - tc_printf(" - Unknown option to set\n"); - tc_printf("---\n"); - break; - } -} - -static enum tc_cliret -tc_cmdtry(char *cmd, size_t size, int *reconnect) -{ - enum tc_cliret rc = TC_CLI_OK; - struct tblex lex; - if (tb_lexinit(&lex, tc_keywords, cmd, size) == -1) - return TC_CLI_ERROR; - struct tbtoken *tk; - switch (tb_lex(&lex, &tk)) { - case TC_EXIT: - rc = TC_CLI_EXIT; - break; - case TC_HELP: - tc_cmdusage(); - cmd = "help()"; - break; - case TC_SETOPT: - tc_setopt(&lex); - goto done; -#if 0 - case TC_LOADFILE: - if (tnt_lex(&lex, &tk) != TNT_TK_STRING) { - rc = TC_CLI_ERROR; - goto done; - } - if (tc_cmd_loadfile((char*)TNT_TK_S(tk)->data, reconnect) == -1) - rc = TC_CLI_ERROR; - goto done; -#endif - } - *reconnect = tc_cliquery(cmd, rc == TC_CLI_EXIT); - if (*reconnect) - rc = TC_CLI_ERROR; -done: - tb_lexfree(&lex); - return rc; -} - -static enum tc_cliret -tc_clicmd(char *cmd, size_t size) -{ - int reconnect = 0; - do { - if (reconnect) { - reconnect = tc_clireconnect(); - if (reconnect) - return TC_CLI_ERROR; - } - enum tc_cliret rc = tc_cmdtry(cmd, size, &reconnect); - if (reconnect) - continue; - if (rc == TC_CLI_EXIT || rc == TC_CLI_ERROR) - return rc; - } while (reconnect); - - return TC_CLI_OK; -} - -int tc_clicmdv(void) -{ - int i, rc = 0; - for (i = 0 ; i < tc.opt.cmdc ; i++) { - char *cmd = tc.opt.cmdv[i]; - int len = strlen(tc.opt.cmdv[i]); - enum tc_cliret ret = tc_clicmd(cmd, len); - if (ret == TC_CLI_EXIT) - break; - if (ret == TC_CLI_ERROR) { - rc = 1; - break; - } - } - return rc; -} - -static void -tc_cliinit(void) -{ - /* ignore SIGPIPE for reconnection handling */ - struct sigaction sa; - memset(&sa, 0, sizeof(sa)); - sigemptyset(&sa.sa_mask); - sa.sa_handler = SIG_IGN; - if (sigaction(SIGPIPE, &sa, NULL) == -1) - tc_error("signal initialization failed\n"); -} - -static char* -tc_clipipe(void) -{ - int size = 8192, pos = 0; - const size_t wcsize = sizeof(wchar_t); - char *str = malloc(size); - if (str == NULL) - tc_oom(); - wchar_t c; - while ((c = getwchar())) { - if (size < (pos + wcsize)) { - size *= 2; - char *nd = (char *)realloc(str, size); - if (nd == NULL) - tc_oom(); - str = nd; - } - if (c == '\r' || c == '\n' || c == WEOF) { - char c_t = (c != WEOF ? getchar() : '\n'); - if (c_t != '\r' && c_t != '\n') - ungetc(c_t, stdin); - wctomb(str + pos++, 0); - break; - } else { - pos += wctomb(str + pos, c); - } - } - if (pos == 1 && c == WEOF) { - free(str); - return NULL; - } - return str; -} - -static int -tc_hasdelim(char* str, size_t len, size_t lensep) -{ - const char *sep = tc.opt.delim; - if (lensep == 0) - return 1; - if (len < lensep) - return 0; - size_t i; - for (i = len; lensep > 0; --lensep, --i) - if (str[i - 1] != sep[lensep - 1]) - return 0; - return 1; -} - -int tc_cli(void) -{ - /* initialize cli */ - tc_cliinit(); - - /* load history file */ - char *home = getenv("HOME"); - char history[1024]; - snprintf(history, sizeof(history), "%s/%s", home, - TC_DEFAULT_HISTORY_FILE); - read_history(history); - - /* set prompt */ - char prompt[128]; - int prompt_len = - snprintf(prompt, sizeof(prompt), "%s> ", tc.opt.host) - 2; - char prompt_delim[128]; - - /* interactive mode */ - char *part_cmd; - struct tc_buf cmd; - if (tc_buf_str(&cmd)) - tc_oom(); - - while (1) { - if (isatty(STDIN_FILENO)) { - snprintf(prompt_delim, sizeof(prompt_delim), - "%*s> ", prompt_len, "-"); - part_cmd = readline(!tc_buf_str_isempty(&cmd) ? - prompt_delim : prompt); - } else { - clearerr(stdin); - part_cmd = tc_clipipe(); - } - if (!part_cmd) - break; - if (tc_buf_str_append(&cmd, part_cmd, strlen(part_cmd))) - tc_oom(); - - int delim_exists = - tc_hasdelim(cmd.data, cmd.used - 1, - tc.opt.delim_len); - - if (tc_buf_str_append(&cmd, "\n", 1)) - tc_oom(); - free(part_cmd); - if (!delim_exists && !feof(stdin)) - continue; - tc_buf_str_delete(&cmd, 1); - if (isatty(STDIN_FILENO)) - add_history(cmd.data); - tc_buf_cmdfy(&cmd, tc.opt.delim_len); - enum tc_cliret ret; - if (delim_exists && tc_buf_str_isempty(&cmd)) { - tc_buf_clear(&cmd); - if (feof(stdin)) { - tc_buf_free(&cmd); - break; - } - } else { - ret = tc_clicmd(cmd.data, cmd.used - 1); - tc_buf_clear(&cmd); - if (ret == TC_CLI_EXIT || feof(stdin)) { - tc_buf_free(&cmd); - break; - } - } - } - - /* update history file */ - write_history(history); - clear_history(); - return 0; -} diff --git a/client/tarantool/cli.h b/client/tarantool/cli.h deleted file mode 100644 index 6120e03125..0000000000 --- a/client/tarantool/cli.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef TC_CLI_H_INCLUDED -#define TC_CLI_H_INCLUDED -/* - * 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. - */ -int tc_cli(void); -int tc_clicmdv(void); - -#endif /* TC_CLI_H_INCLUDED */ diff --git a/client/tarantool/main.c b/client/tarantool/main.c deleted file mode 100644 index 15740a4fa8..0000000000 --- a/client/tarantool/main.c +++ /dev/null @@ -1,194 +0,0 @@ - -/* - * 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 <lib/tarantool.h> -#include <locale.h> -#include <unistd.h> - -#include <client/tarantool/opt.h> -#include <client/tarantool/main.h> -#include <client/tarantool/pager.h> -#include <client/tarantool/cli.h> -#include <client/tarantool/print.h> -#include <client/tarantool/store.h> -#include <client/tarantool/query.h> -/*#include <client/tarantool/print_snap.h>*/ -/*#include <client/tarantool/print_xlog.h>*/ - -struct tarantool_client tc; - -static void -tc_init(void) -{ - memset(&tc, 0, sizeof(tc)); - setlocale(LC_ALL, ""); - if (tc.opt.pager) - free(tc.opt.pager); - if (tc.opt.delim) - free(tc.opt.delim); - tc.pager_stream = stdout; - tc.pager_pid = 0; - tb_sesinit(&tc.console); -} - -static void -tc_shutdown(void) -{ - tb_sesclose(&tc.console); - tc_pager_kill(); -} - -void tc_error(char *fmt, ...) -{ - char msg[256]; - va_list args; - tc_shutdown(); - va_start(args, fmt); - vsnprintf(msg, sizeof(msg), fmt, args); - va_end(args); - tc_printf("error: %s\n", msg); - exit(1); -} - -static int -tc_motdof(char *r) -{ - if (strcmp(r, TC_ERRCMD) != 0) - tc_printf("%s", r); - return 0; -} - -static void -tc_motd(void) -{ - int rc = tc_query("motd()", tc_motdof); - if (rc == -1) - tc_error("%s\n", "failed to send console query"); -} - -static int -tc_primaryportof(char *r) -{ - if (strcmp(r, TC_ERRCMD) != 0) - return 0; - int port = 0; - sscanf(r, "---\n - %d\n...", &port); - return port; -} - -static int -tc_primaryport() -{ - int rc = tc_query("box.cfg.primary_port", tc_primaryportof); - if (rc == -1) - tc_error("%s\n", "failed to send console query"); - if (rc > 0) - return rc; - rc = tc_query("lua box.cfg.primary_port", tc_primaryportof); - if (rc == -1) - tc_error("%s\n", "failed to send console query"); - return rc; -} - -static void -tc_connect(void) -{ - tb_sesset(&tc.console, TB_HOST, tc.opt.host); - tb_sesset(&tc.console, TB_PORT, tc.opt.port_console); - tb_sesset(&tc.console, TB_SENDBUF, 0); - tb_sesset(&tc.console, TB_READBUF, 0); - - int rc = tb_sesconnect(&tc.console); - if (rc == -1) - tc_error("console connection failed"); - - if (tc.opt.port == 0) - tc.opt.port = tc_primaryport(); -} - -#if 0 -static void tc_validate(void) -{ - tc.opt.xlog_printer = tc_print_getxlogcb(tc.opt.format); - tc.opt.snap_printer = tc_print_getsnapcb(tc.opt.format); - if (tc.opt.xlog_printer == NULL) - tc_error("unsupported output xlog format '%s'", - tc.opt.format); - if (tc.opt.snap_printer == NULL) - tc_error("unsupported output snap format '%s'", - tc.opt.format); - if (tc.opt.format && strcmp(tc.opt.format, "raw") == 0) - tc.opt.raw = 1; -} -#endif - -int main(int argc, char *argv[], char *envp[]) -{ - tc_init(); - enum tc_opt_mode mode = - tc_opt_init(&tc.opt, argc, argv, envp); - - /*tc_validate();*/ - - int rc = 0; - switch (mode) { - case TC_OPT_USAGE: - tc_opt_usage(); - break; - case TC_OPT_VERSION: - tc_opt_version(); - break; - case TC_OPT_WAL_CAT: - rc = tc_store_cat(); - break; -#if 0 - case TC_OPT_RPL: - tc_connect(); - rc = tc_store_remote(); - break; - case TC_OPT_WAL_PLAY: - tc_connect(); - rc = tc_store_play(); - break; -#endif - case TC_OPT_CMD: - tc_connect(); - rc = tc_clicmdv(); - break; - case TC_OPT_INTERACTIVE: - tc_connect(); - tc_motd(); - rc = tc_cli(); - break; - } - - tc_shutdown(); - return rc; -} diff --git a/client/tarantool/main.h b/client/tarantool/main.h deleted file mode 100644 index 17ada9393d..0000000000 --- a/client/tarantool/main.h +++ /dev/null @@ -1,72 +0,0 @@ -#ifndef TC_MAIN_H_INCLUDED -#define TC_MAIN_H_INCLUDED -/* - * 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. - */ - -#define TC_VERSION_MAJOR "0" -#define TC_VERSION_MINOR "3" - -#define TC_DEFAULT_HOST "localhost" -#define TC_DEFAULT_PORT 3301 -#define TC_DEFAULT_ADMIN_PORT 3313 -#define TC_DEFAULT_HISTORY_FILE ".tarantool_history" - -struct tarantool_client { - struct tbses console; - struct tc_opt opt; - FILE *pager_stream; - pid_t pager_pid; -}; - -void tc_error(char *fmt, ...); - -static inline void -tc_oom(void) { - tc_error("memory allocation failed"); -} - -static inline void* -tc_malloc(size_t size) { - void *p = malloc(size); - if (p == NULL) - tc_oom(); - return p; -} - -static inline char* -tc_strdup(char *sz) { - char *p = strdup(sz); - if (p == NULL) - tc_oom(); - return p; -} - -#define TC_ERRCMD "---\nunknown command. try typing help.\n...\n" - -#endif /* TC_H_INCLUDED */ diff --git a/client/tarantool/opt.c b/client/tarantool/opt.c deleted file mode 100644 index 9c54c7a844..0000000000 --- a/client/tarantool/opt.c +++ /dev/null @@ -1,214 +0,0 @@ -/* - * 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 <lib/tarantool.h> - -#include <third_party/gopt/gopt.h> - -#include <client/tarantool/opt.h> -#include <client/tarantool/main.h> - -/* supported cli options */ -static const void *tc_options_def = gopt_start( - gopt_option('h', GOPT_ARG, gopt_shorts('h'), - gopt_longs("host"), " <host>", "server address"), -#if 0 - gopt_option('p', GOPT_ARG, gopt_shorts('p'), - gopt_longs("port"), " <port number>", "server port"), -#endif - gopt_option('a', GOPT_ARG, gopt_shorts('a'), - gopt_longs("admin-port"), " <port number>", "server admin console port"), - gopt_option('C', GOPT_ARG, gopt_shorts('C'), - gopt_longs("cat"), " <file name>", "print xlog or snapshot file content"), -#if 0 - gopt_option('P', GOPT_ARG, gopt_shorts('P'), - gopt_longs("play"), " <file name>", "replay xlog file to the specified server"), -#endif - gopt_option('S', GOPT_ARG, gopt_shorts('S'), - gopt_longs("space"), " <space number>", "filter by space number"), - gopt_option('F', GOPT_ARG, gopt_shorts('F'), - gopt_longs("from"), " <log serial number>", "start xlog file from the specified lsn"), - gopt_option('T', GOPT_ARG, gopt_shorts('T'), - gopt_longs("to"), " <log serial number>", "stop on specified xlog lsn"), - gopt_option('M', GOPT_ARG, gopt_shorts('M'), - gopt_longs("format"), " <name>", "cat output format (tarantool, raw)"), -#if 0 - gopt_option('H', 0, gopt_shorts('H'), - gopt_longs("header"), NULL, "add file headers for the raw output"), - gopt_option('R', GOPT_ARG, gopt_shorts('R'), - gopt_longs("rpl"), " <log serial number>", "act as replica for the specified server"), - gopt_option('B', 0, gopt_shorts('B'), - gopt_longs("bin"), NULL, "print STR in lua printer instead" - " of NUM32 and NUM64, except arithmetic update arguments"), -#endif - gopt_option('D', GOPT_ARG, gopt_shorts('D'), - gopt_longs("delim"), " <delim>", - "if you use --cat, then it will add delim to an end of every line of your " - "Lua file, when used at CLI start of client, then it's replacement of " - "setopt delim='<delim>' command"), - gopt_option('?', 0, gopt_shorts('?'), gopt_longs("help"), - NULL, "display this help and exit"), - gopt_option('V', 0, gopt_shorts('V'), gopt_longs("version"), - NULL, "display version information and exit") -); - -void tc_opt_usage(void) -{ - printf("usage: tarantool [options] [query]\n\n"); - printf("tarantool client.\n"); - gopt_help(tc_options_def); - exit(0); -} - -void tc_opt_version(void) -{ - printf("tarantool client, version %s.%s\n", - TC_VERSION_MAJOR, - TC_VERSION_MINOR); - exit(0); -} - -enum tc_opt_mode -tc_opt_init(struct tc_opt *opt, int argc, char **argv, char **envp) -{ - /* usage */ - void *tc_options = gopt_sort(&argc, (const char**)argv, tc_options_def); - if (gopt(tc_options, '?')) { - opt->mode = TC_OPT_USAGE; - goto done; - } - - /* version */ - if (gopt(tc_options, 'V')) { - opt->mode = TC_OPT_VERSION; - goto done; - } - - /* server host */ - gopt_arg(tc_options, 'h', &opt->host); - if (opt->host == NULL) - opt->host = TC_DEFAULT_HOST; - - /* server port */ - const char *arg = NULL; - opt->port = TC_DEFAULT_PORT; - if (gopt_arg(tc_options, 'p', &arg)) - opt->port = atoi(arg); - - /* server admin console port */ - opt->port_console = TC_DEFAULT_ADMIN_PORT; - if (gopt_arg(tc_options, 'a', &arg)) - opt->port_console = atoi(arg); - -#if 0 - /* space */ - opt->space = 0; - opt->space_set = 0; - if (gopt_arg(tc_options, 'S', &arg)) { - opt->space = atoi(arg); - opt->space_set = 1; - } - - /* from lsn */ - opt->lsn_from = 0; - if (gopt_arg(tc_options, 'F', &arg)) { - opt->lsn_from = strtoll(arg, NULL, 10); - opt->lsn_from_set = 1; - } - - /* to lsn */ - opt->lsn_to = 0; - if (gopt_arg(tc_options, 'T', &arg)) { - opt->lsn_to = strtoll(arg, NULL, 10); - opt->lsn_to_set = 1; - } - - /* output format */ - opt->raw = 0; - opt->format = NULL; - if (gopt_arg(tc_options, 'M', &arg)) - opt->format = arg; - - opt->raw_with_headers = 0; - if (gopt(tc_options, 'H')) - opt->raw_with_headers = 1; - - /* string instead of num and num64 */ - opt->str_instead_int = 0; - if (gopt(tc_options, 'B')) - opt->str_instead_int = 1; -#endif - - /* set delimiter on start */ - opt->delim = NULL; - opt->delim_len = 0; - if (gopt_arg(tc_options, 'D', (const char**)&opt->delim)) - opt->delim_len = strlen(opt->delim); - -#if 0 - /* replica mode */ - if (gopt_arg(tc_options, 'R', &arg)) { - opt->mode = TC_OPT_RPL; - opt->lsn = strtoll(arg, NULL, 10); - goto done; - } - - /* wal-cat mode */ - if (gopt_arg(tc_options, 'C', &opt->file)) { - opt->mode = TC_OPT_WAL_CAT; - if (strcmp(opt->file, "-") == 0) - opt->file = NULL; - goto done; - } - - /* wal-play mode */ - if (gopt_arg(tc_options, 'P', &opt->file)) { - opt->mode = TC_OPT_WAL_PLAY; - goto done; - } -#endif - - /* default */ - if (argc >= 2) { - opt->cmdv = argv + 1; - opt->cmdc = argc - 1; - opt->mode = TC_OPT_CMD; - } else { - opt->mode = TC_OPT_INTERACTIVE; - } - - char *pager = getenv("PAGER"); - if (pager) - opt->pager = tc_strdup(pager); - else - opt->pager = NULL; - opt->envp = envp; -done: - gopt_free(tc_options); - return opt->mode; -} diff --git a/client/tarantool/opt.h b/client/tarantool/opt.h deleted file mode 100644 index dfa5a7d262..0000000000 --- a/client/tarantool/opt.h +++ /dev/null @@ -1,77 +0,0 @@ -#ifndef TC_OPT_H_INCLUDED -#define TC_OPT_H_INCLUDED -/* - * 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. - */ - -enum tc_opt_mode { - TC_OPT_USAGE, - TC_OPT_VERSION, - TC_OPT_WAL_CAT, -#if 0 - TC_OPT_RPL, - TC_OPT_WAL_PLAY, -#endif - TC_OPT_CMD, - TC_OPT_INTERACTIVE -}; - -struct tc_opt { - enum tc_opt_mode mode; - const char *host; - int port; - int port_console; - uint64_t lsn; - uint64_t lsn_from; - int lsn_from_set; - uint64_t lsn_to; - int lsn_to_set; - int space; - int space_set; - const char *format; - int raw; - int raw_with_headers; - int str_instead_int; - void *xlog_printer; - void *snap_printer; - const char *file; - char **cmdv; - int cmdc; - char **envp; - char *delim; - size_t delim_len; - char *pager; -}; - -void tc_opt_usage(void); -void tc_opt_version(void); - -enum tc_opt_mode -tc_opt_init(struct tc_opt *opt, int argc, char **argv, char **envp); - -#endif /* TC_OPT_H_INCLUDED */ diff --git a/client/tarantool/pager.c b/client/tarantool/pager.c deleted file mode 100644 index 0b0784cf49..0000000000 --- a/client/tarantool/pager.c +++ /dev/null @@ -1,87 +0,0 @@ - -/* - * 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 <lib/tarantool.h> -#include <unistd.h> -#include <signal.h> -#include <sys/types.h> -#include <sys/wait.h> - -#include "client/tarantool/opt.h" -#include "client/tarantool/main.h" -#include "client/tarantool/pager.h" - -extern struct tarantool_client tc; - -void tc_pager_start() -{ - if (tc.pager_pid != 0) - tc_pager_kill(); - if (tc.opt.pager == NULL) { - tc.pager_stream = stdout; - return; - } - int pipefd[2]; - const char *const argv[] = {"/bin/sh", "-c", tc.opt.pager, NULL}; - if (pipe(pipefd) < 0) - tc_error("Failed to open pipe. Errno: %s", strerror(errno)); - - pid_t pid = fork(); - if (pid < 0) { - tc_error("Failed to fork. Errno: %s", strerror(errno)); - } else if (pid == 0) { - close(pipefd[1]); - dup2(pipefd[0], STDIN_FILENO); - execve(argv[0], (char * const*)argv, (char * const*)tc.opt.envp); - tc_error("Can't start pager! Errno: %s", strerror(errno)); - } else { - close(pipefd[0]); - tc.pager_stream = fdopen(pipefd[1], "w"); - tc.pager_pid = pid; - } -} - -void tc_pager_stop() -{ - if (tc.pager_pid != 0) { - fclose(tc.pager_stream); - tc.pager_stream = stdout; - waitpid(tc.pager_pid, NULL, 0); - tc.pager_pid = 0; - } -} - -void tc_pager_kill() -{ - if (tc.pager_pid != 0) { - kill(tc.pager_pid, SIGTERM); - tc_pager_stop(); - } -} diff --git a/client/tarantool/pager.h b/client/tarantool/pager.h deleted file mode 100644 index eaef6e16d7..0000000000 --- a/client/tarantool/pager.h +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef TC_PAGER_H_INCLUDED -#define TC_PAGER_H_INCLUDED -/* - * 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. - */ - -void tc_pager_start(); -void tc_pager_stop(); -void tc_pager_kill(); - -#endif /* TC_PAGER_H_INCLUDED */ diff --git a/client/tarantool/print.c b/client/tarantool/print.c deleted file mode 100644 index 0e6b4fd50c..0000000000 --- a/client/tarantool/print.c +++ /dev/null @@ -1,230 +0,0 @@ -/* - * 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 <lib/tarantool.h> -#include <ctype.h> -#include <wctype.h> -#include <unistd.h> -#include <errno.h> - -#include <client/tarantool/opt.h> -#include <client/tarantool/main.h> -#include <client/tarantool/print.h> -#include <client/tarantool/query.h> - -extern struct tarantool_client tc; - -void tc_print_buf(char *buf, size_t size) { - fprintf(tc.pager_stream, "%-.*s", (int)size, buf); - fflush(tc.pager_stream); -} - -void tc_printf(char *fmt, ...) { - va_list args; - va_start(args, fmt); - int stat = vfprintf(tc.pager_stream, fmt, args); - if (stat < 0) - tc_error("Can't write into pager - %d", errno); - va_end(args); - return; -} - -static int tc_str_valid(char *data, uint32_t size) { - int length; - wchar_t dest; - - mbtowc(NULL, NULL, 0); - while ((length = mbtowc(&dest, data, size)) > -1 && size > 0) { - if (length == 0) - ++length; - data += length; - size -= length; - } - if (length == -1) - return 0; - return 1; -} - -void tc_print_string(char *data, uint32_t size, char lua) -{ - if (tc_str_valid(data, size)) { - wchar_t dest; - int length; - mbtowc (NULL, NULL, 0); - while ((length = mbtowc(&dest, data, size)) > -1 && size > 0) { - if (dest >= 0x20) { - if (lua) - switch (dest) { - case '\'': - tc_printf("\\\'"); - break; - case '\\': - tc_printf("\\\\"); - break; - default: - tc_printf ("%lc", dest); - } - else - tc_printf ("%lc", dest); - } - else { - switch (dest) { - case 0x00: - tc_printf("\\0"); - length++; - /* Cause of mbtowc returns 0 when \0 */ - break; - case 0x07: - tc_printf("\\a"); - break; - case 0x08: - tc_printf("\\b"); - break; - case 0x09: - tc_printf("\\t"); - break; - case 0x0A: - tc_printf("\\n"); - break; - case 0x0B: - tc_printf("\\v"); - break; - case 0x0C: - tc_printf("\\f"); - break; - case 0x0D: - tc_printf("\\r"); - break; - default: - tc_printf("\\x%02lX", - (unsigned long int)dest); - break; - } - } - size -= length; - data += length; - } - } - else { - while (size-- > 0) { - tc_printf("\\x%02X", (unsigned char)*data); - data++; - } - } -} - -#if 0 - -void tc_print_fields(struct tnt_tuple *tu) -{ - struct tnt_iter ifl; - tnt_iter(&ifl, tu); - while (tnt_next(&ifl)) { - if (TNT_IFIELD_IDX(&ifl) != 0) - tc_printf(", "); - char *data = TNT_IFIELD_DATA(&ifl); - uint32_t size = TNT_IFIELD_SIZE(&ifl); - switch (size) { - case 4: - tc_printf("%"PRIu32, *((uint32_t*)data)); - break; - case 8: - tc_printf("%"PRIu64, *((uint64_t*)data)); - break; - default: - tc_printf("'"); - tc_print_string(data, size, 0); - tc_printf("'"); - } - } - if (ifl.status == TNT_ITER_FAIL) - tc_printf("<parsing error>"); - tnt_iter_free(&ifl); -} - -void tc_print_tuple(struct tnt_tuple *tu) -{ - tc_printf("["); - tc_print_fields(tu); - tc_printf("]\n"); -} - -void tc_print_list(struct tnt_list *l) -{ - struct tnt_iter it; - tnt_iter_list(&it, l); - while (tnt_next(&it)) { - struct tnt_tuple *tu = TNT_ILIST_TUPLE(&it); - tc_print_tuple(tu); - } - tnt_iter_free(&it); -} - -void tc_print_lua_field(char *data, uint32_t size, char string) -{ - if (string) - goto _string; - switch (size){ - case 4: - tc_printf("%"PRIu32, *((uint32_t*)data)); - break; - case 8: - tc_printf("%"PRIu64"LL", *((uint64_t*)data)); - break; - default: -_string: - tc_printf("\'"); - tc_print_string(data, size, 1); - tc_printf("\'"); - } -} - -void tc_print_lua_fields(struct tnt_tuple *tu) -{ - struct tnt_iter ifl; - tnt_iter(&ifl, tu); - while (tnt_next(&ifl)) { - if ((TNT_IFIELD_IDX(&ifl)) != 0) - tc_printf(", "); - char *data = TNT_IFIELD_DATA(&ifl); - uint32_t size = TNT_IFIELD_SIZE(&ifl); - tc_print_lua_field(data, size, tc.opt.str_instead_int); - } - if (ifl.status == TNT_ITER_FAIL) - tc_printf("<parsing error>"); - tnt_iter_free(&ifl); -} - -void tc_print_lua_tuple(struct tnt_tuple *tu) -{ - tc_printf("{"); - tc_print_lua_fields(tu); - tc_printf("}"); -} -#endif diff --git a/client/tarantool/print.h b/client/tarantool/print.h deleted file mode 100644 index 3c8a1aafcf..0000000000 --- a/client/tarantool/print.h +++ /dev/null @@ -1,47 +0,0 @@ -#ifndef TC_PRINT_H_INCLUDED -#define TC_PRINT_H_INCLUDED -/* - * 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. - */ - -void tc_printf(char *fmt, ...); -void tc_print_buf(char *buf, size_t size); - -void tc_print_string(char *data, uint32_t size, char lua); - -#if 0 -void tc_print_fields(struct tnt_tuple *tu); -void tc_print_tuple(struct tnt_tuple *tu); -void tc_print_list(struct tnt_list *l); - -void tc_print_lua_field(char *data, uint32_t size, char string); -void tc_print_lua_fields(struct tnt_tuple *tu); -void tc_print_lua_tuple(struct tnt_tuple *tu); -#endif - -#endif /* TC_PRINT_H_INCLUDED */ diff --git a/client/tarantool/print_snap.c b/client/tarantool/print_snap.c deleted file mode 100644 index f16735cafe..0000000000 --- a/client/tarantool/print_snap.c +++ /dev/null @@ -1,66 +0,0 @@ -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <inttypes.h> -#include <limits.h> -#include <stdint.h> - -#include <connector/c/include/tarantool/tnt.h> -#include <connector/c/include/tarantool/tnt_xlog.h> -#include <connector/c/include/tarantool/tnt_snapshot.h> - -#include "client/tarantool/tc_opt.h" -#include "client/tarantool/tc_admin.h" -#include "client/tarantool/tc.h" -#include "client/tarantool/tc_print.h" -#include "client/tarantool/tc_print_snap.h" -#include "client/tarantool/tc_query.h" -#include "client/tarantool/tc_store.h" - -extern struct tc tc; - -static void -tc_printer_snap_raw( struct tnt_log_row *row, - struct tnt_tuple *tu) -{ - if (tc.opt.raw_with_headers) { - fwrite(&tnt_log_marker_v11, - sizeof(tnt_log_marker_v11), 1, stdout); - } - fwrite(&(row->row_snap), sizeof(row->row_snap), 1, stdout); - fwrite(tu->data, tu->size, 1, stdout); -} -static void -tc_printer_snap_tarantool( struct tnt_log_row *row, - struct tnt_tuple *tu) -{ - tc_printf("space: %"PRIu32" ", - row->row_snap.space); - tc_print_tuple(tu); - -} -static void -tc_printer_snap_lua( struct tnt_log_row *row, - struct tnt_tuple *tu) -{ - tc_printf("lua box.insert(%"PRIu32", ", row->row_snap.space); - tc_print_lua_fields(tu); - tc_printf(")"); - if (tc.opt.delim_len > 0) - tc_printf("%s\n", tc.opt.delim); - else - tc_printf("\n"); -} - -tc_printerf_snap_t tc_print_getsnapcb(const char *name) -{ - if (name == NULL) - return tc_printer_snap_tarantool; - if (!strcasecmp(name, "tarantool")) - return tc_printer_snap_tarantool; - if (!strcasecmp(name, "raw")) - return tc_printer_snap_raw; - if (!strcasecmp(name, "lua")) - return tc_printer_snap_lua; - return NULL; -} diff --git a/client/tarantool/print_snap.h b/client/tarantool/print_snap.h deleted file mode 100644 index 2a661700cb..0000000000 --- a/client/tarantool/print_snap.h +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef TC_PRINT_SNAP_H_INCLUDED -#define TC_PRINT_SNAP_H_INCLUDED -/* - * 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. - */ - -typedef void (*tc_printerf_snap_t)(struct tnt_log_row *row, - struct tnt_tuple *tu); - -tc_printerf_snap_t tc_print_getsnapcb(const char *name); - -#endif /* TC_PRINT_SNAP_H_INCLUDED */ diff --git a/client/tarantool/print_xlog.c b/client/tarantool/print_xlog.c deleted file mode 100644 index 4422714a4f..0000000000 --- a/client/tarantool/print_xlog.c +++ /dev/null @@ -1,207 +0,0 @@ -/* - * 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 <stddef.h> -#include <stdlib.h> -#include <stdio.h> -#include <inttypes.h> -#include <strings.h> -#include <arpa/inet.h> -#include <netinet/in.h> - -#include <connector/c/include/tarantool/tnt.h> -#include <connector/c/include/tarantool/tnt_xlog.h> -#include <connector/c/include/tarantool/tnt_rpl.h> - -#include "client/tarantool/tc_opt.h" -#include "client/tarantool/tc_admin.h" -#include "client/tarantool/tc_print.h" -#include "client/tarantool/tc_print_xlog.h" -#include "client/tarantool/tc_query.h" -#include "client/tarantool/tc_print.h" -#include "client/tarantool/tc.h" - -extern struct tc tc; - -static void -tc_printer_xlog_raw(struct tnt_log_row *row, - struct tnt_request *r) -{ - if (tc.opt.raw_with_headers) { - fwrite(&tnt_log_marker_v11, - sizeof(tnt_log_marker_v11), 1, stdout); - } - fwrite(&(row->hdr), sizeof(row->hdr), 1, stdout); - fwrite(r->origin, r->origin_size, 1, stdout); -} - -static void -tc_printer_xlog_tarantool(struct tnt_log_row *row, - struct tnt_request *r) -{ - struct sockaddr_in *peer = (void *)&row->row.cookie; - tc_printf("%s, lsn: %"PRIu64", time: %lf, len: %"PRIu32", space: " - "%"PRIu32", cookie: %s:%d ", - tc_query_type(r->h.type), - row->hdr.lsn, - row->hdr.tm, - row->hdr.len, - r->r.insert.h.ns, - inet_ntoa(peer->sin_addr), - ntohs(peer->sin_port) - ); - switch (r->h.type) { - case TNT_OP_INSERT: - tc_print_tuple(&r->r.insert.t); - break; - case TNT_OP_DELETE: - case TNT_OP_DELETE_1_3: - tc_print_tuple(&r->r.del.t); - break; - case TNT_OP_UPDATE: - tc_print_tuple(&r->r.update.t); - break; - } -} - -static void -tc_printer_xlog_lua(struct tnt_log_row *row, - struct tnt_request *r) -{ - tc_printf("lua box."); - switch (r->h.type) { - case TNT_OP_INSERT: - if (r->r.insert.h.flags && TNT_FLAG_REPLACE == TNT_FLAG_REPLACE) - tc_printf("replace("); - else - tc_printf("insert("); - tc_printf("%"PRIu32", ", r->r.insert.h.ns); - tc_print_lua_fields(&r->r.insert.t); - break; - case TNT_OP_DELETE: - case TNT_OP_DELETE_1_3: - tc_printf("delete("); - tc_printf("%"PRIu32", ", r->r.del.h.ns); - tc_print_lua_tuple(&r->r.del.t); - break; - case TNT_OP_UPDATE: - tc_printf("update("); - tc_printf("%"PRIu32", ", r->r.update.h.ns); - tc_print_lua_tuple(&r->r.update.t); - tc_printf(", '"); - for (uint32_t i = 0; i < r->r.update.opc; i++) { - switch (r->r.update.opv[i].op) { - case TNT_UPDATE_ASSIGN: - tc_printf("=p"); - break; - case TNT_UPDATE_ADD: - tc_printf("+p"); - break; - case TNT_UPDATE_AND: - tc_printf("&p"); - break; - case TNT_UPDATE_XOR: - tc_printf("^p"); - break; - case TNT_UPDATE_OR: - tc_printf("|p"); - break; - case TNT_UPDATE_SPLICE: - tc_printf(":p"); - break; - case TNT_UPDATE_DELETE: - tc_printf("#p"); - break; - case TNT_UPDATE_INSERT: - tc_printf("!p"); - break; - } - } - tc_printf("'"); - for (uint32_t i = 0; i < r->r.update.opc; i++) { - tc_printf(", %"PRIu32, - r->r.update.opv[i].field); - switch (r->r.update.opv[i].op){ - case TNT_UPDATE_ADD: - case TNT_UPDATE_AND: - case TNT_UPDATE_XOR: - case TNT_UPDATE_OR: - tc_printf(", "); - tc_print_lua_field(r->r.update.opv[i].data, - r->r.update.opv[i].size, 0); - break; - case TNT_UPDATE_SPLICE: - tc_printf(", box.pack('ppp'"); - char *data = r->r.update.opv[i].data; - size_t pos = 1; - tc_printf(", %"PRId32, - *(int32_t *)(data + pos)); - pos += 5; - tc_printf(", %"PRId32", ", - *(int32_t *)(data + pos)); - pos += 4 + r->r.update.opv[i].size_enc_len; - tc_printf("\'"); - tc_print_string(data, - r->r.update.opv[i].size - pos, 1); - tc_printf("\'"); - tc_printf(")"); - break; - case TNT_UPDATE_DELETE: - tc_printf(", \'\'"); - break; - case TNT_UPDATE_INSERT: - case TNT_UPDATE_ASSIGN: - tc_printf(", "); - tc_print_lua_field(r->r.update.opv[i].data, - r->r.update.opv[i].size, - tc.opt.str_instead_int); - break; - } - } - break; - } - tc_printf(") -- %"PRIu64, row->hdr.lsn); - if (tc.opt.delim_len > 0) - tc_printf("%s\n", tc.opt.delim); - else - tc_printf("\n"); -} - -tc_printerf_xlog_t tc_print_getxlogcb(const char *name) -{ - if (name == NULL) - return tc_printer_xlog_tarantool; - if (!strcasecmp(name, "tarantool")) - return tc_printer_xlog_tarantool; - if (!strcasecmp(name, "raw")) - return tc_printer_xlog_raw; - if (!strcasecmp(name, "lua")) - return tc_printer_xlog_lua; - return NULL; -} diff --git a/client/tarantool/print_xlog.h b/client/tarantool/print_xlog.h deleted file mode 100644 index bc48fc9891..0000000000 --- a/client/tarantool/print_xlog.h +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef TC_PRINT_XLOG_H_INCLUDED -#define TC_PRINT_XLOG_H_INCLUDED -/* - * 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. - */ - -typedef void (*tc_printerf_xlog_t)(struct tnt_log_row *row, - struct tnt_request *r); - -tc_printerf_xlog_t tc_print_getxlogcb(const char *name); - -#endif /* TC_PRINT_XLOG_H_INCLUDED */ diff --git a/client/tarantool/query.c b/client/tarantool/query.c deleted file mode 100644 index 1e637f15ad..0000000000 --- a/client/tarantool/query.c +++ /dev/null @@ -1,150 +0,0 @@ - -/* - * 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 <lib/tarantool.h> - -#include "errcode.h" -#include <client/tarantool/opt.h> -#include <client/tarantool/main.h> -#include <client/tarantool/print.h> -#include <client/tarantool/query.h> - -extern struct tarantool_client tc; - -int tc_printer(char *reply, size_t size, void *ctx) -{ - (void)ctx; - (void)size; - tc_printf("%s", reply); - return 0; -} - -int tc_exec(char *q, tc_query_t cb, void *ctx) -{ - int rc = tb_conwrite(&tc.console, q, strlen(q)); - if (rc == -1) - return -1; - size_t size; - char *reply; - rc = tb_conread(&tc.console, &reply, &size); - if (rc == -1) - return -1; - rc = 0; - if (cb && reply) - rc = cb(reply, size, ctx); - free(reply); - return rc; -} - -#if 0 -char *tc_query_error(char *fmt, ...) { - char msg[256]; - va_list args; - va_start(args, fmt); - vsnprintf(msg, sizeof(msg), fmt, args); - va_end(args); - char *ptr = strdup(msg); - if (ptr == NULL) - tc_error("memory allocation failed"); - return ptr; -} - -char *tc_query_type(uint32_t type) { - switch (type) { - case TNT_OP_PING: return "Ping"; - case TNT_OP_INSERT: return "Insert"; - case TNT_OP_DELETE: return "Delete"; - case TNT_OP_DELETE_1_3: return "Delete_1_3"; - case TNT_OP_UPDATE: return "Update"; - case TNT_OP_SELECT: return "Select"; - case TNT_OP_CALL: return "Call"; - } - return "Unknown"; -} - -char *tc_query_op(struct tnt_reply *r) { - return tc_query_type(r->op); -} - -int tc_query_printer(struct tnt_reply *r, void *ptr, char **e) { - (void)ptr; - (void)e; - tc_printf("%s OK, %d rows affected\n", tc_query_op(r), - r->count); - tc_print_list(TNT_REPLY_LIST(r)); - return 0; -} - -int tc_query_foreach(tc_query_t cb, void *cba, char **e) -{ - int rc = -1; - struct tnt_iter i; - tnt_iter_reply(&i, tc.net); - while (tnt_next(&i)) { - struct tnt_reply *r = TNT_IREPLY_PTR(&i); - if (tnt_error(tc.net) != TNT_EOK) { - *e = tc_query_error("%s ERROR, %s", - tc_query_op(r), - tnt_strerror(tc.net)); - goto error; - } else if (r->code != 0) { - *e = tc_query_error("%s ERROR, %s (%s)", - tc_query_op(r), ((r->error) ? r->error : ""), - tnt_errcode_str(r->code >> 8)); - goto error; - } - /* invoking callback if supplied */ - if (cb) { - if (cb(r, cba, e) == -1) - goto error; - } - } - rc = (i.status == TNT_ITER_FAIL) ? -1 : 0; -error: - tnt_iter_free(&i); - return rc; -} - -int tc_query(char *q, char **e) { - int rc = tnt_query(tc.net, q, strlen(q), e); - if (rc == -1) - return -1; - rc = tnt_flush(tc.net); - if (rc < 0) { - char *ee = tnt_strerror(tc.net); - if (ee) { - *e = tc_query_error("%s", ee); - } - return -1; - } - return 0; -} -#endif - diff --git a/client/tarantool/query.h b/client/tarantool/query.h deleted file mode 100644 index 3b4046db46..0000000000 --- a/client/tarantool/query.h +++ /dev/null @@ -1,57 +0,0 @@ -#ifndef TC_QUERY_H_INCLUDED -#define TC_QUERY_H_INCLUDED -/* - * 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. - */ - -typedef int (*tc_query_t)(char *reply, size_t size, void *ctx); - -int tc_printer(char *r, size_t size, void *ctx); -int tc_exec(char *q, tc_query_t cb, void *ctx); - -static inline int -tc_query(char *q, void *cb) { - return tc_exec(q, (tc_query_t)cb, NULL); -} - -#if 0 -typedef int (*tc_query_t)(struct tnt_reply *r, void *ptr, char **e); - -char *tc_query_type(uint32_t type); - -int tc_query_printer(struct tnt_reply *r, void *ptr, char **e); -int tc_query_foreach(tc_query_t cb, void *cba, char **e); -int tc_query(char *q, char **e); - -struct tnt_reply; - -char *tc_query_error(char *fmt, ...); -char *tc_query_op(struct tnt_reply *r); -#endif - -#endif /* TC_QUERY_H_INCLUDED */ diff --git a/client/tarantool/store.c b/client/tarantool/store.c deleted file mode 100644 index 976621d4a3..0000000000 --- a/client/tarantool/store.c +++ /dev/null @@ -1,224 +0,0 @@ -/* - * 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 <lib/tarantool.h> - -#include <client/tarantool/opt.h> -#include <client/tarantool/main.h> -#include <client/tarantool/print.h> -#include <client/tarantool/query.h> -#include <client/tarantool/store.h> - -struct tarantool_client tc; - -typedef int (*tc_iter_t)(struct tbfile *f); - -static int tc_store_error(char *fmt, ...) { - char msg[256]; - va_list args; - va_start(args, fmt); - vsnprintf(msg, sizeof(msg), fmt, args); - va_end(args); - tc_printf("error: %s\n", msg); - return -1; -} - -static int tc_store_foreach(struct tbfile *f, tc_iter_t cb) -{ - int rc; - while ((rc = tb_filenext(f)) > 0) { - if (cb(f) == -1) - return -1; - } - if (rc < 0) - tc_store_error("parsing error: %s", tb_fileerror(f, rc)); - return rc; -} - -static int -tc_store_foreach_xlog(tc_iter_t cb) -{ - struct tbfile f; - int rc = tb_fileopen(&f, (char*)tc.opt.file); - if (rc < 0) - return 1; - rc = tc_store_foreach(&f, cb); - tb_fileclose(&f); - return rc; -} - -static int -tc_store_check_skip(struct tbfile *f) -{ -#if 0 - if (tc.opt.space_set) { - if (f->h.type == TNT_OP_CALL) - return 1; - uint32_t ns = *(uint32_t*)&r->r; - if (ns != tc.opt.space) - return 1; - } -#endif - if (tc.opt.lsn_from_set) { - if (f->h.lsn < tc.opt.lsn_from) - return 1; - } - if (tc.opt.lsn_to_set) { - if (f->h.lsn > tc.opt.lsn_to) - return 1; - } - return 0; -} - -static int tc_store_xlog_printer(struct tbfile *f) -{ - if (tc_store_check_skip(f)) - return 0; - /*((tc_printerf_xlog_t)tc.opt.xlog_printer)(&s->log.current, r);*/ - return 0; -} - -int tc_store_cat(void) -{ -#if 0 - enum tnt_log_type type = tnt_log_guess((char*)tc.opt.file); - if (type == TNT_LOG_NONE) - return 1; - int print_headers = tc.opt.raw && tc.opt.raw_with_headers; - if (print_headers) { - char *h = (type == TNT_LOG_SNAPSHOT ? - TNT_LOG_MAGIC_SNAP : TNT_LOG_MAGIC_XLOG); - fputs(h, stdout); - fputs(TNT_LOG_VERSION, stdout); - fputs("\n", stdout); - } -#endif - - int rc = tc_store_foreach_xlog(tc_store_xlog_printer); - -#if 0 - if (rc == 0 && print_headers) { - fwrite(&tnt_log_marker_eof_v11, - sizeof(tnt_log_marker_eof_v11), 1, stdout); -#endif - - return rc; -} - -#if 0 -static int -tc_store_snap_resender(struct tnt_iter *i) { - struct tnt_tuple *tu = TNT_ISTORAGE_TUPLE(i); - struct tnt_stream_snapshot *ss = - TNT_SSNAPSHOT_CAST(TNT_ISTORAGE_STREAM(i)); - if (tc.opt.space_set) { - if (ss->log.current.row_snap.space != tc.opt.space) - return 0; - } - if (tnt_insert(tc.net, ss->log.current.row_snap.space, - TNT_FLAG_ADD, tu) == -1) - return tc_store_error("failed to write request"); - char *e = NULL; - if (tc_query_foreach(NULL, NULL, &e) == -1) { - tc_store_error("%s", e); - free(e); - return -1; - } - return 0; -} - -static int -tc_store_xlog_resender(struct tnt_iter *i) { - struct tnt_request *r = TNT_IREQUEST_PTR(i); - if (tc_store_check_skip(i, r)) - return 0; - if (tc.net->write_request(tc.net, r) == -1) - return tc_store_error("failed to write request"); - char *e = NULL; - if (tc_query_foreach(NULL, NULL, &e) == -1) { - tc_store_error("%s", e); - free(e); - return -1; - } - return 0; -} - -int tc_store_play(void) -{ - enum tnt_log_type type = tnt_log_guess((char *)tc.opt.file); - if (type == TNT_LOG_NONE) - return 1; - int rc; - switch (type) { - case TNT_LOG_SNAPSHOT: - rc = tc_store_foreach_snap(tc_store_snap_resender); - break; - case TNT_LOG_XLOG: - rc = tc_store_foreach_xlog(tc_store_xlog_resender); - break; - case TNT_LOG_NONE: - rc = 1; - break; - default: - return -1; - } - return rc; -} - -static int tc_store_printer_from_rpl(struct tnt_iter *i) { - struct tnt_request *r = TNT_IREQUEST_PTR(i); - struct tnt_stream_rpl *s = - TNT_RPL_CAST(TNT_IREQUEST_STREAM(i)); - tc_store_print(&s->hdr, r); - return 0; -} - -int tc_store_remote(void) -{ - if (tc.opt.lsn == LLONG_MAX || - tc.opt.lsn == LLONG_MIN) { - tc_store_error("bad lsn number"); - return 1; - } - struct tnt_stream s; - tnt_rpl(&s); - tnt_rpl_attach(&s, tc.net); - int rc = 0; - if (tnt_rpl_open(&s, tc.opt.lsn) == -1) { - rc = 1; - goto done; - } - - if (tc_store_foreach_request(&s, tc_store_printer_from_rpl) == -1) - rc = 1; -done: - tnt_stream_free(&s); - return rc; -} -#endif diff --git a/client/tarantool/store.h b/client/tarantool/store.h deleted file mode 100644 index 901d007f94..0000000000 --- a/client/tarantool/store.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef TC_STORE_H_INCLUDED -#define TC_STORE_H_INCLUDED - -/* - * Copyright (C) 2012 Mail.RU - * - * 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 AUTHOR AND CONTRIBUTORS ``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 AUTHOR 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. - */ - -int tc_store_cat(void); -int tc_store_play(void); -int tc_store_remote(void); - -#endif /* TC_STORE_H_INCLUDED */ diff --git a/connector/CMakeLists.txt b/connector/CMakeLists.txt deleted file mode 100644 index 20bc4cc4b0..0000000000 --- a/connector/CMakeLists.txt +++ /dev/null @@ -1 +0,0 @@ -add_subdirectory(c) diff --git a/connector/c/CMakeLists.txt b/connector/c/CMakeLists.txt deleted file mode 100644 index c1e75e90e5..0000000000 --- a/connector/c/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ - -# -# library soname version -# -#set(LIBTNT_VERSION_MAJOR "1") -#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) -#add_subdirectory(tntrpl) -#add_subdirectory(include) - -add_subdirectory(tb) diff --git a/connector/c/README b/connector/c/README deleted file mode 100644 index 1a780e4e36..0000000000 --- a/connector/c/README +++ /dev/null @@ -1,9 +0,0 @@ - -.------------------------------. -| Tarantool C client libraries | -`------------------------------' - -tnt - tarantool iproto library -tntsql - tarantool sql library -tntnet - tarantool network io library -tntrpl - tarantool replication library diff --git a/connector/c/include/CMakeLists.txt b/connector/c/include/CMakeLists.txt deleted file mode 100644 index a47ec7c2e8..0000000000 --- a/connector/c/include/CMakeLists.txt +++ /dev/null @@ -1,6 +0,0 @@ - -# -# installation of tarantool C client library headers -# - -install(DIRECTORY tarantool DESTINATION include) diff --git a/connector/c/include/tarantool/tnt.h b/connector/c/include/tarantool/tnt.h deleted file mode 100644 index 8d66019063..0000000000 --- a/connector/c/include/tarantool/tnt.h +++ /dev/null @@ -1,60 +0,0 @@ -#ifndef TNT_H_INCLUDED -#define TNT_H_INCLUDED - -/* - * 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. - */ - -#ifdef __cplusplus -extern "C" { -#endif - -#include <stdint.h> -#include <stdarg.h> - -#include <tarantool/tnt_mem.h> -#include <tarantool/tnt_proto.h> -#include <tarantool/tnt_enc.h> -#include <tarantool/tnt_tuple.h> -#include <tarantool/tnt_request.h> -#include <tarantool/tnt_reply.h> -#include <tarantool/tnt_stream.h> -#include <tarantool/tnt_iter.h> -#include <tarantool/tnt_buf.h> -#include <tarantool/tnt_ping.h> -#include <tarantool/tnt_insert.h> -#include <tarantool/tnt_update.h> -#include <tarantool/tnt_delete.h> -#include <tarantool/tnt_call.h> -#include <tarantool/tnt_select.h> - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /* TNT_H_INCLUDED */ diff --git a/connector/c/include/tarantool/tnt_buf.h b/connector/c/include/tarantool/tnt_buf.h deleted file mode 100644 index 663bdd96dd..0000000000 --- a/connector/c/include/tarantool/tnt_buf.h +++ /dev/null @@ -1,49 +0,0 @@ -#ifndef TNT_BUF_H_INCLUDED -#define TNT_BUF_H_INCLUDED - -/* - * 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. - */ - -/* buffer stream object */ - -struct tnt_stream_buf { - char *data; /* buffer data */ - size_t size; /* buffer size */ - size_t rdoff; /* read offset */ -}; - -/* buffer stream accessors */ - -#define TNT_SBUF_CAST(S) ((struct tnt_stream_buf*)(S)->data) -#define TNT_SBUF_DATA(S) TNT_SBUF_CAST(S)->data -#define TNT_SBUF_SIZE(S) TNT_SBUF_CAST(S)->size - -struct tnt_stream *tnt_buf(struct tnt_stream *s); - -#endif /* TNT_BUF_H_INCLUDED */ diff --git a/connector/c/include/tarantool/tnt_call.h b/connector/c/include/tarantool/tnt_call.h deleted file mode 100644 index c1115abc7b..0000000000 --- a/connector/c/include/tarantool/tnt_call.h +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef TNT_CALL_H_INCLUDED -#define TNT_CALL_H_INCLUDED - -/* - * 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. - */ - -ssize_t tnt_call(struct tnt_stream *s, uint32_t flags, const char *proc, - struct tnt_tuple *args); - -#endif /* TNT_CALL_H_INCLUDED */ diff --git a/connector/c/include/tarantool/tnt_delete.h b/connector/c/include/tarantool/tnt_delete.h deleted file mode 100644 index 5056d7929e..0000000000 --- a/connector/c/include/tarantool/tnt_delete.h +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef TNT_DELETE_H_INCLUDED -#define TNT_DELETE_H_INCLUDED - -/* - * 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. - */ - -ssize_t tnt_delete(struct tnt_stream *s, uint32_t ns, uint32_t flags, - struct tnt_tuple *k); - -#endif /* TNT_DELETE_H_INCLUDED */ diff --git a/connector/c/include/tarantool/tnt_dir.h b/connector/c/include/tarantool/tnt_dir.h deleted file mode 100644 index 6e08b44104..0000000000 --- a/connector/c/include/tarantool/tnt_dir.h +++ /dev/null @@ -1,58 +0,0 @@ -#ifndef TNT_DIR_H_INCLUDED -#define TNT_DIR_H_INCLUDED - -/* - * 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. - */ - -enum tnt_dir_type { - TNT_DIR_XLOG, - TNT_DIR_SNAPSHOT -}; - -struct tnt_dir_file { - uint64_t lsn; - char *name; -}; - -struct tnt_dir { - enum tnt_dir_type type; - char *path; - struct tnt_dir_file *files; - int count; -}; - -void tnt_dir_init(struct tnt_dir *d, enum tnt_dir_type type); -void tnt_dir_free(struct tnt_dir *d); - -int tnt_dir_scan(struct tnt_dir *d, char *path); - -int tnt_dir_match_gt(struct tnt_dir *d, uint64_t *out); -int tnt_dir_match_inc(struct tnt_dir *d, uint64_t lsn, uint64_t *out); - -#endif diff --git a/connector/c/include/tarantool/tnt_enc.h b/connector/c/include/tarantool/tnt_enc.h deleted file mode 100644 index ad2c05835c..0000000000 --- a/connector/c/include/tarantool/tnt_enc.h +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef TNT_ENC_H_INCLUDED -#define TNT_ENC_H_INCLUDED - -/* - * 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. - */ - -int tnt_enc_size(uint32_t value); -int tnt_enc_read(const char *buf, uint32_t *value); -void tnt_enc_write(char *buf, uint32_t value); - -#endif /* TNT_ENC_H_INCLUDED */ diff --git a/connector/c/include/tarantool/tnt_insert.h b/connector/c/include/tarantool/tnt_insert.h deleted file mode 100644 index 842a29bf5e..0000000000 --- a/connector/c/include/tarantool/tnt_insert.h +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef TNT_INSERT_H_INCLUDED -#define TNT_INSERT_H_INCLUDED - -/* - * 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. - */ - -ssize_t -tnt_insert(struct tnt_stream *s, - uint32_t ns, uint32_t flags, struct tnt_tuple *kv); - -#endif /* TNT_INSERT_H_INCLUDED */ diff --git a/connector/c/include/tarantool/tnt_io.h b/connector/c/include/tarantool/tnt_io.h deleted file mode 100644 index ae9938c972..0000000000 --- a/connector/c/include/tarantool/tnt_io.h +++ /dev/null @@ -1,46 +0,0 @@ -#ifndef TNT_IO_H_INCLUDED -#define TNT_IO_H_INCLUDED - -/* - * 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. - */ - -enum tnt_error tnt_io_connect(struct tnt_stream_net *s, const char *host, int port); -void tnt_io_close(struct tnt_stream_net *s); - -ssize_t tnt_io_flush(struct tnt_stream_net *s); - -ssize_t tnt_io_send_raw(struct tnt_stream_net *s, const char *buf, size_t size, int all); -ssize_t tnt_io_sendv_raw(struct tnt_stream_net *s, struct iovec *iov, int count, int all); -ssize_t tnt_io_recv_raw(struct tnt_stream_net *s, char *buf, size_t size, int all); - -ssize_t tnt_io_send(struct tnt_stream_net *s, const char *buf, size_t size); -ssize_t tnt_io_sendv(struct tnt_stream_net *s, struct iovec *iov, int count); -ssize_t tnt_io_recv(struct tnt_stream_net *s, char *buf, size_t size); - -#endif /* TNT_IO_H_INCLUDED */ diff --git a/connector/c/include/tarantool/tnt_iob.h b/connector/c/include/tarantool/tnt_iob.h deleted file mode 100644 index 4939127a3f..0000000000 --- a/connector/c/include/tarantool/tnt_iob.h +++ /dev/null @@ -1,52 +0,0 @@ -#ifndef TNT_IOB_H_INCLUDED -#define TNT_IOB_H_INCLUDED - -/* - * 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. - */ - -typedef ssize_t (*tnt_iob_tx_t)(void *ptr, const char *buf, size_t size); -typedef ssize_t (*tnt_iob_txv_t)(void *ptr, struct iovec *iov, int count); - -struct tnt_iob { - char *buf; - size_t off; - size_t top; - size_t size; - tnt_iob_tx_t tx; - tnt_iob_txv_t txv; - void *ptr; -}; - -int tnt_iob_init(struct tnt_iob *iob, size_t size, - tnt_iob_tx_t tx, - tnt_iob_txv_t txv, void *ptr); - -void tnt_iob_free(struct tnt_iob *iob); - -#endif /* TNT_IOB_H_INCLUDED */ diff --git a/connector/c/include/tarantool/tnt_iter.h b/connector/c/include/tarantool/tnt_iter.h deleted file mode 100644 index 1437575a8a..0000000000 --- a/connector/c/include/tarantool/tnt_iter.h +++ /dev/null @@ -1,153 +0,0 @@ -#ifndef TNT_ITER_H_INCLUDED -#define TNT_ITER_H_INCLUDED - -/* - * 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. - */ - -/* tuple iterator type */ - -enum tnt_iter_type { - TNT_ITER_FIELD, - TNT_ITER_LIST, - TNT_ITER_REQUEST, - TNT_ITER_REPLY, - TNT_ITER_STORAGE -}; - -/* tuple field iterator */ - -struct tnt_iter_field { - struct tnt_tuple *tu; /* tuple pointer */ - char *fld_ptr; /* current iteration offset */ - char *fld_ptr_prev; /* prev iteration offset */ - uint32_t fld_index; /* current field index */ - uint32_t fld_size; /* current field size */ - int fld_esize; /* current field encoding size */ - char *fld_data; /* current field data */ -}; - -/* tuple field iterator accessors */ - -#define TNT_IFIELD(I) (&(I)->data.field) -#define TNT_IFIELD_TUPLE(I) TNT_IFIELD(I)->tu -#define TNT_IFIELD_IDX(I) TNT_IFIELD(I)->fld_index -#define TNT_IFIELD_DATA(I) TNT_IFIELD(I)->fld_data -#define TNT_IFIELD_SIZE(I) TNT_IFIELD(I)->fld_size - -/* list iterator */ - -struct tnt_iter_list { - struct tnt_list *l; /* list pointer */ - struct tnt_tuple *tu; /* current tuple pointer */ - uint32_t tu_index; /* current tuple index */ -}; - -/* list iterator accessors */ - -#define TNT_ILIST(I) (&(I)->data.list) -#define TNT_ILIST_TUPLE(I) TNT_ILIST(I)->tu -#define TNT_ILIST_INDEX(I) TNT_ILIST(I)->tu_index - -/* request iterator */ - -struct tnt_iter_request { - struct tnt_stream *s; /* stream pointer */ - struct tnt_request r; /* current request */ -}; - -/* request iterator accessors */ - -#define TNT_IREQUEST(I) (&(I)->data.request) -#define TNT_IREQUEST_PTR(I) &TNT_IREQUEST(I)->r -#define TNT_IREQUEST_STREAM(I) TNT_IREQUEST(I)->s - -/* storage iterator */ - -struct tnt_iter_storage { - struct tnt_stream *s; /* stream pointer */ - struct tnt_tuple t; /* current fetched tuple */ -}; - -/* request iterator accessors */ - -#define TNT_ISTORAGE(I) (&(I)->data.storage) -#define TNT_ISTORAGE_TUPLE(I) &TNT_ISTORAGE(I)->t -#define TNT_ISTORAGE_STREAM(I) TNT_ISTORAGE(I)->s - -/* reply iterator */ - -struct tnt_iter_reply { - struct tnt_stream *s; /* stream pointer */ - struct tnt_reply r; /* current reply */ -}; - -/* reply iterator accessors */ - -#define TNT_IREPLY(I) (&(I)->data.reply) -#define TNT_IREPLY_PTR(I) &TNT_IREPLY(I)->r - -enum tnt_iter_status { - TNT_ITER_OK, - TNT_ITER_FAIL -}; - -/* common iterator object */ - -struct tnt_iter { - enum tnt_iter_type type; - enum tnt_iter_status status; - int alloc; - /* interface callbacks */ - int (*next)(struct tnt_iter *iter); - void (*rewind)(struct tnt_iter *iter); - void (*free)(struct tnt_iter *iter); - /* iterator data */ - union { - struct tnt_iter_field field; - struct tnt_iter_list list; - struct tnt_iter_request request; - struct tnt_iter_reply reply; - struct tnt_iter_storage storage; - } data; -}; - -struct tnt_iter *tnt_iter(struct tnt_iter *i, struct tnt_tuple *t); -struct tnt_iter *tnt_iter_list(struct tnt_iter *i, struct tnt_list *l); -struct tnt_iter *tnt_iter_request(struct tnt_iter *i, struct tnt_stream *s); -struct tnt_iter *tnt_iter_reply(struct tnt_iter *i, struct tnt_stream *s); -struct tnt_iter *tnt_iter_storage(struct tnt_iter *i, struct tnt_stream *s); - -void tnt_iter_free(struct tnt_iter *i); - -int tnt_next(struct tnt_iter *i); -void tnt_rewind(struct tnt_iter *i); - -struct tnt_iter *tnt_field(struct tnt_iter *i, struct tnt_tuple *t, uint32_t index); - -#endif /* TNT_ITER_H_INCLUDED */ diff --git a/connector/c/include/tarantool/tnt_lex.h b/connector/c/include/tarantool/tnt_lex.h deleted file mode 100644 index 6c568ddae8..0000000000 --- a/connector/c/include/tarantool/tnt_lex.h +++ /dev/null @@ -1,118 +0,0 @@ -#ifndef TNT_LEX_H_INCLUDED -#define TNT_LEX_H_INCLUDED - -/* - * 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. - */ - -/* token id's */ - -enum { - TNT_TK_ERROR = -1, - TNT_TK_EOF = 0, - TNT_TK_NONE = 1000, - TNT_TK_NUM32, - TNT_TK_NUM64, - TNT_TK_ID, - TNT_TK_KEY, - TNT_TK_TABLE, - TNT_TK_PUNCT, - TNT_TK_STRING, - TNT_TK_PING, - TNT_TK_UPDATE, - TNT_TK_SET, - TNT_TK_WHERE, - TNT_TK_SPLICE, - TNT_TK_DELETE, - TNT_TK_FROM, - TNT_TK_INSERT, - TNT_TK_REPLACE, - TNT_TK_INTO, - TNT_TK_VALUES, - TNT_TK_SELECT, - TNT_TK_LIMIT, - TNT_TK_CALL, - TNT_TK_OR, - TNT_TK_AND, - TNT_TK_CUSTOM = 2000 -}; - -/* keyword descriptor */ - -struct tnt_lex_keyword { - char *name; - int size; - int tk; -}; - -/* token object */ - -struct tnt_tk { - int tk; - union { - int32_t i32; - int64_t i64; - struct tnt_utf8 s; - } v; - int line, col; - SLIST_ENTRY(tnt_tk) next; - STAILQ_ENTRY(tnt_tk) nextq; -}; - -/* token object accessors */ - -#define TNT_TK_S(TK) (&(TK)->v.s) -#define TNT_TK_I32(TK) ((TK)->v.i32) -#define TNT_TK_I64(TK) ((TK)->v.i64) - -/* lexer object */ - -struct tnt_lex { - struct tnt_utf8 buf; - struct tnt_lex_keyword *keywords; - size_t pos; - int line, col; - int count; - SLIST_HEAD(,tnt_tk) stack; - int countq; - STAILQ_HEAD(,tnt_tk) q; - bool idonly; - char *error; -}; - -bool tnt_lex_init(struct tnt_lex *l, struct tnt_lex_keyword *keywords, - unsigned char *buf, size_t size); -void tnt_lex_free(struct tnt_lex *l); - -char *tnt_lex_nameof(struct tnt_lex *l, int tk); -void tnt_lex_idonly(struct tnt_lex *l, bool on); - -void tnt_lex_push(struct tnt_lex *l, struct tnt_tk *tk); -int tnt_lex(struct tnt_lex *l, struct tnt_tk **tk); - -#endif /* TNT_LEX_H_INCLUDED */ diff --git a/connector/c/include/tarantool/tnt_log.h b/connector/c/include/tarantool/tnt_log.h deleted file mode 100644 index 194a03215f..0000000000 --- a/connector/c/include/tarantool/tnt_log.h +++ /dev/null @@ -1,119 +0,0 @@ -#ifndef TNT_LOG_H_INCLUDED -#define TNT_LOG_H_INCLUDED - -/* - * 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. - */ - -#define TNT_LOG_MAGIC_XLOG "XLOG\n" -#define TNT_LOG_MAGIC_SNAP "SNAP\n" -#define TNT_LOG_VERSION "0.12\n" - -enum tnt_log_error { - TNT_LOG_EOK, - TNT_LOG_EFAIL, - TNT_LOG_EMEMORY, - TNT_LOG_ETYPE, - TNT_LOG_EVERSION, - TNT_LOG_ECORRUPT, - TNT_LOG_ESYSTEM, - TNT_LOG_LAST -}; - -struct tnt_log_header_v11 { - uint32_t crc32_hdr; - uint64_t lsn; - double tm; - uint32_t len; - uint32_t crc32_data; -} __attribute__((packed)); - -struct tnt_log_row_v11 { - uint16_t tag; - uint64_t cookie; - uint16_t op; -} __attribute__((packed)); - -struct tnt_log_row_snap_v11 { - uint16_t tag; - uint64_t cookie; - uint32_t space; - uint32_t tuple_size; - uint32_t data_size; -} __attribute__((packed)); - -enum tnt_log_type { - TNT_LOG_NONE, - TNT_LOG_XLOG, - TNT_LOG_SNAPSHOT -}; - -union tnt_log_value { - struct tnt_request r; - struct tnt_tuple t; -}; - -struct tnt_log_row { - struct tnt_log_header_v11 hdr; - struct tnt_log_row_v11 row; - struct tnt_log_row_snap_v11 row_snap; - union tnt_log_value *value; -}; - -struct tnt_log { - enum tnt_log_type type; - FILE *fd; - off_t current_offset; - off_t offset; - int (*read)(struct tnt_log *l, char **buf, uint32_t *size); - int (*process)(struct tnt_log *l, char *buf, uint32_t size, - union tnt_log_value *value); - struct tnt_log_row current; - union tnt_log_value current_value; - enum tnt_log_error error; - int errno_; -}; - -extern const uint32_t tnt_log_marker_v11; -extern const uint32_t tnt_log_marker_eof_v11; - -enum tnt_log_type tnt_log_guess(char *file); - -enum tnt_log_error -tnt_log_open(struct tnt_log *l, char *file, enum tnt_log_type type); -int tnt_log_seek(struct tnt_log *l, off_t offset); -void tnt_log_close(struct tnt_log *l); - -struct tnt_log_row *tnt_log_next(struct tnt_log *l); -struct tnt_log_row *tnt_log_next_to(struct tnt_log *l, union tnt_log_value *value); - -enum tnt_log_error tnt_log_error(struct tnt_log *l); -char *tnt_log_strerror(struct tnt_log *l); -int tnt_log_errno(struct tnt_log *l); - -#endif /* TNT_LOG_H_INCLUDED */ diff --git a/connector/c/include/tarantool/tnt_mem.h b/connector/c/include/tarantool/tnt_mem.h deleted file mode 100644 index fcad24efb7..0000000000 --- a/connector/c/include/tarantool/tnt_mem.h +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef TNT_MEM_H_INCLUDED -#define TNT_MEM_H_INCLUDED - -/* - * 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. - */ - -typedef void *(tnt_allocator_t)(void *ptr, size_t size); - -void *tnt_mem_init(tnt_allocator_t alloc); -void *tnt_mem_alloc(size_t size); -void *tnt_mem_realloc(void *ptr, size_t size); -char *tnt_mem_dup(char *sz); -void tnt_mem_free(void *ptr); - -#endif /* TNT_MEM_H_INCLUDED */ diff --git a/connector/c/include/tarantool/tnt_net.h b/connector/c/include/tarantool/tnt_net.h deleted file mode 100644 index 2308aeeb05..0000000000 --- a/connector/c/include/tarantool/tnt_net.h +++ /dev/null @@ -1,89 +0,0 @@ -#ifndef TNT_NET_H_INCLUDED -#define TNT_NET_H_INCLUDED - -/* - * 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. - */ - -#ifdef __cplusplus -extern "C" { -#endif - -#include <stdint.h> -#include <stdarg.h> - -#include <sys/types.h> -#include <sys/time.h> - -#include <tarantool/tnt_opt.h> -#include <tarantool/tnt_iob.h> - -enum tnt_error { - TNT_EOK, - TNT_EFAIL, - TNT_EMEMORY, - TNT_ESYSTEM, - TNT_EBIG, - TNT_ESIZE, - TNT_ERESOLVE, - TNT_ETMOUT, - TNT_EBADVAL, - TNT_LAST -}; - -struct tnt_stream_net { - struct tnt_opt opt; - int connected; - int fd; - struct tnt_iob sbuf; - struct tnt_iob rbuf; - enum tnt_error error; - int errno_; -}; - -#define TNT_SNET_CAST(S) ((struct tnt_stream_net*)(S)->data) - -struct tnt_stream *tnt_net(struct tnt_stream *s); -int tnt_set(struct tnt_stream *s, int opt, ...); -int tnt_init(struct tnt_stream *s); - -int tnt_connect(struct tnt_stream *s); -void tnt_close(struct tnt_stream *s); - -ssize_t tnt_flush(struct tnt_stream *s); -int tnt_fd(struct tnt_stream *s); - -enum tnt_error tnt_error(struct tnt_stream *s); -char *tnt_strerror(struct tnt_stream *s); -int tnt_errno(struct tnt_stream *s); - -#ifdef __cplusplus -} -#endif - -#endif /* TNT_NET_H_INCLUDED */ diff --git a/connector/c/include/tarantool/tnt_opt.h b/connector/c/include/tarantool/tnt_opt.h deleted file mode 100644 index 1889eb313d..0000000000 --- a/connector/c/include/tarantool/tnt_opt.h +++ /dev/null @@ -1,69 +0,0 @@ -#ifndef TNT_OPT_H_INCLUDED -#define TNT_OPT_H_INCLUDED - -/* - * 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. - */ - -enum tnt_opt_type { - TNT_OPT_HOSTNAME, - TNT_OPT_PORT, - TNT_OPT_TMOUT_CONNECT, - TNT_OPT_TMOUT_RECV, - TNT_OPT_TMOUT_SEND, - TNT_OPT_SEND_CB, - TNT_OPT_SEND_CBV, - TNT_OPT_SEND_CB_ARG, - TNT_OPT_SEND_BUF, - TNT_OPT_RECV_CB, - TNT_OPT_RECV_CB_ARG, - TNT_OPT_RECV_BUF -}; - -struct tnt_opt { - char *hostname; - int port; - struct timeval tmout_connect; - struct timeval tmout_recv; - struct timeval tmout_send; - void *send_cb; - void *send_cbv; - void *send_cb_arg; - int send_buf; - void *recv_cb; - void *recv_cb_arg; - int recv_buf; -}; - -void tnt_opt_init(struct tnt_opt *opt); -void tnt_opt_free(struct tnt_opt *opt); - -int -tnt_opt_set(struct tnt_opt *opt, enum tnt_opt_type name, va_list args); - -#endif /* TNT_OPT_H_INCLUDED */ diff --git a/connector/c/include/tarantool/tnt_ping.h b/connector/c/include/tarantool/tnt_ping.h deleted file mode 100644 index 49fc52827c..0000000000 --- a/connector/c/include/tarantool/tnt_ping.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef TNT_PING_H_INCLUDED -#define TNT_PING_H_INCLUDED - -/* - * 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. - */ - -ssize_t tnt_ping(struct tnt_stream *s); - -#endif /* TNT_PING_H_INCLUDED */ diff --git a/connector/c/include/tarantool/tnt_proto.h b/connector/c/include/tarantool/tnt_proto.h deleted file mode 100644 index f30f84368a..0000000000 --- a/connector/c/include/tarantool/tnt_proto.h +++ /dev/null @@ -1,83 +0,0 @@ -#ifndef TNT_PROTO_H_INCLUDED -#define TNT_PROTO_H_INCLUDED - -/* - * 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. - */ - -#define TNT_OP_INSERT 13 -#define TNT_OP_SELECT 17 -#define TNT_OP_UPDATE 19 -#define TNT_OP_DELETE_1_3 20 -#define TNT_OP_DELETE 21 -#define TNT_OP_CALL 22 -#define TNT_OP_PING 65280 - -#define TNT_FLAG_RETURN 0x01 -#define TNT_FLAG_ADD 0x02 -#define TNT_FLAG_REPLACE 0x04 -#define TNT_FLAG_BOX_QUIET 0x08 -#define TNT_FLAG_NOT_STORE 0x10 - -struct tnt_header { - uint32_t type; - uint32_t len; - uint32_t reqid; -}; - -struct tnt_header_insert { - uint32_t ns; - uint32_t flags; -}; - -struct tnt_header_delete_1_3 { - uint32_t ns; -}; - -struct tnt_header_delete { - uint32_t ns; - uint32_t flags; -}; - -struct tnt_header_update { - uint32_t ns; - uint32_t flags; -}; - -struct tnt_header_call { - uint32_t flags; -}; - -struct tnt_header_select { - uint32_t ns; - uint32_t index; - uint32_t offset; - uint32_t limit; -}; - -#endif /* TNT_PROTO_H_INCLUDED */ diff --git a/connector/c/include/tarantool/tnt_queue.h b/connector/c/include/tarantool/tnt_queue.h deleted file mode 100644 index beb40701bc..0000000000 --- a/connector/c/include/tarantool/tnt_queue.h +++ /dev/null @@ -1,553 +0,0 @@ -/*- - * Copyright (c) 1991, 1993 - * The Regents of the University of California. All rights reserved. - * - * 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. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 THE REGENTS 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. - * - * @(#)queue.h 8.5 (Berkeley) 8/20/94 - * $FreeBSD: src/sys/sys/queue.h,v 1.60.2.1 2005/08/16 22:41:39 phk Exp $ - */ - -#ifndef _SYS_QUEUE_H_ -#define _SYS_QUEUE_H_ - -#include <sys/cdefs.h> - -/* - * This file defines four types of data structures: singly-linked lists, - * singly-linked tail queues, lists and tail queues. - * - * A singly-linked list is headed by a single forward pointer. The elements - * are singly linked for minimum space and pointer manipulation overhead at - * the expense of O(n) removal for arbitrary elements. New elements can be - * added to the list after an existing element or at the head of the list. - * Elements being removed from the head of the list should use the explicit - * macro for this purpose for optimum efficiency. A singly-linked list may - * only be traversed in the forward direction. Singly-linked lists are ideal - * for applications with large datasets and few or no removals or for - * implementing a LIFO queue. - * - * A singly-linked tail queue is headed by a pair of pointers, one to the - * head of the list and the other to the tail of the list. The elements are - * singly linked for minimum space and pointer manipulation overhead at the - * expense of O(n) removal for arbitrary elements. New elements can be added - * to the list after an existing element, at the head of the list, or at the - * end of the list. Elements being removed from the head of the tail queue - * should use the explicit macro for this purpose for optimum efficiency. - * A singly-linked tail queue may only be traversed in the forward direction. - * Singly-linked tail queues are ideal for applications with large datasets - * and few or no removals or for implementing a FIFO queue. - * - * A list is headed by a single forward pointer (or an array of forward - * pointers for a hash table header). The elements are doubly linked - * so that an arbitrary element can be removed without a need to - * traverse the list. New elements can be added to the list before - * or after an existing element or at the head of the list. A list - * may only be traversed in the forward direction. - * - * A tail queue is headed by a pair of pointers, one to the head of the - * list and the other to the tail of the list. The elements are doubly - * linked so that an arbitrary element can be removed without a need to - * traverse the list. New elements can be added to the list before or - * after an existing element, at the head of the list, or at the end of - * the list. A tail queue may be traversed in either direction. - * - * For details on the use of these macros, see the queue(3) manual page. - * - * - * SLIST LIST STAILQ TAILQ - * _HEAD + + + + - * _HEAD_INITIALIZER + + + + - * _ENTRY + + + + - * _INIT + + + + - * _EMPTY + + + + - * _FIRST + + + + - * _NEXT + + + + - * _PREV - - - + - * _LAST - - + + - * _FOREACH + + + + - * _FOREACH_SAFE + + + + - * _FOREACH_REVERSE - - - + - * _FOREACH_REVERSE_SAFE - - - + - * _INSERT_HEAD + + + + - * _INSERT_BEFORE - + - + - * _INSERT_AFTER + + + + - * _INSERT_TAIL - - + + - * _CONCAT - - + + - * _REMOVE_HEAD + - + - - * _REMOVE + + + + - * - */ -#define QUEUE_MACRO_DEBUG 0 -#if QUEUE_MACRO_DEBUG -/* Store the last 2 places the queue element or head was altered */ -struct qm_trace { - char * lastfile; - int lastline; - char * prevfile; - int prevline; -}; - -#define TRACEBUF struct qm_trace trace; -#define TRASHIT(x) do {(x) = (void *)-1;} while (0) - -#define QMD_TRACE_HEAD(head) do { \ - (head)->trace.prevline = (head)->trace.lastline; \ - (head)->trace.prevfile = (head)->trace.lastfile; \ - (head)->trace.lastline = __LINE__; \ - (head)->trace.lastfile = __FILE__; \ -} while (0) - -#define QMD_TRACE_ELEM(elem) do { \ - (elem)->trace.prevline = (elem)->trace.lastline; \ - (elem)->trace.prevfile = (elem)->trace.lastfile; \ - (elem)->trace.lastline = __LINE__; \ - (elem)->trace.lastfile = __FILE__; \ -} while (0) - -#else -#define QMD_TRACE_ELEM(elem) -#define QMD_TRACE_HEAD(head) -#define TRACEBUF -#define TRASHIT(x) -#endif /* QUEUE_MACRO_DEBUG */ - -/* - * Singly-linked List declarations. - */ -#define SLIST_HEAD(name, type) \ -struct name { \ - struct type *slh_first; /* first element */ \ -} - -#define SLIST_HEAD_INITIALIZER(head) \ - { NULL } - -#define SLIST_ENTRY(type) \ -struct { \ - struct type *sle_next; /* next element */ \ -} - -/* - * Singly-linked List functions. - */ -#define SLIST_EMPTY(head) ((head)->slh_first == NULL) - -#define SLIST_FIRST(head) ((head)->slh_first) - -#define SLIST_FOREACH(var, head, field) \ - for ((var) = SLIST_FIRST((head)); \ - (var); \ - (var) = SLIST_NEXT((var), field)) - -#define SLIST_FOREACH_SAFE(var, head, field, tvar) \ - for ((var) = SLIST_FIRST((head)); \ - (var) && ((tvar) = SLIST_NEXT((var), field), 1); \ - (var) = (tvar)) - -#define SLIST_FOREACH_PREVPTR(var, varp, head, field) \ - for ((varp) = &SLIST_FIRST((head)); \ - ((var) = *(varp)) != NULL; \ - (varp) = &SLIST_NEXT((var), field)) - -#define SLIST_INIT(head) do { \ - SLIST_FIRST((head)) = NULL; \ -} while (0) - -#define SLIST_INSERT_AFTER(slistelm, elm, field) do { \ - SLIST_NEXT((elm), field) = SLIST_NEXT((slistelm), field); \ - SLIST_NEXT((slistelm), field) = (elm); \ -} while (0) - -#define SLIST_INSERT_HEAD(head, elm, field) do { \ - SLIST_NEXT((elm), field) = SLIST_FIRST((head)); \ - SLIST_FIRST((head)) = (elm); \ -} while (0) - -#define SLIST_NEXT(elm, field) ((elm)->field.sle_next) - -#define SLIST_REMOVE(head, elm, type, field) do { \ - if (SLIST_FIRST((head)) == (elm)) { \ - SLIST_REMOVE_HEAD((head), field); \ - } \ - else { \ - struct type *curelm = SLIST_FIRST((head)); \ - while (SLIST_NEXT(curelm, field) != (elm)) \ - curelm = SLIST_NEXT(curelm, field); \ - SLIST_NEXT(curelm, field) = \ - SLIST_NEXT(SLIST_NEXT(curelm, field), field); \ - } \ -} while (0) - -#define SLIST_REMOVE_HEAD(head, field) do { \ - SLIST_FIRST((head)) = SLIST_NEXT(SLIST_FIRST((head)), field); \ -} while (0) - -/* - * Singly-linked Tail queue declarations. - */ -#define STAILQ_HEAD(name, type) \ -struct name { \ - struct type *stqh_first;/* first element */ \ - struct type **stqh_last;/* addr of last next element */ \ -} - -#define STAILQ_HEAD_INITIALIZER(head) \ - { NULL, &(head).stqh_first } - -#define STAILQ_ENTRY(type) \ -struct { \ - struct type *stqe_next; /* next element */ \ -} - -/* - * Singly-linked Tail queue functions. - */ -#define STAILQ_CONCAT(head1, head2) do { \ - if (!STAILQ_EMPTY((head2))) { \ - *(head1)->stqh_last = (head2)->stqh_first; \ - (head1)->stqh_last = (head2)->stqh_last; \ - STAILQ_INIT((head2)); \ - } \ -} while (0) - -#define STAILQ_EMPTY(head) ((head)->stqh_first == NULL) - -#define STAILQ_FIRST(head) ((head)->stqh_first) - -#define STAILQ_FOREACH(var, head, field) \ - for((var) = STAILQ_FIRST((head)); \ - (var); \ - (var) = STAILQ_NEXT((var), field)) - - -#define STAILQ_FOREACH_SAFE(var, head, field, tvar) \ - for ((var) = STAILQ_FIRST((head)); \ - (var) && ((tvar) = STAILQ_NEXT((var), field), 1); \ - (var) = (tvar)) - -#define STAILQ_INIT(head) do { \ - STAILQ_FIRST((head)) = NULL; \ - (head)->stqh_last = &STAILQ_FIRST((head)); \ -} while (0) - -#define STAILQ_INSERT_AFTER(head, tqelm, elm, field) do { \ - if ((STAILQ_NEXT((elm), field) = STAILQ_NEXT((tqelm), field)) == NULL)\ - (head)->stqh_last = &STAILQ_NEXT((elm), field); \ - STAILQ_NEXT((tqelm), field) = (elm); \ -} while (0) - -#define STAILQ_INSERT_HEAD(head, elm, field) do { \ - if ((STAILQ_NEXT((elm), field) = STAILQ_FIRST((head))) == NULL) \ - (head)->stqh_last = &STAILQ_NEXT((elm), field); \ - STAILQ_FIRST((head)) = (elm); \ -} while (0) - -#define STAILQ_INSERT_TAIL(head, elm, field) do { \ - STAILQ_NEXT((elm), field) = NULL; \ - *(head)->stqh_last = (elm); \ - (head)->stqh_last = &STAILQ_NEXT((elm), field); \ -} while (0) - -#define STAILQ_LAST(head, type, field) \ - (STAILQ_EMPTY((head)) ? \ - NULL : \ - ((struct type *) \ - ((char *)((head)->stqh_last) - __offsetof(struct type, field)))) - -#define STAILQ_NEXT(elm, field) ((elm)->field.stqe_next) - -#define STAILQ_REMOVE(head, elm, type, field) do { \ - if (STAILQ_FIRST((head)) == (elm)) { \ - STAILQ_REMOVE_HEAD((head), field); \ - } \ - else { \ - struct type *curelm = STAILQ_FIRST((head)); \ - while (STAILQ_NEXT(curelm, field) != (elm)) \ - curelm = STAILQ_NEXT(curelm, field); \ - if ((STAILQ_NEXT(curelm, field) = \ - STAILQ_NEXT(STAILQ_NEXT(curelm, field), field)) == NULL)\ - (head)->stqh_last = &STAILQ_NEXT((curelm), field);\ - } \ -} while (0) - -#define STAILQ_REMOVE_HEAD(head, field) do { \ - if ((STAILQ_FIRST((head)) = \ - STAILQ_NEXT(STAILQ_FIRST((head)), field)) == NULL) \ - (head)->stqh_last = &STAILQ_FIRST((head)); \ -} while (0) - -#define STAILQ_REMOVE_HEAD_UNTIL(head, elm, field) do { \ - if ((STAILQ_FIRST((head)) = STAILQ_NEXT((elm), field)) == NULL) \ - (head)->stqh_last = &STAILQ_FIRST((head)); \ -} while (0) - -/* - * List declarations. - */ -#define LIST_HEAD(name, type) \ -struct name { \ - struct type *lh_first; /* first element */ \ -} - -#define LIST_HEAD_INITIALIZER(head) \ - { NULL } - -#define LIST_ENTRY(type) \ -struct { \ - struct type *le_next; /* next element */ \ - struct type **le_prev; /* address of previous next element */ \ -} - -/* - * List functions. - */ - -#define LIST_EMPTY(head) ((head)->lh_first == NULL) - -#define LIST_FIRST(head) ((head)->lh_first) - -#define LIST_FOREACH(var, head, field) \ - for ((var) = LIST_FIRST((head)); \ - (var); \ - (var) = LIST_NEXT((var), field)) - -#define LIST_FOREACH_SAFE(var, head, field, tvar) \ - for ((var) = LIST_FIRST((head)); \ - (var) && ((tvar) = LIST_NEXT((var), field), 1); \ - (var) = (tvar)) - -#define LIST_INIT(head) do { \ - LIST_FIRST((head)) = NULL; \ -} while (0) - -#define LIST_INSERT_AFTER(listelm, elm, field) do { \ - if ((LIST_NEXT((elm), field) = LIST_NEXT((listelm), field)) != NULL)\ - LIST_NEXT((listelm), field)->field.le_prev = \ - &LIST_NEXT((elm), field); \ - LIST_NEXT((listelm), field) = (elm); \ - (elm)->field.le_prev = &LIST_NEXT((listelm), field); \ -} while (0) - -#define LIST_INSERT_BEFORE(listelm, elm, field) do { \ - (elm)->field.le_prev = (listelm)->field.le_prev; \ - LIST_NEXT((elm), field) = (listelm); \ - *(listelm)->field.le_prev = (elm); \ - (listelm)->field.le_prev = &LIST_NEXT((elm), field); \ -} while (0) - -#define LIST_INSERT_HEAD(head, elm, field) do { \ - if ((LIST_NEXT((elm), field) = LIST_FIRST((head))) != NULL) \ - LIST_FIRST((head))->field.le_prev = &LIST_NEXT((elm), field);\ - LIST_FIRST((head)) = (elm); \ - (elm)->field.le_prev = &LIST_FIRST((head)); \ -} while (0) - -#define LIST_NEXT(elm, field) ((elm)->field.le_next) - -#define LIST_REMOVE(elm, field) do { \ - if (LIST_NEXT((elm), field) != NULL) \ - LIST_NEXT((elm), field)->field.le_prev = \ - (elm)->field.le_prev; \ - *(elm)->field.le_prev = LIST_NEXT((elm), field); \ -} while (0) - -/* - * Tail queue declarations. - */ -#define TAILQ_HEAD(name, type) \ -struct name { \ - struct type *tqh_first; /* first element */ \ - struct type **tqh_last; /* addr of last next element */ \ - TRACEBUF \ -} - -#define TAILQ_HEAD_INITIALIZER(head) \ - { NULL, &(head).tqh_first } - -#define TAILQ_ENTRY(type) \ -struct { \ - struct type *tqe_next; /* next element */ \ - struct type **tqe_prev; /* address of previous next element */ \ - TRACEBUF \ -} - -/* - * Tail queue functions. - */ -#define TAILQ_CONCAT(head1, head2, field) do { \ - if (!TAILQ_EMPTY(head2)) { \ - *(head1)->tqh_last = (head2)->tqh_first; \ - (head2)->tqh_first->field.tqe_prev = (head1)->tqh_last; \ - (head1)->tqh_last = (head2)->tqh_last; \ - TAILQ_INIT((head2)); \ - QMD_TRACE_HEAD(head1); \ - QMD_TRACE_HEAD(head2); \ - } \ -} while (0) - -#define TAILQ_EMPTY(head) ((head)->tqh_first == NULL) - -#define TAILQ_FIRST(head) ((head)->tqh_first) - -#define TAILQ_FOREACH(var, head, field) \ - for ((var) = TAILQ_FIRST((head)); \ - (var); \ - (var) = TAILQ_NEXT((var), field)) - -#define TAILQ_FOREACH_SAFE(var, head, field, tvar) \ - for ((var) = TAILQ_FIRST((head)); \ - (var) && ((tvar) = TAILQ_NEXT((var), field), 1); \ - (var) = (tvar)) - -#define TAILQ_FOREACH_REVERSE(var, head, headname, field) \ - for ((var) = TAILQ_LAST((head), headname); \ - (var); \ - (var) = TAILQ_PREV((var), headname, field)) - -#define TAILQ_FOREACH_REVERSE_SAFE(var, head, headname, field, tvar) \ - for ((var) = TAILQ_LAST((head), headname); \ - (var) && ((tvar) = TAILQ_PREV((var), headname, field), 1); \ - (var) = (tvar)) - -#define TAILQ_INIT(head) do { \ - TAILQ_FIRST((head)) = NULL; \ - (head)->tqh_last = &TAILQ_FIRST((head)); \ - QMD_TRACE_HEAD(head); \ -} while (0) - -#define TAILQ_INSERT_AFTER(head, listelm, elm, field) do { \ - if ((TAILQ_NEXT((elm), field) = TAILQ_NEXT((listelm), field)) != NULL)\ - TAILQ_NEXT((elm), field)->field.tqe_prev = \ - &TAILQ_NEXT((elm), field); \ - else { \ - (head)->tqh_last = &TAILQ_NEXT((elm), field); \ - QMD_TRACE_HEAD(head); \ - } \ - TAILQ_NEXT((listelm), field) = (elm); \ - (elm)->field.tqe_prev = &TAILQ_NEXT((listelm), field); \ - QMD_TRACE_ELEM(&(elm)->field); \ - QMD_TRACE_ELEM(&listelm->field); \ -} while (0) - -#define TAILQ_INSERT_BEFORE(listelm, elm, field) do { \ - (elm)->field.tqe_prev = (listelm)->field.tqe_prev; \ - TAILQ_NEXT((elm), field) = (listelm); \ - *(listelm)->field.tqe_prev = (elm); \ - (listelm)->field.tqe_prev = &TAILQ_NEXT((elm), field); \ - QMD_TRACE_ELEM(&(elm)->field); \ - QMD_TRACE_ELEM(&listelm->field); \ -} while (0) - -#define TAILQ_INSERT_HEAD(head, elm, field) do { \ - if ((TAILQ_NEXT((elm), field) = TAILQ_FIRST((head))) != NULL) \ - TAILQ_FIRST((head))->field.tqe_prev = \ - &TAILQ_NEXT((elm), field); \ - else \ - (head)->tqh_last = &TAILQ_NEXT((elm), field); \ - TAILQ_FIRST((head)) = (elm); \ - (elm)->field.tqe_prev = &TAILQ_FIRST((head)); \ - QMD_TRACE_HEAD(head); \ - QMD_TRACE_ELEM(&(elm)->field); \ -} while (0) - -#define TAILQ_INSERT_TAIL(head, elm, field) do { \ - TAILQ_NEXT((elm), field) = NULL; \ - (elm)->field.tqe_prev = (head)->tqh_last; \ - *(head)->tqh_last = (elm); \ - (head)->tqh_last = &TAILQ_NEXT((elm), field); \ - QMD_TRACE_HEAD(head); \ - QMD_TRACE_ELEM(&(elm)->field); \ -} while (0) - -#define TAILQ_LAST(head, headname) \ - (*(((struct headname *)((head)->tqh_last))->tqh_last)) - -#define TAILQ_NEXT(elm, field) ((elm)->field.tqe_next) - -#define TAILQ_PREV(elm, headname, field) \ - (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last)) - -#define TAILQ_REMOVE(head, elm, field) do { \ - if ((TAILQ_NEXT((elm), field)) != NULL) \ - TAILQ_NEXT((elm), field)->field.tqe_prev = \ - (elm)->field.tqe_prev; \ - else { \ - (head)->tqh_last = (elm)->field.tqe_prev; \ - QMD_TRACE_HEAD(head); \ - } \ - *(elm)->field.tqe_prev = TAILQ_NEXT((elm), field); \ - TRASHIT((elm)->field.tqe_next); \ - TRASHIT((elm)->field.tqe_prev); \ - QMD_TRACE_ELEM(&(elm)->field); \ -} while (0) - - -#ifdef _KERNEL - -/* - * XXX insque() and remque() are an old way of handling certain queues. - * They bogusly assumes that all queue heads look alike. - */ - -struct quehead { - struct quehead *qh_link; - struct quehead *qh_rlink; -}; - -#ifdef __CC_SUPPORTS___INLINE - -static __inline void -insque(void *a, void *b) -{ - struct quehead *element = (struct quehead *)a, - *head = (struct quehead *)b; - - element->qh_link = head->qh_link; - element->qh_rlink = head; - head->qh_link = element; - element->qh_link->qh_rlink = element; -} - -static __inline void -remque(void *a) -{ - struct quehead *element = (struct quehead *)a; - - element->qh_link->qh_rlink = element->qh_rlink; - element->qh_rlink->qh_link = element->qh_link; - element->qh_rlink = 0; -} - -#else /* !__CC_SUPPORTS___INLINE */ - -void insque(void *a, void *b); -void remque(void *a); - -#endif /* __CC_SUPPORTS___INLINE */ - -#endif /* _KERNEL */ - -#endif /* _SYS_QUEUE_H_ */ diff --git a/connector/c/include/tarantool/tnt_reply.h b/connector/c/include/tarantool/tnt_reply.h deleted file mode 100644 index e49f1d3b79..0000000000 --- a/connector/c/include/tarantool/tnt_reply.h +++ /dev/null @@ -1,53 +0,0 @@ -#ifndef TNT_REPLY_H_INCLUDED -#define TNT_REPLY_H_INCLUDED - -/* - * 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. - */ - -typedef ssize_t (*tnt_reply_t)(void *ptr, char *dst, ssize_t size); - -struct tnt_reply { - uint32_t op; - uint32_t reqid; - uint32_t code; - char *error; - struct tnt_list tuples; - uint32_t count; -}; - -#define TNT_REPLY_ERR(R) ((R)->code >> 8) -#define TNT_REPLY_LIST(R) (&(R)->tuples) - -void tnt_reply_init(struct tnt_reply *r); -void tnt_reply_free(struct tnt_reply *r); - -int tnt_reply(struct tnt_reply *r, char *buf, size_t size, size_t *off); -int tnt_reply_from(struct tnt_reply *r, tnt_reply_t rcv, void *ptr); - -#endif /* TNT_REPLY_H_INCLUDED */ diff --git a/connector/c/include/tarantool/tnt_request.h b/connector/c/include/tarantool/tnt_request.h deleted file mode 100644 index 1c5dcc6b51..0000000000 --- a/connector/c/include/tarantool/tnt_request.h +++ /dev/null @@ -1,110 +0,0 @@ -#ifndef TNT_REQUEST_H_INCLUDED -#define TNT_REQUEST_H_INCLUDED - -/* - * 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 <sys/types.h> -#include <sys/uio.h> - -typedef ssize_t (*tnt_request_t)(void *ptr, char *dst, ssize_t size); - -struct tnt_request_insert { - struct tnt_header_insert h; - struct tnt_tuple t; -}; - -struct tnt_request_delete_1_3 { - struct tnt_header_delete_1_3 h; - struct tnt_tuple t; -}; - -struct tnt_request_delete { - struct tnt_header_delete h; - struct tnt_tuple t; -}; - -struct tnt_request_update_op { - uint8_t op; - uint32_t field; - char size_enc[5]; - uint32_t size_enc_len; - uint32_t size; - char *data; -}; - -struct tnt_request_update { - struct tnt_header_update h; - struct tnt_tuple t; - char *ops; - uint32_t ops_size; - struct tnt_request_update_op *opv; - uint32_t opc; -}; - -struct tnt_request_call { - struct tnt_header_call h; - char proc_enc[5]; - uint32_t proc_enc_len; - char *proc; - uint32_t proc_len; - struct tnt_tuple t; -}; - -struct tnt_request_select { - struct tnt_header_select h; - struct tnt_list l; -}; - -struct tnt_request { - char *origin; - size_t origin_size; - struct tnt_header h; - union { - struct tnt_request_insert insert; - struct tnt_request_delete_1_3 del_1_3; - struct tnt_request_delete del; - struct tnt_request_call call; - struct tnt_request_select select; - struct tnt_request_update update; - } r; - int vc; - struct iovec *v; -}; - -void tnt_request_init(struct tnt_request *r); -void tnt_request_free(struct tnt_request *r); -void tnt_request_setorigin(struct tnt_request *r, char *buf, size_t size); - -int tnt_request(struct tnt_request *r, char *buf, size_t size, size_t *off, - struct tnt_header *hdr); -int tnt_request_from(struct tnt_request *r, tnt_request_t rcv, void *ptr, - struct tnt_header *hdr); - -#endif /* TNT_REQUEST_H_INCLUDED */ diff --git a/connector/c/include/tarantool/tnt_rpl.h b/connector/c/include/tarantool/tnt_rpl.h deleted file mode 100644 index 5f1f813796..0000000000 --- a/connector/c/include/tarantool/tnt_rpl.h +++ /dev/null @@ -1,47 +0,0 @@ -#ifndef TNT_RPL_H_INCLUDED -#define TNT_RPL_H_INCLUDED - -/* - * 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. - */ - -struct tnt_stream_rpl { - struct tnt_log_header_v11 hdr; - struct tnt_log_row_v11 row; - struct tnt_stream *net; -}; - -#define TNT_RPL_CAST(S) ((struct tnt_stream_rpl*)(S)->data) - -struct tnt_stream *tnt_rpl(struct tnt_stream *s); -void tnt_rpl_attach(struct tnt_stream *s, struct tnt_stream *net); - -int tnt_rpl_open(struct tnt_stream *s, uint64_t lsn); -void tnt_rpl_close(struct tnt_stream *s); - -#endif /* TNT_XLOG_H_INCLUDED */ diff --git a/connector/c/include/tarantool/tnt_select.h b/connector/c/include/tarantool/tnt_select.h deleted file mode 100644 index 4ec5672d65..0000000000 --- a/connector/c/include/tarantool/tnt_select.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef TNT_SELECT_H_INCLUDED -#define TNT_SELECT_H_INCLUDED - -/* - * 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. - */ - -ssize_t -tnt_select(struct tnt_stream *s, - uint32_t ns, - uint32_t index, uint32_t offset, uint32_t limit, - struct tnt_list *keys); - -#endif /* TNT_SELECT_H_INCLUDED */ diff --git a/connector/c/include/tarantool/tnt_snapshot.h b/connector/c/include/tarantool/tnt_snapshot.h deleted file mode 100644 index fb5ddeddcd..0000000000 --- a/connector/c/include/tarantool/tnt_snapshot.h +++ /dev/null @@ -1,50 +0,0 @@ -#ifndef TNT_SNAPSHOT_H_INCLUDED -#define TNT_SNAPSHOT_H_INCLUDED - -/* - * 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 <tarantool/tnt_log.h> - -struct tnt_stream_snapshot { - struct tnt_log log; -}; - -#define TNT_SSNAPSHOT_CAST(S) ((struct tnt_stream_snapshot*)(S)->data) - -struct tnt_stream *tnt_snapshot(struct tnt_stream *s); - -int tnt_snapshot_open(struct tnt_stream *s, char *file); -void tnt_snapshot_close(struct tnt_stream *s); - -enum tnt_log_error tnt_snapshot_error(struct tnt_stream *s); -char *tnt_snapshot_strerror(struct tnt_stream *s); -int tnt_snapshot_errno(struct tnt_stream *s); - -#endif /* TNT_SNAPSHOT_H_INCLUDED */ diff --git a/connector/c/include/tarantool/tnt_sql.h b/connector/c/include/tarantool/tnt_sql.h deleted file mode 100644 index ce21810682..0000000000 --- a/connector/c/include/tarantool/tnt_sql.h +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef TNT_SQL_H_INCLUDED -#define TNT_SQL_H_INCLUDED - -/* - * 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. - */ - -int tnt_query(struct tnt_stream *s, const char *q, size_t qsize, char **e); -int tnt_query_is(const char *q, size_t qsize); - -#endif /* TNT_SQL_H_INCLUDED */ diff --git a/connector/c/include/tarantool/tnt_stream.h b/connector/c/include/tarantool/tnt_stream.h deleted file mode 100644 index 8281c10d69..0000000000 --- a/connector/c/include/tarantool/tnt_stream.h +++ /dev/null @@ -1,58 +0,0 @@ -#ifndef TNT_STREAM_H_INCLUDED -#define TNT_STREAM_H_INCLUDED - -/* - * 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 <sys/types.h> -#include <sys/uio.h> - -/* stream interface */ - -struct tnt_stream { - int alloc; - ssize_t (*write)(struct tnt_stream *s, const char *buf, size_t size); - ssize_t (*writev)(struct tnt_stream *s, struct iovec *iov, int count); - ssize_t (*write_request)(struct tnt_stream *s, struct tnt_request *r); - ssize_t (*read)(struct tnt_stream *s, char *buf, size_t size); - int (*read_reply)(struct tnt_stream *s, struct tnt_reply *r); - int (*read_request)(struct tnt_stream *s, struct tnt_request *r); - int (*read_tuple)(struct tnt_stream *s, struct tnt_tuple *t); - void (*free)(struct tnt_stream *s); - void *data; - uint32_t wrcnt; /* count of write operations */ - uint32_t reqid; -}; - -struct tnt_stream *tnt_stream_init(struct tnt_stream *s); -void tnt_stream_free(struct tnt_stream *s); - -uint32_t tnt_stream_reqid(struct tnt_stream *s, uint32_t reqid); - -#endif /* TNT_STREAM_H_INCLUDED */ diff --git a/connector/c/include/tarantool/tnt_tuple.h b/connector/c/include/tarantool/tnt_tuple.h deleted file mode 100644 index dfab8e3aab..0000000000 --- a/connector/c/include/tarantool/tnt_tuple.h +++ /dev/null @@ -1,68 +0,0 @@ -#ifndef TNT_TUPLE_H_INCLUDED -#define TNT_TUPLE_H_INCLUDED - -/* - * 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. - */ - -/* tuple */ - -struct tnt_tuple { - uint32_t cardinality; /* tuple fields count */ - char *data; /* tuple fields */ - size_t size; /* tuple size */ - int alloc; /* allocation mark */ -}; - -void tnt_tuple_init(struct tnt_tuple *t); -void tnt_tuple_free(struct tnt_tuple *t); - -struct tnt_tuple *tnt_tuple(struct tnt_tuple *t, const char *fmt, ...); -struct tnt_tuple *tnt_tuple_add(struct tnt_tuple *t, const void *data, uint32_t size); -struct tnt_tuple *tnt_tuple_set(struct tnt_tuple *t, const void *buf, size_t size); -struct tnt_tuple* tnt_tuple_set_as(struct tnt_tuple *t, const void *buf, size_t size, uint32_t num); - -/* tuple list */ - -struct tnt_list_ptr { - struct tnt_tuple *ptr; /* tuple pointer */ -}; - -struct tnt_list { - struct tnt_list_ptr *list; /* tuple list */ - uint32_t count; /* tuple list count */ - int alloc; /* allocation mark */ -}; - -void tnt_list_init(struct tnt_list *l); -void tnt_list_free(struct tnt_list *l); - -struct tnt_list *tnt_list(struct tnt_list *l, ...); -struct tnt_tuple *tnt_list_at(struct tnt_list *l, struct tnt_tuple *t); - -#endif /* TNT_TUPLE_H_INCLUDED */ diff --git a/connector/c/include/tarantool/tnt_update.h b/connector/c/include/tarantool/tnt_update.h deleted file mode 100644 index 6259a26cb8..0000000000 --- a/connector/c/include/tarantool/tnt_update.h +++ /dev/null @@ -1,77 +0,0 @@ -#ifndef TNT_UPDATE_H_INCLUDED -#define TNT_UPDATE_H_INCLUDED - -/* - * 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. - */ - -enum { - TNT_UPDATE_ASSIGN = 0, - TNT_UPDATE_ADD, - TNT_UPDATE_AND, - TNT_UPDATE_XOR, - TNT_UPDATE_OR, - TNT_UPDATE_SPLICE, - TNT_UPDATE_DELETE, - TNT_UPDATE_INSERT, -}; - -ssize_t -tnt_update_arith(struct tnt_stream *s, uint32_t field, - uint8_t op, uint32_t value); - -ssize_t -tnt_update_arith_i32(struct tnt_stream *s, uint32_t field, - uint8_t op, uint32_t value); - -ssize_t -tnt_update_arith_i64(struct tnt_stream *s, uint32_t field, - uint8_t op, uint64_t value); - -ssize_t -tnt_update_assign(struct tnt_stream *s, uint32_t field, - char *data, uint32_t size); - -ssize_t -tnt_update_splice(struct tnt_stream *s, uint32_t field, - uint32_t offset, - int32_t length, const char *data, size_t size); - -ssize_t -tnt_update_delete(struct tnt_stream *s, uint32_t field); - -ssize_t -tnt_update_insert(struct tnt_stream *s, uint32_t field, - const char *data, uint32_t size); - -ssize_t -tnt_update(struct tnt_stream *s, uint32_t ns, uint32_t flags, - struct tnt_tuple *k, - struct tnt_stream *ops); - -#endif /* TNT_UPDATE_H_INCLUDED */ diff --git a/connector/c/include/tarantool/tnt_utf8.h b/connector/c/include/tarantool/tnt_utf8.h deleted file mode 100644 index 1b5b8e1ca8..0000000000 --- a/connector/c/include/tarantool/tnt_utf8.h +++ /dev/null @@ -1,52 +0,0 @@ -#ifndef TNT_UTF8_H_INCLUDED -#define TNT_UTF8_H_INCLUDED - -/* - * 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. - */ - -struct tnt_utf8 { - unsigned char *data; - size_t size; - size_t len; -}; - -#define TNT_UTF8_CHAR(U, P) ((U)->data + (P)) - -bool tnt_utf8_init(struct tnt_utf8 *u, const unsigned char *data, size_t size); -void tnt_utf8_free(struct tnt_utf8 *u); - -ssize_t tnt_utf8_chrlen(const unsigned char *data, size_t size); -ssize_t tnt_utf8_strlen(const unsigned char *data, size_t size); - -ssize_t tnt_utf8_sizeof(const unsigned char *data, size_t size, size_t n); -bool tnt_utf8_cmp(struct tnt_utf8 *u, struct tnt_utf8 *us); - -ssize_t tnt_utf8_next(struct tnt_utf8 *u, size_t off); - -#endif /* TNT_UTF8_H_INCLUDED */ diff --git a/connector/c/include/tarantool/tnt_xlog.h b/connector/c/include/tarantool/tnt_xlog.h deleted file mode 100644 index 9df82a27dc..0000000000 --- a/connector/c/include/tarantool/tnt_xlog.h +++ /dev/null @@ -1,50 +0,0 @@ -#ifndef TNT_XLOG_H_INCLUDED -#define TNT_XLOG_H_INCLUDED - -/* - * 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 <tarantool/tnt_log.h> - -struct tnt_stream_xlog { - struct tnt_log log; -}; - -#define TNT_SXLOG_CAST(S) ((struct tnt_stream_xlog*)(S)->data) - -struct tnt_stream *tnt_xlog(struct tnt_stream *s); - -int tnt_xlog_open(struct tnt_stream *s, char *file); -void tnt_xlog_close(struct tnt_stream *s); - -enum tnt_log_error tnt_xlog_error(struct tnt_stream *s); -char *tnt_xlog_strerror(struct tnt_stream *s); -int tnt_xlog_errno(struct tnt_stream *s); - -#endif /* TNT_XLOG_H_INCLUDED */ diff --git a/connector/c/include/tp.h b/connector/c/include/tp.h deleted file mode 100644 index 13be854662..0000000000 --- a/connector/c/include/tp.h +++ /dev/null @@ -1,1107 +0,0 @@ -#ifndef TP_H_INCLUDED -#define TP_H_INCLUDED - -/* - * TP - Tarantool Protocol library. - * (http://tarantool.org) - * - * protocol description: - * https://github.com/tarantool/tarantool/blob/master/doc/box-protocol.txt - * ------------------- - * - * TP - a C library designed to create requests and process - * replies to or from a Tarantool server. - * - * The library is designed to be used by a C/C++ application which - * requires sophisticated memory control and/or performance. - * - * The library does not support network operations. All operations - * are done in a user supplied buffer and with help of - * a user-supplied allocator. - * - * The primary purpose of the library was to spare implementors - * of Tarantool drivers in other languages, such as Perl, - * Ruby, Python, etc, from the details of the binary protocol, and - * also to make it possible to avoid double-buffering by writing - * directly to/from language objects from/to a serialized binary - * packet stream. This paradigm makes data transfer from domain - * language types (such as strings, scalars, numbers, etc) to - * the network format direct, and, therefore, most efficient. - * - * As a side effect, the library is usable in any kind of - * networking environment: synchronous with buffered sockets, or - * asynchronous event-based, as well as with cooperative - * multitasking. - * - * Before using the library, please get acquainted with - * Tarnatool binary protocol, documented at - * https://github.com/tarantool/tarantool/blob/master/doc/box-protocol.txt - * - * BASIC REQUEST STRUCTURE - * ----------------------- - * - * Any request in Tarantool consists of a 12-byte header, - * containing request type, id and length, and an optional tuple - * or tuples. Similarly, a response carries back the same request - * type and id, and then a tuple or tuples. - * - * Below is a step-by-step tutorial for creating requests - * and unpacking responses. - * - * TO ASSEMBLE A REQUEST - * --------------------- - * - * (1) initialize an instance of struct tp with tp_init(). - * Provide tp_init() with a buffer and an (optional) allocator - * function. - * - * (2) construct requests by sequentially calling necessary - * operations, such as tp_insert(), tp_delete(), tp_update(), - * tp_call(). Note: these operations only append to the buffer - * a request header, a body of the request, which is usually - * a tuple, must be appended to the buffer with a separate call. - * Each next call of tp_*() API appends request data to - * the tail of the buffer. If the buffer becomes too small to - * contain the binary stream, the reallocation function is - * invoked to enlarge the buffer. - * A buffer can contain multiple requests: Tarantool - * handles them all asynchronously, sending responses - * back as soon as they are ready. The request id can be then - * used to associate responses with requests. - * - * For example: - * - * char buf[256]; - * struct tp req; - * // initialize request buffer - * tp_init(&req, buf, sizeof(buf), NULL, NULL); - * // append INSERT packet header to the buffer - * // request flags are empty, request id is 0 - * tp_insert(&req, 0, 0); - * // begin appending a tuple to the request - * tp_tuple(&req); - * // append one tuple field - * tp_sz(&req, "key"); - * // one more tuple field - * tp_sz(&req, "value"); - * - * (3) the buffer can be used right after all requests are - * appended to it. tp_used() can be used to get the current - * buffer size: - * - * write(1, buf, tp_used(&req)); // write the buffer to stdout - * - * (4) When no longer needed, the buffer must be freed manually. - * - * For additional examples, please read the documentation for - * buffer operations. - * - * PROCESSING A REPLY - * ------------------ - * - * (1) tp_init() must be called with a pointer to a buffer which - * already stores or will eventually receive the server response. - * Functions tp_reqbuf() and tp_req() can be then used to examine - * if a network buffer contains a full reply or not. - * - * Following is an example of tp_req() usage (reading from stdin - * and parsing it until a response is completely read): - * - * struct tp rep; - * tp_init(&rep, NULL, 0, tp_realloc, NULL); - * - * while (1) { - * ssize_t to_read = tp_req(&rep); - * printf("to_read: %zu\n", to_read); - * if (to_read <= 0) - * break; - * ssize_t new_size = tp_ensure(&rep, to_read); - * printf("new_size: %zu\n", new_size); - * if (new_size == -1) - * return -1; - * int rc = fread(rep.p, to_read, 1, stdin); - * if (rc != 1) - * return 1; - * // discard processed data and make space available - * // for new input: - * tp_use(&rep, to_read); - * } - * - * (2) tp_reply() function can be used to find out if the request - * is executed successfully or not: - * server_code = tp_reply(&reply); - * - * if (server_code != 0) { - * printf("error: %-.*s\n", tp_replyerrorlen(&rep), - * tp_replyerror(&rep)); - * } - * - * Note: the library itself doesn't contain #defines for server - * error codes. They are defined in - * https://github.com/tarantool/tarantool/blob/master/include/errcode.h - * - * A server failure can be either transient or persistent. For - * example, a failure to allocate memory is transient: as soon as - * some data is deleted, the request can be executed again, this - * time successfully. A constraint violation is a non-transient - * error: it persists regardless of how many times a request - * is re-executed. Server error codes can be analyzed to better - * handle an error. - * - * (3) The server usually responds to any kind of request with a - * tuple. Tuple data can be accessed via tp_next(), tp_nextfield(), - * tp_gettuple(), tp_getfield(). - * - * See the docs for tp_reply() and tp_next()/tp_nextfield() for an - * example. - * - * API RETURN VALUE CONVENTION - * --------------------------- - * - * API functions return 0 on success, -1 on error. - * If a function appends data to struct tp, it returns the - * size appended on success, or -1 on error. - * - * SEE ALSO - * -------- - * - * TP is used by Tarantool Perl driver: - * https://github.com/dr-co/dr-tarantool/blob/master/Tarantool.xs -*/ - -/* - * Copyright (c) 2012-2013 Tarantool AUTHORS - * (https://github.com/tarantool/tarantool/blob/master/AUTHORS) - * - * 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. -*/ -#ifdef __cplusplus -extern "C" { -#endif - -#include <stdlib.h> -#include <stdint.h> -#include <string.h> -#include <assert.h> - -#define tp_function_unused __attribute__((unused)) -#define tp_packed __attribute__((packed)) -#define tp_inline __attribute__((forceinline)) -#define tp_noinline __attribute__((noinline)) -#if defined(__GNUC__) -#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3) -#define tp_hot __attribute__((hot)) -#endif -#endif -#if !defined(tp_hot) -#define tp_hot -#endif - -#define tp_likely(expr) __builtin_expect(!! (expr), 1) -#define tp_unlikely(expr) __builtin_expect(!! (expr), 0) - -struct tp; - -/* Reallocation function, can be customized for own use */ -typedef char *(*tp_reserve)(struct tp *p, size_t req, size_t *size); - -/* request types. */ -#define TP_PING 65280 -#define TP_INSERT 13 -#define TP_SELECT 17 -#define TP_UPDATE 19 -#define TP_DELETE 21 -#define TP_CALL 22 - -/* requests flags */ -#define TP_BOX_RETURN_TUPLE 1 -#define TP_BOX_ADD 2 -#define TP_BOX_REPLACE 4 - -/* update operation codes */ -#define TP_OPSET 0 -#define TP_OPADD 1 -#define TP_OPAND 2 -#define TP_OPXOR 3 -#define TP_OPOR 4 -#define TP_OPSPLICE 5 -#define TP_OPDELETE 6 -#define TP_OPINSERT 7 - -/* internal protocol headers */ -struct tp_h { - uint32_t type, len, reqid; -} tp_packed; - -struct tp_hinsert { - uint32_t space, flags; -} tp_packed; - -struct tp_hdelete { - uint32_t space, flags; -} tp_packed; - -struct tp_hupdate { - uint32_t space, flags; -} tp_packed; - -struct tp_hcall { - uint32_t flags; -} tp_packed; - -struct tp_hselect { - uint32_t space, index; - uint32_t offset; - uint32_t limit; - uint32_t keyc; -} tp_packed; - -/* - * Main tp object - points either to a request buffer, or to - * a response. - * - * All fields except tp->p should not be accessed directly. - * Appropriate accessors should be used instead. -*/ -struct tp { - struct tp_h *h; /* current request header */ - char *s, *p, *e; /* start, pos, end */ - char *t, *f, *u; /* tuple, tuple field, update operation */ - char *c; /* reply parsing position */ - uint32_t tsz, fsz, tc; /* tuple size, field size, tuple count */ - uint32_t code; /* reply server code */ - uint32_t cnt; /* reply tuple count */ - tp_reserve reserve; /* realloc function pointer */ - void *obj; /* reallocation context pointer */ -}; - -/* Get the size of the allocated buffer */ -static inline size_t -tp_size(struct tp *p) { - return p->e - p->s; -} - -/* Get the size of data in the buffer */ -static inline size_t -tp_used(struct tp *p) { - return p->p - p->s; -} - -/* Get the size available for write */ -static inline size_t -tp_unused(struct tp *p) { - return p->e - p->p; -} - -/* A common reallocation function, can be used - * for 'reserve' param in tp_init(). - * Resizes the buffer twice the previous size using realloc(). - * - * struct tp req; - * tp_init(&req, NULL, tp_realloc, NULL); - * tp_ping(&req); // will call the reallocator - * - * data must be manually freed when the buffer is no longer - * needed. - * (eg. free(p->s)); - * if realloc will return NULL, then you must destroy previous memory. - * (eg. - * if (tp_realloc(p, ..) == NULL) { - * free(p->s) - * return NULL; - * } -*/ -tp_function_unused static char* -tp_realloc(struct tp *p, size_t required, size_t *size) { - size_t toalloc = tp_size(p) * 2; - if (tp_unlikely(toalloc < required)) - toalloc = tp_size(p) + required; - *size = toalloc; - return realloc(p->s, toalloc); -} - - -/* Free function for use in a pair with tp_realloc */ -static inline void -tp_free(struct tp *p) { - free(p->s); -} - -/* Get currently allocated buffer pointer */ -static inline char* -tp_buf(struct tp *p) { - return p->s; -} - -/* Main initialization function. - * - * reserve - reallocation function, may be NULL - * obj - pointer to be passed to the reallocation function as - * context - * buf - current buffer, may be NULL - * size - current buffer size - * - * Either a buffer pointer or a reserve function must be - * provided. -*/ -static inline void -tp_init(struct tp *p, char *buf, size_t size, - tp_reserve reserve, void *obj) { - p->s = buf; - p->p = p->s; - p->e = p->s + size; - p->t = NULL; - p->f = NULL; - p->u = NULL; - p->c = NULL; - p->h = NULL; - p->tsz = 0; - p->fsz = 0; - p->cnt = 0; - p->code = 0; - p->reserve = reserve; - p->obj = obj; -} - -/* Ensure that buffer has enough space to fill size bytes, resize - * buffer if needed. */ -static tp_noinline ssize_t -tp_ensure(struct tp *p, size_t size) { - if (tp_likely(tp_unused(p) >= size)) - return 0; - if (tp_unlikely(p->reserve == NULL)) - return -1; - size_t sz; - register char *np = p->reserve(p, size, &sz); - if (tp_unlikely(np == NULL)) - return -1; - p->p = np + (p->p - p->s); - if (tp_likely(p->h)) - p->h = (struct tp_h*)(np + (((char*)p->h) - p->s)); - if (tp_likely(p->t)) - p->t = np + (p->t - p->s); - if (tp_unlikely(p->f)) - p->f = (np + (p->f - p->s)); - if (tp_unlikely(p->u)) - p->u = (np + (p->u - p->s)); - p->s = np; - p->e = np + sz; - return sz; -} - -/* Mark size bytes as used. - * Can be used to tell the buffer that a chunk has been read - * from the network into it. - */ -static inline ssize_t -tp_use(struct tp *p, size_t size) { - p->p += size; - return tp_used(p); -} - -/* Append data to the buffer. - * Mostly unnecessary, but can be used to add any raw - * iproto-format data to the buffer. - * Normally tp_tuple(), tp_field() and tp_sz() should be used - * instead. - */ -static inline ssize_t -tp_append(struct tp *p, const void *data, size_t size) { - if (tp_unlikely(tp_ensure(p, size) == -1)) - return -1; - memcpy(p->p, data, size); - return tp_use(p, size); -} - -/* Set the current request id. - * - * tp_ping(&req); - * tp_reqid(&req, 777); - */ -static inline void -tp_reqid(struct tp *p, uint32_t reqid) { - assert(p->h != NULL); - p->h->reqid = reqid; -} - -/* Return the current request id */ -static inline uint32_t -tp_getreqid(struct tp *p) { - assert(p->h != NULL); - return p->h->reqid; -} - -/* Get tuple count */ -static inline uint32_t -tp_tuplecount(struct tp *p) { - assert(p->t != NULL); - return *(uint32_t*)(p->t); -} - -/* Write a tuple header */ -static inline ssize_t -tp_tuple(struct tp *p) { - assert(p->h != NULL); - if (tp_unlikely(tp_ensure(p, sizeof(uint32_t)) == -1)) - return -1; - *(uint32_t*)(p->t = p->p) = 0; - p->p += sizeof(uint32_t); - p->h->len += sizeof(uint32_t); - if (p->h->type == TP_SELECT) { - ((struct tp_hselect*) - ((char*)p->h + sizeof(struct tp_h)))->keyc++; - } - return tp_used(p); -} - -/* Ber128 calculation functions, internally used by the library */ -static inline size_t -tp_ber128sizeof(uint32_t value) { - return ( tp_likely(value < (1 << 7))) ? 1 : - ( tp_likely(value < (1 << 14))) ? 2 : - (tp_unlikely(value < (1 << 21))) ? 3 : - (tp_unlikely(value < (1 << 28))) ? 4 : 5; -} - -static tp_noinline void tp_hot -tp_ber128save_slowpath(struct tp *p, uint32_t value) { - if (tp_unlikely(value >= (1 << 21))) { - if (tp_unlikely(value >= (1 << 28))) - *(p->p++) = (value >> 28) | 0x80; - *(p->p++) = (value >> 21) | 0x80; - } - p->p[0] = ((value >> 14) | 0x80); - p->p[1] = ((value >> 7) | 0x80); - p->p[2] = value & 0x7F; - p->p += 3; -} - -static inline void tp_hot -tp_ber128save(struct tp *p, uint32_t value) { - if (tp_unlikely(value >= (1 << 14))) { - tp_ber128save_slowpath(p, value); - return; - } - if (tp_likely(value >= (1 << 7))) - *(p->p++) = ((value >> 7) | 0x80); - *(p->p++) = ((value) & 0x7F); -} - -static tp_noinline int tp_hot -tp_ber128load_slowpath(struct tp *p, uint32_t *value) { - if (tp_likely(! (p->f[2] & 0x80))) { - *value = (p->f[0] & 0x7f) << 14 | - (p->f[1] & 0x7f) << 7 | - (p->f[2] & 0x7f); - p->f += 3; - } else - if (! (p->f[3] & 0x80)) { - *value = (p->f[0] & 0x7f) << 21 | - (p->f[1] & 0x7f) << 14 | - (p->f[2] & 0x7f) << 7 | - (p->f[3] & 0x7f); - p->f += 4; - } else - if (! (p->f[4] & 0x80)) { - *value = (p->f[0] & 0x7f) << 28 | - (p->f[1] & 0x7f) << 21 | - (p->f[2] & 0x7f) << 14 | - (p->f[3] & 0x7f) << 7 | - (p->f[4] & 0x7f); - p->f += 5; - } else - return -1; - return 0; -} - -static inline int tp_hot -tp_ber128load(struct tp *p, uint32_t *value) { - if (tp_likely(! (p->f[0] & 0x80))) { - *value = *(p->f++) & 0x7f; - } else - if (tp_likely(! (p->f[1] & 0x80))) { - *value = (p->f[0] & 0x7f) << 7 | (p->f[1] & 0x7f); - p->f += 2; - } else - return tp_ber128load_slowpath(p, value); - return 0; -} - -/* Write a tuple field - * Note: the tuple must be started prior to calling - * this function with tp_tuple() call. - */ -static inline ssize_t -tp_field(struct tp *p, const char *data, size_t size) { - assert(p->h != NULL); - assert(p->t != NULL); - register int esz = tp_ber128sizeof(size); - if (tp_unlikely(tp_ensure(p, esz + size) == -1)) - return -1; - tp_ber128save(p, size); - memcpy(p->p, data, size); - p->p += size; - (*(uint32_t*)p->t)++; - p->h->len += esz + size; - return tp_used(p); -} - -/* Set the current request. - * Note: this is an internal helper function, not part of the - * tp.h API. - */ -static inline void -tp_setreq(struct tp *p) { - p->h = (struct tp_h*)p->p; - p->t = NULL; - p->u = NULL; -} - -/* Set current request and append data to the buffer. - * Note: this is an internal helper function, not part of the - * tp.h API. tp_ping(), tp_update() and other functions - * which directly create a request header should be used - * instead. - */ -static inline ssize_t -tp_appendreq(struct tp *p, void *h, size_t size) { - int isallocated = p->p != NULL; - tp_setreq(p); - ssize_t rc = tp_append(p, h, size); - if (tp_unlikely(rc == -1)) - return -1; - if (!isallocated) - p->h = (struct tp_h*)p->s; - return rc; -} - -/* Create a ping request. - * - * char buf[64]; - * struct tp req; - * tp_init(&req, buf, sizeof(buf), NULL, NULL); - * tp_ping(&req); - */ -static inline ssize_t -tp_ping(struct tp *p) { - struct tp_h h = { TP_PING, 0, 0 }; - return tp_appendreq(p, &h, sizeof(h)); -} - -/* Create an insert request. - * - * char buf[64]; - * struct tp req; - * tp_init(&req, buf, sizeof(buf), NULL, NULL); - * tp_insert(&req, 0, TP_FRET); - * tp_tuple(&req); - * tp_sz(&req, "key"); - * tp_sz(&req, "value"); - */ -static inline ssize_t -tp_insert(struct tp *p, uint32_t space, uint32_t flags) { - struct { - struct tp_h h; - struct tp_hinsert i; - } h; - h.h.type = TP_INSERT; - h.h.len = sizeof(struct tp_hinsert); - h.h.reqid = 0; - h.i.space = space; - h.i.flags = flags; - return tp_appendreq(p, &h, sizeof(h)); -} - -/* Create a delete request. - * - * char buf[64]; - * struct tp req; - * tp_init(&req, buf, sizeof(buf), NULL, NULL); - * tp_delete(&req, 0, 0); - * tp_tuple(&req); - * tp_sz(&req, "key"); - */ -static inline ssize_t -tp_delete(struct tp *p, uint32_t space, uint32_t flags) { - struct { - struct tp_h h; - struct tp_hdelete d; - } h; - h.h.type = TP_DELETE; - h.h.len = sizeof(struct tp_hdelete); - h.h.reqid = 0; - h.d.space = space; - h.d.flags = flags; - return tp_appendreq(p, &h, sizeof(h)); -} - -/* Create a call request. - * - * char buf[64]; - * struct tp req; - * tp_init(&req, buf, sizeof(buf), NULL, NULL); - * - * char proc[] = "hello_proc"; - * tp_call(&req, 0, proc, sizeof(proc) - 1); - * tp_tuple(&req); - * tp_sz(&req, "arg1"); - * tp_sz(&req, "arg2"); - */ -static inline ssize_t -tp_call(struct tp *p, uint32_t flags, const char *name, size_t name_len) { - struct { - struct tp_h h; - struct tp_hcall c; - } h; - size_t sz = tp_ber128sizeof(name_len); - h.h.type = TP_CALL; - h.h.len = sizeof(struct tp_hcall) + sz + name_len; - h.h.reqid = 0; - h.c.flags = flags; - if (tp_unlikely(tp_ensure(p, sizeof(h) + sz + name_len) == -1)) - return -1; - tp_setreq(p); - memcpy(p->p, &h, sizeof(h)); - p->p += sizeof(h); - tp_ber128save(p, name_len); - memcpy(p->p, name, name_len); - p->p += name_len; - return tp_used(p); -} - -/* Append a select request. - * - * char buf[64]; - * struct tp req; - * tp_init(&req, buf, sizeof(buf), NULL, NULL); - * tp_select(&req, 0, 0, 0, 100); - * tp_tuple(&req); - * tp_sz(&req, "key"); - */ -static inline ssize_t -tp_select(struct tp *p, uint32_t space, uint32_t index, - uint32_t offset, uint32_t limit) { - struct { - struct tp_h h; - struct tp_hselect s; - } h; - h.h.type = TP_SELECT; - h.h.len = sizeof(struct tp_hselect); - h.h.reqid = 0; - h.s.space = space; - h.s.index = index; - h.s.offset = offset; - h.s.limit = limit; - h.s.keyc = 0; - return tp_appendreq(p, &h, sizeof(h)); -} - -/* Create an update request. - * - * char buf[64]; - * struct tp req; - * tp_init(&req, buf, sizeof(buf), NULL, NULL); - * tp_update(&req, 0, 0); - * tp_tuple(&req); - * tp_sz(&req, "key"); - * tp_updatebegin(&req); - * tp_op(&req, 1, TP_OPSET, "VALUE", 5); - */ -static inline ssize_t -tp_update(struct tp *p, uint32_t space, uint32_t flags) { - struct { - struct tp_h h; - struct tp_hupdate u; - } h; - h.h.type = TP_UPDATE; - h.h.len = sizeof(struct tp_hupdate); - h.h.reqid = 0; - h.u.space = space; - h.u.flags = flags; - return tp_appendreq(p, &h, sizeof(h)); -} - -/* Append the number of operations the update request - * is going to contain. - * Must be called right after appending the key which - * identifies the tuple which must be updated. Since - * the key can be multipart, tp_tuple() must be used to - * append it. - * - * In other words, this call sequence creates a proper - * UPDATE request: - * tp_init(...) - * tp_update() - * tp_tuple() - * tp_sz(), tp_sz(), ... - * tp_updatebegin() - * tp_op(), tp_op(), ... - */ -static inline ssize_t -tp_updatebegin(struct tp *p) { - assert(p->h != NULL); - assert(p->h->type == TP_UPDATE); - if (tp_unlikely(tp_ensure(p, sizeof(uint32_t)) == -1)) - return -1; - *(uint32_t*)(p->u = p->p) = 0; - p->p += sizeof(uint32_t); - p->h->len += sizeof(uint32_t); - return tp_used(p); -} - -/* Append a single UPDATE operation. - * - * May be called after tp_updatebegin(). - * Can be used to create TP_OPSET, TP_OPADD, TP_OPAND, - * TP_OPXOR, TP_OPOR operations. - * - * See: tp_update() for example. - */ -static inline ssize_t -tp_op(struct tp *p, uint32_t field, uint8_t op, const char *data, - size_t size) { - assert(p->h != NULL); - assert(p->u != NULL); - assert(p->h->type == TP_UPDATE); - size_t sz = 4 + 1 + tp_ber128sizeof(size) + size; - if (tp_unlikely(tp_ensure(p, sz)) == -1) - return -1; - /* field */ - *(uint32_t*)(p->p) = field; - p->p += sizeof(uint32_t); - /* operation */ - *(uint8_t*)(p->p) = op; - p->p += sizeof(uint8_t); - /* data */ - tp_ber128save(p, size); - if (tp_likely(data)) - memcpy(p->p, data, size); - p->p += size; - /* update offset and count */ - p->h->len += sz; - (*(uint32_t*)p->u)++; - return tp_used(p); -} - -/* Append a SPLICE operation. This operation is unlike any other, - * since it takes three arguments instead of one. - */ -static inline ssize_t -tp_opsplice(struct tp *p, uint32_t field, uint32_t offset, - uint32_t cut, const char *paste, size_t paste_len) { - uint32_t olen = tp_ber128sizeof(sizeof(offset)), - clen = tp_ber128sizeof(sizeof(cut)), - plen = tp_ber128sizeof(paste_len); - uint32_t sz = olen + sizeof(offset) + clen + sizeof(cut) + - plen + paste_len; - ssize_t rc = tp_op(p, field, TP_OPSPLICE, NULL, sz); - if (tp_unlikely(rc == -1)) - return -1; - p->p -= sz; - tp_ber128save(p, sizeof(offset)); - memcpy(p->p, &offset, sizeof(offset)); - p->p += sizeof(offset); - tp_ber128save(p, sizeof(cut)); - memcpy(p->p, &cut, sizeof(cut)); - p->p += sizeof(cut); - tp_ber128save(p, paste_len); - memcpy(p->p, paste, paste_len); - p->p += paste_len; - return rc; -} - -/* Append a '\0' terminated string as a tuple field. */ -static inline ssize_t -tp_sz(struct tp *p, const char *sz) { - return tp_field(p, sz, strlen(sz)); -} - -/* - * Returns the number of bytes which are required to fully - * store a reply in the buffer. - * The return value can be negative, which indicates that - * there is a complete reply in the buffer which is not parsed - * and discarded yet. - */ -static inline ssize_t -tp_reqbuf(const char *buf, size_t size) { - if (tp_unlikely(size < sizeof(struct tp_h))) - return sizeof(struct tp_h) - size; - register int sz = - ((struct tp_h*)buf)->len + sizeof(struct tp_h); - return (tp_likely(size < sz)) ? - sz - size : -(size - sz); -} - -/* Same as tp_reqbuf(), but works on the buffer in struct tp. - */ -static inline ssize_t -tp_req(struct tp *p) { - return tp_reqbuf(p->s, tp_size(p)); -} - -/* Get the size of a yet unprocessed reply data. - * - * This is not part of the API. - */ -static inline size_t -tp_unfetched(struct tp *p) { - return p->p - p->c; -} - -/* Advance the reply processed pointer. - * - * This is not part of the API, tp_use() is a higher level - * function. - */ -static inline void* -tp_fetch(struct tp *p, int inc) { - assert(tp_unfetched(p) >= inc); - register char *po = p->c; - p->c += inc; - return po; -} - -/* Get the last server error. -*/ -static inline char* -tp_replyerror(struct tp *p) { - return p->c; -} - -/* Get the length of the last error message. - */ -static inline int -tp_replyerrorlen(struct tp *p) { - return tp_unfetched(p); -} - -/* Get the tuple count in the response (there must be - * no error). - */ -static inline uint32_t -tp_replycount(struct tp *p) { - return p->cnt; -} - -/* Get the current response return code. - */ -static inline uint32_t -tp_replycode(struct tp *p) { - return p->code; -} - -/* Get the current response operation code. */ -static inline uint32_t -tp_replyop(struct tp *p) { - return p->h->type; -} - -/* - * Initialize the buffer with a fully read server response. - * The response is parsed. - * - * struct tp rep; - * tp_init(&rep, reply_buf, reply_size, NULL, NULL); - * - * ssize_t server_code = tp_reply(&rep); - * - * printf("op: %d\n", tp_replyop(&rep)); - * printf("count: %d\n", tp_replycount(&rep)); - * printf("code: %zu\n", server_code); - * - * if (server_code != 0) { - * printf("error: %-.*s\n", tp_replyerrorlen(&rep), - * tp_replyerror(&rep)); - * } - * - */ -tp_function_unused static ssize_t -tp_reply(struct tp *p) { - ssize_t used = tp_req(p); - if (tp_unlikely(used > 0)) - return -1; - /* this is end of packet in continious buffer */ - p->p = p->e + used; /* end - used */ - p->c = p->s; - p->h = tp_fetch(p, sizeof(struct tp_h)); - p->t = p->f = p->u = NULL; - p->cnt = 0; - p->code = 0; - if (tp_unlikely(p->h->type == TP_PING)) - return 0; - if (tp_unlikely(p->h->type != TP_UPDATE && - p->h->type != TP_INSERT && - p->h->type != TP_DELETE && - p->h->type != TP_SELECT && - p->h->type != TP_CALL)) - return -1; - p->code = *(uint32_t*)tp_fetch(p, sizeof(uint32_t)); - if (p->code != 0) - return p->code; - /* BOX_QUIET */ - if (tp_unlikely(tp_unfetched(p) == 0)) - return p->code; - p->cnt = *(uint32_t*)tp_fetch(p, sizeof(uint32_t)); - return p->code; -} - -/* Example: iteration over returned tuples. - * - * while (tp_next(&rep)) { - * printf("tuple fields: %d\n", tp_tuplecount(&rep)); - * printf("tuple size: %d\n", tp_tuplesize(&rep)); - * printf("["); - * while (tp_nextfield(&rep)) { - * printf("%-.*s", tp_getfieldsize(rep), tp_getfield(&rep)); - * if (tp_hasnextfield(&rep)) - * printf(", "); - * } - * printf("]\n"); - * } -*/ - -/* Rewind iteration to the first tuple. */ -static inline void -tp_rewind(struct tp *p) { - p->t = NULL; - p->f = NULL; -} - -/* Rewind iteration to the first tuple field of the current tuple. */ -static inline void -tp_rewindfield(struct tp *p) { - p->f = NULL; -} - -/* Get the current tuple data, all fields. */ -static inline char* -tp_gettuple(struct tp *p) { - return p->t; -} - -/* Get the current tuple size. */ -static inline uint32_t -tp_tuplesize(struct tp *p) { - return p->tsz; -} - -/* Get the current field. */ -static inline char* -tp_getfield(struct tp *p) { - return p->f; -} - -/* Get the current field size. */ -static inline uint32_t -tp_getfieldsize(struct tp *p) { - return p->fsz; -} - -/* Get a pointer to the end of the current tuple. */ -static inline char* -tp_tupleend(struct tp *p) { - /* tuple_size + p->t + cardinaltiy_size + - * fields_size */ - return p->t + 4 + p->tsz; -} - -/* Check if the response has a tuple. - * Automatically checked during tp_next() iteration. */ -static inline int -tp_hasdata(struct tp *p) { - return tp_replyop(p) != TP_PING && tp_unfetched(p) > 0; -} - -/* Check if there is a one more tuple. */ -static inline int -tp_hasnext(struct tp *p) { - assert(p->t != NULL); - return (p->p - tp_tupleend(p)) >= 4; -} - -/* Check if the current tuple has a one more field. */ -static inline int -tp_hasnextfield(struct tp *p) { - assert(p->t != NULL); - register char *f = p->f + p->fsz; - if (tp_unlikely(p->f == NULL)) - f = p->t + 4; - return (tp_tupleend(p) - f) >= 1; -} - -/* Skip to the next tuple. - * Tuple can be accessed using: - * tp_tuplecount(), tp_tuplesize(), tp_gettuple(). */ -static inline int -tp_next(struct tp *p) { - if (tp_unlikely(p->t == NULL)) { - if (tp_unlikely(! tp_hasdata(p))) - return 0; - p->t = p->c + 4; - goto fetch; - } - if (tp_unlikely(! tp_hasnext(p))) - return 0; - p->t = tp_tupleend(p) + 4; -fetch: - p->tsz = *(uint32_t*)(p->t - 4); - if (tp_unlikely((p->t + p->tsz) > p->e)) - return -1; - p->f = NULL; - return 1; -} - -/* Skip to the next field. - * Data can be accessed using: tp_getfieldsize(), tp_getfield(). */ -static inline int -tp_nextfield(struct tp *p) { - assert(p->t != NULL); - if (tp_unlikely(p->f == NULL)) { - if (tp_unlikely(! tp_hasnextfield(p))) - return 0; - p->f = p->t + 4; - goto fetch; - } - if (tp_unlikely(! tp_hasnextfield(p))) - return 0; - p->f += p->fsz; -fetch:; - register int rc = tp_ber128load(p, &p->fsz); - if (tp_unlikely(rc == -1)) - return -1; - if (tp_unlikely((p->f + p->fsz) > p->e)) - return -1; - return 1; -} - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /* TP_H_INCLUDED */ diff --git a/connector/c/tb b/connector/c/tb deleted file mode 160000 index 67f2367e19..0000000000 --- a/connector/c/tb +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 67f2367e19492401f44bf9be093a8d667094dcc6 diff --git a/connector/c/tnt/CMakeLists.txt b/connector/c/tnt/CMakeLists.txt deleted file mode 100644 index 9b756303a9..0000000000 --- a/connector/c/tnt/CMakeLists.txt +++ /dev/null @@ -1,78 +0,0 @@ -#============================================================================# -# build flags -#============================================================================# - -# default flags -if (${CMAKE_BUILD_TYPE} STREQUAL "None") - set (tnt_cflags "-std=gnu99") -else() - set (tnt_cflags "-std=gnu99 -Wall -Wextra") - set (tnt_cflags "${tnt_cflags} -Wno-sign-compare -Wno-strict-aliasing") -endif() - -# Only add -Werror if it's a debug build, done by developers. -if (${CMAKE_BUILD_TYPE} STREQUAL "Debug") - set (tnt_cflags "${tnt_cflags} -Werror") -endif() - -#============================================================================# -# Build tnt project -#============================================================================# - -# -# source files -# -set (tnt_sources - tnt_mem.c - tnt_enc.c - tnt_tuple.c - tnt_iter.c - tnt_stream.c - tnt_buf.c - tnt_ping.c - tnt_insert.c - tnt_update.c - tnt_delete.c - tnt_call.c - tnt_select.c - tnt_reply.c - tnt_request.c) - -#----------------------------------------------------------------------------# -# Builds -#----------------------------------------------------------------------------# - -# Here we manage to build static/dynamic libraries ourselves, -# do not use the top level settings. -string(REPLACE "-static-libgcc" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") -string(REPLACE "-static" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") - -if (CMAKE_COMPILER_IS_GNUCC AND NOT CMAKE_COMPILER_IS_CLANG) - set (tnt_cflags "${tnt_cflags} -static-libgcc") -endif() - -# -# Static library -# -project(tnt) -add_library(tnt STATIC ${tnt_sources}) -set_target_properties(tnt PROPERTIES COMPILE_FLAGS "${tnt_cflags}") -set_target_properties(tnt PROPERTIES VERSION ${LIBTNT_VERSION} SOVERSION ${LIBTNT_SOVERSION}) -set_target_properties(tnt PROPERTIES OUTPUT_NAME "tarantool") - -# -# Shared library -# -project(tnt_shared) -add_library(tnt_shared SHARED ${tnt_sources}) -set_target_properties(tnt_shared PROPERTIES OUTPUT_NAME tnt) -set_target_properties(tnt_shared PROPERTIES COMPILE_FLAGS "${tnt_cflags}") -set_target_properties(tnt_shared PROPERTIES VERSION ${LIBTNT_VERSION} SOVERSION ${LIBTNT_SOVERSION}) -set_target_properties(tnt_shared PROPERTIES OUTPUT_NAME "tarantool") - -#----------------------------------------------------------------------------# -# Install -#----------------------------------------------------------------------------# - -install (TARGETS tnt ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) -install (TARGETS tnt_shared LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) diff --git a/connector/c/tnt/tnt_buf.c b/connector/c/tnt/tnt_buf.c deleted file mode 100644 index a67016197d..0000000000 --- a/connector/c/tnt/tnt_buf.c +++ /dev/null @@ -1,179 +0,0 @@ - -/* - * 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 <stdlib.h> -#include <stdint.h> -#include <string.h> - -#include <connector/c/include/tarantool/tnt_mem.h> -#include <connector/c/include/tarantool/tnt_proto.h> -#include <connector/c/include/tarantool/tnt_tuple.h> -#include <connector/c/include/tarantool/tnt_request.h> -#include <connector/c/include/tarantool/tnt_reply.h> -#include <connector/c/include/tarantool/tnt_stream.h> -#include <connector/c/include/tarantool/tnt_buf.h> - -static void tnt_buf_free(struct tnt_stream *s) { - struct tnt_stream_buf *sb = TNT_SBUF_CAST(s); - if (sb->data) - tnt_mem_free(sb->data); - tnt_mem_free(s->data); - s->data = NULL; -} - -static ssize_t -tnt_buf_read(struct tnt_stream *s, char *buf, size_t size) { - struct tnt_stream_buf *sb = TNT_SBUF_CAST(s); - if (sb->data == NULL) - return 0; - if (sb->size == sb->rdoff) - return 0; - size_t avail = sb->size - sb->rdoff; - if (size > avail) - size = avail; - memcpy(sb->data + sb->rdoff, buf, size); - sb->rdoff += size; - return size; -} - -static char* tnt_buf_resize(struct tnt_stream *s, size_t size) { - struct tnt_stream_buf *sb = TNT_SBUF_CAST(s); - size_t off = sb->size; - size_t nsize = off + size; - char *nd = realloc(sb->data, nsize); - if (nd == NULL) { - free(sb->data); - return NULL; - } - sb->data = nd; - sb->size = nsize; - return sb->data + off; -} - -static ssize_t -tnt_buf_write(struct tnt_stream *s, const char *buf, size_t size) { - char *p = tnt_buf_resize(s, size); - if (p == NULL) - return -1; - memcpy(p, buf, size); - s->wrcnt++; - return size; -} - -static ssize_t -tnt_buf_writev(struct tnt_stream *s, struct iovec *iov, int count) { - size_t size = 0; - int i; - for (i = 0 ; i < count ; i++) - size += iov[i].iov_len; - char *p = tnt_buf_resize(s, size); - if (p == NULL) - return -1; - for (i = 0 ; i < count ; i++) { - memcpy(p, iov[i].iov_base, iov[i].iov_len); - p += iov[i].iov_len; - } - s->wrcnt++; - return size; -} - -static ssize_t -tnt_buf_write_request(struct tnt_stream *s, struct tnt_request *r) { - return tnt_buf_writev(s, r->v, r->vc); -} - -static int -tnt_buf_reply(struct tnt_stream *s, struct tnt_reply *r) { - struct tnt_stream_buf *sb = TNT_SBUF_CAST(s); - if (sb->data == NULL) - return -1; - if (sb->size == sb->rdoff) - return 1; - size_t off = 0; - int rc = tnt_reply(r, sb->data + sb->rdoff, sb->size - sb->rdoff, &off); - if (rc == 0) - sb->rdoff += off; - return rc; -} - -static int -tnt_buf_request(struct tnt_stream *s, struct tnt_request *r) { - struct tnt_stream_buf *sb = TNT_SBUF_CAST(s); - if (sb->data == NULL) - return -1; - if (sb->size == sb->rdoff) - return 1; - size_t off = 0; - int rc = tnt_request(r, sb->data + sb->rdoff, sb->size - sb->rdoff, - &off, NULL); - if (rc == 0) - sb->rdoff += off; - return rc; -} - -/* - * tnt_buf() - * - * create and initialize buffer stream; - * - * s - stream pointer, maybe NULL - * - * if stream pointer is NULL, then new stream will be created. - * - * returns stream pointer, or NULL on error. -*/ -struct tnt_stream *tnt_buf(struct tnt_stream *s) { - int allocated = s == NULL; - s = tnt_stream_init(s); - if (s == NULL) - return NULL; - /* allocating stream data */ - s->data = tnt_mem_alloc(sizeof(struct tnt_stream_buf)); - if (s->data == NULL) { - if (allocated) - tnt_stream_free(s); - return NULL; - } - /* initializing interfaces */ - s->read = tnt_buf_read; - s->read_reply = tnt_buf_reply; - s->read_request = tnt_buf_request; - s->read_tuple = NULL; - s->write = tnt_buf_write; - s->writev = tnt_buf_writev; - s->write_request = tnt_buf_write_request; - s->free = tnt_buf_free; - /* initializing internal data */ - struct tnt_stream_buf *sb = TNT_SBUF_CAST(s); - sb->rdoff = 0; - sb->size = 0; - sb->data = NULL; - return s; -} diff --git a/connector/c/tnt/tnt_call.c b/connector/c/tnt/tnt_call.c deleted file mode 100644 index fbaeabd77c..0000000000 --- a/connector/c/tnt/tnt_call.c +++ /dev/null @@ -1,94 +0,0 @@ - -/* - * 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 <stdlib.h> -#include <stdint.h> -#include <string.h> - -#include <connector/c/include/tarantool/tnt_proto.h> -#include <connector/c/include/tarantool/tnt_enc.h> -#include <connector/c/include/tarantool/tnt_tuple.h> -#include <connector/c/include/tarantool/tnt_request.h> -#include <connector/c/include/tarantool/tnt_reply.h> -#include <connector/c/include/tarantool/tnt_stream.h> -#include <connector/c/include/tarantool/tnt_call.h> - -/* - * tnt_call() - * - * write call request to stream; - * - * s - stream pointer - * flags - request flags - * proc - remote procedure name - * args - call arguments - * - * returns number of bytes written, or -1 on error. -*/ -ssize_t -tnt_call(struct tnt_stream *s, uint32_t flags, const char *proc, - struct tnt_tuple *args) -{ - /* encoding procedure name */ - int proc_len = strlen(proc); - int proc_enc_size = tnt_enc_size(proc_len); - char proc_enc[5]; - tnt_enc_write(proc_enc, proc_len); - /* filling major header */ - struct tnt_header hdr; - hdr.type = TNT_OP_CALL; - hdr.len = sizeof(struct tnt_header_call) + - proc_enc_size + proc_len + args->size; - if (args->size == 0) - hdr.len += 4; - hdr.reqid = s->reqid; - /* filling call header */ - struct tnt_header_call hdr_call; - hdr_call.flags = flags; - /* writing data to stream */ - struct iovec v[5]; - v[0].iov_base = (void *)&hdr; - v[0].iov_len = sizeof(struct tnt_header); - v[1].iov_base = (void *)&hdr_call; - v[1].iov_len = sizeof(struct tnt_header_call); - v[2].iov_base = proc_enc; - v[2].iov_len = proc_enc_size; - v[3].iov_base = (void *)proc; - v[3].iov_len = proc_len; - uint32_t argc = 0; - if (args->size == 0) { - v[4].iov_base = (void *)&argc; - v[4].iov_len = 4; - } else { - v[4].iov_base = args->data; - v[4].iov_len = args->size; - } - return s->writev(s, v, 5); -} diff --git a/connector/c/tnt/tnt_delete.c b/connector/c/tnt/tnt_delete.c deleted file mode 100644 index 0fec8ec217..0000000000 --- a/connector/c/tnt/tnt_delete.c +++ /dev/null @@ -1,75 +0,0 @@ - -/* - * 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 <stdlib.h> -#include <stdint.h> -#include <string.h> - -#include <connector/c/include/tarantool/tnt_proto.h> -#include <connector/c/include/tarantool/tnt_tuple.h> -#include <connector/c/include/tarantool/tnt_request.h> -#include <connector/c/include/tarantool/tnt_reply.h> -#include <connector/c/include/tarantool/tnt_stream.h> -#include <connector/c/include/tarantool/tnt_delete.h> - -/* - * tnt_delete() - * - * write delete request to stream; - * - * s - stream pointer - * ns - space - * flags - request flags - * k - tuple key - * - * returns number of bytes written, or -1 on error. -*/ -ssize_t -tnt_delete(struct tnt_stream *s, uint32_t ns, uint32_t flags, struct tnt_tuple *k) -{ - /* filling major header */ - struct tnt_header hdr; - hdr.type = TNT_OP_DELETE; - hdr.len = sizeof(struct tnt_header_delete) + k->size; - hdr.reqid = s->reqid; - /* filling delete header */ - struct tnt_header_delete hdr_del; - hdr_del.ns = ns; - hdr_del.flags = flags; - /* writing data to stream */ - struct iovec v[3]; - v[0].iov_base = (void *)&hdr; - v[0].iov_len = sizeof(struct tnt_header); - v[1].iov_base = (void *)&hdr_del; - v[1].iov_len = sizeof(struct tnt_header_delete); - v[2].iov_base = k->data; - v[2].iov_len = k->size; - return s->writev(s, v, 3); -} diff --git a/connector/c/tnt/tnt_enc.c b/connector/c/tnt/tnt_enc.c deleted file mode 100644 index 1db0c23627..0000000000 --- a/connector/c/tnt/tnt_enc.c +++ /dev/null @@ -1,103 +0,0 @@ - -/* - * 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 <stdlib.h> -#include <stdint.h> -#include <string.h> - -#include <connector/c/include/tarantool/tnt_enc.h> - -int -tnt_enc_read(const char *buf, uint32_t *value) -{ - *value = 0; - if (!(buf[0] & 0x80)) { - *value = buf[0] & 0x7f; - return 1; - } - if (!(buf[1] & 0x80)) { - *value = (buf[0] & 0x7f) << 7 | - (buf[1] & 0x7f); - return 2; - } - if (!(buf[2] & 0x80)) { - *value = (buf[0] & 0x7f) << 14 | - (buf[1] & 0x7f) << 7 | - (buf[2] & 0x7f); - return 3; - } - if (!(buf[3] & 0x80)) { - *value = (buf[0] & 0x7f) << 21 | - (buf[1] & 0x7f) << 14 | - (buf[2] & 0x7f) << 7 | - (buf[3] & 0x7f); - return 4; - } - if (!(buf[4] & 0x80)) { - *value = (buf[0] & 0x7f) << 28 | - (buf[1] & 0x7f) << 21 | - (buf[2] & 0x7f) << 14 | - (buf[3] & 0x7f) << 7 | - (buf[4] & 0x7f); - return 5; - } - return -1; -} - -void -tnt_enc_write(char *buf, uint32_t value) -{ - if (value >= (1 << 7)) { - if (value >= (1 << 14)) { - if (value >= (1 << 21)) { - if (value >= (1 << 28)) - *(buf++) = (value >> 28) | 0x80; - *(buf++) = (value >> 21) | 0x80; - } - *(buf++) = ((value >> 14) | 0x80); - } - *(buf++) = ((value >> 7) | 0x80); - } - *(buf++) = ((value) & 0x7F); -} - -int -tnt_enc_size(uint32_t value) -{ - if (value < (1 << 7)) - return 1; - if (value < (1 << 14)) - return 2; - if (value < (1 << 21)) - return 3; - if (value < (1 << 28)) - return 4; - return 5; -} diff --git a/connector/c/tnt/tnt_insert.c b/connector/c/tnt/tnt_insert.c deleted file mode 100644 index 4fcfbca408..0000000000 --- a/connector/c/tnt/tnt_insert.c +++ /dev/null @@ -1,76 +0,0 @@ - -/* - * 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 <stdlib.h> -#include <stdint.h> -#include <string.h> - -#include <connector/c/include/tarantool/tnt_proto.h> -#include <connector/c/include/tarantool/tnt_tuple.h> -#include <connector/c/include/tarantool/tnt_request.h> -#include <connector/c/include/tarantool/tnt_reply.h> -#include <connector/c/include/tarantool/tnt_stream.h> -#include <connector/c/include/tarantool/tnt_insert.h> - -/* - * tnt_insert() - * - * write insert request to stream; - * - * s - stream pointer - * ns - space - * flags - request flags - * kv - tuple key-value - * - * returns number of bytes written, or -1 on error. -*/ -ssize_t -tnt_insert(struct tnt_stream *s, uint32_t ns, uint32_t flags, - struct tnt_tuple *kv) -{ - /* filling major header */ - struct tnt_header hdr; - hdr.type = TNT_OP_INSERT; - hdr.len = sizeof(struct tnt_header_insert) + kv->size; - hdr.reqid = s->reqid; - /* filling insert header */ - struct tnt_header_insert hdr_insert; - hdr_insert.ns = ns; - hdr_insert.flags = flags; - /* writing data to stream */ - struct iovec v[3]; - v[0].iov_base = (void *)&hdr; - v[0].iov_len = sizeof(struct tnt_header); - v[1].iov_base = (void *)&hdr_insert; - v[1].iov_len = sizeof(struct tnt_header_insert); - v[2].iov_base = kv->data; - v[2].iov_len = kv->size; - return s->writev(s, v, 3); -} diff --git a/connector/c/tnt/tnt_iter.c b/connector/c/tnt/tnt_iter.c deleted file mode 100644 index 135850126b..0000000000 --- a/connector/c/tnt/tnt_iter.c +++ /dev/null @@ -1,389 +0,0 @@ - -/* - * 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 <stdlib.h> -#include <stdint.h> -#include <string.h> - -#include <connector/c/include/tarantool/tnt_mem.h> -#include <connector/c/include/tarantool/tnt_proto.h> -#include <connector/c/include/tarantool/tnt_enc.h> -#include <connector/c/include/tarantool/tnt_tuple.h> -#include <connector/c/include/tarantool/tnt_request.h> -#include <connector/c/include/tarantool/tnt_reply.h> -#include <connector/c/include/tarantool/tnt_stream.h> -#include <connector/c/include/tarantool/tnt_iter.h> - -static struct tnt_iter *tnt_iter_init(struct tnt_iter *i) { - if (i) { - memset(i, 0, sizeof(struct tnt_iter)); - return i; - } - i = tnt_mem_alloc(sizeof(struct tnt_iter)); - if (i == NULL) - return NULL; - memset(i, 0, sizeof(struct tnt_iter)); - i->alloc = 1; - i->status = TNT_ITER_OK; - return i; -} - -static int tnt_iter_field_next(struct tnt_iter *i) { - struct tnt_iter_field *ip = TNT_IFIELD(i); - /* initializing iter to the first field */ - if (ip->fld_ptr == NULL) { - /* in case of insufficient data */ - if (ip->tu->size < 4) { - i->status = TNT_ITER_FAIL; - return 0; - } - /* tuple could be empty */ - if (ip->tu->size == 4) { - if (ip->tu->cardinality != 0) - i->status = TNT_ITER_FAIL; - return 0; - } - ip->fld_ptr = ip->tu->data + 4; /* skipping tuple cardinality */ - ip->fld_index = 0; - ip->fld_esize = tnt_enc_read(ip->fld_ptr, &ip->fld_size); - if (ip->fld_esize == -1) { - i->status = TNT_ITER_FAIL; - return 0; - } - ip->fld_data = ip->fld_ptr + ip->fld_esize; - return 1; - } else - if (ip->tu->cardinality == (ip->fld_index + 1)) /* checking end */ - return 0; - /* skipping to the next field */ - ip->fld_ptr += ip->fld_esize + ip->fld_size; - ip->fld_index++; - /* reading field size */ - ip->fld_esize = tnt_enc_read(ip->fld_ptr, &ip->fld_size); - if (ip->fld_esize == -1) { - i->status = TNT_ITER_FAIL; - return 0; - } - ip->fld_data = ip->fld_ptr + ip->fld_esize; - return 1; -} - -static void tnt_iter_field_rewind(struct tnt_iter *i) { - struct tnt_iter_field *ip = TNT_IFIELD(i); - ip->fld_ptr = NULL; - ip->fld_index = 0; - ip->fld_data = NULL; - ip->fld_size = 0; - ip->fld_esize = 0; -} - -/* - * tnt_iter() - * - * initialize tuple field iterator; - * create and initialize tuple field iterator; - * - * i - tuple field iterator pointer, maybe NULL - * t - tuple pointer - * - * if tuple field iterator pointer is NULL, then new tuple iterator will be created. - * - * returns tuple iterator pointer, or NULL on error. -*/ -struct tnt_iter* -tnt_iter(struct tnt_iter *i, struct tnt_tuple *t) -{ - i = tnt_iter_init(i); - if (i == NULL) - return NULL; - i->type = TNT_ITER_FIELD; - i->next = tnt_iter_field_next; - i->rewind = tnt_iter_field_rewind; - i->free = NULL; - struct tnt_iter_field *ip = TNT_IFIELD(i); - ip->tu = t; - return i; -} - -static int tnt_iter_list_next(struct tnt_iter *i) { - struct tnt_iter_list *il = TNT_ILIST(i); - if (il->tu_index == il->l->count) - return 0; - il->tu = il->l->list[il->tu_index++].ptr; - return 1; -} - -static void tnt_iter_list_rewind(struct tnt_iter *i) { - struct tnt_iter_list *il = TNT_ILIST(i); - il->tu_index = 0; -} - -/* - * tnt_iter_list() - * - * initialize tuple list iterator; - * create and initialize tuple list iterator; - * - * i - tuple list iterator pointer, maybe NULL - * t - tuple list pointer - * - * if tuple list iterator pointer is NULL, then new tuple list - * iterator will be created. - * - * returns tuple list iterator pointer, or NULL on error. -*/ -struct tnt_iter* -tnt_iter_list(struct tnt_iter *i, struct tnt_list *l) -{ - i = tnt_iter_init(i); - if (i == NULL) - return NULL; - i->type = TNT_ITER_LIST; - i->next = tnt_iter_list_next; - i->rewind = tnt_iter_list_rewind; - i->free = NULL; - struct tnt_iter_list *il = TNT_ILIST(i); - il->l = l; - return i; -} - -static int tnt_iter_reply_next(struct tnt_iter *i) { - struct tnt_iter_reply *ir = TNT_IREPLY(i); - tnt_reply_free(&ir->r); - tnt_reply_init(&ir->r); - int rc = ir->s->read_reply(ir->s, &ir->r); - if (rc == -1) { - i->status = TNT_ITER_FAIL; - return 0; - } - return (rc == 1 /* finish */ ) ? 0 : 1; -} - -static void tnt_iter_reply_free(struct tnt_iter *i) { - struct tnt_iter_reply *ir = TNT_IREPLY(i); - tnt_reply_free(&ir->r); -} - -/* - * tnt_iter_reply() - * - * initialize tuple reply iterator; - * create and initialize reply iterator; - * - * i - tuple reply iterator pointer, maybe NULL - * s - stream pointer - * - * if stream iterator pointer is NULL, then new stream - * iterator will be created. - * - * returns stream iterator pointer, or NULL on error. -*/ -struct tnt_iter *tnt_iter_reply(struct tnt_iter *i, struct tnt_stream *s) { - i = tnt_iter_init(i); - if (i == NULL) - return NULL; - i->type = TNT_ITER_REPLY; - i->next = tnt_iter_reply_next; - i->rewind = NULL; - i->free = tnt_iter_reply_free; - struct tnt_iter_reply *ir = TNT_IREPLY(i); - ir->s = s; - tnt_reply_init(&ir->r); - return i; -} - -static int tnt_iter_request_next(struct tnt_iter *i) { - struct tnt_iter_request *ir = TNT_IREQUEST(i); - tnt_request_free(&ir->r); - tnt_request_init(&ir->r); - int rc = ir->s->read_request(ir->s, &ir->r); - if (rc == -1) { - i->status = TNT_ITER_FAIL; - return 0; - } - return (rc == 1 /* finish */ ) ? 0 : 1; -} - -static void tnt_iter_request_free(struct tnt_iter *i) { - struct tnt_iter_request *ir = TNT_IREQUEST(i); - tnt_request_free(&ir->r); -} - -/* - * tnt_iter_request() - * - * initialize tuple request iterator; - * create and initialize request iterator; - * - * i - tuple request iterator pointer, maybe NULL - * s - stream pointer - * - * if stream iterator pointer is NULL, then new stream - * iterator will be created. - * - * returns stream iterator pointer, or NULL on error. -*/ -struct tnt_iter *tnt_iter_request(struct tnt_iter *i, struct tnt_stream *s) { - i = tnt_iter_init(i); - if (i == NULL) - return NULL; - i->type = TNT_ITER_REQUEST; - i->next = tnt_iter_request_next; - i->rewind = NULL; - i->free = tnt_iter_request_free; - struct tnt_iter_request *ir = TNT_IREQUEST(i); - ir->s = s; - tnt_request_init(&ir->r); - return i; -} - -static int tnt_iter_storage_next(struct tnt_iter *i) { - struct tnt_iter_storage *is = TNT_ISTORAGE(i); - tnt_tuple_free(&is->t); - tnt_tuple_init(&is->t); - - int rc = is->s->read_tuple(is->s, &is->t); - if (rc == -1) { - i->status = TNT_ITER_FAIL; - return 0; - } - return (rc == 1 /* finish */ ) ? 0 : 1; -} - -static void tnt_iter_storage_free(struct tnt_iter *i) { - struct tnt_iter_storage *is = TNT_ISTORAGE(i); - tnt_tuple_free(&is->t); -} - -/* - * tnt_iter_storage() - * - * initialize tuple storage iterator; - * create and initialize storage iterator; - * - * i - tuple storage iterator pointer, maybe NULL - * s - stream pointer - * - * if stream iterator pointer is NULL, then new stream - * iterator will be created. - * - * returns stream iterator pointer, or NULL on error. -*/ -struct tnt_iter *tnt_iter_storage(struct tnt_iter *i, struct tnt_stream *s) { - i = tnt_iter_init(i); - if (i == NULL) - return NULL; - i->type = TNT_ITER_STORAGE; - i->next = tnt_iter_storage_next; - i->rewind = NULL; - i->free = tnt_iter_storage_free; - struct tnt_iter_storage *is = TNT_ISTORAGE(i); - is->s = s; - tnt_tuple_init(&is->t); - return i; -} - -/* - * tnt_iter_free() - * - * free iterator. - * - * i - iterator pointer - * -*/ -void tnt_iter_free(struct tnt_iter *i) { - if (i->free) - i->free(i); - if (i->alloc) - tnt_mem_free(i); -} - -/* - * tnt_next() - * - * iterates to next field; - * iterates to tuple in list; - * - * i - iterator pointer - * - * depend on iterator tuple, sets to the - * next tuple field or next tuple in the list. - * - * returns 1 or 0 on end. -*/ -int tnt_next(struct tnt_iter *i) { - return i->next(i); -} - -/* - * tnt_rewind() - * - * iterates to first field; - * iterates to first tuple in a list; - * - * i - iterator pointer - * - * depend on iterator tuple, sets to the - * first tuple field or first tuple in a list. -*/ -void tnt_rewind(struct tnt_iter *i) { - i->status = TNT_ITER_OK; - if (i->rewind) - i->rewind(i); -} - -/* - * tnt_field() - * - * set or create iterator to the specified tuple field; - * - * i - tuple iterator pointer - * t - tuple pointer - * index - tuple field index - * - * returns tuple iterator pointer if field found, NULL otherwise. -*/ -struct tnt_iter* -tnt_field(struct tnt_iter *i, struct tnt_tuple *t, uint32_t index) -{ - int allocated = i == NULL; - if (i == NULL) { - i = tnt_iter(i, t); - if (i == NULL) - return NULL; - } else - tnt_rewind(i); - while (tnt_next(i)) - if (TNT_IFIELD_IDX(i) == index) - return i; - if (allocated) - tnt_iter_free(i); - return NULL; -} diff --git a/connector/c/tnt/tnt_mem.c b/connector/c/tnt/tnt_mem.c deleted file mode 100644 index 670c02e444..0000000000 --- a/connector/c/tnt/tnt_mem.c +++ /dev/null @@ -1,66 +0,0 @@ - -/* - * 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 <stdlib.h> -#include <stdio.h> -#include <string.h> - -#include <connector/c/include/tarantool/tnt_mem.h> - -static void *(*_tnt_realloc)(void *ptr, size_t size) = - (void *(*)(void*, size_t))realloc; - -void *tnt_mem_init(tnt_allocator_t alloc) { - void *ptr = _tnt_realloc; - if (alloc) - _tnt_realloc = alloc; - return ptr; -} - -void *tnt_mem_alloc(size_t size) { - return _tnt_realloc(NULL, size); -} - -void *tnt_mem_realloc(void *ptr, size_t size) { - return _tnt_realloc(ptr, size); -} - -char *tnt_mem_dup(char *sz) { - size_t len = strlen(sz); - char *szp = tnt_mem_alloc(len + 1); - if (szp == NULL) - return NULL; - memcpy(szp, sz, len + 1); - return szp; -} - -void tnt_mem_free(void *ptr) { - _tnt_realloc(ptr, 0); -} diff --git a/connector/c/tnt/tnt_ping.c b/connector/c/tnt/tnt_ping.c deleted file mode 100644 index 15fb4bae20..0000000000 --- a/connector/c/tnt/tnt_ping.c +++ /dev/null @@ -1,64 +0,0 @@ - -/* - * 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 <stdlib.h> -#include <stdint.h> -#include <string.h> - -#include <connector/c/include/tarantool/tnt_proto.h> -#include <connector/c/include/tarantool/tnt_tuple.h> -#include <connector/c/include/tarantool/tnt_request.h> -#include <connector/c/include/tarantool/tnt_reply.h> -#include <connector/c/include/tarantool/tnt_stream.h> -#include <connector/c/include/tarantool/tnt_ping.h> - -/* - * tnt_ping() - * - * write ping request to stream; - * - * s - stream pointer - * - * returns number of bytes written, or -1 on error. -*/ -ssize_t -tnt_ping(struct tnt_stream *s) -{ - /* filling major header */ - struct tnt_header hdr; - hdr.type = TNT_OP_PING; - hdr.len = 0; - hdr.reqid = s->reqid; - /* writing data to stream */ - struct iovec v[1]; - v[0].iov_base = (void*)&hdr; - v[0].iov_len = sizeof(struct tnt_header); - return s->writev(s, v, 1); -} diff --git a/connector/c/tnt/tnt_reply.c b/connector/c/tnt/tnt_reply.c deleted file mode 100644 index 14a03da2f2..0000000000 --- a/connector/c/tnt/tnt_reply.c +++ /dev/null @@ -1,216 +0,0 @@ - -/* - * 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 <stdlib.h> -#include <stdint.h> -#include <string.h> - -#include <connector/c/include/tarantool/tnt_mem.h> -#include <connector/c/include/tarantool/tnt_tuple.h> -#include <connector/c/include/tarantool/tnt_proto.h> -#include <connector/c/include/tarantool/tnt_reply.h> - -/* - * tnt_reply_init() - * - * initialize reply object; - * - * r - reply object pointer -*/ -void tnt_reply_init(struct tnt_reply *r) { - memset(r, 0, sizeof(struct tnt_reply)); -} - -/* - * tnt_reply_free() - * - * free reply object; - * - * r - reply object pointer -*/ -void tnt_reply_free(struct tnt_reply *r) { - if (r->error) - tnt_mem_free(r->error); - tnt_list_free(&r->tuples); -} - -/* - * tnt_reply_from() - * - * process iproto reply with supplied recv function; - * - * r - reply object pointer - * rcv - supplied recv function - * ptr - recv function argument - * - * returns zero on fully read reply, or -1 on error. -*/ -int tnt_reply_from(struct tnt_reply *r, tnt_reply_t rcv, void *ptr) { - /* reading iproto header */ - struct tnt_header hdr; - if (rcv(ptr, (char*)&hdr, sizeof(struct tnt_header)) == -1) - return -1; - uint32_t size = hdr.len; - - tnt_list_init(&r->tuples); - r->count = 0; - r->error = NULL; - r->reqid = hdr.reqid; - r->code = 0; - r->op = hdr.type; - - /* ping is the simplest case */ - if (r->op == TNT_OP_PING) - return 0; - - /* reading code */ - if (rcv(ptr, (char*)&r->code, sizeof(r->code)) == -1) - return -1; - size -= 4; - - /* error handling */ - if (r->code != 0) { - r->error = tnt_mem_alloc(size); - if (r->error == NULL) - return -1; - if (rcv(ptr, r->error, size) == -1) { - tnt_mem_free(r->error); - return -1; - } - return 0; - } - - /* checking validity of the operation */ - if (r->op != TNT_OP_INSERT && - r->op != TNT_OP_UPDATE && - r->op != TNT_OP_DELETE && - r->op != TNT_OP_SELECT && - r->op != TNT_OP_CALL) - return -1; - - /* code only (BOX_QUIET flag) */ - if (size == 0) - return 0; - - /* reading count */ - if (rcv(ptr, (char*)&r->count, sizeof(r->count)) == -1) - return -1; - size -= 4; - - /* count only */ - if (size == 0) - return 0; - - /* allocating and reading data */ - char *buf = tnt_mem_alloc(size); - if (buf == NULL) - return -1; - if (rcv(ptr, buf, size) == -1) { - tnt_mem_free(buf); - return -1; - } - char *p = buf; - - /* processing tuples */ - uint32_t total = 0; - uint32_t i; - for (i = 0 ; i < r->count ; i++) { - uint32_t tsize = *(uint32_t*)(p); /* tuple size */ - if (tsize > (size - total)) - goto rollback; - p += 4; - /* [count, enc0, data0, ...] */ - struct tnt_tuple *t = tnt_tuple_set(NULL, p, tsize + 4 /* count */); - if (t == NULL) - goto rollback; - tnt_list_at(&r->tuples, t); - p += tsize + 4; - total += (4 + 4 + tsize); /* length + cardinality + tuple size */ - } - tnt_mem_free(buf); - return 0; - -rollback: - tnt_list_free(&r->tuples); - tnt_mem_free(buf); - return -1; -} - -/* - * tnt_reply() - * - * process buffer as iproto reply; - * - * r - reply object pointer - * buf - buffer data pointer - * size - buffer data size - * off - returned offset, maybe NULL - * - * if reply is fully read, then zero is returned and offset set to the - * end of reply data in buffer. - * - * if reply is not complete, then 1 is returned and offset set to the - * size needed to read. - * - * if there were error while parsing reply, -1 is returned. - * - * returns zero on fully read reply, or NULL on error. -*/ -static ssize_t tnt_reply_cb(void *ptr[2], char *buf, ssize_t size) { - char *src = ptr[0]; - ssize_t *off = ptr[1]; - memcpy(buf, src + *off, size); - *off += size; - return size; -} - -int -tnt_reply(struct tnt_reply *r, char *buf, size_t size, size_t *off) { - /* supplied buffer must contain full reply, - * if it doesn't then returning count of bytes - * needed to process */ - if (size < (sizeof(struct tnt_header))) { - if (off) - *off = sizeof(struct tnt_header) - size; - return 1; - } - struct tnt_header *hdr = (struct tnt_header*)buf; - if (size < sizeof(struct tnt_header) + hdr->len) { - if (off) - *off = (sizeof(struct tnt_header) + hdr->len) - size; - return 1; - } - size_t offv = 0; - void *ptr[2] = { buf, &offv }; - int rc = tnt_reply_from(r, (tnt_reply_t)tnt_reply_cb, ptr); - if (off) - *off = offv; - return rc; -} diff --git a/connector/c/tnt/tnt_request.c b/connector/c/tnt/tnt_request.c deleted file mode 100644 index 55891354cc..0000000000 --- a/connector/c/tnt/tnt_request.c +++ /dev/null @@ -1,507 +0,0 @@ - -/* - * 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 <stdlib.h> -#include <stdint.h> -#include <string.h> - -#include <connector/c/include/tarantool/tnt_mem.h> -#include <connector/c/include/tarantool/tnt_proto.h> -#include <connector/c/include/tarantool/tnt_enc.h> -#include <connector/c/include/tarantool/tnt_tuple.h> -#include <connector/c/include/tarantool/tnt_proto.h> -#include <connector/c/include/tarantool/tnt_request.h> - -/* - * tnt_request_init() - * - * initialize request object; - * - * r - reply pointer -*/ -void -tnt_request_init(struct tnt_request *r) -{ - memset(r, 0, sizeof(struct tnt_request)); -} - -/* - * tnt_request_free() - * - * free request object; - * - * r - request object pointer -*/ -void -tnt_request_free(struct tnt_request *r) -{ - switch (r->h.type) { - case TNT_OP_INSERT: - tnt_tuple_free(&r->r.insert.t); - break; - case TNT_OP_DELETE_1_3: - tnt_tuple_free(&r->r.del_1_3.t); - break; - case TNT_OP_DELETE: - tnt_tuple_free(&r->r.del.t); - break; - case TNT_OP_CALL: - if (r->r.call.proc) { - tnt_mem_free(r->r.call.proc); - r->r.call.proc = NULL; - } - tnt_tuple_free(&r->r.call.t); - break; - case TNT_OP_SELECT: - tnt_list_free(&r->r.select.l); - break; - case TNT_OP_UPDATE: - tnt_tuple_free(&r->r.update.t); - if (r->r.update.ops) { - tnt_mem_free(r->r.update.ops); - r->r.update.ops = NULL; - } - if (r->r.update.opv) { - tnt_mem_free(r->r.update.opv); - r->r.update.opv = NULL; - } - break; - case TNT_OP_PING: - break; - } - if (r->v) { - tnt_mem_free(r->v); - r->v = NULL; - } - if (r->origin) { - tnt_mem_free(r->origin); - r->origin = NULL; - } -} - -/* - * tnt_request_setorigin() - * - * set buffer of request source, free it with request free; - * - * r - request object pointer - * buf - supplied buffer - * size - buffer size -*/ -void -tnt_request_setorigin(struct tnt_request *r, char *buf, size_t size) { - r->origin = buf; - r->origin_size = size; -} - -static int -tnt_request_insert(struct tnt_request *r, tnt_request_t rcv, void *ptr) -{ - if (rcv(ptr, (char*)&r->r.insert, sizeof(struct tnt_header_insert)) == -1) - return -1; - uint32_t size = r->h.len - sizeof(struct tnt_header_insert); - char *buf = tnt_mem_alloc(size); - if (buf == NULL) - return -1; - if (rcv(ptr, buf, size) == -1) { - tnt_mem_free(buf); - return -1; - } - if (tnt_tuple_set(&r->r.insert.t, buf, size) == NULL) { - tnt_mem_free(buf); - return -1; - } - /* creating resend io vector */ - r->vc = 3; - r->v = tnt_mem_alloc(r->vc * sizeof(struct iovec)); - if (r->v == NULL) { - tnt_tuple_free(&r->r.insert.t); - tnt_mem_free(buf); - return -1; - } - r->v[0].iov_base = (void *)&r->h; - r->v[0].iov_len = sizeof(struct tnt_header); - r->v[1].iov_base = (void *)&r->r.insert.h; - r->v[1].iov_len = sizeof(struct tnt_header_insert); - r->v[2].iov_base = r->r.insert.t.data; - r->v[2].iov_len = r->r.insert.t.size; - tnt_mem_free(buf); - return 0; -} - -static int -tnt_request_delete_1_3(struct tnt_request *r, tnt_request_t rcv, void *ptr) -{ - if (rcv(ptr, (char*)&r->r.del_1_3, sizeof(struct tnt_header_delete_1_3)) == -1) - return -1; - uint32_t size = r->h.len - sizeof(struct tnt_header_delete_1_3); - char *buf = tnt_mem_alloc(size); - if (buf == NULL) - return -1; - if (rcv(ptr, buf, size) == -1) { - tnt_mem_free(buf); - return -1; - } - if (tnt_tuple_set(&r->r.del_1_3.t, buf, size) == NULL) { - tnt_mem_free(buf); - return -1; - } - /* creating resend io vector */ - r->vc = 3; - r->v = tnt_mem_alloc(r->vc * sizeof(struct iovec)); - if (r->v == NULL) { - tnt_tuple_free(&r->r.del_1_3.t); - tnt_mem_free(buf); - return -1; - } - r->v[0].iov_base = (void *)&r->h; - r->v[0].iov_len = sizeof(struct tnt_header); - r->v[1].iov_base = (void *)&r->r.del_1_3.h; - r->v[1].iov_len = sizeof(struct tnt_header_delete_1_3); - r->v[2].iov_base = r->r.del_1_3.t.data; - r->v[2].iov_len = r->r.del_1_3.t.size; - tnt_mem_free(buf); - return 0; -} - -static int -tnt_request_delete(struct tnt_request *r, tnt_request_t rcv, void *ptr) -{ - if (rcv(ptr, (char*)&r->r.del, sizeof(struct tnt_header_delete)) == -1) - return -1; - uint32_t size = r->h.len - sizeof(struct tnt_header_delete); - char *buf = tnt_mem_alloc(size); - if (buf == NULL) - return -1; - if (rcv(ptr, buf, size) == -1) { - tnt_mem_free(buf); - return -1; - } - if (tnt_tuple_set(&r->r.del.t, buf, size) == NULL) { - tnt_mem_free(buf); - return -1; - } - /* creating resend io vector */ - r->vc = 3; - r->v = tnt_mem_alloc(r->vc * sizeof(struct iovec)); - if (r->v == NULL) { - tnt_tuple_free(&r->r.del.t); - tnt_mem_free(buf); - return -1; - } - r->v[0].iov_base = (void *)&r->h; - r->v[0].iov_len = sizeof(struct tnt_header); - r->v[1].iov_base = (void *)&r->r.del.h; - r->v[1].iov_len = sizeof(struct tnt_header_delete); - r->v[2].iov_base = r->r.del.t.data; - r->v[2].iov_len = r->r.del.t.size; - tnt_mem_free(buf); - return 0; -} - -static int -tnt_request_call(struct tnt_request *r, tnt_request_t rcv, void *ptr) -{ - if (rcv(ptr, (char*)&r->r.call, sizeof(struct tnt_header_call)) == -1) - return -1; - uint32_t size = r->h.len - sizeof(struct tnt_header_call); - char *buf = tnt_mem_alloc(size); - if (buf == NULL) - goto error; - if (rcv(ptr, buf, size) == -1) - goto error; - int esize = tnt_enc_read(buf, &r->r.call.proc_len); - if (esize == -1 || esize >= 5) - goto error; - memcpy(r->r.call.proc_enc, buf, esize); - /* function name */ - r->r.call.proc_enc_len = esize; - r->r.call.proc = tnt_mem_alloc(r->r.call.proc_len + 1); - if (r->r.call.proc == NULL) - goto error; - memcpy(r->r.call.proc, buf + esize, r->r.call.proc_len); - r->r.call.proc[r->r.call.proc_len] = 0; - /* function arguments */ - size -= esize + r->r.call.proc_len; - if (tnt_tuple_set(&r->r.call.t, buf + esize + r->r.call.proc_len, size) == NULL) { - tnt_mem_free(r->r.call.proc); - r->r.call.proc = NULL; - goto error; - } - /* creating resend io vector */ - r->vc = 5; - r->v = tnt_mem_alloc(r->vc * sizeof(struct iovec)); - if (r->v == NULL) - goto error; - r->v[0].iov_base = (void *)&r->h; - r->v[0].iov_len = sizeof(struct tnt_header); - r->v[1].iov_base = (void *)&r->r.call.h; - r->v[1].iov_len = sizeof(struct tnt_header_call); - r->v[2].iov_base = r->r.call.proc_enc; - r->v[2].iov_len = r->r.call.proc_enc_len; - r->v[3].iov_base = r->r.call.proc; - r->v[3].iov_len = r->r.call.proc_len; - r->v[4].iov_base = r->r.call.t.data; - r->v[4].iov_len = r->r.call.t.size; - tnt_mem_free(buf); - return 0; -error: - tnt_tuple_free(&r->r.call.t); - if (buf) - tnt_mem_free(buf); - return -1; -} - -static int -tnt_request_select(struct tnt_request *r, tnt_request_t rcv, void *ptr) -{ - if (rcv(ptr, (char*)&r->r.select, sizeof(struct tnt_header_select)) == -1) - return -1; - uint32_t size = r->h.len - sizeof(struct tnt_header_select); - char *buf = tnt_mem_alloc(size); - if (buf == NULL) - goto error; - if (rcv(ptr, buf, size) == -1) - goto error; - /* count of tuples */ - uint32_t i, count = *(uint32_t*)buf; - uint32_t off = 4; - /* processing tuples */ - tnt_list_init(&r->r.select.l); - for (i = 0 ; i < count ; i++) { - /* calculating tuple size */ - uint32_t j, cardinality = *(uint32_t*)(buf + off); - uint32_t size = 4; - for (j = 0 ; j < cardinality ; j++) { - uint32_t fld_size = 0; - int fld_esize = tnt_enc_read(buf + off + size, &fld_size); - if (fld_esize == -1) - goto error; - size += fld_esize + fld_size; - } - /* initializing tuple and adding to list */ - struct tnt_tuple *tu = tnt_list_at(&r->r.select.l, NULL); - if (tnt_tuple_set(tu, buf + off, size) == NULL) - goto error; - off += size; - } - tnt_mem_free(buf); - return 0; -error: - tnt_list_free(&r->r.select.l); - if (buf) - tnt_mem_free(buf); - return -1; -} - -static int -tnt_request_update(struct tnt_request *r, tnt_request_t rcv, void *ptr) -{ - if (rcv(ptr, (char*)&r->r.update, sizeof(struct tnt_header_update)) == -1) - return -1; - r->r.update.opc = 0; - r->r.update.opv = NULL; - uint32_t size = r->h.len - sizeof(struct tnt_header_update); - char *buf = tnt_mem_alloc(size); - if (buf == NULL) - goto error; - if (rcv(ptr, buf, size) == -1) - goto error; - /* calculating key tuple size */ - uint32_t i, cardinality = *(uint32_t*)(buf); - uint32_t ks = 4; - for (i = 0 ; i < cardinality ; i++) { - uint32_t fld_size = 0; - int fld_esize = tnt_enc_read(buf + ks, &fld_size); - if (fld_esize == -1) - goto error; - ks += fld_esize + fld_size; - } - /* initializing tuple */ - if (tnt_tuple_set(&r->r.update.t, buf, ks) == NULL) - goto error; - size -= ks /*- 4 */; - - /* ops data */ - r->r.update.opc = *(uint32_t*)(buf + ks); - uint32_t opvsz = sizeof(struct tnt_request_update_op) * r->r.update.opc; - r->r.update.opv = tnt_mem_alloc(opvsz); - if (r->r.update.opv == NULL) - goto error; - memset(r->r.update.opv, 0, sizeof(opvsz)); - - /* allocating ops buffer */ - r->r.update.ops_size = 4; - r->r.update.ops = tnt_mem_alloc(size); - if (r->r.update.ops == NULL) - goto error; - memcpy(r->r.update.ops, buf + ks /*+ 4*/, size); - - /* parsing operations */ - char *p = r->r.update.ops + 4; - for (i = 0 ; i < r->r.update.opc ; i++) { - struct tnt_request_update_op *op = &r->r.update.opv[i]; - /* field */ - op->field = *(uint32_t*)(p); - p += 4; - /* operation */ - op->op = *(uint8_t*)(p); - p += 1; - /* enc_size */ - int esize = tnt_enc_read(p, &op->size); - if (esize == -1 || esize >= 5) - goto error; - op->size_enc_len = esize; - memcpy(op->size_enc, p, op->size_enc_len); - p += op->size_enc_len; - op->data = p; - p += op->size; - r->r.update.ops_size += 4 + 1 + op->size_enc_len + op->size; - } - - /* creating resend io vector */ - r->vc = 5; - r->v = tnt_mem_alloc(r->vc * sizeof(struct iovec)); - if (r->v == NULL) - goto error; - r->v[0].iov_base = (void *)&r->h; - r->v[0].iov_len = sizeof(struct tnt_header); - r->v[1].iov_base = (void *)&r->r.update.h; - r->v[1].iov_len = sizeof(struct tnt_header_update); - r->v[2].iov_base = r->r.update.t.data; - r->v[2].iov_len = r->r.update.t.size; - r->v[3].iov_base = (void *)&r->r.update.opc; - r->v[3].iov_len = 4; - r->v[4].iov_base = r->r.update.ops; - r->v[4].iov_len = r->r.update.ops_size; - tnt_mem_free(buf); - return 0; -error: - tnt_tuple_free(&r->r.update.t); - if (r->r.update.ops) { - tnt_mem_free(r->r.update.ops); - r->r.update.ops = NULL; - } - if (r->r.update.opv) { - tnt_mem_free(r->r.update.opv); - r->r.update.opv = NULL; - } - if (buf) - tnt_mem_free(buf); - return -1; -} - -/* - * tnt_request_from() - * - * process iproto request with supplied recv function; - * - * r - request object pointer - * rcv - supplied recv function - * ptr - recv function argument - * hdr - pointer to iproto header, may be NULL - * - * returns zero on fully read reply, or -1 on error. -*/ -int -tnt_request_from(struct tnt_request *r, tnt_request_t rcv, void *ptr, - struct tnt_header *hdr) -{ - if (hdr) { - memcpy(&r->h, hdr, sizeof(struct tnt_header)); - } else { - if (rcv(ptr, (char*)&r->h, sizeof(struct tnt_header)) == -1) - return -1; - } - switch (r->h.type) { - case TNT_OP_INSERT: return tnt_request_insert(r, rcv, ptr); - case TNT_OP_DELETE_1_3: return tnt_request_delete_1_3(r, rcv, ptr); - case TNT_OP_DELETE: return tnt_request_delete(r, rcv, ptr); - case TNT_OP_CALL: return tnt_request_call(r, rcv, ptr); - case TNT_OP_SELECT: return tnt_request_select(r, rcv, ptr); - case TNT_OP_UPDATE: return tnt_request_update(r, rcv, ptr); - case TNT_OP_PING: return 0; - } - return -1; -} - -/* - * tnt_request() - * - * process buffer as iproto request (deserilization); - * - * r - request object pointer - * buf - buffer data pointer - * size - buffer data size - * off - returned offset, maybe NULL - * hdr - iproto header, maybe NULL - * - * if request is fully read, then zero is returned and offset set to the - * end of reply data in buffer. - * - * if request is not complete, then 1 is returned and offset set to the - * size needed to read. - * - * if there were error while parsing reply, -1 is returned. - * - * returns zero on fully read reply, or NULL on error. -*/ -static ssize_t tnt_request_cb(void *ptr[2], char *buf, ssize_t size) { - char *src = ptr[0]; - ssize_t *off = ptr[1]; - memcpy(buf, src + *off, size); - *off += size; - return size; -} - -int -tnt_request(struct tnt_request *r, char *buf, size_t size, size_t *off, - struct tnt_header *hdr) -{ - if (hdr == NULL) { - if (size < (sizeof(struct tnt_header))) { - if (off) - *off = sizeof(struct tnt_header) - size; - return 1; - } - struct tnt_header *hdr_ = (struct tnt_header*)buf; - if (size < hdr_->len) { - if (off) - *off = hdr_->len - size; - return 1; - } - } - size_t offv = 0; - void *ptr[2] = { buf, &offv }; - int rc = tnt_request_from(r, (tnt_request_t)tnt_request_cb, ptr, hdr); - if (off) - *off = offv; - return rc; -} diff --git a/connector/c/tnt/tnt_select.c b/connector/c/tnt/tnt_select.c deleted file mode 100644 index 3e3c51c42e..0000000000 --- a/connector/c/tnt/tnt_select.c +++ /dev/null @@ -1,110 +0,0 @@ - -/* - * 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 <stdlib.h> -#include <stdint.h> -#include <string.h> - -#include <connector/c/include/tarantool/tnt_mem.h> -#include <connector/c/include/tarantool/tnt_proto.h> -#include <connector/c/include/tarantool/tnt_tuple.h> -#include <connector/c/include/tarantool/tnt_request.h> -#include <connector/c/include/tarantool/tnt_reply.h> -#include <connector/c/include/tarantool/tnt_stream.h> -#include <connector/c/include/tarantool/tnt_iter.h> -#include <connector/c/include/tarantool/tnt_select.h> - -/* - * tnt_select() - * - * write select request to stream; - * - * s - stream pointer - * ns - space - * index - request index - * offset- request offset - * limit - request limit - * keys - list of tuples keys - * - * returns number of bytes written, or -1 on error. -*/ -ssize_t -tnt_select(struct tnt_stream *s, - uint32_t ns, - uint32_t index, uint32_t offset, uint32_t limit, - struct tnt_list *keys) -{ - /* calculating tuples sizes */ - size_t size = 0; - struct tnt_iter i; - tnt_iter_list(&i, keys); - while (tnt_next(&i)) { - struct tnt_tuple *t = TNT_ILIST_TUPLE(&i); - size += t->size; - } - /* filling major header */ - struct tnt_header hdr; - hdr.type = TNT_OP_SELECT; - hdr.len = sizeof(struct tnt_header_select) + 4 + size; - hdr.reqid = s->reqid; - /* filling select header */ - struct tnt_header_select hdr_sel; - hdr_sel.ns = ns; - hdr_sel.index = index; - hdr_sel.offset = offset; - hdr_sel.limit = limit; - /* allocating write vector */ - int vc = 3 + keys->count; - struct iovec *v = tnt_mem_alloc(sizeof(struct iovec) * vc); - if (v == NULL) { - tnt_iter_free(&i); - return -1; - } - /* filling write vector */ - v[0].iov_base = (void *)&hdr; - v[0].iov_len = sizeof(struct tnt_header); - v[1].iov_base = (void *)&hdr_sel; - v[1].iov_len = sizeof(struct tnt_header_select); - v[2].iov_base = (void *)&keys->count; - v[2].iov_len = 4; - int vi = 3; - tnt_rewind(&i); - while (tnt_next(&i)) { - struct tnt_tuple *t = TNT_ILIST_TUPLE(&i); - v[vi].iov_base = t->data; - v[vi].iov_len = t->size; - vi++; - } - tnt_iter_free(&i); - /* writing data to stream */ - ssize_t rc = s->writev(s, v, vc); - tnt_mem_free(v); - return rc; -} diff --git a/connector/c/tnt/tnt_stream.c b/connector/c/tnt/tnt_stream.c deleted file mode 100644 index 5f2bc36855..0000000000 --- a/connector/c/tnt/tnt_stream.c +++ /dev/null @@ -1,97 +0,0 @@ - -/* - * 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 <stdlib.h> -#include <stdint.h> -#include <string.h> - -#include <connector/c/include/tarantool/tnt_mem.h> -#include <connector/c/include/tarantool/tnt_proto.h> -#include <connector/c/include/tarantool/tnt_tuple.h> -#include <connector/c/include/tarantool/tnt_request.h> -#include <connector/c/include/tarantool/tnt_reply.h> -#include <connector/c/include/tarantool/tnt_stream.h> - -/* - * tnt_stream_reqid() - * - * set reqid value - * - * s - stream pointer - * reqid - new reqid value - * - * returns old reqid value - * -*/ -uint32_t -tnt_stream_reqid(struct tnt_stream *s, uint32_t reqid) -{ - uint32_t old = s->reqid; - s->reqid = reqid; - return old; -} - -/* - * tnt_stream_init() - * - * free stream object. - * - * s - stream pointer - * -*/ -struct tnt_stream* -tnt_stream_init(struct tnt_stream *s) -{ - if (s) { - memset(s, 0, sizeof(struct tnt_stream)); - return s; - } - s = tnt_mem_alloc(sizeof(struct tnt_stream)); - if (s == NULL) - return NULL; - memset(s, 0, sizeof(struct tnt_stream)); - s->alloc = 1; - return s; -} - -/* - * tnt_stream_free() - * - * free stream object. - * - * s - stream pointer - * -*/ -void tnt_stream_free(struct tnt_stream *s) { - if (s->free) - s->free(s); - if (s->alloc) - tnt_mem_free(s); -} diff --git a/connector/c/tnt/tnt_tuple.c b/connector/c/tnt/tnt_tuple.c deleted file mode 100644 index 9b8cec4a6a..0000000000 --- a/connector/c/tnt/tnt_tuple.c +++ /dev/null @@ -1,407 +0,0 @@ - -/* - * 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 <stdlib.h> -#include <stdarg.h> -#include <stdint.h> -#include <string.h> -#include <ctype.h> - -#include <connector/c/include/tarantool/tnt_mem.h> -#include <connector/c/include/tarantool/tnt_enc.h> -#include <connector/c/include/tarantool/tnt_tuple.h> - -/* - * tnt_tuple_init() - * - * initialize tuple; - * - * t - tuple pointer -*/ -void tnt_tuple_init(struct tnt_tuple *t) { - memset(t, 0, sizeof(struct tnt_tuple)); -} - -/* - * tnt_tuple_free() - * - * free tuple; - * - * t - tuple pointer -*/ -void tnt_tuple_free(struct tnt_tuple *t) { - if (t->data) - tnt_mem_free(t->data); - t->size = 0; - t->cardinality = 0; - t->data = NULL; - if (t->alloc) - tnt_mem_free(t); -} - -/* - * tnt_tuple_add() - * - * add field to existing tuple; - * create new tuple and add field; - * create new tuple; - * - * t - tuple pointer, maybe NULL - * data - tuple field data pointer, maybe NULL - * size - tuple field data size, maybe zero - * - * if tuple pointer is NULL, then new tuple will be created. - * If tuple pointer is NULL and size is zero, then only - * new empty tuple will be created. - * if tuple field data is NULL, then new field would be - * created, but no data copied to it. - * - * returns tuple pointer, or NULL on error. -*/ -struct tnt_tuple* -tnt_tuple_add(struct tnt_tuple *t, const void *data, uint32_t size) -{ - int allocated = t == NULL; - if (t == NULL) { - t = tnt_mem_alloc(sizeof(struct tnt_tuple)); - if (t == NULL) - return NULL; - memset(t, 0, sizeof(struct tnt_tuple)); - t->alloc = 1; - if (size == 0) - return t; - } - if (t->size == 0) - t->size = 4; /* cardinality */ - int esize = tnt_enc_size(size); - size_t nsize = t->size + esize + size; - /* reallocating tuple data */ - char *ndata = realloc(t->data, nsize); - if (ndata == NULL) { - if (allocated) - tnt_mem_free(t); - return NULL; - } - t->cardinality++; - /* updating tuple cardinality */ - memcpy(ndata, &t->cardinality, 4); - /* setting new field */ - tnt_enc_write(ndata + t->size, size); - if (data) - memcpy(ndata + t->size + esize, data, size); - t->data = ndata; - t->size = nsize; - return t; -} - -/* - * tnt_tuple() - * - * add formated fields to existing tuple; - * create new tuple and add formated fields; - * - * t - tuple pointer, maybe NULL - * fmt - printf-alike format (%s, %*s, %d, %l, %ll, %ul, %ull are supported) - * - * if tuple pointer is NULL, then new tuple will be created. - * if tuple pointer is NULL and fmt is NULL, then new empty tuple - * will be created. - * - * returns tuple pointer, or NULL on error. -*/ -struct tnt_tuple* -tnt_tuple(struct tnt_tuple *t, const char *fmt, ...) -{ - if (t == NULL) { - t = tnt_tuple_add(NULL, NULL, 0); - if (t == NULL) - return NULL; - if (fmt == NULL) - return t; - } - va_list args; - va_start(args, fmt); - const char *p = fmt; - while (*p) { - if (isspace(*p)) { - p++; - continue; - } else - if (*p != '%') - return NULL; - p++; - switch (*p) { - case '*': { - if (*(p + 1) == 's') { - int len = va_arg(args, int); - char *s = va_arg(args, char*); - tnt_tuple_add(t, s, len); - p += 2; - } else - return NULL; - break; - } - case 's': { - char *s = va_arg(args, char*); - tnt_tuple_add(t, s, strlen(s)); - p++; - break; - } - case 'd': { - int i = va_arg(args, int); - tnt_tuple_add(t, (char*)&i, sizeof(int)); - p++; - break; - } - case 'u': - if (*(p + 1) == 'l') { - if (*(p + 2) == 'l') { - unsigned long long int ull = va_arg(args, unsigned long long); - tnt_tuple_add(t, (char*)&ull, sizeof(unsigned long long int)); - p += 3; - } else { - unsigned long int ul = va_arg(args, unsigned long int); - tnt_tuple_add(t, (char*)&ul, sizeof(unsigned long int)); - p += 2; - } - } else - return NULL; - break; - case 'l': - if (*(p + 1) == 'l') { - long long int ll = va_arg(args, int); - tnt_tuple_add(t, (char*)&ll, sizeof(long long int)); - p += 2; - } else { - long int l = va_arg(args, int); - tnt_tuple_add(t, (char*)&l, sizeof(long int)); - p++; - } - break; - default: - return NULL; - } - } - va_end(args); - return t; -} - -/* - * tnt_tuple_validate() - * - * check if supplied buffer is a valid tuple; - * - * buf - iproto tuple buffer representation - * size - buffer size - * - * returns 0, or -1 on error. -*/ -static int tnt_tuple_validate(const void *buf, size_t size) { - if (size < sizeof(uint32_t)) - return -1; - size_t fld_off = sizeof(uint32_t); - uint32_t cardinality = *(uint32_t*)buf; - while (cardinality-- != 0) { - uint32_t fld_size; - int fld_esize = tnt_enc_read((const char *)buf + fld_off, &fld_size); - if (fld_esize == -1) - return -1; - fld_off += fld_esize + fld_size; - if (fld_off > size) - return -1; - } - return 0; -} - -/* - * tnt_tuple_set() - * - * set tuple from data; - * create new tuple and set it from data; - * - * t - tuple pointer, maybe NULL - * buf - iproto tuple buffer representation - * size - buffer size - * - * if tuple pointer is NULL, then new tuple will be created. - * - * returns tuple pointer, or NULL on error. -*/ -struct tnt_tuple *tnt_tuple_set(struct tnt_tuple *t, const void *buf, size_t size) { - if (tnt_tuple_validate(buf, size) == -1) - return NULL; - int allocated = t == NULL; - if (t == NULL) { - t = tnt_tuple_add(NULL, NULL, 0); - if (t == NULL) - return NULL; - } - t->cardinality = *(uint32_t*)buf; - t->size = size; - t->data = tnt_mem_alloc(size); - if (t->data == NULL) - goto error; - memcpy(t->data, buf, size); - return t; -error: - if (allocated) - tnt_tuple_free(t); - return NULL; -} - -/* - * tnt_tuple_set_as() - * - * set tuple from data; - * create new tuple and set it from data; - * - * t - tuple pointer, maybe NULL - * buf - iproto tuple fields buffer representation - * size - buffer size - * num - tuple cardinality - * - * if tuple pointer is NULL, then new tuple will be created. - * - * returns tuple pointer, or NULL on error. -*/ -struct tnt_tuple* -tnt_tuple_set_as(struct tnt_tuple *t, const void *buf, size_t size, uint32_t num) -{ - int allocated = t == NULL; - if (t == NULL) { - t = tnt_tuple_add(NULL, NULL, 0); - if (t == NULL) - return NULL; - } - t->cardinality = num; - t->size = sizeof(uint32_t) + size; - t->data = tnt_mem_alloc(t->size); - if (t->data == NULL) - goto error; - memcpy(t->data, &num, sizeof(uint32_t)); - memcpy(t->data + sizeof(uint32_t), buf, size); - return t; -error: - if (allocated) - tnt_tuple_free(t); - return NULL; -} - -/* - * tnt_list_init() - * - * initialize tuple list; - * - * l - tuple list pointer -*/ -void tnt_list_init(struct tnt_list *l) { - memset(l, 0, sizeof(struct tnt_list)); -} - -/* - * tnt_list_free() - * - * free tuple list; - * - * l - tuple list pointer -*/ -void tnt_list_free(struct tnt_list *l) { - if (l->list == NULL) - return; - uint32_t i; - for (i = 0 ; i < l->count ; i++) - tnt_tuple_free(l->list[i].ptr); - tnt_mem_free(l->list); - if (l->alloc) - tnt_mem_free(l); -} - -/* - * tnt_list() - * - * add tuples to the list; - * - * l - tuple list pointer, maybe NULL - * - * returns tuple list pointer, NULL on error. -*/ -struct tnt_list *tnt_list(struct tnt_list *l, ...) { - if (l == NULL) { - l = tnt_mem_alloc(sizeof(struct tnt_list)); - if (l == NULL) - return NULL; - memset(l, 0, sizeof(struct tnt_list)); - l->alloc++; - } - va_list args; - va_start(args, l); - while (1) { - struct tnt_tuple *ptr = va_arg(args, struct tnt_tuple*); - if (ptr == NULL) - break; - tnt_list_at(l, ptr); - } - va_end(args); - return l; -} - -/* - * tnt_list_at() - * - * attach tuple to list; - * create new tuple and attach it the the list; - * - * l - tuple list pointer - * t - tuple pointer - * - * returns tuple pointer, NULL on error. -*/ -struct tnt_tuple *tnt_list_at(struct tnt_list *l, struct tnt_tuple *t) { - /* allocating tuple if necessary */ - int allocated = t == NULL; - if (t == NULL) { - t = tnt_tuple_add(NULL, NULL, 0); - if (t == NULL) - return NULL; - } - /* reallocating tuple data */ - char *ndata = realloc(l->list, sizeof(struct tnt_list_ptr) * (l->count + 1)); - if (ndata == NULL) { - free(l->list); - if (allocated) - tnt_tuple_free(t); - return NULL; - } - l->list = (struct tnt_list_ptr*)ndata; - /* setting pointer data */ - l->list[l->count].ptr = t; - l->count++; - return t; -} diff --git a/connector/c/tnt/tnt_update.c b/connector/c/tnt/tnt_update.c deleted file mode 100644 index 53b3989945..0000000000 --- a/connector/c/tnt/tnt_update.c +++ /dev/null @@ -1,262 +0,0 @@ - -/* - * 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 <stdlib.h> -#include <stdint.h> -#include <string.h> - -#include <connector/c/include/tarantool/tnt_mem.h> -#include <connector/c/include/tarantool/tnt_proto.h> -#include <connector/c/include/tarantool/tnt_enc.h> -#include <connector/c/include/tarantool/tnt_tuple.h> -#include <connector/c/include/tarantool/tnt_request.h> -#include <connector/c/include/tarantool/tnt_reply.h> -#include <connector/c/include/tarantool/tnt_stream.h> -#include <connector/c/include/tarantool/tnt_buf.h> -#include <connector/c/include/tarantool/tnt_update.h> - -static ssize_t -tnt_update_op(struct tnt_stream *s, - uint32_t field, uint8_t op, const char *data, uint32_t size) -{ - /* encoding size */ - int encs = tnt_enc_size(size); - char enc[5]; - tnt_enc_write(enc, size); - struct iovec iov[4]; - int iovc = 3; - /* field */ - iov[0].iov_base = (void *)&field; - iov[0].iov_len = 4; - /* operation */ - iov[1].iov_base = (void *)&op; - iov[1].iov_len = 1; - /* encoding size */ - iov[2].iov_base = enc; - iov[2].iov_len = encs; - /* data */ - if (data) { - iov[3].iov_base = (void *) data; - iov[3].iov_len = size; - iovc++; - } - return s->writev(s, iov, iovc); -} - -/* - * tnt_update_arith() - * - * write 32-bit arithmetic update operation to buffer stream; - * - * s - stream buffer pointer - * field - field number - * op - update operation type - * value - update operation value - * - * returns number of bytes written, or -1 on error. -*/ -ssize_t -tnt_update_arith(struct tnt_stream *s, uint32_t field, - uint8_t op, uint32_t value) -{ - return tnt_update_op(s, field, op, (char*)&value, sizeof(value)); -} - -/* - * tnt_update_arith_i32() - * - * write 32-bit arithmetic update operation to buffer stream; - * - * s - stream buffer pointer - * field - field number - * op - update operation type - * value - update operation value - * - * returns number of bytes written, or -1 on error. -*/ -ssize_t -tnt_update_arith_i32(struct tnt_stream *s, uint32_t field, - uint8_t op, uint32_t value) -{ - return tnt_update_op(s, field, op, (char*)&value, sizeof(value)); -} - -/* - * tnt_update_arith_i64() - * - * write 64-bit arithmetic update operation to buffer stream; - * - * s - stream buffer pointer - * field - field number - * op - update operation type - * value - update operation value - * - * returns number of bytes written, or -1 on error. -*/ -ssize_t -tnt_update_arith_i64(struct tnt_stream *s, uint32_t field, - uint8_t op, uint64_t value) -{ - return tnt_update_op(s, field, op, (char*)&value, sizeof(value)); -} - -/* - * tnt_update_assign() - * - * write assign update operation to buffer stream; - * - * s - stream buffer pointer - * field - field number - * data - update operation data - * value - update operation data size - * - * returns number of bytes written, or -1 on error. -*/ -ssize_t -tnt_update_assign(struct tnt_stream *s, uint32_t field, - char *data, uint32_t size) -{ - return tnt_update_op(s, field, TNT_UPDATE_ASSIGN, data, size); -} - -/* - * tnt_update_splice() - * - * write update splice operation to buffer stream; - * - * s - stream buffer pointer - * field - field number - * offset - splice offset - * length - splice length - * data - splice operation data - * value - splice operation data size - * - * returns number of bytes written, or -1 on error. -*/ -ssize_t -tnt_update_splice(struct tnt_stream *s, uint32_t field, - uint32_t offset, - int32_t length, const char *data, size_t size) -{ - /* calculating splice data sizes */ - uint32_t offset_len = tnt_enc_size(sizeof(offset)), - length_len = tnt_enc_size(sizeof(length)), - data_len = tnt_enc_size(size); - uint32_t sz = offset_len + sizeof(offset) + - length_len + sizeof(length) + data_len + size; - /* allocating splice request buffer */ - char *buf = tnt_mem_alloc(sz); - if (buf == NULL) - return -1; - /* filling splice request data */ - char *p = buf; - tnt_enc_write(p, sizeof(offset)); - p += offset_len; - memcpy(p, &offset, sizeof(offset)); - p += sizeof(offset); - tnt_enc_write(p, sizeof(length)); - p += length_len; - memcpy(p, &length, sizeof(length)); - p += sizeof(length); - tnt_enc_write(p, size); - p += data_len; - memcpy(p, data, size); - p += size; - /* writing splice request */ - ssize_t rc = tnt_update_op(s, field, TNT_UPDATE_SPLICE, buf, sz); - tnt_mem_free(buf); - return rc; -} - -/* - * tnt_update_delete() - * - * write update delete operation to buffer stream; - * - * s - stream buffer pointer - * field - field number - * - * returns number of bytes written, or -1 on error. -*/ -ssize_t -tnt_update_delete(struct tnt_stream *s, uint32_t field) -{ - return tnt_update_op(s, field, TNT_UPDATE_DELETE, NULL, 0); -} - -ssize_t -tnt_update_insert(struct tnt_stream *s, uint32_t field, - const char *data, uint32_t size) -{ - return tnt_update_op(s, field, TNT_UPDATE_INSERT, data, size); -} - -/* - * tnt_update() - * - * write select request to stream; - * - * s - stream pointer - * ns - space - * flags - request flags - * k - update key tuple - * ops - stream buffer pointer - * - * returns number of bytes written, or -1 on error. -*/ -ssize_t -tnt_update(struct tnt_stream *s, uint32_t ns, uint32_t flags, - struct tnt_tuple *k, - struct tnt_stream *ops) -{ - /* filling major header */ - struct tnt_header hdr; - hdr.type = TNT_OP_UPDATE; - hdr.len = sizeof(struct tnt_header_update) + - k->size + 4 + TNT_SBUF_SIZE(ops); - hdr.reqid = s->reqid; - /* filling update header */ - struct tnt_header_update hdr_update; - hdr_update.ns = ns; - hdr_update.flags = flags; - /* writing data to stream */ - struct iovec v[5]; - v[0].iov_base = (void *)&hdr; - v[0].iov_len = sizeof(struct tnt_header); - v[1].iov_base = (void *)&hdr_update; - v[1].iov_len = sizeof(struct tnt_header_update); - v[2].iov_base = k->data; - v[2].iov_len = k->size; - v[3].iov_base = (void *)&ops->wrcnt; - v[3].iov_len = 4; - v[4].iov_base = TNT_SBUF_DATA(ops); - v[4].iov_len = TNT_SBUF_SIZE(ops); - return s->writev(s, v, 5); -} diff --git a/connector/c/tntnet/CMakeLists.txt b/connector/c/tntnet/CMakeLists.txt deleted file mode 100644 index a298c5b679..0000000000 --- a/connector/c/tntnet/CMakeLists.txt +++ /dev/null @@ -1,70 +0,0 @@ -#============================================================================# -# build flags -#============================================================================# - -# default flags -if (${CMAKE_BUILD_TYPE} STREQUAL "None") - set (tntnet_cflags "-std=gnu99") -else() - set (tntnet_cflags "-std=gnu99 -Wall -Wextra") - set (tntnet_cflags "${tntnet_cflags} -Wno-sign-compare -Wno-strict-aliasing") -endif() - -# Only add -Werror if it's a debug build, done by developers. -if (${CMAKE_BUILD_TYPE} STREQUAL "Debug") - set (tntnet_cflags "${tntnet_cflags} -Werror") -endif() - -#============================================================================# -# Build tnt net project -#============================================================================# - -# -# source files -# - -set (tntnet_sources - tnt_iob.c - tnt_io.c - tnt_opt.c - tnt_net.c) - -#----------------------------------------------------------------------------# -# Builds -#----------------------------------------------------------------------------# - -# Here we manage to build static/dynamic libraries ourselves, -# do not use the top level settings. -string(REPLACE "-static-libgcc" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") -string(REPLACE "-static" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") - -if (CMAKE_COMPILER_IS_GNUCC AND NOT CMAKE_COMPILER_IS_CLANG) - set (tnt_cflags "${tnt_cflags} -static-libgcc") -endif() - -# -# Static library -# -project(tntnet) -add_library(tntnet STATIC ${tntnet_sources}) -set_target_properties(tntnet PROPERTIES COMPILE_FLAGS "${tntnet_cflags}") -set_target_properties(tntnet PROPERTIES VERSION ${LIBTNT_VERSION} SOVERSION ${LIBTNT_SOVERSION}) -set_target_properties(tntnet PROPERTIES OUTPUT_NAME "tarantoolnet") - -# -# Shared library -# -project(tntnet_shared) -add_library(tntnet_shared SHARED ${tntnet_sources}) -target_link_libraries(tntnet_shared tnt_shared) -set_target_properties(tntnet_shared PROPERTIES OUTPUT_NAME tntnet) -set_target_properties(tntnet_shared PROPERTIES COMPILE_FLAGS "${tntnet_cflags}") -set_target_properties(tntnet_shared PROPERTIES VERSION ${LIBTNT_VERSION} SOVERSION ${LIBTNT_SOVERSION}) -set_target_properties(tntnet_shared PROPERTIES OUTPUT_NAME "tarantoolnet") - -#----------------------------------------------------------------------------# -# Install -#----------------------------------------------------------------------------# - -install (TARGETS tntnet ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) -install (TARGETS tntnet_shared LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) diff --git a/connector/c/tntnet/tnt_io.c b/connector/c/tntnet/tnt_io.c deleted file mode 100644 index 3169f947f3..0000000000 --- a/connector/c/tntnet/tnt_io.c +++ /dev/null @@ -1,428 +0,0 @@ - -/* - * 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 <stdlib.h> -#include <stdio.h> -#include <stdarg.h> -#include <string.h> - -#include <sys/time.h> -#include <sys/types.h> -#include <sys/socket.h> -#include <sys/uio.h> -#include <netinet/in.h> -#include <netinet/tcp.h> -#include <netdb.h> -#include <unistd.h> -#include <fcntl.h> -#include <errno.h> -#include <limits.h> - -#include <connector/c/include/tarantool/tnt.h> -#include <connector/c/include/tarantool/tnt_net.h> -#include <connector/c/include/tarantool/tnt_io.h> - -#if !defined(MIN) -# define MIN(a, b) (a) < (b) ? (a) : (b) -#endif /* !defined(MIN) */ - -static enum tnt_error -tnt_io_resolve(struct sockaddr_in *addr, - const char *hostname, unsigned short port) -{ - memset(addr, 0, sizeof(struct sockaddr_in)); - addr->sin_family = AF_INET; - addr->sin_port = htons(port); - struct addrinfo *addr_info = NULL; - if (getaddrinfo(hostname, NULL, NULL, &addr_info) == 0) { - memcpy(&addr->sin_addr, - (void*)&((struct sockaddr_in *)addr_info->ai_addr)->sin_addr, - sizeof(addr->sin_addr)); - freeaddrinfo(addr_info); - return TNT_EOK; - } - if (addr_info) - freeaddrinfo(addr_info); - return TNT_ERESOLVE; -} - -static enum tnt_error tnt_io_nonblock(struct tnt_stream_net *s, int set) { - int flags = fcntl(s->fd, F_GETFL); - if (flags == -1) { - s->errno_ = errno; - return TNT_ESYSTEM; - } - if (set) - flags |= O_NONBLOCK; - else - flags &= ~O_NONBLOCK; - if (fcntl(s->fd, F_SETFL, flags) == -1) { - s->errno_ = errno; - return TNT_ESYSTEM; - } - return TNT_EOK; -} - -static enum tnt_error -tnt_io_connect_do(struct tnt_stream_net *s, const char *host, int port) -{ - /* resolving address */ - struct sockaddr_in addr; - enum tnt_error result = tnt_io_resolve(&addr, host, port); - if (result != TNT_EOK) - return result; - - /* setting nonblock */ - result = tnt_io_nonblock(s, 1); - if (result != TNT_EOK) - return result; - - if (connect(s->fd, (struct sockaddr*)&addr, sizeof(addr)) == -1) { - if (errno == EINPROGRESS) { - /** waiting for connection while handling signal events */ - const int64_t micro = 1000000; - int64_t tmout_usec = s->opt.tmout_connect.tv_sec * micro; - /* get start connect time */ - struct timeval start_connect; - if (gettimeofday(&start_connect, NULL) == -1) { - s->errno_ = errno; - return TNT_ESYSTEM; - } - /* set initial timer */ - struct timeval tmout; - memcpy(&tmout, &s->opt.tmout_connect, sizeof(tmout)); - while (1) { - fd_set fds; - FD_ZERO(&fds); - FD_SET(s->fd, &fds); - int ret = select(s->fd + 1, NULL, &fds, NULL, &tmout); - if (ret == -1) { - if (errno == EINTR || errno == EAGAIN) { - /* get current time */ - struct timeval curr; - if (gettimeofday(&curr, NULL) == -1) { - s->errno_ = errno; - return TNT_ESYSTEM; - } - /* calculate timeout last time */ - int64_t passd_usec = (curr.tv_sec - start_connect.tv_sec) * micro + - (curr.tv_usec - start_connect.tv_usec); - int64_t curr_tmeout = passd_usec - tmout_usec; - if (curr_tmeout <= 0) { - /* timeout */ - return TNT_ETMOUT; - } - tmout.tv_sec = curr_tmeout / micro; - tmout.tv_usec = curr_tmeout % micro; - } else { - s->errno_ = errno; - return TNT_ESYSTEM; - } - } else if (ret == 0) { - /* timeout */ - return TNT_ETMOUT; - } else { - /* we have a event on socket */ - break; - } - } - /* checking error status */ - int opt = 0; - socklen_t len = sizeof(opt); - if ((getsockopt(s->fd, SOL_SOCKET, SO_ERROR, &opt, &len) == -1) || opt) { - s->errno_ = (opt) ? opt: errno; - return TNT_ESYSTEM; - } - } else { - s->errno_ = errno; - return TNT_ESYSTEM; - } - } - - /* setting block */ - result = tnt_io_nonblock(s, 0); - if (result != TNT_EOK) - return result; - return TNT_EOK; -} - -static enum tnt_error tnt_io_xbufmax(struct tnt_stream_net *s, int opt, int min) { - int max = 128 * 1024 * 1024; - if (min == 0) - min = 16384; - unsigned int avg = 0; - while (min <= max) { - avg = ((unsigned int)(min + max)) / 2; - if (setsockopt(s->fd, SOL_SOCKET, opt, &avg, sizeof(avg)) == 0) - min = avg + 1; - else - max = avg - 1; - } - return TNT_EOK; -} - -static enum tnt_error tnt_io_setopts(struct tnt_stream_net *s) { - int opt = 1; - if (setsockopt(s->fd, IPPROTO_TCP, TCP_NODELAY, &opt, sizeof(opt)) == -1) - goto error; - - tnt_io_xbufmax(s, SO_SNDBUF, s->opt.send_buf); - tnt_io_xbufmax(s, SO_RCVBUF, s->opt.recv_buf); - - if (setsockopt(s->fd, SOL_SOCKET, SO_SNDTIMEO, - &s->opt.tmout_send, sizeof(s->opt.tmout_send)) == -1) - goto error; - if (setsockopt(s->fd, SOL_SOCKET, SO_RCVTIMEO, - &s->opt.tmout_recv, sizeof(s->opt.tmout_recv)) == -1) - goto error; - return TNT_EOK; -error: - s->errno_ = errno; - return TNT_ESYSTEM; -} - -enum tnt_error -tnt_io_connect(struct tnt_stream_net *s, const char *host, int port) -{ - s->fd = socket(AF_INET, SOCK_STREAM, 0); - if (s->fd < 0) { - s->errno_ = errno; - return TNT_ESYSTEM; - } - enum tnt_error result = tnt_io_setopts(s); - if (result != TNT_EOK) - goto out; - result = tnt_io_connect_do(s, host, port); - if (result != TNT_EOK) - goto out; - s->connected = 1; - return TNT_EOK; -out: - tnt_io_close(s); - return result; -} - -void tnt_io_close(struct tnt_stream_net *s) -{ - if (s->fd > 0) { - close(s->fd); - s->fd = -1; - } - s->connected = 0; -} - -ssize_t tnt_io_flush(struct tnt_stream_net *s) { - if (s->sbuf.off == 0) - return 0; - ssize_t rc = tnt_io_send_raw(s, s->sbuf.buf, s->sbuf.off, 1); - if (rc == -1) - return -1; - s->sbuf.off = 0; - return rc; -} - -ssize_t -tnt_io_send_raw(struct tnt_stream_net *s, const char *buf, size_t size, int all) -{ - size_t off = 0; - do { - ssize_t r; - if (s->sbuf.tx) { - r = s->sbuf.tx(s->sbuf.buf, buf + off, size - off); - } else { - do { - r = send(s->fd, buf + off, size - off, 0); - } while (r == -1 && (errno == EINTR)); - } - if (r <= 0) { - s->error = TNT_ESYSTEM; - s->errno_ = errno; - return -1; - } - off += r; - } while (off != size && all); - return off; -} - -ssize_t -tnt_io_sendv_raw(struct tnt_stream_net *s, struct iovec *iov, int count, int all) -{ - size_t total = 0; - while (count > 0) { - ssize_t r; - if (s->sbuf.txv) { - r = s->sbuf.txv(s->sbuf.buf, iov, MIN(count, IOV_MAX)); - } else { - do { - r = writev(s->fd, iov, count); - } while (r == -1 && (errno == EINTR)); - } - if (r <= 0) { - s->error = TNT_ESYSTEM; - s->errno_ = errno; - return -1; - } - total += r; - if (!all) - break; - while (count > 0) { - if (iov->iov_len > (size_t)r) { - iov->iov_base += r; - iov->iov_len -= r; - break; - } else { - r -= iov->iov_len; - iov++; - count--; - } - } - } - return total; -} - -ssize_t -tnt_io_send(struct tnt_stream_net *s, const char *buf, size_t size) -{ - if (s->sbuf.buf == NULL) - return tnt_io_send_raw(s, buf, size, 1); - if (size > s->sbuf.size) { - s->error = TNT_EBIG; - return -1; - } - if ((s->sbuf.off + size) <= s->sbuf.size) { - memcpy(s->sbuf.buf + s->sbuf.off, buf, size); - s->sbuf.off += size; - return size; - } - ssize_t r = tnt_io_send_raw(s, s->sbuf.buf, s->sbuf.off, 1); - if (r == -1) - return -1; - s->sbuf.off = size; - memcpy(s->sbuf.buf, buf, size); - return size; -} - -inline static void -tnt_io_sendv_put(struct tnt_stream_net *s, struct iovec *iov, int count) { - int i; - for (i = 0 ; i < count ; i++) { - memcpy(s->sbuf.buf + s->sbuf.off, - iov[i].iov_base, - iov[i].iov_len); - s->sbuf.off += iov[i].iov_len; - } -} - -ssize_t -tnt_io_sendv(struct tnt_stream_net *s, struct iovec *iov, int count) -{ - if (s->sbuf.buf == NULL) - return tnt_io_sendv_raw(s, iov, count, 1); - size_t size = 0; - int i; - for (i = 0 ; i < count ; i++) - size += iov[i].iov_len; - if (size > s->sbuf.size) { - s->error = TNT_EBIG; - return -1; - } - if ((s->sbuf.off + size) <= s->sbuf.size) { - tnt_io_sendv_put(s, iov, count); - return size; - } - ssize_t r = tnt_io_send_raw(s, s->sbuf.buf, s->sbuf.off, 1); - if (r == -1) - return -1; - s->sbuf.off = 0; - tnt_io_sendv_put(s, iov, count); - return size; -} - -ssize_t -tnt_io_recv_raw(struct tnt_stream_net *s, char *buf, size_t size, int all) -{ - size_t off = 0; - do { - ssize_t r; - if (s->rbuf.tx) { - r = s->rbuf.tx(s->rbuf.buf, buf + off, size - off); - } else { - do { - r = recv(s->fd, buf + off, size - off, 0); - } while (r == -1 && (errno == EINTR)); - } - if (r <= 0) { - s->error = TNT_ESYSTEM; - s->errno_ = errno; - return -1; - } - off += r; - } while (off != size && all); - return off; -} - -ssize_t -tnt_io_recv(struct tnt_stream_net *s, char *buf, size_t size) -{ - if (s->rbuf.buf == NULL) - return tnt_io_recv_raw(s, buf, size, 1); - size_t lv, rv, off = 0, left = size; - while (1) { - if ((s->rbuf.off + left) <= s->rbuf.top) { - memcpy(buf + off, s->rbuf.buf + s->rbuf.off, left); - s->rbuf.off += left; - return size; - } - - lv = s->rbuf.top - s->rbuf.off; - rv = left - lv; - if (lv) { - memcpy(buf + off, s->rbuf.buf + s->rbuf.off, lv); - off += lv; - } - - s->rbuf.off = 0; - ssize_t top = tnt_io_recv_raw(s, s->rbuf.buf, s->rbuf.size, 0); - if (top <= 0) { - s->errno_ = errno; - s->error = TNT_ESYSTEM; - return -1; - } - - s->rbuf.top = top; - if (rv <= s->rbuf.top) { - memcpy(buf + off, s->rbuf.buf, rv); - s->rbuf.off = rv; - return size; - } - left -= lv; - } - return -1; -} diff --git a/connector/c/tntnet/tnt_iob.c b/connector/c/tntnet/tnt_iob.c deleted file mode 100644 index 04cd0980fa..0000000000 --- a/connector/c/tntnet/tnt_iob.c +++ /dev/null @@ -1,67 +0,0 @@ - -/* - * 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 <stdlib.h> -#include <stdio.h> -#include <string.h> - -#include <unistd.h> -#include <sys/uio.h> - -#include <connector/c/include/tarantool/tnt.h> -#include <connector/c/include/tarantool/tnt_iob.h> - -int -tnt_iob_init(struct tnt_iob *iob, size_t size, - tnt_iob_tx_t tx, - tnt_iob_txv_t txv, void *ptr) -{ - iob->tx = tx; - iob->txv = txv; - iob->ptr = ptr; - iob->size = size; - iob->off = 0; - iob->top = 0; - iob->buf = NULL; - if (size > 0) { - iob->buf = tnt_mem_alloc(size); - if (iob->buf == NULL) - return -1; - memset(iob->buf, 0, size); - } - return 0; -} - -void -tnt_iob_free(struct tnt_iob *iob) -{ - if (iob->buf) - tnt_mem_free(iob->buf); -} diff --git a/connector/c/tntnet/tnt_net.c b/connector/c/tntnet/tnt_net.c deleted file mode 100644 index 5e35d19fc4..0000000000 --- a/connector/c/tntnet/tnt_net.c +++ /dev/null @@ -1,313 +0,0 @@ - -/* - * 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 <stdlib.h> -#include <stdio.h> -#include <stdarg.h> -#include <string.h> - -#include <connector/c/include/tarantool/tnt.h> -#include <connector/c/include/tarantool/tnt_net.h> -#include <connector/c/include/tarantool/tnt_io.h> - -static void tnt_net_free(struct tnt_stream *s) { - struct tnt_stream_net *sn = TNT_SNET_CAST(s); - tnt_io_close(sn); - tnt_iob_free(&sn->sbuf); - tnt_iob_free(&sn->rbuf); - tnt_opt_free(&sn->opt); - tnt_mem_free(s->data); - s->data = NULL; -} - -static ssize_t -tnt_net_read(struct tnt_stream *s, char *buf, size_t size) { - struct tnt_stream_net *sn = TNT_SNET_CAST(s); - /* read doesn't touches wrcnt */ - return tnt_io_recv(sn, buf, size); -} - -static ssize_t -tnt_net_write(struct tnt_stream *s, const char *buf, size_t size) { - struct tnt_stream_net *sn = TNT_SNET_CAST(s); - ssize_t rc = tnt_io_send(sn, buf, size); - if (rc != -1) - s->wrcnt++; - return rc; -} - -static ssize_t -tnt_net_writev(struct tnt_stream *s, struct iovec *iov, int count) { - struct tnt_stream_net *sn = TNT_SNET_CAST(s); - ssize_t rc = tnt_io_sendv(sn, iov, count); - if (rc != -1) - s->wrcnt++; - return rc; -} - -static ssize_t -tnt_net_write_request(struct tnt_stream *s, struct tnt_request *r) { - return tnt_net_writev(s, r->v, r->vc); -} - -static ssize_t -tnt_net_recv_cb(struct tnt_stream *s, char *buf, ssize_t size) { - struct tnt_stream_net *sn = TNT_SNET_CAST(s); - return tnt_io_recv(sn, buf, size); -} - -static int -tnt_net_reply(struct tnt_stream *s, struct tnt_reply *r) { - if (s->wrcnt == 0) - return 1; - s->wrcnt--; - return tnt_reply_from(r, (tnt_reply_t)tnt_net_recv_cb, s); -} - -static int -tnt_net_request(struct tnt_stream *s, struct tnt_request *r) { - /* read doesn't touches wrcnt */ - return tnt_request_from(r, (tnt_request_t)tnt_net_recv_cb, s, NULL); -} - -/* - * tnt_net() - * - * create and initialize network stream; - * - * s - stream pointer, maybe NULL - * - * if stream pointer is NULL, then new stream will be created. - * - * returns stream pointer, or NULL on error. -*/ -struct tnt_stream *tnt_net(struct tnt_stream *s) { - int allocated = s == NULL; - s = tnt_stream_init(s); - if (s == NULL) - return NULL; - /* allocating stream data */ - s->data = tnt_mem_alloc(sizeof(struct tnt_stream_net)); - if (s->data == NULL) { - if (allocated) - tnt_stream_free(s); - return NULL; - } - memset(s->data, 0, sizeof(struct tnt_stream_net)); - /* initializing interfaces */ - s->read = tnt_net_read; - s->read_reply = tnt_net_reply; - s->read_request = tnt_net_request; - s->read_tuple = NULL; - s->write = tnt_net_write; - s->writev = tnt_net_writev; - s->write_request = tnt_net_write_request; - s->free = tnt_net_free; - /* initializing internal data */ - struct tnt_stream_net *sn = TNT_SNET_CAST(s); - sn->fd = -1; - tnt_opt_init(&sn->opt); - return s; -} - -/* - * tnt_set() - * - * set options to network stream; - * - * s - network stream pointer - * opt - option id - * ... - option value - * - * returns 0 on success, or -1 on error. -*/ -int tnt_set(struct tnt_stream *s, int opt, ...) { - struct tnt_stream_net *sn = TNT_SNET_CAST(s); - va_list args; - va_start(args, opt); - sn->error = tnt_opt_set(&sn->opt, opt, args); - va_end(args); - return (sn->error == TNT_EOK) ? 0 : -1; -} - -/* - * tnt_init() - * - * initialize prepared network stream; - * - * s - network stream pointer - * - * returns 0 on success, or -1 on error. -*/ -int tnt_init(struct tnt_stream *s) { - struct tnt_stream_net *sn = TNT_SNET_CAST(s); - if (tnt_iob_init(&sn->sbuf, sn->opt.send_buf, sn->opt.send_cb, - sn->opt.send_cbv, sn->opt.send_cb_arg) == -1) { - sn->error = TNT_EMEMORY; - return -1; - } - if (tnt_iob_init(&sn->rbuf, sn->opt.recv_buf, sn->opt.recv_cb, NULL, - sn->opt.recv_cb_arg) == -1) { - sn->error = TNT_EMEMORY; - return -1; - } - if (sn->opt.hostname == NULL) { - sn->error = TNT_EBADVAL; - return -1; - } - if (sn->opt.port == 0) { - sn->error = TNT_EBADVAL; - return -1; - } - return 0; -} - -/* - * tnt_connect() - * - * connect to server; - * reconnect to server; - * - * s - network stream pointer - * - * returns 0 on success, or -1 on error. -*/ -int tnt_connect(struct tnt_stream *s) { - struct tnt_stream_net *sn = TNT_SNET_CAST(s); - if (sn->connected) - tnt_close(s); - sn->error = tnt_io_connect(sn, sn->opt.hostname, sn->opt.port); - if (sn->error != TNT_EOK) - return -1; - return 0; -} - -/* - * tnt_close() - * - * close connection to server; - * - * s - network stream pointer - * - * returns 0 on success, or -1 on error. -*/ -void tnt_close(struct tnt_stream *s) { - struct tnt_stream_net *sn = TNT_SNET_CAST(s); - tnt_io_close(sn); -} - -/* - * tnt_flush() - * - * send bufferized data to server; - * - * s - network stream pointer - * - * returns size of data been sended on success, or -1 on error. -*/ -ssize_t tnt_flush(struct tnt_stream *s) { - struct tnt_stream_net *sn = TNT_SNET_CAST(s); - return tnt_io_flush(sn); -} - -/* - * tnt_fd() - * - * get connection socket description; - * - * s - network stream pointer -*/ -int tnt_fd(struct tnt_stream *s) { - struct tnt_stream_net *sn = TNT_SNET_CAST(s); - return sn->fd; -} - -/* - * tnt_error() - * - * get library error status; - * - * s - network stream pointer -*/ -enum tnt_error tnt_error(struct tnt_stream *s) { - struct tnt_stream_net *sn = TNT_SNET_CAST(s); - return sn->error; -} - -/* must be in sync with enum tnt_error */ - -struct tnt_error_desc { - enum tnt_error type; - char *desc; -}; - -static struct tnt_error_desc tnt_error_list[] = -{ - { TNT_EOK, "ok" }, - { TNT_EFAIL, "fail" }, - { TNT_EMEMORY, "memory allocation failed" }, - { TNT_ESYSTEM, "system error" }, - { TNT_EBIG, "buffer is too big" }, - { TNT_ESIZE, "bad buffer size" }, - { TNT_ERESOLVE, "gethostbyname(2) failed" }, - { TNT_ETMOUT, "operation timeout" }, - { TNT_EBADVAL, "bad argument" }, - { TNT_LAST, NULL } -}; - -/* - * tnt_strerror() - * - * get library error status description string; - * - * s - network stream pointer -*/ -char *tnt_strerror(struct tnt_stream *s) { - struct tnt_stream_net *sn = TNT_SNET_CAST(s); - if (sn->error == TNT_ESYSTEM) { - static char msg[256]; - snprintf(msg, sizeof(msg), "%s (errno: %d)", - strerror(sn->errno_), sn->errno_); - return msg; - } - return tnt_error_list[(int)sn->error].desc; -} - -/* - * tnt_errno() - * - * get saved errno; - * - * s - network stream pointer -*/ -int tnt_errno(struct tnt_stream *s) { - struct tnt_stream_net *sn = TNT_SNET_CAST(s); - return sn->errno_; -} diff --git a/connector/c/tntnet/tnt_opt.c b/connector/c/tntnet/tnt_opt.c deleted file mode 100644 index 810ebabbf9..0000000000 --- a/connector/c/tntnet/tnt_opt.c +++ /dev/null @@ -1,112 +0,0 @@ - -/* - * 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 <stdlib.h> -#include <stdarg.h> -#include <stdio.h> -#include <string.h> - -#include <sys/types.h> -#include <sys/time.h> - -#include <connector/c/include/tarantool/tnt.h> -#include <connector/c/include/tarantool/tnt_net.h> - -void -tnt_opt_init(struct tnt_opt *opt) -{ - memset(opt, 0, sizeof(struct tnt_opt)); - opt->port = 15312; - opt->recv_buf = 16384; - opt->send_buf = 16384; - opt->tmout_connect.tv_sec = 16; - opt->tmout_connect.tv_usec = 0; -} - -void -tnt_opt_free(struct tnt_opt *opt) -{ - if (opt->hostname) - tnt_mem_free(opt->hostname); -} - -int -tnt_opt_set(struct tnt_opt *opt, enum tnt_opt_type name, va_list args) -{ - struct timeval *tvp; - switch (name) { - case TNT_OPT_HOSTNAME: - if (opt->hostname) - tnt_mem_free(opt->hostname); - opt->hostname = tnt_mem_dup(va_arg(args, char*)); - if (opt->hostname == NULL) - return TNT_EMEMORY; - break; - case TNT_OPT_PORT: - opt->port = va_arg(args, int); - break; - case TNT_OPT_TMOUT_CONNECT: - tvp = va_arg(args, struct timeval*); - memcpy(&opt->tmout_connect, tvp, sizeof(struct timeval)); - break; - case TNT_OPT_TMOUT_RECV: - tvp = va_arg(args, struct timeval*); - memcpy(&opt->tmout_recv, tvp, sizeof(struct timeval)); - break; - case TNT_OPT_TMOUT_SEND: - tvp = va_arg(args, struct timeval*); - memcpy(&opt->tmout_send, tvp, sizeof(struct timeval)); - break; - case TNT_OPT_SEND_CB: - opt->send_cb = va_arg(args, void*); - break; - case TNT_OPT_SEND_CBV: - opt->send_cbv = va_arg(args, void*); - break; - case TNT_OPT_SEND_CB_ARG: - opt->send_cb_arg = va_arg(args, void*); - break; - case TNT_OPT_SEND_BUF: - opt->send_buf = va_arg(args, int); - break; - case TNT_OPT_RECV_CB: - opt->recv_cb = va_arg(args, void*); - break; - case TNT_OPT_RECV_CB_ARG: - opt->recv_cb_arg = va_arg(args, void*); - break; - case TNT_OPT_RECV_BUF: - opt->recv_buf = va_arg(args, int); - break; - default: - return TNT_EFAIL; - } - return TNT_EOK; -} diff --git a/connector/c/tntrpl/CMakeLists.txt b/connector/c/tntrpl/CMakeLists.txt deleted file mode 100644 index bb38ae1a73..0000000000 --- a/connector/c/tntrpl/CMakeLists.txt +++ /dev/null @@ -1,69 +0,0 @@ -#============================================================================# -# build flags -#============================================================================# - -# default flags -if (${CMAKE_BUILD_TYPE} STREQUAL "None") - set (tntrpl_cflags "-std=gnu99") -else() - set (tntrpl_cflags "-std=gnu99 -Wall -Wextra") - set (tntrpl_cflags "${tntrpl_cflags} -Wno-sign-compare -Wno-strict-aliasing") -endif() - -# Only add -Werror if it's a debug build, done by developers. -if (${CMAKE_BUILD_TYPE} STREQUAL "Debug") - set (tntrpl_cflags "${tntrpl_cflags} -Werror") -endif() - -#============================================================================# -# Build tnt rpl project -#============================================================================# - -# -# source files -# - -set (tntrpl_sources tnt_log.c tnt_dir.c tnt_xlog.c tnt_snapshot.c tnt_rpl.c - ${CMAKE_SOURCE_DIR}/third_party/crc32.c) - -#----------------------------------------------------------------------------# -# Builds -#----------------------------------------------------------------------------# - -# Here we manage to build static/dynamic libraries ourselves, -# do not use the top level settings. -string(REPLACE "-static-libgcc" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") -string(REPLACE "-static" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") - -if (CMAKE_COMPILER_IS_GNUCC AND NOT CMAKE_COMPILER_IS_CLANG) - set (tnt_cflags "${tnt_cflags} -static-libgcc") -endif() - -# -# Static library -# - -project(tntrpl) -add_library(tntrpl STATIC ${tntrpl_sources}) -set_target_properties(tntrpl PROPERTIES COMPILE_FLAGS "${tntrpl_cflags}") -set_target_properties(tntrpl PROPERTIES VERSION ${LIBTNT_VERSION} SOVERSION ${LIBTNT_SOVERSION}) -set_target_properties(tntrpl PROPERTIES OUTPUT_NAME "tarantoolrpl") - -# -# Shared library -# - -project(tntrpl_shared) -add_library(tntrpl_shared SHARED ${tntrpl_sources}) -target_link_libraries(tntrpl_shared tnt_shared tntnet_shared) -set_target_properties(tntrpl_shared PROPERTIES OUTPUT_NAME tntrpl) -set_target_properties(tntrpl_shared PROPERTIES COMPILE_FLAGS "${tntrpl_cflags}") -set_target_properties(tntrpl_shared PROPERTIES VERSION ${LIBTNT_VERSION} SOVERSION ${LIBTNT_SOVERSION}) -set_target_properties(tntrpl_shared PROPERTIES OUTPUT_NAME "tarantoolrpl") - -#----------------------------------------------------------------------------# -# Install -#----------------------------------------------------------------------------# - -install (TARGETS tntrpl ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) -install (TARGETS tntrpl_shared LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) diff --git a/connector/c/tntrpl/tnt_dir.c b/connector/c/tntrpl/tnt_dir.c deleted file mode 100644 index 3bd113f01e..0000000000 --- a/connector/c/tntrpl/tnt_dir.c +++ /dev/null @@ -1,173 +0,0 @@ - -/* - * 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 <stdlib.h> -#include <stdio.h> -#include <stdint.h> -#include <string.h> -#include <limits.h> - -#include <unistd.h> -#include <sys/types.h> -#include <dirent.h> -#include <errno.h> - -#include <connector/c/include/tarantool/tnt.h> -#include <connector/c/include/tarantool/tnt_dir.h> - -void tnt_dir_init(struct tnt_dir *d, enum tnt_dir_type type) { - d->type = type; - d->path = NULL; - d->files = NULL; - d->count = 0; -} - -void tnt_dir_free(struct tnt_dir *d) { - if (d->path) { - tnt_mem_free(d->path); - d->path = NULL; - } - if (d->files) { - int i = 0; - while (i < d->count) { - if (d->files[i].name) - tnt_mem_free(d->files[i].name); - i++; - } - tnt_mem_free(d->files); - d->files = NULL; - } -} - -static int tnt_dir_put(struct tnt_dir *d, - int *top, char *name, uint64_t lsn) -{ - if (d->count == *top) { - *top = (*top == 0) ? 128 : *top * 2; - d->files = tnt_mem_realloc(d->files, sizeof(struct tnt_dir_file) * *top); - if (d->files == NULL) - return -1; - } - struct tnt_dir_file *current = &d->files[d->count]; - current->lsn = lsn; - current->name = (char*)tnt_mem_dup(name); - if (current->name == NULL) - return -1; - d->count++; - return 0; -} - -static int tnt_dir_cmp(const void *_a, const void *_b) { - const struct tnt_dir_file *a = _a; - const struct tnt_dir_file *b = _b; - if (a->lsn == b->lsn) - return 0; - return (a->lsn > b->lsn) ? 1: -1; -} - -int tnt_dir_scan(struct tnt_dir *d, char *path) { - d->path = tnt_mem_dup(path); - if (d->path == NULL) - return -1; - DIR *dir = opendir(d->path); - if (dir == NULL) - goto error; - - struct dirent *dep = NULL; - struct dirent de; - int rc, top = 0; - while ((rc = readdir_r(dir, &de, &dep)) == 0) { - if (dep == NULL) - break; - if (strcmp(de.d_name, ".") == 0 || - strcmp(de.d_name, "..") == 0) - continue; - - char *ext = strchr(de.d_name, '.'); - if (ext == NULL) - continue; - - switch (d->type) { - case TNT_DIR_XLOG: - if (strcmp(ext, ".xlog") != 0) - continue; - break; - case TNT_DIR_SNAPSHOT: - if (strcmp(ext, ".snap") != 0) - continue; - break; - } - - uint64_t lsn = strtoll(de.d_name, &ext, 10); - if (lsn == LLONG_MAX || lsn == LLONG_MIN) - continue; - - rc = tnt_dir_put(d, &top, de.d_name, lsn); - if (rc == -1) - goto error; - } - if (rc != 0) - goto error; - - qsort(d->files, d->count, sizeof(struct tnt_dir_file), - tnt_dir_cmp); - - closedir(dir); - return 0; -error: - if (dir) - closedir(dir); - tnt_dir_free(d); - return -1; -} - -int tnt_dir_match_gt(struct tnt_dir *d, uint64_t *out) { - if (d->count == 0) - return -1; - *out = d->files[d->count -1].lsn; - return 0; -} - -int tnt_dir_match_inc(struct tnt_dir *d, uint64_t lsn, uint64_t *out) { - if (d->count == 0) - return -1; - int current = 0; - int count = d->count; - while (count > 1) { - if (d->files[current].lsn <= lsn && lsn <= d->files[current + 1].lsn) { - *out = d->files[current].lsn; - return 0; - } - current++; - count--; - } - *out = d->files[current].lsn; - return 0; -} diff --git a/connector/c/tntrpl/tnt_log.c b/connector/c/tntrpl/tnt_log.c deleted file mode 100644 index f625bf3bd4..0000000000 --- a/connector/c/tntrpl/tnt_log.c +++ /dev/null @@ -1,329 +0,0 @@ - -/* - * 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 <stdlib.h> -#include <stdio.h> -#include <stdarg.h> -#include <string.h> - -#include <unistd.h> -#include <fcntl.h> -#include <errno.h> - -#include <third_party/crc32.h> - -#include <connector/c/include/tarantool/tnt.h> -#include <connector/c/include/tarantool/tnt_log.h> - -enum tnt_log_type tnt_log_guess(char *file) { - if (file == NULL) - return TNT_LOG_XLOG; - char *ext = strrchr(file, '.'); - if (ext == NULL) - return TNT_LOG_NONE; - if (strcasecmp(ext, ".snap") == 0) - return TNT_LOG_SNAPSHOT; - if (strcasecmp(ext, ".xlog") == 0) - return TNT_LOG_XLOG; - return TNT_LOG_NONE; -} - -inline static int -tnt_log_seterr(struct tnt_log *l, enum tnt_log_error e) { - l->error = e; - if (e == TNT_LOG_ESYSTEM) - l->errno_ = errno; - return -1; -} - -const uint32_t tnt_log_marker_v11 = 0xba0babed; -const uint32_t tnt_log_marker_eof_v11 = 0x10adab1e; - -inline static int -tnt_log_eof(struct tnt_log *l, char *data) { - uint32_t marker = 0; - if (data) - tnt_mem_free(data); - /* checking eof condition */ - if (ftello(l->fd) == l->offset + sizeof(tnt_log_marker_eof_v11)) { - fseeko(l->fd, l->offset, SEEK_SET); - if (fread(&marker, sizeof(marker), 1, l->fd) != 1) - return tnt_log_seterr(l, TNT_LOG_ESYSTEM); - else - if (marker != tnt_log_marker_eof_v11) - return tnt_log_seterr(l, TNT_LOG_ECORRUPT); - l->offset = ftello(l->fd); - } - /* eof */ - return 1; -} - -static int tnt_log_read(struct tnt_log *l, char **buf, uint32_t *size) -{ - /* current record offset (before marker) */ - l->current_offset = ftello(l->fd); - - /* reading marker */ - char *data = NULL; - uint32_t marker = 0; - if (fread(&marker, sizeof(marker), 1, l->fd) != 1) - return tnt_log_eof(l, data); - - /* seeking for marker if necessary */ - while (marker != tnt_log_marker_v11) { - int c = fgetc(l->fd); - if (c == EOF) - return tnt_log_eof(l, data); - marker = marker >> 8 | ((uint32_t) c & 0xff) << - (sizeof(marker) * 8 - 8); - } - - /* reading header */ - if (fread(&l->current.hdr, sizeof(l->current.hdr), 1, l->fd) != 1) - return tnt_log_eof(l, data); - - /* updating offset */ - l->offset = ftello(l->fd); - - /* checking header crc, starting from lsn */ - uint32_t crc32_hdr = - crc32c(0, (unsigned char*)&l->current.hdr + sizeof(uint32_t), - sizeof(struct tnt_log_header_v11) - - sizeof(uint32_t)); - if (crc32_hdr != l->current.hdr.crc32_hdr) - return tnt_log_seterr(l, TNT_LOG_ECORRUPT); - - /* allocating memory and reading data */ - data = tnt_mem_alloc(l->current.hdr.len); - if (data == NULL) - return tnt_log_seterr(l, TNT_LOG_EMEMORY); - if (fread(data, l->current.hdr.len, 1, l->fd) != 1) - return tnt_log_eof(l, data); - - /* checking data crc */ - uint32_t crc32_data = crc32c(0, (unsigned char*)data, l->current.hdr.len); - if (crc32_data != l->current.hdr.crc32_data) { - tnt_mem_free(data); - return tnt_log_seterr(l, TNT_LOG_ECORRUPT); - } - - *buf = data; - *size = l->current.hdr.len; - return 0; -} - -static int -tnt_log_process_xlog(struct tnt_log *l, char *buf, uint32_t size, - union tnt_log_value *value) -{ - (void)size; - /* copying row data */ - memcpy(&l->current.row, buf, sizeof(l->current.row)); - - /* preparing pseudo iproto header */ - struct tnt_header hdr_iproto; - hdr_iproto.type = l->current.row.op; - hdr_iproto.len = l->current.hdr.len - sizeof(l->current.row); - hdr_iproto.reqid = 0; - - /* deserializing operation */ - tnt_request_init(&value->r); - size_t off = 0; - int rc = tnt_request(&value->r, - buf + sizeof(l->current.row), - l->current.hdr.len - sizeof(l->current.row), - &off, - &hdr_iproto); - - /* in case of not completed request or parsing error */ - if (rc != 0) - return tnt_log_seterr(l, TNT_LOG_ECORRUPT); - return 0; -} - -static int -tnt_log_process_snapshot(struct tnt_log *l, char *buf, uint32_t size, - union tnt_log_value *value) -{ - (void)size; - - /* freeing previously allocated tuple */ - tnt_tuple_free(&value->t); - - /* copying snapshot row data */ - memcpy(&l->current.row_snap, buf, sizeof(l->current.row_snap)); - - /* reading and validating tuple */ - struct tnt_tuple *tu = - tnt_tuple_set_as(&value->t, buf + sizeof(l->current.row_snap), - l->current.row_snap.data_size, - l->current.row_snap.tuple_size); - if (tu == NULL) - return tnt_log_seterr(l, TNT_LOG_ECORRUPT); - - return (tu) ? 0 : -1; -} - -struct tnt_log_row* -tnt_log_next_to(struct tnt_log *l, union tnt_log_value *value) { - char *buf = NULL; - uint32_t size = 0; - int rc = l->read(l, &buf, &size); - if (rc != 0) - return NULL; - rc = l->process(l, buf, size, value); - if (rc != 0) { - tnt_mem_free(buf); - return NULL; - } - if (l->type == TNT_LOG_XLOG) { - tnt_request_setorigin(&value->r, buf, size); - } else { - tnt_mem_free(buf); - } - return &l->current; -} - -struct tnt_log_row *tnt_log_next(struct tnt_log *l) { - return tnt_log_next_to(l, &l->current_value); -} - -inline static int -tnt_log_open_err(struct tnt_log *l, enum tnt_log_error e) { - tnt_log_seterr(l, e); - tnt_log_close(l); - return -1; -} - -enum tnt_log_error -tnt_log_open(struct tnt_log *l, char *file, enum tnt_log_type type) -{ - char filetype[32]; - char version[32]; - char *rc, *magic = "\0"; - l->type = type; - /* trying to open file */ - if (file) { - l->fd = fopen(file, "r"); - if (l->fd == NULL) - return tnt_log_open_err(l, TNT_LOG_ESYSTEM); - } else { - l->fd = stdin; - } - /* reading xlog filetype */ - rc = fgets(filetype, sizeof(filetype), l->fd); - if (rc == NULL) - return tnt_log_open_err(l, TNT_LOG_ESYSTEM); - /* reading log version */ - rc = fgets(version, sizeof(version), l->fd); - if (rc == NULL) - return tnt_log_open_err(l, TNT_LOG_ESYSTEM); - /* checking file type and setting read/process - * interfaces */ - l->read = tnt_log_read; - switch (type) { - case TNT_LOG_XLOG: - magic = TNT_LOG_MAGIC_XLOG; - l->process = tnt_log_process_xlog; - break; - case TNT_LOG_SNAPSHOT: - magic = TNT_LOG_MAGIC_SNAP; - l->process = tnt_log_process_snapshot; - break; - case TNT_LOG_NONE: - break; - } - if (strcmp(filetype, magic)) - return tnt_log_open_err(l, TNT_LOG_ETYPE); - /* checking version */ - if (strcmp(version, TNT_LOG_VERSION)) - return tnt_log_open_err(l, TNT_LOG_EVERSION); - for (;;) { - char buf[256]; - rc = fgets(buf, sizeof(buf), l->fd); - if (rc == NULL) - return tnt_log_open_err(l, TNT_LOG_EFAIL); - if (strcmp(rc, "\n") == 0 || strcmp(rc, "\r\n") == 0) - break; - } - /* getting current offset */ - l->offset = ftello(l->fd); - l->current_offset = 0; - memset(&l->current_value, 0, sizeof(l->current_value)); - return 0; -} - -void tnt_log_close(struct tnt_log *l) { - if (l->fd && l->fd != stdin) - fclose(l->fd); - l->fd = NULL; -} - -int tnt_log_seek(struct tnt_log *l, off_t offset) -{ - l->offset = offset; - return fseeko(l->fd, offset, SEEK_SET); -} - -enum tnt_log_error tnt_log_error(struct tnt_log *l) { - return l->error; -} - -struct tnt_log_error_desc { - enum tnt_log_error type; - char *desc; -}; - -static struct tnt_log_error_desc tnt_log_error_list[] = -{ - { TNT_LOG_EOK, "ok" }, - { TNT_LOG_EFAIL, "fail" }, - { TNT_LOG_EMEMORY, "memory allocation failed" }, - { TNT_LOG_ETYPE, "file type mismatch" }, - { TNT_LOG_EVERSION, "file version mismatch" }, - { TNT_LOG_ECORRUPT, "file crc failed or bad eof marker" }, - { TNT_LOG_ESYSTEM, "system error" }, - { TNT_LOG_LAST, NULL } -}; - -char *tnt_log_strerror(struct tnt_log *l) { - if (l->error == TNT_LOG_ESYSTEM) { - static char msg[256]; - snprintf(msg, sizeof(msg), "%s (errno: %d)", - strerror(l->errno_), - l->errno_); - return msg; - } - return tnt_log_error_list[(int)l->error].desc; -} - -int tnt_log_errno(struct tnt_log *l) { - return l->errno_; -} diff --git a/connector/c/tntrpl/tnt_rpl.c b/connector/c/tntrpl/tnt_rpl.c deleted file mode 100644 index 2316d0dc1e..0000000000 --- a/connector/c/tntrpl/tnt_rpl.c +++ /dev/null @@ -1,200 +0,0 @@ - -/* - * 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 <stdlib.h> -#include <stdio.h> -#include <stdarg.h> -#include <string.h> - -#include <unistd.h> -#include <fcntl.h> -#include <errno.h> - -#include <connector/c/include/tarantool/tnt.h> -#include <connector/c/include/tarantool/tnt_net.h> -#include <connector/c/include/tarantool/tnt_io.h> -#include <connector/c/include/tarantool/tnt_log.h> -#include <connector/c/include/tarantool/tnt_rpl.h> - -static const uint32_t tnt_rpl_version = 12; - -static void tnt_rpl_free(struct tnt_stream *s) { - struct tnt_stream_rpl *sr = TNT_RPL_CAST(s); - if (sr->net) { - /* network stream should not be free'd here */ - sr->net = NULL; - } - tnt_mem_free(s->data); -} - -static ssize_t -tnt_rpl_recv_cb(struct tnt_stream *s, char *buf, ssize_t size) { - struct tnt_stream_net *sn = TNT_SNET_CAST(s); - return tnt_io_recv(sn, buf, size); -} - -static int -tnt_rpl_request(struct tnt_stream *s, struct tnt_request *r) -{ - struct tnt_stream_rpl *sr = TNT_RPL_CAST(s); - struct tnt_stream_net *sn = TNT_SNET_CAST(sr->net); - /* fetching header */ - if (tnt_io_recv(sn, (char*)&sr->hdr, sizeof(sr->hdr)) == -1) - return -1; - /* fetching row header */ - if (tnt_io_recv(sn, (char*)&sr->row, sizeof(sr->row)) == -1) - return -1; - /* preparing pseudo iproto header */ - struct tnt_header hdr_iproto; - hdr_iproto.type = sr->row.op; - hdr_iproto.len = sr->hdr.len - sizeof(struct tnt_log_row_v11); - hdr_iproto.reqid = 0; - /* deserializing operation */ - if (tnt_request_from(r, (tnt_request_t)tnt_rpl_recv_cb, - sr->net, - &hdr_iproto) == -1) - return -1; - return 0; -} - -/* - * tnt_rpl() - * - * create and initialize replication stream; - * - * s - stream pointer, maybe NULL - * - * if stream pointer is NULL, then new stream will be created. - * - * returns stream pointer, or NULL on error. -*/ -struct tnt_stream *tnt_rpl(struct tnt_stream *s) -{ - int allocated = s == NULL; - s = tnt_stream_init(s); - if (s == NULL) - return NULL; - /* allocating stream data */ - s->data = tnt_mem_alloc(sizeof(struct tnt_stream_rpl)); - if (s->data == NULL) - goto error; - memset(s->data, 0, sizeof(struct tnt_stream_rpl)); - /* initializing interfaces */ - s->read = NULL; - s->read_request = tnt_rpl_request; - s->read_reply = NULL; - s->read_tuple = NULL; - s->write = NULL; - s->writev = NULL; - s->free = tnt_rpl_free; - /* initializing internal data */ - struct tnt_stream_rpl *sr = TNT_RPL_CAST(s); - sr->net = NULL; - return s; -error: - if (s->data) { - tnt_mem_free(s->data); - s->data = NULL; - } - if (allocated) - tnt_stream_free(s); - return NULL; -} - -/* - * tnt_rpl_open() - * - * connect to a server and initialize handshake; - * - * s - replication stream pointer - * lsn - start lsn - * - * network stream must be properly initialized before - * this function called (see ttnt_rpl_net, tnt_set). - * - * returns 0 on success, or -1 on error. -*/ -int tnt_rpl_open(struct tnt_stream *s, uint64_t lsn) -{ - struct tnt_stream_rpl *sr = TNT_RPL_CAST(s); - /* intializing connection */ - if (tnt_init(sr->net) == -1) - return -1; - if (tnt_connect(sr->net) == -1) - return -1; - struct tnt_stream_net *sn = TNT_SNET_CAST(sr->net); - - /* handshake : send version */ - uint32_t send_version[3] = { tnt_rpl_version, 0, 0 }; - if (tnt_io_send_raw(sn, (char*)send_version, sizeof(send_version), 1) == -1) - return -1; - /* handshake : reading and checking version */ - uint32_t recv_version[3] = { 0 }; - if (tnt_io_recv_raw(sn, (char*)recv_version, sizeof(recv_version), 1) == -1) - return -1; - if (recv_version[0] != tnt_rpl_version) - return -1; - - /* sending request */ - uint32_t request = 0; - if (tnt_io_send_raw(sn, (char*)&request, sizeof(request), 1) == -1) - return -1; - - /* sending initial lsn */ - if (tnt_io_send_raw(sn, (char*)&lsn, sizeof(lsn), 1) == -1) - return -1; - return 0; -} - -/* - * tnt_rpl_close() - * - * close a connection; - * - * s - replication stream pointer - * - * returns 0 on success, or -1 on error. -*/ -void tnt_rpl_close(struct tnt_stream *s) { - struct tnt_stream_rpl *sr = TNT_RPL_CAST(s); - if (sr->net) - tnt_close(s); -} - -/* - * tnt_rpl_attach() - * - * attach network stream (tnt_stream_net object); - * - * s - replication stream pointer -*/ -void tnt_rpl_attach(struct tnt_stream *s, struct tnt_stream *net) { - TNT_RPL_CAST(s)->net = net; -} diff --git a/connector/c/tntrpl/tnt_snapshot.c b/connector/c/tntrpl/tnt_snapshot.c deleted file mode 100644 index 07b486802c..0000000000 --- a/connector/c/tntrpl/tnt_snapshot.c +++ /dev/null @@ -1,163 +0,0 @@ - -/* - * 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 <stdlib.h> -#include <stdio.h> -#include <stdarg.h> -#include <string.h> - -#include <unistd.h> -#include <fcntl.h> -#include <errno.h> - -#include <third_party/crc32.h> - -#include <connector/c/include/tarantool/tnt.h> -#include <connector/c/include/tarantool/tnt_log.h> -#include <connector/c/include/tarantool/tnt_snapshot.h> - -static void tnt_snapshot_free(struct tnt_stream *s) { - struct tnt_stream_snapshot *ss = TNT_SSNAPSHOT_CAST(s); - tnt_log_close(&ss->log); - tnt_mem_free(s->data); - s->data = NULL; -} - -static int -tnt_snapshot_read_tuple(struct tnt_stream *s, struct tnt_tuple *t) -{ - struct tnt_stream_snapshot *ss = TNT_SSNAPSHOT_CAST(s); - - struct tnt_log_row *row = - tnt_log_next_to(&ss->log, (union tnt_log_value*)t); - - if (row == NULL && tnt_log_error(&ss->log) == TNT_LOG_EOK) - return 1; - - return (row) ? 0: -1; -} - -/* - * tnt_snapshot() - * - * create and initialize snapshot stream; - * - * s - stream pointer, maybe NULL - * - * if stream pointer is NULL, then new stream will be created. - * - * returns stream pointer, or NULL on error. -*/ -struct tnt_stream *tnt_snapshot(struct tnt_stream *s) -{ - int allocated = s == NULL; - s = tnt_stream_init(s); - if (s == NULL) - return NULL; - /* allocating stream data */ - s->data = tnt_mem_alloc(sizeof(struct tnt_stream_snapshot)); - if (s->data == NULL) { - if (allocated) - tnt_stream_free(s); - return NULL; - } - memset(s->data, 0, sizeof(struct tnt_stream_snapshot)); - /* initializing interfaces */ - s->read = NULL; - s->read_request = NULL; - s->read_reply = NULL; - s->read_tuple = tnt_snapshot_read_tuple; - s->write = NULL; - s->writev = NULL; - s->free = tnt_snapshot_free; - /* initializing internal data */ - return s; -} - -/* - * tnt_snapshot_open() - * - * open snapshot file and associate it with stream; - * - * s - snapshot stream pointer - * - * returns 0 on success, or -1 on error. -*/ -int tnt_snapshot_open(struct tnt_stream *s, char *file) { - struct tnt_stream_snapshot *ss = TNT_SSNAPSHOT_CAST(s); - return tnt_log_open(&ss->log, file, TNT_LOG_SNAPSHOT); -} - -/* - * tnt_snapshot_close() - * - * close snapshot stream; - * - * s - snapshot stream pointer - * - * returns 0 on success, or -1 on error. -*/ -void tnt_snapshot_close(struct tnt_stream *s) { - struct tnt_stream_snapshot *ss = TNT_SSNAPSHOT_CAST(s); - tnt_log_close(&ss->log); -} - -/* - * tnt_snapshot_error() - * - * get stream error status; - * - * s - snapshot stream pointer -*/ -enum tnt_log_error tnt_snapshot_error(struct tnt_stream *s) { - return TNT_SSNAPSHOT_CAST(s)->log.error; -} - -/* - * tnt_snapshot_strerror() - * - * get stream error status description string; - * - * s - snapshot stream pointer -*/ -char *tnt_snapshot_strerror(struct tnt_stream *s) { - return tnt_log_strerror(&TNT_SSNAPSHOT_CAST(s)->log); -} - -/* - * tnt_snapshot_errno() - * - * get saved errno; - * - * s - snapshot stream pointer -*/ -int tnt_snapshot_errno(struct tnt_stream *s) { - return TNT_SSNAPSHOT_CAST(s)->log.errno_; -} diff --git a/connector/c/tntrpl/tnt_xlog.c b/connector/c/tntrpl/tnt_xlog.c deleted file mode 100644 index 622201e79f..0000000000 --- a/connector/c/tntrpl/tnt_xlog.c +++ /dev/null @@ -1,163 +0,0 @@ - -/* - * 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 <stdlib.h> -#include <stdio.h> -#include <stdarg.h> -#include <string.h> - -#include <unistd.h> -#include <fcntl.h> -#include <errno.h> - -#include <third_party/crc32.h> - -#include <connector/c/include/tarantool/tnt.h> -#include <connector/c/include/tarantool/tnt_log.h> -#include <connector/c/include/tarantool/tnt_xlog.h> - -static void tnt_xlog_free(struct tnt_stream *s) { - struct tnt_stream_xlog *sx = TNT_SXLOG_CAST(s); - tnt_log_close(&sx->log); - tnt_mem_free(s->data); - s->data = NULL; -} - -static int -tnt_xlog_request(struct tnt_stream *s, struct tnt_request *r) -{ - struct tnt_stream_xlog *sx = TNT_SXLOG_CAST(s); - - struct tnt_log_row *row = - tnt_log_next_to(&sx->log, (union tnt_log_value*)r); - - if (row == NULL && tnt_log_error(&sx->log) == TNT_LOG_EOK) - return 1; - - return (row) ? 0: -1; -} - -/* - * tnt_xlog() - * - * create and initialize xlog stream; - * - * s - stream pointer, maybe NULL - * - * if stream pointer is NULL, then new stream will be created. - * - * returns stream pointer, or NULL on error. -*/ -struct tnt_stream *tnt_xlog(struct tnt_stream *s) -{ - int allocated = s == NULL; - s = tnt_stream_init(s); - if (s == NULL) - return NULL; - /* allocating stream data */ - s->data = tnt_mem_alloc(sizeof(struct tnt_stream_xlog)); - if (s->data == NULL) { - if (allocated) - tnt_stream_free(s); - return NULL; - } - memset(s->data, 0, sizeof(struct tnt_stream_xlog)); - /* initializing interfaces */ - s->read = NULL; - s->read_request = tnt_xlog_request; - s->read_reply = NULL; - s->read_tuple = NULL; - s->write = NULL; - s->writev = NULL; - s->free = tnt_xlog_free; - /* initializing internal data */ - return s; -} - -/* - * tnt_xlog_open() - * - * open xlog file and associate it with stream; - * - * s - xlog stream pointer - * - * returns 0 on success, or -1 on error. -*/ -int tnt_xlog_open(struct tnt_stream *s, char *file) { - struct tnt_stream_xlog *sx = TNT_SXLOG_CAST(s); - return tnt_log_open(&sx->log, file, TNT_LOG_XLOG); -} - -/* - * tnt_xlog_close() - * - * close xlog stream; - * - * s - xlog stream pointer - * - * returns 0 on success, or -1 on error. -*/ -void tnt_xlog_close(struct tnt_stream *s) { - struct tnt_stream_xlog *sx = TNT_SXLOG_CAST(s); - tnt_log_close(&sx->log); -} - -/* - * tnt_xlog_error() - * - * get stream error status; - * - * s - xlog stream pointer -*/ -enum tnt_log_error tnt_xlog_error(struct tnt_stream *s) { - return TNT_SXLOG_CAST(s)->log.error; -} - -/* - * tnt_xlog_strerror() - * - * get stream error status description string; - * - * s - xlog stream pointer -*/ -char *tnt_xlog_strerror(struct tnt_stream *s) { - return tnt_log_strerror(&TNT_SXLOG_CAST(s)->log); -} - -/* - * tnt_xlog_errno() - * - * get saved errno; - * - * s - xlog stream pointer -*/ -int tnt_xlog_errno(struct tnt_stream *s) { - return TNT_SXLOG_CAST(s)->log.errno_; -} diff --git a/connector/c/tntsql/CMakeLists.txt b/connector/c/tntsql/CMakeLists.txt deleted file mode 100644 index 09da87d382..0000000000 --- a/connector/c/tntsql/CMakeLists.txt +++ /dev/null @@ -1,71 +0,0 @@ -#============================================================================# -# build flags -#============================================================================# - -# default flags -if (${CMAKE_BUILD_TYPE} STREQUAL "None") - set (tntsql_cflags "-std=gnu99") -else() - set (tntsql_cflags "-std=gnu99 -Wall -Wextra") - set (tntsql_cflags "${tntsql_cflags} -Wno-sign-compare -Wno-strict-aliasing") -endif() - -# Only add -Werror if it's a debug build, done by developers. -if (${CMAKE_BUILD_TYPE} STREQUAL "Debug") - set (tntsql_cflags "${tntsql_cflags} -Werror") -endif() - -#============================================================================# -# Build tnt sql project -#============================================================================# - -# -# source files -# - -set (tntsql_sources - tnt_utf8.c - tnt_lex.c - tnt_sql.c) - -#----------------------------------------------------------------------------# -# Builds -#----------------------------------------------------------------------------# - -# Here we manage to build static/dynamic libraries ourselves, -# do not use the top level settings. -string(REPLACE "-static-libgcc" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") -string(REPLACE "-static" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") - -if (CMAKE_COMPILER_IS_GNUCC AND NOT CMAKE_COMPILER_IS_CLANG) - set (tnt_cflags "${tnt_cflags} -static-libgcc") -endif() - -# -# Static library -# - -project(tntsql) -add_library(tntsql STATIC ${tntsql_sources}) -set_target_properties(tntsql PROPERTIES COMPILE_FLAGS "${tntsql_cflags}") -set_target_properties(tntsql PROPERTIES VERSION ${LIBTNT_VERSION} SOVERSION ${LIBTNT_SOVERSION}) -set_target_properties(tntsql PROPERTIES OUTPUT_NAME "tarantoolsql") - -# -# Shared library -# - -project(tntsql_shared) -add_library(tntsql_shared SHARED ${tntsql_sources}) -target_link_libraries(tntsql_shared tnt_shared) -set_target_properties(tntsql_shared PROPERTIES OUTPUT_NAME tntsql) -set_target_properties(tntsql_shared PROPERTIES COMPILE_FLAGS "${tntsql_cflags}") -set_target_properties(tntsql_shared PROPERTIES VERSION ${LIBTNT_VERSION} SOVERSION ${LIBTNT_SOVERSION}) -set_target_properties(tntsql_shared PROPERTIES OUTPUT_NAME "tarantoolsql") - -#----------------------------------------------------------------------------# -# Install -#----------------------------------------------------------------------------# - -install (TARGETS tntsql ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) -install (TARGETS tntsql_shared LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) diff --git a/connector/c/tntsql/tnt_lex.c b/connector/c/tntsql/tnt_lex.c deleted file mode 100644 index 0238b6da73..0000000000 --- a/connector/c/tntsql/tnt_lex.c +++ /dev/null @@ -1,354 +0,0 @@ - -/* - * 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 <stdint.h> -#include <stdbool.h> -#include <stdarg.h> -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <ctype.h> -#include <limits.h> -#include <errno.h> - -#include <connector/c/include/tarantool/tnt.h> -#include <connector/c/include/tarantool/tnt_utf8.h> -#include <connector/c/include/tarantool/tnt_queue.h> -#include <connector/c/include/tarantool/tnt_lex.h> - -bool tnt_lex_init(struct tnt_lex *l, struct tnt_lex_keyword *keywords, - unsigned char *buf, size_t size) -{ - if (!tnt_utf8_init(&l->buf, buf, size)) - return false; - l->keywords = keywords; - l->pos = 0; - l->col = 1; - l->line = 1; - l->count = 0; - l->countq = 0; - SLIST_INIT(&l->stack); - STAILQ_INIT(&l->q); - l->error = NULL; - l->idonly = false; - return true; -} - -void tnt_lex_free(struct tnt_lex *l) -{ - struct tnt_tk *tk, *tkn; - STAILQ_FOREACH_SAFE(tk, &l->q, nextq, tkn) { - if (tk->tk == TNT_TK_STRING || tk->tk == TNT_TK_ID) - tnt_utf8_free(TNT_TK_S(tk)); - tnt_mem_free(tk); - } - tnt_utf8_free(&l->buf); - if (l->error) - tnt_mem_free(l->error); -} - -void tnt_lex_push(struct tnt_lex *l, struct tnt_tk *tk) -{ - SLIST_INSERT_HEAD(&l->stack, tk, next); - l->count++; -} - -void -tnt_lex_idonly(struct tnt_lex *l, bool on) -{ - l->idonly = on; -} - -static struct tnt_tk* -tnt_lex_pop(struct tnt_lex *l) -{ - if (l->count == 0) - return NULL; - struct tnt_tk *tk = SLIST_FIRST(&l->stack); - SLIST_REMOVE_HEAD(&l->stack, next); - l->count--; - return tk; -} - -static struct tnt_tk* -tnt_lex_tk(struct tnt_lex *l, int tk, int line, int col) { - struct tnt_tk *t = tnt_mem_alloc(sizeof(struct tnt_tk)); - memset(t, 0, sizeof(struct tnt_tk)); - t->tk = tk; - t->line = line; - t->col = col; - STAILQ_INSERT_TAIL(&l->q, t, nextq); - l->countq++; - return t; -} - -static int -tnt_lex_error(struct tnt_lex *l, const char *fmt, ...) { - if (fmt == NULL) - return TNT_TK_EOF; - if (l->error) - tnt_mem_free(l->error); - char msg[256]; - va_list args; - va_start(args, fmt); - vsnprintf(msg, sizeof(msg), fmt, args); - va_end(args); - l->error = tnt_mem_dup(msg); - return TNT_TK_ERROR; -} - -inline static ssize_t -tnt_lex_next(struct tnt_lex *l) { - ssize_t r = tnt_utf8_next(&l->buf, l->pos); - if (r > 0) { - l->pos = r; - l->col++; - } - return r; -} - -char* -tnt_lex_nameof(struct tnt_lex *l, int tk) -{ - /* system tokens */ - switch (tk) { - case TNT_TK_EOF: return "End-Of-Statement"; - case TNT_TK_ERROR: return "ERROR"; - case TNT_TK_NUM32: return "NUM32"; - case TNT_TK_NUM64: return "NUM64"; - case TNT_TK_STRING: return "STRING"; - case TNT_TK_ID: return "ID"; - case TNT_TK_KEY: return "KEY"; - case TNT_TK_TABLE: return "TABLE"; - case TNT_TK_PUNCT: return "PUNCT"; - } - /* matching keyword */ - int i; - for (i = 0 ; l->keywords[i].name ; i++) - if (l->keywords[i].tk == tk) - return l->keywords[i].name; - return NULL; -} - -#define tnt_lex_step(l) \ - do { \ - ssize_t r = tnt_lex_next(l); \ - if (r == -1) \ - return tnt_lex_error(l, "utf8 decoding error"); \ - } while (0) - -#define tnt_lex_try(l, reason) \ - do { \ - ssize_t r = tnt_lex_next(l); \ - if (r == -1) \ - return tnt_lex_error(l, "utf8 decoding error"); \ - else \ - if (r == 0) \ - return tnt_lex_error(l, reason); \ - } while (0) - -#define tnt_lex_chr(l) (*TNT_UTF8_CHAR(&l->buf, l->pos)) - -int -tnt_lex(struct tnt_lex *l, struct tnt_tk **tk) -{ - /* trying stack first */ - if (l->count) { - *tk = tnt_lex_pop(l); - if ((*tk)->tk == TNT_TK_PUNCT) - return TNT_TK_I32(*tk); - return (*tk)->tk; - } - - /* skipping spaces and comments */ - unsigned char ch; - while (1) { - if (l->pos == l->buf.size) { - *tk = tnt_lex_tk(l, TNT_TK_EOF, l->line, l->col); - return TNT_TK_EOF; - } - ch = tnt_lex_chr(l); - if (isspace(ch)) { - if (ch == '\n') { - if (((l->pos + 1) != l->buf.size)) - l->line++; - l->col = 0; - } - tnt_lex_step(l); - continue; - } else - if (ch == '#') { - while (1) { - if (l->pos == l->buf.size) { - *tk = tnt_lex_tk(l, TNT_TK_EOF, l->line, l->col); - return TNT_TK_EOF; - } - tnt_lex_step(l); - if (tnt_lex_chr(l) == '\n') { - if (((l->pos + 1) != l->buf.size)) - l->line++; - l->col = 0; - tnt_lex_step(l); - break; - } - } - continue; - } - break; - } - - /* saving lexem position */ - int line = l->line; - int col = l->col; - ssize_t start = l->pos, size = 0; - ch = tnt_lex_chr(l); - - /* string */ - if (ch == '\'') { - start++; - while (1) { - tnt_lex_try(l, "bad string definition"); - ch = tnt_lex_chr(l); - if (ch == '\'') - break; - if (ch == '\n') - return tnt_lex_error(l, "bad string definition"); - } - size = l->pos - start; - tnt_lex_step(l); - *tk = tnt_lex_tk(l, TNT_TK_STRING, line, col); - if (size > 0) - tnt_utf8_init(TNT_TK_S(*tk), TNT_UTF8_CHAR(&l->buf, start), size); - return TNT_TK_STRING; - } - - bool minus = false; - /* punctuation */ - if (ispunct(ch) && ch != '_') { - tnt_lex_step(l); - if (ch == '-') { - ch = tnt_lex_chr(l); - if (isdigit(ch)) { - minus = true; - goto numeric; - } - } - *tk = tnt_lex_tk(l, TNT_TK_PUNCT, line, col); - TNT_TK_I32(*tk) = ch; - return ch; - } - -numeric: /* numeric value */ - if (isdigit(ch)) { - int64_t num = 0; - while (1) { - if (isdigit(tnt_lex_chr(l))) - num = (num * 10) + tnt_lex_chr(l) - '0'; - else - break; - ssize_t r = tnt_lex_next(l); - if (r == -1) - return tnt_lex_error(l, "utf8 decoding error"); - if (r == 0) - break; - } - if (minus) - num *= -1; - if (tnt_lex_chr(l) == 'L') { - ssize_t r = tnt_lex_next(l); - if (r == -1) - return tnt_lex_error(l, "utf8 decoding error"); - } else - if (num >= INT_MIN && num < INT_MAX) { - *tk = tnt_lex_tk(l, TNT_TK_NUM32, line, col); - TNT_TK_I32(*tk) = (int32_t)num; - return TNT_TK_NUM32; - } - *tk = tnt_lex_tk(l, TNT_TK_NUM64, line, col); - TNT_TK_I64(*tk) = num; - return TNT_TK_NUM64; - } - - /* skipping to the end of lexem */ - while (1) { - ch = tnt_lex_chr(l); - if (isspace(ch) || (ispunct(ch) && ch != '_')) - break; - ssize_t r = tnt_lex_next(l); - if (r == -1) - return tnt_lex_error(l, "utf8 decoding error"); - else - if (r == 0) - break; - } - size = l->pos - start; - - /* handle to tell lexer that table's, key's and keyword's are id's */ - if (l->idonly) - goto id; - - /* matching keyword */ - int i; - for (i = 0 ; l->keywords[i].name ; i++) { - if (l->keywords[i].size != size) - continue; - if (strncasecmp(l->keywords[i].name, - (const char*)TNT_UTF8_CHAR(&l->buf, start), size) == 0) { - *tk = tnt_lex_tk(l, l->keywords[i].tk, line, col); - return l->keywords[i].tk; - } - } - - /* table or key id */ - ch = *TNT_UTF8_CHAR(&l->buf, start); - if ((ch == 't' || ch == 'k') && size >= 2) { - int idtk = (ch == 't') ? TNT_TK_TABLE : TNT_TK_KEY; - int32_t id = 0; - for (i = 1 ; i < size ; i++) { - ch = *TNT_UTF8_CHAR(&l->buf, start + i); - if (isdigit(ch)) - id *= 10, id += ch - '0'; - else - goto id; - } - *tk = tnt_lex_tk(l, idtk, line, col); - TNT_TK_I32(*tk) = id; - return idtk; - } - -id: /* assuming id */ - *tk = tnt_lex_tk(l, TNT_TK_ID, line, col); - tnt_utf8_init(TNT_TK_S(*tk), TNT_UTF8_CHAR(&l->buf, start), size); - return TNT_TK_ID; -} - -#undef tnt_lex_step -#undef tnt_lex_try -#undef tnt_lex_chr diff --git a/connector/c/tntsql/tnt_sql.c b/connector/c/tntsql/tnt_sql.c deleted file mode 100644 index f6fba568f9..0000000000 --- a/connector/c/tntsql/tnt_sql.c +++ /dev/null @@ -1,531 +0,0 @@ - -/* - * 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 <stdint.h> -#include <stdbool.h> -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <ctype.h> - -#include <connector/c/include/tarantool/tnt.h> -#include <connector/c/include/tarantool/tnt_queue.h> -#include <connector/c/include/tarantool/tnt_utf8.h> -#include <connector/c/include/tarantool/tnt_lex.h> - -/* sql parsing context. */ - -struct tnt_sql { - struct tnt_stream *s; - struct tnt_lex *l; - char *error; -}; - -static bool -tnt_sql_error(struct tnt_sql *sql, struct tnt_tk *last, const char *fmt, ...) -{ - char msgu[256]; - va_list args; - va_start(args, fmt); - vsnprintf(msgu, sizeof(msgu), fmt, args); - va_end(args); - int line = (last) ? last->line : sql->l->line; - int col = (last) ? last->col : sql->l->col; - char msg[256]; - snprintf(msg, sizeof(msg), "%d:%d %s", line, col, msgu); - if (sql->error == NULL) - sql->error = tnt_mem_dup(msg); - return false; -} - -/* token validating routines. */ - -static bool -tnt_sql_tk(struct tnt_sql *sql, int tk, struct tnt_tk **tkp) -{ - struct tnt_tk *tkp_ = NULL; - int tk_ = tnt_lex(sql->l, &tkp_); - if (tk_ == TNT_TK_ERROR) - return tnt_sql_error(sql, NULL, "%s", sql->l->error); - if (tk_ != tk) { - if (tk < 0xff && ispunct(tk)) - return tnt_sql_error(sql, tkp_, "expected '%c'", tk); - return tnt_sql_error(sql, tkp_, "expected '%s'", tnt_lex_nameof(sql->l, tk)); - } - if (tkp) - *tkp = tkp_; - return true; -} -inline static bool -tnt_sqltk(struct tnt_sql *sql,int tk) { - return tnt_sql_tk(sql, tk, NULL); -} -inline static bool -tnt_sqltkv(struct tnt_sql *sql, int tk, struct tnt_tk **tkp) { - return tnt_sql_tk(sql, tk, tkp); -} - -static bool -tnt_sql_try(struct tnt_sql *sql, int tk, struct tnt_tk **tkp) { - struct tnt_tk *tkp_ = NULL; - int tk_ = tnt_lex(sql->l, &tkp_); - if (tk_ == TNT_TK_ERROR) - return tnt_sql_error(sql, NULL, "%s", sql->l->error); - if (tk_ != tk) { - tnt_lex_push(sql->l, tkp_); - return false; - } - if (tkp) - *tkp = tkp_; - return true; -} -inline static int -tnt_sqltry(struct tnt_sql *sql, int tk) { - return tnt_sql_try(sql, tk, NULL); -} -inline static int -tnt_sqltryv(struct tnt_sql *sql, int tk, struct tnt_tk **tkp) { - return tnt_sql_try(sql, tk, tkp); -} - -/* key-value parsing for tuple operation. */ - -static bool -tnt_sql_keyval(struct tnt_sql *sql, struct tnt_tuple *tu, bool key, struct tnt_tk **kt) -{ - /* key */ - struct tnt_tk *k = NULL; - if (key && (!tnt_sqltkv(sql, TNT_TK_KEY, &k) || !tnt_sqltk(sql, '='))) - return false; - if (kt) - *kt = k; - /* value */ - struct tnt_tk *v = NULL; - if (tnt_lex(sql->l, &v) == TNT_TK_ERROR) - return tnt_sql_error(sql, NULL, "%s", sql->l->error); - switch (v->tk) { - case TNT_TK_NUM32: - tnt_tuple_add(tu, (char*)&TNT_TK_I32(v), 4); - break; - case TNT_TK_NUM64: - tnt_tuple_add(tu, (char*)&TNT_TK_I64(v), 8); - break; - case TNT_TK_STRING: - tnt_tuple_add(tu, (char*)TNT_TK_S(v)->data, - TNT_TK_S(v)->size); - break; - default: - return tnt_sql_error(sql, k, "expected NUM32 or NUM64 or STRING"); - } - return true; -} - -static bool -tnt_sql_kv(struct tnt_sql *sql, struct tnt_tuple *tu, bool key) { - return tnt_sql_keyval(sql, tu, key, NULL); -} - -static bool -tnt_sql_kv_select(struct tnt_sql *sql, struct tnt_tuple *tu, int32_t *index) -{ - struct tnt_tk *key = NULL; - bool rc = tnt_sql_keyval(sql, tu, true, &key); - if (rc == false) - return false; - if (*index == -1) - *index = TNT_TK_I32(key); - else - if (*index != TNT_TK_I32(key)) - return tnt_sql_error(sql, key, - "select key values must refer to the same index"); - return true; -} - -#define tnt_expect(a) \ - do { if (!(a)) goto error; } while (0) - -/* parsing update statement. */ - -static bool -tnt_sql_stmt_update(struct tnt_sql *sql, struct tnt_tuple *tu, struct tnt_stream *u) -{ - /* UPDATE TABLE SET operations WHERE predicate */ - bool rc = false; - struct tnt_tk *tn = NULL; - tnt_expect(tnt_sqltkv(sql, TNT_TK_TABLE, &tn)); - tnt_expect(tnt_sqltk(sql, TNT_TK_SET)); - while (1) { - struct tnt_tk *k = NULL; - tnt_expect(tnt_sqltkv(sql, TNT_TK_KEY, &k)); - tnt_expect(tnt_sqltk(sql, '=')); - struct tnt_tk *v; - switch (tnt_lex(sql->l, &v)) { - /* k = k op v */ - case TNT_TK_KEY: - if (TNT_TK_I32(k) != TNT_TK_I32(v)) { - tnt_sql_error(sql, k, "can't update on different keys"); - goto error; - } - int ut; - switch (tnt_lex(sql->l, &v)) { - case TNT_TK_ERROR: - tnt_sql_error(sql, k, "%s", sql->l->error); - goto error; - case '+': ut = TNT_UPDATE_ADD; - break; - case '&': ut = TNT_UPDATE_AND; - break; - case '^': ut = TNT_UPDATE_XOR; - break; - case '|': ut = TNT_UPDATE_OR; - break; - default: - tnt_sql_error(sql, k, "bad update operation"); - goto error; - } - tnt_expect(tnt_sqltkv(sql, TNT_TK_NUM32, &v)); - tnt_update_arith(u, TNT_TK_I32(k), ut, TNT_TK_I32(v)); - break; - /* k = string */ - case TNT_TK_STRING: - tnt_update_assign(u, TNT_TK_I32(k), (char*)TNT_TK_S(v)->data, - TNT_TK_S(v)->size); - break; - /* k = num32 */ - case TNT_TK_NUM32: - tnt_update_assign(u, TNT_TK_I32(k), (char*)&TNT_TK_I32(v), 4); - break; - /* k = num64 */ - case TNT_TK_NUM64: - tnt_update_assign(u, TNT_TK_I64(k), (char*)&TNT_TK_I64(v), 8); - break; - /* k = splice(k, a, b) */ - case TNT_TK_SPLICE: { - struct tnt_tk *field = NULL, *off = NULL, - *len = NULL, *list = NULL; - tnt_expect(tnt_sqltk(sql, '(')); - tnt_expect(tnt_sqltkv(sql, TNT_TK_KEY, &field)); - if (TNT_TK_I32(k) != TNT_TK_I32(field)) { - tnt_sql_error(sql, k, "can't update on different keys"); - goto error; - } - tnt_expect(tnt_sqltk(sql, ',')); - tnt_expect(tnt_sqltkv(sql, TNT_TK_NUM32, &off)); - tnt_expect(tnt_sqltk(sql, ',')); - tnt_expect(tnt_sqltkv(sql, TNT_TK_NUM32, &len)); - tnt_expect(tnt_sqltk(sql, ',')); - tnt_expect(tnt_sqltkv(sql, TNT_TK_STRING, &list)); - tnt_expect(tnt_sqltk(sql, ')')); - tnt_update_splice(u, TNT_TK_I32(k), TNT_TK_I32(off), TNT_TK_I32(len), - (char*)TNT_TK_S(list)->data, - TNT_TK_S(list)->size); - break; - } - case TNT_TK_ERROR: - tnt_sql_error(sql, k, "%s", sql->l->error); - goto error; - } - if (tnt_sqltry(sql, ',')) - continue; - if (sql->error) - goto error; - break; - } - tnt_expect(tnt_sqltk(sql, TNT_TK_WHERE)); - /* predicate */ - tnt_expect(tnt_sql_kv(sql, tu, true)); - tnt_expect(tnt_sqltk(sql, TNT_TK_EOF)); - if (tnt_update(sql->s, TNT_TK_I32(tn), 0, tu, u) == -1) { - tnt_sql_error(sql, tn, "update failed"); - goto error; - } - rc = true; -error: - return rc; -} - -/* parsing single sql statement. */ - -static bool -tnt_sql_stmt(struct tnt_sql *sql) -{ - struct tnt_tuple tu; - struct tnt_list tuples; - struct tnt_stream update; - tnt_tuple_init(&tu); - tnt_list_init(&tuples); - tnt_buf(&update); - - int flags = 0; - struct tnt_tk *tk = NULL, *tn = NULL; - bool rc = false; - switch (tnt_lex(sql->l, &tk)) { - /* <INSERT|REPLACE> [INTO] TABLE VALUES ( list ) */ - case TNT_TK_INSERT: - case TNT_TK_REPLACE: - tnt_sqltry(sql, TNT_TK_INTO); - if (sql->error) - goto error; - tnt_expect(tnt_sqltkv(sql, TNT_TK_TABLE, &tn)); - tnt_expect(tnt_sqltk(sql, TNT_TK_VALUES)); - tnt_expect(tnt_sqltk(sql, '(')); - while (1) { - tnt_expect(tnt_sql_kv(sql, &tu, false)); - if (tnt_sqltry(sql, ',')) - continue; - if (sql->error) - goto error; - break; - } - flags = TNT_FLAG_ADD; - if (tk->tk == TNT_TK_REPLACE) - flags = TNT_FLAG_REPLACE; - tnt_expect(tnt_sqltk(sql, ')')); - tnt_expect(tnt_sqltk(sql, TNT_TK_EOF)); - if (tnt_insert(sql->s, TNT_TK_I32(tn), flags, &tu) == -1) { - tnt_sql_error(sql, tk, "insert failed"); - goto error; - } - break; - /* UPDATE TABLE SET operations WHERE predicate */ - case TNT_TK_UPDATE: - if (!tnt_sql_stmt_update(sql, &tu, &update)) - goto error; - break; - /* DELETE FROM TABLE WHERE predicate */ - case TNT_TK_DELETE: - tnt_expect(tnt_sqltk(sql, TNT_TK_FROM)); - tnt_expect(tnt_sqltkv(sql, TNT_TK_TABLE, &tn)); - tnt_expect(tnt_sqltk(sql, TNT_TK_WHERE)); - /* predicate */ - tnt_expect(tnt_sql_kv(sql, &tu, true)); - tnt_expect(tnt_sqltk(sql, TNT_TK_EOF)); - if (tnt_delete(sql->s, TNT_TK_I32(tn), 0, &tu) == -1) { - tnt_sql_error(sql, tk, "delete failed"); - goto error; - } - break; - /* SELECT * FROM TABLE WHERE predicate OR predicate... LIMIT NUM */ - case TNT_TK_SELECT: { - tnt_expect(tnt_sqltk(sql, '*')); - tnt_expect(tnt_sqltk(sql, TNT_TK_FROM)); - tnt_expect(tnt_sqltkv(sql, TNT_TK_TABLE, &tn)); - tnt_expect(tnt_sqltk(sql, TNT_TK_WHERE)); - int32_t index = -1; - while (1) { - struct tnt_tuple *tup = tnt_list_at(&tuples, NULL); - while (1) { - tnt_expect(tnt_sql_kv_select(sql, tup, &index)); - if (tnt_sqltry(sql, TNT_TK_AND)) - continue; - if (sql->error) - goto error; - break; - } - if (tnt_sqltry(sql, TNT_TK_OR)) - continue; - if (sql->error) - goto error; - break; - } - uint32_t limit = UINT32_MAX; - if (tnt_sqltry(sql, TNT_TK_LIMIT)) { - struct tnt_tk *ltk; - tnt_expect(tnt_sqltkv(sql, TNT_TK_NUM32, <k)); - limit = TNT_TK_I32(ltk); - } else - if (sql->error) - goto error; - tnt_expect(tnt_sqltk(sql, TNT_TK_EOF)); - if (tnt_select(sql->s, TNT_TK_I32(tn), index, 0, limit, &tuples) == -1) { - tnt_sql_error(sql, tk, "select failed"); - goto error; - } - break; - } - /* CALL NAME[{.NAME}+](STRING [{,STRING}+]) */ - case TNT_TK_CALL: { - char proc[512]; - int len = 0; - while (1) { - struct tnt_tk *name = NULL; - tnt_lex_idonly(sql->l, true); - tnt_expect(tnt_sqltkv(sql, TNT_TK_ID, &name)); - tnt_lex_idonly(sql->l, false); - len += snprintf(proc + len, sizeof(proc) - len, "%.*s", - (int)TNT_TK_S(name)->size, TNT_TK_S(name)->data); - if (!tnt_sqltry(sql, '.')) - break; - if (sql->error) - goto error; - len += snprintf(proc + len, sizeof(proc) - len, "%s", "."); - } - tnt_expect(tnt_sqltk(sql, '(')); - if (tnt_sqltry(sql, ')')) - goto noargs; - if (sql->error) - goto error; - while (1) { - tnt_expect(tnt_sql_kv(sql, &tu, false)); - if (tnt_sqltry(sql, ',')) - continue; - if (sql->error) - goto error; - break; - } - tnt_expect(tnt_sqltk(sql, ')')); -noargs: - tnt_expect(tnt_sqltk(sql, TNT_TK_EOF)); - if (tnt_call(sql->s, 0, proc, &tu) == -1) { - tnt_sql_error(sql, tk, "call failed"); - goto error; - } - break; - } - /* PING */ - case TNT_TK_PING: - tnt_expect(tnt_sqltk(sql, TNT_TK_EOF)); - if (tnt_ping(sql->s) == -1) { - tnt_sql_error(sql, tk, "ping failed"); - goto error; - } - break; - case TNT_TK_EOF: - break; - case TNT_TK_ERROR: - return tnt_sql_error(sql, tk, "%s", sql->l->error); - default: - return tnt_sql_error(sql, tk, - "insert, replace, update, delete, select, call, ping are expected"); - } - rc = true; -error: - tnt_tuple_free(&tu); - tnt_list_free(&tuples); - tnt_stream_free(&update); - return rc; -} - -#undef tnt_expect - -/* primary sql grammar parsing function. */ - -static bool tnt_sql(struct tnt_sql *sql) { - return tnt_sql_stmt(sql); -} - -struct tnt_lex_keyword tnt_sql_keywords[] = -{ - { "PING", 4, TNT_TK_PING }, - { "UPDATE", 6, TNT_TK_UPDATE }, - { "SET", 3, TNT_TK_SET }, - { "WHERE", 5, TNT_TK_WHERE }, - { "SPLICE", 6, TNT_TK_SPLICE }, - { "DELETE", 6, TNT_TK_DELETE }, - { "FROM", 4, TNT_TK_FROM }, - { "INSERT", 6, TNT_TK_INSERT }, - { "REPLACE", 7, TNT_TK_REPLACE }, - { "INTO", 4, TNT_TK_INTO }, - { "VALUES", 6, TNT_TK_VALUES }, - { "SELECT", 6, TNT_TK_SELECT }, - { "OR", 2, TNT_TK_OR }, - { "AND", 3, TNT_TK_AND }, - { "LIMIT", 5, TNT_TK_LIMIT }, - { "CALL", 4, TNT_TK_CALL }, - { NULL, 0, TNT_TK_NONE } -}; - -/* - * tnt_query() - * - * Parses and processes supplied SQL query; - * - * s - stream pointer - * q - sql query string - * qsize - query size - * e - error description string - * - * returns 0 on success, or -1 on error - * and string description returned (must be freed after use). -*/ -int -tnt_query(struct tnt_stream *s, const char *q, size_t qsize, char **e) -{ - struct tnt_lex l; - if (!tnt_lex_init(&l, tnt_sql_keywords, (unsigned char*)q, qsize)) - return -1; - struct tnt_sql sql = { s, &l, NULL }; - bool ret = tnt_sql(&sql); - if (e) { - *e = sql.error; - } else { - if (sql.error) - tnt_mem_free(sql.error); - } - tnt_lex_free(&l); - return (ret) ? 0 : -1; -} - -/* - * tnt_query_is() - * - * Tells if the supplied query should be processed as SQL. - * - * q - sql query string - * qsize - query size - * - * returns 1 if yes, 0 otherwise. -*/ -int -tnt_query_is(char *q, size_t qsize) -{ - struct tnt_lex l; - if (!tnt_lex_init(&l, tnt_sql_keywords, (unsigned char*)q, qsize)) - return 0; - int rc = 0; - struct tnt_tk *tk; - switch (tnt_lex(&l, &tk)) { - case TNT_TK_ERROR: - case TNT_TK_EOF: - break; - default: - if (tk->tk == TNT_TK_PING || - tk->tk == TNT_TK_INSERT || - tk->tk == TNT_TK_REPLACE || - tk->tk == TNT_TK_UPDATE || - tk->tk == TNT_TK_SELECT || - tk->tk == TNT_TK_DELETE || - tk->tk == TNT_TK_CALL) - rc = 1; - break; - } - tnt_lex_free(&l); - return rc; -} diff --git a/connector/c/tntsql/tnt_utf8.c b/connector/c/tntsql/tnt_utf8.c deleted file mode 100644 index 8e08deb610..0000000000 --- a/connector/c/tntsql/tnt_utf8.c +++ /dev/null @@ -1,159 +0,0 @@ - -/* - * 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 <stdint.h> -#include <stdbool.h> -#include <stdlib.h> -#include <stdio.h> -#include <string.h> - -#include <connector/c/include/tarantool/tnt.h> -#include <connector/c/include/tarantool/tnt_utf8.h> - -bool -tnt_utf8_init(struct tnt_utf8 *u, const unsigned char *data, size_t size) -{ - u->size = size; - u->data = (unsigned char*)tnt_mem_alloc(u->size + 1); - u->data[u->size] = 0; - memcpy(u->data, data, u->size); - ssize_t len = tnt_utf8_strlen(u->data, u->size); - if (len == -1) { - tnt_mem_free(u->data); - return false; - } - u->len = len; - return true; -} - -void -tnt_utf8_free(struct tnt_utf8 *u) -{ - if (u->data) - tnt_mem_free(u->data); - u->data = NULL; - u->size = 0; - u->len = 0; -} - -ssize_t -tnt_utf8_chrlen(const unsigned char *data, size_t size) -{ -#define tnt_bit(I) (1 << (I)) -#define tnt_bit_is(B, I) ((B) & tnt_bit(I)) - /* U-00000000 – U-0000007F: ASCII representation */ - if (data[0] < 0x7F) - return 1; - /* The first byte of a multibyte sequence that represents a non-ASCII - * character is always in the range 0xC0 to 0xFD and it indicates - * how many bytes follow for this character */ - if (data[0] < 0xC0 || data[0] > 0xFD ) - return -1; - unsigned int i, count = 0; - /* U-00000080 – U-000007FF */ - if (tnt_bit_is(data[0], 7) && tnt_bit_is(data[0], 6)) { - count = 2; - /* U-00000800 – U-0000FFFF */ - if (tnt_bit_is(data[0], 5)) { - count = 3; - /* U-00010000 – U-001FFFFF */ - if (tnt_bit_is(data[0], 4)) { - count = 4; - /* it is possible to declare more than 4 bytes, - * but practically unused */ - } - } - } - if (count == 0) - return -1; - if (size < count) - return -1; - /* no ASCII byte (0x00-0x7F) can appear as part of - * any other character */ - for (i = 1 ; i < count ; i++) - if (data[i] < 0x7F) - return -1; - return count; -#undef tnt_bit -#undef tnt_bit_is -} - -ssize_t -tnt_utf8_strlen(const unsigned char *data, size_t size) -{ - register size_t i = 0; - register ssize_t c = 0, r = 0; - while (i < size) { - r =tnt_utf8_chrlen(data + i, size - i); - if (r == -1) - return -1; - c++; - i += r; - } - return c; -} - -ssize_t -tnt_utf8_sizeof(const unsigned char *data, size_t size, size_t n) -{ - register size_t i = 0, c = 0; - register ssize_t r = 0; - while ((i < size) && (c < n)) { - r = tnt_utf8_chrlen(data + i, size - i); - if (r == -1) - return -1; - c++; - i += r; - } - if (c != n) - return -1; - return i; -} - -bool -tnt_utf8_cmp(struct tnt_utf8 *u, struct tnt_utf8 *us) -{ - if (u->size != us->size) - return false; - if (u->len != us->len) - return false; - return !memcmp(u->data, us->data, u->size); -} - -ssize_t -tnt_utf8_next(struct tnt_utf8 *u, size_t off) -{ - if (off == u->size) - return 0; - ssize_t r = tnt_utf8_chrlen(u->data + off, u->size - off); - if (r == -1) - return -1; - return off + r; -} diff --git a/connector/java/pom.xml b/connector/java/pom.xml deleted file mode 100644 index 4b22daf3df..0000000000 --- a/connector/java/pom.xml +++ /dev/null @@ -1,25 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - - <groupId>ru.mail</groupId> - <artifactId>tarantool-connector</artifactId> - <version>1.0.0</version> - - <dependencies> - <dependency> - <groupId>log4j</groupId> - <artifactId>log4j</artifactId> - <version>1.2.16</version> - <scope>compile</scope> - </dependency> - <dependency> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - <version>1.1.1</version> - <scope>compile</scope> - </dependency> - </dependencies> -</project> \ No newline at end of file diff --git a/connector/java/src/main/java/tarantool/common/ByteUtil.java b/connector/java/src/main/java/tarantool/common/ByteUtil.java deleted file mode 100644 index 33e6df4c6f..0000000000 --- a/connector/java/src/main/java/tarantool/common/ByteUtil.java +++ /dev/null @@ -1,179 +0,0 @@ -package tarantool.common; - - -public class ByteUtil { - - public static final int LENGTH_SHORT = 2; - public static final int LENGTH_INTEGER = 4; - public static final int LENGTH_LONG = 8; - - public static int writeInteger(byte[] bytes, int position, int value) { - bytes[position + 3] = (byte) ((value >>> 24) & 0xFF); - bytes[position + 2] = (byte) ((value >>> 16) & 0xFF); - bytes[position + 1] = (byte) ((value >>> 8) & 0xFF); - bytes[position ] = (byte) ((value) & 0xFF); - return LENGTH_INTEGER; - } - - public static int readInteger(byte[] bytes, int position) { - return ((bytes[position + 3] & 0xFF) << 24) | - ((bytes[position + 2] & 0xFF) << 16) | - ((bytes[position + 1] & 0xFF) << 8) | - ((bytes[position] & 0xFF)); - } - - public static int writeUnsignedInteger(byte[] bytes, int position, long value) { - bytes[position + 3] = (byte) ((value >>> 24) & 0xFF); - bytes[position + 2] = (byte) ((value >>> 16) & 0xFF); - bytes[position + 1] = (byte) ((value >>> 8) & 0xFF); - bytes[position ] = (byte) ((value) & 0xFF); - return LENGTH_INTEGER; - } - - public static long readUnsignedInteger(byte[] bytes, int position) { - return ((long)(bytes[position + 3] & 0xFF) << 24) | - ((long)(bytes[position + 2] & 0xFF) << 16) | - ((long)(bytes[position + 1] & 0xFF) << 8) | - ((long)(bytes[position] & 0xFF)); - } - - public static int writeLong(byte[] bytes, int position, long value) { - bytes[position + 7] = (byte) ((value >>> 56) & 0xFF); - bytes[position + 6] = (byte) ((value >>> 48) & 0xFF); - bytes[position + 5] = (byte) ((value >>> 40) & 0xFF); - bytes[position + 4] = (byte) ((value >>> 32) & 0xFF); - bytes[position + 3] = (byte) ((value >>> 24) & 0xFF); - bytes[position + 2] = (byte) ((value >>> 16) & 0xFF); - bytes[position + 1] = (byte) ((value >>> 8) & 0xFF); - bytes[position ] = (byte) ((value) & 0xFF); - return LENGTH_LONG; - } - - public static long readLong(byte[] bytes, int position) { - return ((long)(bytes[position + 7] & 0xFF) << 56) | - ((long)(bytes[position + 6] & 0xFF) << 48) | - ((long)(bytes[position + 5] & 0xFF) << 40) | - ((long)(bytes[position + 4] & 0xFF) << 32) | - ((long)(bytes[position + 3] & 0xFF) << 24) | - ((long)(bytes[position + 2] & 0xFF) << 16) | - ((long)(bytes[position + 1] & 0xFF) << 8) | - ((long)(bytes[position] & 0xFF)); - } - - public static byte[] toBytes(long value) { - byte[] bytes = new byte[LENGTH_LONG]; - bytes[7] = (byte) ((value >>> 56) & 0xFF); - bytes[6] = (byte) ((value >>> 48) & 0xFF); - bytes[5] = (byte) ((value >>> 40) & 0xFF); - bytes[4] = (byte) ((value >>> 32) & 0xFF); - bytes[3] = (byte) ((value >>> 24) & 0xFF); - bytes[2] = (byte) ((value >>> 16) & 0xFF); - bytes[1] = (byte) ((value >>> 8) & 0xFF); - bytes[0] = (byte) ((value) & 0xFF); - return bytes; - } - - public static long toLong(byte[] bytes) { - return ((long)(bytes[7] & 0xFF) << 56) | - ((long)(bytes[6] & 0xFF) << 48) | - ((long)(bytes[5] & 0xFF) << 40) | - ((long)(bytes[4] & 0xFF) << 32) | - ((long)(bytes[3] & 0xFF) << 24) | - ((long)(bytes[2] & 0xFF) << 16) | - ((long)(bytes[1] & 0xFF) << 8) | - ((long)(bytes[0] & 0xFF)); - } - - public static int writeBytes(byte[] bytes, int position, byte[] value, int start, int length) { - System.arraycopy(value, start, bytes, position, length); - return length; - } - - public static int readBytes(byte[] src, int position, byte[] dest, int destPosition, int length) { - System.arraycopy(src, position, dest, destPosition, length); - return length; - } - - public static byte[] convertLongIdToByteArray(long id) { - byte[] byteId = new byte[LENGTH_LONG]; - ByteUtil.writeLong(byteId, 0, id); - return byteId; - } - - /** - * Compute the space needed to encode the length in BER code. - * - * @param length Length to encode - * @return the count of bytes needed to encode the value <code>length</code> - */ - public static int sizeOfInVarInt32(int length) { - if (length < (1 << 7)) { - return 1; - } - if (length < (1 << 14)) { - return 2; - } - if (length < (1 << 21)) { - return 3; - } - if (length < (1 << 28)) { - return 4; - } - return 5; - } - - public static int decodeLengthInVar32Int(byte[] in, int offset) { - if ((in[offset] & 0x80) == 0) { - return (in[offset] & 0x7F); - } - if ((in[offset + 1] & 0x80) == 0) { - return (in[offset] & 0x7F) << 7 - | (in[offset + 1] & 0x7F); - } - if ((in[offset + 2] & 0x80) == 0) { - return (in[offset] & 0x7F) << 14 - | (in[offset + 1] & 0x7F) << 7 - | (in[offset + 2] & 0x7F); - } - if ((in[offset + 3] & 0x80) == 0) { - return (in[offset] & 0x7F) << 21 - | (in[offset + 1] & 0x7F) << 14 - | (in[offset + 2] & 0x7F) << 7 - | (in[offset + 3] & 0x7F); - } - if ((in[offset + 4] & 0x80) == 0) { - return (in[offset] & 0x7F) << 28 - | (in[offset + 1] & 0x7F) << 21 - | (in[offset + 2] & 0x7F) << 14 - | (in[offset + 3] & 0x7F) << 7 - | (in[offset + 4] & 0x7F); - } - return 0; - } - - - /** - * Encodes the length. - * - * @param out an <code>byte[]</code> to which the length is encoded. - * @param offset positoin in out where start to write length - * @param length the length of the object - */ - public static int encodeLengthInVar32Int(byte[] out, int offset, int length) { - int currentOffset = offset; - if (length >= (1 << 7)) { - if (length >= (1 << 14)) { - if (length >= (1 << 21)) { - if (length >= (1 << 28)) { - out[currentOffset++] = (byte) ((length >> 28) | 0x80); - } - out[currentOffset++] = (byte) ((length >> 21) | 0x80); - } - out[currentOffset++] = (byte) ((length >> 14) | 0x80); - } - out[currentOffset++] = (byte) ((length >> 7) | 0x80); - } - out[currentOffset] = (byte) ((length) & 0x7F); - return currentOffset - offset + 1; - } -} diff --git a/connector/java/src/main/java/tarantool/connector/RequestResponseFormatter.java b/connector/java/src/main/java/tarantool/connector/RequestResponseFormatter.java deleted file mode 100644 index d5c2acc23e..0000000000 --- a/connector/java/src/main/java/tarantool/connector/RequestResponseFormatter.java +++ /dev/null @@ -1,210 +0,0 @@ -package tarantool.connector; - - -import java.io.IOException; - -import tarantool.connector.exception.TarantoolConnectorException; -import tarantool.connector.socketpool.worker.SocketWorker; -import tarantool.common.ByteUtil; - - -public class RequestResponseFormatter { - - public static final int HEADER_LENGTH = 12; - - private static final int INSERT_PACKET_SIZE = RequestResponseFormatter.HEADER_LENGTH + 20 + ByteUtil.sizeOfInVarInt32(4); - private static final int GET_PACKET_SIZE = RequestResponseFormatter.HEADER_LENGTH + 32 + ByteUtil.sizeOfInVarInt32(4); - private static final int DELETE_PACKET_SIZE = RequestResponseFormatter.HEADER_LENGTH + 16 + ByteUtil.sizeOfInVarInt32(4); - private static final int KEY_SET_PACKET_SIZE = RequestResponseFormatter.HEADER_LENGTH + 4; - private static final int LUA_SCRIPT_PACKET_SIZE = RequestResponseFormatter.HEADER_LENGTH + 8; - - // ascii string "get_all_pkeys" - private static final byte[] GET_ALL_KEYS_LUA_SCRIPT = {103, 101, 116, 95, 97, 108, 108, 95, 112, 107, 101, 121, 115}; - - public static byte[] createInsertCommand(byte[] uid, int requestId, int nameSpaceId, byte[] data) { - final byte[] packet = new byte[INSERT_PACKET_SIZE + ByteUtil.sizeOfInVarInt32(data.length) + data.length]; - - int offset = createHeader(packet, TarantoolCommand.INSERT.getId(), requestId); - - // 4 bytes - Namespace number - offset += ByteUtil.writeInteger(packet, offset, nameSpaceId); - // 4 bytes - <flags, uint32_t> - offset += ByteUtil.writeInteger(packet, offset, 0); - // 4 bytes - <cardinality, uint32_t>: Number of fields in the tuple - offset += ByteUtil.writeInteger(packet, offset, 2); - - /** - * <field[0], field_t> - * field_t: <size, varint32><data, uint8_t[]>, The field with the user data of indicated length - * ... - * <field[cardinality-1], field_t> - */ - // N bytes - field_t: <size, varint32> - offset += ByteUtil.encodeLengthInVar32Int(packet, offset, 8); - // 4 bytes - <data, uint8_t[]> - offset += ByteUtil.writeBytes(packet, offset, uid, 0, uid.length); - // N bytes - field_t: <size, varint32> - offset += ByteUtil.encodeLengthInVar32Int(packet, offset, data.length); - // N bytes - <data, uint8_t[]> - ByteUtil.writeBytes(packet, offset, data, 0, data.length); - - return packet; - } - - public static byte[] createGetDataCommand(byte[] uid, int requestId, int nameSpaceId) { - final byte[] packet = new byte[GET_PACKET_SIZE]; - - int offset = createHeader(packet, TarantoolCommand.SELECT.getId(), requestId); - - // 4 bytes - Namespace number - offset += ByteUtil.writeInteger(packet, offset, nameSpaceId); - // 4 bytes - Index number - offset += ByteUtil.writeInteger(packet, offset, 0); - // 4 bytes - Offset of the return data - offset += ByteUtil.writeInteger(packet, offset, 0); - /** - * 4 bytes - Maximal number of results in the answer - * -1 UINT32_MAX actually - */ - offset += ByteUtil.writeInteger(packet, offset, -1); - // 4 bytes - Number of keys for the current query - offset += ByteUtil.writeInteger(packet, offset, 1); - /** - * <key_cardinality, int32_t><key_fields, tuple_t> - */ - offset += ByteUtil.writeInteger(packet, offset, 1); - offset += ByteUtil.encodeLengthInVar32Int(packet, offset, 8); - ByteUtil.writeBytes(packet, offset, uid, 0, uid.length); - - return packet; - } - - public static byte[] createDeleteCommand(byte[] uid, int requestId, int nameSpaceId) { - final byte[] packet = new byte[DELETE_PACKET_SIZE]; - - int offset = createHeader(packet, TarantoolCommand.DELETE.getId(), requestId); - - // 4 bytes - Namespace number - offset += ByteUtil.writeInteger(packet, offset, nameSpaceId); - - /** - * <key_cardinality, int32_t><key_fields, tuple_t> - * 8 bytes + VAR32 - */ - offset += ByteUtil.writeInteger(packet, offset, 1); - offset += ByteUtil.encodeLengthInVar32Int(packet, offset, 8); - ByteUtil.writeBytes(packet, offset, uid, 0, uid.length); - - return packet; - } - - public static byte[] createDeliverKeySetCommand(int requestId, int nameSpaceId) { - byte[] packet = new byte[KEY_SET_PACKET_SIZE]; - int offset = createHeader(packet, TarantoolCommand.LUA_CALL.getId(), requestId); - ByteUtil.writeInteger(packet, offset, nameSpaceId); - return packet; - } - - public static byte[] createScriptDeliverKeySetCommand(int requestId, int nameSpaceId, int batchSize) { - byte[] batchSizeStr = convertIntToANSI(batchSize); - - int size = GET_ALL_KEYS_LUA_SCRIPT.length + ByteUtil.sizeOfInVarInt32(GET_ALL_KEYS_LUA_SCRIPT.length) - + batchSizeStr.length + ByteUtil.sizeOfInVarInt32(batchSizeStr.length); - - byte[] packet = new byte[LUA_SCRIPT_PACKET_SIZE + size]; - int offset = createHeader(packet, TarantoolCommand.LUA_CALL.getId(), requestId); - // 4 bytes - Namespace number - offset += ByteUtil.writeInteger(packet, offset, nameSpaceId); - - // N bytes - field_t: <size, varint32> - offset += ByteUtil.encodeLengthInVar32Int(packet, offset, GET_ALL_KEYS_LUA_SCRIPT.length); - // 4 bytes - <data, uint8_t[]> - offset += ByteUtil.writeBytes(packet, offset, GET_ALL_KEYS_LUA_SCRIPT, 0, GET_ALL_KEYS_LUA_SCRIPT.length); - // 4 bytes - arguments count - offset += ByteUtil.writeInteger(packet, offset, 1); - /** - * <key_fields, tuple_t> - */ - offset += ByteUtil.encodeLengthInVar32Int(packet, offset, batchSizeStr.length); - ByteUtil.writeBytes(packet, offset, batchSizeStr, 0, batchSizeStr.length); - - return packet; - } - - public static byte[] createPingCommand(int requestId) { - byte[] packet = new byte[RequestResponseFormatter.HEADER_LENGTH]; - createHeader(packet, TarantoolCommand.PING.getId(), requestId); - return packet; - } - - public static TarantoolResponse responseParser(byte[] header) { - int dataLength = ByteUtil.readInteger(header, 4); - int requestId = ByteUtil.readInteger(header, 8); - return new TarantoolResponse(dataLength, requestId); - } - - public static int createHeader(byte[] buffer, int command, int requestId) { - int offset = 0; - // 4 bytes - The code of the operation which the server must execute - offset += ByteUtil.writeInteger(buffer, offset, command); - // 4 bytes - The length of the data packet which does not count the header size - offset += ByteUtil.writeInteger(buffer, offset, buffer.length - RequestResponseFormatter.HEADER_LENGTH); - // 4 bytes - A random number which identifies the query - offset += ByteUtil.writeInteger(buffer, offset, requestId); - - return offset; - } - - public static byte[] readResponseData(int requestId, SocketWorker worker) throws IOException, TarantoolConnectorException { - byte[] header = new byte[RequestResponseFormatter.HEADER_LENGTH]; - int readData = worker.readData(header, RequestResponseFormatter.HEADER_LENGTH); - TarantoolResponse response = responseParser(header); - - if (readData != RequestResponseFormatter.HEADER_LENGTH) { - throw new TarantoolConnectorException("Incorrect size of response header"); - } - - if (requestId != response.getRequestId()) { - throw new TarantoolConnectorException("Incorrect request Id"); - } - - int dataLength = response.getDataLength(); - if (dataLength <= 0) { - throw new TarantoolConnectorException("Incorrect size of response result"); - } - - byte[] result = new byte[dataLength]; - readData = worker.readData(result, dataLength); - - if (readData != dataLength) { - throw new TarantoolConnectorException("Wrong size of data or length of data that was read"); - } - - return result; - } - - private static byte[] convertIntToANSI(int value) { - int count = 0; - int index = value < 0? 1: 0; - int abs = Math.abs(value); - long delimiter = 1; - for (;;) { - count++; - if (abs / (delimiter * 10) == 0) { - break; - } - delimiter *= 10; - } - byte[] result = new byte[count + index]; - if (index > 0) { - result[index - 1] = 45; - } - for (; count--> 0; delimiter /= 10) { - long d = abs / delimiter; - result[index++] = (byte)(d + 48); - abs -= d * delimiter; - } - - return result; - } -} diff --git a/connector/java/src/main/java/tarantool/connector/TarantoolCommand.java b/connector/java/src/main/java/tarantool/connector/TarantoolCommand.java deleted file mode 100644 index 504e8eecdd..0000000000 --- a/connector/java/src/main/java/tarantool/connector/TarantoolCommand.java +++ /dev/null @@ -1,89 +0,0 @@ -package tarantool.connector; - -import java.util.HashMap; -import java.util.Map; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -public class TarantoolCommand { - private static final Log LOG = LogFactory.getLog(TarantoolCommand.class); - - private final static Map<Integer, TarantoolCommand> COMMANDS_MAPS; - - public final static TarantoolCommand PING; - public final static TarantoolCommand INSERT; - public final static TarantoolCommand SELECT; - public final static TarantoolCommand UPDATE; - public final static TarantoolCommand DELETE; - public final static TarantoolCommand LUA_CALL; // valid as keyset operation in tarantool 1.3.2 - - static { - COMMANDS_MAPS = new HashMap<Integer, TarantoolCommand>(6); - PING = new TarantoolCommand(0xFF00, "ping"); - INSERT = new TarantoolCommand(0x0D, "insert"); - SELECT = new TarantoolCommand(0x11, "select"); - UPDATE = new TarantoolCommand(0x13, "update"); - DELETE = new TarantoolCommand(0x14, "delete"); - LUA_CALL = new TarantoolCommand(0x15, "luacall"); - } - - private int id; - private String name; - - public static TarantoolCommand getCommandBy(int id) { - final TarantoolCommand tarantoolCommand = COMMANDS_MAPS.get(id); - if (tarantoolCommand == null) { - LOG.warn("Not supported code received from server with id: " + id); - return null; - } - return tarantoolCommand; - } - - TarantoolCommand(int id, String name) { - this.id = id; - this.name = name; - TarantoolCommand tarantoolCommand = COMMANDS_MAPS.put(id, this); - if (tarantoolCommand == null) { - return; - } - throw new IllegalStateException("Duplicate name with id: " + id + " and name: " + name + ", " + tarantoolCommand.getName()); - } - - public int getId() { - return id; - } - - public String getName() { - return name; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - - TarantoolCommand that = (TarantoolCommand) o; - - return id == that.id; - } - - @Override - public int hashCode() { - int result = id; - result = 31 * result + (name != null ? name.hashCode() : 0); - return result; - } - - @Override - public String toString() { - return "TarantoolCommand{" + - "id=" + id + - ", name='" + name + '\'' + - '}'; - } -} diff --git a/connector/java/src/main/java/tarantool/connector/TarantoolConnector.java b/connector/java/src/main/java/tarantool/connector/TarantoolConnector.java deleted file mode 100644 index ce4086a0a7..0000000000 --- a/connector/java/src/main/java/tarantool/connector/TarantoolConnector.java +++ /dev/null @@ -1,58 +0,0 @@ -package tarantool.connector; - -import tarantool.connector.exception.TarantoolConnectorException; - - -public interface TarantoolConnector { - void insertData(long id, byte[] data) throws InterruptedException, TarantoolConnectorException; - - void insertData(byte[] id, byte[] data) throws InterruptedException, TarantoolConnectorException; - - byte[] getData(long id) throws InterruptedException, TarantoolConnectorException; - - byte[] getData(byte[] id) throws InterruptedException, TarantoolConnectorException; - - boolean deleteById(long id) throws InterruptedException, TarantoolConnectorException; - - boolean deleteById(byte[] id) throws InterruptedException, TarantoolConnectorException; - - /** - * Attention! This method can use only with tarantool from trunk feature-get-all-keys. - * This method locks all activity in tarantool. - * @return array of byte array with keys - * @throws TarantoolConnectorException - * @throws InterruptedException - */ - @Deprecated - byte[][] getKeySetAsByteArray() throws TarantoolConnectorException, InterruptedException; - - /** - * Attention! This method can use only with tarantool from trunk feature-get-all-keys. - * This method locks all activity in tarantool. - * @return long array with keys - * @throws TarantoolConnectorException - * @throws InterruptedException - */ - @Deprecated - long[] getKeySetAsLongArray() throws TarantoolConnectorException, InterruptedException; - - /** - * Don't lock activity but need LUA script support and server side command - * @return - * @throws TarantoolConnectorException - * @throws InterruptedException - */ - long[] getScriptKeySetAsLongArray(int batchSize) throws TarantoolConnectorException, InterruptedException; - - /** - * Don't lock activity but need LUA script support and server side command - * @return - * @throws TarantoolConnectorException - * @throws InterruptedException - */ - byte[][] getScriptKeySetAsByteArray(int batchSize) throws TarantoolConnectorException, InterruptedException; - - void truncate() throws InterruptedException, TarantoolConnectorException; - - void close(); -} diff --git a/connector/java/src/main/java/tarantool/connector/TarantoolConnectorConfig.java b/connector/java/src/main/java/tarantool/connector/TarantoolConnectorConfig.java deleted file mode 100644 index 0ac6587d78..0000000000 --- a/connector/java/src/main/java/tarantool/connector/TarantoolConnectorConfig.java +++ /dev/null @@ -1,36 +0,0 @@ -package tarantool.connector; - -import tarantool.connector.socketpool.SocketPoolConfig; -import tarantool.connector.socketpool.SocketPoolType; -import tarantool.connector.socketpool.worker.FactoryType; - - -public class TarantoolConnectorConfig { - - private final SocketPoolConfig socketPoolConfig; - private final int nameSpace; - - public TarantoolConnectorConfig(String host, int port, int socketReadTimeout, int minPoolSize, int maxPoolSize, long waitingTimeout, - long reconnectTimeout, long initializeTimeout, int disconnectBound, FactoryType type, SocketPoolType socketPoolType, - long latencyPeriod, int nameSpace) { - this.socketPoolConfig = new SocketPoolConfig(host, port, socketReadTimeout, minPoolSize, maxPoolSize, waitingTimeout, reconnectTimeout, - initializeTimeout, disconnectBound, type, socketPoolType, latencyPeriod); - this.nameSpace = nameSpace; - } - - public int getNameSpace() { - return nameSpace; - } - - public SocketPoolConfig getSocketPoolConfig() { - return socketPoolConfig; - } - - @Override - public String toString() { - return "TarantoolConnectorConfig{" + - "socketPoolConfig=" + socketPoolConfig + - ", nameSpace=" + nameSpace + - '}'; - } -} diff --git a/connector/java/src/main/java/tarantool/connector/TarantoolConnectorImpl.java b/connector/java/src/main/java/tarantool/connector/TarantoolConnectorImpl.java deleted file mode 100644 index 1d15c61f3d..0000000000 --- a/connector/java/src/main/java/tarantool/connector/TarantoolConnectorImpl.java +++ /dev/null @@ -1,344 +0,0 @@ -package tarantool.connector; - -import java.io.IOException; -import java.net.UnknownHostException; -import java.util.concurrent.atomic.AtomicInteger; - -import tarantool.connector.exception.TarantoolConnectorException; -import tarantool.connector.exception.TarantoolUnavailableException; -import tarantool.connector.socketpool.SocketPool; -import tarantool.connector.socketpool.SocketPoolFactory; -import tarantool.connector.socketpool.exception.SocketPoolException; -import tarantool.connector.socketpool.exception.SocketPoolTimeOutException; -import tarantool.connector.socketpool.worker.SocketWorker; -import tarantool.common.ByteUtil; - - -public class TarantoolConnectorImpl implements TarantoolConnector { - - private final int nameSpace; - private final AtomicInteger requestId = new AtomicInteger(1); - - private final SocketPool pool; - - private interface InternalParser<T> { - void allocateMemory(int size); - void parse(byte[] buffer, int offset, int index); - T getResult(); - T getEmptyResult(); - } - - private static class LongParser implements InternalParser<long[]> { - long[] keys; - - @Override - public void allocateMemory(int size) { - keys = new long[size]; - } - - @Override - public void parse(byte[] buffer, int offset, int index) { - keys[index] = ByteUtil.readLong(buffer, offset); - } - - @Override - public long[] getResult() { - return keys; - } - - @Override - public long[] getEmptyResult() { - return new long[0]; - } - } - - private static class ByteArrayParser implements InternalParser<byte[][]> { - private byte[][] keys; - - @Override - public void allocateMemory(int size) { - keys = new byte[size][ByteUtil.LENGTH_LONG]; - } - - @Override - public void parse(byte[] buffer, int offset, int index) { - ByteUtil.readBytes(buffer, offset, keys[index], 0, ByteUtil.LENGTH_LONG); - } - - @Override - public byte[][] getResult() { - return keys; - } - - @Override - public byte[][] getEmptyResult() { - return new byte[0][0]; - } - } - - public TarantoolConnectorImpl(TarantoolConnectorConfig tarantoolConfig) - throws UnknownHostException, SocketPoolTimeOutException { - - this.nameSpace = tarantoolConfig.getNameSpace(); - this.pool = SocketPoolFactory.createSocketPool(tarantoolConfig.getSocketPoolConfig()); - } - - private int getRequestId() { - if (requestId.get() == Integer.MAX_VALUE) { - requestId.compareAndSet(Integer.MAX_VALUE, 1); - } - return requestId.getAndIncrement(); - } - - @Override - public void insertData(long id, byte[] data) throws InterruptedException, TarantoolConnectorException { - SocketWorker worker = getSocketWorker(); - try { - insert(id, getRequestId(), data, worker); - } catch (IOException e) { - throw new TarantoolConnectorException("Can't correct make socket operation", e); - } finally { - worker.release(); - } - } - - @Override - public void insertData(byte[] id, byte[] data) throws InterruptedException, TarantoolConnectorException { - SocketWorker worker = getSocketWorker(); - try { - insert(id, getRequestId(), data, worker); - } catch (IOException e) { - throw new TarantoolConnectorException("Can't correct make socket operation", e); - } finally { - worker.release(); - } - } - - @Override - public byte[] getData(long id) throws InterruptedException, TarantoolConnectorException { - SocketWorker worker = getSocketWorker(); - try { - return get(id, getRequestId(), worker); - } catch (IOException e) { - throw new TarantoolConnectorException("Can't correct make socket operation", e); - } finally { - worker.release(); - } - } - - @Override - public byte[] getData(byte[] id) throws InterruptedException, TarantoolConnectorException { - SocketWorker worker = getSocketWorker(); - try { - return get(id, getRequestId(), worker); - } catch (IOException e) { - throw new TarantoolConnectorException("Can't correct make socket operation", e); - } finally { - worker.release(); - } - } - - @Override - public boolean deleteById(long id) throws InterruptedException, TarantoolConnectorException { - return deleteById(ByteUtil.convertLongIdToByteArray(id)); - } - - @Override - public boolean deleteById(byte[] id) throws InterruptedException, TarantoolConnectorException { - SocketWorker worker = getSocketWorker(); - try { - int requestId = getRequestId(); - byte[] packet = RequestResponseFormatter.createDeleteCommand(id, requestId, nameSpace); - - worker.writeData(packet); - - byte[] result = RequestResponseFormatter.readResponseData(requestId, worker); - - final TarantoolServerErrorCode errorCode = TarantoolServerErrorCode.getErrorBy(ByteUtil.readInteger(result, 0)); - if (errorCode == null) { - int deletedElements = ByteUtil.readInteger(result, 4); - return deletedElements > 0; - } else { - throw new TarantoolConnectorException("Can't delete data by id: " + errorCode); - } - } catch (IOException e) { - throw new TarantoolConnectorException("Can't correct make socket operation", e); - } finally { - worker.release(); - } - } - - @Override - public byte[][] getKeySetAsByteArray() throws TarantoolConnectorException, InterruptedException { - return getKeySet(new ByteArrayParser()); - } - - @Override - public long[] getKeySetAsLongArray() throws TarantoolConnectorException, InterruptedException { - return getKeySet(new LongParser()); - } - - @SuppressWarnings("unchecked") - private <T> T getKeySet(InternalParser parser) throws InterruptedException, TarantoolConnectorException { - SocketWorker worker = getSocketWorker(); - try { - int requestId = getRequestId(); - byte[] packet = RequestResponseFormatter.createDeliverKeySetCommand(requestId, nameSpace); - worker.writeData(packet); - - byte[] result = RequestResponseFormatter.readResponseData(requestId, worker); - final TarantoolServerErrorCode errorCode = TarantoolServerErrorCode.getErrorBy(ByteUtil.readInteger(result, 0)); - if (errorCode == null) { - int updatedElements = ByteUtil.readInteger(result, 4); - if (updatedElements > 0) { - int offset = 8; - parser.allocateMemory(updatedElements); - for (int i = 0; i < updatedElements; i++) { - offset += 8; - int valueLength = ByteUtil.decodeLengthInVar32Int(result, offset); - if (valueLength != 8) { - throw new TarantoolConnectorException("Get key set operation return incorrect id length: " + valueLength); - } - - offset += ByteUtil.sizeOfInVarInt32(valueLength); - parser.parse(result, offset, i); - offset += 8; - } - return (T)parser.getResult(); - } else { - return (T)parser.getEmptyResult(); - } - } else { - throw new TarantoolConnectorException("Can't get key set: " + errorCode); - } - } catch (IOException e) { - throw new TarantoolConnectorException("Can't correct make socket operation", e); - } finally { - worker.release(); - } - } - - @Override - public long[] getScriptKeySetAsLongArray(int batchSize) throws TarantoolConnectorException, InterruptedException { - return getScriptKeySet(batchSize, new LongParser()); - } - - @Override - public byte[][] getScriptKeySetAsByteArray(int batchSize) throws TarantoolConnectorException, InterruptedException { - return getScriptKeySet(batchSize, new ByteArrayParser()); - } - - @SuppressWarnings("unchecked") - private <T> T getScriptKeySet(int batchSize, InternalParser parser) throws InterruptedException, TarantoolConnectorException { - SocketWorker worker = getSocketWorker(); - try { - int requestId = getRequestId(); - byte[] packet = RequestResponseFormatter.createScriptDeliverKeySetCommand(requestId, nameSpace, batchSize); - worker.writeData(packet); - - byte[] result = RequestResponseFormatter.readResponseData(requestId, worker); - final TarantoolServerErrorCode errorCode = TarantoolServerErrorCode.getErrorBy(ByteUtil.readInteger(result, 0)); - if (errorCode == null) { - int updatedElements = ByteUtil.readInteger(result, 4); - if (updatedElements > 0) { - int offset = 8; - parser.allocateMemory(updatedElements); - for (int i = 0; i < updatedElements; i++) { - int valueLength = ByteUtil.decodeLengthInVar32Int(result, offset); - if (valueLength != 8) { - throw new TarantoolConnectorException("Get key set operation return incorrect id length: " + valueLength); - } - - offset += ByteUtil.sizeOfInVarInt32(valueLength); - parser.parse(result, offset, i); - offset += 8; - } - return (T)parser.getResult(); - } else { - return (T)parser.getEmptyResult(); - } - } else { - throw new TarantoolConnectorException("Can't get key set: " + errorCode); - } - } catch (IOException e) { - throw new TarantoolConnectorException("Can't correct make socket operation", e); - } finally { - worker.release(); - } - } - - @Override - public void truncate() throws InterruptedException, TarantoolConnectorException { - long[] keySet = getKeySetAsLongArray(); - for(long key: keySet) { - deleteById(key); - } - } - - @Override - public void close() { - pool.close(); - } - - private SocketWorker getSocketWorker() throws InterruptedException, TarantoolConnectorException { - try { - return pool.borrowSocketWorker(); - } catch (SocketPoolTimeOutException e) { - throw new TarantoolConnectorException("There are no free sockets", e); - } catch (SocketPoolException e) { - throw new TarantoolUnavailableException("Socket pool unavailable", e); - } - } - - private void insert(long id, int requestId, byte[] data, SocketWorker worker) - throws IOException, TarantoolConnectorException { - insert(ByteUtil.convertLongIdToByteArray(id), requestId, data, worker); - } - - private void insert(byte[] id, int requestId, byte[] data, SocketWorker worker) - throws IOException, TarantoolConnectorException { - byte[] packet = RequestResponseFormatter.createInsertCommand(id, requestId, nameSpace, data); - worker.writeData(packet); - - byte[] result = RequestResponseFormatter.readResponseData(requestId, worker); - - final TarantoolServerErrorCode errorCode = TarantoolServerErrorCode.getErrorBy(ByteUtil.readInteger(result, 0)); - if (errorCode == null) { - int updatedElements = ByteUtil.readInteger(result, 4); - if (updatedElements != 1) { - throw new TarantoolConnectorException("Incorrect number [" + updatedElements + "] of updated elements during insert operation."); - } - } else { - throw new TarantoolConnectorException("Can't insert data: " + errorCode); - } - } - - private byte[] get(long id, int requestId, SocketWorker worker) - throws IOException, TarantoolConnectorException { - return get(ByteUtil.convertLongIdToByteArray(id), requestId, worker); - } - - private byte[] get(byte[] id, int requestId, SocketWorker worker) - throws IOException, TarantoolConnectorException { - byte[] packet = RequestResponseFormatter.createGetDataCommand(id, requestId, nameSpace); - worker.writeData(packet); - - byte[] result = RequestResponseFormatter.readResponseData(requestId, worker); - final TarantoolServerErrorCode errorCode = TarantoolServerErrorCode.getErrorBy(ByteUtil.readInteger(result, 0)); - if (errorCode == null) { - int updatedElements = ByteUtil.readInteger(result, 4); - if (updatedElements == 1) { - // skip lenght of the data (4 bytes), number of fields (4 bytes), uid (5 bytes) - int valueLength = ByteUtil.decodeLengthInVar32Int(result, 25); - int offset = ByteUtil.sizeOfInVarInt32(valueLength); - final byte[] values = new byte[valueLength]; - ByteUtil.readBytes(result, 25 + offset, values, 0, valueLength); - return values; - } else { - return new byte[0]; - } - } else { - throw new TarantoolConnectorException("Can't get data: " + errorCode); - } - } -} diff --git a/connector/java/src/main/java/tarantool/connector/TarantoolResponse.java b/connector/java/src/main/java/tarantool/connector/TarantoolResponse.java deleted file mode 100644 index ca96c5cc0e..0000000000 --- a/connector/java/src/main/java/tarantool/connector/TarantoolResponse.java +++ /dev/null @@ -1,20 +0,0 @@ -package tarantool.connector; - - -public class TarantoolResponse { - private final int dataLength; - private final int requestId; - - public TarantoolResponse(int dataLength, int requestId) { - this.dataLength = dataLength; - this.requestId = requestId; - } - - public int getDataLength() { - return dataLength; - } - - public int getRequestId() { - return requestId; - } -} diff --git a/connector/java/src/main/java/tarantool/connector/TarantoolServerErrorCode.java b/connector/java/src/main/java/tarantool/connector/TarantoolServerErrorCode.java deleted file mode 100644 index 16de269e14..0000000000 --- a/connector/java/src/main/java/tarantool/connector/TarantoolServerErrorCode.java +++ /dev/null @@ -1,86 +0,0 @@ -package tarantool.connector; - -import java.util.HashMap; -import java.util.Map; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - - -public class TarantoolServerErrorCode { - private static final Log LOG = LogFactory.getLog(TarantoolServerErrorCode.class); - - public final static TarantoolServerErrorCode ERR_CODE_OK; - public final static TarantoolServerErrorCode ERR_CODE_NONMASTER; - public final static TarantoolServerErrorCode ERR_CODE_ILLEGAL_PARAMS; - public final static TarantoolServerErrorCode ERR_CODE_NODE_IS_RO; - public final static TarantoolServerErrorCode ERR_CODE_NODE_IS_LOCKED; - public final static TarantoolServerErrorCode ERR_CODE_MEMORY_ISSUE; - public final static TarantoolServerErrorCode ERR_CODE_UNSUPPORTED_COMMAND; - public final static TarantoolServerErrorCode ERR_CODE_WRONG_FIELD; - public final static TarantoolServerErrorCode ERR_CODE_WRONG_NUMBER; - public final static TarantoolServerErrorCode ERR_CODE_DUPLICATE; - public final static TarantoolServerErrorCode ERR_CODE_NOTHING; - public final static TarantoolServerErrorCode ERR_CODE_WRONG_VERSION; - public final static TarantoolServerErrorCode ERR_CODE_UNKNOWN_ERROR; - - private int codeId; - private String error; - - private static Map<Integer, TarantoolServerErrorCode> ERROR_CODE_MAPS; - - static { - ERROR_CODE_MAPS = new HashMap<Integer, TarantoolServerErrorCode>(13); - ERR_CODE_OK = new TarantoolServerErrorCode(0x00000000, "The query was executed without errors"); - ERR_CODE_NONMASTER = new TarantoolServerErrorCode(0x00000102, "An attempt was made to change data on a read-only port"); - ERR_CODE_ILLEGAL_PARAMS = new TarantoolServerErrorCode(0x00000202, "Incorrectly formatted query"); - ERR_CODE_NODE_IS_RO = new TarantoolServerErrorCode(0x00000401, "The requested data is blocked from modification"); - ERR_CODE_NODE_IS_LOCKED = new TarantoolServerErrorCode(0x00000601, "The requested data is not available"); - ERR_CODE_MEMORY_ISSUE = new TarantoolServerErrorCode(0x00000701, "An error occurred when allocating memory"); - ERR_CODE_UNSUPPORTED_COMMAND = new TarantoolServerErrorCode(0x00000a02, "The query is not recognized"); - ERR_CODE_WRONG_FIELD = new TarantoolServerErrorCode(0x00001E02, "An unknown field was requested"); - ERR_CODE_WRONG_NUMBER = new TarantoolServerErrorCode(0x00001F02, "An out-of-range numeric value was included in the query"); - ERR_CODE_DUPLICATE = new TarantoolServerErrorCode(0x00002002, "An attempt was made to create an object with an existing key"); - ERR_CODE_NOTHING = new TarantoolServerErrorCode(0x00002400, "The query does not support data modification or return"); - ERR_CODE_WRONG_VERSION = new TarantoolServerErrorCode(0x00002602, "The protocol version is not supported"); - ERR_CODE_UNKNOWN_ERROR = new TarantoolServerErrorCode(0x00002702, "Unknown error"); - } - - public static TarantoolServerErrorCode getErrorBy(int errorCode) { - if (errorCode == ERR_CODE_OK.codeId) { - return null; - } - final TarantoolServerErrorCode tarantoolServerErrorCode = ERROR_CODE_MAPS.get(errorCode); - if (tarantoolServerErrorCode == null) { - LOG.warn("Not supported code received from server: " + errorCode); - return ERR_CODE_UNKNOWN_ERROR; - } - return tarantoolServerErrorCode; - } - - public TarantoolServerErrorCode(int codeId, String error) { - this.codeId = codeId; - this.error = error; - TarantoolServerErrorCode previousError = ERROR_CODE_MAPS.put(codeId, this); - if (previousError == null) { - return; - } - throw new IllegalStateException("Duplicate error code: " + codeId + " for errors: " + error + ", " + previousError.getError()); - } - - public String getError() { - return error; - } - - public int getCodeId() { - return codeId; - } - - @Override - public String toString() { - return "TarantoolServerErrorCode{" + - "codeId=" + codeId + - ", error='" + error + '\'' + - '}'; - } -} diff --git a/connector/java/src/main/java/tarantool/connector/exception/TarantoolConnectorException.java b/connector/java/src/main/java/tarantool/connector/exception/TarantoolConnectorException.java deleted file mode 100644 index b3f4d1dea8..0000000000 --- a/connector/java/src/main/java/tarantool/connector/exception/TarantoolConnectorException.java +++ /dev/null @@ -1,13 +0,0 @@ -package tarantool.connector.exception; - - -public class TarantoolConnectorException extends Exception { - - public TarantoolConnectorException(String message) { - super(message); - } - - public TarantoolConnectorException(String message, Throwable throwable) { - super(message, throwable); - } -} diff --git a/connector/java/src/main/java/tarantool/connector/exception/TarantoolUnavailableException.java b/connector/java/src/main/java/tarantool/connector/exception/TarantoolUnavailableException.java deleted file mode 100644 index 178c1395f7..0000000000 --- a/connector/java/src/main/java/tarantool/connector/exception/TarantoolUnavailableException.java +++ /dev/null @@ -1,13 +0,0 @@ -package tarantool.connector.exception; - - -public class TarantoolUnavailableException extends TarantoolConnectorException { - - public TarantoolUnavailableException(String message) { - super(message); - } - - public TarantoolUnavailableException(String message, Throwable throwable) { - super(message, throwable); - } -} diff --git a/connector/java/src/main/java/tarantool/connector/socketpool/AbstractSocketPool.java b/connector/java/src/main/java/tarantool/connector/socketpool/AbstractSocketPool.java deleted file mode 100644 index 462d2a344a..0000000000 --- a/connector/java/src/main/java/tarantool/connector/socketpool/AbstractSocketPool.java +++ /dev/null @@ -1,173 +0,0 @@ -package tarantool.connector.socketpool; - -import java.io.IOException; -import java.net.InetAddress; -import java.net.UnknownHostException; -import java.util.concurrent.BlockingQueue; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.LinkedBlockingQueue; -import java.util.concurrent.ThreadFactory; -import java.util.concurrent.TimeUnit; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import tarantool.connector.socketpool.exception.SocketPoolException; -import tarantool.connector.socketpool.worker.FactoryType; -import tarantool.connector.socketpool.worker.SocketFactory; -import tarantool.connector.socketpool.worker.SocketWorker; -import tarantool.connector.socketpool.worker.SocketWorkerInternal; - - -public abstract class AbstractSocketPool implements SocketPool { - - private static final Log LOG = LogFactory.getLog(AbstractSocketPool.class); - - public static final long WAITING_SOCKET_POOL_TIMEOUT = 1000L; // 1 sec - public static final long RECONNECT_SOCKET_TIMEOUT = 1000L; // 1 sec - public static final long INITIALIZE_SOCKET_POOL_TIMEOUT = 20000L; // 20 sec - public static final int DISCONNECT_BOUND = 10; - - private static final long DISCONNECT_BOUND_CHECK_PERIOD = TimeUnit.SECONDS.toNanos(1); - - final long waitingTimeout; - final long reconnectTimeout; - final long initializeTimeout; - - final SocketFactory socketWorkerFactory; - - private final int disconnectBound; - private long[] timeQueue; - private int timeQueueIndex = 0; - - private final ExecutorService reconnectExecutor; - private final BlockingQueue<SocketWorkerInternal> reconnectQueue = new LinkedBlockingQueue<SocketWorkerInternal>(); - - final SocketPoolStateMachine stateMachine = new SocketPoolStateMachine(); - - public AbstractSocketPool(String host, int port, int socketReadTimeout, long waitingTimeout, - long reconnectTimeout, long initializeTimeout, int disconnectBound, FactoryType type) throws UnknownHostException { - - if (host == null || "".equals(host.trim())) { - throw new IllegalArgumentException("Incorrect host:" + host); - } - - if (port < 0 || port > 0xFFFF) { - throw new IllegalArgumentException("Port out of range:" + port); - } - - if (waitingTimeout < 0L) { - throw new IllegalArgumentException("Incorrect value of waiting timeout"); - } - - if (reconnectTimeout < 0L) { - throw new IllegalArgumentException("Incorrect value of reconnect timeout"); - } - - if (disconnectBound < 0) { - throw new IllegalArgumentException("Incorrect value of disconnect bound"); - } - - if (socketReadTimeout < 0) { - throw new IllegalArgumentException("Incorrect value of socket read timeout"); - } - - if (initializeTimeout < 0L) { - throw new IllegalArgumentException("Incorrect value of initialize timeout"); - } - - this.waitingTimeout = waitingTimeout; - this.reconnectTimeout = reconnectTimeout; - this.initializeTimeout = initializeTimeout; - this.disconnectBound = disconnectBound; - this.timeQueue = new long[disconnectBound]; - - socketWorkerFactory = type.createFactory(InetAddress.getByName(host), port, socketReadTimeout, this); - - reconnectExecutor = Executors.newSingleThreadExecutor(new ThreadFactory() { - @Override - public Thread newThread(Runnable r) { - Thread thread = new Thread(r, "ReconnectionThread"); - thread.setDaemon(true); - thread.setPriority(Thread.MIN_PRIORITY); - return thread; - } - }); - reconnectExecutor.execute(new Runnable() { - @Override - public void run() { - Thread thread = Thread.currentThread(); - while (!thread.isInterrupted()) { - SocketWorkerInternal worker = null; - try { - worker = reconnectQueue.take(); - worker.connect(); - if (stateMachine.isReconnecting() && reconnectQueue.isEmpty()) { - Thread.sleep(AbstractSocketPool.this.reconnectTimeout); - if (reconnectQueue.isEmpty()) { // wait reconnectTimeout for check unstable net - stateMachine.connect(); - } - } - LOG.info("Reconnect completed successfully"); - internalReturnSocketWorker(worker); - } catch (InterruptedException e) { - LOG.info("Reconnecting thread is stopped"); - thread.interrupt(); // thread was stopped, propagate interruption - } catch (IOException e) { - LOG.info("Reconnect completed failed"); - try { - reconnectQueue.put(worker); - Thread.sleep(AbstractSocketPool.this.reconnectTimeout); - } catch (InterruptedException e1) { - LOG.info("Reconnecting thread is stopped"); - thread.interrupt(); // thread was stopped, propagate interruption - } - } - } - } - }); - } - - public void close() { - stateMachine.close(); - reconnectExecutor.shutdownNow(); - internalClose(); - } - - public void returnSocketWorker(SocketWorkerInternal socketWorker) { - if (socketWorker.isConnected()) { - internalReturnSocketWorker(socketWorker); - } else { - pushToReconnect(socketWorker); - if (stateMachine.isRunning()) { - synchronized (stateMachine) { - if (!stateMachine.isRunning()) { - return; - } - int index = timeQueueIndex++ % timeQueue.length; - long lastTimePoint = timeQueue[index]; - timeQueue[index] = System.nanoTime(); - - if (lastTimePoint > 0 && System.nanoTime() - lastTimePoint < DISCONNECT_BOUND_CHECK_PERIOD) { - stateMachine.disconnect(); - timeQueueIndex = 0; - timeQueue = new long[disconnectBound]; - feedReconnect(); - } - } - } - } - } - - void pushToReconnect(SocketWorkerInternal socketWorker) { - socketWorker.close(); - boolean added = reconnectQueue.offer(socketWorker); - assert added: "Queue can't add wrapper, too many socket worker for queue size"; - } - - public abstract SocketWorker borrowSocketWorker() throws InterruptedException, SocketPoolException; - abstract void internalReturnSocketWorker(SocketWorkerInternal socketWorker); - abstract void feedReconnect(); - abstract void internalClose(); -} \ No newline at end of file diff --git a/connector/java/src/main/java/tarantool/connector/socketpool/DynamicSocketPool.java b/connector/java/src/main/java/tarantool/connector/socketpool/DynamicSocketPool.java deleted file mode 100644 index f6f618a589..0000000000 --- a/connector/java/src/main/java/tarantool/connector/socketpool/DynamicSocketPool.java +++ /dev/null @@ -1,267 +0,0 @@ -package tarantool.connector.socketpool; - -import java.io.IOException; -import java.net.UnknownHostException; -import java.util.Deque; -import java.util.LinkedList; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.ThreadFactory; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.locks.Condition; -import java.util.concurrent.locks.Lock; -import java.util.concurrent.locks.ReentrantLock; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import tarantool.connector.socketpool.exception.SocketPoolClosedException; -import tarantool.connector.socketpool.exception.SocketPoolException; -import tarantool.connector.socketpool.exception.SocketPoolTimeOutException; -import tarantool.connector.socketpool.exception.SocketPoolUnavailableException; -import tarantool.connector.socketpool.worker.SocketWorker; -import tarantool.connector.socketpool.worker.SocketWorkerInternal; - -/** - * Socket pool with low and top waterline. Socket pool uses dynamic balancer for thread count - */ -class DynamicSocketPool extends AbstractSocketPool { - - private static final Log LOG = LogFactory.getLog(DynamicSocketPool.class); - - private static final long MIN_LATENCY_PERIOD = 5000; //5 sec - - private final long latency; - private final int minPoolSize; - private final int maxPoolSize; - private int currentUsed = 0; - - private final Deque<SocketWorkerInternal> queue = new LinkedList<SocketWorkerInternal>(); - - private final Lock lock = new ReentrantLock(); - private final Condition cond = lock.newCondition(); - - private final ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor(new ThreadFactory(){ - @Override - public Thread newThread(Runnable r) { - Thread thread = new Thread(r, "DynamicSocketPoolLatencyCleaner"); - thread.setDaemon(true); - thread.setPriority(Thread.MIN_PRIORITY); - return thread; - } - }); - - public DynamicSocketPool(SocketPoolConfig config) throws UnknownHostException, SocketPoolTimeOutException { - super(config.getHost(), config.getPort(), config.getSocketReadTimeout(), config.getWaitingTimeout(), - config.getReconnectTimeout(), config.getInitializeTimeout(), config.getDisconnectBound(), config.getType()); - - if (config.getMinPoolSize() < 0 || config.getMaxPoolSize() > config.getMaxPoolSize() || config.getMaxPoolSize() == 0) { - throw new IllegalArgumentException("Incorrect value of min or max pool size"); - } - - if (config.getLatencyPeriod() < 0) { - throw new IllegalArgumentException("Incorrect value of latency time"); - } - - this.minPoolSize = config.getMinPoolSize(); - this.maxPoolSize = config.getMaxPoolSize(); - this.latency = config.getLatencyPeriod(); - - - - startSocketPoolCleaner(); - - initializePool(); - } - - private void initializePool() throws SocketPoolTimeOutException { - long startTime = System.currentTimeMillis(); - - for (int i = 0; i < minPoolSize;) { - - - if (stateMachine.isClosed()) { - LOG.info("Socket pool is closed, initialization aborted"); - return; // Socket pool is closed - } - - lock.lock(); - try { - if (queue.size() + currentUsed > minPoolSize) { - break; - } - - try { - SocketWorkerInternal socketWorker = socketWorkerFactory.create(); - queue.addFirst(socketWorker); - i++; - } catch (IOException e) { - LOG.warn("Can't establish socket connection because: Exception - " + - e.getClass().getSimpleName() + " and case - " + e.getMessage()); - - try { - Thread.sleep(reconnectTimeout); - } catch (InterruptedException e1) { - LOG.error("Thread in reconnect timeout state is interrupted. Reconnection is aborted"); - Thread.currentThread().interrupt(); - return; - } - } - } finally { - lock.unlock(); - } - - if (System.currentTimeMillis() - startTime > initializeTimeout) { - throw new SocketPoolTimeOutException("Initialize pool timeout occur"); - } - } - } - - private void startSocketPoolCleaner() { - Runnable cleanTask = new Runnable() { - @Override - public void run() { - long scheduleTime = latency; - - - - if (stateMachine.isClosed()) { - LOG.info("Socket pool is closed, cleaner thread stopped"); - return; - } - - lock.lock(); - try { - if (queue.size() + currentUsed <= minPoolSize) { - return; - } - - long remainingTime, currentTime = System.currentTimeMillis(); - while(!queue.isEmpty()) { - SocketWorkerInternal socketWorker = queue.peekLast(); - assert socketWorker != null: "Deque must contain socket worker"; - - remainingTime = currentTime - socketWorker.getLastTimeStamp(); - if (remainingTime > latency) { - SocketWorkerInternal removed = queue.pollLast(); - assert removed == socketWorker: "Incorrect operation peek and remove"; - - socketWorker.close(); - } else { - scheduleTime = latency - remainingTime; - break; - } - } - } finally { - lock.unlock(); - - if (!stateMachine.isClosed()) { - scheduler.schedule(this, MIN_LATENCY_PERIOD + scheduleTime, TimeUnit.MILLISECONDS); - } - } - } - }; - - if (!stateMachine.isClosed()) { - scheduler.schedule(cleanTask, MIN_LATENCY_PERIOD + latency, TimeUnit.MILLISECONDS); - } - } - - public SocketWorker borrowSocketWorker() throws InterruptedException, SocketPoolException { - SocketWorkerInternal socketWorker; - - - - if (stateMachine.isClosed()) { - throw new SocketPoolClosedException("Socket pool is closed, borrowing of socket worker was rejected"); - } - - if (stateMachine.isReconnecting()) { - throw new SocketPoolUnavailableException("Socket pool is reconnecting, borrowing of socket worker was rejected"); - } - - lock.lock(); - try { - do { - socketWorker = queue.pollFirst(); - if (socketWorker == null) { - if (currentUsed < maxPoolSize) { - try { - socketWorker = socketWorkerFactory.create(); - } catch (IOException e) { - LOG.warn("Can't establish socket connection because: Exception - " + - e.getClass().getSimpleName() + " and case - " + e.getMessage()); - throw new SocketPoolUnavailableException("Can't create extra socket", e); - } - } else { - while(queue.isEmpty()) { - if (!cond.await(waitingTimeout, TimeUnit.MILLISECONDS)) { - throw new SocketPoolTimeOutException("Timeout is occurred while wait for socket worker"); - } - } - - socketWorker = queue.pollFirst(); - assert socketWorker != null: "Incorrect state of queue"; - } - } - } while(socketWorker == null); - - currentUsed++; - - } finally { - lock.unlock(); - } - - return socketWorker; - } - - public void internalReturnSocketWorker(SocketWorkerInternal socketWorker) { - - - if (stateMachine.isClosed()) { - socketWorker.close(); - LOG.info("Socket pool is closed, return operation skipped"); - return; - } - - lock.lock(); - try { - if (currentUsed > 0) { - currentUsed--; - } - - queue.addFirst(socketWorker); - - cond.signal(); - } finally { - lock.unlock(); - } - } - - @Override - void feedReconnect() { - lock.lock(); - try { - for (SocketWorkerInternal worker: queue) { - pushToReconnect(worker); - } - queue.clear(); - } finally { - lock.unlock(); - } - } - - void internalClose() { - LOG.info("Socket pool internal close ..."); - - lock.lock(); - try { - scheduler.shutdownNow(); - for(SocketWorkerInternal socketWorker: queue) { - socketWorker.close(); - } - } finally { - lock.unlock(); - } - } -} \ No newline at end of file diff --git a/connector/java/src/main/java/tarantool/connector/socketpool/SocketPool.java b/connector/java/src/main/java/tarantool/connector/socketpool/SocketPool.java deleted file mode 100644 index f7f60bed37..0000000000 --- a/connector/java/src/main/java/tarantool/connector/socketpool/SocketPool.java +++ /dev/null @@ -1,11 +0,0 @@ -package tarantool.connector.socketpool; - -import tarantool.connector.socketpool.exception.SocketPoolException; -import tarantool.connector.socketpool.worker.SocketWorker; - - -public interface SocketPool { - SocketWorker borrowSocketWorker() - throws InterruptedException, SocketPoolException; - void close(); -} diff --git a/connector/java/src/main/java/tarantool/connector/socketpool/SocketPoolConfig.java b/connector/java/src/main/java/tarantool/connector/socketpool/SocketPoolConfig.java deleted file mode 100644 index 90c3a81caf..0000000000 --- a/connector/java/src/main/java/tarantool/connector/socketpool/SocketPoolConfig.java +++ /dev/null @@ -1,116 +0,0 @@ -package tarantool.connector.socketpool; - -import tarantool.connector.socketpool.worker.FactoryType; - -public class SocketPoolConfig { - - private String host; - private int port; - private int socketReadTimeout; - private int minPoolSize; - private int maxPoolSize; - private long waitingTimeout; - private long reconnectTimeout; - private long initializeTimeout; - private int disconnectBound; - private FactoryType type; - private SocketPoolType socketPoolType; - private long latencyPeriod; - - public SocketPoolConfig(String host, int port, int socketReadTimeout, int minPoolSize, int maxPoolSize, long waitingTimeout, - long reconnectTimeout, long initializeTimeout, int disconnectBound, FactoryType type, SocketPoolType socketPoolType, - long latencyPeriod) { - this.host = host; - this.port = port; - this.socketReadTimeout = socketReadTimeout; - this.minPoolSize = minPoolSize; - this.maxPoolSize = maxPoolSize; - this.waitingTimeout = waitingTimeout; - this.reconnectTimeout = reconnectTimeout; - this.initializeTimeout = initializeTimeout; - this.disconnectBound = disconnectBound; - this.type = type; - this.socketPoolType = socketPoolType; - this.latencyPeriod = latencyPeriod; - } - - public SocketPoolConfig(String host, int port, int socketReadTimeout, int minPoolSize, long waitingTimeout, long reconnectTimeout, - long initializeTimeout, int disconnectBound, FactoryType type, SocketPoolType socketPoolType) { - this.host = host; - this.port = port; - this.socketReadTimeout = socketReadTimeout; - this.minPoolSize = minPoolSize; - this.waitingTimeout = waitingTimeout; - this.reconnectTimeout = reconnectTimeout; - this.initializeTimeout = initializeTimeout; - this.disconnectBound = disconnectBound; - this.type = type; - this.socketPoolType = socketPoolType; - } - - public String getHost() { - return host; - } - - public int getPort() { - return port; - } - - public int getSocketReadTimeout() { - return socketReadTimeout; - } - - public int getMinPoolSize() { - return minPoolSize; - } - - public int getMaxPoolSize() { - return maxPoolSize; - } - - public long getWaitingTimeout() { - return waitingTimeout; - } - - public long getReconnectTimeout() { - return reconnectTimeout; - } - - public long getInitializeTimeout() { - return initializeTimeout; - } - - public int getDisconnectBound() { - return disconnectBound; - } - - public FactoryType getType() { - return type; - } - - public long getLatencyPeriod() { - return latencyPeriod; - } - - public SocketPoolType getSocketPoolType() { - return socketPoolType; - } - - @Override - public String toString() { - return "SocketPoolConfig{" + - "host='" + host + '\'' + - ", port=" + port + - ", socketReadTimeout=" + socketReadTimeout + - ", minPoolSize=" + minPoolSize + - ", maxPoolSize=" + maxPoolSize + - ", waitingTimeout=" + waitingTimeout + - ", reconnectTimeout=" + reconnectTimeout + - ", initializeTimeout=" + initializeTimeout + - ", disconnectBound=" + disconnectBound + - ", type=" + type + - ", socketPoolType=" + socketPoolType + - ", latencyPeriod=" + latencyPeriod + - '}'; - } -} diff --git a/connector/java/src/main/java/tarantool/connector/socketpool/SocketPoolFactory.java b/connector/java/src/main/java/tarantool/connector/socketpool/SocketPoolFactory.java deleted file mode 100644 index d1bf043885..0000000000 --- a/connector/java/src/main/java/tarantool/connector/socketpool/SocketPoolFactory.java +++ /dev/null @@ -1,21 +0,0 @@ -package tarantool.connector.socketpool; - -import java.net.UnknownHostException; - -import tarantool.connector.socketpool.exception.SocketPoolTimeOutException; - - -public class SocketPoolFactory { - - public static SocketPool createSocketPool(SocketPoolConfig socketPoolConfig) - throws UnknownHostException, SocketPoolTimeOutException { - switch (socketPoolConfig.getSocketPoolType()) { - case DYNAMIC_POOL: - return new DynamicSocketPool(socketPoolConfig); - case STATIC_POOL: - return new StaticSocketPool(socketPoolConfig); - default: - throw new IllegalArgumentException("Incorrect socket pool type: " + socketPoolConfig.getSocketPoolType()); - } - } -} diff --git a/connector/java/src/main/java/tarantool/connector/socketpool/SocketPoolStateMachine.java b/connector/java/src/main/java/tarantool/connector/socketpool/SocketPoolStateMachine.java deleted file mode 100644 index 9179f2e4f5..0000000000 --- a/connector/java/src/main/java/tarantool/connector/socketpool/SocketPoolStateMachine.java +++ /dev/null @@ -1,77 +0,0 @@ -package tarantool.connector.socketpool; - - -class SocketPoolStateMachine { - // state diagram - enum PoolState { - RUNNING { - @Override - PoolState connect() { - return RUNNING; - } - @Override - PoolState disconnect() { - return RECONNECTING; - } - @Override - PoolState close() { - return CLOSED; - }}, - RECONNECTING { - @Override - PoolState connect() { - return RUNNING; - } - @Override - PoolState disconnect() { - return RECONNECTING; - } - @Override - PoolState close() { - return CLOSED; - }}, - CLOSED { - @Override - PoolState connect() { - throw new IllegalStateException("Can't change closed pool state"); - } - @Override - PoolState disconnect() { - throw new IllegalStateException("Can't change closed pool state"); - } - @Override - PoolState close() { - throw new IllegalStateException("Can't change closed pool state"); - }}; - - abstract PoolState connect(); - abstract PoolState disconnect(); - abstract PoolState close(); - } - - private volatile PoolState state = PoolState.RUNNING; - - public void connect() { - state = state.connect(); - } - - public void disconnect() { - state = state.disconnect(); - } - - public void close() { - state = state.close(); - } - - public boolean isRunning() { - return state == PoolState.RUNNING; - } - - public boolean isReconnecting() { - return state == PoolState.RECONNECTING; - } - - public boolean isClosed() { - return state == PoolState.CLOSED; - } -} diff --git a/connector/java/src/main/java/tarantool/connector/socketpool/SocketPoolType.java b/connector/java/src/main/java/tarantool/connector/socketpool/SocketPoolType.java deleted file mode 100644 index 4f1efdab24..0000000000 --- a/connector/java/src/main/java/tarantool/connector/socketpool/SocketPoolType.java +++ /dev/null @@ -1,7 +0,0 @@ -package tarantool.connector.socketpool; - - -public enum SocketPoolType { - DYNAMIC_POOL, - STATIC_POOL -} diff --git a/connector/java/src/main/java/tarantool/connector/socketpool/StaticSocketPool.java b/connector/java/src/main/java/tarantool/connector/socketpool/StaticSocketPool.java deleted file mode 100644 index 68d2e44113..0000000000 --- a/connector/java/src/main/java/tarantool/connector/socketpool/StaticSocketPool.java +++ /dev/null @@ -1,130 +0,0 @@ -package tarantool.connector.socketpool; - -import java.io.IOException; -import java.net.UnknownHostException; -import java.util.concurrent.BlockingQueue; -import java.util.concurrent.LinkedBlockingQueue; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.locks.ReadWriteLock; -import java.util.concurrent.locks.ReentrantReadWriteLock; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import tarantool.connector.socketpool.exception.SocketPoolClosedException; -import tarantool.connector.socketpool.exception.SocketPoolException; -import tarantool.connector.socketpool.exception.SocketPoolTimeOutException; -import tarantool.connector.socketpool.exception.SocketPoolUnavailableException; -import tarantool.connector.socketpool.worker.SocketWorker; -import tarantool.connector.socketpool.worker.SocketWorkerInternal; - - -class StaticSocketPool extends AbstractSocketPool { - - private static final Log LOG = LogFactory.getLog(StaticSocketPool.class); - - private final int poolSize; - - private final BlockingQueue<SocketWorkerInternal> queue = new LinkedBlockingQueue<SocketWorkerInternal>(); - - private final ReadWriteLock rwLock = new ReentrantReadWriteLock(); - - public StaticSocketPool(SocketPoolConfig config) throws UnknownHostException, SocketPoolTimeOutException { - super(config.getHost(), config.getPort(), config.getSocketReadTimeout(), config.getWaitingTimeout(), - config.getReconnectTimeout(), config.getInitializeTimeout(), config.getDisconnectBound(), config.getType()); - - if (config.getMinPoolSize() <= 0) { - throw new IllegalArgumentException("Incorrect value of pool size"); - } - - this.poolSize = config.getMinPoolSize(); - - initializePool(); - } - - private void initializePool() throws SocketPoolTimeOutException { - long startTime = System.currentTimeMillis(); - - for (int i = 0; i < poolSize;) { - try { - SocketWorkerInternal socketWorker = socketWorkerFactory.create(); - queue.add(socketWorker); - i++; - - if (stateMachine.isClosed()) { - socketWorker.close(); - LOG.info("Socket pool is closed, initialization aborted"); - break; - } - } catch (IOException e) { - LOG.warn("Can't establish socket connection because: Exception - " + - e.getClass().getSimpleName() + " and case - " + e.getMessage()); - - try { - Thread.sleep(reconnectTimeout); - } catch (InterruptedException e1) { - LOG.error("Thread in reconnect timeout state is interrupted. Reconnection is aborted"); - Thread.currentThread().interrupt(); - return; - } - } - - if (System.currentTimeMillis() - startTime > initializeTimeout) { - throw new SocketPoolTimeOutException("Initialize pool timeout occur"); - } - } - } - - public SocketWorker borrowSocketWorker() throws InterruptedException, SocketPoolException { - - if (stateMachine.isReconnecting()) { - throw new SocketPoolUnavailableException("Socket pool is reconnecting, borrowing of socket worker was rejected"); - } - - SocketWorker worker = queue.poll(waitingTimeout, TimeUnit.MILLISECONDS); - - if (stateMachine.isClosed()) { - throw new SocketPoolClosedException("Socket pool is closed, borrowing of socket worker was rejected"); - } - - if (worker == null) { - throw new SocketPoolTimeOutException("Timeout is occurred while wait for socket worker"); - } - - return worker; - } - - public void internalReturnSocketWorker(SocketWorkerInternal socketWorker) { - rwLock.readLock().lock(); - try { - boolean added = queue.offer(socketWorker); - assert added: "Queue can't add wrapper, too many socket worker for queue size"; - - if (stateMachine.isClosed()) { - socketWorker.close(); - LOG.info("Socket pool is closed, return operation skipped"); - } - } finally { - rwLock.readLock().unlock(); - } - } - - @Override - void feedReconnect() { - rwLock.writeLock().lock(); - try { - for (SocketWorkerInternal worker: queue) { - pushToReconnect(worker); - } - queue.clear(); - } finally { - rwLock.writeLock().unlock(); - } - } - - void internalClose() { - for(SocketWorkerInternal socketWorker: queue) { - socketWorker.close(); - } - } -} diff --git a/connector/java/src/main/java/tarantool/connector/socketpool/exception/SocketPoolClosedException.java b/connector/java/src/main/java/tarantool/connector/socketpool/exception/SocketPoolClosedException.java deleted file mode 100644 index 3a20bb8ca6..0000000000 --- a/connector/java/src/main/java/tarantool/connector/socketpool/exception/SocketPoolClosedException.java +++ /dev/null @@ -1,13 +0,0 @@ -package tarantool.connector.socketpool.exception; - - -public class SocketPoolClosedException extends SocketPoolException { - - public SocketPoolClosedException(String message) { - super(message); - } - - public SocketPoolClosedException(String message, Throwable throwable) { - super(message, throwable); - } -} diff --git a/connector/java/src/main/java/tarantool/connector/socketpool/exception/SocketPoolException.java b/connector/java/src/main/java/tarantool/connector/socketpool/exception/SocketPoolException.java deleted file mode 100644 index 30e4667586..0000000000 --- a/connector/java/src/main/java/tarantool/connector/socketpool/exception/SocketPoolException.java +++ /dev/null @@ -1,13 +0,0 @@ -package tarantool.connector.socketpool.exception; - - -public class SocketPoolException extends Exception { - - public SocketPoolException(String message) { - super(message); - } - - public SocketPoolException(String message, Throwable throwable) { - super(message, throwable); - } -} diff --git a/connector/java/src/main/java/tarantool/connector/socketpool/exception/SocketPoolTimeOutException.java b/connector/java/src/main/java/tarantool/connector/socketpool/exception/SocketPoolTimeOutException.java deleted file mode 100644 index 7a435e9772..0000000000 --- a/connector/java/src/main/java/tarantool/connector/socketpool/exception/SocketPoolTimeOutException.java +++ /dev/null @@ -1,13 +0,0 @@ -package tarantool.connector.socketpool.exception; - - -public class SocketPoolTimeOutException extends SocketPoolException { - - public SocketPoolTimeOutException(String message) { - super(message); - } - - public SocketPoolTimeOutException(String message, Throwable throwable) { - super(message, throwable); - } -} diff --git a/connector/java/src/main/java/tarantool/connector/socketpool/exception/SocketPoolUnavailableException.java b/connector/java/src/main/java/tarantool/connector/socketpool/exception/SocketPoolUnavailableException.java deleted file mode 100644 index 69bafdb744..0000000000 --- a/connector/java/src/main/java/tarantool/connector/socketpool/exception/SocketPoolUnavailableException.java +++ /dev/null @@ -1,13 +0,0 @@ -package tarantool.connector.socketpool.exception; - - -public class SocketPoolUnavailableException extends SocketPoolException { - - public SocketPoolUnavailableException(String message) { - super(message); - } - - public SocketPoolUnavailableException(String message, Throwable throwable) { - super(message, throwable); - } -} diff --git a/connector/java/src/main/java/tarantool/connector/socketpool/worker/ChannelSocketWorker.java b/connector/java/src/main/java/tarantool/connector/socketpool/worker/ChannelSocketWorker.java deleted file mode 100644 index 0564f7dc0d..0000000000 --- a/connector/java/src/main/java/tarantool/connector/socketpool/worker/ChannelSocketWorker.java +++ /dev/null @@ -1,81 +0,0 @@ -package tarantool.connector.socketpool.worker; - -import java.io.EOFException; -import java.io.IOException; -import java.net.InetAddress; -import java.net.InetSocketAddress; -import java.net.Socket; -import java.nio.ByteBuffer; -import java.nio.channels.SocketChannel; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import tarantool.connector.socketpool.AbstractSocketPool; - - -class ChannelSocketWorker extends SocketWorkerInternal { - - private static final Log LOG = LogFactory.getLog(ChannelSocketWorker.class); - - private SocketChannel socketChannel; - - ChannelSocketWorker(InetAddress address, int port, int soTimeout, AbstractSocketPool pool) throws IOException { - super(pool, address, port, soTimeout); - connect(); - } - - @Override - public void connect() throws IOException { - socketChannel = SocketChannel.open(new InetSocketAddress(address, port)); - Socket socket = socketChannel.socket(); - - socket.setKeepAlive(true); - socket.setTcpNoDelay(true); - socket.setSoTimeout(soTimeout); // set but NIO not supported socket timeout - - connected(); - } - - @Override - public void close() { - try { - socketChannel.close(); - } catch (IOException e) { - LOG.error("Can't close socket channel which associated with the socket"); - } - - disconnected(); - } - - @Override - public void writeData(byte[] buffer) throws IOException { - try { - ByteBuffer byteBuffer = ByteBuffer.wrap(buffer); - while(byteBuffer.hasRemaining()) { - socketChannel.write(byteBuffer); - } - } catch (IOException e) { - LOG.error("Error occurred in write channel operation", e); - disconnected(); - throw e; - } - } - - @Override - public int readData(byte[] buffer, int length) throws IOException { - try { - ByteBuffer byteBuffer = ByteBuffer.wrap(buffer); - while (byteBuffer.hasRemaining()) { - if (socketChannel.read(byteBuffer) == -1) { - throw new EOFException("Unexpected end of stream"); - } - } - return byteBuffer.position(); - } catch (IOException e) { - LOG.error("Error occurred in read channel operation", e); - disconnected(); - throw e; - } - } -} diff --git a/connector/java/src/main/java/tarantool/connector/socketpool/worker/FactoryType.java b/connector/java/src/main/java/tarantool/connector/socketpool/worker/FactoryType.java deleted file mode 100644 index 255b6042d7..0000000000 --- a/connector/java/src/main/java/tarantool/connector/socketpool/worker/FactoryType.java +++ /dev/null @@ -1,34 +0,0 @@ -package tarantool.connector.socketpool.worker; - -import java.io.IOException; -import java.net.InetAddress; - -import tarantool.connector.socketpool.AbstractSocketPool; - -public enum FactoryType { - PLAIN_SOCKET { - @Override - public SocketFactory createFactory(final InetAddress address, final int port, final int soTimeout, final AbstractSocketPool pool) { - return new SocketFactory() { - @Override - public SocketWorkerInternal create() throws IOException { - return new PlainSocketWorker(address, port, soTimeout, pool); - } - }; - } - }, - - CHANNEL_SOCKET { - @Override - public SocketFactory createFactory(final InetAddress address, final int port, final int soTimeout, final AbstractSocketPool pool) { - return new SocketFactory() { - @Override - public SocketWorkerInternal create() throws IOException { - return new ChannelSocketWorker(address, port,soTimeout, pool); - } - }; - } - }; - - public abstract SocketFactory createFactory(InetAddress address, int port, int soTimeout, AbstractSocketPool pool); -} diff --git a/connector/java/src/main/java/tarantool/connector/socketpool/worker/PlainSocketWorker.java b/connector/java/src/main/java/tarantool/connector/socketpool/worker/PlainSocketWorker.java deleted file mode 100644 index 26917360a8..0000000000 --- a/connector/java/src/main/java/tarantool/connector/socketpool/worker/PlainSocketWorker.java +++ /dev/null @@ -1,95 +0,0 @@ -package tarantool.connector.socketpool.worker; - -import java.io.EOFException; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.net.InetAddress; -import java.net.Socket; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import tarantool.connector.socketpool.AbstractSocketPool; - - -class PlainSocketWorker extends SocketWorkerInternal { - - private static final Log LOG = LogFactory.getLog(PlainSocketWorker.class); - - private Socket socket; - - private OutputStream outputStream; - private InputStream inputStream; - - PlainSocketWorker(InetAddress address, int port, int soTimeout, AbstractSocketPool pool) - throws IOException { - super(pool, address, port, soTimeout); - connect(); - } - - @Override - public void connect() throws IOException { - socket = new Socket(address, port); - - socket.setKeepAlive(true); - socket.setTcpNoDelay(true); - socket.setSoTimeout(soTimeout); - - outputStream = socket.getOutputStream(); - inputStream = socket.getInputStream(); - - connected(); - } - - @Override - public void close() { - try { - socket.shutdownInput(); - } catch (IOException e) { - LOG.error("Can't shutdown input which associated with the socket"); - } - try { - socket.shutdownOutput(); - } catch (IOException e) { - LOG.error("Can't shutdown output which associated with the socket"); - } - try { - socket.close(); - } catch (IOException e) { - LOG.error("Can't close socket"); - } - - disconnected(); - } - - @Override - public void writeData(byte[] buffer) throws IOException { - try { - outputStream.write(buffer); - outputStream.flush(); - } catch (IOException e) { - LOG.error("Error occurred in write socket operation", e); - disconnected(); - throw e; - } - } - - @Override - public int readData(byte[] buffer, int length) throws IOException { - try { - int loadedBytes = 0, currentReadBytes = 0; - while((loadedBytes += currentReadBytes) != length) { - currentReadBytes = inputStream.read(buffer, loadedBytes, length - loadedBytes); - if (currentReadBytes == -1) { - throw new EOFException("Unexpected end of stream"); - } - } - return loadedBytes; - } catch (IOException e) { - LOG.error("Error occurred in read socket operation", e); - disconnected(); - throw e; - } - } -} diff --git a/connector/java/src/main/java/tarantool/connector/socketpool/worker/SocketFactory.java b/connector/java/src/main/java/tarantool/connector/socketpool/worker/SocketFactory.java deleted file mode 100644 index 3f38862dee..0000000000 --- a/connector/java/src/main/java/tarantool/connector/socketpool/worker/SocketFactory.java +++ /dev/null @@ -1,8 +0,0 @@ -package tarantool.connector.socketpool.worker; - -import java.io.IOException; - - -public interface SocketFactory { - public SocketWorkerInternal create() throws IOException; -} diff --git a/connector/java/src/main/java/tarantool/connector/socketpool/worker/SocketWorker.java b/connector/java/src/main/java/tarantool/connector/socketpool/worker/SocketWorker.java deleted file mode 100644 index f66849b683..0000000000 --- a/connector/java/src/main/java/tarantool/connector/socketpool/worker/SocketWorker.java +++ /dev/null @@ -1,10 +0,0 @@ -package tarantool.connector.socketpool.worker; - -import java.io.IOException; - - -public interface SocketWorker { - public void writeData(byte[] buffer) throws IOException; - public int readData(byte[] buffer, int length) throws IOException; - public void release(); -} diff --git a/connector/java/src/main/java/tarantool/connector/socketpool/worker/SocketWorkerInternal.java b/connector/java/src/main/java/tarantool/connector/socketpool/worker/SocketWorkerInternal.java deleted file mode 100644 index ca76e7f1e0..0000000000 --- a/connector/java/src/main/java/tarantool/connector/socketpool/worker/SocketWorkerInternal.java +++ /dev/null @@ -1,58 +0,0 @@ -package tarantool.connector.socketpool.worker; - -import java.io.IOException; -import java.net.InetAddress; - -import tarantool.connector.socketpool.AbstractSocketPool; - - -public abstract class SocketWorkerInternal implements SocketWorker { - - private enum ConnectionState { - CONNECTED, - DISCONNECTED - } - - private long lastTimeStamp; - private final AbstractSocketPool pool; - - final InetAddress address; - final int port; - final int soTimeout; - - ConnectionState state = ConnectionState.DISCONNECTED; - - SocketWorkerInternal(AbstractSocketPool pool, InetAddress address, int port, int soTimeout) { - this.pool = pool; - this.address = address; - this.port = port; - this.soTimeout = soTimeout; - - lastTimeStamp = System.currentTimeMillis(); - } - - final void connected() { - state = ConnectionState.CONNECTED; - } - - final void disconnected() { - state = ConnectionState.DISCONNECTED; - } - - public final boolean isConnected() { - return state == ConnectionState.CONNECTED; - } - - public long getLastTimeStamp() { - return lastTimeStamp; - } - - @Override - public final void release() { - lastTimeStamp = System.currentTimeMillis(); - pool.returnSocketWorker(this); - } - - public abstract void close(); - public abstract void connect() throws IOException; -} diff --git a/connector/java/src/main/java/tarantool/sample/TarantoolSample.java b/connector/java/src/main/java/tarantool/sample/TarantoolSample.java deleted file mode 100644 index 4dd3c2533f..0000000000 --- a/connector/java/src/main/java/tarantool/sample/TarantoolSample.java +++ /dev/null @@ -1,64 +0,0 @@ -package tarantool.sample; - -import java.net.UnknownHostException; -import java.util.Arrays; - -import tarantool.connector.TarantoolConnector; -import tarantool.connector.TarantoolConnectorConfig; -import tarantool.connector.TarantoolConnectorImpl; -import tarantool.connector.exception.TarantoolConnectorException; -import tarantool.connector.socketpool.SocketPoolType; -import tarantool.connector.socketpool.exception.SocketPoolTimeOutException; -import tarantool.connector.socketpool.worker.FactoryType; - -import static tarantool.connector.socketpool.AbstractSocketPool.DISCONNECT_BOUND; -import static tarantool.connector.socketpool.AbstractSocketPool.INITIALIZE_SOCKET_POOL_TIMEOUT; -import static tarantool.connector.socketpool.AbstractSocketPool.RECONNECT_SOCKET_TIMEOUT; -import static tarantool.connector.socketpool.AbstractSocketPool.WAITING_SOCKET_POOL_TIMEOUT; - -public class TarantoolSample { - - public static void main(String[] args) { - - int nameSpace = 0; - long latencyPeriod = 60000L; - String host = "127.0.0.1"; - int port = 33333; - int socketReadTimeout = 5000; - int minPoolSize = 1; - int maxPoolSize = 1; - - byte[] buffer = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; - - TarantoolConnectorConfig config = new TarantoolConnectorConfig(host, port, socketReadTimeout, minPoolSize, - maxPoolSize, WAITING_SOCKET_POOL_TIMEOUT, RECONNECT_SOCKET_TIMEOUT, INITIALIZE_SOCKET_POOL_TIMEOUT, - DISCONNECT_BOUND, FactoryType.PLAIN_SOCKET, SocketPoolType.STATIC_POOL, latencyPeriod, nameSpace); - - TarantoolConnector tarantoolConnector = null; - try { - tarantoolConnector = new TarantoolConnectorImpl(config); - - tarantoolConnector.insertData(1L, buffer); - byte[] incomingBuffer = tarantoolConnector.getData(1L); - - if (Arrays.equals(incomingBuffer, buffer)) { - System.out.println("Test is successful! Byte buffers are equals"); - } else { - System.out.println("Attention! Byte buffers are not equals. Result: " + Arrays.toString(incomingBuffer)); - } - } catch (UnknownHostException e) { - e.printStackTrace(); - } catch (InterruptedException e) { - e.printStackTrace(); - } catch (TarantoolConnectorException e) { - e.printStackTrace(); - } catch (SocketPoolTimeOutException e) { - e.printStackTrace(); - } finally { - if (tarantoolConnector != null) { - tarantoolConnector.close(); - } - } - } - -} diff --git a/connector/python/README.rst b/connector/python/README.rst deleted file mode 100644 index f3ed72b151..0000000000 --- a/connector/python/README.rst +++ /dev/null @@ -1,13 +0,0 @@ -================= - tarantool-python -================= - -Python interface to the `Tarantool database <https://github.com/tarantool/tarantool>`_. - -The latest version of this package is found at -`<https://github.com/mailru/tarantool-python>`_. - -Tarantool is a fast key/value data store originally designed by `Mail.Ru <http://mail.ru>`_ -and released under the terms of `BSD license <http://www.gnu.org/licenses/license-list.html#ModifiedBSD>`_. -Tarantool is production-ready and actively used at `Mail.Ru <http://mail.ru>`_, -one of the leading Russian web content providers. diff --git a/connector/ruby/README b/connector/ruby/README deleted file mode 100644 index 2c000361ab..0000000000 --- a/connector/ruby/README +++ /dev/null @@ -1,2 +0,0 @@ -Tarantool Ruby driver can be found at -https://github.com/tarantool/tarantool-ruby -- GitLab