Skip to content

Commit

Permalink
Extend peer shard info
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelportilla committed Jan 14, 2021
1 parent 55dc7a2 commit 6b28633
Show file tree
Hide file tree
Showing 25 changed files with 1,001 additions and 673 deletions.
1 change: 1 addition & 0 deletions Builds/CMake/RippledCore.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,7 @@ target_sources (rippled PRIVATE
src/ripple/nodestore/impl/ManagerImp.cpp
src/ripple/nodestore/impl/NodeObject.cpp
src/ripple/nodestore/impl/Shard.cpp
"../../src/ripple/nodestore/impl/ShardInfo.cpp"
src/ripple/nodestore/impl/TaskQueue.cpp
#[===============================[
main sources:
Expand Down
15 changes: 6 additions & 9 deletions src/ripple/basics/RangeSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,18 +98,15 @@ template <class T>
std::string
to_string(RangeSet<T> const& rs)
{
using ripple::to_string;

if (rs.empty())
return "empty";
std::string res = "";

std::string s;
for (auto const& interval : rs)
{
if (!res.empty())
res += ",";
res += to_string(interval);
}
return res;
s += ripple::to_string(interval) + ",";
s.pop_back();

return s;
}

/** Convert the given styled string to a RangeSet.
Expand Down
18 changes: 9 additions & 9 deletions src/ripple/nodestore/DatabaseShard.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
#define RIPPLE_NODESTORE_DATABASESHARD_H_INCLUDED

#include <ripple/app/ledger/Ledger.h>
#include <ripple/basics/RangeSet.h>
#include <ripple/nodestore/Database.h>
#include <ripple/nodestore/ShardInfo.h>
#include <ripple/nodestore/Types.h>

#include <boost/optional.hpp>
Expand Down Expand Up @@ -61,7 +61,7 @@ class DatabaseShard : public Database
@return `true` if the database initialized without error
*/
virtual bool
virtual [[nodiscard]] bool
init() = 0;

/** Prepare to store a new ledger in the shard being acquired
Expand All @@ -75,7 +75,7 @@ class DatabaseShard : public Database
between requests.
@implNote adds a new writable shard if necessary
*/
virtual boost::optional<std::uint32_t>
virtual [[nodiscard]] boost::optional<std::uint32_t>
prepareLedger(std::uint32_t validLedgerSeq) = 0;

/** Prepare one or more shard indexes to be imported into the database
Expand Down Expand Up @@ -118,7 +118,7 @@ class DatabaseShard : public Database
@param seq The sequence of the ledger
@return The ledger if found, nullptr otherwise
*/
virtual std::shared_ptr<Ledger>
virtual [[nodiscard]] std::shared_ptr<Ledger>
fetchLedger(uint256 const& hash, std::uint32_t seq) = 0;

/** Notifies the database that the given ledger has been
Expand All @@ -129,12 +129,12 @@ class DatabaseShard : public Database
virtual void
setStored(std::shared_ptr<Ledger const> const& ledger) = 0;

/** Query which complete shards are stored
/** Query information about shards held
@return the indexes of complete shards
@return Information about shards held by this node
*/
virtual std::string
getCompleteShards() = 0;
virtual [[nodiscard]] std::unique_ptr<ShardInfo>
getShardInfo() = 0;

/** @return The maximum number of ledgers stored in a shard
*/
Expand Down Expand Up @@ -187,7 +187,7 @@ seqToShardIndex(
return (ledgerSeq - 1) / ledgersPerShard;
}

extern std::unique_ptr<DatabaseShard>
extern [[nodiscard]] std::unique_ptr<DatabaseShard>
make_ShardStore(
Application& app,
Stoppable& parent,
Expand Down
67 changes: 67 additions & 0 deletions src/ripple/nodestore/ShardInfo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2020 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================

#ifndef RIPPLE_NODESTORE_SHARDINFO_H_INCLUDED
#define RIPPLE_NODESTORE_SHARDINFO_H_INCLUDED

#include <ripple/basics/RangeSet.h>
#include <ripple/nodestore/Types.h>
#include <ripple/nodestore/impl/Shard.h>
#include <ripple/protocol/messages.h>

namespace ripple {
namespace NodeStore {

/* Contains information on the status of shards for a node
*/
class ShardInfo
{
public:
struct Incomplete
{
Incomplete() = delete;
Incomplete(State state_, float progress_)
: state(state_), progress(progress_)
{
}

State const state;
float const progress;
};

[[nodiscard]] std::string
finalToString() const;

[[nodiscard]] std::string
incompleteToString() const;

[[nodiscard]] protocol::TMPeerShardInfoV2
makeMessage(Application& app) const;

// Complete and verified immutable shards
RangeSet<std::uint32_t> final;

// Incomplete shards being acquired or verified
std::map<std::uint32_t, Incomplete> incomplete;
};

} // namespace NodeStore
} // namespace ripple

#endif
15 changes: 15 additions & 0 deletions src/ripple/nodestore/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,21 @@ enum Status {
/** A batch of NodeObjects to write at once. */
using Batch = std::vector<std::shared_ptr<NodeObject>>;

/** Shard states. */
enum class State {
acquire, // Being acquired
complete, // Backend contains all ledgers, requires finalizing
finalizing, // Being finalized
final, // Database verified, shard is immutable
queued // Queued to be finalized
};

static constexpr State acquire = State::acquire;
static constexpr State complete = State::complete;
static constexpr State finalizing = State::finalizing;
static constexpr State final = State::final;
static constexpr State queued = State::queued;

} // namespace NodeStore
} // namespace ripple

Expand Down
Loading

0 comments on commit 6b28633

Please sign in to comment.