diff --git a/CMakeLists.txt b/CMakeLists.txt index 27c29861..f5dcd324 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -56,6 +56,8 @@ if (BUILD_PEERPLAYS_TESTNET) set(GRAPHENE_EGENESIS_JSON "${CMAKE_CURRENT_SOURCE_DIR}/genesis-testnet.json" CACHE PATH "location of the genesis.json to embed in the executable" ) #add_compile_definitions(BUILD_PEERPLAYS_TESTNET=1) add_definitions(-DBUILD_PEERPLAYS_TESTNET=1) + add_definitions(-DBOOST_MULTI_INDEX_ENABLE_INVARIANT_CHECKING=1) + add_definitions(-DBOOST_MULTI_INDEX_ENABLE_SAFE_MODE=1) message ("\n====================\nBuilding for Testnet\n====================\n") else (BUILD_PEERPLAYS_TESTNET) set(GRAPHENE_EGENESIS_JSON "${CMAKE_CURRENT_SOURCE_DIR}/genesis-mainnet.json" CACHE PATH "location of the genesis.json to embed in the executable" ) diff --git a/libraries/app/application.cpp b/libraries/app/application.cpp index 19f1ed10..4fcd22e7 100644 --- a/libraries/app/application.cpp +++ b/libraries/app/application.cpp @@ -853,9 +853,10 @@ application::~application() { my->_p2p_network->close(); my->_p2p_network.reset(); } - if (my->_chain_db) { - my->_chain_db->close(); - } + //if (my->_chain_db) { + // my->_chain_db->close(); + // my->_chain_db.reset(); + //} } void application::set_program_options(boost::program_options::options_description &cli, @@ -1010,8 +1011,10 @@ void application::shutdown_plugins() { void application::shutdown() { if (my->_p2p_network) my->_p2p_network->close(); - if (my->_chain_db) + if (my->_chain_db){ my->_chain_db->close(); + my->_chain_db.reset(); + } } void application::initialize_plugins(const boost::program_options::variables_map &options) { diff --git a/libraries/chain/db_init.cpp b/libraries/chain/db_init.cpp index 724cad85..f1a74612 100644 --- a/libraries/chain/db_init.cpp +++ b/libraries/chain/db_init.cpp @@ -332,7 +332,7 @@ void database::initialize_evaluators() void database::initialize_indexes() { reset_indexes(); - _undo_db.set_max_size( GRAPHENE_MIN_UNDO_HISTORY ); + _undo_db.set_max_size( 100 /*GRAPHENE_MIN_UNDO_HISTORY*/ ); //Protocol object indexes add_index< primary_index >(); // 8192 assets per chunk diff --git a/libraries/db/include/graphene/db/index.hpp b/libraries/db/include/graphene/db/index.hpp index 1bc593f4..93b49fab 100644 --- a/libraries/db/include/graphene/db/index.hpp +++ b/libraries/db/include/graphene/db/index.hpp @@ -110,6 +110,7 @@ namespace graphene { namespace db { const object& get( object_id_type id )const { auto maybe_found = find( id ); + ilog("get ID is ${id}", ("id", id)); FC_ASSERT( maybe_found != nullptr, "Unable to find Object", ("id",id) ); return *maybe_found; } diff --git a/libraries/db/include/graphene/db/undo_database.hpp b/libraries/db/include/graphene/db/undo_database.hpp index 0eb00f55..c7bb2de7 100644 --- a/libraries/db/include/graphene/db/undo_database.hpp +++ b/libraries/db/include/graphene/db/undo_database.hpp @@ -25,6 +25,9 @@ #include #include #include +#include +#include +#include namespace graphene { namespace db { @@ -132,6 +135,8 @@ namespace graphene { namespace db { std::deque _stack; object_database& _db; size_t _max_size = 256; + + mutable fc::spin_yield_lock _spin_yield; }; } } // graphene::db diff --git a/libraries/db/undo_database.cpp b/libraries/db/undo_database.cpp index bffd761d..ee3fc11b 100644 --- a/libraries/db/undo_database.cpp +++ b/libraries/db/undo_database.cpp @@ -25,6 +25,8 @@ #include #include +#include + namespace graphene { namespace db { void undo_database::enable() { _disabled = false; } @@ -44,6 +46,8 @@ undo_database::session::~session() { undo_database::session undo_database::start_undo_session( bool force_enable ) { + synchronized(_spin_yield) + if( _disabled && !force_enable ) return session(*this); bool disable_on_exit = _disabled && force_enable; if( force_enable ) @@ -58,6 +62,8 @@ undo_database::session undo_database::start_undo_session( bool force_enable ) } void undo_database::on_create( const object& obj ) { + synchronized(_spin_yield) + if( _disabled ) return; if( _stack.empty() ) @@ -73,6 +79,8 @@ void undo_database::on_modify( const object& obj ) { if( _disabled ) return; + synchronized(_spin_yield) + if( _stack.empty() ) _stack.emplace_back(); auto& state = _stack.back(); @@ -86,6 +94,8 @@ void undo_database::on_remove( const object& obj ) { if( _disabled ) return; + synchronized(_spin_yield) + if( _stack.empty() ) _stack.emplace_back(); undo_state& state = _stack.back(); @@ -105,7 +115,9 @@ void undo_database::on_remove( const object& obj ) } void undo_database::undo() -{ try { +{ + synchronized(_spin_yield) + try { FC_ASSERT( !_disabled ); FC_ASSERT( _active_sessions > 0 ); disable(); @@ -136,6 +148,8 @@ void undo_database::undo() void undo_database::merge() { + synchronized(_spin_yield) + FC_ASSERT( _active_sessions > 0 ); if( _active_sessions == 1 && _stack.size() == 1 ) { @@ -256,12 +270,16 @@ void undo_database::merge() } void undo_database::commit() { + synchronized(_spin_yield) + FC_ASSERT( _active_sessions > 0 ); --_active_sessions; } void undo_database::pop_commit() { + synchronized(_spin_yield) + FC_ASSERT( _active_sessions == 0 ); FC_ASSERT( !_stack.empty() ); @@ -299,6 +317,8 @@ void undo_database::pop_commit() } const undo_state& undo_database::head()const { + synchronized(_spin_yield) + FC_ASSERT( !_stack.empty() ); return _stack.back(); } diff --git a/libraries/fc b/libraries/fc index 6171e973..711b04fb 160000 --- a/libraries/fc +++ b/libraries/fc @@ -1 +1 @@ -Subproject commit 6171e973c7fcfc9e0a39eaee2f05da84416a90e6 +Subproject commit 711b04fb4f21bcaf8fdf00f51f4d6410849bec92