BerkeleyDB BlockchainDB impl copy/paste/modify

LMDB implementation code copy/paste/modified into the Berkeley DB
implementation.  Need to test if it builds, then if it works, and so on,
but the code is all there.
This commit is contained in:
Thomas Winget 2015-03-14 19:28:34 -04:00
parent 5112dc37d7
commit 1bc89398b4
No known key found for this signature in database
GPG key ID: 58131A160789E630
2 changed files with 1304 additions and 9 deletions

File diff suppressed because it is too large Load diff

View file

@ -25,12 +25,66 @@
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <db_cxx.h>
#include "blockchain_db/blockchain_db.h" #include "blockchain_db/blockchain_db.h"
#include "cryptonote_protocol/blobdatatype.h" // for type blobdata #include "cryptonote_protocol/blobdatatype.h" // for type blobdata
namespace cryptonote namespace cryptonote
{ {
struct bdb_txn_safe
{
bdb_txn_safe() : m_txn(NULL) { }
~bdb_txn_safe()
{
LOG_PRINT_L3("bdb_txn_safe: destructor");
abort();
}
void commit(std::string message = "")
{
if (message.size() == 0)
{
message = "Failed to commit a transaction to the db";
}
if (txn->commit())
{
m_txn = NULL;
LOG_PRINT_L0(message);
throw DB_ERROR(message.c_str());
}
m_txn = NULL;
}
void abort()
{
LOG_PRINT_L3("bdb_txn_safe: abort()");
if(m_txn != NULL)
{
m_txn->abort();
m_txn = NULL;
}
else
{
LOG_PRINT_L0("WARNING: bdb_txn_safe: abort() called, but m_txn is NULL");
}
}
operator DbTxn*()
{
return m_txn;
}
operator DbTxn**()
{
return &m_txn;
}
DbTxn* m_txn;
};
class BlockchainBDB : public BlockchainDB class BlockchainBDB : public BlockchainDB
{ {
public: public:
@ -199,15 +253,35 @@ private:
void check_open() const; void check_open() const;
DbEnv* m_env;
Db* m_blocks;
Db* m_block_heights;
Db* m_block_hashes;
Db* m_block_timestamps;
Db* m_block_sizes;
Db* m_block_diffs;
Db* m_block_coins;
Db* m_txs;
Db* m_tx_unlocks;
Db* m_tx_heights;
Db* m_tx_outputs;
Db* m_output_txs;
Db* m_output_indices;
Db* m_output_amounts;
Db* m_output_keys;
Db* m_spent_keys;
bool m_open; bool m_open;
uint64_t m_height; uint64_t m_height;
uint64_t m_num_outputs; uint64_t m_num_outputs;
std::string m_folder; std::string m_folder;
txn_safe* m_write_txn; // may point to either a short-lived txn or a batch txn txn_safe m_write_txn; // may point to either a short-lived txn or a batch txn
txn_safe m_write_batch_txn; // persist batch txn outside of BlockchainBDB
bool m_batch_transactions; // support for batch transactions bool m_batch_transactions; // support for batch transactions
bool m_batch_active; // whether batch transaction is in progress
}; };
} // namespace cryptonote } // namespace cryptonote