Skip to content

Commit

Permalink
[RDB] block indexer
Browse files Browse the repository at this point in the history
Signed-off-by: iceseer <[email protected]>
  • Loading branch information
iceseer committed May 30, 2021
1 parent b3b4774 commit 8a843bf
Show file tree
Hide file tree
Showing 17 changed files with 552 additions and 53 deletions.
22 changes: 18 additions & 4 deletions irohad/ametsuchi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -116,19 +116,33 @@ add_library(ametsuchi
impl/in_memory_block_storage_factory.cpp
)

add_library(postgres_indexer
impl/postgres_indexer.cpp
impl/postgres_block_index.cpp
add_library(block_indexer
impl/block_index_impl.cpp
)
target_link_libraries(postgres_indexer
target_link_libraries(block_indexer
common
logger
shared_model_interfaces
shared_model_cryptography
)

add_library(postgres_indexer
impl/postgres_indexer.cpp
)
target_link_libraries(postgres_indexer
block_indexer
SOCI::postgresql
SOCI::core
)

add_library(rocksdb_indexer
impl/rocksdb_indexer.cpp
)
target_link_libraries(rocksdb_indexer
block_indexer
RocksDB::rocksdb
)

target_compile_definitions(postgres_indexer
PRIVATE SOCI_USE_BOOST HAVE_BOOST
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

#include "ametsuchi/impl/postgres_block_index.hpp"
#include "ametsuchi/impl/block_index_impl.hpp"

#include <boost/range/adaptor/filtered.hpp>
#include <boost/range/adaptor/indexed.hpp>
Expand Down Expand Up @@ -38,7 +38,7 @@ namespace {
// Collect all assets belonging to creator, sender, and receiver
// to make account_id:height:asset_id -> list of tx indexes
// for transfer asset in command
void PostgresBlockIndex::makeAccountAssetIndex(
void BlockIndexImpl::makeAccountAssetIndex(
const AccountIdType &account_id,
shared_model::interface::types::HashType const &hash,
shared_model::interface::types::TimestampType const ts,
Expand Down Expand Up @@ -67,11 +67,11 @@ void PostgresBlockIndex::makeAccountAssetIndex(
}
}

PostgresBlockIndex::PostgresBlockIndex(std::unique_ptr<Indexer> indexer,
logger::LoggerPtr log)
BlockIndexImpl::BlockIndexImpl(std::unique_ptr<Indexer> indexer,
logger::LoggerPtr log)
: indexer_(std::move(indexer)), log_(std::move(log)) {}

void PostgresBlockIndex::index(const shared_model::interface::Block &block) {
void BlockIndexImpl::index(const shared_model::interface::Block &block) {
auto height = block.height();
for (auto tx : block.transactions() | boost::adaptors::indexed(0)) {
const auto &creator_id = tx.value().creatorAccountId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@ namespace iroha {
* 2. account -> block for source and destination accounts
* 3. (account, height) -> list of txes
*/
class PostgresBlockIndex : public BlockIndex {
class BlockIndexImpl : public BlockIndex {
public:
PostgresBlockIndex(std::unique_ptr<Indexer> indexer,
logger::LoggerPtr log);
BlockIndexImpl(std::unique_ptr<Indexer> indexer, logger::LoggerPtr log);

/// Index a block.
void index(const shared_model::interface::Block &block) override;
Expand Down
4 changes: 2 additions & 2 deletions irohad/ametsuchi/impl/executor_common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ namespace iroha::ametsuchi {
std::string_view delims);

template <size_t C>
std::array<std::string_view, C> staticSplitId(std::string_view const str) {
std::string_view const delims = "@#";
std::array<std::string_view, C> staticSplitId(
std::string_view const str, std::string_view const delims = "@#") {
std::array<std::string_view, C> output;

auto it_first = str.data();
Expand Down
6 changes: 3 additions & 3 deletions irohad/ametsuchi/impl/mutable_storage_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
#include <boost/variant/apply_visitor.hpp>
#include <stdexcept>
#include "ametsuchi/command_executor.hpp"
#include "ametsuchi/impl/block_index_impl.hpp"
#include "ametsuchi/impl/peer_query_wsv.hpp"
#include "ametsuchi/impl/postgres_block_index.hpp"
#include "ametsuchi/impl/postgres_command_executor.hpp"
#include "ametsuchi/impl/postgres_indexer.hpp"
#include "ametsuchi/impl/postgres_wsv_command.hpp"
Expand All @@ -35,9 +35,9 @@ namespace iroha {
peer_query_(
std::make_unique<PeerQueryWsv>(std::make_shared<PostgresWsvQuery>(
sql_, log_manager->getChild("WsvQuery")->getLogger()))),
block_index_(std::make_unique<PostgresBlockIndex>(
block_index_(std::make_unique<BlockIndexImpl>(
std::make_unique<PostgresIndexer>(sql_),
log_manager->getChild("PostgresBlockIndex")->getLogger())),
log_manager->getChild("BlockIndexImpl")->getLogger())),
transaction_executor_(std::make_unique<TransactionExecutor>(
std::move(command_executor))),
block_storage_(std::move(block_storage)),
Expand Down
Loading

0 comments on commit 8a843bf

Please sign in to comment.