rippled
JobTypes.h
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 #ifndef RIPPLE_CORE_JOBTYPES_H_INCLUDED
21 #define RIPPLE_CORE_JOBTYPES_H_INCLUDED
22 
23 #include <ripple/core/Job.h>
24 #include <ripple/core/JobTypeInfo.h>
25 #include <map>
26 #include <string>
27 #include <type_traits>
28 #include <unordered_map>
29 
30 namespace ripple {
31 
32 class JobTypes
33 {
34 public:
36  using const_iterator = Map::const_iterator;
37 
38 private:
40  : m_unknown(
41  jtINVALID,
42  "invalid",
43  0,
44  true,
45  std::chrono::milliseconds{0},
47  {
48  using namespace std::chrono_literals;
49  int maxLimit = std::numeric_limits<int>::max();
50 
51  add(jtPACK, "makeFetchPack", 1, false, 0ms, 0ms);
52  add(jtPUBOLDLEDGER, "publishAcqLedger", 2, false, 10000ms, 15000ms);
54  "untrustedValidation",
55  maxLimit,
56  false,
57  2000ms,
58  5000ms);
59  add(jtTRANSACTION_l, "localTransaction", maxLimit, false, 100ms, 500ms);
60  add(jtREPLAY_REQ, "ledgerReplayRequest", 10, false, 250ms, 1000ms);
61  add(jtLEDGER_REQ, "ledgerRequest", 2, false, 0ms, 0ms);
62  add(jtPROPOSAL_ut, "untrustedProposal", maxLimit, false, 500ms, 1250ms);
63  add(jtREPLAY_TASK, "ledgerReplayTask", maxLimit, false, 0ms, 0ms);
64  add(jtLEDGER_DATA, "ledgerData", 2, false, 0ms, 0ms);
65  add(jtCLIENT, "clientCommand", maxLimit, false, 2000ms, 5000ms);
66  add(jtRPC, "RPC", maxLimit, false, 0ms, 0ms);
67  add(jtUPDATE_PF, "updatePaths", maxLimit, false, 0ms, 0ms);
68  add(jtTRANSACTION, "transaction", maxLimit, false, 250ms, 1000ms);
69  add(jtBATCH, "batch", maxLimit, false, 250ms, 1000ms);
70  add(jtADVANCE, "advanceLedger", maxLimit, false, 0ms, 0ms);
71  add(jtPUBLEDGER, "publishNewLedger", maxLimit, false, 3000ms, 4500ms);
72  add(jtTXN_DATA, "fetchTxnData", 1, false, 0ms, 0ms);
73  add(jtWAL, "writeAhead", maxLimit, false, 1000ms, 2500ms);
75  "trustedValidation",
76  maxLimit,
77  false,
78  500ms,
79  1500ms);
80  add(jtWRITE, "writeObjects", maxLimit, false, 1750ms, 2500ms);
81  add(jtACCEPT, "acceptLedger", maxLimit, false, 0ms, 0ms);
82  add(jtPROPOSAL_t, "trustedProposal", maxLimit, false, 100ms, 500ms);
83  add(jtSWEEP, "sweep", maxLimit, false, 0ms, 0ms);
84  add(jtNETOP_CLUSTER, "clusterReport", 1, false, 9999ms, 9999ms);
85  add(jtNETOP_TIMER, "heartbeat", 1, false, 999ms, 999ms);
86  add(jtADMIN, "administration", maxLimit, false, 0ms, 0ms);
87 
88  add(jtPEER, "peerCommand", 0, true, 200ms, 2500ms);
89  add(jtDISK, "diskAccess", 0, true, 500ms, 1000ms);
90  add(jtTXN_PROC, "processTransaction", 0, true, 0ms, 0ms);
91  add(jtOB_SETUP, "orderBookSetup", 0, true, 0ms, 0ms);
92  add(jtPATH_FIND, "pathFind", 0, true, 0ms, 0ms);
93  add(jtHO_READ, "nodeRead", 0, true, 0ms, 0ms);
94  add(jtHO_WRITE, "nodeWrite", 0, true, 0ms, 0ms);
95  add(jtGENERIC, "generic", 0, true, 0ms, 0ms);
96  add(jtNS_SYNC_READ, "SyncReadNode", 0, true, 0ms, 0ms);
97  add(jtNS_ASYNC_READ, "AsyncReadNode", 0, true, 0ms, 0ms);
98  add(jtNS_WRITE, "WriteNode", 0, true, 0ms, 0ms);
99  }
100 
101 public:
102  static JobTypes const&
104  {
105  static JobTypes const types;
106  return types;
107  }
108 
109  static std::string const&
111  {
112  return instance().get(jt).name();
113  }
114 
115  JobTypeInfo const&
116  get(JobType jt) const
117  {
118  Map::const_iterator const iter(m_map.find(jt));
119  assert(iter != m_map.end());
120 
121  if (iter != m_map.end())
122  return iter->second;
123 
124  return m_unknown;
125  }
126 
127  JobTypeInfo const&
128  getInvalid() const
129  {
130  return m_unknown;
131  }
132 
133  Map::size_type
134  size() const
135  {
136  return m_map.size();
137  }
138 
140  begin() const
141  {
142  return m_map.cbegin();
143  }
144 
146  cbegin() const
147  {
148  return m_map.cbegin();
149  }
150 
152  end() const
153  {
154  return m_map.cend();
155  }
156 
158  cend() const
159  {
160  return m_map.cend();
161  }
162 
163 private:
164  void
167  int limit,
168  bool special,
169  std::chrono::milliseconds avgLatency,
170  std::chrono::milliseconds peakLatency)
171  {
172  assert(m_map.find(jt) == m_map.end());
173 
174  auto const [_, inserted] = m_map.emplace(
175  std::piecewise_construct,
178  jt, name, limit, special, avgLatency, peakLatency));
179 
180  assert(inserted == true);
181  (void)_;
182  (void)inserted;
183  }
184 
187 };
188 
189 } // namespace ripple
190 
191 #endif
ripple::jtTRANSACTION
@ jtTRANSACTION
Definition: Job.h:53
ripple::jtHO_WRITE
@ jtHO_WRITE
Definition: Job.h:75
ripple::Dir::const_iterator
Definition: Directory.h:49
ripple::JobTypes::add
void add(JobType jt, std::string name, int limit, bool special, std::chrono::milliseconds avgLatency, std::chrono::milliseconds peakLatency)
Definition: JobTypes.h:165
std::string
STL class.
ripple::jtCLIENT
@ jtCLIENT
Definition: Job.h:50
ripple::JobTypes
Definition: JobTypes.h:32
ripple::jtPATH_FIND
@ jtPATH_FIND
Definition: Job.h:73
ripple::jtACCEPT
@ jtACCEPT
Definition: Job.h:61
ripple::jtHO_READ
@ jtHO_READ
Definition: Job.h:74
ripple::jtREPLAY_TASK
@ jtREPLAY_TASK
Definition: Job.h:48
ripple::JobTypes::m_map
Map m_map
Definition: JobTypes.h:186
std::map::find
T find(T... args)
std::map::size
T size(T... args)
ripple::jtNETOP_CLUSTER
@ jtNETOP_CLUSTER
Definition: Job.h:64
std::chrono::milliseconds
ripple::JobTypes::const_iterator
Map::const_iterator const_iterator
Definition: JobTypes.h:36
std::map::emplace
T emplace(T... args)
ripple::jtNS_SYNC_READ
@ jtNS_SYNC_READ
Definition: Job.h:79
ripple::jtUPDATE_PF
@ jtUPDATE_PF
Definition: Job.h:52
ripple::jtADMIN
@ jtADMIN
Definition: Job.h:66
ripple::jtNS_WRITE
@ jtNS_WRITE
Definition: Job.h:81
ripple::jtSWEEP
@ jtSWEEP
Definition: Job.h:63
ripple::jtWRITE
@ jtWRITE
Definition: Job.h:60
ripple::jtLEDGER_DATA
@ jtLEDGER_DATA
Definition: Job.h:49
ripple::JobTypes::cbegin
const_iterator cbegin() const
Definition: JobTypes.h:146
ripple::jtBATCH
@ jtBATCH
Definition: Job.h:54
ripple::jtTXN_DATA
@ jtTXN_DATA
Definition: Job.h:57
ripple::jtTRANSACTION_l
@ jtTRANSACTION_l
Definition: Job.h:44
ripple::jtPUBOLDLEDGER
@ jtPUBOLDLEDGER
Definition: Job.h:42
ripple::jtDISK
@ jtDISK
Definition: Job.h:70
ripple::jtTXN_PROC
@ jtTXN_PROC
Definition: Job.h:71
ripple::jtPROPOSAL_t
@ jtPROPOSAL_t
Definition: Job.h:62
ripple::jtNETOP_TIMER
@ jtNETOP_TIMER
Definition: Job.h:65
ripple::JobTypes::m_unknown
JobTypeInfo m_unknown
Definition: JobTypes.h:185
ripple::JobTypeInfo
Holds all the 'static' information about a job, which does not change.
Definition: JobTypeInfo.h:28
ripple::jtGENERIC
@ jtGENERIC
Definition: Job.h:76
ripple::jtVALIDATION_t
@ jtVALIDATION_t
Definition: Job.h:59
ripple::JobTypes::get
JobTypeInfo const & get(JobType jt) const
Definition: JobTypes.h:116
ripple::JobTypes::instance
static JobTypes const & instance()
Definition: JobTypes.h:103
ripple::jtINVALID
@ jtINVALID
Definition: Job.h:35
ripple::jtOB_SETUP
@ jtOB_SETUP
Definition: Job.h:72
ripple::JobTypes::name
static std::string const & name(JobType jt)
Definition: JobTypes.h:110
ripple::JobTypes::begin
const_iterator begin() const
Definition: JobTypes.h:140
ripple::jtRPC
@ jtRPC
Definition: Job.h:51
std::forward_as_tuple
T forward_as_tuple(T... args)
map
ripple::jtPUBLEDGER
@ jtPUBLEDGER
Definition: Job.h:56
ripple::JobTypeInfo::name
std::string const & name() const
Definition: JobTypeInfo.h:71
ripple::jtPEER
@ jtPEER
Definition: Job.h:69
ripple::jtPACK
@ jtPACK
Definition: Job.h:41
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::JobTypes::getInvalid
JobTypeInfo const & getInvalid() const
Definition: JobTypes.h:128
ripple::jtVALIDATION_ut
@ jtVALIDATION_ut
Definition: Job.h:43
ripple::JobTypes::cend
const_iterator cend() const
Definition: JobTypes.h:158
std::map::cbegin
T cbegin(T... args)
std
STL namespace.
ripple::jtWAL
@ jtWAL
Definition: Job.h:58
ripple::JobTypes::end
const_iterator end() const
Definition: JobTypes.h:152
ripple::jtREPLAY_REQ
@ jtREPLAY_REQ
Definition: Job.h:45
ripple::jtPROPOSAL_ut
@ jtPROPOSAL_ut
Definition: Job.h:47
ripple::JobType
JobType
Definition: Job.h:33
std::map::end
T end(T... args)
ripple::jtADVANCE
@ jtADVANCE
Definition: Job.h:55
std::numeric_limits::max
T max(T... args)
ripple::JobTypes::JobTypes
JobTypes()
Definition: JobTypes.h:39
unordered_map
ripple::JobTypes::size
Map::size_type size() const
Definition: JobTypes.h:134
type_traits
ripple::jtNS_ASYNC_READ
@ jtNS_ASYNC_READ
Definition: Job.h:80
ripple::jtLEDGER_REQ
@ jtLEDGER_REQ
Definition: Job.h:46
string