Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor StorageImpl #123

Merged

Conversation

luckychess
Copy link
Contributor

Description of the Change

StorageImpl refactoring:

  • PoolWrapper is passed as an external dependency
  • Postgres initialization code is moved into PgConnectionInit class
  • Corresponding fixes in Application and tests

Benefits

Connections could be created outside the storage now which is very convenient for testing and (coming) PostgresBlockStorage.

Possible Drawbacks

Pull request is huge :(

- PoolWrapper is passed as an external dependency
- Postgres initialization code is moved into PgConnectionInit class
- Corresponding fixes in Application and tests

Signed-off-by: Konstantin Munichev <toobwn@gmail.com>
Copy link
Contributor

@MBoldyrev MBoldyrev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some points in my comments may be discussed, so I neither approve, nor demand changes.


FailoverCallback::FailoverCallback(
soci::session &connection,
std::function<void(soci::session &)> init,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why have you removed the original using InitFunctionType?


namespace iroha {
namespace ametsuchi {
class FailoverCallbackFactory {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the factory name is quite misleading. Factories tend to facilitate objects creation, while this one just passes all the arguments to the object's constructor.
What this class does is lifetime management.
Thus i would suggest renaming this class to something like FailoverCallbacksManager.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for renaming it into FailoverCallbackHolder, I like your variant better than my ...Manager. There are some more substitutions to be made though:

https://github.com/hyperledger/iroha/blob/d01018a6c1373ee3fca8cf95975a063eda0a3904/irohad/main/impl/pg_connection_init.cpp#L74


#include <memory>

#include <soci/soci.h>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this include be avoided using a forward declaration, like you did for FailoverCallbackFactory?

log_manager_(std::move(log_manager)),
log_(log_manager_->getLogger()),
pool_size_(pool_size),
prepared_blocks_enabled_(enable_prepared_blocks),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the enable_prepared_blocks constructor argument seems duplicating a field of pool_wrapper:

Suggested change
prepared_blocks_enabled_(enable_prepared_blocks),
prepared_blocks_enabled_(pool_wrapper_->enable_prepared_transactions_),


void StorageImpl::tryRollback(soci::session &session) {
if (block_is_prepared_) {
PgConnectionInit::rollbackPrepared(session, prepared_block_name_)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks weird...
do you have a TODO to separate schema manager from connection initializer?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope. Do we already have a task for it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am strongly for creating one. Schema management should be separated from connection initialization and generic storage impl.

@@ -0,0 +1,11 @@
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What did you add this file for?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't. This is pretty annoying, some test modifies this file. I will fix it one day.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, it wasn't in .gitignore for some reason so easy fix is coming.

}

inline void processPqNotice(void *arg, const char *message) {
auto *log = reinterpret_cast<logger::Logger *>(arg);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you use logger::Logger, you should include logger/logger.hpp.
But I would suggest to move this to cpp file and to ensure that it has this include, because otherwise the CMake logger target dependency must be manually added to every file using this header.
If you choose to follow my advise, please include #include "logger/logger_fwd.hpp" to this file.

target_link_libraries(pg_connection_init
SOCI::postgresql
SOCI::core
fmt
Copy link
Contributor

@MBoldyrev MBoldyrev Jun 17, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fmt
logger

The real dependency is logger, and the fact that it compiles without it is a lucky chance.

irohad/main/impl/pg_connection_init.cpp Show resolved Hide resolved
#include "ametsuchi/reconnection_strategy.hpp"
#include "common/result.hpp"
#include "interfaces/permissions.hpp"
#include "logger/logger_manager.hpp"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#include "logger/logger_manager.hpp"
#include "logger/logger_manager_fwd.hpp"

- Fixes in naming
- Log dependencies
- Couple of other small fixes

Signed-off-by: Konstantin Munichev <toobwn@gmail.com>
Signed-off-by: Konstantin Munichev <toobwn@gmail.com>
Signed-off-by: Konstantin Munichev <toobwn@gmail.com>
Signed-off-by: Konstantin Munichev <toobwn@gmail.com>
.gitignore Outdated
@@ -31,8 +31,8 @@ include/generated/*
iroha.conf
peers.list
cmake-build*
test/system/irohad_test_data/config.sample.copy
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is in the repo and hence is versioned with other source. I think for your purposes you should use .git/info/exclude, which is your private and does not synchronize.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ssssssssssss! I had to check this.
But anyway, it looks like a bad test design.

Signed-off-by: Andrei Lebedev <lebdron@gmail.com>
Copy link
Contributor

@lebdron lebdron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great overall, thank you! However, some issues have to be addressed before the merge.

@@ -175,13 +177,17 @@ void Irohad::dropStorage() {
storage->reset();
}

// Irohad::RunResult Irohad::initPoolWrapper() {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove commented-out code.

@@ -152,6 +154,8 @@ class Irohad {
protected:
// -----------------------| component initialization |------------------------

// virtual RunResult initPoolWrapper();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for commented-out code.

@@ -45,6 +47,8 @@ class StorageInitTest : public ::testing::Test {
std::string pg_opt_without_dbname_;
std::string pgopt_;

// std::shared_ptr<iroha::ametsuchi::PoolWrapper> pool_wrapper_;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for commented-out code.

#include <soci/postgresql/soci-postgresql.h>

#include "ametsuchi/reconnection_strategy.hpp"
#include "failover_callback.hpp"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like self-include, please remove.

irohad/ametsuchi/impl/failover_callback.hpp Show resolved Hide resolved
namespace ametsuchi {
class PgConnectionInit {
public:
static std::string formatPostgresMessage(const char *message);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems to be used only in pg_connection_init.cpp, maybe move it there in an anonymous namespace? Same for processPqNotice

ReconnectionStrategyFactory &reconnection_strategy_factory,
const PostgresOptions &options,
logger::LoggerManagerTreePtr log_manager) {
const int pool_size = 10;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest to make it a parameter as it was before, and define this variable in Irohad::initStorage


auto conn = initPostgresConnection(options_str, pool_size);
if (auto e = boost::get<expected::Error<std::string>>(&conn)) {
return expected::makeError(std::move(e->error));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return expected::makeError(std::move(e->error));
return *e;

@@ -25,6 +25,8 @@ namespace iroha {
class WsvRestorer;
class TxPresenceCache;
class Storage;
class ReconnectionStrategyFactory;
struct PoolWrapper;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably can be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ReconnectionStrategyFactory still has to stay.

@@ -50,13 +51,42 @@ namespace iroha {
std::make_unique<InMemoryBlockStorageFactory>();
auto reconnection_strategy_factory = std::make_unique<
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this variable be made fixture static field? Otherwise its lifetime is not managed.

Signed-off-by: Konstantin Munichev <toobwn@gmail.com>
Signed-off-by: Konstantin Munichev <toobwn@gmail.com>
Copy link
Contributor

@lebdron lebdron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

Signed-off-by: Andrei Lebedev <lebdron@gmail.com>
@luckychess luckychess merged commit 5430063 into hyperledger-iroha:master Jun 19, 2019
@luckychess luckychess deleted the feature/storage-refactor branch June 19, 2019 20:36
DCNick3 added a commit to DCNick3/iroha that referenced this pull request Jul 20, 2023
…ncremental updates to our proc macros

Signed-off-by: Nikita Strygin <DCNick3@users.noreply.github.com>
appetrosyan pushed a commit to DCNick3/iroha that referenced this pull request Jul 24, 2023
…ncremental updates to our proc macros

Signed-off-by: Nikita Strygin <DCNick3@users.noreply.github.com>
nvzhu pushed a commit to soramitsu/soramitsu-iroha that referenced this pull request Jan 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants