aboutsummaryrefslogtreecommitdiff
path: root/src/blockchain_db/berkeleydb/db_bdb.h
diff options
context:
space:
mode:
authorThomas Winget <tewinget@gmail.com>2015-03-14 19:28:34 -0400
committerThomas Winget <tewinget@gmail.com>2015-03-16 04:17:48 -0400
commit1bc89398b4cea4406418f7c385025a1d3c062054 (patch)
tree0e49cb94023fc862d9674cbf7a44df2d134465bb /src/blockchain_db/berkeleydb/db_bdb.h
parentTry to not pollute cryptonote namespace (diff)
downloadmonero-1bc89398b4cea4406418f7c385025a1d3c062054.tar.xz
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.
Diffstat (limited to '')
-rw-r--r--src/blockchain_db/berkeleydb/db_bdb.h80
1 files changed, 77 insertions, 3 deletions
diff --git a/src/blockchain_db/berkeleydb/db_bdb.h b/src/blockchain_db/berkeleydb/db_bdb.h
index 32686e6ba..b28afbf20 100644
--- a/src/blockchain_db/berkeleydb/db_bdb.h
+++ b/src/blockchain_db/berkeleydb/db_bdb.h
@@ -25,12 +25,66 @@
// 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.
+#include <db_cxx.h>
+
#include "blockchain_db/blockchain_db.h"
#include "cryptonote_protocol/blobdatatype.h" // for type blobdata
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
{
public:
@@ -199,15 +253,35 @@ private:
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;
uint64_t m_height;
uint64_t m_num_outputs;
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_batch_txn; // persist batch txn outside of BlockchainBDB
+ txn_safe m_write_txn; // may point to either a short-lived txn or a batch txn
bool m_batch_transactions; // support for batch transactions
- bool m_batch_active; // whether batch transaction is in progress
};
} // namespace cryptonote