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