More DB support cleanup
Hide DB types from db_types.h - no reason to recompile dependencies
when DB types change.
Also remove lingering in-memory DB references, they've been
obsolete since 9e82b694da
This commit is contained in:
parent
4c7f8ac04f
commit
80344740bd
|
@ -38,6 +38,14 @@
|
||||||
#include "berkeleydb/db_bdb.h"
|
#include "berkeleydb/db_bdb.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static const char *db_types[] = {
|
||||||
|
"lmdb",
|
||||||
|
#ifdef BERKELEY_DB
|
||||||
|
"berkeley",
|
||||||
|
#endif
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
#undef MONERO_DEFAULT_LOG_CATEGORY
|
#undef MONERO_DEFAULT_LOG_CATEGORY
|
||||||
#define MONERO_DEFAULT_LOG_CATEGORY "blockchain.db"
|
#define MONERO_DEFAULT_LOG_CATEGORY "blockchain.db"
|
||||||
|
|
||||||
|
@ -46,6 +54,30 @@ using epee::string_tools::pod_to_hex;
|
||||||
namespace cryptonote
|
namespace cryptonote
|
||||||
{
|
{
|
||||||
|
|
||||||
|
bool blockchain_valid_db_type(const std::string& db_type)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
for (i=0; db_types[i]; i++)
|
||||||
|
{
|
||||||
|
if (db_types[i] == db_type)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string blockchain_db_types(const std::string& sep)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
std::string ret = "";
|
||||||
|
for (i=0; db_types[i]; i++)
|
||||||
|
{
|
||||||
|
if (i)
|
||||||
|
ret += sep;
|
||||||
|
ret += db_types[i];
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
BlockchainDB *new_db(const std::string& db_type)
|
BlockchainDB *new_db(const std::string& db_type)
|
||||||
{
|
{
|
||||||
if (db_type == "lmdb")
|
if (db_type == "lmdb")
|
||||||
|
|
|
@ -31,9 +31,6 @@
|
||||||
|
|
||||||
namespace cryptonote
|
namespace cryptonote
|
||||||
{
|
{
|
||||||
|
bool blockchain_valid_db_type(const std::string& db_type);
|
||||||
const std::unordered_set<std::string> blockchain_db_types =
|
std::string blockchain_db_types(const std::string& sep);
|
||||||
{ "lmdb"
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace cryptonote
|
} // namespace cryptonote
|
||||||
|
|
|
@ -40,17 +40,6 @@
|
||||||
namespace po = boost::program_options;
|
namespace po = boost::program_options;
|
||||||
using namespace epee;
|
using namespace epee;
|
||||||
|
|
||||||
std::string join_set_strings(const std::unordered_set<std::string>& db_types_all, const char* delim)
|
|
||||||
{
|
|
||||||
std::string result;
|
|
||||||
std::ostringstream s;
|
|
||||||
std::copy(db_types_all.begin(), db_types_all.end(), std::ostream_iterator<std::string>(s, delim));
|
|
||||||
result = s.str();
|
|
||||||
if (result.length() > 0)
|
|
||||||
result.erase(result.end()-strlen(delim), result.end());
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
TRY_ENTRY();
|
TRY_ENTRY();
|
||||||
|
@ -59,10 +48,7 @@ int main(int argc, char* argv[])
|
||||||
|
|
||||||
std::string default_db_type = "lmdb";
|
std::string default_db_type = "lmdb";
|
||||||
|
|
||||||
std::unordered_set<std::string> db_types_all = cryptonote::blockchain_db_types;
|
std::string available_dbs = cryptonote::blockchain_db_types(", ");
|
||||||
db_types_all.insert("memory");
|
|
||||||
|
|
||||||
std::string available_dbs = join_set_strings(db_types_all, ", ");
|
|
||||||
available_dbs = "available: " + available_dbs;
|
available_dbs = "available: " + available_dbs;
|
||||||
|
|
||||||
uint32_t log_level = 0;
|
uint32_t log_level = 0;
|
||||||
|
@ -140,7 +126,7 @@ int main(int argc, char* argv[])
|
||||||
m_config_folder = command_line::get_arg(vm, data_dir_arg);
|
m_config_folder = command_line::get_arg(vm, data_dir_arg);
|
||||||
|
|
||||||
std::string db_type = command_line::get_arg(vm, arg_database);
|
std::string db_type = command_line::get_arg(vm, arg_database);
|
||||||
if (db_types_all.count(db_type) == 0)
|
if (!cryptonote::blockchain_valid_db_type(db_type))
|
||||||
{
|
{
|
||||||
std::cerr << "Invalid database type: " << db_type << std::endl;
|
std::cerr << "Invalid database type: " << db_type << std::endl;
|
||||||
return 1;
|
return 1;
|
||||||
|
|
|
@ -42,8 +42,6 @@
|
||||||
#include "blockchain_db/db_types.h"
|
#include "blockchain_db/db_types.h"
|
||||||
#include "cryptonote_core/cryptonote_core.h"
|
#include "cryptonote_core/cryptonote_core.h"
|
||||||
|
|
||||||
#include <lmdb.h> // for db flag arguments
|
|
||||||
|
|
||||||
#undef MONERO_DEFAULT_LOG_CATEGORY
|
#undef MONERO_DEFAULT_LOG_CATEGORY
|
||||||
#define MONERO_DEFAULT_LOG_CATEGORY "bcutil"
|
#define MONERO_DEFAULT_LOG_CATEGORY "bcutil"
|
||||||
|
|
||||||
|
@ -78,18 +76,6 @@ namespace po = boost::program_options;
|
||||||
using namespace cryptonote;
|
using namespace cryptonote;
|
||||||
using namespace epee;
|
using namespace epee;
|
||||||
|
|
||||||
|
|
||||||
std::string join_set_strings(const std::unordered_set<std::string>& db_types_all, const char* delim)
|
|
||||||
{
|
|
||||||
std::string result;
|
|
||||||
std::ostringstream s;
|
|
||||||
std::copy(db_types_all.begin(), db_types_all.end(), std::ostream_iterator<std::string>(s, delim));
|
|
||||||
result = s.str();
|
|
||||||
if (result.length() > 0)
|
|
||||||
result.erase(result.end()-strlen(delim), result.end());
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
// db_mode: safe, fast, fastest
|
// db_mode: safe, fast, fastest
|
||||||
int get_db_flags_from_mode(const std::string& db_mode)
|
int get_db_flags_from_mode(const std::string& db_mode)
|
||||||
{
|
{
|
||||||
|
@ -516,12 +502,8 @@ int main(int argc, char* argv[])
|
||||||
epee::string_tools::set_module_name_and_folder(argv[0]);
|
epee::string_tools::set_module_name_and_folder(argv[0]);
|
||||||
|
|
||||||
std::string default_db_type = "lmdb";
|
std::string default_db_type = "lmdb";
|
||||||
std::string default_db_engine_compiled = "blockchain_db";
|
|
||||||
|
|
||||||
std::unordered_set<std::string> db_types_all = cryptonote::blockchain_db_types;
|
std::string available_dbs = cryptonote::blockchain_db_types(", ");
|
||||||
db_types_all.insert("memory");
|
|
||||||
|
|
||||||
std::string available_dbs = join_set_strings(db_types_all, ", ");
|
|
||||||
available_dbs = "available: " + available_dbs;
|
available_dbs = "available: " + available_dbs;
|
||||||
|
|
||||||
uint32_t log_level = 0;
|
uint32_t log_level = 0;
|
||||||
|
@ -667,7 +649,6 @@ int main(int argc, char* argv[])
|
||||||
|
|
||||||
|
|
||||||
std::string db_type;
|
std::string db_type;
|
||||||
std::string db_engine_compiled;
|
|
||||||
int db_flags = 0;
|
int db_flags = 0;
|
||||||
int res = 0;
|
int res = 0;
|
||||||
res = parse_db_arguments(db_arg_str, db_type, db_flags);
|
res = parse_db_arguments(db_arg_str, db_type, db_flags);
|
||||||
|
@ -677,25 +658,12 @@ int main(int argc, char* argv[])
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (db_types_all.count(db_type) == 0)
|
if (!cryptonote::blockchain_valid_db_type(db_type))
|
||||||
{
|
{
|
||||||
std::cerr << "Invalid database type: " << db_type << std::endl;
|
std::cerr << "Invalid database type: " << db_type << std::endl;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((db_type == "lmdb")
|
|
||||||
#if defined(BERKELEY_DB)
|
|
||||||
|| (db_type == "berkeley")
|
|
||||||
#endif
|
|
||||||
)
|
|
||||||
{
|
|
||||||
db_engine_compiled = "blockchain_db";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
db_engine_compiled = "memory";
|
|
||||||
}
|
|
||||||
|
|
||||||
MINFO("database: " << db_type);
|
MINFO("database: " << db_type);
|
||||||
MINFO("database flags: " << db_flags);
|
MINFO("database flags: " << db_flags);
|
||||||
MINFO("verify: " << std::boolalpha << opt_verify << std::noboolalpha);
|
MINFO("verify: " << std::boolalpha << opt_verify << std::noboolalpha);
|
||||||
|
@ -724,16 +692,6 @@ int main(int argc, char* argv[])
|
||||||
// properties to do so. Both ways work, but fake core isn't necessary in that
|
// properties to do so. Both ways work, but fake core isn't necessary in that
|
||||||
// circumstance.
|
// circumstance.
|
||||||
|
|
||||||
if (db_type != "lmdb"
|
|
||||||
#if defined(BERKELEY_DB)
|
|
||||||
&& db_type != "berkeley"
|
|
||||||
#endif
|
|
||||||
)
|
|
||||||
{
|
|
||||||
std::cerr << "database type unrecognized" << ENDL;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
cryptonote::cryptonote_protocol_stub pr; //TODO: stub only for this kind of test, make real validation of relayed objects
|
cryptonote::cryptonote_protocol_stub pr; //TODO: stub only for this kind of test, make real validation of relayed objects
|
||||||
cryptonote::core core(&pr);
|
cryptonote::core core(&pr);
|
||||||
core.disable_dns_checkpoints(true);
|
core.disable_dns_checkpoints(true);
|
||||||
|
|
|
@ -96,7 +96,7 @@ namespace command_line
|
||||||
, "checkpoints from DNS server will be enforced"
|
, "checkpoints from DNS server will be enforced"
|
||||||
, false
|
, false
|
||||||
};
|
};
|
||||||
std::string arg_db_type_description = "Specify database type, available: " + boost::algorithm::join(cryptonote::blockchain_db_types, ", ");
|
std::string arg_db_type_description = "Specify database type, available: " + cryptonote::blockchain_db_types(", ");
|
||||||
const command_line::arg_descriptor<std::string> arg_db_type = {
|
const command_line::arg_descriptor<std::string> arg_db_type = {
|
||||||
"db-type"
|
"db-type"
|
||||||
, arg_db_type_description.c_str()
|
, arg_db_type_description.c_str()
|
||||||
|
|
|
@ -145,13 +145,10 @@ int main(int argc, char const * argv[])
|
||||||
std::string db_type = command_line::get_arg(vm, command_line::arg_db_type);
|
std::string db_type = command_line::get_arg(vm, command_line::arg_db_type);
|
||||||
|
|
||||||
// verify that blockchaindb type is valid
|
// verify that blockchaindb type is valid
|
||||||
if(cryptonote::blockchain_db_types.count(db_type) == 0)
|
if(!cryptonote::blockchain_valid_db_type(db_type))
|
||||||
{
|
{
|
||||||
std::cout << "Invalid database type (" << db_type << "), available types are:" << std::endl;
|
std::cout << "Invalid database type (" << db_type << "), available types are: " <<
|
||||||
for (const auto& type : cryptonote::blockchain_db_types)
|
cryptonote::blockchain_db_types(", ") << std::endl;
|
||||||
{
|
|
||||||
std::cout << "\t" << type << std::endl;
|
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue