0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
RangeState.h
Go to the documentation of this file.
1 /* -*- c++ -*-
2  * Copyright (C) 2007-2015 Hypertable, Inc.
3  *
4  * This file is part of Hypertable.
5  *
6  * Hypertable is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; version 3 of the
9  * License, or any later version.
10  *
11  * Hypertable is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  * 02110-1301, USA.
20  */
21 
28 #ifndef Hypertable_Lib_RangeState_h
29 #define Hypertable_Lib_RangeState_h
30 
32 #include <Common/String.h>
33 #include <Common/Serializable.h>
34 
35 namespace Hypertable {
36 
39 
48  class RangeState : public Serializable {
49  public:
50 
52  enum StateType {
58  PHANTOM = 0x80
59  };
60 
65  split_point(0), old_boundary_row(0), source(0) { }
66 
71  RangeState(CharArena &arena, const RangeState &other) {
72  state = other.state;
73  timestamp = other.timestamp;
74  soft_limit = other.soft_limit;
75  transfer_log = other.transfer_log ? arena.dup(other.transfer_log) : 0;
76  split_point = other.split_point ? arena.dup(other.split_point) : 0;
77  old_boundary_row = other.old_boundary_row ? arena.dup(other.old_boundary_row) : 0;
78  source = other.source ? arena.dup(other.source) : 0;
79  }
80 
82  virtual ~RangeState() {}
83 
89  virtual void clear();
90 
99  static std::string get_text(uint8_t state);
100 
102  uint8_t state;
103 
105  int64_t timestamp;
106 
108  uint64_t soft_limit;
109 
111  const char *transfer_log;
112 
114  const char *split_point;
115 
117  const char *old_boundary_row;
118 
120  const char *source;
121 
122  protected:
123 
126  uint8_t encoding_version() const override;
127 
130 
132  size_t encoded_length_internal() const override;
133 
136  void encode_internal(uint8_t **bufp) const override;
137 
144  void decode_internal(uint8_t version, const uint8_t **bufp,
145  size_t *remainp) override;
146 
147  };
148 
158  std::ostream &operator<<(std::ostream &out, const RangeState &st);
159 
166  class RangeStateManaged : public RangeState {
167  public:
168 
171 
176  operator=(rs);
177  }
178 
185  operator=(rs);
186  }
187 
189  virtual ~RangeStateManaged() {}
190 
191  void clear() override;
192 
199  const RangeState *otherp = &other;
200  return operator=(*otherp);
201  }
202 
221  state = rs.state;
222  timestamp = rs.timestamp;
223  soft_limit = rs.soft_limit;
224 
225  if (rs.transfer_log) {
227  transfer_log = m_transfer_log.c_str();
228  }
229  else
231 
232  if (rs.split_point) {
234  split_point = m_split_point.c_str();
235  }
236  else
238 
239  if (rs.old_boundary_row) {
242  }
243  else
245 
246  if (rs.source) {
247  m_source = rs.source;
248  source = m_source.c_str();
249  }
250  else
251  clear_source();
252 
253  return *this;
254  }
255 
261  void set_transfer_log(const std::string &tl) {
262  m_transfer_log = tl;
263  transfer_log = m_transfer_log.c_str();
264  }
265 
270  m_transfer_log = "";
271  transfer_log = 0;
272  }
273 
279  void set_split_point(const std::string &sp) {
280  m_split_point = sp;
281  split_point = m_split_point.c_str();
282  }
283 
288  m_split_point = "";
289  split_point = 0;
290  }
291 
297  void set_old_boundary_row(const std::string &obr) {
298  m_old_boundary_row = obr;
300  }
301 
306  m_old_boundary_row = "";
307  old_boundary_row = 0;
308  }
309 
315  void set_source(const std::string &src) {
316  m_source = src;
317  source = m_source.c_str();
318  }
319 
323  void clear_source() {
324  m_source = "";
325  source = 0;
326  }
327 
328  private:
329 
336  void decode_internal(uint8_t version, const uint8_t **bufp,
337  size_t *remainp) override;
338 
340  std::string m_transfer_log;
341 
343  std::string m_split_point;
344 
346  std::string m_old_boundary_row;
347 
349  std::string m_source;
350  };
351 
353 
354 }
355 
356 #endif // Hypertable_Lib_RangeState_h
void decode_internal(uint8_t version, const uint8_t **bufp, size_t *remainp) override
Reads serialized representation of object from a buffer.
Definition: RangeState.cc:133
void set_source(const std::string &src)
Sets source server name.
Definition: RangeState.h:315
StateType
Mixed enumeration for range state values and PHANTOM bit mask.
Definition: RangeState.h:52
void encode_internal(uint8_t **bufp) const override
Writes serialized representation of object to a buffer.
Definition: RangeState.cc:123
virtual void clear()
Clears state.
Definition: RangeState.cc:41
void set_old_boundary_row(const std::string &obr)
Sets old boundary row.
Definition: RangeState.h:297
void clear_source()
Clears source member.
Definition: RangeState.h:323
uint64_t soft_limit
Soft split size limit.
Definition: RangeState.h:108
PageArena memory allocator for STL classes.
virtual ~RangeStateManaged()
Destructor.
Definition: RangeState.h:189
const char * old_boundary_row
Original range boundary row.
Definition: RangeState.h:117
const char * source
Source server where this range previously lived.
Definition: RangeState.h:120
CharT * dup(const CharT *s)
Duplicate a null terminated string; memory is allocated from the pool.
Definition: PageArena.h:274
uint8_t encoding_version() const override
Returns encoding version.
Definition: RangeState.cc:76
void clear_transfer_log()
Clears transfer log.
Definition: RangeState.h:269
RangeStateManaged(const RangeStateManaged &rs)
Copy constructor.
Definition: RangeState.h:175
const char * transfer_log
Full pathname of transfer log.
Definition: RangeState.h:111
std::ostream & operator<<(std::ostream &os, const crontab_entry &entry)
Helper function to write crontab_entry to an ostream.
Definition: Crontab.cc:301
The PageArena allocator is simple and fast, avoiding individual mallocs/frees.
Definition: PageArena.h:69
RangeState(CharArena &arena, const RangeState &other)
Copy constructor.
Definition: RangeState.h:71
uint8_t state
Range state value (see StateType)
Definition: RangeState.h:102
RangeState()
Default constructor.
Definition: RangeState.h:64
size_t encoded_length_internal() const override
Returns internal serialized length.
Definition: RangeState.cc:80
int64_t timestamp
Timestamp
Definition: RangeState.h:105
static std::string get_text(uint8_t state)
Returns string representation of range state value.
Definition: RangeState.cc:48
std::string m_old_boundary_row
Old boundary row string container.
Definition: RangeState.h:346
Declarations for Serializable.
Hypertable definitions
RangeStateManaged(const RangeState &rs)
Constructor initialized with RangeState object.
Definition: RangeState.h:184
RangeStateManaged()
Default constructor.
Definition: RangeState.h:170
Relinquish - range compacted.
Definition: RangeState.h:57
void set_transfer_log(const std::string &tl)
Sets transfer log.
Definition: RangeState.h:261
std::string m_split_point
Split point string container.
Definition: RangeState.h:343
Mixin class that provides a standard serialization interface.
Definition: Serializable.h:65
Split - range shrunk.
Definition: RangeState.h:55
std::string m_transfer_log
Transfer log string container.
Definition: RangeState.h:340
void clear() override
Clears state.
Definition: RangeState.cc:160
const char * split_point
Split point (row key)
Definition: RangeState.h:114
A String class based on std::string.
std::string m_source
Source server string container.
Definition: RangeState.h:349
void set_split_point(const std::string &sp)
Sets split point.
Definition: RangeState.h:279
Range state.
Definition: RangeState.h:48
void decode_internal(uint8_t version, const uint8_t **bufp, size_t *remainp) override
Reads serialized representation of object from a buffer.
Definition: RangeState.cc:165
void clear_old_boundary_row()
Clears old_boundary_row.
Definition: RangeState.h:305
void clear_split_point()
Clears split point.
Definition: RangeState.h:287
Range state with memory management.
Definition: RangeState.h:166
RangeStateManaged & operator=(const RangeState &rs)
Assignment operator with RangeState object.
Definition: RangeState.h:220
RangeStateManaged & operator=(const RangeStateManaged &other)
Assignment operator.
Definition: RangeState.h:198
virtual ~RangeState()
Destructor.
Definition: RangeState.h:82