xrpld
Loading...
Searching...
No Matches
Vacuum.cpp
1#include <xrpl/server/Vacuum.h>
2
3#include <xrpl/beast/utility/Journal.h>
4#include <xrpl/beast/utility/instrumentation.h>
5#include <xrpl/rdb/DBInit.h>
6#include <xrpl/rdb/DatabaseCon.h>
7
8#include <soci/into.h>
9
10#include <cstdint>
11#include <filesystem>
12#include <iostream>
13#include <memory>
14
15namespace xrpl {
16
17bool
19{
20 std::filesystem::path const dbPath = setup.dataDir / kTxDbName;
21
22 uintmax_t const dbSize = std::filesystem::file_size(dbPath);
23 XRPL_ASSERT(dbSize != static_cast<uintmax_t>(-1), "xrpl::doVacuumDB : file_size succeeded");
24
25 if (auto available = std::filesystem::space(dbPath.parent_path()).available; available < dbSize)
26 {
27 std::cerr << "The database filesystem must have at least as "
28 "much free space as the size of "
29 << dbPath.string() << ", which is " << dbSize << " bytes. Only " << available
30 << " bytes are available.\n";
31 return false;
32 }
33
34 auto txnDB = std::make_unique<DatabaseCon>(setup, kTxDbName, setup.txPragma, kTxDbInit, j);
35 auto& session = txnDB->getSession();
36 std::uint32_t pageSize = 0;
37
38 // Only the most trivial databases will fit in memory on typical
39 // (recommended) hardware. Force temp files to be written to disk
40 // regardless of the config settings.
41 session << commonDbPragmaTemp("file");
42 session << "PRAGMA page_size;", soci::into(pageSize);
43
44 std::cout << "VACUUM beginning. page_size: " << pageSize << std::endl;
45
46 session << "VACUUM;";
47 XRPL_ASSERT(setup.globalPragma, "xrpl::doVacuumDB : non-null global pragma");
48 for (auto const& p : *setup.globalPragma)
49 session << p;
50 session << "PRAGMA page_size;", soci::into(pageSize);
51
52 std::cout << "VACUUM finished. page_size: " << pageSize << std::endl;
53
54 return true;
55}
56
57} // namespace xrpl
A generic endpoint for log messages.
Definition Journal.h:44
T endl(T... args)
T file_size(T... args)
T make_unique(T... args)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
bool doVacuumDB(DatabaseCon::Setup const &setup, beast::Journal j)
doVacuumDB Creates, initialises, and performs cleanup on a database.
Definition Vacuum.cpp:18
constexpr std::array< char const *, 8 > kTxDbInit
Definition DBInit.h:75
std::string commonDbPragmaTemp(std::string_view tempStore)
Definition DBInit.h:33
constexpr auto kTxDbName
Definition DBInit.h:73
T parent_path(T... args)
T space(T... args)
std::array< std::string, 4 > txPragma
Definition DatabaseCon.h:98
static std::unique_ptr< std::vector< std::string > const > globalPragma
Definition DatabaseCon.h:97
std::filesystem::path dataDir
Definition DatabaseCon.h:82