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  megabytes(
263  app_.config().getValueFor(SizedItem::burstSize, boost::none)),
264  scheduler_,
265  readThreads,
266  app_.getJobQueue(),
269  fdRequired_ += db->fdRequired();
270  }
271  return db;
272 }
273 
274 void
276 {
277  {
278  std::lock_guard lock(mutex_);
279  newLedger_ = ledger;
280  working_ = true;
281  }
282  cond_.notify_one();
283 }
284 
285 void
287 {
288  if (!working_)
289  return;
290 
292  rendezvous_.wait(lock, [&] { return !working_; });
293 }
294 
295 int
297 {
298  return fdRequired_;
299 }
300 
301 bool
303 {
304  // Copy a single record from node to dbRotating_
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,
566  scheduler_,
568  backend->open();
569  return backend;
570 }
571 
572 void
574  DatabaseCon& database,
575  LedgerIndex lastRotated,
576  std::string const& minQuery,
577  std::string const& deleteQuery)
578 {
579  assert(deleteInterval_);
581 
582  {
583  boost::optional<std::uint64_t> m;
584  JLOG(journal_.trace())
585  << "Begin: Look up lowest value of: " << minQuery;
586  {
587  auto db = database.checkoutDb();
588  *db << minQuery, soci::into(m);
589  }
590  JLOG(journal_.trace()) << "End: Look up lowest value of: " << minQuery;
591  if (!m)
592  return;
593  min = *m;
594  }
595 
596  if (min > lastRotated || health() != Health::ok)
597  return;
598  if (min == lastRotated)
599  {
600  // Micro-optimization mainly to clarify logs
601  JLOG(journal_.trace()) << "Nothing to delete from " << deleteQuery;
602  return;
603  }
604 
605  boost::format formattedDeleteQuery(deleteQuery);
606 
607  JLOG(journal_.debug()) << "start: " << deleteQuery << " from " << min
608  << " to " << lastRotated;
609  while (min < lastRotated)
610  {
611  min = std::min(lastRotated, min + deleteBatch_);
612  JLOG(journal_.trace()) << "Begin: Delete up to " << deleteBatch_
613  << " rows with LedgerSeq < " << min
614  << " using query: " << deleteQuery;
615  {
616  auto db = database.checkoutDb();
617  *db << boost::str(formattedDeleteQuery % min);
618  }
619  JLOG(journal_.trace())
620  << "End: Delete up to " << deleteBatch_ << " rows with LedgerSeq < "
621  << min << " using query: " << deleteQuery;
622  if (health())
623  return;
624  if (min < lastRotated)
626  if (health())
627  return;
628  }
629  JLOG(journal_.debug()) << "finished: " << deleteQuery;
630 }
631 
632 void
634 {
635  ledgerMaster_->clearLedgerCachePrior(validatedSeq);
637 }
638 
639 void
641 {
643  return;
645  return;
646 }
647 
648 void
650 {
651  // Do not allow ledgers to be acquired from the network
652  // that are about to be deleted.
653  minimumOnline_ = lastRotated + 1;
654  JLOG(journal_.trace()) << "Begin: Clear internal ledgers up to "
655  << lastRotated;
656  ledgerMaster_->clearPriorLedgers(lastRotated);
657  JLOG(journal_.trace()) << "End: Clear internal ledgers up to "
658  << lastRotated;
659  if (health())
660  return;
661 
662  clearSql(
663  *ledgerDb_,
664  lastRotated,
665  "SELECT MIN(LedgerSeq) FROM Ledgers;",
666  "DELETE FROM Ledgers WHERE LedgerSeq < %u;");
667  if (health())
668  return;
669 
670  clearSql(
672  lastRotated,
673  "SELECT MIN(LedgerSeq) FROM Transactions;",
674  "DELETE FROM Transactions WHERE LedgerSeq < %u;");
675  if (health())
676  return;
677 
678  clearSql(
680  lastRotated,
681  "SELECT MIN(LedgerSeq) FROM AccountTransactions;",
682  "DELETE FROM AccountTransactions WHERE LedgerSeq < %u;");
683  if (health())
684  return;
685 }
686 
689 {
690  {
691  std::lock_guard lock(mutex_);
692  if (stop_)
693  return Health::stopping;
694  }
695  if (!netOPs_)
696  return Health::ok;
697  assert(deleteInterval_);
698 
699  if (healthy_)
700  {
701  auto age = ledgerMaster_->getValidatedLedgerAge();
703  if (recoveryWaitTime_ && mode == OperatingMode::SYNCING &&
704  age < ageThreshold_)
705  {
706  JLOG(journal_.warn())
707  << "Waiting " << recoveryWaitTime_->count()
708  << "s for node to get back into sync with network. state: "
709  << app_.getOPs().strOperatingMode(mode, false) << ". age "
710  << age.count() << 's';
712 
714  mode = netOPs_->getOperatingMode();
715  }
716  if (mode != OperatingMode::FULL || age > ageThreshold_)
717  {
718  JLOG(journal_.warn()) << "Not deleting. state: "
719  << app_.getOPs().strOperatingMode(mode, false)
720  << ". age " << age.count() << 's';
721  healthy_ = false;
722  }
723  }
724 
725  if (healthy_)
726  return Health::ok;
727  else
728  return Health::unhealthy;
729 }
730 
731 void
733 {
734  if (deleteInterval_)
735  {
736  {
737  std::lock_guard lock(mutex_);
738  stop_ = true;
739  }
740  cond_.notify_one();
741  }
742  else
743  {
744  stopped();
745  }
746 }
747 
748 void
750 {
751  if (deleteInterval_)
752  {
753  {
754  std::lock_guard lock(mutex_);
755  stop_ = true;
756  }
757  cond_.notify_one();
758  }
759  else
760  {
761  stopped();
762  }
763 }
764 
765 boost::optional<LedgerIndex>
767 {
768  // minimumOnline_ with 0 value is equivalent to unknown/not set.
769  // Don't attempt to acquire ledgers if that value is unknown.
771  return minimumOnline_.load();
772  return app_.getLedgerMaster().minSqlSeq();
773 }
774 
775 //------------------------------------------------------------------------------
776 
779  Application& app,
780  Stoppable& parent,
781  NodeStore::Scheduler& scheduler,
782  beast::Journal journal)
783 {
784  return std::make_unique<SHAMapStoreImp>(app, parent, scheduler, journal);
785 }
786 
787 } // 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:688
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:52
ripple::LedgerMaster::clearLedgerCachePrior
void clearLedgerCachePrior(LedgerIndex seq)
Definition: LedgerMaster.cpp:1763
std::string
STL class.
ripple::SHAMapStoreImp::ledgerDb_
DatabaseCon * ledgerDb_
Definition: SHAMapStoreImp.h:126
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: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:275
ripple::LedgerMaster::minSqlSeq
boost::optional< LedgerIndex > minSqlSeq()
Definition: LedgerMaster.cpp:2232
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)
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:812
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:640
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::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::copyNode
bool copyNode(std::uint64_t &nodeCount, SHAMapTreeNode const &node)
Definition: SHAMapStoreImp.cpp:302
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:573
ripple::SHAMapStoreImp::app_
Application & app_
Definition: SHAMapStoreImp.h:77
ripple::Stoppable
Provides an interface for starting and stopping.
Definition: Stoppable.h:201
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::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: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::SHAMapTreeNode
Definition: SHAMapTreeNode.h:133
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:732
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:766
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:41
ripple::TransactionMaster::getCache
TaggedCache< uint256, Transaction > & getCache()
Definition: TransactionMaster.cpp:162
ripple::SHAMapStoreImp::clearPrior
void clearPrior(LedgerIndex lastRotated)
Definition: SHAMapStoreImp.cpp:649
ripple::SHAMapStoreImp::SavedStateDB::getState
SavedState getState()
Definition: SHAMapStoreImp.cpp:110
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: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: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:142
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::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: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:296
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:778
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::SHAMapStoreImp::onChildrenStopped
void onChildrenStopped() override
Override called when all children have stopped.
Definition: SHAMapStoreImp.cpp:749
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:633
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: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:119
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:1755
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:286
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