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/beast/core/CurrentThreadName.h>
24 #include <ripple/core/ConfigSections.h>
25 #include <ripple/nodestore/impl/DatabaseRotatingImp.h>
26 
27 #include <boost/algorithm/string/predicate.hpp>
28 
29 namespace ripple {
30 void
32  BasicConfig const& config,
33  std::string const& dbName)
34 {
35  std::lock_guard lock(mutex_);
36 
37  open(session_, config, dbName);
38 
39  session_ << "PRAGMA synchronous=FULL;";
40 
41  session_ << "CREATE TABLE IF NOT EXISTS DbState ("
42  " Key INTEGER PRIMARY KEY,"
43  " WritableDb TEXT,"
44  " ArchiveDb TEXT,"
45  " LastRotatedLedger INTEGER"
46  ");";
47 
48  session_ << "CREATE TABLE IF NOT EXISTS CanDelete ("
49  " Key INTEGER PRIMARY KEY,"
50  " CanDeleteSeq INTEGER"
51  ");";
52 
53  std::int64_t count = 0;
54  {
55  boost::optional<std::int64_t> countO;
56  session_ << "SELECT COUNT(Key) FROM DbState WHERE Key = 1;",
57  soci::into(countO);
58  if (!countO)
59  Throw<std::runtime_error>(
60  "Failed to fetch Key Count from DbState.");
61  count = *countO;
62  }
63 
64  if (!count)
65  {
66  session_ << "INSERT INTO DbState VALUES (1, '', '', 0);";
67  }
68 
69  {
70  boost::optional<std::int64_t> countO;
71  session_ << "SELECT COUNT(Key) FROM CanDelete WHERE Key = 1;",
72  soci::into(countO);
73  if (!countO)
74  Throw<std::runtime_error>(
75  "Failed to fetch Key Count from CanDelete.");
76  count = *countO;
77  }
78 
79  if (!count)
80  {
81  session_ << "INSERT INTO CanDelete VALUES (1, 0);";
82  }
83 }
84 
87 {
88  LedgerIndex seq;
89  std::lock_guard lock(mutex_);
90 
91  session_ << "SELECT CanDeleteSeq FROM CanDelete WHERE Key = 1;",
92  soci::into(seq);
93  ;
94 
95  return seq;
96 }
97 
100 {
101  std::lock_guard lock(mutex_);
102 
103  session_ << "UPDATE CanDelete SET CanDeleteSeq = :canDelete WHERE Key = 1;",
104  soci::use(canDelete);
105 
106  return canDelete;
107 }
108 
111 {
112  SavedState state;
113 
114  std::lock_guard lock(mutex_);
115 
116  session_ << "SELECT WritableDb, ArchiveDb, LastRotatedLedger"
117  " FROM DbState WHERE Key = 1;",
118  soci::into(state.writableDb), soci::into(state.archiveDb),
119  soci::into(state.lastRotated);
120 
121  return state;
122 }
123 
124 void
126 {
127  std::lock_guard lock(mutex_);
128  session_ << "UPDATE DbState"
129  " SET WritableDb = :writableDb,"
130  " ArchiveDb = :archiveDb,"
131  " LastRotatedLedger = :lastRotated"
132  " WHERE Key = 1;",
133  soci::use(state.writableDb), soci::use(state.archiveDb),
134  soci::use(state.lastRotated);
135 }
136 
137 void
139 {
140  std::lock_guard lock(mutex_);
141  session_ << "UPDATE DbState SET LastRotatedLedger = :seq"
142  " WHERE Key = 1;",
143  soci::use(seq);
144 }
145 
146 //------------------------------------------------------------------------------
147 
149  Application& app,
150  Stoppable& parent,
151  NodeStore::Scheduler& scheduler,
152  beast::Journal journal)
153  : SHAMapStore(parent)
154  , app_(app)
155  , scheduler_(scheduler)
156  , journal_(journal)
157  , working_(true)
158  , canDelete_(std::numeric_limits<LedgerIndex>::max())
159 {
160  Config& config{app.config()};
161  Section& section{config.section(ConfigSection::nodeDatabase())};
162  if (section.empty())
163  {
164  Throw<std::runtime_error>(
165  "Missing [" + ConfigSection::nodeDatabase() +
166  "] entry in configuration file");
167  }
168 
169  // RocksDB only. Use sensible defaults if no values specified.
170  if (boost::iequals(get<std::string>(section, "type"), "RocksDB"))
171  {
172  if (!section.exists("cache_mb"))
173  {
174  section.set(
175  "cache_mb",
176  std::to_string(config.getValueFor(SizedItem::hashNodeDBCache)));
177  }
178 
179  if (!section.exists("filter_bits") && (config.NODE_SIZE >= 2))
180  section.set("filter_bits", "10");
181  }
182 
183  get_if_exists(section, "online_delete", deleteInterval_);
184 
185  if (deleteInterval_)
186  {
187  // Configuration that affects the behavior of online delete
188  get_if_exists(section, "delete_batch", deleteBatch_);
189  std::uint32_t temp;
190  if (get_if_exists(section, "back_off_milliseconds", temp) ||
191  // Included for backward compaibility with an undocumented setting
192  get_if_exists(section, "backOff", temp))
193  {
195  }
196  if (get_if_exists(section, "age_threshold_seconds", temp))
198  if (get_if_exists(section, "recovery_wait_seconds", temp))
200 
201  get_if_exists(section, "advisory_delete", advisoryDelete_);
202 
203  auto const minInterval = config.standalone()
206  if (deleteInterval_ < minInterval)
207  {
208  Throw<std::runtime_error>(
209  "online_delete must be at least " +
210  std::to_string(minInterval));
211  }
212 
213  if (config.LEDGER_HISTORY > deleteInterval_)
214  {
215  Throw<std::runtime_error>(
216  "online_delete must not be less than ledger_history "
217  "(currently " +
218  std::to_string(config.LEDGER_HISTORY) + ")");
219  }
220 
221  state_db_.init(config, dbName_);
222  dbPaths();
223  }
224 }
225 
228 {
229  // Anything which calls addJob must be a descendant of the JobQueue.
230  // Therefore Database objects use the JobQueue as Stoppable parent.
232  if (deleteInterval_)
233  {
234  SavedState state = state_db_.getState();
235  auto writableBackend = makeBackendRotating(state.writableDb);
236  auto archiveBackend = makeBackendRotating(state.archiveDb);
237  if (!state.writableDb.size())
238  {
239  state.writableDb = writableBackend->getName();
240  state.archiveDb = archiveBackend->getName();
241  state_db_.setState(state);
242  }
243 
244  // Create NodeStore with two backends to allow online deletion of data
245  auto dbr = std::make_unique<NodeStore::DatabaseRotatingImp>(
246  name,
247  scheduler_,
248  readThreads,
249  app_.getJobQueue(),
250  std::move(writableBackend),
251  std::move(archiveBackend),
254  fdRequired_ += dbr->fdRequired();
255  dbRotating_ = dbr.get();
256  db.reset(dynamic_cast<NodeStore::Database*>(dbr.release()));
257  }
258  else
259  {
261  name,
262  scheduler_,
263  readThreads,
264  app_.getJobQueue(),
267  fdRequired_ += db->fdRequired();
268  }
269  return db;
270 }
271 
272 void
274 {
275  {
276  std::lock_guard lock(mutex_);
277  newLedger_ = ledger;
278  working_ = true;
279  }
280  cond_.notify_one();
281 }
282 
283 void
285 {
286  if (!working_)
287  return;
288 
290  rendezvous_.wait(lock, [&] { return !working_; });
291 }
292 
293 int
295 {
296  return fdRequired_;
297 }
298 
299 bool
301  std::uint64_t& nodeCount,
302  SHAMapAbstractNode const& node)
303 {
304  // Copy a single record from node to dbRotating_
305  dbRotating_->fetch(node.getNodeHash().as_uint256(), node.getSeq());
306  if (!(++nodeCount % checkHealthInterval_))
307  {
308  if (health())
309  return false;
310  }
311 
312  return true;
313 }
314 
315 void
317 {
318  beast::setCurrentThreadName("SHAMapStore");
319  LedgerIndex lastRotated = state_db_.getState().lastRotated;
320  netOPs_ = &app_.getOPs();
326 
327  if (advisoryDelete_)
329 
330  while (true)
331  {
332  healthy_ = true;
333  std::shared_ptr<Ledger const> validatedLedger;
334 
335  {
337  working_ = false;
339  if (stop_)
340  {
341  stopped();
342  return;
343  }
344  cond_.wait(lock);
345  if (newLedger_)
346  {
347  validatedLedger = std::move(newLedger_);
348  }
349  else
350  continue;
351  }
352 
353  LedgerIndex const validatedSeq = validatedLedger->info().seq;
354  if (!lastRotated)
355  {
356  lastRotated = validatedSeq;
357  state_db_.setLastRotated(lastRotated);
358  }
359 
360  // will delete up to (not including) lastRotated
361  if (validatedSeq >= lastRotated + deleteInterval_ &&
362  canDelete_ >= lastRotated - 1 && !health())
363  {
364  JLOG(journal_.warn())
365  << "rotating validatedSeq " << validatedSeq << " lastRotated "
366  << lastRotated << " deleteInterval " << deleteInterval_
367  << " canDelete_ " << canDelete_ << " state "
368  << app_.getOPs().strOperatingMode(false) << " age "
370 
371  clearPrior(lastRotated);
372  switch (health())
373  {
374  case Health::stopping:
375  stopped();
376  return;
377  case Health::unhealthy:
378  continue;
379  case Health::ok:
380  default:;
381  }
382 
383  JLOG(journal_.debug()) << "copying ledger " << validatedSeq;
384  std::uint64_t nodeCount = 0;
385  validatedLedger->stateMap().snapShot(false)->visitNodes(std::bind(
387  this,
388  std::ref(nodeCount),
389  std::placeholders::_1));
390  switch (health())
391  {
392  case Health::stopping:
393  stopped();
394  return;
395  case Health::unhealthy:
396  continue;
397  case Health::ok:
398  default:;
399  }
400  // Only log if we completed without a "health" abort
401  JLOG(journal_.debug()) << "copied ledger " << validatedSeq
402  << " nodecount " << nodeCount;
403 
404  JLOG(journal_.debug()) << "freshening caches";
405  freshenCaches();
406  switch (health())
407  {
408  case Health::stopping:
409  stopped();
410  return;
411  case Health::unhealthy:
412  continue;
413  case Health::ok:
414  default:;
415  }
416  // Only log if we completed without a "health" abort
417  JLOG(journal_.debug()) << validatedSeq << " freshened caches";
418 
419  JLOG(journal_.trace()) << "Making a new backend";
420  auto newBackend = makeBackendRotating();
421  JLOG(journal_.debug())
422  << validatedSeq << " new backend " << newBackend->getName();
423 
424  clearCaches(validatedSeq);
425  switch (health())
426  {
427  case Health::stopping:
428  stopped();
429  return;
430  case Health::unhealthy:
431  continue;
432  case Health::ok:
433  default:;
434  }
435 
436  lastRotated = validatedSeq;
437 
439  [&](std::string const& writableBackendName) {
440  SavedState savedState;
441  savedState.writableDb = newBackend->getName();
442  savedState.archiveDb = writableBackendName;
443  savedState.lastRotated = lastRotated;
444  state_db_.setState(savedState);
445 
446  clearCaches(validatedSeq);
447 
448  return std::move(newBackend);
449  });
450 
451  JLOG(journal_.warn()) << "finished rotation " << validatedSeq;
452  }
453  }
454 }
455 
456 void
458 {
460  boost::filesystem::path dbPath = get<std::string>(section, "path");
461 
462  if (boost::filesystem::exists(dbPath))
463  {
464  if (!boost::filesystem::is_directory(dbPath))
465  {
466  journal_.error()
467  << "node db path must be a directory. " << dbPath.string();
468  Throw<std::runtime_error>("node db path must be a directory.");
469  }
470  }
471  else
472  {
473  boost::filesystem::create_directories(dbPath);
474  }
475 
476  SavedState state = state_db_.getState();
477 
478  {
479  auto update = [&dbPath](std::string& sPath) {
480  if (sPath.empty())
481  return false;
482 
483  // Check if configured "path" matches stored directory path
484  using namespace boost::filesystem;
485  auto const stored{path(sPath)};
486  if (stored.parent_path() == dbPath)
487  return false;
488 
489  sPath = (dbPath / stored.filename()).string();
490  return true;
491  };
492 
493  if (update(state.writableDb))
494  {
495  update(state.archiveDb);
496  state_db_.setState(state);
497  }
498  }
499 
500  bool writableDbExists = false;
501  bool archiveDbExists = false;
502 
503  for (boost::filesystem::directory_iterator it(dbPath);
504  it != boost::filesystem::directory_iterator();
505  ++it)
506  {
507  if (!state.writableDb.compare(it->path().string()))
508  writableDbExists = true;
509  else if (!state.archiveDb.compare(it->path().string()))
510  archiveDbExists = true;
511  else if (!dbPrefix_.compare(it->path().stem().string()))
512  boost::filesystem::remove_all(it->path());
513  }
514 
515  if ((!writableDbExists && state.writableDb.size()) ||
516  (!archiveDbExists && state.archiveDb.size()) ||
517  (writableDbExists != archiveDbExists) ||
518  state.writableDb.empty() != state.archiveDb.empty())
519  {
520  boost::filesystem::path stateDbPathName =
521  app_.config().legacy("database_path");
522  stateDbPathName /= dbName_;
523  stateDbPathName += "*";
524 
525  journal_.error()
526  << "state db error:\n"
527  << " writableDbExists " << writableDbExists << " archiveDbExists "
528  << archiveDbExists << '\n'
529  << " writableDb '" << state.writableDb << "' archiveDb '"
530  << state.archiveDb << "\n\n"
531  << "The existing data is in a corrupted state.\n"
532  << "To resume operation, remove the files matching "
533  << stateDbPathName.string() << " and contents of the directory "
534  << get<std::string>(section, "path") << '\n'
535  << "Optionally, you can move those files to another\n"
536  << "location if you wish to analyze or back up the data.\n"
537  << "However, there is no guarantee that the data in its\n"
538  << "existing form is usable.";
539 
540  Throw<std::runtime_error>("state db error");
541  }
542 }
543 
546 {
548  boost::filesystem::path newPath;
549 
550  if (path.size())
551  {
552  newPath = path;
553  }
554  else
555  {
556  boost::filesystem::path p = get<std::string>(section, "path");
557  p /= dbPrefix_;
558  p += ".%%%%";
559  newPath = boost::filesystem::unique_path(p);
560  }
561  section.set("path", newPath.string());
562 
564  section, scheduler_, app_.logs().journal(nodeStoreName_))};
565  backend->open();
566  return backend;
567 }
568 
569 void
571  DatabaseCon& database,
572  LedgerIndex lastRotated,
573  std::string const& minQuery,
574  std::string const& deleteQuery)
575 {
576  assert(deleteInterval_);
578 
579  {
580  boost::optional<std::uint64_t> m;
581  JLOG(journal_.trace())
582  << "Begin: Look up lowest value of: " << minQuery;
583  {
584  auto db = database.checkoutDb();
585  *db << minQuery, soci::into(m);
586  }
587  JLOG(journal_.trace()) << "End: Look up lowest value of: " << minQuery;
588  if (!m)
589  return;
590  min = *m;
591  }
592 
593  if (min > lastRotated || health() != Health::ok)
594  return;
595  if (min == lastRotated)
596  {
597  // Micro-optimization mainly to clarify logs
598  JLOG(journal_.trace()) << "Nothing to delete from " << deleteQuery;
599  return;
600  }
601 
602  boost::format formattedDeleteQuery(deleteQuery);
603 
604  JLOG(journal_.debug()) << "start: " << deleteQuery << " from " << min
605  << " to " << lastRotated;
606  while (min < lastRotated)
607  {
608  min = std::min(lastRotated, min + deleteBatch_);
609  JLOG(journal_.trace()) << "Begin: Delete up to " << deleteBatch_
610  << " rows with LedgerSeq < " << min
611  << " using query: " << deleteQuery;
612  {
613  auto db = database.checkoutDb();
614  *db << boost::str(formattedDeleteQuery % min);
615  }
616  JLOG(journal_.trace())
617  << "End: Delete up to " << deleteBatch_ << " rows with LedgerSeq < "
618  << min << " using query: " << deleteQuery;
619  if (health())
620  return;
621  if (min < lastRotated)
623  if (health())
624  return;
625  }
626  JLOG(journal_.debug()) << "finished: " << deleteQuery;
627 }
628 
629 void
631 {
632  ledgerMaster_->clearLedgerCachePrior(validatedSeq);
634 }
635 
636 void
638 {
640  return;
642  return;
644  return;
645 }
646 
647 void
649 {
650  // Do not allow ledgers to be acquired from the network
651  // that are about to be deleted.
652  minimumOnline_ = lastRotated + 1;
653  JLOG(journal_.trace()) << "Begin: Clear internal ledgers up to "
654  << lastRotated;
655  ledgerMaster_->clearPriorLedgers(lastRotated);
656  JLOG(journal_.trace()) << "End: Clear internal ledgers up to "
657  << lastRotated;
658  if (health())
659  return;
660 
661  clearSql(
662  *ledgerDb_,
663  lastRotated,
664  "SELECT MIN(LedgerSeq) FROM Ledgers;",
665  "DELETE FROM Ledgers WHERE LedgerSeq < %u;");
666  if (health())
667  return;
668 
669  clearSql(
671  lastRotated,
672  "SELECT MIN(LedgerSeq) FROM Transactions;",
673  "DELETE FROM Transactions WHERE LedgerSeq < %u;");
674  if (health())
675  return;
676 
677  clearSql(
679  lastRotated,
680  "SELECT MIN(LedgerSeq) FROM AccountTransactions;",
681  "DELETE FROM AccountTransactions WHERE LedgerSeq < %u;");
682  if (health())
683  return;
684 }
685 
688 {
689  {
690  std::lock_guard lock(mutex_);
691  if (stop_)
692  return Health::stopping;
693  }
694  if (!netOPs_)
695  return Health::ok;
696  assert(deleteInterval_);
697 
698  if (healthy_)
699  {
700  auto age = ledgerMaster_->getValidatedLedgerAge();
702  if (recoveryWaitTime_ && mode == OperatingMode::SYNCING &&
703  age < ageThreshold_)
704  {
705  JLOG(journal_.warn())
706  << "Waiting " << recoveryWaitTime_->count()
707  << "s for node to get back into sync with network. state: "
708  << app_.getOPs().strOperatingMode(mode, false) << ". age "
709  << age.count() << 's';
711 
713  mode = netOPs_->getOperatingMode();
714  }
715  if (mode != OperatingMode::FULL || age > ageThreshold_)
716  {
717  JLOG(journal_.warn()) << "Not deleting. state: "
718  << app_.getOPs().strOperatingMode(mode, false)
719  << ". age " << age.count() << 's';
720  healthy_ = false;
721  }
722  }
723 
724  if (healthy_)
725  return Health::ok;
726  else
727  return Health::unhealthy;
728 }
729 
730 void
732 {
733  if (deleteInterval_)
734  {
735  {
736  std::lock_guard lock(mutex_);
737  stop_ = true;
738  }
739  cond_.notify_one();
740  }
741  else
742  {
743  stopped();
744  }
745 }
746 
747 void
749 {
750  if (deleteInterval_)
751  {
752  {
753  std::lock_guard lock(mutex_);
754  stop_ = true;
755  }
756  cond_.notify_one();
757  }
758  else
759  {
760  stopped();
761  }
762 }
763 
764 boost::optional<LedgerIndex>
766 {
767  // minimumOnline_ with 0 value is equivalent to unknown/not set.
768  // Don't attempt to acquire ledgers if that value is unknown.
770  return minimumOnline_.load();
771  return app_.getLedgerMaster().minSqlSeq();
772 }
773 
774 //------------------------------------------------------------------------------
775 
778  Application& app,
779  Stoppable& parent,
780  NodeStore::Scheduler& scheduler,
781  beast::Journal journal)
782 {
783  return std::make_unique<SHAMapStoreImp>(app, parent, scheduler, journal);
784 }
785 
786 } // namespace ripple
ripple::Section
Holds a collection of configuration values.
Definition: BasicConfig.h:43
ripple::SHAMapStoreImp::SavedStateDB::setCanDelete
LedgerIndex setCanDelete(LedgerIndex canDelete)
Definition: SHAMapStoreImp.cpp:99
ripple::SHAMapStoreImp::health
Health health()
Definition: SHAMapStoreImp.cpp:687
ripple::Application
Definition: Application.h:97
ripple::SHAMapStoreImp::dbPaths
void dbPaths()
Definition: SHAMapStoreImp.cpp:457
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::SHAMapStoreImp
SHAMapStoreImp(Application &app, Stoppable &parent, NodeStore::Scheduler &scheduler, beast::Journal journal)
Definition: SHAMapStoreImp.cpp:148
ripple::SHAMapStoreImp::healthy_
bool healthy_
Definition: SHAMapStoreImp.h:98
std::bind
T bind(T... args)
ripple::SHAMapStoreImp::scheduler_
NodeStore::Scheduler & scheduler_
Definition: SHAMapStoreImp.h:92
ripple::NodeStore::Database
Persistency layer for NodeObject.
Definition: Database.h:53
ripple::LedgerMaster::clearLedgerCachePrior
void clearLedgerCachePrior(LedgerIndex seq)
Definition: LedgerMaster.cpp:1764
std::string
STL class.
ripple::SHAMapStoreImp::ledgerDb_
DatabaseCon * ledgerDb_
Definition: SHAMapStoreImp.h:126
std::shared_ptr
STL class.
ripple::Stoppable::stopped
void stopped()
Called by derived classes to indicate that the stoppable has stopped.
Definition: Stoppable.cpp:72
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:102
ripple::SHAMapStoreImp::onLedgerClosed
void onLedgerClosed(std::shared_ptr< Ledger const > const &ledger) override
Called by LedgerMaster every time a ledger validates.
Definition: SHAMapStoreImp.cpp:273
ripple::LedgerMaster::minSqlSeq
boost::optional< LedgerIndex > minSqlSeq()
Definition: LedgerMaster.cpp:2191
ripple::SHAMapStoreImp::minimumDeletionInterval_
static const std::uint32_t minimumDeletionInterval_
Definition: SHAMapStoreImp.h:86
ripple::SHAMapStoreImp::dbPrefix_
const std::string dbPrefix_
Definition: SHAMapStoreImp.h:82
ripple::SHAMapStoreImp::ledgerMaster_
LedgerMaster * ledgerMaster_
Definition: SHAMapStoreImp.h:122
ripple::SHAMapStoreImp::mutex_
std::mutex mutex_
Definition: SHAMapStoreImp.h:101
std::string::size
T size(T... args)
std::chrono::milliseconds
ripple::SHAMapStore
class to create database, launch online delete thread, and related SQLite database
Definition: SHAMapStore.h:37
ripple::SHAMapStoreImp::transactionDb_
DatabaseCon * transactionDb_
Definition: SHAMapStoreImp.h:125
beast::Journal::warn
Stream warn() const
Definition: Journal.h:327
std::lock_guard
STL class.
ripple::NetworkOPs::getOperatingMode
virtual OperatingMode getOperatingMode() const =0
ripple::SHAMapStoreImp::journal_
const beast::Journal journal_
Definition: SHAMapStoreImp.h:93
ripple::SHAMapStoreImp::cond_
std::condition_variable cond_
Definition: SHAMapStoreImp.h:99
ripple::SHAMapStoreImp::freshenCaches
void freshenCaches()
Definition: SHAMapStoreImp.cpp:637
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:86
ripple::SHAMapStoreImp::SavedStateDB::mutex_
std::mutex mutex_
Definition: SHAMapStoreImp.h:52
ripple::NodeStore::Manager::make_Backend
virtual std::unique_ptr< Backend > make_Backend(Section const &parameters, Scheduler &scheduler, beast::Journal journal)=0
Create a backend.
ripple::SHAMapStoreImp::nodeStoreName_
static constexpr auto nodeStoreName_
Definition: SHAMapStoreImp.h:128
ripple::SHAMapStoreImp::run
void run()
Definition: SHAMapStoreImp.cpp:316
std::unique_ptr::reset
T reset(T... args)
ripple::Application::getOPs
virtual NetworkOPs & getOPs()=0
ripple::SHAMapStoreImp::dbRotating_
NodeStore::DatabaseRotating * dbRotating_
Definition: SHAMapStoreImp.h:94
ripple::get_if_exists
bool get_if_exists(Section const &section, std::string const &name, T &v)
Definition: BasicConfig.h:347
ripple::OperatingMode::SYNCING
@ SYNCING
fallen slightly behind
ripple::SHAMapStoreImp::clearSql
void clearSql(DatabaseCon &database, LedgerIndex lastRotated, std::string const &minQuery, std::string const &deleteQuery)
delete from sqlite table in batches to not lock the db excessively.
Definition: SHAMapStoreImp.cpp:570
ripple::SHAMapStoreImp::app_
Application & app_
Definition: SHAMapStoreImp.h:77
ripple::Stoppable
Provides an interface for starting and stopping.
Definition: Stoppable.h:200
ripple::SHAMapStoreImp::stop_
bool stop_
Definition: SHAMapStoreImp.h:97
ripple::DatabaseCon::checkoutDb
LockedSociSession checkoutDb()
Definition: DatabaseCon.h:176
ripple::Application::getLedgerMaster
virtual LedgerMaster & getLedgerMaster()=0
ripple::Config
Definition: Config.h:67
ripple::SHAMapStoreImp::SavedStateDB::session_
soci::session session_
Definition: SHAMapStoreImp.h:51
ripple::SHAMapStoreImp::advisoryDelete_
bool advisoryDelete_
Definition: SHAMapStoreImp.h:108
ripple::SHAMapAbstractNode::getNodeHash
SHAMapHash const & getNodeHash() const
Definition: SHAMapTreeNode.h:345
ripple::SHAMapAbstractNode::getSeq
std::uint32_t getSeq() const
Definition: SHAMapTreeNode.h:333
ripple::NodeStore::Database::fetch
virtual std::shared_ptr< NodeObject > fetch(uint256 const &hash, std::uint32_t seq)=0
Fetch an object.
ripple::Application::config
virtual Config & config()=0
std::unique_lock
STL class.
ripple::SHAMapStoreImp::minimumOnline_
std::atomic< LedgerIndex > minimumOnline_
Definition: SHAMapStoreImp.h:90
std::string::compare
T compare(T... args)
ripple::SHAMapStoreImp::SavedStateDB::setState
void setState(SavedState const &state)
Definition: SHAMapStoreImp.cpp:125
ripple::SHAMapStoreImp::treeNodeCache_
TreeNodeCache * treeNodeCache_
Definition: SHAMapStoreImp.h:124
ripple::SHAMapStoreImp::working_
std::atomic< bool > working_
Definition: SHAMapStoreImp.h:103
std::to_string
T to_string(T... args)
ripple::SHAMapStoreImp::deleteInterval_
std::uint32_t deleteInterval_
Definition: SHAMapStoreImp.h:107
ripple::Application::getJobQueue
virtual JobQueue & getJobQueue()=0
ripple::SHAMapStoreImp::onStop
void onStop() override
Override called when the stop notification is issued.
Definition: SHAMapStoreImp.cpp:731
ripple::SHAMapStoreImp::ageThreshold_
std::chrono::seconds ageThreshold_
Definition: SHAMapStoreImp.h:111
beast::Journal::error
Stream error() const
Definition: Journal.h:333
ripple::SHAMapStoreImp::minimumOnline
boost::optional< LedgerIndex > minimumOnline() const override
The minimum ledger to try and maintain in our database.
Definition: SHAMapStoreImp.cpp:765
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:175
ripple::Application::logs
virtual Logs & logs()=0
ripple::SHAMapStoreImp::copyNode
bool copyNode(std::uint64_t &nodeCount, SHAMapAbstractNode const &node)
Definition: SHAMapStoreImp.cpp:300
ripple::SHAMapStoreImp::SavedState::writableDb
std::string writableDb
Definition: SHAMapStoreImp.h:41
ripple::TransactionMaster::getCache
TaggedCache< uint256, Transaction > & getCache()
Definition: TransactionMaster.cpp:151
ripple::SHAMapStoreImp::clearPrior
void clearPrior(LedgerIndex lastRotated)
Definition: SHAMapStoreImp.cpp:648
ripple::SHAMapStoreImp::SavedStateDB::getState
SavedState getState()
Definition: SHAMapStoreImp.cpp:110
beast::Journal
A generic endpoint for log messages.
Definition: Journal.h:58
ripple::Application::getLedgerDB
virtual DatabaseCon & getLedgerDB()=0
std::int64_t
std::condition_variable::wait
T wait(T... args)
ripple::SHAMapStoreImp::SavedState
Definition: SHAMapStoreImp.h:39
ripple::SHAMapStoreImp::recoveryWaitTime_
boost::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:117
ripple::NodeStore::Scheduler
Scheduling for asynchronous backend activity.
Definition: ripple/nodestore/Scheduler.h:57
ripple::SHAMapStoreImp::Health
Health
Definition: SHAMapStoreImp.h:46
ripple::SHAMapStoreImp::checkHealthInterval_
const std::uint64_t checkHealthInterval_
Definition: SHAMapStoreImp.h:84
ripple::SHAMapStoreImp::state_db_
SavedStateDB state_db_
Definition: SHAMapStoreImp.h:95
std::min
T min(T... args)
ripple::SHAMapStoreImp::backOff_
std::chrono::milliseconds backOff_
Definition: SHAMapStoreImp.h:110
std::condition_variable::notify_one
T notify_one(T... args)
ripple::SHAMapStoreImp::SavedState::archiveDb
std::string archiveDb
Definition: SHAMapStoreImp.h:42
ripple::SHAMapStoreImp::SavedStateDB::init
void init(BasicConfig const &config, std::string const &dbName)
Definition: SHAMapStoreImp.cpp:31
ripple::LedgerMaster::getValidatedLedgerAge
std::chrono::seconds getValidatedLedgerAge()
Definition: LedgerMaster.cpp:268
ripple::SHAMapStoreImp::dbName_
const std::string dbName_
Definition: SHAMapStoreImp.h:80
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::SavedState::lastRotated
LedgerIndex lastRotated
Definition: SHAMapStoreImp.h:43
ripple::SHAMapStoreImp::fdRequired
int fdRequired() const override
Returns the number of file descriptors that are needed.
Definition: SHAMapStoreImp.cpp:294
ripple::Logs::journal
beast::Journal journal(std::string const &name)
Definition: Log.cpp:144
ripple::make_SHAMapStore
std::unique_ptr< SHAMapStore > make_SHAMapStore(Application &app, Stoppable &parent, NodeStore::Scheduler &scheduler, beast::Journal journal)
Definition: SHAMapStoreImp.cpp:777
std
STL namespace.
ripple::SHAMapStoreImp::SavedStateDB::setLastRotated
void setLastRotated(LedgerIndex seq)
Definition: SHAMapStoreImp.cpp:138
ripple::SHAMapStoreImp::canDelete_
std::atomic< LedgerIndex > canDelete_
Definition: SHAMapStoreImp.h:104
ripple::SHAMapStoreImp::minimumDeletionIntervalSA_
static const std::uint32_t minimumDeletionIntervalSA_
Definition: SHAMapStoreImp.h:88
ripple::DatabaseCon
Definition: DatabaseCon.h:81
ripple::NodeStore::DatabaseRotating::getPositiveCache
virtual TaggedCache< uint256, NodeObject > const & getPositiveCache()=0
ripple::SHAMapStoreImp::onChildrenStopped
void onChildrenStopped() override
Override called when all children have stopped.
Definition: SHAMapStoreImp.cpp:748
ripple::SHAMapStoreImp::deleteBatch_
std::uint32_t deleteBatch_
Definition: SHAMapStoreImp.h:109
ripple::SHAMapStoreImp::fullBelowCache_
FullBelowCache * fullBelowCache_
Definition: SHAMapStoreImp.h:123
std::chrono::seconds::count
T count(T... args)
ripple::SHAMapStoreImp::clearCaches
void clearCaches(LedgerIndex validatedSeq)
Definition: SHAMapStoreImp.cpp:630
ripple::SHAMapAbstractNode
Definition: SHAMapTreeNode.h:122
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:68
ripple::SHAMapStoreImp::makeBackendRotating
std::unique_ptr< NodeStore::Backend > makeBackendRotating(std::string path=std::string())
Definition: SHAMapStoreImp.cpp:545
beast::Journal::debug
Stream debug() const
Definition: Journal.h:315
ripple::SHAMapStoreImp::makeNodeStore
std::unique_ptr< NodeStore::Database > makeNodeStore(std::string const &name, std::int32_t readThreads) override
Definition: SHAMapStoreImp.cpp:227
ripple::SHAMapHash::as_uint256
uint256 const & as_uint256() const
Definition: SHAMapTreeNode.h:54
std::numeric_limits::max
T max(T... args)
ripple::NodeStore::Manager::make_Database
virtual std::unique_ptr< Database > make_Database(std::string const &name, Scheduler &scheduler, int readThreads, Stoppable &parent, Section const &backendParameters, beast::Journal journal)=0
Construct a NodeStore database.
ripple::NodeStore::Manager::instance
static Manager & instance()
Returns the instance of the manager singleton.
Definition: ManagerImp.cpp:117
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:105
ripple::SHAMapStoreImp::netOPs_
NetworkOPs * netOPs_
Definition: SHAMapStoreImp.h:121
std::unique_ptr
STL class.
ripple::SHAMapStoreImp::freshenCache
bool freshenCache(CacheInstance &cache)
Definition: SHAMapStoreImp.h:208
ripple::LedgerMaster::clearPriorLedgers
void clearPriorLedgers(LedgerIndex seq)
Definition: LedgerMaster.cpp:1756
std::condition_variable::notify_all
T notify_all(T... args)
ripple::BasicConfig
Holds unparsed configuration information.
Definition: BasicConfig.h:178
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:284
ripple::Application::getTxnDB
virtual DatabaseCon & getTxnDB()=0
ripple::open
void open(soci::session &s, BasicConfig const &config, std::string const &dbName)
Open a soci session.
Definition: SociDB.cpp:100
ripple::BasicConfig::section
Section & section(std::string const &name)
Returns the section with the given name.
Definition: BasicConfig.cpp:138
ripple::SHAMapStoreImp::rendezvous_
std::condition_variable rendezvous_
Definition: SHAMapStoreImp.h:100
ripple::Application::getMasterTransaction
virtual TransactionMaster & getMasterTransaction()=0
ripple::OperatingMode::FULL
@ FULL
we have the ledger and can even validate