Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Commit

Permalink
Add ability to build without mongodb #172
Browse files Browse the repository at this point in the history
  • Loading branch information
heifner committed Nov 2, 2017
1 parent 3962475 commit 72cecfc
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 21 deletions.
42 changes: 22 additions & 20 deletions plugins/db_plugin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,38 @@ add_library( db_plugin
db_plugin.cpp
${HEADERS} )

find_package(libmongoc-1.0 1.8 REQUIRED)
find_package(libmongoc-1.0 1.8)

message ("-- mongoc found version \"${MONGOC_VERSION}\"")
message ("-- mongoc include path \"${MONGOC_INCLUDE_DIRS}\"")
message ("-- mongoc libraries \"${MONGOC_LIBRARIES}\"")
if (libmongoc-1.0_FOUND)

find_package(PkgConfig QUIET)
message("-- mongoc found version \"${MONGOC_VERSION}\"")
message("-- mongoc include path \"${MONGOC_INCLUDE_DIRS}\"")
message("-- mongoc libraries \"${MONGOC_LIBRARIES}\"")

# NOTE: For this to work, the PKG_CONFIG_PATH variable (man pkg-config) must be set to point to the
# 'lib/pkgconfig' subdirectory of the directory used as the argument to CMAKE_INSTALL_PREFIX when
# building libmongocxx and libbsoncxx.
pkg_search_module(BSONCXX REQUIRED libbsoncxx)
pkg_search_module(MONGOCXX REQUIRED libmongocxx)
find_package(PkgConfig QUIET)

link_directories(
${MONGOCXX_LIBRARY_DIRS}
${BSONCXX_LIBRARY_DIRS}
)
# NOTE: For this to work, the PKG_CONFIG_PATH variable (man pkg-config) must be set to point to the
# 'lib/pkgconfig' subdirectory of the directory used as the argument to CMAKE_INSTALL_PREFIX when
# building libmongocxx and libbsoncxx.
pkg_search_module(BSONCXX REQUIRED libbsoncxx)
pkg_search_module(MONGOCXX REQUIRED libmongocxx)

link_directories(
${MONGOCXX_LIBRARY_DIRS}
${BSONCXX_LIBRARY_DIRS}
)
add_definitions(-DMONGODB)
endif()

target_include_directories( db_plugin
target_include_directories(db_plugin
PRIVATE ${MONGOCXX_INCLUDE_DIRS}
PRIVATE ${BSONCXX_INCLUDE_DIRS}
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include"
)
target_link_libraries( db_plugin
)
target_link_libraries(db_plugin
PUBLIC chain_plugin eos_chain appbase
PRIVATE ${MONGOCXX_LIBRARIES} ${BSONCXX_LIBRARIES}
)


)

install( TARGETS
db_plugin
Expand Down
22 changes: 21 additions & 1 deletion plugins/db_plugin/db_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@
#include <boost/thread/thread.hpp>
#include <boost/lockfree/spsc_queue.hpp>

#ifdef MONGODB
#include <bsoncxx/builder/basic/kvp.hpp>
#include <bsoncxx/builder/basic/document.hpp>
#include <bsoncxx/builder/stream/document.hpp>
#include <bsoncxx/json.hpp>

#include <mongocxx/client.hpp>
#include <mongocxx/instance.hpp>
#endif

namespace fc { class variant; }

Expand All @@ -31,6 +33,14 @@ using chain::ProcessedTransaction;
using chain::signed_block;
using chain::transaction_id_type;

#ifndef MONGODB
class db_plugin_impl {
public:
db_plugin_impl() {}
};
#endif

#ifdef MONGODB
class db_plugin_impl {
public:
db_plugin_impl();
Expand Down Expand Up @@ -523,6 +533,7 @@ void db_plugin_impl::init() {
}
}

#endif /* MONGODB */
////////////
// db_plugin
////////////
Expand All @@ -538,6 +549,7 @@ db_plugin::~db_plugin()

void db_plugin::set_program_options(options_description& cli, options_description& cfg)
{
#ifdef MONGODB
cfg.add_options()
("filter-on-accounts,f", bpo::value<std::vector<std::string>>()->composing(),
"Track only transactions whose scopes involve the listed accounts. Default is to track all transactions.")
Expand All @@ -546,23 +558,29 @@ void db_plugin::set_program_options(options_description& cli, options_descriptio
("mongodb-uri,m", bpo::value<std::string>()->default_value("mongodb://localhost:27017"),
"MongoDB URI connection string, see: https://docs.mongodb.com/master/reference/connection-string/")
;
#endif
}

void db_plugin::wipe_database() {
#ifdef MONGODB
if (!my->startup) {
elog("ERROR: db_plugin::wipe_database() called before configuration or after startup. Ignoring.");
} else {
my->wipe_database_on_startup = true;
}
#endif
}

void db_plugin::applied_irreversible_block(const signed_block& block) {
#ifdef MONGODB
my->applied_irreversible_block(block);
#endif
}


void db_plugin::plugin_initialize(const variables_map& options)
{
#ifdef MONGODB
ilog("initializing db plugin");
if(options.count("filter-on-accounts")) {
auto foa = options.at("filter-on-accounts").as<std::vector<std::string>>();
Expand All @@ -582,17 +600,19 @@ void db_plugin::plugin_initialize(const variables_map& options)
my->wipe_database();
}
my->init();
#endif
}

void db_plugin::plugin_startup()
{
#ifdef MONGODB
ilog("starting db plugin");
// TODO: assert that last irreversible in db is one less than received (on startup only?, every so often?)

my->consum_thread = boost::thread([this]{ my->consum_blocks(); });

// chain_controller is created and has resynced or replayed if needed
my->startup = false;
#endif
}

void db_plugin::plugin_shutdown()
Expand Down

0 comments on commit 72cecfc

Please sign in to comment.