rippled
SHAMapStoreImp.cpp
1 //------------------------------------------------------------------------------
2 /*
3  This file is part of rippled: https://github.com/ripple/rippled
4  Copyright (c) 2012, 2013 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/TransactionMaster.h>
21 #include <ripple/app/misc/NetworkOPs.h>
22 #include <ripple/app/misc/SHAMapStoreImp.h>
23 #include <ripple/app/rdb/State.h>
24 #include <ripple/app/rdb/backend/SQLiteDatabase.h>
25 #include <ripple/beast/core/CurrentThreadName.h>
26 #include <ripple/core/ConfigSections.h>
27 #include <ripple/core/Pg.h>
28 #include <ripple/nodestore/impl/DatabaseRotatingImp.h>
29 
30 #include <ripple/nodestore/Scheduler.h>
31 
32 #include <boost/algorithm/string/predicate.hpp>
33 
34 namespace ripple {
35 void
37  BasicConfig const& config,
38  std::string const& dbName)
39 {
40  std::lock_guard lock(mutex_);
41  initStateDB(sqlDb_, config, dbName);
42 }
43 
46 {
47  std::lock_guard lock(mutex_);
48 
49  return ripple::getCanDelete(sqlDb_);
50 }
51 
54 {
55  std::lock_guard lock(mutex_);
56 
57  return ripple::setCanDelete(sqlDb_, canDelete);
58 }
59 
62 {
63  std::lock_guard lock(mutex_);
64 
65  return ripple::getSavedState(sqlDb_);
66 }
67 
68 void
70 {
71  std::lock_guard lock(mutex_);
72  ripple::setSavedState(sqlDb_, state);
73 }
74 
75 void
77 {
78  std::lock_guard lock(mutex_);
79  ripple::setLastRotated(sqlDb_, seq);
80 }
81 
82 //------------------------------------------------------------------------------
83 
85  Application& app,
86  NodeStore::Scheduler& scheduler,
87  beast::Journal journal)
88  : app_(app)
89  , scheduler_(scheduler)
90  , journal_(journal)
91  , working_(true)
92  , canDelete_(std::numeric_limits<LedgerIndex>::max())
93 {
94  Config& config{app.config()};
95 
96  Section& section{config.section(ConfigSection::nodeDatabase())};
97  if (section.empty())
98  {
99  Throw<std::runtime_error>(
100  "Missing [" + ConfigSection::nodeDatabase() +
101  "] entry in configuration file");
102  }
103 
104  // RocksDB only. Use sensible defaults if no values specified.
105  if (boost::iequals(get(section, "type"), "RocksDB"))
106  {
107  if (!section.exists("cache_mb"))
108  {
109  section.set(
110  "cache_mb",
111  std::to_string(config.getValueFor(SizedItem::hashNodeDBCache)));
112  }
113 
114  if (!section.exists("filter_bits") && (config.NODE_SIZE >= 2))
115  section.set("filter_bits", "10");
116  }
117 
118  get_if_exists(section, "online_delete", deleteInterval_);
119 
120  if (deleteInterval_)
121  {
122  if (app_.config().reporting())
123  {
124  Throw<std::runtime_error>(
125  "Reporting does not support online_delete. Remove "
126  "online_delete info from config");
127  }
128 
129  // Configuration that affects the behavior of online delete
130  get_if_exists(section, "delete_batch", deleteBatch_);
131  std::uint32_t temp;
132  if (get_if_exists(section, "back_off_milliseconds", temp) ||
133  // Included for backward compaibility with an undocumented setting
134  get_if_exists(section, "backOff", temp))
135  {
137  }
138  if (get_if_exists(section, "age_threshold_seconds", temp))
140  if (get_if_exists(section, "recovery_wait_seconds", temp))
142 
143  get_if_exists(section, "advisory_delete", advisoryDelete_);
144 
145  auto const minInterval = config.standalone()
148  if (deleteInterval_ < minInterval)
149  {
150  Throw<std::runtime_error>(
151  "online_delete must be at least " +
152  std::to_string(minInterval));
153  }
154 
155  if (config.LEDGER_HISTORY > deleteInterval_)
156  {
157  Throw<std::runtime_error>(
158  "online_delete must not be less than ledger_history "
159  "(currently " +
160  std::to_string(config.LEDGER_HISTORY) + ")");
161  }
162 
163  state_db_.init(config, dbName_);
164  dbPaths();
165  }
166 }
167 
170 {
172 
173  // Provide default values:
174  if (!nscfg.exists("cache_size"))
175  nscfg.set(
176  "cache_size",
178  SizedItem::treeCacheSize, std::nullopt)));
179 
180  if (!nscfg.exists("cache_age"))
181  nscfg.set(
182  "cache_age",
184  SizedItem::treeCacheAge, std::nullopt)));
185 
187 
188  if (deleteInterval_)
189  {
190  if (app_.config().reporting())
191  {
192  Throw<std::runtime_error>(
193  "Reporting does not support online_delete. Remove "
194  "online_delete info from config");
195  }
196  SavedState state = state_db_.getState();
197  auto writableBackend = makeBackendRotating(state.writableDb);
198  auto archiveBackend = makeBackendRotating(state.archiveDb);
199  if (!state.writableDb.size())
200  {
201  state.writableDb = writableBackend->getName();
202  state.archiveDb = archiveBackend->getName();
203  state_db_.setState(state);
204  }
205 
206  // Create NodeStore with two backends to allow online deletion of
207  // data
208  auto dbr = std::make_unique<NodeStore::DatabaseRotatingImp>(
209  scheduler_,
210  readThreads,
211  std::move(writableBackend),
212  std::move(archiveBackend),
213  nscfg,
215  fdRequired_ += dbr->fdRequired();
216  dbRotating_ = dbr.get();
217  db.reset(dynamic_cast<NodeStore::Database*>(dbr.release()));
218  }
219  else
220  {
222  megabytes(
223  app_.config().getValueFor(SizedItem::burstSize, std::nullopt)),
224  scheduler_,
225  readThreads,
226  nscfg,
228  fdRequired_ += db->fdRequired();
229  }
230  return db;
231 }
232 
233 void
235 {
236  {
237  std::lock_guard lock(mutex_);
238  newLedger_ = ledger;
239  working_ = true;
240  }
241  cond_.notify_one();
242 }
243 
244 void
246 {
247  if (!working_)
248  return;
249 
251  rendezvous_.wait(lock, [&] { return !working_; });
252 }
253 
254 int
256 {
257  return fdRequired_;
258 }
259 
260 bool
262 {
263  // Copy a single record from node to dbRotating_
265  node.getHash().as_uint256(),
266  0,
268  true);
269  if (!(++nodeCount % checkHealthInterval_))
270  {
271  if (stopping())
272  return false;
273  }
274 
275  return true;
276 }
277 
278 void
280 {
281  if (app_.config().reporting())
282  {
283  assert(false);
284  Throw<std::runtime_error>(
285  "Reporting does not support online_delete. Remove "
286  "online_delete info from config");
287  }
288  beast::setCurrentThreadName("SHAMapStore");
289  LedgerIndex lastRotated = state_db_.getState().lastRotated;
290  netOPs_ = &app_.getOPs();
294 
295  if (advisoryDelete_)
297 
298  while (true)
299  {
300  healthy_ = true;
301  std::shared_ptr<Ledger const> validatedLedger;
302 
303  {
305  working_ = false;
307  if (stop_)
308  {
309  return;
310  }
311  cond_.wait(lock);
312  if (newLedger_)
313  {
314  validatedLedger = std::move(newLedger_);
315  }
316  else
317  continue;
318  }
319 
320  LedgerIndex const validatedSeq = validatedLedger->info().seq;
321  if (!lastRotated)
322  {
323  lastRotated = validatedSeq;
324  state_db_.setLastRotated(lastRotated);
325  }
326 
327  bool const readyToRotate =
328  validatedSeq >= lastRotated + deleteInterval_ &&
329  canDelete_ >= lastRotated - 1 && !stopping();
330 
331  // Make sure we don't delete ledgers currently being
332  // imported into the ShardStore
333  bool const waitForImport = readyToRotate && [this, lastRotated] {
334  if (auto shardStore = app_.getShardStore())
335  {
336  if (auto sequence = shardStore->getDatabaseImportSequence())
337  return sequence <= lastRotated - 1;
338  }
339 
340  return false;
341  }();
342 
343  if (waitForImport)
344  {
345  JLOG(journal_.info())
346  << "NOT rotating validatedSeq " << validatedSeq
347  << " as rotation would interfere with ShardStore import";
348  }
349 
350  // will delete up to (not including) lastRotated
351  if (readyToRotate && !waitForImport)
352  {
353  JLOG(journal_.warn())
354  << "rotating validatedSeq " << validatedSeq << " lastRotated "
355  << lastRotated << " deleteInterval " << deleteInterval_
356  << " canDelete_ " << canDelete_ << " state "
357  << app_.getOPs().strOperatingMode(false) << " age "
359 
360  clearPrior(lastRotated);
361  if (stopping())
362  return;
363 
364  JLOG(journal_.debug()) << "copying ledger " << validatedSeq;
365  std::uint64_t nodeCount = 0;
366  validatedLedger->stateMap().snapShot(false)->visitNodes(std::bind(
368  this,
369  std::ref(nodeCount),
370  std::placeholders::_1));
371  if (stopping())
372  return;
373  // Only log if we completed without a "health" abort
374  JLOG(journal_.debug()) << "copied ledger " << validatedSeq
375  << " nodecount " << nodeCount;
376 
377  JLOG(journal_.debug()) << "freshening caches";
378  freshenCaches();
379  if (stopping())
380  return;
381  // Only log if we completed without a "health" abort
382  JLOG(journal_.debug()) << validatedSeq << " freshened caches";
383 
384  JLOG(journal_.trace()) << "Making a new backend";
385  auto newBackend = makeBackendRotating();
386  JLOG(journal_.debug())
387  << validatedSeq << " new backend " << newBackend->getName();
388 
389  clearCaches(validatedSeq);
390  if (stopping())
391  return;
392 
393  lastRotated = validatedSeq;
394 
396  [&](std::string const& writableBackendName) {
397  SavedState savedState;
398  savedState.writableDb = newBackend->getName();
399  savedState.archiveDb = writableBackendName;
400  savedState.lastRotated = lastRotated;
401  state_db_.setState(savedState);
402 
403  clearCaches(validatedSeq);
404 
405  return std::move(newBackend);
406  });
407 
408  JLOG(journal_.warn()) << "finished rotation " << validatedSeq;
409  }
410  }
411 }
412 
413 void
415 {
417  boost::filesystem::path dbPath = get(section, "path");
418 
419  if (boost::filesystem::exists(dbPath))
420  {
421  if (!boost::filesystem::is_directory(dbPath))
422  {
423  journal_.error()
424  << "node db path must be a directory. " << dbPath.string();
425  Throw<std::runtime_error>("node db path must be a directory.");
426  }
427  }
428  else
429  {
430  boost::filesystem::create_directories(dbPath);
431  }
432 
433  SavedState state = state_db_.getState();
434 
435  {
436  auto update = [&dbPath](std::string& sPath) {
437  if (sPath.empty())
438  return false;
439 
440  // Check if configured "path" matches stored directory path
441  using namespace boost::filesystem;
442  auto const stored{path(sPath)};
443  if (stored.parent_path() == dbPath)
444  return false;
445 
446  sPath = (dbPath / stored.filename()).string();
447  return true;
448  };
449 
450  if (update(state.writableDb))
451  {
452  update(state.archiveDb);
453  state_db_.setState(state);
454  }
455  }
456 
457  bool writableDbExists = false;
458  bool archiveDbExists = false;
459 
461  for (boost::filesystem::directory_iterator it(dbPath);
462  it != boost::filesystem::directory_iterator();
463  ++it)
464  {
465  if (!state.writableDb.compare(it->path().string()))
466  writableDbExists = true;
467  else if (!state.archiveDb.compare(it->path().string()))
468  archiveDbExists = true;
469  else if (!dbPrefix_.compare(it->path().stem().string()))
470  pathsToDelete.push_back(it->path());
471  }
472 
473  if ((!writableDbExists && state.writableDb.size()) ||
474  (!archiveDbExists && state.archiveDb.size()) ||
475  (writableDbExists != archiveDbExists) ||
476  state.writableDb.empty() != state.archiveDb.empty())
477  {
478  boost::filesystem::path stateDbPathName =
479  app_.config().legacy("database_path");
480  stateDbPathName /= dbName_;
481  stateDbPathName += "*";
482 
483  journal_.error()
484  << "state db error:\n"
485  << " writableDbExists " << writableDbExists << " archiveDbExists "
486  << archiveDbExists << '\n'
487  << " writableDb '" << state.writableDb << "' archiveDb '"
488  << state.archiveDb << "\n\n"
489  << "The existing data is in a corrupted state.\n"
490  << "To resume operation, remove the files matching "
491  << stateDbPathName.string() << " and contents of the directory "
492  << get(section, "path") << '\n'
493  << "Optionally, you can move those files to another\n"
494  << "location if you wish to analyze or back up the data.\n"
495  << "However, there is no guarantee that the data in its\n"
496  << "existing form is usable.";
497 
498  Throw<std::runtime_error>("state db error");
499  }
500 
501  // The necessary directories exist. Now, remove any others.
502  for (boost::filesystem::path& p : pathsToDelete)
503  boost::filesystem::remove_all(p);
504 }
505 
508 {
510  boost::filesystem::path newPath;
511 
512  if (path.size())
513  {
514  newPath = path;
515  }
516  else
517  {
518  boost::filesystem::path p = get(section, "path");
519  p /= dbPrefix_;
520  p += ".%%%%";
521  newPath = boost::filesystem::unique_path(p);
522  }
523  section.set("path", newPath.string());
524 
526  section,
527  megabytes(
528  app_.config().getValueFor(SizedItem::burstSize, std::nullopt)),
529  scheduler_,
531  backend->open();
532  return backend;
533 }
534 
535 void
537  LedgerIndex lastRotated,
538  std::string const& TableName,
539  std::function<std::optional<LedgerIndex>()> const& getMinSeq,
540  std::function<void(LedgerIndex)> const& deleteBeforeSeq)
541 {
542  assert(deleteInterval_);
544 
545  {
546  JLOG(journal_.trace())
547  << "Begin: Look up lowest value of: " << TableName;
548  auto m = getMinSeq();
549  JLOG(journal_.trace()) << "End: Look up lowest value of: " << TableName;
550  if (!m)
551  return;
552  min = *m;
553  }
554 
555  if (min > lastRotated || stopping())
556  return;
557  if (min == lastRotated)
558  {
559  // Micro-optimization mainly to clarify logs
560  JLOG(journal_.trace()) << "Nothing to delete from " << TableName;
561  return;
562  }
563 
564  JLOG(journal_.debug()) << "start deleting in: " << TableName << " from "
565  << min << " to " << lastRotated;
566  while (min < lastRotated)
567  {
568  min = std::min(lastRotated, min + deleteBatch_);
569  JLOG(journal_.trace())
570  << "Begin: Delete up to " << deleteBatch_
571  << " rows with LedgerSeq < " << min << " from: " << TableName;
572  deleteBeforeSeq(min);
573  JLOG(journal_.trace())
574  << "End: Delete up to " << deleteBatch_ << " rows with LedgerSeq < "
575  << min << " from: " << TableName;
576  if (stopping())
577  return;
578  if (min < lastRotated)
580  if (stopping())
581  return;
582  }
583  JLOG(journal_.debug()) << "finished deleting from: " << TableName;
584 }
585 
586 void
588 {
589  ledgerMaster_->clearLedgerCachePrior(validatedSeq);
591 }
592 
593 void
595 {
597  return;
599  return;
600 }
601 
602 void
604 {
605  if (app_.config().reporting())
606  {
607  assert(false);
608  Throw<std::runtime_error>(
609  "Reporting does not support online_delete. Remove "
610  "online_delete info from config");
611  }
612  // Do not allow ledgers to be acquired from the network
613  // that are about to be deleted.
614  minimumOnline_ = lastRotated + 1;
615  JLOG(journal_.trace()) << "Begin: Clear internal ledgers up to "
616  << lastRotated;
617  ledgerMaster_->clearPriorLedgers(lastRotated);
618  JLOG(journal_.trace()) << "End: Clear internal ledgers up to "
619  << lastRotated;
620  if (stopping())
621  return;
622 
623  SQLiteDatabase* const db =
624  dynamic_cast<SQLiteDatabase*>(&app_.getRelationalDatabase());
625 
626  if (!db)
627  Throw<std::runtime_error>("Failed to get relational database");
628 
629  clearSql(
630  lastRotated,
631  "Ledgers",
632  [db]() -> std::optional<LedgerIndex> { return db->getMinLedgerSeq(); },
633  [db](LedgerIndex min) -> void { db->deleteBeforeLedgerSeq(min); });
634  if (stopping())
635  return;
636 
637  if (!app_.config().useTxTables())
638  return;
639 
640  clearSql(
641  lastRotated,
642  "Transactions",
643  [&db]() -> std::optional<LedgerIndex> {
644  return db->getTransactionsMinLedgerSeq();
645  },
646  [&db](LedgerIndex min) -> void {
648  });
649  if (stopping())
650  return;
651 
652  clearSql(
653  lastRotated,
654  "AccountTransactions",
655  [&db]() -> std::optional<LedgerIndex> {
657  },
658  [&db](LedgerIndex min) -> void {
660  });
661  if (stopping())
662  return;
663 }
664 
665 bool
667 {
668  auto age = ledgerMaster_->getValidatedLedgerAge();
670  std::unique_lock lock(mutex_);
671  while (!stop_ && (mode != OperatingMode::FULL || age > ageThreshold_))
672  {
673  lock.unlock();
674  JLOG(journal_.warn()) << "Waiting " << recoveryWaitTime_.count()
675  << "s for node to stabilize. state: "
676  << app_.getOPs().strOperatingMode(mode, false)
677  << ". age " << age.count() << 's';
680  mode = netOPs_->getOperatingMode();
681  lock.lock();
682  }
683 
684  return stop_;
685 }
686 
687 void
689 {
690  if (thread_.joinable())
691  {
692  {
693  std::lock_guard lock(mutex_);
694  stop_ = true;
695  cond_.notify_one();
696  }
697  thread_.join();
698  }
699 }
700 
703 {
704  // minimumOnline_ with 0 value is equivalent to unknown/not set.
705  // Don't attempt to acquire ledgers if that value is unknown.
707  return minimumOnline_.load();
708  return app_.getLedgerMaster().minSqlSeq();
709 }
710 
711 //------------------------------------------------------------------------------
712 
715  Application& app,
716  NodeStore::Scheduler& scheduler,
717  beast::Journal journal)
718 {
719  return std::make_unique<SHAMapStoreImp>(app, scheduler, journal);
720 }
721 
722 } // namespace ripple
ripple::SQLiteDatabase
Definition: SQLiteDatabase.h:27
ripple::Section
Holds a collection of configuration values.
Definition: BasicConfig.h:42
ripple::SHAMapStoreImp::SavedStateDB::setCanDelete
LedgerIndex setCanDelete(LedgerIndex canDelete)
Definition: SHAMapStoreImp.cpp:53
ripple::setCanDelete
LedgerIndex setCanDelete(soci::session &session, LedgerIndex canDelete)
setCanDelete Updates the ledger sequence which can be deleted.
Definition: State.cpp:91
ripple::Application
Definition: Application.h:115
ripple::SHAMapStoreImp::dbPaths
void dbPaths()
Definition: SHAMapStoreImp.cpp:414
ripple::Application::getNodeFamily
virtual Family & getNodeFamily()=0
std::this_thread::sleep_for
T sleep_for(T... args)
ripple::Family::getTreeNodeCache
virtual std::shared_ptr< TreeNodeCache > getTreeNodeCache(std::uint32_t ledgerSeq)=0
Return a pointer to the Family Tree Node Cache.
ripple::SHAMapStoreImp::healthy_
bool healthy_
Definition: SHAMapStoreImp.h:93
std::bind
T bind(T... args)
ripple::SHAMapStoreImp::scheduler_
NodeStore::Scheduler & scheduler_
Definition: SHAMapStoreImp.h:87
ripple::SHAMapStoreImp::SHAMapStoreImp
SHAMapStoreImp(Application &app, NodeStore::Scheduler &scheduler, beast::Journal journal)
Definition: SHAMapStoreImp.cpp:84
ripple::NodeStore::Database
Persistency layer for NodeObject.
Definition: Database.h:51
ripple::LedgerMaster::clearLedgerCachePrior
void clearLedgerCachePrior(LedgerIndex seq)
Definition: LedgerMaster.cpp:1891
std::string
STL class.
std::shared_ptr
STL class.
beast::Journal::trace
Stream trace() const
Severity stream access functions.
Definition: Journal.h:309
ripple::SHAMapStoreImp::newLedger_
std::shared_ptr< Ledger const > newLedger_
Definition: SHAMapStoreImp.h:97
ripple::SHAMapStoreImp::onLedgerClosed
void onLedgerClosed(std::shared_ptr< Ledger const > const &ledger) override
Called by LedgerMaster every time a ledger validates.
Definition: SHAMapStoreImp.cpp:234
ripple::SHAMapStoreImp::minimumDeletionInterval_
static const std::uint32_t minimumDeletionInterval_
Definition: SHAMapStoreImp.h:81
ripple::SHAMapStoreImp::dbPrefix_
const std::string dbPrefix_
Definition: SHAMapStoreImp.h:77
ripple::SHAMapStoreImp::ledgerMaster_
LedgerMaster * ledgerMaster_
Definition: SHAMapStoreImp.h:117
ripple::setSavedState
void setSavedState(soci::session &session, SavedState const &state)
setSavedState Saves the given state.
Definition: State.cpp:111
std::vector< boost::filesystem::path >
ripple::SHAMapStoreImp::mutex_
std::mutex mutex_
Definition: SHAMapStoreImp.h:96
std::string::size
T size(T... args)
ripple::SHAMapStoreImp::makeNodeStore
std::unique_ptr< NodeStore::Database > makeNodeStore(int readThreads) override
Definition: SHAMapStoreImp.cpp:169
ripple::SavedState::writableDb
std::string writableDb
Definition: State.h:35
std::chrono::milliseconds
ripple::SHAMapStoreImp::stop
void stop() override
Definition: SHAMapStoreImp.cpp:688
ripple::SizedItem::treeCacheAge
@ treeCacheAge
beast::Journal::warn
Stream warn() const
Definition: Journal.h:327
std::lock_guard
STL class.
ripple::Application::getShardStore
virtual NodeStore::DatabaseShard * getShardStore()=0
ripple::NetworkOPs::getOperatingMode
virtual OperatingMode getOperatingMode() const =0
ripple::SHAMapStoreImp::journal_
const beast::Journal journal_
Definition: SHAMapStoreImp.h:88
ripple::SHAMapStoreImp::cond_
std::condition_variable cond_
Definition: SHAMapStoreImp.h:94
ripple::SHAMapStoreImp::freshenCaches
void freshenCaches()
Definition: SHAMapStoreImp.cpp:594
std::function
ripple::SizedItem::hashNodeDBCache
@ hashNodeDBCache
ripple::Family::getFullBelowCache
virtual std::shared_ptr< FullBelowCache > getFullBelowCache(std::uint32_t ledgerSeq)=0
Return a pointer to the Family Full Below Cache.
ripple::SHAMapStoreImp::SavedStateDB::getCanDelete
LedgerIndex getCanDelete()
Definition: SHAMapStoreImp.cpp:45
ripple::SQLiteDatabase::getAccountTransactionsMinLedgerSeq
virtual std::optional< LedgerIndex > getAccountTransactionsMinLedgerSeq()=0
getAccountTransactionsMinLedgerSeq Returns the minimum ledger sequence stored in the AccountTransacti...
ripple::SHAMapStoreImp::SavedStateDB::mutex_
std::mutex mutex_
Definition: SHAMapStoreImp.h:47
ripple::SHAMapStoreImp::nodeStoreName_
static constexpr auto nodeStoreName_
Definition: SHAMapStoreImp.h:121
ripple::SHAMapStoreImp::stopping
bool stopping()
This is a health check for online deletion that waits until rippled is stable until returning.
Definition: SHAMapStoreImp.cpp:666
ripple::SHAMapStoreImp::run
void run()
Definition: SHAMapStoreImp.cpp:279
std::unique_ptr::reset
T reset(T... args)
ripple::Application::getOPs
virtual NetworkOPs & getOPs()=0
ripple::SHAMapStoreImp::copyNode
bool copyNode(std::uint64_t &nodeCount, SHAMapTreeNode const &node)
Definition: SHAMapStoreImp.cpp:261
ripple::SHAMapStoreImp::dbRotating_
NodeStore::DatabaseRotating * dbRotating_
Definition: SHAMapStoreImp.h:89
ripple::get_if_exists
bool get_if_exists(Section const &section, std::string const &name, T &v)
Definition: BasicConfig.h:384
ripple::SQLiteDatabase::getTransactionsMinLedgerSeq
virtual std::optional< LedgerIndex > getTransactionsMinLedgerSeq()=0
getTransactionsMinLedgerSeq Returns the minimum ledger sequence stored in the Transactions table.
ripple::SHAMapStoreImp::app_
Application & app_
Definition: SHAMapStoreImp.h:72
std::vector::push_back
T push_back(T... args)
ripple::SHAMapStoreImp::clearSql
void clearSql(LedgerIndex lastRotated, std::string const &TableName, std::function< std::optional< LedgerIndex >()> const &getMinSeq, std::function< void(LedgerIndex)> const &deleteBeforeSeq)
delete from sqlite table in batches to not lock the db excessively.
Definition: SHAMapStoreImp.cpp:536
std::thread::joinable
T joinable(T... args)
ripple::Config::reporting
bool reporting() const
Definition: Config.h:316
ripple::SHAMapStoreImp::recoveryWaitTime_
std::chrono::seconds recoveryWaitTime_
If the node is out of sync during an online_delete health check, sleep the thread for this time,...
Definition: SHAMapStoreImp.h:112
ripple::SHAMapStoreImp::stop_
bool stop_
Definition: SHAMapStoreImp.h:92
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:990
ripple::Application::getLedgerMaster
virtual LedgerMaster & getLedgerMaster()=0
ripple::Config
Definition: Config.h:68
ripple::SHAMapStoreImp::advisoryDelete_
bool advisoryDelete_
Definition: SHAMapStoreImp.h:103
ripple::Application::config
virtual Config & config()=0
ripple::megabytes
constexpr auto megabytes(T value) noexcept
Definition: ByteUtilities.h:34
std::unique_lock
STL class.
ripple::SHAMapStoreImp::minimumOnline_
std::atomic< LedgerIndex > minimumOnline_
Definition: SHAMapStoreImp.h:85
ripple::Application::getRelationalDatabase
virtual RelationalDatabase & getRelationalDatabase()=0
std::string::compare
T compare(T... args)
ripple::SQLiteDatabase::deleteAccountTransactionsBeforeLedgerSeq
virtual void deleteAccountTransactionsBeforeLedgerSeq(LedgerIndex ledgerSeq)=0
deleteAccountTransactionsBeforeLedgerSeq Deletes all account transactions with a sequence number less...
ripple::SHAMapStoreImp::SavedStateDB::setState
void setState(SavedState const &state)
Definition: SHAMapStoreImp.cpp:69
ripple::SHAMapStoreImp::treeNodeCache_
TreeNodeCache * treeNodeCache_
Definition: SHAMapStoreImp.h:119
ripple::SHAMapTreeNode
Definition: SHAMapTreeNode.h:53
ripple::Config::useTxTables
bool useTxTables() const
Definition: Config.h:322
ripple::SHAMapStoreImp::working_
std::atomic< bool > working_
Definition: SHAMapStoreImp.h:98
std::to_string
T to_string(T... args)
ripple::SHAMapStoreImp::deleteInterval_
std::uint32_t deleteInterval_
Definition: SHAMapStoreImp.h:102
ripple::SHAMapStoreImp::ageThreshold_
std::chrono::seconds ageThreshold_
Definition: SHAMapStoreImp.h:106
ripple::RelationalDatabase::getMinLedgerSeq
virtual std::optional< LedgerIndex > getMinLedgerSeq()=0
getMinLedgerSeq Returns the minimum ledger sequence in the Ledgers table.
beast::Journal::error
Stream error() const
Definition: Journal.h:333
beast::Journal::info
Stream info() const
Definition: Journal.h:321
ripple::LedgerMaster::minSqlSeq
std::optional< LedgerIndex > minSqlSeq()
Definition: LedgerMaster.cpp:2361
ripple::initStateDB
void initStateDB(soci::session &session, BasicConfig const &config, std::string const &dbName)
initStateDB Opens a session with the State database.
Definition: State.cpp:25
ripple::BasicConfig::legacy
void legacy(std::string const &section, std::string value)
Set a value that is not a key/value pair.
Definition: BasicConfig.cpp:164
ripple::Application::logs
virtual Logs & logs()=0
ripple::TransactionMaster::getCache
TaggedCache< uint256, Transaction > & getCache()
Definition: TransactionMaster.cpp:162
ripple::SHAMapStoreImp::clearPrior
void clearPrior(LedgerIndex lastRotated)
Definition: SHAMapStoreImp.cpp:603
beast::Journal
A generic endpoint for log messages.
Definition: Journal.h:58
ripple::SizedItem::burstSize
@ burstSize
std::uint32_t
std::condition_variable::wait
T wait(T... args)
ripple::NodeStore::Scheduler
Scheduling for asynchronous backend activity.
Definition: ripple/nodestore/Scheduler.h:60
ripple::getSavedState
SavedState getSavedState(soci::session &session)
getSavedState Returns the saved state.
Definition: State.cpp:99
ripple::SHAMapStoreImp::checkHealthInterval_
const std::uint64_t checkHealthInterval_
Definition: SHAMapStoreImp.h:79
ripple::SHAMapStoreImp::state_db_
SavedStateDB state_db_
Definition: SHAMapStoreImp.h:90
ripple::SHAMapStoreImp::SavedStateDB::getState
SavedState getState()
Definition: SHAMapStoreImp.cpp:61
ripple::SHAMapStoreImp::SavedStateDB::sqlDb_
soci::session sqlDb_
Definition: SHAMapStoreImp.h:46
std::min
T min(T... args)
ripple::SHAMapTreeNode::getHash
SHAMapHash const & getHash() const
Return the hash of this node.
Definition: SHAMapTreeNode.h:143
ripple::SHAMapStoreImp::backOff_
std::chrono::milliseconds backOff_
Definition: SHAMapStoreImp.h:105
std::condition_variable::notify_one
T notify_one(T... args)
ripple::SHAMapStoreImp::thread_
std::thread thread_
Definition: SHAMapStoreImp.h:91
ripple::SHAMapStoreImp::SavedStateDB::init
void init(BasicConfig const &config, std::string const &dbName)
Definition: SHAMapStoreImp.cpp:36
ripple::LedgerMaster::getValidatedLedgerAge
std::chrono::seconds getValidatedLedgerAge()
Definition: LedgerMaster.cpp:274
ripple::SHAMapStoreImp::dbName_
const std::string dbName_
Definition: SHAMapStoreImp.h:75
ripple::setLastRotated
void setLastRotated(soci::session &session, LedgerIndex seq)
setLastRotated Updates the last rotated ledger sequence.
Definition: State.cpp:123
beast::setCurrentThreadName
void setCurrentThreadName(std::string_view name)
Changes the name of the caller thread.
Definition: CurrentThreadName.cpp:119
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::SHAMapStoreImp::fdRequired
int fdRequired() const override
Returns the number of file descriptors that are needed.
Definition: SHAMapStoreImp.cpp:255
ripple::Section::set
void set(std::string const &key, std::string const &value)
Set a key/value pair.
Definition: BasicConfig.cpp:32
ripple::NodeStore::Manager::make_Backend
virtual std::unique_ptr< Backend > make_Backend(Section const &parameters, std::size_t burstSize, Scheduler &scheduler, beast::Journal journal)=0
Create a backend.
ripple::Logs::journal
beast::Journal journal(std::string const &name)
Definition: Log.cpp:144
ripple::SizedItem::treeCacheSize
@ treeCacheSize
std
STL namespace.
ripple::SavedState::archiveDb
std::string archiveDb
Definition: State.h:36
ripple::getCanDelete
LedgerIndex getCanDelete(soci::session &session)
getCanDelete Returns the ledger sequence which can be deleted.
Definition: State.cpp:81
ripple::SHAMapStoreImp::SavedStateDB::setLastRotated
void setLastRotated(LedgerIndex seq)
Definition: SHAMapStoreImp.cpp:76
ripple::SQLiteDatabase::deleteTransactionsBeforeLedgerSeq
virtual void deleteTransactionsBeforeLedgerSeq(LedgerIndex ledgerSeq)=0
deleteTransactionsBeforeLedgerSeq Deletes all transactions with a sequence number less than or equal ...
ripple::SHAMapStoreImp::canDelete_
std::atomic< LedgerIndex > canDelete_
Definition: SHAMapStoreImp.h:99
ripple::SHAMapStoreImp::minimumDeletionIntervalSA_
static const std::uint32_t minimumDeletionIntervalSA_
Definition: SHAMapStoreImp.h:83
ripple::SavedState::lastRotated
LedgerIndex lastRotated
Definition: State.h:37
ripple::SQLiteDatabase::deleteBeforeLedgerSeq
virtual void deleteBeforeLedgerSeq(LedgerIndex ledgerSeq)=0
deleteBeforeLedgerSeq Deletes all ledgers with a sequence number less than or equal to the given ledg...
ripple::SHAMapStoreImp::deleteBatch_
std::uint32_t deleteBatch_
Definition: SHAMapStoreImp.h:104
ripple::SHAMapStoreImp::fullBelowCache_
FullBelowCache * fullBelowCache_
Definition: SHAMapStoreImp.h:118
std::chrono::seconds::count
T count(T... args)
ripple::SHAMapStoreImp::minimumOnline
std::optional< LedgerIndex > minimumOnline() const override
The minimum ledger to try and maintain in our database.
Definition: SHAMapStoreImp.cpp:702
ripple::SHAMapStoreImp::clearCaches
void clearCaches(LedgerIndex validatedSeq)
Definition: SHAMapStoreImp.cpp:587
std::string::empty
T empty(T... args)
ripple::NetworkOPs::strOperatingMode
virtual std::string strOperatingMode(OperatingMode const mode, bool const admin=false) const =0
ripple::OperatingMode
OperatingMode
Specifies the mode under which the server believes it's operating.
Definition: NetworkOPs.h:66
std::optional
ripple::SHAMapStoreImp::makeBackendRotating
std::unique_ptr< NodeStore::Backend > makeBackendRotating(std::string path=std::string())
Definition: SHAMapStoreImp.cpp:507
beast::Journal::debug
Stream debug() const
Definition: Journal.h:315
ripple::NodeStore::Database::fetchNodeObject
std::shared_ptr< NodeObject > fetchNodeObject(uint256 const &hash, std::uint32_t ledgerSeq=0, FetchType fetchType=FetchType::synchronous, bool duplicate=false)
Fetch a node object.
Definition: Database.cpp:226
ripple::SHAMapHash::as_uint256
uint256 const & as_uint256() const
Definition: SHAMapHash.h:43
std::numeric_limits::max
T max(T... args)
ripple::NodeStore::Manager::instance
static Manager & instance()
Returns the instance of the manager singleton.
Definition: ManagerImp.cpp:120
ripple::NodeStore::DatabaseRotating::rotateWithLock
virtual void rotateWithLock(std::function< std::unique_ptr< NodeStore::Backend >(std::string const &writableBackendName)> const &f)=0
Rotates the backends.
ripple::SHAMapStoreImp::fdRequired_
int fdRequired_
Definition: SHAMapStoreImp.h:100
ripple::NodeStore::Manager::make_Database
virtual std::unique_ptr< Database > make_Database(std::size_t burstSize, Scheduler &scheduler, int readThreads, Section const &backendParameters, beast::Journal journal)=0
Construct a NodeStore database.
ripple::SHAMapStoreImp::netOPs_
NetworkOPs * netOPs_
Definition: SHAMapStoreImp.h:116
ripple::make_SHAMapStore
std::unique_ptr< SHAMapStore > make_SHAMapStore(Application &app, NodeStore::Scheduler &scheduler, beast::Journal journal)
Definition: SHAMapStoreImp.cpp:714
std::unique_ptr
STL class.
ripple::NodeStore::FetchType::synchronous
@ synchronous
ripple::SHAMapStoreImp::freshenCache
bool freshenCache(CacheInstance &cache)
Definition: SHAMapStoreImp.h:194
ripple::SavedState
Definition: State.h:33
ripple::LedgerMaster::clearPriorLedgers
void clearPriorLedgers(LedgerIndex seq)
Definition: LedgerMaster.cpp:1883
std::condition_variable::notify_all
T notify_all(T... args)
ripple::BasicConfig
Holds unparsed configuration information.
Definition: BasicConfig.h:215
ripple::ConfigSection::nodeDatabase
static std::string nodeDatabase()
Definition: ConfigSections.h:33
std::ref
T ref(T... args)
ripple::SHAMapStoreImp::rendezvous
void rendezvous() const override
Definition: SHAMapStoreImp.cpp:245
std::thread::join
T join(T... args)
ripple::get
T & get(EitherAmount &amt)
Definition: AmountSpec.h:118
ripple::BasicConfig::section
Section & section(std::string const &name)
Returns the section with the given name.
Definition: BasicConfig.cpp:127
ripple::SHAMapStoreImp::rendezvous_
std::condition_variable rendezvous_
Definition: SHAMapStoreImp.h:95
ripple::detail::BasicFullBelowCache::clear
void clear()
Definition: FullBelowCache.h:128
ripple::Application::getMasterTransaction
virtual TransactionMaster & getMasterTransaction()=0
ripple::OperatingMode::FULL
@ FULL
we have the ledger and can even validate