Skip to content
This repository has been archived by the owner on Apr 17, 2019. It is now read-only.

Commit

Permalink
Feature/soci (#1505)
Browse files Browse the repository at this point in the history
Pqxx replaced by SOCI. Some bugs are fixed by Andrei

Signed-off-by: Victor Drobny <[email protected]>
  • Loading branch information
vdrobnyi authored and l4l committed Jul 25, 2018
1 parent 9ae5bb7 commit 9d12009
Show file tree
Hide file tree
Showing 35 changed files with 959 additions and 1,008 deletions.
5 changes: 3 additions & 2 deletions cmake/Modules/Findpq.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,10 @@ find_package_handle_standard_args(pq DEFAULT_MSG
pg_config_EXECUTABLE
)


set(URL https://git.postgresql.org/git/postgresql.git)
set(VERSION 029386ccbddd0a33d481b94e511f5219b03e6636)
set_target_description(pq "C postgres client library" ${URL} ${VERSION})


if (NOT pq_FOUND)
externalproject_add(postgres_postgres
GIT_REPOSITORY ${URL}
Expand All @@ -52,6 +50,9 @@ endif ()
get_filename_component(pq_LIBRARY_DIR ${pq_LIBRARY} DIRECTORY)
mark_as_advanced(pq_LIBRARY_DIR)

get_filename_component(pg_config_EXECUTABLE_DIR ${pg_config_EXECUTABLE} DIRECTORY)
mark_as_advanced(pg_config_EXECUTABLE_DIR)

set_target_properties(pq PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${pq_INCLUDE_DIR};${postgres_INCLUDE_DIR}"
IMPORTED_LOCATION ${pq_LIBRARY}
Expand Down
46 changes: 0 additions & 46 deletions cmake/Modules/Findpqxx.cmake

This file was deleted.

91 changes: 91 additions & 0 deletions cmake/Modules/Findsoci.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
set(_SOCI_REQUIRED_VARS SOCI_INCLUDE_DIR SOCI_LIBRARY SOCI_postgresql_PLUGIN)

add_library(SOCI::core UNKNOWN IMPORTED)
add_library(SOCI::postgresql UNKNOWN IMPORTED)

find_path(
SOCI_INCLUDE_DIR soci.h
PATH_SUFFIXES "" "soci"
DOC "Soci (http://soci.sourceforge.net) include directory")
mark_as_advanced(SOCI_INCLUDE_DIR)
get_filename_component(_SOCI_INCLUDE_PARENT_DIR ${SOCI_INCLUDE_DIR} DIRECTORY)
set(SOCI_INCLUDE_DIRS ${SOCI_INCLUDE_DIR} ${_SOCI_INCLUDE_PARENT_DIR})
mark_as_advanced(SOCI_INCLUDE_DIRS)

find_library(
SOCI_LIBRARY
NAMES soci_core
HINTS ${SOCI_INCLUDE_DIR}/..
PATH_SUFFIXES lib${LIB_SUFFIX})
mark_as_advanced(SOCI_LIBRARY)

find_library(
SOCI_postgresql_PLUGIN
NAMES soci_postgresql
HINTS ${SOCI_INCLUDE_DIR}/..
PATH_SUFFIXES lib${LIB_SUFFIX})
mark_as_advanced(SOCI_postgresql_PLUGIN)

get_filename_component(SOCI_LIBRARY_DIR ${SOCI_LIBRARY} PATH)
mark_as_advanced(SOCI_LIBRARY_DIR)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(soci DEFAULT_MSG ${_SOCI_REQUIRED_VARS})

set(URL https://github.com/SOCI/soci)
set(VERSION 111b50af8c3876ea392367640b4bd83b4f903ab8) # 3.2.3
set_target_description(soci "The C++ Database Access Library" ${URL} ${VERSION})

if (NOT soci_FOUND)
externalproject_add(soci_soci
GIT_REPOSITORY ${URL}
GIT_TAG ${VERSION}
CONFIGURE_COMMAND ${CMAKE_COMMAND}
-G${CMAKE_GENERATOR}
-H${EP_PREFIX}/src/soci_soci/src
-B${EP_PREFIX}/src/soci_soci-build
-DCMAKE_INCLUDE_PATH=${pq_INCLUDE_DIR}
-DCMAKE_LIBRARY_PATH=${pq_INCLUDE_DIR}
-DCMAKE_PROGRAM_PATH=${pg_config_EXECUTABLE_DIR}
-DCMAKE_CXX_FLAGS=-I${postgres_INCLUDE_DIR}
-DCMAKE_INSTALL_PREFIX=${EP_PREFIX}
-DWITH_BOOST=ON
-DWITH_DB2=OFF
-DWITH_FIREBIRD=OFF
-DWITH_MYSQL=OFF
-DWITH_ODBC=OFF
-DWITH_ORACLE=OFF
-DWITH_POSTGRESQL=ON
-DWITH_SQLITE3=OFF
BUILD_BYPRODUCTS ${EP_PREFIX}/src/soci_soci-build/lib/${CMAKE_STATIC_LIBRARY_PREFIX}soci_core${CMAKE_STATIC_LIBRARY_SUFFIX}
${EP_PREFIX}/src/soci_soci-build/lib/${CMAKE_STATIC_LIBRARY_PREFIX}soci_postgresql${CMAKE_STATIC_LIBRARY_SUFFIX}
TEST_COMMAND "" # remove test step
UPDATE_COMMAND "" # remove update step
)
externalproject_get_property(soci_soci binary_dir)
set(SOCI_INCLUDE_DIRS ${EP_PREFIX}/include ${EP_PREFIX}/include/soci)
set(SOCI_LIBRARY ${binary_dir}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}soci_core${CMAKE_STATIC_LIBRARY_SUFFIX})
set(SOCI_postgresql_PLUGIN ${binary_dir}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}soci_postgresql${CMAKE_STATIC_LIBRARY_SUFFIX})
file(MAKE_DIRECTORY ${EP_PREFIX}/include/soci)

add_dependencies(soci_soci pq)
add_dependencies(SOCI::core soci_soci)
add_dependencies(SOCI::postgresql soci_soci)
endif ()

set_target_properties(SOCI::core PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${SOCI_INCLUDE_DIRS}"
IMPORTED_LOCATION "${SOCI_LIBRARY}"
INTERFACE_LINK_LIBRARIES dl
)

set_target_properties(SOCI::postgresql PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${SOCI_INCLUDE_DIRS}"
IMPORTED_LOCATION "${SOCI_postgresql_PLUGIN}"
INTERFACE_LINK_LIBRARIES pq
)

if(ENABLE_LIBS_PACKAGING)
add_install_step_for_lib(${SOCI_LIBRARY})
add_install_step_for_lib(${SOCI_postgresql_PLUGIN})
endif()
6 changes: 3 additions & 3 deletions cmake/dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ find_package(rapidjson)
##########################
find_package(pq)

##########################a
# pqxx #
##########################
find_package(pqxx)
# SOCI #
##########################
find_package(soci)

################################
# gflags #
Expand Down
29 changes: 19 additions & 10 deletions docker/dependencies/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -187,18 +187,27 @@ RUN set -e; \
# remove
rm -rf /tmp/postgresql

# install pqxx
# install soci 3.2.3
RUN set -e; \
export PATH="/opt/dependencies/libpq/bin:$PATH"; \
git clone https://github.com/jtv/libpqxx /tmp/libpqxx; \
(cd /tmp/libpqxx ; git checkout 5b17abce5ac2b1a2f8278718405b7ade8bb30ae9); \
curl -L -o /tmp/libpqxx/config/config.guess 'http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=6b2374c79506ee82a8b440f6d1ca293e2e2e2463'; \
curl -L -o /tmp/libpqxx/config/config.sub 'http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub;hb=6b2374c79506ee82a8b440f6d1ca293e2e2e2463'; \
(cd /tmp/libpqxx ; /tmp/libpqxx/configure --disable-documentation --with-pic --prefix=/opt/dependencies/libpqxx); \
make -j${PARALLELISM} -C /tmp/libpqxx; \
make -C /tmp/libpqxx install; \
git clone https://github.com/SOCI/soci /tmp/soci; \
(cd /tmp/soci ; git checkout 111b50af8c3876ea392367640b4bd83b4f903ab8); \
cmake \
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} \
-DWITH_BOOST=ON \
-DWITH_DB2=OFF \
-DWITH_FIREBIRD=OFF \
-DWITH_MYSQL=OFF \
-DWITH_ODBC=OFF \
-DWITH_ORACLE=OFF \
-DWITH_POSTGRESQL=ON \
-DWITH_SQLITE3=OFF \
-H/tmp/soci/src \
-B/tmp/soci/build \
-DCMAKE_PREFIX_PATH="/opt/dependencies/libpq" \
-DCMAKE_INSTALL_PREFIX=/opt/dependencies/soci; \
cmake --build /tmp/soci/build --target install; \
ldconfig; \
rm -rf /tmp/libpqxx
rm -rf /tmp/soci

# install tbb
RUN set -e; \
Expand Down
26 changes: 17 additions & 9 deletions docker/develop/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -177,17 +177,25 @@ RUN set -e; \
# remove
rm -rf /tmp/postgresql

# install pqxx
# install soci 3.2.3
RUN set -e; \
git clone https://github.com/jtv/libpqxx /tmp/libpqxx; \
(cd /tmp/libpqxx ; git checkout 5b17abce5ac2b1a2f8278718405b7ade8bb30ae9); \
curl -L -o /tmp/libpqxx/config/config.guess 'http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=6b2374c79506ee82a8b440f6d1ca293e2e2e2463'; \
curl -L -o /tmp/libpqxx/config/config.sub 'http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub;hb=6b2374c79506ee82a8b440f6d1ca293e2e2e2463'; \
(cd /tmp/libpqxx ; /tmp/libpqxx/configure --disable-documentation --with-pic); \
make -j${PARALLELISM} -C /tmp/libpqxx; \
make -C /tmp/libpqxx install; \
git clone https://github.com/SOCI/soci /tmp/soci; \
(cd /tmp/soci ; git checkout 111b50af8c3876ea392367640b4bd83b4f903ab8); \
cmake \
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} \
-DWITH_BOOST=ON \
-DWITH_DB2=OFF \
-DWITH_FIREBIRD=OFF \
-DWITH_MYSQL=OFF \
-DWITH_ODBC=OFF \
-DWITH_ORACLE=OFF \
-DWITH_POSTGRESQL=ON \
-DWITH_SQLITE3=OFF \
-H/tmp/soci/src \
-B/tmp/soci/build; \
cmake --build /tmp/soci/build --target install; \
ldconfig; \
rm -rf /tmp/libpqxx
rm -rf /tmp/soci

# install tbb
RUN set -e; \
Expand Down
2 changes: 1 addition & 1 deletion docs/source/guides/build.rst
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ to install all dependencies with Homebrew.
.. code-block:: shell
xcode-select --install
brew install cmake boost postgres grpc autoconf automake libtool golang libpqxx
brew install cmake boost postgres grpc autoconf automake libtool golang soci
.. hint:: To install the Homebrew itself please run

Expand Down
3 changes: 2 additions & 1 deletion irohad/ametsuchi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ add_library(ametsuchi
target_link_libraries(ametsuchi
logger
rxcpp
pqxx
libs_common
command_execution
query_execution
shared_model_interfaces
shared_model_proto_backend
shared_model_stateless_validation
SOCI::core
SOCI::postgresql
)
27 changes: 11 additions & 16 deletions irohad/ametsuchi/impl/mutable_storage_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,16 @@ namespace iroha {
namespace ametsuchi {
MutableStorageImpl::MutableStorageImpl(
shared_model::interface::types::HashType top_hash,
std::unique_ptr<pqxx::lazyconnection> connection,
std::unique_ptr<pqxx::nontransaction> transaction)
std::unique_ptr<soci::session> sql)
: top_hash_(top_hash),
connection_(std::move(connection)),
transaction_(std::move(transaction)),
wsv_(std::make_unique<PostgresWsvQuery>(*transaction_)),
executor_(std::make_unique<PostgresWsvCommand>(*transaction_)),
block_index_(std::make_unique<PostgresBlockIndex>(*transaction_)),
sql_(std::move(sql)),
wsv_(std::make_shared<PostgresWsvQuery>(*sql_)),
executor_(std::make_shared<PostgresWsvCommand>(*sql_)),
block_index_(std::make_unique<PostgresBlockIndex>(*sql_)),
command_executor_(std::make_shared<CommandExecutor>(wsv_, executor_)),
committed(false),
log_(logger::log("MutableStorage")) {
auto query = std::make_shared<PostgresWsvQuery>(*transaction_);
auto command = std::make_shared<PostgresWsvCommand>(*transaction_);
command_executor_ =
std::make_shared<CommandExecutor>(CommandExecutor(query, command));
transaction_->exec("BEGIN;");
*sql_ << "BEGIN";
}

bool MutableStorageImpl::apply(
Expand All @@ -67,7 +62,7 @@ namespace iroha {
execute_command);
};

transaction_->exec("SAVEPOINT savepoint_;");
*sql_ << "SAVEPOINT savepoint_";
auto result = function(block, *wsv_, top_hash_)
and std::all_of(block.transactions().begin(),
block.transactions().end(),
Expand All @@ -78,16 +73,16 @@ namespace iroha {
block_index_->index(block);

top_hash_ = block.hash();
transaction_->exec("RELEASE SAVEPOINT savepoint_;");
*sql_ << "RELEASE SAVEPOINT savepoint_";
} else {
transaction_->exec("ROLLBACK TO SAVEPOINT savepoint_;");
*sql_ << "ROLLBACK TO SAVEPOINT savepoint_";
}
return result;
}

MutableStorageImpl::~MutableStorageImpl() {
if (not committed) {
transaction_->exec("ROLLBACK;");
*sql_ << "ROLLBACK";
}
}
} // namespace ametsuchi
Expand Down
16 changes: 6 additions & 10 deletions irohad/ametsuchi/impl/mutable_storage_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@
#ifndef IROHA_MUTABLE_STORAGE_IMPL_HPP
#define IROHA_MUTABLE_STORAGE_IMPL_HPP

#include <soci/soci.h>
#include <map>
#include <pqxx/connection>
#include <pqxx/nontransaction>

#include "ametsuchi/mutable_storage.hpp"
#include "execution/command_executor.hpp"
Expand All @@ -37,10 +36,8 @@ namespace iroha {
friend class StorageImpl;

public:
MutableStorageImpl(
shared_model::interface::types::HashType top_hash,
std::unique_ptr<pqxx::lazyconnection> connection,
std::unique_ptr<pqxx::nontransaction> transaction);
MutableStorageImpl(shared_model::interface::types::HashType top_hash,
std::unique_ptr<soci::session> sql);

bool apply(
const shared_model::interface::Block &block,
Expand All @@ -58,10 +55,9 @@ namespace iroha {
std::map<uint32_t, std::shared_ptr<shared_model::interface::Block>>
block_store_;

std::unique_ptr<pqxx::lazyconnection> connection_;
std::unique_ptr<pqxx::nontransaction> transaction_;
std::unique_ptr<WsvQuery> wsv_;
std::unique_ptr<WsvCommand> executor_;
std::unique_ptr<soci::session> sql_;
std::shared_ptr<WsvQuery> wsv_;
std::shared_ptr<WsvCommand> executor_;
std::unique_ptr<BlockIndex> block_index_;
std::shared_ptr<CommandExecutor> command_executor_;

Expand Down
Loading

0 comments on commit 9d12009

Please sign in to comment.