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 <boost/filesystem/operations.hpp>
9#include <boost/filesystem/path.hpp>
10#include <boost/format.hpp> // IWYU pragma: keep
11
12#include <soci/into.h>
13
14#include <cstdint>
15#include <iostream>
16#include <memory>
17
18namespace xrpl {
19
20bool
22{
23 boost::filesystem::path const dbPath = setup.dataDir / kTxDbName;
24
25 uintmax_t const dbSize = file_size(dbPath);
26 XRPL_ASSERT(dbSize != static_cast<uintmax_t>(-1), "xrpl::doVacuumDB : file_size succeeded");
27
28 if (auto available = space(dbPath.parent_path()).available; available < dbSize)
29 {
30 std::cerr << "The database filesystem must have at least as "
31 "much free space as the size of "
32 << dbPath.string() << ", which is " << dbSize << " bytes. Only " << available
33 << " bytes are available.\n";
34 return false;
35 }
36
37 auto txnDB = std::make_unique<DatabaseCon>(setup, kTxDbName, setup.txPragma, kTxDbInit, j);
38 auto& session = txnDB->getSession();
39 std::uint32_t pageSize = 0;
40
41 // Only the most trivial databases will fit in memory on typical
42 // (recommended) hardware. Force temp files to be written to disk
43 // regardless of the config settings.
44 session << boost::format(kCommonDbPragmaTemp) % "file";
45 session << "PRAGMA page_size;", soci::into(pageSize);
46
47 std::cout << "VACUUM beginning. page_size: " << pageSize << std::endl;
48
49 session << "VACUUM;";
50 XRPL_ASSERT(setup.globalPragma, "xrpl::doVacuumDB : non-null global pragma");
51 for (auto const& p : *setup.globalPragma)
52 session << p;
53 session << "PRAGMA page_size;", soci::into(pageSize);
54
55 std::cout << "VACUUM finished. page_size: " << pageSize << std::endl;
56
57 return true;
58}
59
60} // namespace xrpl
A generic endpoint for log messages.
Definition Journal.h:38
T endl(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:21
constexpr std::array< char const *, 8 > kTxDbInit
Definition DBInit.h:52
constexpr char const * kCommonDbPragmaTemp
Definition DBInit.h:14
constexpr auto kTxDbName
Definition DBInit.h:50
std::array< std::string, 4 > txPragma
Definition DatabaseCon.h:91
static std::unique_ptr< std::vector< std::string > const > globalPragma
Definition DatabaseCon.h:90
boost::filesystem::path dataDir
Definition DatabaseCon.h:75