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/RelationalDBInterface_global.h>
24 #include <ripple/app/rdb/backend/RelationalDBInterfaceSqlite.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 (health())
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 && !health();
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  switch (health())
362  {
363  case Health::stopping:
364  return;
365  case Health::unhealthy:
366  continue;
367  case Health::ok:
368  default:;
369  }
370 
371  JLOG(journal_.debug()) << "copying ledger " << validatedSeq;
372  std::uint64_t nodeCount = 0;
373  validatedLedger->stateMap().snapShot(false)->visitNodes(std::bind(
375  this,
376  std::ref(nodeCount),
377  std::placeholders::_1));
378  switch (health())
379  {
380  case Health::stopping:
381  return;
382  case Health::unhealthy:
383  continue;
384  case Health::ok:
385  default:;
386  }
387  // Only log if we completed without a "health" abort
388  JLOG(journal_.debug()) << "copied ledger " << validatedSeq
389  << " nodecount " << nodeCount;
390 
391  JLOG(journal_.debug()) << "freshening caches";
392  freshenCaches();
393  switch (health())
394  {
395  case Health::stopping:
396  return;
397  case Health::unhealthy:
398  continue;
399  case Health::ok:
400  default:;
401  }
402  // Only log if we completed without a "health" abort
403  JLOG(journal_.debug()) << validatedSeq << " freshened caches";
404 
405  JLOG(journal_.trace()) << "Making a new backend";
406  auto newBackend = makeBackendRotating();
407  JLOG(journal_.debug())
408  << validatedSeq << " new backend " << newBackend->getName();
409 
410  clearCaches(validatedSeq);
411  switch (health())
412  {
413  case Health::stopping:
414  return;
415  case Health::unhealthy:
416  continue;
417  case Health::ok:
418  default:;
419  }
420 
421  lastRotated = validatedSeq;
422 
424  [&](std::string const& writableBackendName) {
425  SavedState savedState;
426  savedState.writableDb = newBackend->getName();
427  savedState.archiveDb = writableBackendName;
428  savedState.lastRotated = lastRotated;
429  state_db_.setState(savedState);
430 
431  clearCaches(validatedSeq);
432 
433  return std::move(newBackend);
434  });
435 
436  JLOG(journal_.warn()) << "finished rotation " << validatedSeq;
437  }
438  }
439 }
440 
441 void
443 {
445  boost::filesystem::path dbPath = get(section, "path");
446 
447  if (boost::filesystem::exists(dbPath))
448  {
449  if (!boost::filesystem::is_directory(dbPath))
450  {
451  journal_.error()
452  << "node db path must be a directory. " << dbPath.string();
453  Throw<std::runtime_error>("node db path must be a directory.");
454  }
455  }
456  else
457  {
458  boost::filesystem::create_directories(dbPath);
459  }
460 
461  SavedState state = state_db_.getState();
462 
463  {
464  auto update = [&dbPath](std::string& sPath) {
465  if (sPath.empty())
466  return false;
467 
468  // Check if configured "path" matches stored directory path
469  using namespace boost::filesystem;
470  auto const stored{path(sPath)};
471  if (stored.parent_path() == dbPath)
472  return false;
473 
474  sPath = (dbPath / stored.filename()).string();
475  return true;
476  };
477 
478  if (update(state.writableDb))
479  {
480  update(state.archiveDb);
481  state_db_.setState(state);
482  }
483  }
484 
485  bool writableDbExists = false;
486  bool archiveDbExists = false;
487 
488  for (boost::filesystem::directory_iterator it(dbPath);
489  it != boost::filesystem::directory_iterator();
490  ++it)
491  {
492  if (!state.writableDb.compare(it->path().string()))
493  writableDbExists = true;
494  else if (!state.archiveDb.compare(it->path().string()))
495  archiveDbExists = true;
496  else if (!dbPrefix_.compare(it->path().stem().string()))
497  boost::filesystem::remove_all(it->path());
498  }
499 
500  if ((!writableDbExists && state.writableDb.size()) ||
501  (!archiveDbExists && state.archiveDb.size()) ||
502  (writableDbExists != archiveDbExists) ||
503  state.writableDb.empty() != state.archiveDb.empty())
504  {
505  boost::filesystem::path stateDbPathName =
506  app_.config().legacy("database_path");
507  stateDbPathName /= dbName_;
508  stateDbPathName += "*";
509 
510  journal_.error()
511  << "state db error:\n"
512  << " writableDbExists " << writableDbExists << " archiveDbExists "
513  << archiveDbExists << '\n'
514  << " writableDb '" << state.writableDb << "' archiveDb '"
515  << state.archiveDb << "\n\n"
516  << "The existing data is in a corrupted state.\n"
517  << "To resume operation, remove the files matching "
518  << stateDbPathName.string() << " and contents of the directory "
519  << get(section, "path") << '\n'
520  << "Optionally, you can move those files to another\n"
521  << "location if you wish to analyze or back up the data.\n"
522  << "However, there is no guarantee that the data in its\n"
523  << "existing form is usable.";
524 
525  Throw<std::runtime_error>("state db error");
526  }
527 }
528 
531 {
533  boost::filesystem::path newPath;
534 
535  if (path.size())
536  {
537  newPath = path;
538  }
539  else
540  {
541  boost::filesystem::path p = get(section, "path");
542  p /= dbPrefix_;
543  p += ".%%%%";
544  newPath = boost::filesystem::unique_path(p);
545  }
546  section.set("path", newPath.string());
547 
549  section,
550  megabytes(
551  app_.config().getValueFor(SizedItem::burstSize, std::nullopt)),
552  scheduler_,
554  backend->open();
555  return backend;
556 }
557 
558 void
560  LedgerIndex lastRotated,
561  std::string const& TableName,
562  std::function<std::optional<LedgerIndex>()> const& getMinSeq,
563  std::function<void(LedgerIndex)> const& deleteBeforeSeq)
564 {
565  assert(deleteInterval_);
567 
568  {
569  JLOG(journal_.trace())
570  << "Begin: Look up lowest value of: " << TableName;
571  auto m = getMinSeq();
572  JLOG(journal_.trace()) << "End: Look up lowest value of: " << TableName;
573  if (!m)
574  return;
575  min = *m;
576  }
577 
578  if (min > lastRotated || health() != Health::ok)
579  return;
580  if (min == lastRotated)
581  {
582  // Micro-optimization mainly to clarify logs
583  JLOG(journal_.trace()) << "Nothing to delete from " << TableName;
584  return;
585  }
586 
587  JLOG(journal_.debug()) << "start deleting in: " << TableName << " from "
588  << min << " to " << lastRotated;
589  while (min < lastRotated)
590  {
591  min = std::min(lastRotated, min + deleteBatch_);
592  JLOG(journal_.trace())
593  << "Begin: Delete up to " << deleteBatch_
594  << " rows with LedgerSeq < " << min << " from: " << TableName;
595  deleteBeforeSeq(min);
596  JLOG(journal_.trace())
597  << "End: Delete up to " << deleteBatch_ << " rows with LedgerSeq < "
598  << min << " from: " << TableName;
599  if (health())
600  return;
601  if (min < lastRotated)
603  if (health())
604  return;
605  }
606  JLOG(journal_.debug()) << "finished deleting from: " << TableName;
607 }
608 
609 void
611 {
612  ledgerMaster_->clearLedgerCachePrior(validatedSeq);
614 }
615 
616 void
618 {
620  return;
622  return;
623 }
624 
625 void
627 {
628  if (app_.config().reporting())
629  {
630  assert(false);
631  Throw<std::runtime_error>(
632  "Reporting does not support online_delete. Remove "
633  "online_delete info from config");
634  }
635  // Do not allow ledgers to be acquired from the network
636  // that are about to be deleted.
637  minimumOnline_ = lastRotated + 1;
638  JLOG(journal_.trace()) << "Begin: Clear internal ledgers up to "
639  << lastRotated;
640  ledgerMaster_->clearPriorLedgers(lastRotated);
641  JLOG(journal_.trace()) << "End: Clear internal ledgers up to "
642  << lastRotated;
643  if (health())
644  return;
645 
647  dynamic_cast<RelationalDBInterfaceSqlite*>(
649 
650  clearSql(
651  lastRotated,
652  "Ledgers",
653  [&iface]() -> std::optional<LedgerIndex> {
654  return iface->getMinLedgerSeq();
655  },
656  [&iface](LedgerIndex min) -> void {
657  iface->deleteBeforeLedgerSeq(min);
658  });
659  if (health())
660  return;
661 
662  if (!app_.config().useTxTables())
663  return;
664 
665  clearSql(
666  lastRotated,
667  "Transactions",
668  [&iface]() -> std::optional<LedgerIndex> {
669  return iface->getTransactionsMinLedgerSeq();
670  },
671  [&iface](LedgerIndex min) -> void {
673  });
674  if (health())
675  return;
676 
677  clearSql(
678  lastRotated,
679  "AccountTransactions",
680  [&iface]() -> std::optional<LedgerIndex> {
681  return iface->getAccountTransactionsMinLedgerSeq();
682  },
683  [&iface](LedgerIndex min) -> void {
685  });
686  if (health())
687  return;
688 }
689 
692 {
693  {
694  std::lock_guard lock(mutex_);
695  if (stop_)
696  return Health::stopping;
697  }
698  if (!netOPs_)
699  return Health::ok;
700  assert(deleteInterval_);
701 
702  if (healthy_)
703  {
704  auto age = ledgerMaster_->getValidatedLedgerAge();
706  if (recoveryWaitTime_ && mode == OperatingMode::SYNCING &&
707  age < ageThreshold_)
708  {
709  JLOG(journal_.warn())
710  << "Waiting " << recoveryWaitTime_->count()
711  << "s for node to get back into sync with network. state: "
712  << app_.getOPs().strOperatingMode(mode, false) << ". age "
713  << age.count() << 's';
715 
717  mode = netOPs_->getOperatingMode();
718  }
719  if (mode != OperatingMode::FULL || age > ageThreshold_)
720  {
721  JLOG(journal_.warn()) << "Not deleting. state: "
722  << app_.getOPs().strOperatingMode(mode, false)
723  << ". age " << age.count() << 's';
724  healthy_ = false;
725  }
726  }
727 
728  if (healthy_)
729  return Health::ok;
730  else
731  return Health::unhealthy;
732 }
733 
734 void
736 {
737  if (thread_.joinable())
738  {
739  {
740  std::lock_guard lock(mutex_);
741  stop_ = true;
742  cond_.notify_one();
743  }
744  thread_.join();
745  }
746 }
747 
750 {
751  // minimumOnline_ with 0 value is equivalent to unknown/not set.
752  // Don't attempt to acquire ledgers if that value is unknown.
754  return minimumOnline_.load();
755  return app_.getLedgerMaster().minSqlSeq();
756 }
757 
758 //------------------------------------------------------------------------------
759 
762  Application& app,
763  NodeStore::Scheduler& scheduler,
764  beast::Journal journal)
765 {
766  return std::make_unique<SHAMapStoreImp>(app, scheduler, journal);
767 }
768 
769 } // namespace ripple
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 ledger sequence which can be deleted.
Definition: RelationalDBInterface_global.cpp:375
ripple::SHAMapStoreImp::health
Health health()
Definition: SHAMapStoreImp.cpp:691
ripple::Application
Definition: Application.h:115
ripple::SHAMapStoreImp::dbPaths
void dbPaths()
Definition: SHAMapStoreImp.cpp:442
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:95
std::bind
T bind(T... args)
ripple::SHAMapStoreImp::scheduler_
NodeStore::Scheduler & scheduler_
Definition: SHAMapStoreImp.h:89
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:1860
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:99
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:83
ripple::SHAMapStoreImp::dbPrefix_
const std::string dbPrefix_
Definition: SHAMapStoreImp.h:79
ripple::SHAMapStoreImp::ledgerMaster_
LedgerMaster * ledgerMaster_
Definition: SHAMapStoreImp.h:119
ripple::setSavedState
void setSavedState(soci::session &session, SavedState const &state)
setSavedState Saves given state.
Definition: RelationalDBInterface_global.cpp:395
ripple::SHAMapStoreImp::mutex_
std::mutex mutex_
Definition: SHAMapStoreImp.h:98
std::string::size
T size(T... args)
ripple::Application::getRelationalDBInterface
virtual RelationalDBInterface & getRelationalDBInterface()=0
ripple::SavedState::writableDb
std::string writableDb
Definition: RelationalDBInterface_global.h:171
std::chrono::milliseconds
ripple::SHAMapStoreImp::recoveryWaitTime_
std::optional< std::chrono::seconds > recoveryWaitTime_
If set, and the node is out of sync during an online_delete health check, sleep the thread for this t...
Definition: SHAMapStoreImp.h:114
ripple::RelationalDBInterfaceSqlite::deleteBeforeLedgerSeq
virtual void deleteBeforeLedgerSeq(LedgerIndex ledgerSeq)=0
deleteBeforeLedgerSeq Deletes all ledgers with given sequence and all sequences below it.
ripple::SHAMapStoreImp::stop
void stop() override
Definition: SHAMapStoreImp.cpp:735
std::optional::emplace
T emplace(T... args)
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:90
ripple::SHAMapStoreImp::cond_
std::condition_variable cond_
Definition: SHAMapStoreImp.h:96
ripple::SHAMapStoreImp::freshenCaches
void freshenCaches()
Definition: SHAMapStoreImp.cpp:617
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::RelationalDBInterfaceSqlite::getTransactionsMinLedgerSeq
virtual std::optional< LedgerIndex > getTransactionsMinLedgerSeq()=0
getTransactionsMinLedgerSeq Returns minimum ledger sequence among records in the Transactions table.
ripple::SHAMapStoreImp::SavedStateDB::mutex_
std::mutex mutex_
Definition: SHAMapStoreImp.h:49
ripple::SHAMapStoreImp::nodeStoreName_
static constexpr auto nodeStoreName_
Definition: SHAMapStoreImp.h:123
ripple::SHAMapStoreImp::run
void run()
Definition: SHAMapStoreImp.cpp:279
ripple::RelationalDBInterfaceSqlite::deleteTransactionsBeforeLedgerSeq
virtual void deleteTransactionsBeforeLedgerSeq(LedgerIndex ledgerSeq)=0
deleteTransactionsBeforeLedgerSeq Deletes all transactions with given ledger sequence and all sequenc...
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:91
ripple::RelationalDBInterface::getMinLedgerSeq
virtual std::optional< LedgerIndex > getMinLedgerSeq()=0
getMinLedgerSeq Returns minimum ledger sequence in Ledgers table.
ripple::get_if_exists
bool get_if_exists(Section const &section, std::string const &name, T &v)
Definition: BasicConfig.h:384
ripple::OperatingMode::SYNCING
@ SYNCING
fallen slightly behind
ripple::SHAMapStoreImp::app_
Application & app_
Definition: SHAMapStoreImp.h:74
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:559
std::thread::joinable
T joinable(T... args)
ripple::Config::reporting
bool reporting() const
Definition: Config.h:316
ripple::SHAMapStoreImp::stop_
bool stop_
Definition: SHAMapStoreImp.h:94
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::RelationalDBInterfaceSqlite
Definition: RelationalDBInterfaceSqlite.h:27
ripple::SHAMapStoreImp::advisoryDelete_
bool advisoryDelete_
Definition: SHAMapStoreImp.h:105
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:87
std::string::compare
T compare(T... args)
ripple::SHAMapStoreImp::SavedStateDB::setState
void setState(SavedState const &state)
Definition: SHAMapStoreImp.cpp:69
ripple::SHAMapStoreImp::treeNodeCache_
TreeNodeCache * treeNodeCache_
Definition: SHAMapStoreImp.h:121
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:100
std::to_string
T to_string(T... args)
ripple::SHAMapStoreImp::deleteInterval_
std::uint32_t deleteInterval_
Definition: SHAMapStoreImp.h:104
ripple::SHAMapStoreImp::ageThreshold_
std::chrono::seconds ageThreshold_
Definition: SHAMapStoreImp.h:108
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:2330
ripple::initStateDB
void initStateDB(soci::session &session, BasicConfig const &config, std::string const &dbName)
initStateDB Opens DB session with State DB.
Definition: RelationalDBInterface_global.cpp:309
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:626
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 saved state.
Definition: RelationalDBInterface_global.cpp:383
ripple::SHAMapStoreImp::Health
Health
Definition: SHAMapStoreImp.h:43
ripple::SHAMapStoreImp::checkHealthInterval_
const std::uint64_t checkHealthInterval_
Definition: SHAMapStoreImp.h:81
ripple::SHAMapStoreImp::state_db_
SavedStateDB state_db_
Definition: SHAMapStoreImp.h:92
ripple::SHAMapStoreImp::SavedStateDB::getState
SavedState getState()
Definition: SHAMapStoreImp.cpp:61
ripple::SHAMapStoreImp::SavedStateDB::sqlDb_
soci::session sqlDb_
Definition: SHAMapStoreImp.h:48
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:107
std::condition_variable::notify_one
T notify_one(T... args)
ripple::RelationalDBInterfaceSqlite::deleteAccountTransactionsBeforeLedgerSeq
virtual void deleteAccountTransactionsBeforeLedgerSeq(LedgerIndex ledgerSeq)=0
deleteAccountTransactionsBeforeLedgerSeq Deletes all account transactions with given ledger sequence ...
ripple::SHAMapStoreImp::thread_
std::thread thread_
Definition: SHAMapStoreImp.h:93
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:270
ripple::SHAMapStoreImp::dbName_
const std::string dbName_
Definition: SHAMapStoreImp.h:77
ripple::setLastRotated
void setLastRotated(soci::session &session, LedgerIndex seq)
setLastRotated Updates last rotated ledger sequence.
Definition: RelationalDBInterface_global.cpp:407
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: RelationalDBInterface_global.h:172
ripple::getCanDelete
LedgerIndex getCanDelete(soci::session &session)
getCanDelete Returns ledger sequence which can be deleted.
Definition: RelationalDBInterface_global.cpp:365
ripple::SHAMapStoreImp::SavedStateDB::setLastRotated
void setLastRotated(LedgerIndex seq)
Definition: SHAMapStoreImp.cpp:76
ripple::SHAMapStoreImp::canDelete_
std::atomic< LedgerIndex > canDelete_
Definition: SHAMapStoreImp.h:101
ripple::SHAMapStoreImp::minimumDeletionIntervalSA_
static const std::uint32_t minimumDeletionIntervalSA_
Definition: SHAMapStoreImp.h:85
ripple::SavedState::lastRotated
LedgerIndex lastRotated
Definition: RelationalDBInterface_global.h:173
ripple::SHAMapStoreImp::deleteBatch_
std::uint32_t deleteBatch_
Definition: SHAMapStoreImp.h:106
ripple::SHAMapStoreImp::fullBelowCache_
FullBelowCache * fullBelowCache_
Definition: SHAMapStoreImp.h:120
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:749
ripple::SHAMapStoreImp::clearCaches
void clearCaches(LedgerIndex validatedSeq)
Definition: SHAMapStoreImp.cpp:610
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:530
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:158
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::makeNodeStore
std::unique_ptr< NodeStore::Database > makeNodeStore(std::int32_t readThreads) override
Definition: SHAMapStoreImp.cpp:169
ripple::SHAMapStoreImp::fdRequired_
int fdRequired_
Definition: SHAMapStoreImp.h:102
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:118
ripple::RelationalDBInterfaceSqlite::getAccountTransactionsMinLedgerSeq
virtual std::optional< LedgerIndex > getAccountTransactionsMinLedgerSeq()=0
getAccountTransactionsMinLedgerSeq Returns minimum ledger sequence among records in the AccountTransa...
ripple::make_SHAMapStore
std::unique_ptr< SHAMapStore > make_SHAMapStore(Application &app, NodeStore::Scheduler &scheduler, beast::Journal journal)
Definition: SHAMapStoreImp.cpp:761
std::unique_ptr
STL class.
ripple::NodeStore::FetchType::synchronous
@ synchronous
ripple::SHAMapStoreImp::freshenCache
bool freshenCache(CacheInstance &cache)
Definition: SHAMapStoreImp.h:196
ripple::SavedState
Definition: RelationalDBInterface_global.h:169
ripple::LedgerMaster::clearPriorLedgers
void clearPriorLedgers(LedgerIndex seq)
Definition: LedgerMaster.cpp:1852
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:97
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