rippled
RelationalDBInterface_shards.h
1 //------------------------------------------------------------------------------
2 /*
3  This file is part of rippled: https://github.com/ripple/rippled
4  Copyright (c) 2020 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 #ifndef RIPPLE_CORE_RELATIONALDBINTERFACE_SHARDS_H_INCLUDED
21 #define RIPPLE_CORE_RELATIONALDBINTERFACE_SHARDS_H_INCLUDED
22 
23 #include <ripple/app/ledger/Ledger.h>
24 #include <ripple/app/rdb/RelationalDBInterface.h>
25 #include <ripple/core/Config.h>
26 #include <ripple/protocol/RippleLedgerHash.h>
27 #include <boost/filesystem.hpp>
28 
29 namespace ripple {
30 
32 {
35 };
36 
37 /* Shard DB */
38 
51  Config const& config,
52  DatabaseCon::Setup const& setup,
53  DatabaseCon::CheckpointerSetup const& checkpointerSetup);
54 
65 bool
67  std::shared_ptr<Ledger const> const& ledger,
68  Application& app,
69  soci::session& lgrMetaSession,
70  soci::session& txnMetaSession,
71  std::uint32_t shardIndex);
72 
81 getShardIndexforLedger(soci::session& session, LedgerHash const& hash);
82 
91 getShardIndexforTransaction(soci::session& session, TxID const& id);
92 
102  Config const& config,
103  DatabaseCon::Setup const& setup);
104 
115  Config const& config,
116  DatabaseCon::Setup const& setup,
117  DatabaseCon::CheckpointerSetup const& checkpointerSetup);
118 
129 bool
131  soci::session& txdb,
132  soci::session& lgrdb,
133  std::shared_ptr<Ledger const> const& ledger,
134  std::uint32_t index,
135  std::atomic<bool>& stop,
136  beast::Journal j);
137 
138 /* Shard acquire DB */
139 
148  DatabaseCon::Setup const& setup,
149  DatabaseCon::CheckpointerSetup const& checkpointerSetup);
150 
156 void
157 insertAcquireDBIndex(soci::session& session, std::uint32_t index);
158 
169 selectAcquireDBLedgerSeqs(soci::session& session, std::uint32_t index);
170 
172 {
175 };
176 
188 selectAcquireDBLedgerSeqsHash(soci::session& session, std::uint32_t index);
189 
198 void
200  soci::session& session,
201  std::shared_ptr<Ledger const> const& ledger,
202  std::uint32_t index,
203  std::uint32_t lastSeq,
204  std::optional<std::string> const& seqs);
205 
206 /* Archive DB */
207 
215 makeArchiveDB(boost::filesystem::path const& dir, std::string const& dbName);
216 
223 void
225  DatabaseCon& db,
226  std::function<void(std::string const&, int)> const& func);
227 
234 void
236  DatabaseCon& db,
237  std::uint32_t shardIndex,
238  std::string const& url);
239 
245 void
247 
252 void
254 
255 } // namespace ripple
256 
257 #endif
ripple::Application
Definition: Application.h:103
ripple::makeAcquireDB
std::unique_ptr< DatabaseCon > makeAcquireDB(DatabaseCon::Setup const &setup, DatabaseCon::CheckpointerSetup const &checkpointerSetup)
makeAcquireDB Opens shard acquire DB and returns its descriptor.
Definition: RelationalDBInterface_shards.cpp:338
ripple::DatabasePair::transactionDb
std::unique_ptr< DatabaseCon > transactionDb
Definition: RelationalDBInterface_shards.h:34
std::string
STL class.
std::shared_ptr
STL class.
ripple::DatabaseCon::Setup
Definition: DatabaseCon.h:84
std::pair
ripple::selectAcquireDBLedgerSeqsHash
std::pair< bool, AcquireShardSeqsHash > selectAcquireDBLedgerSeqsHash(soci::session &session, std::uint32_t index)
selectAcquireDBLedgerSeqsHash Returns set of acquired ledgers and hash for given shard.
Definition: RelationalDBInterface_shards.cpp:386
ripple::insertAcquireDBIndex
void insertAcquireDBIndex(soci::session &session, std::uint32_t index)
insertAcquireDBIndex Adds new shard index to shard acquire DB.
Definition: RelationalDBInterface_shards.cpp:351
ripple::DatabasePair::ledgerDb
std::unique_ptr< DatabaseCon > ledgerDb
Definition: RelationalDBInterface_shards.h:33
ripple::DatabaseCon::CheckpointerSetup
Definition: DatabaseCon.h:107
std::function
ripple::base_uint< 256 >
ripple::updateAcquireDB
void updateAcquireDB(soci::session &session, std::shared_ptr< Ledger const > const &ledger, std::uint32_t index, std::uint32_t lastSeq, std::optional< std::string > const &seqs)
updateAcquireDB Updates information in acquire DB.
Definition: RelationalDBInterface_shards.cpp:417
ripple::Config
Definition: Config.h:68
ripple::deleteFromArchiveDB
void deleteFromArchiveDB(DatabaseCon &db, std::uint32_t shardIndex)
deleteFromArchiveDB Deletes entry from shard archive DB.
Definition: RelationalDBInterface_shards.cpp:482
ripple::dropArchiveDB
void dropArchiveDB(DatabaseCon &db)
dropArchiveDB Removes table in shard archive DB.
Definition: RelationalDBInterface_shards.cpp:489
beast::Journal
A generic endpoint for log messages.
Definition: Journal.h:58
std::uint32_t
std::atomic< bool >
ripple::DatabasePair
Definition: RelationalDBInterface_shards.h:31
ripple::updateLedgerDBs
bool updateLedgerDBs(soci::session &txsession, soci::session &lgrsession, std::shared_ptr< Ledger const > const &ledger, std::uint32_t index, std::atomic< bool > &stop, beast::Journal j)
updateLedgerDBs Save given ledger to shard databases.
Definition: RelationalDBInterface_shards.cpp:201
ripple::AcquireShardSeqsHash
Definition: RelationalDBInterface_shards.h:171
ripple::AcquireShardSeqsHash::hash
std::optional< std::string > hash
Definition: RelationalDBInterface_shards.h:174
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::readArchiveDB
void readArchiveDB(DatabaseCon &db, std::function< void(std::string const &, int)> const &func)
readArchiveDB Read entries from shard archive database and calls fiven callback for each entry.
Definition: RelationalDBInterface_shards.cpp:458
ripple::makeMetaDBs
DatabasePair makeMetaDBs(Config const &config, DatabaseCon::Setup const &setup, DatabaseCon::CheckpointerSetup const &checkpointerSetup)
makeMetaDBs Opens ledger and transaction 'meta' databases which map ledger hashes and transaction IDs...
Definition: RelationalDBInterface_shards.cpp:36
ripple::DatabaseCon
Definition: DatabaseCon.h:81
ripple::saveLedgerMeta
bool saveLedgerMeta(std::shared_ptr< Ledger const > const &ledger, Application &app, soci::session &lgrMetaSession, soci::session &txnMetaSession, std::uint32_t const shardIndex)
saveLedgerMeta Stores (transaction ID -> shard index) and (ledger hash -> shard index) mappings in th...
Definition: RelationalDBInterface_shards.cpp:66
ripple::makeShardIncompleteLedgerDBs
DatabasePair makeShardIncompleteLedgerDBs(Config const &config, DatabaseCon::Setup const &setup, DatabaseCon::CheckpointerSetup const &checkpointerSetup)
makeShardIncompleteLedgerDBs Opens shard databases for not fully downloaded or verified shard and ret...
Definition: RelationalDBInterface_shards.cpp:178
std::optional< std::uint32_t >
ripple::insertArchiveDB
void insertArchiveDB(DatabaseCon &db, std::uint32_t shardIndex, std::string const &url)
insertArchiveDB Adds entry to shard archive database.
Definition: RelationalDBInterface_shards.cpp:472
ripple::selectAcquireDBLedgerSeqs
std::pair< bool, std::optional< std::string > > selectAcquireDBLedgerSeqs(soci::session &session, std::uint32_t index)
selectAcquireDBLedgerSeqs Returns set of acquired ledgers for given shard.
Definition: RelationalDBInterface_shards.cpp:359
ripple::makeArchiveDB
std::unique_ptr< DatabaseCon > makeArchiveDB(boost::filesystem::path const &dir, std::string const &dbName)
makeArchiveDB Opens shard archive DB and returns its descriptor.
Definition: RelationalDBInterface_shards.cpp:451
ripple::getShardIndexforTransaction
std::optional< std::uint32_t > getShardIndexforTransaction(soci::session &session, TxID const &id)
getShardIndexforTransaction Queries the transaction meta database to retrieve the index of the shard ...
Definition: RelationalDBInterface_shards.cpp:144
std::unique_ptr
STL class.
ripple::AcquireShardSeqsHash::sequences
std::optional< std::string > sequences
Definition: RelationalDBInterface_shards.h:173
ripple::makeShardCompleteLedgerDBs
DatabasePair makeShardCompleteLedgerDBs(Config const &config, DatabaseCon::Setup const &setup)
makeShardCompleteLedgerDBs Opens shard databases for already verified shard and returns its descripto...
Definition: RelationalDBInterface_shards.cpp:158
ripple::getShardIndexforLedger
std::optional< std::uint32_t > getShardIndexforLedger(soci::session &session, LedgerHash const &hash)
getShardIndexforLedger Queries the ledger meta database to retrieve the index of the shard that conta...
Definition: RelationalDBInterface_shards.cpp:130