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/misc/SHAMapStoreImp.h>
21 
22 #include <ripple/app/ledger/TransactionMaster.h>
23 #include <ripple/app/misc/NetworkOPs.h>
24 #include <ripple/app/rdb/State.h>
25 #include <ripple/app/rdb/backend/SQLiteDatabase.h>
26 #include <ripple/beast/core/CurrentThreadName.h>
27 #include <ripple/core/ConfigSections.h>
28 #include <ripple/core/Pg.h>
29 #include <ripple/nodestore/Scheduler.h>
30 #include <ripple/nodestore/impl/DatabaseRotatingImp.h>
31 #include <ripple/shamap/SHAMapMissingNode.h>
32 
33 #include <boost/algorithm/string/predicate.hpp>
34 
35 namespace ripple {
36 void
38  BasicConfig const& config,
39  std::string const& dbName)
40 {
41  std::lock_guard lock(mutex_);
42  initStateDB(sqlDb_, config, dbName);
43 }
44 
47 {
48  std::lock_guard lock(mutex_);
49 
50  return ripple::getCanDelete(sqlDb_);
51 }
52 
55 {
56  std::lock_guard lock(mutex_);
57 
58  return ripple::setCanDelete(sqlDb_, canDelete);
59 }
60 
63 {
64  std::lock_guard lock(mutex_);
65 
66  return ripple::getSavedState(sqlDb_);
67 }
68 
69 void
71 {
72  std::lock_guard lock(mutex_);
73  ripple::setSavedState(sqlDb_, state);
74 }
75 
76 void
78 {
79  std::lock_guard lock(mutex_);
80  ripple::setLastRotated(sqlDb_, seq);
81 }
82 
83 //------------------------------------------------------------------------------
84 
86  Application& app,
87  NodeStore::Scheduler& scheduler,
88  beast::Journal journal)
89  : app_(app)
90  , scheduler_(scheduler)
91  , journal_(journal)
92  , working_(true)
93  , canDelete_(std::numeric_limits<LedgerIndex>::max())
94 {
95  Config& config{app.config()};
96 
97  Section& section{config.section(ConfigSection::nodeDatabase())};
98  if (section.empty())
99  {
100  Throw<std::runtime_error>(
101  "Missing [" + ConfigSection::nodeDatabase() +
102  "] entry in configuration file");
103  }
104 
105  // RocksDB only. Use sensible defaults if no values specified.
106  if (boost::iequals(get(section, "type"), "RocksDB"))
107  {
108  if (!section.exists("cache_mb"))
109  {
110  section.set(
111  "cache_mb",
112  std::to_string(config.getValueFor(SizedItem::hashNodeDBCache)));
113  }
114 
115  if (!section.exists("filter_bits") && (config.NODE_SIZE >= 2))
116  section.set("filter_bits", "10");
117  }
118 
119  get_if_exists(section, "online_delete", deleteInterval_);
120 
121  if (deleteInterval_)
122  {
123  if (app_.config().reporting())
124  {
125  Throw<std::runtime_error>(
126  "Reporting does not support online_delete. Remove "
127  "online_delete info from config");
128  }
129 
130  // Configuration that affects the behavior of online delete
131  get_if_exists(section, "delete_batch", deleteBatch_);
132  std::uint32_t temp;
133  if (get_if_exists(section, "back_off_milliseconds", temp) ||
134  // Included for backward compaibility with an undocumented setting
135  get_if_exists(section, "backOff", temp))
136  {
138  }
139  if (get_if_exists(section, "age_threshold_seconds", temp))
141  if (get_if_exists(section, "recovery_wait_seconds", temp))
143 
144  get_if_exists(section, "advisory_delete", advisoryDelete_);
145 
146  auto const minInterval = config.standalone()
149  if (deleteInterval_ < minInterval)
150  {
151  Throw<std::runtime_error>(
152  "online_delete must be at least " +
153  std::to_string(minInterval));
154  }
155 
156  if (config.LEDGER_HISTORY > deleteInterval_)
157  {
158  Throw<std::runtime_error>(
159  "online_delete must not be less than ledger_history "
160  "(currently " +
161  std::to_string(config.LEDGER_HISTORY) + ")");
162  }
163 
164  state_db_.init(config, dbName_);
165  dbPaths();
166  }
167 }
168 
171 {
173 
174  // Provide default values:
175  if (!nscfg.exists("cache_size"))
176  nscfg.set(
177  "cache_size",
179  SizedItem::treeCacheSize, std::nullopt)));
180 
181  if (!nscfg.exists("cache_age"))
182  nscfg.set(
183  "cache_age",
185  SizedItem::treeCacheAge, std::nullopt)));
186 
188 
189  if (deleteInterval_)
190  {
191  if (app_.config().reporting())
192  {
193  Throw<std::runtime_error>(
194  "Reporting does not support online_delete. Remove "
195  "online_delete info from config");
196  }
197  SavedState state = state_db_.getState();
198  auto writableBackend = makeBackendRotating(state.writableDb);
199  auto archiveBackend = makeBackendRotating(state.archiveDb);
200  if (!state.writableDb.size())
201  {
202  state.writableDb = writableBackend->getName();
203  state.archiveDb = archiveBackend->getName();
204  state_db_.setState(state);
205  }
206 
207  // Create NodeStore with two backends to allow online deletion of
208  // data
209  auto dbr = std::make_unique<NodeStore::DatabaseRotatingImp>(
210  scheduler_,
211  readThreads,
212  std::move(writableBackend),
213  std::move(archiveBackend),
214  nscfg,
216  fdRequired_ += dbr->fdRequired();
217  dbRotating_ = dbr.get();
218  db.reset(dynamic_cast<NodeStore::Database*>(dbr.release()));
219  }
220  else
221  {
223  megabytes(
224  app_.config().getValueFor(SizedItem::burstSize, std::nullopt)),
225  scheduler_,
226  readThreads,
227  nscfg,
229  fdRequired_ += db->fdRequired();
230  }
231  return db;
232 }
233 
234 void
236 {
237  {
238  std::lock_guard lock(mutex_);
239  newLedger_ = ledger;
240  working_ = true;
241  }
242  cond_.notify_one();
243 }
244 
245 void
247 {
248  if (!working_)
249  return;
250 
252  rendezvous_.wait(lock, [&] { return !working_; });
253 }
254 
255 int
257 {
258  return fdRequired_;
259 }
260 
261 bool
263 {
264  // Copy a single record from node to dbRotating_
266  node.getHash().as_uint256(),
267  0,
269  true);
270  if (!(++nodeCount % checkHealthInterval_))
271  {
272  if (healthWait() == stopping)
273  return false;
274  }
275 
276  return true;
277 }
278 
279 void
281 {
282  if (app_.config().reporting())
283  {
284  assert(false);
285  Throw<std::runtime_error>(
286  "Reporting does not support online_delete. Remove "
287  "online_delete info from config");
288  }
289  beast::setCurrentThreadName("SHAMapStore");
290  LedgerIndex lastRotated = state_db_.getState().lastRotated;
291  netOPs_ = &app_.getOPs();
295 
296  if (advisoryDelete_)
298 
299  while (true)
300  {
301  healthy_ = true;
302  std::shared_ptr<Ledger const> validatedLedger;
303 
304  {
306  working_ = false;
308  if (stop_)
309  {
310  return;
311  }
312  cond_.wait(lock);
313  if (newLedger_)
314  {
315  validatedLedger = std::move(newLedger_);
316  }
317  else
318  continue;
319  }
320 
321  LedgerIndex const validatedSeq = validatedLedger->info().seq;
322  if (!lastRotated)
323  {
324  lastRotated = validatedSeq;
325  state_db_.setLastRotated(lastRotated);
326  }
327 
328  bool const readyToRotate =
329  validatedSeq >= lastRotated + deleteInterval_ &&
330  canDelete_ >= lastRotated - 1 && healthWait() == keepGoing;
331 
332  // Make sure we don't delete ledgers currently being
333  // imported into the ShardStore
334  bool const waitForImport = readyToRotate && [this, lastRotated] {
335  if (auto shardStore = app_.getShardStore())
336  {
337  if (auto sequence = shardStore->getDatabaseImportSequence())
338  return sequence <= lastRotated - 1;
339  }
340 
341  return false;
342  }();
343 
344  if (waitForImport)
345  {
346  JLOG(journal_.info())
347  << "NOT rotating validatedSeq " << validatedSeq
348  << " as rotation would interfere with ShardStore import";
349  }
350 
351  // will delete up to (not including) lastRotated
352  if (readyToRotate && !waitForImport)
353  {
354  JLOG(journal_.warn())
355  << "rotating validatedSeq " << validatedSeq << " lastRotated "
356  << lastRotated << " deleteInterval " << deleteInterval_
357  << " canDelete_ " << canDelete_ << " state "
358  << app_.getOPs().strOperatingMode(false) << " age "
360 
361  clearPrior(lastRotated);
362  if (healthWait() == stopping)
363  return;
364 
365  JLOG(journal_.debug()) << "copying ledger " << validatedSeq;
366  std::uint64_t nodeCount = 0;
367 
368  try
369  {
370  validatedLedger->stateMap().snapShot(false)->visitNodes(
371  std::bind(
373  this,
374  std::ref(nodeCount),
375  std::placeholders::_1));
376  }
377  catch (SHAMapMissingNode const& e)
378  {
379  JLOG(journal_.error())
380  << "Missing node while copying ledger before rotate: "
381  << e.what();
382  continue;
383  }
384 
385  if (healthWait() == stopping)
386  return;
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  if (healthWait() == stopping)
394  return;
395  // Only log if we completed without a "health" abort
396  JLOG(journal_.debug()) << validatedSeq << " freshened caches";
397 
398  JLOG(journal_.trace()) << "Making a new backend";
399  auto newBackend = makeBackendRotating();
400  JLOG(journal_.debug())
401  << validatedSeq << " new backend " << newBackend->getName();
402 
403  clearCaches(validatedSeq);
404  if (healthWait() == stopping)
405  return;
406 
407  lastRotated = validatedSeq;
408 
410  [&](std::string const& writableBackendName) {
411  SavedState savedState;
412  savedState.writableDb = newBackend->getName();
413  savedState.archiveDb = writableBackendName;
414  savedState.lastRotated = lastRotated;
415  state_db_.setState(savedState);
416 
417  clearCaches(validatedSeq);
418 
419  return std::move(newBackend);
420  });
421 
422  JLOG(journal_.warn()) << "finished rotation " << validatedSeq;
423  }
424  }
425 }
426 
427 void
429 {
431  boost::filesystem::path dbPath = get(section, "path");
432 
433  if (boost::filesystem::exists(dbPath))
434  {
435  if (!boost::filesystem::is_directory(dbPath))
436  {
437  journal_.error()
438  << "node db path must be a directory. " << dbPath.string();
439  Throw<std::runtime_error>("node db path must be a directory.");
440  }
441  }
442  else
443  {
444  boost::filesystem::create_directories(dbPath);
445  }
446 
447  SavedState state = state_db_.getState();
448 
449  {
450  auto update = [&dbPath](std::string& sPath) {
451  if (sPath.empty())
452  return false;
453 
454  // Check if configured "path" matches stored directory path
455  using namespace boost::filesystem;
456  auto const stored{path(sPath)};
457  if (stored.parent_path() == dbPath)
458  return false;
459 
460  sPath = (dbPath / stored.filename()).string();
461  return true;
462  };
463 
464  if (update(state.writableDb))
465  {
466  update(state.archiveDb);
467  state_db_.setState(state);
468  }
469  }
470 
471  bool writableDbExists = false;
472  bool archiveDbExists = false;
473 
475  for (boost::filesystem::directory_iterator it(dbPath);
476  it != boost::filesystem::directory_iterator();
477  ++it)
478  {
479  if (!state.writableDb.compare(it->path().string()))
480  writableDbExists = true;
481  else if (!state.archiveDb.compare(it->path().string()))
482  archiveDbExists = true;
483  else if (!dbPrefix_.compare(it->path().stem().string()))
484  pathsToDelete.push_back(it->path());
485  }
486 
487  if ((!writableDbExists && state.writableDb.size()) ||
488  (!archiveDbExists && state.archiveDb.size()) ||
489  (writableDbExists != archiveDbExists) ||
490  state.writableDb.empty() != state.archiveDb.empty())
491  {
492  boost::filesystem::path stateDbPathName =
493  app_.config().legacy("database_path");
494  stateDbPathName /= dbName_;
495  stateDbPathName += "*";
496 
497  journal_.error()
498  << "state db error:\n"
499  << " writableDbExists " << writableDbExists << " archiveDbExists "
500  << archiveDbExists << '\n'
501  << " writableDb '" << state.writableDb << "' archiveDb '"
502  << state.archiveDb << "\n\n"
503  << "The existing data is in a corrupted state.\n"
504  << "To resume operation, remove the files matching "
505  << stateDbPathName.string() << " and contents of the directory "
506  << get(section, "path") << '\n'
507  << "Optionally, you can move those files to another\n"
508  << "location if you wish to analyze or back up the data.\n"
509  << "However, there is no guarantee that the data in its\n"
510  << "existing form is usable.";
511 
512  Throw<std::runtime_error>("state db error");
513  }
514 
515  // The necessary directories exist. Now, remove any others.
516  for (boost::filesystem::path& p : pathsToDelete)
517  boost::filesystem::remove_all(p);
518 }
519 
522 {
524  boost::filesystem::path newPath;
525 
526  if (path.size())
527  {
528  newPath = path;
529  }
530  else
531  {
532  boost::filesystem::path p = get(section, "path");
533  p /= dbPrefix_;
534  p += ".%%%%";
535  newPath = boost::filesystem::unique_path(p);
536  }
537  section.set("path", newPath.string());
538 
540  section,
541  megabytes(
542  app_.config().getValueFor(SizedItem::burstSize, std::nullopt)),
543  scheduler_,
545  backend->open();
546  return backend;
547 }
548 
549 void
551  LedgerIndex lastRotated,
552  std::string const& TableName,
553  std::function<std::optional<LedgerIndex>()> const& getMinSeq,
554  std::function<void(LedgerIndex)> const& deleteBeforeSeq)
555 {
556  assert(deleteInterval_);
558 
559  {
560  JLOG(journal_.trace())
561  << "Begin: Look up lowest value of: " << TableName;
562  auto m = getMinSeq();
563  JLOG(journal_.trace()) << "End: Look up lowest value of: " << TableName;
564  if (!m)
565  return;
566  min = *m;
567  }
568 
569  if (min > lastRotated || healthWait() == stopping)
570  return;
571  if (min == lastRotated)
572  {
573  // Micro-optimization mainly to clarify logs
574  JLOG(journal_.trace()) << "Nothing to delete from " << TableName;
575  return;
576  }
577 
578  JLOG(journal_.debug()) << "start deleting in: " << TableName << " from "
579  << min << " to " << lastRotated;
580  while (min < lastRotated)
581  {
582  min = std::min(lastRotated, min + deleteBatch_);
583  JLOG(journal_.trace())
584  << "Begin: Delete up to " << deleteBatch_
585  << " rows with LedgerSeq < " << min << " from: " << TableName;
586  deleteBeforeSeq(min);
587  JLOG(journal_.trace())
588  << "End: Delete up to " << deleteBatch_ << " rows with LedgerSeq < "
589  << min << " from: " << TableName;
590  if (healthWait() == stopping)
591  return;
592  if (min < lastRotated)
594  if (healthWait() == stopping)
595  return;
596  }
597  JLOG(journal_.debug()) << "finished deleting from: " << TableName;
598 }
599 
600 void
602 {
603  ledgerMaster_->clearLedgerCachePrior(validatedSeq);
605 }
606 
607 void
609 {
611  return;
613  return;
614 }
615 
616 void
618 {
619  if (app_.config().reporting())
620  {
621  assert(false);
622  Throw<std::runtime_error>(
623  "Reporting does not support online_delete. Remove "
624  "online_delete info from config");
625  }
626  // Do not allow ledgers to be acquired from the network
627  // that are about to be deleted.
628  minimumOnline_ = lastRotated + 1;
629  JLOG(journal_.trace()) << "Begin: Clear internal ledgers up to "
630  << lastRotated;
631  ledgerMaster_->clearPriorLedgers(lastRotated);
632  JLOG(journal_.trace()) << "End: Clear internal ledgers up to "
633  << lastRotated;
634  if (healthWait() == stopping)
635  return;
636 
637  SQLiteDatabase* const db =
638  dynamic_cast<SQLiteDatabase*>(&app_.getRelationalDatabase());
639 
640  if (!db)
641  Throw<std::runtime_error>("Failed to get relational database");
642 
643  clearSql(
644  lastRotated,
645  "Ledgers",
646  [db]() -> std::optional<LedgerIndex> { return db->getMinLedgerSeq(); },
647  [db](LedgerIndex min) -> void { db->deleteBeforeLedgerSeq(min); });
648  if (healthWait() == stopping)
649  return;
650 
651  if (!app_.config().useTxTables())
652  return;
653 
654  clearSql(
655  lastRotated,
656  "Transactions",
657  [&db]() -> std::optional<LedgerIndex> {
658  return db->getTransactionsMinLedgerSeq();
659  },
660  [&db](LedgerIndex min) -> void {
662  });
663  if (healthWait() == stopping)
664  return;
665 
666  clearSql(
667  lastRotated,
668  "AccountTransactions",
669  [&db]() -> std::optional<LedgerIndex> {
671  },
672  [&db](LedgerIndex min) -> void {
674  });
675  if (healthWait() == stopping)
676  return;
677 }
678 
681 {
682  auto age = ledgerMaster_->getValidatedLedgerAge();
684  std::unique_lock lock(mutex_);
685  while (!stop_ && (mode != OperatingMode::FULL || age > ageThreshold_))
686  {
687  lock.unlock();
688  JLOG(journal_.warn()) << "Waiting " << recoveryWaitTime_.count()
689  << "s for node to stabilize. state: "
690  << app_.getOPs().strOperatingMode(mode, false)
691  << ". age " << age.count() << 's';
694  mode = netOPs_->getOperatingMode();
695  lock.lock();
696  }
697 
698  return stop_ ? stopping : keepGoing;
699 }
700 
701 void
703 {
704  if (thread_.joinable())
705  {
706  {
707  std::lock_guard lock(mutex_);
708  stop_ = true;
709  cond_.notify_one();
710  }
711  thread_.join();
712  }
713 }
714 
717 {
718  // minimumOnline_ with 0 value is equivalent to unknown/not set.
719  // Don't attempt to acquire ledgers if that value is unknown.
721  return minimumOnline_.load();
722  return app_.getLedgerMaster().minSqlSeq();
723 }
724 
725 //------------------------------------------------------------------------------
726 
729  Application& app,
730  NodeStore::Scheduler& scheduler,
731  beast::Journal journal)
732 {
733  return std::make_unique<SHAMapStoreImp>(app, scheduler, journal);
734 }
735 
736 } // 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:54
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:428
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:85
ripple::NodeStore::Database
Persistency layer for NodeObject.
Definition: Database.h:51
ripple::LedgerMaster::clearLedgerCachePrior
void clearLedgerCachePrior(LedgerIndex seq)
Definition: LedgerMaster.cpp:1895
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:235
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:116
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:170
ripple::SavedState::writableDb
std::string writableDb
Definition: State.h:35
std::chrono::milliseconds
ripple::SHAMapStoreImp::stop
void stop() override
Definition: SHAMapStoreImp.cpp:702
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:608
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:46
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:120
ripple::SHAMapStoreImp::healthWait
HealthResult healthWait()
Definition: SHAMapStoreImp.cpp:680
ripple::SHAMapStoreImp::run
void run()
Definition: SHAMapStoreImp.cpp:280
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:262
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::SHAMapMissingNode
Definition: SHAMapMissingNode.h:55
ripple::SHAMapStoreImp::app_
Application & app_
Definition: SHAMapStoreImp.h:72
std::vector::push_back
T push_back(T... args)
ripple::SHAMapStoreImp::HealthResult
HealthResult
This is a health check for online deletion that waits until rippled is stable before returning.
Definition: SHAMapStoreImp.h:232
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:550
std::thread::joinable
T joinable(T... args)
ripple::Config::reporting
bool reporting() const
Definition: Config.h:337
ripple::SHAMapStoreImp::recoveryWaitTime_
std::chrono::seconds recoveryWaitTime_
If the node is out of sync during an online_delete healthWait() call, sleep the thread for this time,...
Definition: SHAMapStoreImp.h:111
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:1022
ripple::Application::getLedgerMaster
virtual LedgerMaster & getLedgerMaster()=0
ripple::Config
Definition: Config.h:89
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:70
ripple::SHAMapStoreImp::treeNodeCache_
TreeNodeCache * treeNodeCache_
Definition: SHAMapStoreImp.h:118
ripple::SHAMapTreeNode
Definition: SHAMapTreeNode.h:53
ripple::Config::useTxTables
bool useTxTables() const
Definition: Config.h:343
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:2367
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:617
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:62
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:37
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::stopping
@ stopping
Definition: SHAMapStoreImp.h:232
ripple::SHAMapStoreImp::fdRequired
int fdRequired() const override
Returns the number of file descriptors that are needed.
Definition: SHAMapStoreImp.cpp:256
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:77
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:117
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:716
ripple::SHAMapStoreImp::clearCaches
void clearCaches(LedgerIndex validatedSeq)
Definition: SHAMapStoreImp.cpp:601
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:521
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:252
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:115
ripple::make_SHAMapStore
std::unique_ptr< SHAMapStore > make_SHAMapStore(Application &app, NodeStore::Scheduler &scheduler, beast::Journal journal)
Definition: SHAMapStoreImp.cpp:728
std::unique_ptr
STL class.
ripple::NodeStore::FetchType::synchronous
@ synchronous
ripple::SHAMapStoreImp::freshenCache
bool freshenCache(CacheInstance &cache)
Definition: SHAMapStoreImp.h:193
ripple::SavedState
Definition: State.h:33
ripple::LedgerMaster::clearPriorLedgers
void clearPriorLedgers(LedgerIndex seq)
Definition: LedgerMaster.cpp:1887
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:246
std::thread::join
T join(T... args)
std::runtime_error::what
T what(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::SHAMapStoreImp::keepGoing
@ keepGoing
Definition: SHAMapStoreImp.h:232
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