rippled
ShardInfo.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_NODESTORE_SHARDINFO_H_INCLUDED
21 #define RIPPLE_NODESTORE_SHARDINFO_H_INCLUDED
22 
23 #include <ripple/basics/RangeSet.h>
24 #include <ripple/nodestore/Types.h>
25 #include <ripple/protocol/messages.h>
26 
27 namespace ripple {
28 namespace NodeStore {
29 
30 /* Contains information on the status of shards for a node
31  */
32 class ShardInfo
33 {
34 private:
35  class Incomplete
36  {
37  public:
38  Incomplete() = delete;
41  {
42  }
43 
44  [[nodiscard]] ShardState
45  state() const noexcept
46  {
47  return state_;
48  }
49 
50  [[nodiscard]] std::uint32_t
51  percentProgress() const noexcept
52  {
53  return percentProgress_;
54  }
55 
56  private:
59  };
60 
61 public:
62  [[nodiscard]] NetClock::time_point const&
63  msgTimestamp() const
64  {
65  return msgTimestamp_;
66  }
67 
68  void
70  {
71  msgTimestamp_ = timestamp;
72  }
73 
74  [[nodiscard]] std::string
75  finalizedToString() const;
76 
77  [[nodiscard]] bool
79  {
80  return from_string(finalized_, str);
81  }
82 
83  [[nodiscard]] RangeSet<std::uint32_t> const&
84  finalized() const
85  {
86  return finalized_;
87  }
88 
89  [[nodiscard]] std::string
90  incompleteToString() const;
91 
92  [[nodiscard]] std::map<std::uint32_t, Incomplete> const&
93  incomplete() const
94  {
95  return incomplete_;
96  }
97 
98  // Returns true if successful or false because of a duplicate index
99  bool
100  update(
101  std::uint32_t shardIndex,
102  ShardState state,
103  std::uint32_t percentProgress);
104 
105  [[nodiscard]] protocol::TMPeerShardInfoV2
106  makeMessage(Application& app);
107 
108 private:
109  // Finalized immutable shards
111 
112  // Incomplete shards being acquired or finalized
114 
115  // Message creation time
117 };
118 
119 } // namespace NodeStore
120 } // namespace ripple
121 
122 #endif
ripple::Application
Definition: Application.h:115
std::string
STL class.
ripple::NodeStore::ShardInfo::incomplete_
std::map< std::uint32_t, Incomplete > incomplete_
Definition: ShardInfo.h:113
ripple::NodeStore::ShardInfo::setMsgTimestamp
void setMsgTimestamp(NetClock::time_point const &timestamp)
Definition: ShardInfo.h:69
ripple::from_string
bool from_string(RangeSet< T > &rs, std::string const &s)
Convert the given styled string to a RangeSet.
Definition: RangeSet.h:123
ripple::NodeStore::ShardInfo::update
bool update(std::uint32_t shardIndex, ShardState state, std::uint32_t percentProgress)
Definition: ShardInfo.cpp:55
ripple::ShardState
ShardState
Shard states.
Definition: nodestore/Types.h:60
ripple::NodeStore::ShardInfo::Incomplete::Incomplete
Incomplete(ShardState state, std::uint32_t percentProgress)
Definition: ShardInfo.h:39
ripple::NodeStore::ShardInfo::Incomplete::percentProgress_
std::uint32_t percentProgress_
Definition: ShardInfo.h:58
ripple::NodeStore::ShardInfo::Incomplete::Incomplete
Incomplete()=delete
ripple::NodeStore::ShardInfo::setFinalizedFromString
bool setFinalizedFromString(std::string const &str)
Definition: ShardInfo.h:78
ripple::NodeStore::ShardInfo::Incomplete
Definition: ShardInfo.h:35
ripple::NodeStore::ShardInfo::finalized_
RangeSet< std::uint32_t > finalized_
Definition: ShardInfo.h:110
ripple::NodeStore::ShardInfo::incomplete
std::map< std::uint32_t, Incomplete > const & incomplete() const
Definition: ShardInfo.h:93
ripple::NodeStore::ShardInfo::msgTimestamp
NetClock::time_point const & msgTimestamp() const
Definition: ShardInfo.h:63
ripple::NodeStore::ShardInfo::Incomplete::state_
ShardState state_
Definition: ShardInfo.h:57
ripple::NodeStore::ShardInfo::makeMessage
protocol::TMPeerShardInfoV2 makeMessage(Application &app)
Definition: ShardInfo.cpp:74
std::chrono::time_point
std::uint32_t
std::map
STL class.
ripple::NodeStore::ShardInfo
Definition: ShardInfo.h:32
ripple::NodeStore::ShardInfo::msgTimestamp_
NetClock::time_point msgTimestamp_
Definition: ShardInfo.h:116
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::NodeStore::ShardInfo::incompleteToString
std::string incompleteToString() const
Definition: ShardInfo.cpp:38
ripple::NodeStore::ShardInfo::finalizedToString
std::string finalizedToString() const
Definition: ShardInfo.cpp:30
ripple::NodeStore::ShardInfo::Incomplete::state
ShardState state() const noexcept
Definition: ShardInfo.h:45
ripple::RangeSet
boost::icl::interval_set< T, std::less, ClosedInterval< T > > RangeSet
A set of closed intervals over the domain T.
Definition: RangeSet.h:69
ripple::NodeStore::ShardInfo::Incomplete::percentProgress
std::uint32_t percentProgress() const noexcept
Definition: ShardInfo.h:51
ripple::NodeStore::ShardInfo::finalized
RangeSet< std::uint32_t > const & finalized() const
Definition: ShardInfo.h:84