rippled
RelationalDBInterface_shards.cpp
1 //------------------------------------------------------------------------------
2 /*
3  This file is part of rippled: https://github.com/ripple/rippled
4  Copyright (c) 2020 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 <ripple/app/ledger/AcceptedLedger.h>
21 #include <ripple/app/ledger/LedgerMaster.h>
22 #include <ripple/app/ledger/LedgerToJson.h>
23 #include <ripple/app/rdb/RelationalDBInterface.h>
24 #include <ripple/app/rdb/RelationalDBInterface_shards.h>
25 #include <ripple/basics/BasicConfig.h>
26 #include <ripple/basics/StringUtilities.h>
27 #include <ripple/core/DatabaseCon.h>
28 #include <ripple/core/SociDB.h>
29 #include <ripple/json/to_string.h>
30 #include <boost/algorithm/string.hpp>
31 #include <boost/range/adaptor/transformed.hpp>
32 
33 namespace ripple {
34 
35 DatabasePair
37  Config const& config,
38  DatabaseCon::Setup const& setup,
39  DatabaseCon::CheckpointerSetup const& checkpointerSetup)
40 {
41  // ledger meta database
42  auto lgrMetaDB{std::make_unique<DatabaseCon>(
43  setup,
47  checkpointerSetup)};
48 
49  if (config.useTxTables())
50  {
51  // transaction meta database
52  auto txMetaDB{std::make_unique<DatabaseCon>(
53  setup,
57  checkpointerSetup)};
58 
59  return {std::move(lgrMetaDB), std::move(txMetaDB)};
60  }
61 
62  return {std::move(lgrMetaDB), nullptr};
63 }
64 
65 bool
67  std::shared_ptr<Ledger const> const& ledger,
68  Application& app,
69  soci::session& lgrMetaSession,
70  soci::session& txnMetaSession,
71  std::uint32_t const shardIndex)
72 {
73  std::string_view constexpr lgrSQL =
74  R"sql(INSERT OR REPLACE INTO LedgerMeta VALUES
75  (:ledgerHash,:shardIndex);)sql";
76 
77  auto const hash = to_string(ledger->info().hash);
78  lgrMetaSession << lgrSQL, soci::use(hash), soci::use(shardIndex);
79 
80  if (app.config().useTxTables())
81  {
82  AcceptedLedger::pointer const aLedger = [&app, ledger] {
83  try
84  {
85  auto aLedger =
86  app.getAcceptedLedgerCache().fetch(ledger->info().hash);
87  if (!aLedger)
88  {
89  aLedger = std::make_shared<AcceptedLedger>(ledger, app);
90  app.getAcceptedLedgerCache().canonicalize_replace_client(
91  ledger->info().hash, aLedger);
92  }
93 
94  return aLedger;
95  }
96  catch (std::exception const&)
97  {
98  JLOG(app.journal("Ledger").warn())
99  << "An accepted ledger was missing nodes";
100  }
101 
102  return AcceptedLedger::pointer{nullptr};
103  }();
104 
105  if (!aLedger)
106  return false;
107 
108  soci::transaction tr(txnMetaSession);
109 
110  for (auto const& [_, acceptedLedgerTx] : aLedger->getMap())
111  {
112  (void)_;
113 
114  std::string_view constexpr txnSQL =
115  R"sql(INSERT OR REPLACE INTO TransactionMeta VALUES
116  (:transactionID,:shardIndex);)sql";
117 
118  auto const transactionID =
119  to_string(acceptedLedgerTx->getTransactionID());
120 
121  txnMetaSession << txnSQL, soci::use(transactionID),
122  soci::use(shardIndex);
123  }
124 
125  tr.commit();
126  }
127 
128  return true;
129 }
130 
132 getShardIndexforLedger(soci::session& session, LedgerHash const& hash)
133 {
134  std::uint32_t shardIndex;
135  session << "SELECT ShardIndex FROM LedgerMeta WHERE LedgerHash = '" << hash
136  << "';",
137  soci::into(shardIndex);
138 
139  if (!session.got_data())
140  return std::nullopt;
141 
142  return shardIndex;
143 }
144 
146 getShardIndexforTransaction(soci::session& session, TxID const& id)
147 {
148  std::uint32_t shardIndex;
149  session << "SELECT ShardIndex FROM TransactionMeta WHERE TransID = '" << id
150  << "';",
151  soci::into(shardIndex);
152 
153  if (!session.got_data())
154  return std::nullopt;
155 
156  return shardIndex;
157 }
158 
161  Config const& config,
162  DatabaseCon::Setup const& setup)
163 {
164  auto tx{std::make_unique<DatabaseCon>(
166  tx->getSession() << boost::str(
167  boost::format("PRAGMA cache_size=-%d;") %
168  kilobytes(config.getValueFor(SizedItem::txnDBCache, std::nullopt)));
169 
170  auto lgr{std::make_unique<DatabaseCon>(
172  lgr->getSession() << boost::str(
173  boost::format("PRAGMA cache_size=-%d;") %
174  kilobytes(config.getValueFor(SizedItem::lgrDBCache, std::nullopt)));
175 
176  return {std::move(lgr), std::move(tx)};
177 }
178 
181  Config const& config,
182  DatabaseCon::Setup const& setup,
183  DatabaseCon::CheckpointerSetup const& checkpointerSetup)
184 {
185  // transaction database
186  auto tx{std::make_unique<DatabaseCon>(
187  setup, TxDBName, TxDBPragma, TxDBInit, checkpointerSetup)};
188  tx->getSession() << boost::str(
189  boost::format("PRAGMA cache_size=-%d;") %
191 
192  // ledger database
193  auto lgr{std::make_unique<DatabaseCon>(
194  setup, LgrDBName, LgrDBPragma, LgrDBInit, checkpointerSetup)};
195  lgr->getSession() << boost::str(
196  boost::format("PRAGMA cache_size=-%d;") %
198 
199  return {std::move(lgr), std::move(tx)};
200 }
201 
202 bool
204  soci::session& txsession,
205  soci::session& lgrsession,
206  std::shared_ptr<Ledger const> const& ledger,
207  std::uint32_t index,
208  std::atomic<bool>& stop,
209  beast::Journal j)
210 {
211  auto const ledgerSeq{ledger->info().seq};
212 
213  // Update the transactions database
214  {
215  auto& session{txsession};
216  soci::transaction tr(session);
217 
218  session << "DELETE FROM Transactions "
219  "WHERE LedgerSeq = :seq;",
220  soci::use(ledgerSeq);
221  session << "DELETE FROM AccountTransactions "
222  "WHERE LedgerSeq = :seq;",
223  soci::use(ledgerSeq);
224 
225  if (ledger->info().txHash.isNonZero())
226  {
227  auto const sSeq{std::to_string(ledgerSeq)};
228  if (!ledger->txMap().isValid())
229  {
230  JLOG(j.error())
231  << "shard " << index << " has an invalid transaction map"
232  << " on sequence " << sSeq;
233  return false;
234  }
235 
236  for (auto const& item : ledger->txs)
237  {
238  if (stop)
239  return false;
240 
241  auto const txID{item.first->getTransactionID()};
242  auto const sTxID{to_string(txID)};
243  auto const txMeta{std::make_shared<TxMeta>(
244  txID, ledger->seq(), *item.second)};
245 
246  session << "DELETE FROM AccountTransactions "
247  "WHERE TransID = :txID;",
248  soci::use(sTxID);
249 
250  auto const& accounts = txMeta->getAffectedAccounts(j);
251  if (!accounts.empty())
252  {
253  auto const sTxnSeq{std::to_string(txMeta->getIndex())};
254  auto const s{boost::str(
255  boost::format("('%s','%s',%s,%s)") % sTxID % "%s" %
256  sSeq % sTxnSeq)};
257  std::string sql;
258  sql.reserve((accounts.size() + 1) * 128);
259  sql =
260  "INSERT INTO AccountTransactions "
261  "(TransID, Account, LedgerSeq, TxnSeq) VALUES ";
262  sql += boost::algorithm::join(
263  accounts |
264  boost::adaptors::transformed(
265  [&](AccountID const& accountID) {
266  return boost::str(
267  boost::format(s) %
268  ripple::toBase58(accountID));
269  }),
270  ",");
271  sql += ';';
272  session << sql;
273 
274  JLOG(j.trace())
275  << "shard " << index << " account transaction: " << sql;
276  }
277  else if (!isPseudoTx(*item.first))
278  {
279  // It's okay for pseudo transactions to not affect any
280  // accounts. But otherwise...
281  JLOG(j.warn())
282  << "shard " << index << " transaction in ledger "
283  << sSeq << " affects no accounts";
284  }
285 
286  Serializer s;
287  item.second->add(s);
288  session
290  item.first->getMetaSQL(
291  ledgerSeq, sqlBlobLiteral(s.modData())) +
292  ';');
293  }
294  }
295 
296  tr.commit();
297  }
298 
299  auto const sHash{to_string(ledger->info().hash)};
300 
301  // Update the ledger database
302  {
303  auto& session{lgrsession};
304  soci::transaction tr(session);
305 
306  auto const sParentHash{to_string(ledger->info().parentHash)};
307  auto const sDrops{to_string(ledger->info().drops)};
308  auto const sAccountHash{to_string(ledger->info().accountHash)};
309  auto const sTxHash{to_string(ledger->info().txHash)};
310 
311  session << "DELETE FROM Ledgers "
312  "WHERE LedgerSeq = :seq;",
313  soci::use(ledgerSeq);
314  session << "INSERT OR REPLACE INTO Ledgers ("
315  "LedgerHash, LedgerSeq, PrevHash, TotalCoins, ClosingTime,"
316  "PrevClosingTime, CloseTimeRes, CloseFlags, AccountSetHash,"
317  "TransSetHash)"
318  "VALUES ("
319  ":ledgerHash, :ledgerSeq, :prevHash, :totalCoins,"
320  ":closingTime, :prevClosingTime, :closeTimeRes,"
321  ":closeFlags, :accountSetHash, :transSetHash);",
322  soci::use(sHash), soci::use(ledgerSeq), soci::use(sParentHash),
323  soci::use(sDrops),
324  soci::use(ledger->info().closeTime.time_since_epoch().count()),
325  soci::use(
326  ledger->info().parentCloseTime.time_since_epoch().count()),
327  soci::use(ledger->info().closeTimeResolution.count()),
328  soci::use(ledger->info().closeFlags), soci::use(sAccountHash),
329  soci::use(sTxHash);
330 
331  tr.commit();
332  }
333 
334  return true;
335 }
336 
337 /* Shard acquire db */
338 
341  DatabaseCon::Setup const& setup,
342  DatabaseCon::CheckpointerSetup const& checkpointerSetup)
343 {
344  return std::make_unique<DatabaseCon>(
345  setup,
349  checkpointerSetup);
350 }
351 
352 void
353 insertAcquireDBIndex(soci::session& session, std::uint32_t index)
354 {
355  session << "INSERT INTO Shard (ShardIndex) "
356  "VALUES (:shardIndex);",
357  soci::use(index);
358 }
359 
361 selectAcquireDBLedgerSeqs(soci::session& session, std::uint32_t index)
362 {
363  // resIndex and must be boost::optional (not std) because that's
364  // what SOCI expects in its interface.
365  boost::optional<std::uint32_t> resIndex;
366  soci::blob sociBlob(session);
367  soci::indicator blobPresent;
368 
369  session << "SELECT ShardIndex, StoredLedgerSeqs "
370  "FROM Shard "
371  "WHERE ShardIndex = :index;",
372  soci::into(resIndex), soci::into(sociBlob, blobPresent),
373  soci::use(index);
374 
375  if (!resIndex || index != resIndex)
376  return {false, {}};
377 
378  if (blobPresent != soci::i_ok)
379  return {true, {}};
380 
381  std::string s;
382  convert(sociBlob, s);
383 
384  return {true, s};
385 }
386 
388 selectAcquireDBLedgerSeqsHash(soci::session& session, std::uint32_t index)
389 {
390  // resIndex and sHash0 must be boost::optional (not std) because that's
391  // what SOCI expects in its interface.
392  boost::optional<std::uint32_t> resIndex;
393  boost::optional<std::string> sHash0;
394  soci::blob sociBlob(session);
395  soci::indicator blobPresent;
396 
397  session << "SELECT ShardIndex, LastLedgerHash, StoredLedgerSeqs "
398  "FROM Shard "
399  "WHERE ShardIndex = :index;",
400  soci::into(resIndex), soci::into(sHash0),
401  soci::into(sociBlob, blobPresent), soci::use(index);
402 
404  (sHash0 ? *sHash0 : std::optional<std::string>());
405 
406  if (!resIndex || index != resIndex)
407  return {false, {{}, {}}};
408 
409  if (blobPresent != soci::i_ok)
410  return {true, {{}, sHash}};
411 
412  std::string s;
413  convert(sociBlob, s);
414 
415  return {true, {s, sHash}};
416 }
417 
418 void
420  soci::session& session,
421  std::shared_ptr<Ledger const> const& ledger,
422  std::uint32_t index,
423  std::uint32_t lastSeq,
424  std::optional<std::string> const& seqs)
425 {
426  soci::blob sociBlob(session);
427  auto const sHash{to_string(ledger->info().hash)};
428 
429  if (seqs)
430  convert(*seqs, sociBlob);
431 
432  if (ledger->info().seq == lastSeq)
433  {
434  // Store shard's last ledger hash
435  session << "UPDATE Shard "
436  "SET LastLedgerHash = :lastLedgerHash,"
437  "StoredLedgerSeqs = :storedLedgerSeqs "
438  "WHERE ShardIndex = :shardIndex;",
439  soci::use(sHash), soci::use(sociBlob), soci::use(index);
440  }
441  else
442  {
443  session << "UPDATE Shard "
444  "SET StoredLedgerSeqs = :storedLedgerSeqs "
445  "WHERE ShardIndex = :shardIndex;",
446  soci::use(sociBlob), soci::use(index);
447  }
448 }
449 
450 /* Archive DB */
451 
453 makeArchiveDB(boost::filesystem::path const& dir, std::string const& dbName)
454 {
455  return std::make_unique<DatabaseCon>(
457 }
458 
459 void
461  DatabaseCon& db,
462  std::function<void(std::string const&, int)> const& func)
463 {
464  soci::rowset<soci::row> rs =
465  (db.getSession().prepare << "SELECT * FROM State;");
466 
467  for (auto it = rs.begin(); it != rs.end(); ++it)
468  {
469  func(it->get<std::string>(1), it->get<int>(0));
470  }
471 }
472 
473 void
475  DatabaseCon& db,
476  std::uint32_t shardIndex,
477  std::string const& url)
478 {
479  db.getSession() << "INSERT INTO State VALUES (:index, :url);",
480  soci::use(shardIndex), soci::use(url);
481 }
482 
483 void
485 {
486  db.getSession() << "DELETE FROM State WHERE ShardIndex = :index;",
487  soci::use(shardIndex);
488 }
489 
490 void
492 {
493  db.getSession() << "DROP TABLE State;";
494 }
495 
496 } // namespace ripple
ripple::AcquireShardDBPragma
constexpr std::array< char const *, 1 > AcquireShardDBPragma
Definition: DBInit.h:168
ripple::Application
Definition: Application.h:103
ripple::AcquireShardDBName
constexpr auto AcquireShardDBName
Definition: DBInit.h:166
ripple::SHAMap::isValid
bool isValid() const
Definition: SHAMap.h:580
ripple::makeAcquireDB
std::unique_ptr< DatabaseCon > makeAcquireDB(DatabaseCon::Setup const &setup, DatabaseCon::CheckpointerSetup const &checkpointerSetup)
makeAcquireDB Opens shard acquire DB and returns its descriptor.
Definition: RelationalDBInterface_shards.cpp:338
ripple::Application::getAcceptedLedgerCache
virtual TaggedCache< uint256, AcceptedLedger > & getAcceptedLedgerCache()=0
std::string
STL class.
std::shared_ptr
STL class.
ripple::LedgerInfo::parentHash
uint256 parentHash
Definition: ReadView.h:103
std::exception
STL class.
ripple::base_uint::isNonZero
bool isNonZero() const
Definition: base_uint.h:513
ripple::DatabaseCon::Setup
Definition: DatabaseCon.h:84
beast::Journal::trace
Stream trace() const
Severity stream access functions.
Definition: Journal.h:309
ripple::LgrMetaDBInit
constexpr std::array< char const *, 3 > LgrMetaDBInit
Definition: DBInit.h:129
std::string_view
STL class.
ripple::Serializer::modData
Blob & modData()
Definition: Serializer.h:178
std::pair
std::string::reserve
T reserve(T... args)
ripple::LedgerInfo::hash
uint256 hash
Definition: ReadView.h:100
ripple::convert
void convert(soci::blob &from, std::vector< std::uint8_t > &to)
Definition: SociDB.cpp:154
ripple::selectAcquireDBLedgerSeqsHash
std::pair< bool, AcquireShardSeqsHash > selectAcquireDBLedgerSeqsHash(soci::session &session, std::uint32_t index)
selectAcquireDBLedgerSeqsHash Returns set of acquired ledgers and hash for given shard.
Definition: RelationalDBInterface_shards.cpp:386
ripple::insertAcquireDBIndex
void insertAcquireDBIndex(soci::session &session, std::uint32_t index)
insertAcquireDBIndex Adds new shard index to shard acquire DB.
Definition: RelationalDBInterface_shards.cpp:351
ripple::toBase58
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
Definition: AccountID.cpp:29
ripple::DatabaseCon::CheckpointerSetup
Definition: DatabaseCon.h:107
beast::Journal::warn
Stream warn() const
Definition: Journal.h:327
ripple::kilobytes
constexpr auto kilobytes(T value) noexcept
Definition: ByteUtilities.h:27
ripple::AcquireShardDBInit
constexpr std::array< char const *, 1 > AcquireShardDBInit
Definition: DBInit.h:171
ripple::ShardArchiveHandlerDBInit
static constexpr std::array< char const *, 3 > ShardArchiveHandlerDBInit
Definition: DBInit.h:228
ripple::STTx::getMetaSQLInsertReplaceHeader
static std::string const & getMetaSQLInsertReplaceHeader()
Definition: STTx.cpp:231
std::function
ripple::LedgerInfo::seq
LedgerIndex seq
Definition: ReadView.h:92
ripple::LedgerInfo::txHash
uint256 txHash
Definition: ReadView.h:101
ripple::LgrDBInit
constexpr std::array< char const *, 5 > LgrDBInit
Definition: DBInit.h:48
ripple::TxMetaDBPragma
constexpr std::array TxMetaDBPragma
Definition: DBInit.h:145
ripple::LgrMetaDBName
constexpr auto LgrMetaDBName
Definition: DBInit.h:118
ripple::LedgerInfo::closeTime
NetClock::time_point closeTime
Definition: ReadView.h:123
ripple::DownloaderDBPragma
static constexpr std::array< char const *, 2 > DownloaderDBPragma
Definition: DBInit.h:225
ripple::TxDBName
constexpr auto TxDBName
Definition: DBInit.h:73
ripple::base_uint< 256 >
ripple::updateAcquireDB
void updateAcquireDB(soci::session &session, std::shared_ptr< Ledger const > const &ledger, std::uint32_t index, std::uint32_t lastSeq, std::optional< std::string > const &seqs)
updateAcquireDB Updates information in acquire DB.
Definition: RelationalDBInterface_shards.cpp:417
ripple::Ledger::info
LedgerInfo const & info() const override
Returns information about the ledger.
Definition: Ledger.h:148
std::chrono::time_point::time_since_epoch
T time_since_epoch(T... args)
ripple::isPseudoTx
bool isPseudoTx(STObject const &tx)
Check whether a transaction is a pseudo-transaction.
Definition: STTx.cpp:539
ripple::Config::getValueFor
int getValueFor(SizedItem item, std::optional< std::size_t > node=std::nullopt) const
Retrieve the default value for the item at the specified node size.
Definition: Config.cpp:931
ripple::TxMetaDBName
constexpr auto TxMetaDBName
Definition: DBInit.h:142
ripple::LgrDBPragma
constexpr std::array< char const *, 1 > LgrDBPragma
Definition: DBInit.h:45
ripple::Config
Definition: Config.h:68
ripple::deleteFromArchiveDB
void deleteFromArchiveDB(DatabaseCon &db, std::uint32_t shardIndex)
deleteFromArchiveDB Deletes entry from shard archive DB.
Definition: RelationalDBInterface_shards.cpp:482
ripple::Application::config
virtual Config & config()=0
ripple::Config::useTxTables
bool useTxTables() const
Definition: Config.h:282
ripple::LedgerInfo::closeFlags
int closeFlags
Definition: ReadView.h:114
std::to_string
T to_string(T... args)
ripple::dropArchiveDB
void dropArchiveDB(DatabaseCon &db)
dropArchiveDB Removes table in shard archive DB.
Definition: RelationalDBInterface_shards.cpp:489
beast::Journal::error
Stream error() const
Definition: Journal.h:333
ripple::TxMetaDBInit
constexpr std::array< char const *, 3 > TxMetaDBInit
Definition: DBInit.h:153
ripple::SizedItem::lgrDBCache
@ lgrDBCache
ripple::HashPrefix::transactionID
@ transactionID
transaction plus signature to give transaction ID
beast::Journal
A generic endpoint for log messages.
Definition: Journal.h:58
std::uint32_t
std::atomic< bool >
ripple::DatabasePair
Definition: RelationalDBInterface_shards.h:31
ripple::SizedItem::txnDBCache
@ txnDBCache
ripple::FinalShardDBPragma
constexpr std::array< char const *, 2 > FinalShardDBPragma
Definition: DBInit.h:182
ripple::LedgerInfo::drops
XRPAmount drops
Definition: ReadView.h:105
ripple::Serializer
Definition: Serializer.h:39
ripple::DatabaseCon::getSession
soci::session & getSession()
Definition: DatabaseCon.h:172
ripple::Ledger::txMap
SHAMap const & txMap() const
Definition: Ledger.h:319
ripple::updateLedgerDBs
bool updateLedgerDBs(soci::session &txsession, soci::session &lgrsession, std::shared_ptr< Ledger const > const &ledger, std::uint32_t index, std::atomic< bool > &stop, beast::Journal j)
updateLedgerDBs Save given ledger to shard databases.
Definition: RelationalDBInterface_shards.cpp:201
ripple::LgrMetaDBPragma
constexpr std::array LgrMetaDBPragma
Definition: DBInit.h:121
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::Application::journal
virtual beast::Journal journal(std::string const &name)=0
ripple::readArchiveDB
void readArchiveDB(DatabaseCon &db, std::function< void(std::string const &, int)> const &func)
readArchiveDB Read entries from shard archive database and calls fiven callback for each entry.
Definition: RelationalDBInterface_shards.cpp:458
ripple::ReadView::seq
LedgerIndex seq() const
Returns the sequence number of the base ledger.
Definition: ReadView.h:260
ripple::LedgerInfo::closeTimeResolution
NetClock::duration closeTimeResolution
Definition: ReadView.h:117
ripple::makeMetaDBs
DatabasePair makeMetaDBs(Config const &config, DatabaseCon::Setup const &setup, DatabaseCon::CheckpointerSetup const &checkpointerSetup)
makeMetaDBs Opens ledger and transaction 'meta' databases which map ledger hashes and transaction IDs...
Definition: RelationalDBInterface_shards.cpp:36
ripple::DatabaseCon
Definition: DatabaseCon.h:81
ripple::TxDBPragma
constexpr std::array TxDBPragma
Definition: DBInit.h:76
std::chrono::duration::count
T count(T... args)
ripple::saveLedgerMeta
bool saveLedgerMeta(std::shared_ptr< Ledger const > const &ledger, Application &app, soci::session &lgrMetaSession, soci::session &txnMetaSession, std::uint32_t const shardIndex)
saveLedgerMeta Stores (transaction ID -> shard index) and (ledger hash -> shard index) mappings in th...
Definition: RelationalDBInterface_shards.cpp:66
ripple::makeShardIncompleteLedgerDBs
DatabasePair makeShardIncompleteLedgerDBs(Config const &config, DatabaseCon::Setup const &setup, DatabaseCon::CheckpointerSetup const &checkpointerSetup)
makeShardIncompleteLedgerDBs Opens shard databases for not fully downloaded or verified shard and ret...
Definition: RelationalDBInterface_shards.cpp:178
std::optional< std::uint32_t >
ripple::to_string
std::string to_string(Manifest const &m)
Format the specified manifest to a string for debugging purposes.
Definition: app/misc/impl/Manifest.cpp:39
ripple::insertArchiveDB
void insertArchiveDB(DatabaseCon &db, std::uint32_t shardIndex, std::string const &url)
insertArchiveDB Adds entry to shard archive database.
Definition: RelationalDBInterface_shards.cpp:472
ripple::selectAcquireDBLedgerSeqs
std::pair< bool, std::optional< std::string > > selectAcquireDBLedgerSeqs(soci::session &session, std::uint32_t index)
selectAcquireDBLedgerSeqs Returns set of acquired ledgers for given shard.
Definition: RelationalDBInterface_shards.cpp:359
ripple::TxDBInit
constexpr std::array< char const *, 8 > TxDBInit
Definition: DBInit.h:84
ripple::makeArchiveDB
std::unique_ptr< DatabaseCon > makeArchiveDB(boost::filesystem::path const &dir, std::string const &dbName)
makeArchiveDB Opens shard archive DB and returns its descriptor.
Definition: RelationalDBInterface_shards.cpp:451
ripple::getShardIndexforTransaction
std::optional< std::uint32_t > getShardIndexforTransaction(soci::session &session, TxID const &id)
getShardIndexforTransaction Queries the transaction meta database to retrieve the index of the shard ...
Definition: RelationalDBInterface_shards.cpp:144
std::unique_ptr
STL class.
ripple::sqlBlobLiteral
std::string sqlBlobLiteral(Blob const &blob)
Format arbitrary binary data as an SQLite "blob literal".
Definition: StringUtilities.cpp:33
ripple::LedgerInfo::accountHash
uint256 accountHash
Definition: ReadView.h:102
ripple::ReadView::txs
txs_type txs
Definition: ReadView.h:390
ripple::makeShardCompleteLedgerDBs
DatabasePair makeShardCompleteLedgerDBs(Config const &config, DatabaseCon::Setup const &setup)
makeShardCompleteLedgerDBs Opens shard databases for already verified shard and returns its descripto...
Definition: RelationalDBInterface_shards.cpp:158
ripple::LedgerInfo::parentCloseTime
NetClock::time_point parentCloseTime
Definition: ReadView.h:93
ripple::LgrDBName
constexpr auto LgrDBName
Definition: DBInit.h:43
ripple::getShardIndexforLedger
std::optional< std::uint32_t > getShardIndexforLedger(soci::session &session, LedgerHash const &hash)
getShardIndexforLedger Queries the ledger meta database to retrieve the index of the shard that conta...
Definition: RelationalDBInterface_shards.cpp:130