hyperledger/iroha
Iroha - A simple, decentralized ledger http://iroha.tech
pg_connection_init.hpp
Go to the documentation of this file.
1 
6 #ifndef IROHA_PG_CONNECTION_INIT_HPP
7 #define IROHA_PG_CONNECTION_INIT_HPP
8 
9 #include <soci/soci.h>
10 
11 #include <soci/callbacks.h>
12 #include <soci/postgresql/soci-postgresql.h>
13 #include <boost/algorithm/string.hpp>
14 #include <boost/range/algorithm/replace_if.hpp>
15 
21 #include "common/result.hpp"
23 #include "logger/logger_fwd.hpp"
25 
26 namespace iroha {
27  namespace ametsuchi {
29  public:
30  static expected::Result<std::shared_ptr<soci::connection_pool>,
31  std::string>
32  initPostgresConnection(std::string &options_str, size_t pool_size);
33 
34  static expected::Result<PoolWrapper, std::string> prepareConnectionPool(
35  const ReconnectionStrategyFactory &reconnection_strategy_factory,
36  const PostgresOptions &options,
37  const int pool_size,
38  logger::LoggerManagerTreePtr log_manager);
39 
43  static bool preparedTransactionsAvailable(soci::session &sql);
44 
45  static iroha::expected::Result<void, std::string> rollbackPrepared(
46  soci::session &sql, const std::string &prepared_block_name);
47 
48  static expected::Result<bool, std::string> createDatabaseIfNotExist(
49  const PostgresOptions &pg_opt);
50 
51  /*
52  * Remove all records from the tables
53  * @return error message if reset has failed
54  */
55  static expected::Result<void, std::string> resetWsv(soci::session &sql);
56 
61  static expected::Result<void, std::string> resetPeers(soci::session &sql);
62 
63  private:
79  template <typename RollbackFunction>
80  static void initializeConnectionPool(
81  soci::connection_pool &connection_pool,
82  size_t pool_size,
83  const std::string &prepare_tables_sql,
84  RollbackFunction try_rollback,
85  FailoverCallbackHolder &callback_factory,
86  const ReconnectionStrategyFactory &reconnection_strategy_factory,
87  const std::string &pg_reconnection_options,
88  logger::LoggerManagerTreePtr log_manager);
89 
90  public:
91  static const std::string init_;
92  };
93  } // namespace ametsuchi
94 } // namespace iroha
95 
96 #endif // IROHA_PG_CONNECTION_INIT_HPP
Definition: postgres_options.hpp:19
static bool preparedTransactionsAvailable(soci::session &sql)
Definition: pg_connection_init.cpp:95
Definition: reconnection_strategy.hpp:35
Definition: pg_connection_init.hpp:28
Definition: failover_callback_holder.hpp:13
static expected::Result< void, std::string > resetWsv(soci::session &sql)
Definition: pg_connection_init.cpp:298
static expected::Result< PoolWrapper, std::string > prepareConnectionPool(const ReconnectionStrategyFactory &reconnection_strategy_factory, const PostgresOptions &options, const int pool_size, logger::LoggerManagerTreePtr log_manager)
Definition: pg_connection_init.cpp:43
static const std::string init_
Definition: pg_connection_init.hpp:91
Definition: block_query.hpp:14
std::shared_ptr< LoggerManagerTree > LoggerManagerTreePtr
Definition: logger_manager_fwd.hpp:14
static expected::Result< std::shared_ptr< soci::connection_pool >, std::string > initPostgresConnection(std::string &options_str, size_t pool_size)
Definition: pg_connection_init.cpp:27
static iroha::expected::Result< void, std::string > rollbackPrepared(soci::session &sql, const std::string &prepared_block_name)
Definition: pg_connection_init.cpp:105
static expected::Result< bool, std::string > createDatabaseIfNotExist(const PostgresOptions &pg_opt)
Definition: pg_connection_init.cpp:116
static expected::Result< void, std::string > resetPeers(soci::session &sql)
Definition: pg_connection_init.cpp:327