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

Commit

Permalink
Renamed class db_plugin to mongo_db_plugin #1074
Browse files Browse the repository at this point in the history
  • Loading branch information
heifner committed Jan 11, 2018
1 parent 3f13f83 commit 9001194
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@

namespace eosio {

using db_plugin_impl_ptr = std::shared_ptr<class db_plugin_impl>;
using mongo_db_plugin_impl_ptr = std::shared_ptr<class mongo_db_plugin_impl>;

/**
* Provides persistence to MongoDB for:
* Blocks
* Transactions
* Messages
* Actions
* Accounts
*
* See data dictionary (DB Schema Definition - EOS API) for description of MongoDB schema.
Expand All @@ -29,12 +29,12 @@ using db_plugin_impl_ptr = std::shared_ptr<class db_plugin_impl>;
*
* If MongoDB env not available (#ifndef MONGODB) this plugin is a no-op.
*/
class db_plugin : public plugin<db_plugin> {
class mongo_db_plugin : public plugin<mongo_db_plugin> {
public:
APPBASE_PLUGIN_REQUIRES((chain_plugin))

db_plugin();
virtual ~db_plugin();
mongo_db_plugin();
virtual ~mongo_db_plugin();

virtual void set_program_options(options_description& cli, options_description& cfg) override;

Expand All @@ -47,7 +47,7 @@ class db_plugin : public plugin<db_plugin> {
void plugin_shutdown();

private:
db_plugin_impl_ptr my;
mongo_db_plugin_impl_ptr my;
};

}
Expand Down
89 changes: 46 additions & 43 deletions plugins/mongo_db_plugin/mongo_db_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,20 @@ using chain::signed_block;
using chain::transaction_id_type;

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

#ifdef MONGODB
class db_plugin_impl {

static appbase::abstract_plugin& _mongo_db_plugin = app().register_plugin<mongo_db_plugin>();

class mongo_db_plugin_impl {
public:
db_plugin_impl();
~db_plugin_impl();
mongo_db_plugin_impl();
~mongo_db_plugin_impl();

void applied_irreversible_block(const signed_block&);
void process_irreversible_block(const signed_block&);
Expand Down Expand Up @@ -100,23 +103,23 @@ class db_plugin_impl {
static const std::string accounts_col;
};

abi_def db_plugin_impl::eos_abi;
abi_def mongo_db_plugin_impl::eos_abi;

const account_name db_plugin_impl::newaccount = "newaccount";
const account_name db_plugin_impl::transfer = "transfer";
const account_name db_plugin_impl::lock = "lock";
const account_name db_plugin_impl::unlock = "unlock";
const account_name db_plugin_impl::claim = "claim";
const account_name db_plugin_impl::setcode = "setcode";
const account_name db_plugin_impl::setabi = "setabi";
const account_name mongo_db_plugin_impl::newaccount = "newaccount";
const account_name mongo_db_plugin_impl::transfer = "transfer";
const account_name mongo_db_plugin_impl::lock = "lock";
const account_name mongo_db_plugin_impl::unlock = "unlock";
const account_name mongo_db_plugin_impl::claim = "claim";
const account_name mongo_db_plugin_impl::setcode = "setcode";
const account_name mongo_db_plugin_impl::setabi = "setabi";

const std::string db_plugin_impl::blocks_col = "Blocks";
const std::string db_plugin_impl::trans_col = "Transactions";
const std::string db_plugin_impl::actions_col = "Actions";
const std::string db_plugin_impl::accounts_col = "Accounts";
const std::string mongo_db_plugin_impl::blocks_col = "Blocks";
const std::string mongo_db_plugin_impl::trans_col = "Transactions";
const std::string mongo_db_plugin_impl::actions_col = "Actions";
const std::string mongo_db_plugin_impl::accounts_col = "Accounts";


void db_plugin_impl::applied_irreversible_block(const signed_block& block) {
void mongo_db_plugin_impl::applied_irreversible_block(const signed_block& block) {
try {
if (startup) {
// on startup we don't want to queue, instead push back on caller
Expand All @@ -136,7 +139,7 @@ void db_plugin_impl::applied_irreversible_block(const signed_block& block) {
}
}

void db_plugin_impl::consum_blocks() {
void mongo_db_plugin_impl::consum_blocks() {
try {
signed_block block;
size_t size = 0;
Expand All @@ -162,7 +165,7 @@ void db_plugin_impl::consum_blocks() {
break;
}
}
ilog("db_plugin consum thread shutdown gracefully");
ilog("mongo_db_plugin consum thread shutdown gracefully");
} catch (fc::exception& e) {
elog("FC Exception while consuming block ${e}", ("e", e.to_string()));
} catch (std::exception& e) {
Expand Down Expand Up @@ -193,7 +196,7 @@ namespace {
try {
abi_serializer abis;
if (msg.scope == chain::config::system_account_name) {
abis.set_abi(db_plugin_impl::eos_abi);
abis.set_abi(mongo_db_plugin_impl::eos_abi);
} else {
auto from_account = find_account(accounts, msg.name);
auto abi = fc::json::from_string(bsoncxx::to_json(from_account.view()["abi"].get_document())).as<abi_def>();
Expand Down Expand Up @@ -240,7 +243,7 @@ namespace {
}
}

void db_plugin_impl::process_irreversible_block(const signed_block& block) {
void mongo_db_plugin_impl::process_irreversible_block(const signed_block& block) {
try {
_process_irreversible_block(block);
} catch (fc::exception& e) {
Expand All @@ -252,7 +255,7 @@ void db_plugin_impl::process_irreversible_block(const signed_block& block) {
}
}

void db_plugin_impl::_process_irreversible_block(const signed_block& block)
void mongo_db_plugin_impl::_process_irreversible_block(const signed_block& block)
{
using namespace bsoncxx::types;
using namespace bsoncxx::builder;
Expand Down Expand Up @@ -411,7 +414,7 @@ void db_plugin_impl::_process_irreversible_block(const signed_block& block)
}

// For now providing some simple account processing to maintain eos_balance
void db_plugin_impl::update_account(const chain::action& msg) {
void mongo_db_plugin_impl::update_account(const chain::action& msg) {
using bsoncxx::builder::basic::kvp;
using bsoncxx::builder::stream::document;
using bsoncxx::builder::stream::open_document;
Expand Down Expand Up @@ -564,7 +567,7 @@ void db_plugin_impl::update_account(const chain::action& msg) {
}
}

bool db_plugin_impl::is_scope_relevant(const vector<account_name>& scope)
bool mongo_db_plugin_impl::is_scope_relevant(const vector<account_name>& scope)
{
for (const account_name& account_name : scope)
if (filter_on.count(account_name))
Expand All @@ -573,24 +576,24 @@ bool db_plugin_impl::is_scope_relevant(const vector<account_name>& scope)
return false;
}

db_plugin_impl::db_plugin_impl()
mongo_db_plugin_impl::mongo_db_plugin_impl()
: mongo_inst{}
, mongo_conn{}
{
}

db_plugin_impl::~db_plugin_impl() {
mongo_db_plugin_impl::~mongo_db_plugin_impl() {
try {
done = true;
condtion.notify_one();

consum_thread.join();
} catch (std::exception& e) {
elog("Exception on db_plugin shutdown of consum thread: ${e}", ("e", e.what()));
elog("Exception on mongo_db_plugin shutdown of consum thread: ${e}", ("e", e.what()));
}
}

void db_plugin_impl::wipe_database() {
void mongo_db_plugin_impl::wipe_database() {
ilog("db wipe_database");

accounts = mongo_conn[db_name][accounts_col]; // Accounts
Expand All @@ -604,7 +607,7 @@ void db_plugin_impl::wipe_database() {
blocks.drop();
}

void db_plugin_impl::init() {
void mongo_db_plugin_impl::init() {
using namespace bsoncxx::types;
// Create the native contract accounts manually; sadly, we can't run their contracts to make them create themselves
// See native_contract_chain_initializer::prepare_database()
Expand Down Expand Up @@ -649,19 +652,19 @@ void db_plugin_impl::init() {

#endif /* MONGODB */
////////////
// db_plugin
// mongo_db_plugin
////////////

db_plugin::db_plugin()
:my(new db_plugin_impl)
mongo_db_plugin::mongo_db_plugin()
:my(new mongo_db_plugin_impl)
{
}

db_plugin::~db_plugin()
mongo_db_plugin::~mongo_db_plugin()
{
}

void db_plugin::set_program_options(options_description& cli, options_description& cfg)
void mongo_db_plugin::set_program_options(options_description& cli, options_description& cfg)
{
#ifdef MONGODB
cfg.add_options()
Expand All @@ -676,24 +679,24 @@ void db_plugin::set_program_options(options_description& cli, options_descriptio
#endif
}

void db_plugin::wipe_database() {
void mongo_db_plugin::wipe_database() {
#ifdef MONGODB
if (!my->startup) {
elog("ERROR: db_plugin::wipe_database() called before configuration or after startup. Ignoring.");
elog("ERROR: mongo_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) {
void mongo_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)
void mongo_db_plugin::plugin_initialize(const variables_map& options)
{
#ifdef MONGODB
if (options.count("mongodb-uri")) {
Expand Down Expand Up @@ -721,13 +724,13 @@ void db_plugin::plugin_initialize(const variables_map& options)
}
my->init();
} else {
wlog("eosio::db_plugin configured, but no --mongodb-uri specified.");
wlog("db_plugin disabled.");
wlog("eosio::mongo_db_plugin configured, but no --mongodb-uri specified.");
wlog("mongo_db_plugin disabled.");
}
#endif
}

void db_plugin::plugin_startup()
void mongo_db_plugin::plugin_startup()
{
#ifdef MONGODB
if (my->configured) {
Expand All @@ -741,7 +744,7 @@ void db_plugin::plugin_startup()
#endif
}

void db_plugin::plugin_shutdown()
void mongo_db_plugin::plugin_shutdown()
{
my.reset();
}
Expand Down
2 changes: 1 addition & 1 deletion programs/launcher/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,7 @@ launcher_def::write_config_file (tn_node_def &node) {
cfg << "plugin = eosio::producer_plugin\n";
}
if( instance.has_db ) {
cfg << "plugin = eosio::db_plugin\n";
cfg << "plugin = eosio::mongo_db_plugin\n";
}
cfg << "plugin = eosio::chain_api_plugin\n";
//<< "plugin = eosio::account_history_plugin\n"
Expand Down

0 comments on commit 9001194

Please sign in to comment.