Ensure database directories existence

Signed-off-by: Anthony Fieroni <bvbfan@abv.bg>
This commit is contained in:
Anthony Fieroni 2020-01-21 17:22:19 +02:00
parent ac042b808a
commit db96a93844
10 changed files with 26 additions and 41 deletions

View file

@ -44,9 +44,6 @@ void applyPragmas(sqlite::database& db, std::size_t cache)
db << "PRAGMA journal_mode=WAL";
db << "PRAGMA temp_store=MEMORY";
db << "PRAGMA case_sensitive_like=true";
db.define("POPS", [](std::string s) -> std::string { if (!s.empty()) s.pop_back(); return s; });
db.define("REVERSE", [](std::vector<uint8_t> s) -> std::vector<uint8_t> { std::reverse(s.begin(), s.end()); return s; });
}
CClaimTrie::CClaimTrie(std::size_t cacheBytes, bool fWipe, int height,
@ -522,6 +519,9 @@ CClaimTrieCacheBase::CClaimTrieCacheBase(CClaimTrie* base)
nNextHeight = base->nNextHeight;
applyPragmas(db, base->dbCacheBytes >> 10U); // in KB
db.define("POPS", [](std::string s) -> std::string { if (!s.empty()) s.pop_back(); return s; });
db.define("REVERSE", [](std::vector<uint8_t> s) -> std::vector<uint8_t> { std::reverse(s.begin(), s.end()); return s; });
}
CClaimTrieCacheBase::CClaimTrieCacheBase(CClaimTrieCacheBase&& o)

View file

@ -13,6 +13,7 @@
#include <unordered_set>
#include <utility>
void applyPragmas(sqlite::database& db, std::size_t cache);
uint256 getValueHash(const COutPoint& outPoint, int nHeightOfLastTakeover);
class CClaimTrie

View file

