Skip to content

Commit

Permalink
Add logging for:
Browse files Browse the repository at this point in the history
 - application
 - irohad
 - storage
  • Loading branch information
muratovv committed Aug 6, 2017
1 parent 05bcf5d commit 63245b3
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 17 deletions.
1 change: 1 addition & 0 deletions irohad/ametsuchi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ add_library(ametsuchi
)

target_link_libraries(ametsuchi
logger
rxcpp
optional
pqxx
Expand Down
31 changes: 21 additions & 10 deletions irohad/ametsuchi/impl/storage_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ namespace iroha {
wsv_connection_(std::move(wsv_connection)),
wsv_transaction_(std::move(wsv_transaction)),
wsv_(std::move(wsv)) {
log_ = logger::log("StorageImpl");

wsv_transaction_->exec(init_);
wsv_transaction_->exec(
"SET SESSION CHARACTERISTICS AS TRANSACTION READ ONLY;");
Expand All @@ -54,7 +56,7 @@ namespace iroha {
try {
postgres_connection->activate();
} catch (const pqxx::broken_connection &e) {
// TODO log error
log_->error("Connection to postre broken: {}", e.what());
return nullptr;
}
auto wsv_transaction = std::make_unique<pqxx::nontransaction>(
Expand All @@ -77,7 +79,7 @@ namespace iroha {
try {
postgres_connection->activate();
} catch (const pqxx::broken_connection &e) {
// TODO log error
log_->error("Connection to postre broken: {}", e.what());
return nullptr;
}
auto wsv_transaction = std::make_unique<pqxx::nontransaction>(
Expand All @@ -91,7 +93,7 @@ namespace iroha {
try {
index->connect(redis_host_, redis_port_);
} catch (const cpp_redis::redis_error &e) {
// TODO log error
log_->error("Connection to redis broken: {}", e.what());
return nullptr;
}

Expand All @@ -100,12 +102,12 @@ namespace iroha {
if (block_store_->last_id()) {
auto blob = block_store_->get(block_store_->last_id());
if (!blob) {
// TODO log block not found error
log_->error("Fetching of blob failed");
return nullptr;
}
auto block = serializer_.deserialize(*blob);
if (!block) {
// TODO log deserialize error
log_->error("Deserialization of block failed");
return nullptr;
}
top_hash = block->hash;
Expand All @@ -121,34 +123,43 @@ namespace iroha {
std::shared_ptr<StorageImpl> StorageImpl::create(
std::string block_store_dir, std::string redis_host,
std::size_t redis_port, std::string postgres_options) {
auto log_ = logger::log("StorageImpl:create");
log_->info("Start storage creation");
// TODO lock

auto block_store = FlatFile::create(block_store_dir);
if (!block_store) {
// TODO log error
log_->error("Cannot create block store in {}", block_store_dir);
return nullptr;
}
log_->info("block store created");

auto index = std::make_unique<cpp_redis::redis_client>();
try {
index->connect(redis_host, redis_port);
} catch (const cpp_redis::redis_error &e) {
// TODO log error
log_->error("Connection {}:{} with redis broken",
redis_host,
redis_port);
return nullptr;
}
log_->info("connection to redis completed");

auto postgres_connection =
std::make_unique<pqxx::lazyconnection>(postgres_options);
try {
postgres_connection->activate();
} catch (const pqxx::broken_connection &e) {
// TODO log error
log_->error("Cannot with postgre broken: {}", e.what());
return nullptr;
}
log_->info("connection to postgre completed");

auto wsv_transaction = std::make_unique<pqxx::nontransaction>(
*postgres_connection, "Storage");
std::unique_ptr<WsvQuery> wsv =
std::make_unique<PostgresWsvQuery>(*wsv_transaction);
log_->info("transaction to postgre initialized");

return std::shared_ptr<StorageImpl>(
new StorageImpl(block_store_dir, redis_host, redis_port,
Expand Down Expand Up @@ -193,7 +204,7 @@ namespace iroha {
.flat_map([this](auto i) {
auto bytes = block_store_->get(i);
return rxcpp::observable<>::create<typename decltype(
bytes)::value_type>([bytes](auto s) {
bytes)::value_type>([bytes](auto s) {
if (bytes) {
s.on_next(*bytes);
}
Expand All @@ -203,7 +214,7 @@ namespace iroha {
.flat_map([this](auto bytes) {
auto block = serializer_.deserialize(bytes);
return rxcpp::observable<>::create<typename decltype(
block)::value_type>([block](auto s) {
block)::value_type>([block](auto s) {
if (block.has_value()) {
s.on_next(*block);
}
Expand Down
3 changes: 3 additions & 0 deletions irohad/ametsuchi/impl/storage_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "ametsuchi/block_serializer.hpp"
#include "ametsuchi/impl/flat_file/flat_file.hpp"
#include "ametsuchi/storage.hpp"
#include "logger/logger.hpp"

namespace iroha {
namespace ametsuchi {
Expand Down Expand Up @@ -79,6 +80,8 @@ namespace iroha {
// Allows multiple readers and a single writer
std::shared_timed_mutex rw_lock_;

decltype(logger::log("")) log_;

const std::string init_ =
"CREATE TABLE IF NOT EXISTS domain (\n"
" domain_id character varying(164),\n"
Expand Down
1 change: 1 addition & 0 deletions irohad/main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ add_library(application
impl/consensus_init.cpp
)
target_link_libraries(application
logger
gtest
gmock
yac
Expand Down
21 changes: 16 additions & 5 deletions irohad/main/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ Irohad::Irohad(const std::string &block_store_dir,
torii_port_(torii_port),
storage(StorageImpl::create(block_store_dir, redis_host, redis_port,
pg_conn)),
peer_number_(peer_number) {}
peer_number_(peer_number) {
log_ = logger::log("IROHAD");
log_->info("created");
}

Irohad::~Irohad() {
internal_server->Shutdown();
Expand Down Expand Up @@ -88,6 +91,7 @@ void Irohad::run() {
auto pb_tx_factory = std::make_shared<PbTransactionFactory>();
auto pb_query_factory = std::make_shared<PbQueryFactory>();
auto pb_query_response_factory = std::make_shared<PbQueryResponseFactory>();
log_->info("[Init] => converters");

// Crypto Provider:
auto crypto_verifier = std::make_shared<MockCryptoProvider>();
Expand All @@ -99,22 +103,28 @@ void Irohad::run() {
.WillRepeatedly(::testing::Return(true));
EXPECT_CALL(*crypto_verifier, verify(::testing::A<const Block &>()))
.WillRepeatedly(::testing::Return(true));
log_->info("[Init] => crypto provider");

// Hash provider
auto hash_provider = std::make_shared<HashProviderImpl>();
log_->info("[Init] => hash provider");

// Validators:
auto stateless_validator = createStatelessValidator(crypto_verifier);
auto stateful_validator = std::make_shared<StatefulValidatorImpl>();
auto chain_validator = std::make_shared<ChainValidatorImpl>(crypto_verifier);
log_->info("[Init] => validators");

auto orderer = std::make_shared<PeerOrdererImpl>(storage);
log_->info("[Init] => peer orderer");

auto wsv = std::make_shared<ametsuchi::PeerQueryWsv>(storage);
auto peer_address = wsv->getLedgerPeers().value().at(peer_number_).address;

// Ordering gate
auto ordering_gate = ordering_init.initOrderingGate(wsv, loop, 10, 5000);
log_->info("[Init] => init ordering gate - [{}]",
logger::logBool(ordering_gate));

// Simulator
auto simulator = createSimulator(ordering_gate, stateful_validator, storage,
Expand All @@ -136,12 +146,12 @@ void Irohad::run() {
// PeerCommunicationService
auto pcs = createPeerCommunicationService(ordering_gate, synchronizer);

pcs->on_proposal().subscribe([](auto) {
// TODO log proposals
pcs->on_proposal().subscribe([this](auto) {
log_->info("~~~~~~~~~| PROPOSAL ^_^ |~~~~~~~~~ ");
});

pcs->on_commit().subscribe([](auto) {
// TODO log commits
pcs->on_commit().subscribe([this](auto) {
log_->info("~~~~~~~~~| COMMIT =^._.^= |~~~~~~~~~ ");
});

// Torii:
Expand Down Expand Up @@ -172,6 +182,7 @@ void Irohad::run() {
server_thread = std::thread([this] {
torii_server->run(std::move(command_service), std::move(query_service));
});
log_->info("===> iroha initialized");
torii_server->waitForServersReady();
loop->run();
}
Expand Down
8 changes: 8 additions & 0 deletions irohad/main/application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
#include "main/impl/ordering_init.hpp"
#include "main/impl/consensus_init.hpp"

#include "logger/logger.hpp"

class Irohad {
public:

Expand Down Expand Up @@ -129,6 +131,12 @@ class Irohad {

std::thread internal_thread, server_thread;

// todo verify is those decltype correct
std::shared_ptr<spdlog::logger> log_;




public:
std::shared_ptr<iroha::ametsuchi::StorageImpl> storage;
uint64_t peer_number_;
Expand Down
12 changes: 10 additions & 2 deletions irohad/main/irohad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ limitations under the License.

#include <gflags/gflags.h>
#include <grpc++/grpc++.h>
#include <rapidjson/rapidjson.h>
#include <fstream>
#include <thread>
#include "common/config.hpp"
#include "main/application.hpp"
#include "main/genesis_block_server/genesis_block_processor.hpp"
#include "main/iroha_conf_loader.hpp"
#include "main/raw_block_insertion.hpp"

#include "logger/logger.hpp"

bool validate_config(const char *flag_name, std::string const &path) {
return not path.empty();
}
Expand All @@ -42,27 +42,35 @@ DEFINE_validator(genesis_block, &validate_genesis_path);
DEFINE_uint64(peer_number, 0, "Specify peer number");

int main(int argc, char *argv[]) {
auto log = logger::log("MAIN");
log->info("start");
namespace mbr = config_members;

gflags::ParseCommandLineFlags(&argc, &argv, true);
gflags::ShutDownCommandLineFlags();

auto config = parse_iroha_config(FLAGS_config);
log->info("config initialized");
Irohad irohad(config[mbr::BlockStorePath].GetString(),
config[mbr::RedisHost].GetString(),
config[mbr::RedisPort].GetUint(),
config[mbr::PgOpt].GetString(),
config[mbr::ToriiPort].GetUint(), FLAGS_peer_number);
log->info("storage initialized: {}", logger::logBool(irohad.storage));

iroha::main::BlockInserter inserter(irohad.storage);
auto file = inserter.loadFile(FLAGS_genesis_block);
auto block = inserter.parseBlock(file.value());
log->info("Parsed block");

if (block.has_value()) {
inserter.applyToLedger({block.value()});
log->info("Genesis block inserted, number of transactions: {}",
block.value().transactions.size());
}

// runs iroha
log->info("runs iroha");
irohad.run();

return 0;
Expand Down

0 comments on commit 63245b3

Please sign in to comment.