Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

cleanup db.cpp/.h after Ultraprune patch #2011

Closed
wants to merge 1 commit into from

2 participants

@Diapolo
  • remove obsolete functions, variables, definitions and such
  • cleanup layout (no need to keep that many ugly empty lines IMHO)

I searched trough the source to see where functions are used and removed all that were not used anywhere anymore. Tried a compilation afterwards and the client still works fine :). Needs a careful review from a core dev.

@Diapolo Diapolo cleanup db.cpp/.h after Ultraprune patch
- remove obsolete functions, variables, definitions and such
- cleanup layout (no need to keep that many ugly empty lines IMHO)
0c7d18c
@sipa
Owner

I think you're a bit over-eager, and missed the fact that mocking is only used in tests.

@Diapolo Diapolo closed this
@Diapolo

Indeed... searched through the client source but didn't search within tests, sorry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 14, 2012
  1. @Diapolo

    cleanup db.cpp/.h after Ultraprune patch

    Diapolo authored
    - remove obsolete functions, variables, definitions and such
    - cleanup layout (no need to keep that many ugly empty lines IMHO)
This page is out of date. Refresh to see the latest.
Showing with 8 additions and 94 deletions.
  1. +7 −78 src/db.cpp
  2. +1 −16 src/db.h
View
85 src/db.cpp
@@ -17,11 +17,8 @@
using namespace std;
using namespace boost;
-
unsigned int nWalletDBUpdated;
-
-
//
// CDB
//
@@ -37,8 +34,7 @@ void CDBEnv::EnvShutdown()
int ret = dbenv.close(0);
if (ret != 0)
printf("EnvShutdown exception: %s (%d)\n", DbEnv::strerror(ret), ret);
- if (!fMockDb)
- DbEnv(0).remove(GetDataDir().string().c_str(), 0);
+ DbEnv(0).remove(GetDataDir().string().c_str(), 0);
}
CDBEnv::CDBEnv() : dbenv(DB_CXX_NO_EXCEPTIONS)
@@ -97,43 +93,9 @@ bool CDBEnv::Open(const boost::filesystem::path& path)
return error("CDB() : error %s (%d) opening database environment", DbEnv::strerror(ret), ret);
fDbEnvInit = true;
- fMockDb = false;
return true;
}
-void CDBEnv::MakeMock()
-{
- if (fDbEnvInit)
- throw runtime_error("CDBEnv::MakeMock(): already initialized");
-
- if (fShutdown)
- throw runtime_error("CDBEnv::MakeMock(): during shutdown");
-
- printf("CDBEnv::MakeMock()\n");
-
- dbenv.set_cachesize(1, 0, 1);
- dbenv.set_lg_bsize(10485760*4);
- dbenv.set_lg_max(10485760);
- dbenv.set_lk_max_locks(10000);
- dbenv.set_lk_max_objects(10000);
- dbenv.set_flags(DB_AUTO_COMMIT, 1);
- dbenv.log_set_config(DB_LOG_IN_MEMORY, 1);
- int ret = dbenv.open(NULL,
- DB_CREATE |
- DB_INIT_LOCK |
- DB_INIT_LOG |
- DB_INIT_MPOOL |
- DB_INIT_TXN |
- DB_THREAD |
- DB_PRIVATE,
- S_IRUSR | S_IWUSR);
- if (ret > 0)
- throw runtime_error(strprintf("CDBEnv::MakeMock(): error %d opening database environment", ret));
-
- fDbEnvInit = true;
- fMockDb = true;
-}
-
CDBEnv::VerifyResult CDBEnv::Verify(std::string strFile, bool (*recoverFunc)(CDBEnv& dbenv, std::string strFile))
{
LOCK(cs_db);
@@ -196,16 +158,12 @@ bool CDBEnv::Salvage(std::string strFile, bool fAggressive,
return (result == 0);
}
-
void CDBEnv::CheckpointLSN(std::string strFile)
{
dbenv.txn_checkpoint(0, 0, 0);
- if (fMockDb)
- return;
dbenv.lsn_reset(strFile.c_str(), 0);
}
-
CDB::CDB(const char *pszFile, const char* pszMode) :
pdb(NULL), activeTxn(NULL)
{
@@ -231,20 +189,11 @@ CDB::CDB(const char *pszFile, const char* pszMode) :
{
pdb = new Db(&bitdb.dbenv, 0);
- bool fMockDb = bitdb.IsMock();
- if (fMockDb)
- {
- DbMpoolFile*mpf = pdb->get_mpf();
- ret = mpf->set_flags(DB_MPOOL_NOFILE, 1);
- if (ret != 0)
- throw runtime_error(strprintf("CDB() : failed to configure for no temp file backing for database %s", pszFile));
- }
-
- ret = pdb->open(NULL, // Txn pointer
- fMockDb ? NULL : pszFile, // Filename
- fMockDb ? pszFile : "main", // Logical db name
- DB_BTREE, // Database type
- nFlags, // Flags
+ ret = pdb->open(NULL, // Txn pointer
+ pszFile, // Filename
+ "main", // Logical db name
+ DB_BTREE, // Database type
+ nFlags, // Flags
0);
if (ret != 0)
@@ -314,15 +263,6 @@ void CDBEnv::CloseDb(const string& strFile)
}
}
-bool CDBEnv::RemoveDb(const string& strFile)
-{
- this->CloseDb(strFile);
-
- LOCK(cs_db);
- int rc = dbenv.dbremove(NULL, strFile.c_str(), NULL, DB_AUTO_COMMIT);
- return (rc == 0);
-}
-
bool CDB::Rewrite(const string& strFile, const char* pszSkip)
{
while (!fShutdown)
@@ -416,7 +356,6 @@ bool CDB::Rewrite(const string& strFile, const char* pszSkip)
return false;
}
-
void CDBEnv::Flush(bool fShutdown)
{
int64 nStart = GetTimeMillis();
@@ -440,8 +379,7 @@ void CDBEnv::Flush(bool fShutdown)
printf("%s checkpoint\n", strFile.c_str());
dbenv.txn_checkpoint(0, 0, 0);
printf("%s detach\n", strFile.c_str());
- if (!fMockDb)
- dbenv.lsn_reset(strFile.c_str(), 0);
+ dbenv.lsn_reset(strFile.c_str(), 0);
printf("%s closed\n", strFile.c_str());
mapFileUseCount.erase(mi++);
}
@@ -462,15 +400,6 @@ void CDBEnv::Flush(bool fShutdown)
}
-
-
-
-
-
-
-
-
-
//
// CAddrDB
//
View
17 src/db.h
@@ -2,6 +2,7 @@
// Copyright (c) 2009-2012 The Bitcoin developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
#ifndef BITCOIN_DB_H
#define BITCOIN_DB_H
@@ -13,12 +14,7 @@
#include <db_cxx.h>
-class CAddress;
class CAddrMan;
-class CBlockLocator;
-class CDiskBlockIndex;
-class CMasterKey;
-class COutPoint;
class CWallet;
class CWalletTx;
@@ -27,12 +23,10 @@ extern unsigned int nWalletDBUpdated;
void ThreadFlushWalletDB(void* parg);
bool BackupWallet(const CWallet& wallet, const std::string& strDest);
-
class CDBEnv
{
private:
bool fDbEnvInit;
- bool fMockDb;
void EnvShutdown();
@@ -44,8 +38,6 @@ class CDBEnv
CDBEnv();
~CDBEnv();
- void MakeMock();
- bool IsMock() { return fMockDb; }
/*
* Verify that database file strFile is OK. If it is not,
@@ -71,7 +63,6 @@ class CDBEnv
void CheckpointLSN(std::string strFile);
void CloseDb(const std::string& strFile);
- bool RemoveDb(const std::string& strFile);
DbTxn *TxnBegin(int flags=DB_TXN_WRITE_NOSYNC)
{
@@ -306,12 +297,6 @@ class CDB
};
-
-
-
-
-
-
/** Access to the (IP) address database (peers.dat) */
class CAddrDB
{
Something went wrong with that request. Please try again.