rippled
ShardArchive.cpp
1 //------------------------------------------------------------------------------
2 /*
3  This file is part of rippled: https://github.com/ripple/rippled
4  Copyright (c) 2021 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/rdb/ShardArchive.h>
21 
22 namespace ripple {
23 
25 makeArchiveDB(boost::filesystem::path const& dir, std::string const& dbName)
26 {
27  return std::make_unique<DatabaseCon>(
29 }
30 
31 void
33  DatabaseCon& db,
34  std::function<void(std::string const&, int)> const& func)
35 {
36  soci::rowset<soci::row> rs =
37  (db.getSession().prepare << "SELECT * FROM State;");
38 
39  for (auto it = rs.begin(); it != rs.end(); ++it)
40  {
41  func(it->get<std::string>(1), it->get<int>(0));
42  }
43 }
44 
45 void
47  DatabaseCon& db,
48  std::uint32_t shardIndex,
49  std::string const& url)
50 {
51  db.getSession() << "INSERT INTO State VALUES (:index, :url);",
52  soci::use(shardIndex), soci::use(url);
53 }
54 
55 void
57 {
58  db.getSession() << "DELETE FROM State WHERE ShardIndex = :index;",
59  soci::use(shardIndex);
60 }
61 
62 void
64 {
65  db.getSession() << "DROP TABLE State;";
66 }
67 
68 } // namespace ripple
std::string
STL class.
ripple::ShardArchiveHandlerDBInit
static constexpr std::array< char const *, 3 > ShardArchiveHandlerDBInit
Definition: DBInit.h:258
std::function
ripple::DownloaderDBPragma
static constexpr std::array< char const *, 2 > DownloaderDBPragma
Definition: DBInit.h:255
ripple::deleteFromArchiveDB
void deleteFromArchiveDB(DatabaseCon &db, std::uint32_t shardIndex)
deleteFromArchiveDB Deletes an entry from the shard archive database.
Definition: ShardArchive.cpp:56
ripple::dropArchiveDB
void dropArchiveDB(DatabaseCon &db)
dropArchiveDB Removes a table in the shard archive database.
Definition: ShardArchive.cpp:63
std::uint32_t
ripple::DatabaseCon::getSession
soci::session & getSession()
Definition: DatabaseCon.h:172
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 Reads entries from the shard archive database and invokes the given callback for each e...
Definition: ShardArchive.cpp:32
ripple::DatabaseCon
Definition: DatabaseCon.h:81
ripple::insertArchiveDB
void insertArchiveDB(DatabaseCon &db, std::uint32_t shardIndex, std::string const &url)
insertArchiveDB Adds an entry to the shard archive database.
Definition: ShardArchive.cpp:46
ripple::makeArchiveDB
std::unique_ptr< DatabaseCon > makeArchiveDB(boost::filesystem::path const &dir, std::string const &dbName)
makeArchiveDB Opens the shard archive database and returns its descriptor.
Definition: ShardArchive.cpp:25
std::unique_ptr
STL class.