aboutsummaryrefslogtreecommitdiff
path: root/src/blockchain_db
diff options
context:
space:
mode:
authorThomas Winget <tewinget@gmail.com>2015-03-25 11:41:30 -0400
committerThomas Winget <tewinget@gmail.com>2015-03-25 12:09:44 -0400
commit7b14d4a17f739c383322312f1a597f264c074c6e (patch)
tree3934f69a876d5f10637c93fc868d5a8f139aa164 /src/blockchain_db
parentupdate berkeleydb branch to blockchain branch (diff)
downloadmonero-7b14d4a17f739c383322312f1a597f264c074c6e.tar.xz
Steps toward multiple dbs available -- working
There will need to be some more refactoring for these changes to be considered complete/correct, but for now it's working. new daemon cli argument "--db-type", works for LMDB and BerkeleyDB. A good deal of refactoring is also present in this commit, namely Blockchain no longer instantiates BlockchainDB, but rather is passed a pointer to an already-instantiated BlockchainDB on init().
Diffstat (limited to 'src/blockchain_db')
-rw-r--r--src/blockchain_db/berkeleydb/db_bdb.cpp7
-rw-r--r--src/blockchain_db/berkeleydb/db_bdb.h3
-rw-r--r--src/blockchain_db/blockchain_db.cpp5
-rw-r--r--src/blockchain_db/blockchain_db.h6
-rw-r--r--src/blockchain_db/db_types.h40
-rw-r--r--src/blockchain_db/lmdb/db_lmdb.cpp7
-rw-r--r--src/blockchain_db/lmdb/db_lmdb.h4
7 files changed, 50 insertions, 22 deletions
diff --git a/src/blockchain_db/berkeleydb/db_bdb.cpp b/src/blockchain_db/berkeleydb/db_bdb.cpp
index 786c13b0b..4b254500b 100644
--- a/src/blockchain_db/berkeleydb/db_bdb.cpp
+++ b/src/blockchain_db/berkeleydb/db_bdb.cpp
@@ -724,13 +724,6 @@ void BlockchainBDB::open(const std::string& filename, const int db_flags)
m_open = true;
}
-// unused for now, create will happen on open if doesn't exist
-void BlockchainBDB::create(const std::string& filename)
-{
- LOG_PRINT_L3("BlockchainBDB::" << __func__);
- throw DB_CREATE_FAILURE("create() is not implemented for this BlockchainDB, open() will create files if needed.");
-}
-
void BlockchainBDB::close()
{
LOG_PRINT_L3("BlockchainBDB::" << __func__);
diff --git a/src/blockchain_db/berkeleydb/db_bdb.h b/src/blockchain_db/berkeleydb/db_bdb.h
index b68ed287f..d4eb5434c 100644
--- a/src/blockchain_db/berkeleydb/db_bdb.h
+++ b/src/blockchain_db/berkeleydb/db_bdb.h
@@ -95,8 +95,6 @@ public:
virtual void open(const std::string& filename, const int db_flags);
- virtual void create(const std::string& filename);
-
virtual void close();
virtual void sync();
@@ -279,7 +277,6 @@ private:
Db* m_spent_keys;
- bool m_open;
uint64_t m_height;
uint64_t m_num_outputs;
std::string m_folder;
diff --git a/src/blockchain_db/blockchain_db.cpp b/src/blockchain_db/blockchain_db.cpp
index 8b08d3805..d648be44e 100644
--- a/src/blockchain_db/blockchain_db.cpp
+++ b/src/blockchain_db/blockchain_db.cpp
@@ -129,6 +129,11 @@ void BlockchainDB::pop_block(block& blk, std::vector<transaction>& txs)
}
}
+bool BlockchainDB::is_open()
+{
+ return m_open;
+}
+
void BlockchainDB::remove_transaction(const crypto::hash& tx_hash)
{
transaction tx = get_tx(tx_hash);
diff --git a/src/blockchain_db/blockchain_db.h b/src/blockchain_db/blockchain_db.h
index 7b6b55a40..04d9c5384 100644
--- a/src/blockchain_db/blockchain_db.h
+++ b/src/blockchain_db/blockchain_db.h
@@ -62,6 +62,7 @@
*
* General:
* open()
+ * is_open()
* close()
* sync()
* reset()
@@ -328,8 +329,8 @@ public:
// open the db at location <filename>, or create it if there isn't one.
virtual void open(const std::string& filename, const int db_flags = 0) = 0;
- // make sure implementation has a create function as well
- virtual void create(const std::string& filename) = 0;
+ // returns true of the db is open/ready, else false
+ bool is_open();
// close and sync the db
virtual void close() = 0;
@@ -482,6 +483,7 @@ public:
// returns true if key image <img> is present in spent key images storage
virtual bool has_key_image(const crypto::key_image& img) const = 0;
+ bool m_open;
}; // class BlockchainDB
diff --git a/src/blockchain_db/db_types.h b/src/blockchain_db/db_types.h
new file mode 100644
index 000000000..b13007df4
--- /dev/null
+++ b/src/blockchain_db/db_types.h
@@ -0,0 +1,40 @@
+// Copyright (c) 2015, The Monero Project
+//
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without modification, are
+// permitted provided that the following conditions are met:
+//
+// 1. Redistributions of source code must retain the above copyright notice, this list of
+// conditions and the following disclaimer.
+//
+// 2. Redistributions in binary form must reproduce the above copyright notice, this list
+// of conditions and the following disclaimer in the documentation and/or other
+// materials provided with the distribution.
+//
+// 3. Neither the name of the copyright holder nor the names of its contributors may be
+// used to endorse or promote products derived from this software without specific
+// prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
+// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+// 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.
+//
+// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
+#pragma once
+
+namespace cryptonote
+{
+
+ const std::unordered_set<std::string> blockchain_db_types =
+ { "lmdb"
+ , "berkeley"
+ };
+
+} // namespace cryptonote
diff --git a/src/blockchain_db/lmdb/db_lmdb.cpp b/src/blockchain_db/lmdb/db_lmdb.cpp
index 524a1c269..8e09dfab2 100644
--- a/src/blockchain_db/lmdb/db_lmdb.cpp
+++ b/src/blockchain_db/lmdb/db_lmdb.cpp
@@ -733,13 +733,6 @@ void BlockchainLMDB::open(const std::string& filename, const int mdb_flags)
// from here, init should be finished
}
-// unused for now, create will happen on open if doesn't exist
-void BlockchainLMDB::create(const std::string& filename)
-{
- LOG_PRINT_L3("BlockchainLMDB::" << __func__);
- throw DB_CREATE_FAILURE("create() is not implemented for this BlockchainDB, open() will create files if needed.");
-}
-
void BlockchainLMDB::close()
{
LOG_PRINT_L3("BlockchainLMDB::" << __func__);
diff --git a/src/blockchain_db/lmdb/db_lmdb.h b/src/blockchain_db/lmdb/db_lmdb.h
index c3c7ce439..8f1e07e0d 100644
--- a/src/blockchain_db/lmdb/db_lmdb.h
+++ b/src/blockchain_db/lmdb/db_lmdb.h
@@ -24,6 +24,7 @@
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
// 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.
+#pragma once
#include "blockchain_db/blockchain_db.h"
#include "cryptonote_protocol/blobdatatype.h" // for type blobdata
@@ -116,8 +117,6 @@ public:
virtual void open(const std::string& filename, const int mdb_flags=0);
- virtual void create(const std::string& filename);
-
virtual void close();
virtual void sync();
@@ -302,7 +301,6 @@ private:
MDB_dbi m_spent_keys;
- bool m_open;
uint64_t m_height;
uint64_t m_num_outputs;
std::string m_folder;