@ -66,7 +66,8 @@ size_t FlatFileSeq::Allocate(const FlatFilePos& pos, size_t add_size, bool& out_
if (CheckDiskSpace(m_dir, inc_size)) {
FILE *file = Open(pos);
if (file) {
LogPrintf("Pre-allocating up to position 0x%x in %s%05u.dat\n", new_size, m_prefix, pos.nFile);
// it bothers too much
// LogPrintf("Pre-allocating up to position 0x%x in %s%05u.dat\n", new_size, m_prefix, pos.nFile);
AllocateFileRange(file, pos.nPos, inc_size);
fclose(file);
return inc_size;

View file

@ -3,6 +3,7 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <chainparams.h>
#include <claimtrie/trie.h>
#include <index/base.h>
#include <shutdown.h>
#include <tinyformat.h>
@ -32,13 +33,9 @@ static const sqlite::sqlite_config sharedConfig {
};
BaseIndex::DB::DB(const fs::path& path, size_t n_cache_size, bool fMemory, bool fWipe)
: sqlite::database(fMemory ? ":memory:" : (path / "index.sqlite").string(), sharedConfig)
: sqlite::database(fMemory ? ":memory:" : (path / "db.sqlite").string(), sharedConfig)
{
(*this) << "PRAGMA cache_size=-" + std::to_string(n_cache_size >> 10); // in -KB
(*this) << "PRAGMA synchronous=OFF"; // don't disk sync after transaction commit
(*this) << "PRAGMA journal_mode=MEMORY";
(*this) << "PRAGMA temp_store=MEMORY";
(*this) << "PRAGMA case_sensitive_like=true";
applyPragmas(*this, n_cache_size >> 10); // in -KB
(*this) << "CREATE TABLE IF NOT EXISTS locator (branch BLOB NOT NULL COLLATE BINARY);";
(*this) << "CREATE TABLE IF NOT EXISTS file_pos (file INTEGER NOT NULL, pos INTEGER NOT NULL);";
@ -53,7 +50,7 @@ BaseIndex::DB::DB(const fs::path& path, size_t n_cache_size, bool fMemory, bool
(*this) << "DELETE FROM file_pos";
(*this) << "DELETE FROM block";
}
(*this) << "begin";
(*this) << "BEGIN";
}
bool BaseIndex::DB::ReadBestBlock(CBlockLocator& locator) const
@ -207,11 +204,11 @@ void BaseIndex::ThreadSync()
bool BaseIndex::Commit()
{
if (!CommitInternal() || sqlite::commit(GetDB()) != SQLITE_OK) {
GetDB() << "rollback";
GetDB() << "begin";
GetDB() << "ROLLBACK";
GetDB() << "BEGIN";
return error("%s: Failed to commit latest %s state", __func__, GetName());
}
GetDB() << "begin";
GetDB() << "BEGIN";
return true;
}

View file

@ -50,11 +50,11 @@ BlockFilterIndex::BlockFilterIndex(BlockFilterType filter_type,
const std::string& filter_name = BlockFilterTypeName(filter_type);
if (filter_name.empty()) throw std::invalid_argument("unknown filter_type");
fs::path path = GetDataDir() / "indexes" / "blockfilter" / filter_name;
fs::path path = GetBlocksDir() / "filter" / filter_name;
fs::create_directories(path);
m_name = filter_name + " block filter index";
m_db = MakeUnique<BaseIndex::DB>(path / "db", n_cache_size, f_memory, f_wipe);
m_db = MakeUnique<BaseIndex::DB>(path, n_cache_size, f_memory, f_wipe);
m_filter_fileseq = MakeUnique<FlatFileSeq>(std::move(path), "fltr", FLTR_FILE_CHUNK_SIZE);
}

View file

@ -150,7 +150,6 @@ const CLogCategoryDesc LogCategories[] =
{BCLog::LIBEVENT, "libevent"},
{BCLog::COINDB, "coindb"},
{BCLog::QT, "qt"},
{BCLog::LEVELDB, "leveldb"},
{BCLog::CLAIMS, "claims"},
{BCLog::ALL, "1"},
{BCLog::ALL, "all"},

View file

@ -54,7 +54,6 @@ namespace BCLog {
LIBEVENT = (1 << 17),
COINDB = (1 << 18),
QT = (1 << 19),
LEVELDB = (1 << 20),
CLAIMS = (1 << 30),
ALL = ~(uint32_t)0,
};

View file

@ -5,7 +5,7 @@
#include <txdb.h>
#include <claimtrie/sqlite.h>
#include <claimtrie/trie.h>
#include <key_io.h>
#include <pow.h>
#include <random.h>
@ -28,11 +28,7 @@ static const sqlite::sqlite_config sharedConfig {
CCoinsViewDB::CCoinsViewDB(fs::path ldb_path, size_t nCacheSize, bool fMemory, bool fWipe)
: db(fMemory ? ":memory:" : (ldb_path / "coins.sqlite").string(), sharedConfig)
{
db << "PRAGMA cache_size=-" + std::to_string(nCacheSize >> 10); // in -KB
db << "PRAGMA synchronous=OFF"; // don't disk sync after transaction commit
db << "PRAGMA journal_mode=WAL";
db << "PRAGMA temp_store=MEMORY";
db << "PRAGMA case_sensitive_like=true";
applyPragmas(db, nCacheSize >> 10); // in -KB
db << "CREATE TABLE IF NOT EXISTS unspent (txID BLOB NOT NULL COLLATE BINARY, txN INTEGER NOT NULL, "
"isCoinbase INTEGER NOT NULL, blockHeight INTEGER NOT NULL, amount INTEGER NOT NULL, "
@ -52,7 +48,7 @@ CCoinsViewDB::CCoinsViewDB(fs::path ldb_path, size_t nCacheSize, bool fMemory, b
bool CCoinsViewDB::GetCoin(const COutPoint &outpoint, Coin &coin) const {
auto query = db << "SELECT isCoinbase, blockHeight, amount, script FROM unspent "
"WHERE txID = ? AND txN = ?" << outpoint.hash << outpoint.n;
"WHERE txID = ? AND txN = ?" << outpoint.hash << outpoint.n;
for (auto&& row: query) {
uint32_t coinbase = 0, height = 0;
row >> coinbase >> height >> coin.out.nValue >> coin.out.scriptPubKey;
@ -65,7 +61,7 @@ bool CCoinsViewDB::GetCoin(const COutPoint &outpoint, Coin &coin) const {
bool CCoinsViewDB::HaveCoin(const COutPoint &outpoint) const {
auto query = db << "SELECT 1 FROM unspent "
"WHERE txID = ? AND txN = ?" << outpoint.hash << outpoint.n;
"WHERE txID = ? AND txN = ?" << outpoint.hash << outpoint.n;
return query.begin() != query.end();
}
@ -170,13 +166,9 @@ size_t CCoinsViewDB::EstimateSize() const
}
CBlockTreeDB::CBlockTreeDB(size_t nCacheSize, bool fMemory, bool fWipe)
: db(fMemory ? ":memory:" : (GetDataDir() / "block_index.sqlite").string(), sharedConfig)
: db(fMemory ? ":memory:" : (GetBlocksDir() / "index.sqlite").string(), sharedConfig)
{
db << "PRAGMA cache_size=-" + std::to_string(nCacheSize >> 10); // in -KB
db << "PRAGMA synchronous=OFF"; // don't disk sync after transaction commit
db << "PRAGMA journal_mode=WAL";
db << "PRAGMA temp_store=MEMORY";
db << "PRAGMA case_sensitive_like=true";
applyPragmas(db, nCacheSize >> 10); // in -KB
db << "CREATE TABLE IF NOT EXISTS block_file ("
"file INTEGER NOT NULL PRIMARY KEY, "

View file

@ -1339,11 +1339,10 @@ CAmount GetBlockSubsidy(int nHeight, const Consensus::Params& consensusParams)
}
CoinsViews::CoinsViews(
std::string ldb_name,
size_t cache_size_bytes,
bool in_memory,
bool should_wipe) : m_dbview(
GetDataDir() / ldb_name, cache_size_bytes, in_memory, should_wipe),
GetDataDir(), cache_size_bytes, in_memory, should_wipe),
m_catcherview(&m_dbview) {}
void CoinsViews::InitCache()
@ -1359,11 +1358,9 @@ CChainState::CChainState() : m_blockman(g_blockman) {}
void CChainState::InitCoinsDB(
size_t cache_size_bytes,
bool in_memory,
bool should_wipe,
std::string leveldb_name)
bool should_wipe)
{
m_coins_views = MakeUnique<CoinsViews>(
leveldb_name, cache_size_bytes, in_memory, should_wipe);
m_coins_views = MakeUnique<CoinsViews>(cache_size_bytes, in_memory, should_wipe);
}
void CChainState::InitCoinsCache()

View file

@ -532,7 +532,7 @@ public:
//! state to disk, which should not be done until the health of the database is verified.
//!
//! All arguments forwarded onto CCoinsViewDB.
CoinsViews(std::string ldb_name, size_t cache_size_bytes, bool in_memory, bool should_wipe);
CoinsViews(size_t cache_size_bytes, bool in_memory, bool should_wipe);
//! Initialize the CCoinsViewCache member.
void InitCache() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
@ -602,8 +602,7 @@ public:
void InitCoinsDB(
size_t cache_size_bytes,
bool in_memory,
bool should_wipe,
std::string leveldb_name = "chainstate");
bool should_wipe);
//! Initialize the in-memory coins cache (to be done after the health of the on-disk database
//! is verified).