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, "delete_batch", deleteBatch_);
184  get_if_exists(section, "backOff", backOff_);
185  get_if_exists(section, "age_threshold", ageThreshold_);
186  get_if_exists(section, "online_delete", deleteInterval_);
187 
188  if (deleteInterval_)
189  {
190  get_if_exists(section, "advisory_delete", advisoryDelete_);
191 
192  auto const minInterval = config.standalone()
195  if (deleteInterval_ < minInterval)
196  {
197  Throw<std::runtime_error>(
198  "online_delete must be at least " +
199  std::to_string(minInterval));
200  }
201 
202  if (config.LEDGER_HISTORY > deleteInterval_)
203  {
204  Throw<std::runtime_error>(
205  "online_delete must not be less than ledger_history "
206  "(currently " +
207  std::to_string(config.LEDGER_HISTORY) + ")");
208  }
209 
210  state_db_.init(config, dbName_);
211  dbPaths();
212  }
213 }
214 
217 {
218  // Anything which calls addJob must be a descendant of the JobQueue.
219  // Therefore Database objects use the JobQueue as Stoppable parent.
221  if (deleteInterval_)
222  {
223  SavedState state = state_db_.getState();
224  auto writableBackend = makeBackendRotating(state.writableDb);
225  auto archiveBackend = makeBackendRotating(state.archiveDb);
226  if (!state.writableDb.size())
227  {
228  state.writableDb = writableBackend->getName();
229  state.archiveDb = archiveBackend->getName();
230  state_db_.setState(state);
231  }
232 
233  // Create NodeStore with two backends to allow online deletion of data
234  auto dbr = std::make_unique<NodeStore::DatabaseRotatingImp>(
235  name,
236  scheduler_,
237  readThreads,
238  app_.getJobQueue(),
239  std::move(writableBackend),
240  std::move(archiveBackend),
243  fdRequired_ += dbr->fdRequired();
244  dbRotating_ = dbr.get();
245  db.reset(dynamic_cast<NodeStore::Database*>(dbr.release()));
246  }
247  else
248  {
250  name,
251  scheduler_,
252  readThreads,
253  app_.getJobQueue(),
256  fdRequired_ += db->fdRequired();
257  }
258  return db;
259 }
260 
261 void
263 {
264  {
265  std::lock_guard lock(mutex_);
266  newLedger_ = ledger;
267  working_ = true;
268  }
269  cond_.notify_one();
270 }
271 
272 void
274 {
275  if (!working_)
276  return;
277 
279  rendezvous_.wait(lock, [&] { return !working_; });
280 }
281 
282 int
284 {
285  return fdRequired_;
286 }
287 
288 bool
290  std::uint64_t& nodeCount,
291  SHAMapAbstractNode const& node)
292 {
293  // Copy a single record from node to dbRotating_
294  dbRotating_->fetch(node.getNodeHash().as_uint256(), node.getSeq());
295  if (!(++nodeCount % checkHealthInterval_))
296  {
297  if (health())
298  return false;
299  }
300 
301  return true;
302 }
303 
304 void
306 {
307  beast::setCurrentThreadName("SHAMapStore");
308  LedgerIndex lastRotated = state_db_.getState().lastRotated;
309  netOPs_ = &app_.getOPs();
315 
316  if (advisoryDelete_)
318 
319  while (true)
320  {
321  healthy_ = true;
322  std::shared_ptr<Ledger const> validatedLedger;
323 
324  {
326  working_ = false;
328  if (stop_)
329  {
330  stopped();
331  return;
332  }
333  cond_.wait(lock);
334  if (newLedger_)
335  {
336  validatedLedger = std::move(newLedger_);
337  }
338  else
339  continue;
340  }
341 
342  LedgerIndex const validatedSeq = validatedLedger->info().seq;
343  if (!lastRotated)
344  {
345  lastRotated = validatedSeq;
346  state_db_.setLastRotated(lastRotated);
347  }
348 
349  // will delete up to (not including) lastRotated
350  if (validatedSeq >= lastRotated + deleteInterval_ &&
351  canDelete_ >= lastRotated - 1)
352  {
353  JLOG(journal_.warn())
354  << "rotating validatedSeq " << validatedSeq << " lastRotated "
355  << lastRotated << " deleteInterval " << deleteInterval_
356  << " canDelete_ " << canDelete_;
357 
358  switch (health())
359  {
360  case Health::stopping:
361  stopped();
362  return;
363  case Health::unhealthy:
364  continue;
365  case Health::ok:
366  default:;
367  }
368 
369  clearPrior(lastRotated);
370  switch (health())
371  {
372  case Health::stopping:
373  stopped();
374  return;
375  case Health::unhealthy:
376  continue;
377  case Health::ok:
378  default:;
379  }
380 
381  std::uint64_t nodeCount = 0;
382  validatedLedger->stateMap().snapShot(false)->visitNodes(std::bind(
384  this,
385  std::ref(nodeCount),
386  std::placeholders::_1));
387  JLOG(journal_.debug()) << "copied ledger " << validatedSeq
388  << " nodecount " << nodeCount;
389  switch (health())
390  {
391  case Health::stopping:
392  stopped();
393  return;
394  case Health::unhealthy:
395  continue;
396  case Health::ok:
397  default:;
398  }
399 
400  freshenCaches();
401  JLOG(journal_.debug()) << validatedSeq << " freshened caches";
402  switch (health())
403  {
404  case Health::stopping:
405  stopped();
406  return;
407  case Health::unhealthy:
408  continue;
409  case Health::ok:
410  default:;
411  }
412 
413  auto newBackend = makeBackendRotating();
414  JLOG(journal_.debug())
415  << validatedSeq << " new backend " << newBackend->getName();
416 
417  clearCaches(validatedSeq);
418  switch (health())
419  {
420  case Health::stopping:
421  stopped();
422  return;
423  case Health::unhealthy:
424  continue;
425  case Health::ok:
426  default:;
427  }
428 
429  lastRotated = validatedSeq;
430 
432  [&](std::string const& writableBackendName) {
433  SavedState savedState;
434  savedState.writableDb = newBackend->getName();
435  savedState.archiveDb = writableBackendName;
436  savedState.lastRotated = lastRotated;
437  state_db_.setState(savedState);
438 
439  clearCaches(validatedSeq);
440 
441  return std::move(newBackend);
442  });
443 
444  JLOG(journal_.warn()) << "finished rotation " << validatedSeq;
445  }
446  }
447 }
448 
449 void
451 {
453  boost::filesystem::path dbPath = get<std::string>(section, "path");
454 
455  if (boost::filesystem::exists(dbPath))
456  {
457  if (!boost::filesystem::is_directory(dbPath))
458  {
459  journal_.error()
460  << "node db path must be a directory. " << dbPath.string();
461  Throw<std::runtime_error>("node db path must be a directory.");
462  }
463  }
464  else
465  {
466  boost::filesystem::create_directories(dbPath);
467  }
468 
469  SavedState state = state_db_.getState();
470 
471  {
472  auto update = [&dbPath](std::string& sPath) {
473  if (sPath.empty())
474  return false;
475 
476  // Check if configured "path" matches stored directory path
477  using namespace boost::filesystem;
478  auto const stored{path(sPath)};
479  if (stored.parent_path() == dbPath)
480  return false;
481 
482  sPath = (dbPath / stored.filename()).string();
483  return true;
484  };
485 
486  if (update(state.writableDb))
487  {
488  update(state.archiveDb);
489  state_db_.setState(state);
490  }
491  }
492 
493  bool writableDbExists = false;
494  bool archiveDbExists = false;
495 
496  for (boost::filesystem::directory_iterator it(dbPath);
497  it != boost::filesystem::directory_iterator();
498  ++it)
499  {
500  if (!state.writableDb.compare(it->path().string()))
501  writableDbExists = true;
502  else if (!state.archiveDb.compare(it->path().string()))
503  archiveDbExists = true;
504  else if (!dbPrefix_.compare(it->path().stem().string()))
505  boost::filesystem::remove_all(it->path());
506  }
507 
508  if ((!writableDbExists && state.writableDb.size()) ||
509  (!archiveDbExists && state.archiveDb.size()) ||
510  (writableDbExists != archiveDbExists) ||
511  state.writableDb.empty() != state.archiveDb.empty())
512  {
513  boost::filesystem::path stateDbPathName =
514  app_.config().legacy("database_path");
515  stateDbPathName /= dbName_;
516  stateDbPathName += "*";
517 
518  journal_.error()
519  << "state db error:\n"
520  << " writableDbExists " << writableDbExists << " archiveDbExists "
521  << archiveDbExists << '\n'
522  << " writableDb '" << state.writableDb << "' archiveDb '"
523  << state.archiveDb << "\n\n"
524  << "The existing data is in a corrupted state.\n"
525  << "To resume operation, remove the files matching "
526  << stateDbPathName.string() << " and contents of the directory "
527  << get<std::string>(section, "path") << '\n'
528  << "Optionally, you can move those files to another\n"
529  << "location if you wish to analyze or back up the data.\n"
530  << "However, there is no guarantee that the data in its\n"
531  << "existing form is usable.";
532 
533  Throw<std::runtime_error>("state db error");
534  }
535 }
536 
539 {
541  boost::filesystem::path newPath;
542 
543  if (path.size())
544  {
545  newPath = path;
546  }
547  else
548  {
549  boost::filesystem::path p = get<std::string>(section, "path");
550  p /= dbPrefix_;
551  p += ".%%%%";
552  newPath = boost::filesystem::unique_path(p);
553  }
554  section.set("path", newPath.string());
555 
557  section, scheduler_, app_.logs().journal(nodeStoreName_))};
558  backend->open();
559  return backend;
560 }
561 
562 bool
564  DatabaseCon& database,
565  LedgerIndex lastRotated,
566  std::string const& minQuery,
567  std::string const& deleteQuery)
568 {
570 
571  {
572  auto db = database.checkoutDb();
573  boost::optional<std::uint64_t> m;
574  *db << minQuery, soci::into(m);
575  if (!m)
576  return false;
577  min = *m;
578  }
579 
580  if (min > lastRotated || health() != Health::ok)
581  return false;
582 
583  boost::format formattedDeleteQuery(deleteQuery);
584 
585  JLOG(journal_.debug()) << "start: " << deleteQuery << " from " << min
586  << " to " << lastRotated;
587  while (min < lastRotated)
588  {
589  min = std::min(lastRotated, min + deleteBatch_);
590  {
591  auto db = database.checkoutDb();
592  *db << boost::str(formattedDeleteQuery % min);
593  }
594  if (health())
595  return true;
596  if (min < lastRotated)
598  }
599  JLOG(journal_.debug()) << "finished: " << deleteQuery;
600  return true;
601 }
602 
603 void
605 {
606  ledgerMaster_->clearLedgerCachePrior(validatedSeq);
608 }
609 
610 void
612 {
614  return;
616  return;
618  return;
619 }
620 
621 void
623 {
624  if (health())
625  return;
626 
627  // Do not allow ledgers to be acquired from the network
628  // that are about to be deleted.
629  minimumOnline_ = lastRotated + 1;
630  ledgerMaster_->clearPriorLedgers(lastRotated);
631  if (health())
632  return;
633 
634  clearSql(
635  *ledgerDb_,
636  lastRotated,
637  "SELECT MIN(LedgerSeq) FROM Ledgers;",
638  "DELETE FROM Ledgers WHERE LedgerSeq < %u;");
639  if (health())
640  return;
641 
642  clearSql(
644  lastRotated,
645  "SELECT MIN(LedgerSeq) FROM Transactions;",
646  "DELETE FROM Transactions WHERE LedgerSeq < %u;");
647  if (health())
648  return;
649 
650  clearSql(
652  lastRotated,
653  "SELECT MIN(LedgerSeq) FROM AccountTransactions;",
654  "DELETE FROM AccountTransactions WHERE LedgerSeq < %u;");
655  if (health())
656  return;
657 }
658 
661 {
662  {
663  std::lock_guard lock(mutex_);
664  if (stop_)
665  return Health::stopping;
666  }
667  if (!netOPs_)
668  return Health::ok;
669 
670  constexpr static std::chrono::seconds age_threshold(60);
671  auto age = ledgerMaster_->getValidatedLedgerAge();
673  if (mode != OperatingMode::FULL || age > age_threshold)
674  {
675  JLOG(journal_.warn()) << "Not deleting. state: "
676  << app_.getOPs().strOperatingMode(mode, false)
677  << ". age " << age.count() << 's';
678  healthy_ = false;
679  }
680 
681  if (healthy_)
682  return Health::ok;
683  else
684  return Health::unhealthy;
685 }
686 
687 void
689 {
690  if (deleteInterval_)
691  {
692  {
693  std::lock_guard lock(mutex_);
694  stop_ = true;
695  }
696  cond_.notify_one();
697  }
698  else
699  {
700  stopped();
701  }
702 }
703 
704 void
706 {
707  if (deleteInterval_)
708  {
709  {
710  std::lock_guard lock(mutex_);
711  stop_ = true;
712  }
713  cond_.notify_one();
714  }
715  else
716  {
717  stopped();
718  }
719 }
720 
721 boost::optional<LedgerIndex>
723 {
724  // minimumOnline_ with 0 value is equivalent to unknown/not set.
725  // Don't attempt to acquire ledgers if that value is unknown.
727  return minimumOnline_.load();
728  return app_.getLedgerMaster().minSqlSeq();
729 }
730 
731 //------------------------------------------------------------------------------
732 
735  Application& app,
736  Stoppable& parent,
737  NodeStore::Scheduler& scheduler,
738  beast::Journal journal)
739 {
740  return std::make_unique<SHAMapStoreImp>(app, parent, scheduler, journal);
741 }
742 
743 } // 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:660
ripple::Application
Definition: Application.h:97
ripple::SHAMapStoreImp::dbPaths
void dbPaths()
Definition: SHAMapStoreImp.cpp:450
std::this_thread::sleep_for
T sleep_for(T... args)
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:97
std::bind
T bind(T... args)
ripple::SHAMapStoreImp::scheduler_
NodeStore::Scheduler & scheduler_
Definition: SHAMapStoreImp.h:91
ripple::NodeStore::Database
Persistency layer for NodeObject.
Definition: Database.h:53
ripple::LedgerMaster::clearLedgerCachePrior
void clearLedgerCachePrior(LedgerIndex seq)
Definition: LedgerMaster.cpp:1708
std::string
STL class.
ripple::SHAMapStoreImp::ledgerDb_
DatabaseCon * ledgerDb_
Definition: SHAMapStoreImp.h:119
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
ripple::SHAMapStoreImp::newLedger_
std::shared_ptr< Ledger const > newLedger_
Definition: SHAMapStoreImp.h:101
ripple::SHAMapStoreImp::onLedgerClosed
void onLedgerClosed(std::shared_ptr< Ledger const > const &ledger) override
Called by LedgerMaster every time a ledger validates.
Definition: SHAMapStoreImp.cpp:262
ripple::LedgerMaster::minSqlSeq
boost::optional< LedgerIndex > minSqlSeq()
Definition: LedgerMaster.cpp:2135
ripple::SHAMapStoreImp::minimumDeletionInterval_
static const std::uint32_t minimumDeletionInterval_
Definition: SHAMapStoreImp.h:85
ripple::SHAMapStoreImp::dbPrefix_
const std::string dbPrefix_
Definition: SHAMapStoreImp.h:81
ripple::SHAMapStoreImp::ledgerMaster_
LedgerMaster * ledgerMaster_
Definition: SHAMapStoreImp.h:115
ripple::SHAMapStoreImp::mutex_
std::mutex mutex_
Definition: SHAMapStoreImp.h:100
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:118
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:92
ripple::SHAMapStoreImp::cond_
std::condition_variable cond_
Definition: SHAMapStoreImp.h:98
ripple::SHAMapStoreImp::freshenCaches
void freshenCaches()
Definition: SHAMapStoreImp.cpp:611
ripple::SizedItem::hashNodeDBCache
@ hashNodeDBCache
ripple::SHAMapStoreImp::SavedStateDB::getCanDelete
LedgerIndex getCanDelete()
Definition: SHAMapStoreImp.cpp:86
ripple::SHAMapStoreImp::SavedStateDB::mutex_
std::mutex mutex_
Definition: SHAMapStoreImp.h:51
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:121
ripple::SHAMapStoreImp::ageThreshold_
std::int32_t ageThreshold_
Definition: SHAMapStoreImp.h:110
ripple::SHAMapStoreImp::run
void run()
Definition: SHAMapStoreImp.cpp:305
std::unique_ptr::reset
T reset(T... args)
ripple::Application::getOPs
virtual NetworkOPs & getOPs()=0
ripple::SHAMapStoreImp::dbRotating_
NodeStore::DatabaseRotating * dbRotating_
Definition: SHAMapStoreImp.h:93
ripple::get_if_exists
bool get_if_exists(Section const &section, std::string const &name, T &v)
Definition: BasicConfig.h:347
ripple::SHAMapStoreImp::app_
Application & app_
Definition: SHAMapStoreImp.h:76
ripple::Stoppable
Provides an interface for starting and stopping.
Definition: Stoppable.h:200
ripple::SHAMapStoreImp::stop_
bool stop_
Definition: SHAMapStoreImp.h:96
ripple::DatabaseCon::checkoutDb
LockedSociSession checkoutDb()
Definition: DatabaseCon.h:129
ripple::Application::family
virtual Family & family()=0
ripple::Application::getLedgerMaster
virtual LedgerMaster & getLedgerMaster()=0
ripple::Config
Definition: Config.h:66
ripple::SHAMapStoreImp::SavedStateDB::session_
soci::session session_
Definition: SHAMapStoreImp.h:50
ripple::SHAMapStoreImp::advisoryDelete_
bool advisoryDelete_
Definition: SHAMapStoreImp.h:107
ripple::SHAMapAbstractNode::getNodeHash
SHAMapHash const & getNodeHash() const
Definition: SHAMapTreeNode.h:331
ripple::SHAMapAbstractNode::getSeq
std::uint32_t getSeq() const
Definition: SHAMapTreeNode.h:319
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:89
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:117
ripple::SHAMapStoreImp::working_
std::atomic< bool > working_
Definition: SHAMapStoreImp.h:102
std::to_string
T to_string(T... args)
ripple::SHAMapStoreImp::deleteInterval_
std::uint32_t deleteInterval_
Definition: SHAMapStoreImp.h:106
ripple::Application::getJobQueue
virtual JobQueue & getJobQueue()=0
ripple::SHAMapStoreImp::onStop
void onStop() override
Override called when the stop notification is issued.
Definition: SHAMapStoreImp.cpp:688
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:722
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:289
ripple::SHAMapStoreImp::SavedState::writableDb
std::string writableDb
Definition: SHAMapStoreImp.h:40
ripple::TransactionMaster::getCache
TaggedCache< uint256, Transaction > & getCache()
Definition: TransactionMaster.cpp:151
ripple::SHAMapStoreImp::clearPrior
void clearPrior(LedgerIndex lastRotated)
Definition: SHAMapStoreImp.cpp:622
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::backOff_
std::uint32_t backOff_
Definition: SHAMapStoreImp.h:109
ripple::SHAMapStoreImp::SavedState
Definition: SHAMapStoreImp.h:38
ripple::NodeStore::Scheduler
Scheduling for asynchronous backend activity.
Definition: ripple/nodestore/Scheduler.h:57
ripple::SHAMapStoreImp::Health
Health
Definition: SHAMapStoreImp.h:45
ripple::SHAMapStoreImp::checkHealthInterval_
const std::uint64_t checkHealthInterval_
Definition: SHAMapStoreImp.h:83
ripple::Family::treecache
virtual TreeNodeCache & treecache()=0
ripple::SHAMapStoreImp::state_db_
SavedStateDB state_db_
Definition: SHAMapStoreImp.h:94
std::min
T min(T... args)
std::condition_variable::notify_one
T notify_one(T... args)
ripple::SHAMapStoreImp::SavedState::archiveDb
std::string archiveDb
Definition: SHAMapStoreImp.h:41
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:265
ripple::SHAMapStoreImp::dbName_
const std::string dbName_
Definition: SHAMapStoreImp.h:79
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:42
ripple::SHAMapStoreImp::fdRequired
int fdRequired() const override
Returns the number of file descriptors that are needed.
Definition: SHAMapStoreImp.cpp:283
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:734
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:103
ripple::SHAMapStoreImp::minimumDeletionIntervalSA_
static const std::uint32_t minimumDeletionIntervalSA_
Definition: SHAMapStoreImp.h:87
ripple::DatabaseCon
Definition: DatabaseCon.h:82
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:705
ripple::SHAMapStoreImp::deleteBatch_
std::uint32_t deleteBatch_
Definition: SHAMapStoreImp.h:108
ripple::SHAMapStoreImp::fullBelowCache_
FullBelowCache * fullBelowCache_
Definition: SHAMapStoreImp.h:116
ripple::SHAMapStoreImp::clearCaches
void clearCaches(LedgerIndex validatedSeq)
Definition: SHAMapStoreImp.cpp:604
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:538
beast::Journal::debug
Stream debug() const
Definition: Journal.h:315
ripple::Family::fullbelow
virtual FullBelowCache & fullbelow()=0
ripple::SHAMapStoreImp::makeNodeStore
std::unique_ptr< NodeStore::Database > makeNodeStore(std::string const &name, std::int32_t readThreads) override
Definition: SHAMapStoreImp.cpp:216
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:104
ripple::SHAMapStoreImp::netOPs_
NetworkOPs * netOPs_
Definition: SHAMapStoreImp.h:114
std::unique_ptr
STL class.
ripple::SHAMapStoreImp::freshenCache
bool freshenCache(CacheInstance &cache)
Definition: SHAMapStoreImp.h:201
ripple::LedgerMaster::clearPriorLedgers
void clearPriorLedgers(LedgerIndex seq)
Definition: LedgerMaster.cpp:1700
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:273
ripple::SHAMapStoreImp::clearSql
bool 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 pause briefly to extend access tim...
Definition: SHAMapStoreImp.cpp:563
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:99
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:99
ripple::Application::getMasterTransaction
virtual TransactionMaster & getMasterTransaction()=0
ripple::OperatingMode::FULL
@ FULL
we have the ledger and can even validate