rippled
Loading...
Searching...
No Matches
Vacuum.cpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2021 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#include <xrpld/app/rdb/Vacuum.h>
21
22#include <boost/format.hpp>
23
24namespace ripple {
25
26bool
28{
29 boost::filesystem::path dbPath = setup.dataDir / TxDBName;
30
31 uintmax_t const dbSize = file_size(dbPath);
32 XRPL_ASSERT(
33 dbSize != static_cast<uintmax_t>(-1),
34 "ripple:doVacuumDB : file_size succeeded");
35
36 if (auto available = space(dbPath.parent_path()).available;
37 available < dbSize)
38 {
39 std::cerr << "The database filesystem must have at least as "
40 "much free space as the size of "
41 << dbPath.string() << ", which is " << dbSize
42 << " bytes. Only " << available << " bytes are available.\n";
43 return false;
44 }
45
47 setup, TxDBName, setup.txPragma, TxDBInit, j);
48 auto& session = txnDB->getSession();
49 std::uint32_t pageSize;
50
51 // Only the most trivial databases will fit in memory on typical
52 // (recommended) hardware. Force temp files to be written to disk
53 // regardless of the config settings.
54 session << boost::format(CommonDBPragmaTemp) % "file";
55 session << "PRAGMA page_size;", soci::into(pageSize);
56
57 std::cout << "VACUUM beginning. page_size: " << pageSize << std::endl;
58
59 session << "VACUUM;";
60 XRPL_ASSERT(
61 setup.globalPragma, "ripple:doVacuumDB : non-null global pragma");
62 for (auto const& p : *setup.globalPragma)
63 session << p;
64 session << "PRAGMA page_size;", soci::into(pageSize);
65
66 std::cout << "VACUUM finished. page_size: " << pageSize << std::endl;
67
68 return true;
69}
70
71} // namespace ripple
A generic endpoint for log messages.
Definition Journal.h:60
T endl(T... args)
T is_same_v
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25
constexpr std::array< char const *, 8 > TxDBInit
Definition DBInit.h:72
constexpr char const * CommonDBPragmaTemp
Definition DBInit.h:34
constexpr auto TxDBName
Definition DBInit.h:70
bool doVacuumDB(DatabaseCon::Setup const &setup, beast::Journal j)
doVacuumDB Creates, initialises, and performs cleanup on a database.
Definition Vacuum.cpp:27
boost::filesystem::path dataDir
Definition DatabaseCon.h:94
static std::unique_ptr< std::vector< std::string > const > globalPragma
std::array< std::string, 4 > txPragma