xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
libxrpl
server
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
15
namespace
xrpl
{
16
17
bool
18
doVacuumDB
(
DatabaseCon::Setup
const
& setup,
beast::Journal
j)
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
std::cerr
beast::Journal
A generic endpoint for log messages.
Definition
Journal.h:44
std::cout
cstdint
std::endl
T endl(T... args)
std::filesystem::file_size
T file_size(T... args)
filesystem
std::uint32_t
iostream
std::make_unique
T make_unique(T... args)
memory
xrpl
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition
algorithm.h:5
xrpl::doVacuumDB
bool doVacuumDB(DatabaseCon::Setup const &setup, beast::Journal j)
doVacuumDB Creates, initialises, and performs cleanup on a database.
Definition
Vacuum.cpp:18
xrpl::kTxDbInit
constexpr std::array< char const *, 8 > kTxDbInit
Definition
DBInit.h:75
xrpl::commonDbPragmaTemp
std::string commonDbPragmaTemp(std::string_view tempStore)
Definition
DBInit.h:33
xrpl::kTxDbName
constexpr auto kTxDbName
Definition
DBInit.h:73
std::filesystem::path::parent_path
T parent_path(T... args)
std::filesystem::path
std::filesystem::space
T space(T... args)
std::filesystem::path::string
T string(T... args)
xrpl::DatabaseCon::Setup
Definition
DatabaseCon.h:77
xrpl::DatabaseCon::Setup::txPragma
std::array< std::string, 4 > txPragma
Definition
DatabaseCon.h:98
xrpl::DatabaseCon::Setup::globalPragma
static std::unique_ptr< std::vector< std::string > const > globalPragma
Definition
DatabaseCon.h:97
xrpl::DatabaseCon::Setup::dataDir
std::filesystem::path dataDir
Definition
DatabaseCon.h:82
Generated by
1.17.0