Skip to content

Commit

Permalink
Merge pull request #120 from peerplays-network/GRPH-89
Browse files Browse the repository at this point in the history
Better object database handling
  • Loading branch information
bobinson authored Sep 12, 2019
2 parents 0bdbd64 + b3c64c8 commit ddc41d6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
10 changes: 9 additions & 1 deletion libraries/chain/db_management.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@ void database::reindex(fc::path data_dir, const genesis_state_type& initial_allo
void database::wipe(const fc::path& data_dir, bool include_blocks)
{
ilog("Wiping database", ("include_blocks", include_blocks));
close();
if (_opened) {
close();
}
object_database::wipe(data_dir);
if( include_blocks )
fc::remove_all( data_dir / "database" );
Expand Down Expand Up @@ -148,12 +150,16 @@ void database::open(
("last_block->id", last_block->id())("head_block_num",head_block_num()) );
}
}
_opened = true;
}
FC_CAPTURE_LOG_AND_RETHROW( (data_dir) )
}

void database::close(bool rewind)
{
if (!_opened)
return;

// TODO: Save pending tx's on close()
clear_pending();

Expand Down Expand Up @@ -198,6 +204,8 @@ void database::close(bool rewind)
_block_id_to_block.close();

_fork_db.reset();

_opened = false;
}

void database::force_slow_replays()
Expand Down
9 changes: 9 additions & 0 deletions libraries/chain/include/graphene/chain/database.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,15 @@ namespace graphene { namespace chain {
node_property_object _node_property_object;
fc::hash_ctr_rng<secret_hash_type, 20> _random_number_generator;
bool _slow_replays = false;

/**
* Whether database is successfully opened or not.
*
* The database is considered open when there's no exception
* or assertion fail during database::open() method, and
* database::close() has not been called, or failed during execution.
*/
bool _opened = false;
};

namespace detail
Expand Down

0 comments on commit ddc41d6

Please sign in to comment.