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 <boost/algorithm/string/predicate.hpp>
31 
32 namespace ripple {
33 void
35  BasicConfig const& config,
36  std::string const& dbName)
37 {
38  std::lock_guard lock(mutex_);
39  initStateDB(sqlDb_, config, dbName);
40 }
41 
44 {
45  std::lock_guard lock(mutex_);
46 
47  return ripple::getCanDelete(sqlDb_);
48 }
49 
52 {
53  std::lock_guard lock(mutex_);
54 
55  return ripple::setCanDelete(sqlDb_, canDelete);
56 }
57 
60 {
61  std::lock_guard lock(mutex_);
62 
63  return ripple::getSavedState(sqlDb_);
64 }
65 
66 void
68 {
69  std::lock_guard lock(mutex_);
70  ripple::setSavedState(sqlDb_, state);
71 }
72 
73 void
75 {
76  std::lock_guard lock(mutex_);
77  ripple::setLastRotated(sqlDb_, seq);
78 }
79 
80 //------------------------------------------------------------------------------
81 
83  Application& app,
84  NodeStore::Scheduler& scheduler,
85  beast::Journal journal)
86  : app_(app)
87  , scheduler_(scheduler)
88  , journal_(journal)
89  , working_(true)
90  , canDelete_(std::numeric_limits<LedgerIndex>::max())
91 {
92  Config& config{app.config()};
93 
94  Section& section{config.section(ConfigSection::nodeDatabase())};
95  if (section.empty())
96  {
97  Throw<std::runtime_error>(
98  "Missing [" + ConfigSection::nodeDatabase() +
99  "] entry in configuration file");
100  }
101 
102  // RocksDB only. Use sensible defaults if no values specified.
103  if (boost::iequals(get(section, "type"), "RocksDB"))
104  {
105  if (!section.exists("cache_mb"))
106  {
107  section.set(
108  "cache_mb",
109  std::to_string(config.getValueFor(SizedItem::hashNodeDBCache)));
110  }
111 
112  if (!section.exists("filter_bits") && (config.NODE_SIZE >= 2))
113  section.set("filter_bits", "10");
114  }
115 
116  get_if_exists(section, "online_delete", deleteInterval_);
117 
118  if (deleteInterval_)
119  {
120  if (app_.config().reporting())
121  {
122  Throw<std::runtime_error>(
123  "Reporting does not support online_delete. Remove "
124  "online_delete info from config");
125  }
126 
127  // Configuration that affects the behavior of online delete
128  get_if_exists(section, "delete_batch", deleteBatch_);
129  std::uint32_t temp;
130  if (get_if_exists(section, "back_off_milliseconds", temp) ||
131  // Included for backward compaibility with an undocumented setting
132  get_if_exists(section, "backOff", temp))
133  {
135  }
136  if (get_if_exists(section, "age_threshold_seconds", temp))
138  if (get_if_exists(section, "recovery_wait_seconds", temp))
140 
141  get_if_exists(section, "advisory_delete", advisoryDelete_);
142 
143  auto const minInterval = config.standalone()
146  if (deleteInterval_ < minInterval)
147  {
148  Throw<std::runtime_error>(
149  "online_delete must be at least " +
150  std::to_string(minInterval));
151  }
152 
153  if (config.LEDGER_HISTORY > deleteInterval_)
154  {
155  Throw<std::runtime_error>(
156  "online_delete must not be less than ledger_history "
157  "(currently " +
158  std::to_string(config.LEDGER_HISTORY) + ")");
159  }
160 
161  state_db_.init(config, dbName_);
162  dbPaths();
163  }
164 }
165 
168 {
170  if (deleteInterval_)
171  {
172  if (app_.config().reporting())
173  {
174  Throw<std::runtime_error>(
175  "Reporting does not support online_delete. Remove "
176  "online_delete info from config");
177  }
178  SavedState state = state_db_.getState();
179  auto writableBackend = makeBackendRotating(state.writableDb);
180  auto archiveBackend = makeBackendRotating(state.archiveDb);
181  if (!state.writableDb.size())
182  {
183  state.writableDb = writableBackend->getName();
184  state.archiveDb = archiveBackend->getName();
185  state_db_.setState(state);
186  }
187 
188  // Create NodeStore with two backends to allow online deletion of data
189  auto dbr = std::make_unique<NodeStore::DatabaseRotatingImp>(
190  scheduler_,
191  readThreads,
192  std::move(writableBackend),
193  std::move(archiveBackend),
196  fdRequired_ += dbr->fdRequired();
197  dbRotating_ = dbr.get();
198  db.reset(dynamic_cast<NodeStore::Database*>(dbr.release()));
199  }
200  else
201  {
203  megabytes(
204  app_.config().getValueFor(SizedItem::burstSize, std::nullopt)),
205  scheduler_,
206  readThreads,
209  fdRequired_ += db->fdRequired();
210  }
211  return db;
212 }
213 
214 void
216 {
217  {
218  std::lock_guard lock(mutex_);
219  newLedger_ = ledger;
220  working_ = true;
221  }
222  cond_.notify_one();
223 }
224 
225 void
227 {
228  if (!working_)
229  return;
230 
232  rendezvous_.wait(lock, [&] { return !working_; });
233 }
234 
235 int
237 {
238  return fdRequired_;
239 }
240 
241 bool
243 {
244  // Copy a single record from node to dbRotating_
246  if (!(++nodeCount % checkHealthInterval_))
247  {
248  if (health())
249  return false;
250  }
251 
252  return true;
253 }
254 
255 void
257 {
258  if (app_.config().reporting())
259  {
260  assert(false);
261  Throw<std::runtime_error>(
262  "Reporting does not support online_delete. Remove "
263  "online_delete info from config");
264  }
265  beast::setCurrentThreadName("SHAMapStore");
266  LedgerIndex lastRotated = state_db_.getState().lastRotated;
267  netOPs_ = &app_.getOPs();
271 
272  if (advisoryDelete_)
274 
275  while (true)
276  {
277  healthy_ = true;
278  std::shared_ptr<Ledger const> validatedLedger;
279 
280  {
282  working_ = false;
284  if (stop_)
285  {
286  return;
287  }
288  cond_.wait(lock);
289  if (newLedger_)
290  {
291  validatedLedger = std::move(newLedger_);
292  }
293  else
294  continue;
295  }
296 
297  LedgerIndex const validatedSeq = validatedLedger->info().seq;
298  if (!lastRotated)
299  {
300  lastRotated = validatedSeq;
301  state_db_.setLastRotated(lastRotated);
302  }
303 
304  bool const readyToRotate =
305  validatedSeq >= lastRotated + deleteInterval_ &&
306  canDelete_ >= lastRotated - 1 && !health();
307 
308  // Make sure we don't delete ledgers currently being
309  // imported into the ShardStore
310  bool const waitForImport = readyToRotate && [this, lastRotated] {
311  if (auto shardStore = app_.getShardStore())
312  {
313  if (auto sequence = shardStore->getDatabaseImportSequence())
314  return sequence <= lastRotated - 1;
315  }
316 
317  return false;
318  }();
319 
320  if (waitForImport)
321  {
322  JLOG(journal_.info())
323  << "NOT rotating validatedSeq " << validatedSeq
324  << " as rotation would interfere with ShardStore import";
325  }
326 
327  // will delete up to (not including) lastRotated
328  if (readyToRotate && !waitForImport)
329  {
330  JLOG(journal_.warn())
331  << "rotating validatedSeq " << validatedSeq << " lastRotated "
332  << lastRotated << " deleteInterval " << deleteInterval_
333  << " canDelete_ " << canDelete_ << " state "
334  << app_.getOPs().strOperatingMode(false) << " age "
336 
337  clearPrior(lastRotated);
338  switch (health())
339  {
340  case Health::stopping:
341  return;
342  case Health::unhealthy:
343  continue;
344  case Health::ok:
345  default:;
346  }
347 
348  JLOG(journal_.debug()) << "copying ledger " << validatedSeq;
349  std::uint64_t nodeCount = 0;
350  validatedLedger->stateMap().snapShot(false)->visitNodes(std::bind(
352  this,
353  std::ref(nodeCount),
354  std::placeholders::_1));
355  switch (health())
356  {
357  case Health::stopping:
358  return;
359  case Health::unhealthy:
360  continue;
361  case Health::ok:
362  default:;
363  }
364  // Only log if we completed without a "health" abort
365  JLOG(journal_.debug()) << "copied ledger " << validatedSeq
366  << " nodecount " << nodeCount;
367 
368  JLOG(journal_.debug()) << "freshening caches";
369  freshenCaches();
370  switch (health())
371  {
372  case Health::stopping:
373  return;
374  case Health::unhealthy:
375  continue;
376  case Health::ok:
377  default:;
378  }
379  // Only log if we completed without a "health" abort
380  JLOG(journal_.debug()) << validatedSeq << " freshened caches";
381 
382  JLOG(journal_.trace()) << "Making a new backend";
383  auto newBackend = makeBackendRotating();
384  JLOG(journal_.debug())
385  << validatedSeq << " new backend " << newBackend->getName();
386 
387  clearCaches(validatedSeq);
388  switch (health())
389  {
390  case Health::stopping:
391  return;
392  case Health::unhealthy:
393  continue;
394  case Health::ok:
395  default:;
396  }
397 
398  lastRotated = validatedSeq;
399 
401  [&](std::string const& writableBackendName) {
402  SavedState savedState;
403  savedState.writableDb = newBackend->getName();
404  savedState.archiveDb = writableBackendName;
405  savedState.lastRotated = lastRotated;
406  state_db_.setState(savedState);
407 
408  clearCaches(validatedSeq);
409 
410  return std::move(newBackend);
411  });
412 
413  JLOG(journal_.warn()) << "finished rotation " << validatedSeq;
414  }
415  }
416 }
417 
418 void
420 {
422  boost::filesystem::path dbPath = get(section, "path");
423 
424  if (boost::filesystem::exists(dbPath))
425  {
426  if (!boost::filesystem::is_directory(dbPath))
427  {
428  journal_.error()
429  << "node db path must be a directory. " << dbPath.string();
430  Throw<std::runtime_error>("node db path must be a directory.");
431  }
432  }
433  else
434  {
435  boost::filesystem::create_directories(dbPath);
436  }
437 
438  SavedState state = state_db_.getState();
439 
440  {
441  auto update = [&dbPath](std::string& sPath) {
442  if (sPath.empty())
443  return false;
444 
445  // Check if configured "path" matches stored directory path
446  using namespace boost::filesystem;
447  auto const stored{path(sPath)};
448  if (stored.parent_path() == dbPath)
449  return false;
450 
451  sPath = (dbPath / stored.filename()).string();
452  return true;
453  };
454 
455  if (update(state.writableDb))
456  {
457  update(state.archiveDb);
458  state_db_.setState(state);
459  }
460  }
461 
462  bool writableDbExists = false;
463  bool archiveDbExists = false;
464 
465  for (boost::filesystem::directory_iterator it(dbPath);
466  it != boost::filesystem::directory_iterator();
467  ++it)
468  {
469  if (!state.writableDb.compare(it->path().string()))
470  writableDbExists = true;
471  else if (!state.archiveDb.compare(it->path().string()))
472  archiveDbExists = true;
473  else if (!dbPrefix_.compare(it->path().stem().string()))
474  boost::filesystem::remove_all(it->path());
475  }
476 
477  if ((!writableDbExists && state.writableDb.size()) ||
478  (!archiveDbExists && state.archiveDb.size()) ||
479  (writableDbExists != archiveDbExists) ||
480  state.writableDb.empty() != state.archiveDb.empty())
481  {
482  boost::filesystem::path stateDbPathName =
483  app_.config().legacy("database_path");
484  stateDbPathName /= dbName_;
485  stateDbPathName += "*";
486 
487  journal_.error()
488  << "state db error:\n"
489  << " writableDbExists " << writableDbExists << " archiveDbExists "
490  << archiveDbExists << '\n'
491  << " writableDb '" << state.writableDb << "' archiveDb '"
492  << state.archiveDb << "\n\n"
493  << "The existing data is in a corrupted state.\n"
494  << "To resume operation, remove the files matching "
495  << stateDbPathName.string() << " and contents of the directory "
496  << get(section, "path") << '\n'
497  << "Optionally, you can move those files to another\n"
498  << "location if you wish to analyze or back up the data.\n"
499  << "However, there is no guarantee that the data in its\n"
500  << "existing form is usable.";
501 
502  Throw<std::runtime_error>("state db error");
503  }
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 || health() != Health::ok)
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 (health())
577  return;
578  if (min < lastRotated)
580  if (health())
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 (health())
621  return;
622 
624  dynamic_cast<RelationalDBInterfaceSqlite*>(
626 
627  clearSql(
628  lastRotated,
629  "Ledgers",
630  [&iface]() -> std::optional<LedgerIndex> {
631  return iface->getMinLedgerSeq();
632  },
633  [&iface](LedgerIndex min) -> void {
634  iface->deleteBeforeLedgerSeq(min);
635  });
636  if (health())
637  return;
638 
639  if (!app_.config().useTxTables())
640  return;
641 
642  clearSql(
643  lastRotated,
644  "Transactions",
645  [&iface]() -> std::optional<LedgerIndex> {
646  return iface->getTransactionsMinLedgerSeq();
647  },
648  [&iface](LedgerIndex min) -> void {
650  });
651  if (health())
652  return;
653 
654  clearSql(
655  lastRotated,
656  "AccountTransactions",
657  [&iface]() -> std::optional<LedgerIndex> {
658  return iface->getAccountTransactionsMinLedgerSeq();
659  },
660  [&iface](LedgerIndex min) -> void {
662  });
663  if (health())
664  return;
665 }
666 
669 {
670  {
671  std::lock_guard lock(mutex_);
672  if (stop_)
673  return Health::stopping;
674  }
675  if (!netOPs_)
676  return Health::ok;
677  assert(deleteInterval_);
678 
679  if (healthy_)
680  {
681  auto age = ledgerMaster_->getValidatedLedgerAge();
683  if (recoveryWaitTime_ && mode == OperatingMode::SYNCING &&
684  age < ageThreshold_)
685  {
686  JLOG(journal_.warn())
687  << "Waiting " << recoveryWaitTime_->count()
688  << "s for node to get back into sync with network. state: "
689  << app_.getOPs().strOperatingMode(mode, false) << ". age "
690  << age.count() << 's';
692 
694  mode = netOPs_->getOperatingMode();
695  }
696  if (mode != OperatingMode::FULL || age > ageThreshold_)
697  {
698  JLOG(journal_.warn()) << "Not deleting. state: "
699  << app_.getOPs().strOperatingMode(mode, false)
700  << ". age " << age.count() << 's';
701  healthy_ = false;
702  }
703  }
704 
705  if (healthy_)
706  return Health::ok;
707  else
708  return Health::unhealthy;
709 }
710 
711 void
713 {
714  if (thread_.joinable())
715  {
716  {
717  std::lock_guard lock(mutex_);
718  stop_ = true;
719  cond_.notify_one();
720  }
721  thread_.join();
722  }
723 }
724 
727 {
728  // minimumOnline_ with 0 value is equivalent to unknown/not set.
729  // Don't attempt to acquire ledgers if that value is unknown.
731  return minimumOnline_.load();
732  return app_.getLedgerMaster().minSqlSeq();
733 }
734 
735 //------------------------------------------------------------------------------
736 
739  Application& app,
740  NodeStore::Scheduler& scheduler,
741  beast::Journal journal)
742 {
743  return std::make_unique<SHAMapStoreImp>(app, scheduler, journal);
744 }
745 
746 } // 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:51
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:668
ripple::Application
Definition: Application.h:103
ripple::SHAMapStoreImp::dbPaths
void dbPaths()
Definition: SHAMapStoreImp.cpp:419
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:82
ripple::NodeStore::Database
Persistency layer for NodeObject.
Definition: Database.h:52
ripple::LedgerMaster::clearLedgerCachePrior
void clearLedgerCachePrior(LedgerIndex seq)
Definition: LedgerMaster.cpp:1850
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:215
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 given state.
Definition: RelationalDBInterface_global.cpp:395
ripple::SHAMapStoreImp::mutex_
std::mutex mutex_
Definition: SHAMapStoreImp.h:96
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:112
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:712
std::optional::emplace
T emplace(T... args)
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:43
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:47
ripple::SHAMapStoreImp::nodeStoreName_
static constexpr auto nodeStoreName_
Definition: SHAMapStoreImp.h:121
ripple::SHAMapStoreImp::run
void run()
Definition: SHAMapStoreImp.cpp:256
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:242
ripple::SHAMapStoreImp::dbRotating_
NodeStore::DatabaseRotating * dbRotating_
Definition: SHAMapStoreImp.h:89
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:72
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:291
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:942
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: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
std::string::compare
T compare(T... args)
ripple::SHAMapStoreImp::SavedStateDB::setState
void setState(SavedState const &state)
Definition: SHAMapStoreImp.cpp:67
ripple::SHAMapStoreImp::treeNodeCache_
TreeNodeCache * treeNodeCache_
Definition: SHAMapStoreImp.h:119
ripple::SHAMapTreeNode
Definition: SHAMapTreeNode.h:134
ripple::Config::useTxTables
bool useTxTables() const
Definition: Config.h:297
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
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:2320
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: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::NodeStore::Database::fetchNodeObject
std::shared_ptr< NodeObject > fetchNodeObject(uint256 const &hash, std::uint32_t ledgerSeq=0, FetchType fetchType=FetchType::synchronous)
Fetch a node object.
Definition: Database.cpp:158
ripple::getSavedState
SavedState getSavedState(soci::session &session)
getSavedState Returns saved state.
Definition: RelationalDBInterface_global.cpp:383
ripple::SHAMapStoreImp::Health
Health
Definition: SHAMapStoreImp.h:41
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:59
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:224
ripple::SHAMapStoreImp::backOff_
std::chrono::milliseconds backOff_
Definition: SHAMapStoreImp.h:105
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:91
ripple::SHAMapStoreImp::SavedStateDB::init
void init(BasicConfig const &config, std::string const &dbName)
Definition: SHAMapStoreImp.cpp:34
ripple::LedgerMaster::getValidatedLedgerAge
std::chrono::seconds getValidatedLedgerAge()
Definition: LedgerMaster.cpp:270
ripple::SHAMapStoreImp::dbName_
const std::string dbName_
Definition: SHAMapStoreImp.h:75
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:236
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
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:74
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: RelationalDBInterface_global.h:173
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:726
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::SHAMapHash::as_uint256
uint256 const & as_uint256() const
Definition: SHAMapTreeNode.h:59
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:167
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::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:738
std::unique_ptr
STL class.
ripple::SHAMapStoreImp::freshenCache
bool freshenCache(CacheInstance &cache)
Definition: SHAMapStoreImp.h:194
ripple::SavedState
Definition: RelationalDBInterface_global.h:169
ripple::LedgerMaster::clearPriorLedgers
void clearPriorLedgers(LedgerIndex seq)
Definition: LedgerMaster.cpp:1842
std::condition_variable::notify_all
T notify_all(T... args)
ripple::BasicConfig
Holds unparsed configuration information.
Definition: BasicConfig.h:215
ripple::detail::BasicFullBelowCache::clear
void clear()
Definition: FullBelowCache.h:127
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:226
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::Application::getMasterTransaction
virtual TransactionMaster & getMasterTransaction()=0
ripple::OperatingMode::FULL
@ FULL
we have the ledger and can even validate