Skip to content

Commit 6c6c59f

Browse files
committed
Adding DB file size as an option
1 parent be193ca commit 6c6c59f

File tree

6 files changed

+15
-8
lines changed

6 files changed

+15
-8
lines changed

src/dbwrapper.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class CBitcoinLevelDBLogger : public leveldb::Logger {
7373
}
7474
};
7575

76-
static leveldb::Options GetOptions(size_t nCacheSize, bool compression, int maxOpenFiles)
76+
static leveldb::Options GetOptions(size_t nCacheSize, bool compression, int maxOpenFiles, size_t maxFileSize)
7777
{
7878
leveldb::Options options;
7979
options.block_cache = leveldb::NewLRUCache(nCacheSize / 2);
@@ -82,6 +82,7 @@ static leveldb::Options GetOptions(size_t nCacheSize, bool compression, int maxO
8282
options.compression = compression ? leveldb::kSnappyCompression : leveldb::kNoCompression;
8383
options.max_open_files = maxOpenFiles;
8484
options.info_log = new CBitcoinLevelDBLogger();
85+
options.max_file_size = maxFileSize;
8586
if (leveldb::kMajorVersion > 1 || (leveldb::kMajorVersion == 1 && leveldb::kMinorVersion >= 16)) {
8687
// LevelDB versions before 1.16 consider short writes to be corruption. Only trigger error
8788
// on corruption in later versions.
@@ -90,14 +91,14 @@ static leveldb::Options GetOptions(size_t nCacheSize, bool compression, int maxO
9091
return options;
9192
}
9293

93-
CDBWrapper::CDBWrapper(const fs::path& path, size_t nCacheSize, bool fMemory, bool fWipe, bool obfuscate, bool compression, int maxOpenFiles)
94+
CDBWrapper::CDBWrapper(const fs::path& path, size_t nCacheSize, bool fMemory, bool fWipe, bool obfuscate, bool compression, int maxOpenFiles, size_t maxFileSize)
9495
{
9596
penv = nullptr;
9697
readoptions.verify_checksums = true;
9798
iteroptions.verify_checksums = true;
9899
iteroptions.fill_cache = false;
99100
syncoptions.sync = true;
100-
options = GetOptions(nCacheSize, compression, maxOpenFiles);
101+
options = GetOptions(nCacheSize, compression, maxOpenFiles, maxFileSize);
101102
options.create_if_missing = true;
102103
if (fMemory) {
103104
penv = leveldb::NewMemEnv(leveldb::Env::Default());

src/dbwrapper.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ class CDBWrapper
220220
* @param[in] compression Enable snappy compression for the database
221221
* @param[in] maxOpenFiles The maximum number of open files for the database
222222
*/
223-
CDBWrapper(const fs::path& path, size_t nCacheSize, bool fMemory = false, bool fWipe = false, bool obfuscate = false, bool compression = false, int maxOpenFiles = 64);
223+
CDBWrapper(const fs::path& path, size_t nCacheSize, bool fMemory, bool fWipe, bool obfuscate, bool compression, int maxOpenFiles, size_t maxFileSize);
224224
~CDBWrapper();
225225

226226
template <typename K, typename V>

src/init.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -1374,10 +1374,12 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
13741374
// block tree db settings
13751375
int dbMaxOpenFiles = gArgs.GetArg("-dbmaxopenfiles", DEFAULT_DB_MAX_OPEN_FILES);
13761376
bool dbCompression = gArgs.GetBoolArg("-dbcompression", DEFAULT_DB_COMPRESSION);
1377+
size_t dbMaxFileSize = gArgs.GetArg("-dbmaxfilesize", DEFAULT_DB_MAX_FILE_SIZE) << 20;
13771378

13781379
LogPrintf("Block index database configuration:\n");
13791380
LogPrintf("* Using %d max open files\n", dbMaxOpenFiles);
13801381
LogPrintf("* Compression is %s\n", dbCompression ? "enabled" : "disabled");
1382+
LogPrintf("* Using %d MB files\n", (dbMaxFileSize / 1024 / 1024));
13811383

13821384
// cache size calculations
13831385
int64_t nTotalCache = (gArgs.GetArg("-dbcache", nDefaultDbCache) << 20);
@@ -1418,7 +1420,7 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
14181420
delete pcoinscatcher;
14191421
delete pblocktree;
14201422

1421-
pblocktree = new CBlockTreeDB(nBlockTreeDBCache, false, fReset, dbCompression, dbMaxOpenFiles);
1423+
pblocktree = new CBlockTreeDB(nBlockTreeDBCache, false, fReset, dbCompression, dbMaxOpenFiles, dbMaxFileSize);
14221424

14231425
if (fReset) {
14241426
pblocktree->WriteReindexing(true);

src/txdb.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ struct CoinEntry {
6060

6161
}
6262

63-
CCoinsViewDB::CCoinsViewDB(size_t nCacheSize, bool fMemory, bool fWipe) : db(GetDataDir() / "chainstate", nCacheSize, fMemory, fWipe, true, false, 64)
63+
CCoinsViewDB::CCoinsViewDB(size_t nCacheSize, bool fMemory, bool fWipe) : db(GetDataDir() / "chainstate", nCacheSize, fMemory, fWipe, true, false, 64, 2 << 20)
6464
{
6565
}
6666

@@ -153,7 +153,7 @@ size_t CCoinsViewDB::EstimateSize() const
153153
return db.EstimateSize(DB_COIN, (char)(DB_COIN+1));
154154
}
155155

156-
CBlockTreeDB::CBlockTreeDB(size_t nCacheSize, bool fMemory, bool fWipe, bool compression, int maxOpenFiles) : CDBWrapper(GetDataDir() / "blocks" / "index", nCacheSize, fMemory, fWipe, false, compression, maxOpenFiles) {
156+
CBlockTreeDB::CBlockTreeDB(size_t nCacheSize, bool fMemory, bool fWipe, bool compression, int maxOpenFiles, size_t maxFileSize) : CDBWrapper(GetDataDir() / "blocks" / "index", nCacheSize, fMemory, fWipe, false, compression, maxOpenFiles, maxFileSize) {
157157
}
158158

159159
bool CBlockTreeDB::ReadBlockFileInfo(int nFile, CBlockFileInfo &info) {

src/txdb.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ class CCoinsViewDBCursor: public CCoinsViewCursor
112112
class CBlockTreeDB : public CDBWrapper
113113
{
114114
public:
115-
CBlockTreeDB(size_t nCacheSize, bool fMemory = false, bool fWipe = false, bool compression = true, int maxOpenFiles = 1000);
115+
CBlockTreeDB(size_t nCacheSize, bool fMemory, bool fWipe, bool compression, int maxOpenFiles, size_t maxFileSize);
116116
private:
117117
CBlockTreeDB(const CBlockTreeDB&);
118118
void operator=(const CBlockTreeDB&);

src/validation.h

+4
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ static const bool DEFAULT_TIMESTAMPINDEX = false;
138138
static const bool DEFAULT_SPENTINDEX = false;
139139
static const unsigned int DEFAULT_DB_MAX_OPEN_FILES = 1000;
140140
static const bool DEFAULT_DB_COMPRESSION = true;
141+
142+
/** Default for -dbmaxfilesize , in MB */
143+
static const int64_t DEFAULT_DB_MAX_FILE_SIZE = 2;
144+
141145
static const unsigned int DEFAULT_BANSCORE_THRESHOLD = 100;
142146
/** Default for -persistmempool */
143147
static const bool DEFAULT_PERSIST_MEMPOOL = true;

0 commit comments

Comments
 (0)