0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
MetaLogEntityRange.cc
Go to the documentation of this file.
1 /*
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 #include <Common/Compat.h>
29 
30 #include "MetaLogEntityRange.h"
31 
33 
34 #include <Common/Serialization.h>
35 
36 using namespace Hypertable;
37 using namespace Hypertable::MetaLog;
38 using namespace std;
39 
41 
43  : Entity(header_) {
44 }
45 
47  const RangeSpec &spec,
48  const RangeState &state,
49  bool needs_compaction)
50  : Entity(EntityType::RANGE2), m_table(table), m_spec(spec), m_state(state),
51  m_needs_compaction(needs_compaction), m_load_acknowledged(false) {
52 }
53 
55  lock_guard<mutex> lock(m_mutex);
56  table = m_table;
57 }
58 
60  return m_table.id;
61 }
62 
63 void MetaLogEntityRange::set_table_generation(uint32_t generation) {
64  lock_guard<mutex> lock(m_mutex);
65  m_table.generation = generation;
66 }
67 
69  lock_guard<mutex> lock(m_mutex);
70  spec = m_spec;
71 }
72 
74  lock_guard<mutex> lock(m_mutex);
75  state = m_state;
76 }
77 
79  lock_guard<mutex> lock(m_mutex);
80  return (int)m_state.state;
81 }
82 
84  lock_guard<mutex> lock(m_mutex);
85  m_state.state |= bits;
86 }
87 
89  lock_guard<mutex> lock(m_mutex);
90  m_state.state &= ~bits;
91 }
92 
93 void MetaLogEntityRange::set_state(uint8_t state, const String &source) {
94  lock_guard<mutex> lock(m_mutex);
95  m_state.state = state;
96  m_state.set_source(source);
97 }
98 
100  lock_guard<mutex> lock(m_mutex);
101  m_state.clear();
102 }
103 
105  lock_guard<mutex> lock(m_mutex);
106  return m_state.soft_limit;
107 }
108 
109 void MetaLogEntityRange::set_soft_limit(uint64_t soft_limit) {
110  lock_guard<mutex> lock(m_mutex);
111  m_state.soft_limit = soft_limit;
112 }
113 
115  lock_guard<mutex> lock(m_mutex);
116  return m_state.split_point;
117 }
118 
120  lock_guard<mutex> lock(m_mutex);
122 }
123 
125  lock_guard<mutex> lock(m_mutex);
127 }
128 
130  lock_guard<mutex> lock(m_mutex);
132 }
133 
135  lock_guard<mutex> lock(m_mutex);
136  return m_spec.start_row;
137 }
138 
140  lock_guard<mutex> lock(m_mutex);
141  m_spec.set_start_row(row);
142 }
143 
145  lock_guard<mutex> lock(m_mutex);
146  return m_spec.end_row;
147 }
148 
150  lock_guard<mutex> lock(m_mutex);
151  m_spec.set_end_row(row);
152 }
153 
155  lock_guard<mutex> lock(m_mutex);
156  start = m_spec.start_row;
157  end = m_spec.end_row;
158 }
159 
161  lock_guard<mutex> lock(m_mutex);
162  return m_state.old_boundary_row;
163 }
164 
166  lock_guard<mutex> lock(m_mutex);
168 }
169 
171  lock_guard<mutex> lock(m_mutex);
172  return m_needs_compaction;
173 }
174 
176  lock_guard<mutex> lock(m_mutex);
177  m_needs_compaction = val;
178 }
179 
181  lock_guard<mutex> lock(m_mutex);
182  return m_load_acknowledged;
183 }
184 
186  lock_guard<mutex> lock(m_mutex);
187  m_load_acknowledged = val;
188 }
189 
191  lock_guard<mutex> lock(m_mutex);
192  return m_state.source ? m_state.source : "";
193 }
194 
195 void MetaLogEntityRange::decode(const uint8_t **bufp, size_t *remainp,
196  uint16_t definition_version) {
197  if (definition_version < 3)
198  decode_old(bufp, remainp);
199  else
200  Entity::decode(bufp, remainp);
201 }
202 
204  return "Range";
205 }
206 
207 void MetaLogEntityRange::display(std::ostream &os) {
208  lock_guard<mutex> lock(m_mutex);
209  os << " " << m_table << " " << m_spec << " " << m_state << " ";
210  os << "needs_compaction=" << (m_needs_compaction ? "true" : "false") << " ";
211  os << "load_acknowledged=" << (m_load_acknowledged ? "true" : "false") << " ";
212 }
213 
215  return 1;
216 }
217 
220  m_state.encoded_length() + 2;
221 }
222 
223 void MetaLogEntityRange::encode_internal(uint8_t **bufp) const {
224  m_table.encode(bufp);
225  m_spec.encode(bufp);
226  m_state.encode(bufp);
229 }
230 
231 void MetaLogEntityRange::decode_internal(uint8_t version, const uint8_t **bufp,
232  size_t *remainp) {
233  m_table.decode(bufp, remainp);
234  m_spec.decode(bufp, remainp);
235  m_state.decode(bufp, remainp);
238 }
239 
240 void MetaLogEntityRange::decode_old(const uint8_t **bufp, size_t *remainp) {
241  legacy_decode(bufp, remainp, &m_table);
242  legacy_decode(bufp, remainp, &m_spec);
243  legacy_decode(bufp, remainp, &m_state);
247  Serialization::decode_vstr(bufp, remainp);
248  else {
250  encountered_upgrade = true;
251  }
252 }
void get_table_identifier(TableIdentifier &table)
Copies table identifier.
void set_source(const std::string &src)
Sets source server name.
Definition: RangeState.h:315
size_t encoded_length_internal() const override
Returns internal serialized length.
char * decode_vstr(const uint8_t **bufp, size_t *remainp)
Decode a vstr (vint64, data, null).
String get_end_row()
Gets end row.
void set_soft_limit(uint64_t soft_limit)
Sets soft limit.
bool m_load_acknowledged
Load acknowledged flag.
void set_old_boundary_row(const std::string &obr)
Sets old boundary row.
Definition: RangeState.h:297
uint8_t encoding_version() const override
Returns encoding version.
Range specification.
Definition: RangeSpec.h:40
void clear_state_bits(uint8_t bits)
Clears bits of range state.
String get_start_row()
Gets Start row.
std::string String
A String is simply a typedef to std::string.
Definition: String.h:44
Declarations for MetaLogEntityRange.
virtual size_t encoded_length() const
Returns serialized object length.
Definition: Serializable.cc:37
String get_source()
Gets source server.
String get_old_boundary_row()
Gets old boundary row.
std::mutex m_mutex
Mutex for serializing access to members
uint64_t soft_limit
Soft split size limit.
Definition: RangeState.h:108
void set_table_generation(uint32_t generation)
Sets table generation.
bool get_needs_compaction()
Gets needs compaction flag.
bool m_needs_compaction
Needs compaction flag.
TableIdentifierManaged m_table
Table identifier
STL namespace.
const String name() override
Returns the entity name ("Range")
void set_transfer_log(const String &path)
Sets transfer log.
EntityHeader header
Entity header
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
Base class for MetaLog entities.
Definition: MetaLogEntity.h:62
void set_start_row(const std::string &s)
Definition: RangeSpec.h:112
void set_load_acknowledged(bool val)
Sets load acknowledged flag.
const char * end_row
Definition: RangeSpec.h:60
RangeStateManaged m_state
Range state
virtual void encode(uint8_t **bufp) const
Writes serialized representation of object to a buffer.
Definition: Serializable.cc:64
void set_split_row(const String &row)
Sets split row.
bool decode_bool(const uint8_t **bufp, size_t *remainp)
Decodes a boolean value from the given buffer.
Definition: Serialization.h:96
String get_transfer_log()
Gets transfer log.
void get_boundary_rows(String &start, String &end)
Gets boundary rows (start and end rows)
const char * get_table_id()
Returns table id.
int32_t type
Entity type defined within the context of a Definition
bool get_load_acknowledged()
Gets load acknowledged flag.
Compatibility Macros for C/C++.
const char * transfer_log
Full pathname of transfer log.
Definition: RangeState.h:111
void display(std::ostream &os) override
Writes a human readable representation of the object state to an output stream.
uint8_t state
Range state value (see StateType)
Definition: RangeState.h:102
uint64_t get_soft_limit()
Gets soft limit.
Functions to serialize/deserialize primitives to/from a memory buffer.
void get_range_state(RangeStateManaged &state)
Gets range state object.
void set_old_boundary_row(const String &row)
Sets old boundary row.
virtual void decode(const uint8_t **bufp, size_t *remainp)
Reads serialized representation of object from a buffer.
Definition: Serializable.cc:70
void set_end_row(const String &row)
Sets end row.
void lock()
Locks the entity's mutex.
Definition: MetaLogEntity.h:97
Hypertable definitions
void encode_internal(uint8_t **bufp) const override
Writes serialized representation of object to a buffer.
void legacy_decode(const uint8_t **bufp, size_t *remainp, BalancePlan *plan)
void encode_bool(uint8_t **bufp, bool bval)
Encodes a boolean into the given buffer.
Definition: Serialization.h:84
void set_transfer_log(const std::string &tl)
Sets transfer log.
Definition: RangeState.h:261
const char * start_row
Definition: RangeSpec.h:59
void decode_old(const uint8_t **bufp, size_t *remainp)
void set_needs_compaction(bool val)
Sets needs compaction flag.
void set_start_row(const String &row)
Sets start row.
void clear() override
Clears state.
Definition: RangeState.cc:160
const char * split_point
Split point (row key)
Definition: RangeState.h:114
void decode_internal(uint8_t version, const uint8_t **bufp, size_t *remainp) override
Reads serialized representation of object from a buffer.
String get_split_row()
Gets split row.
void set_end_row(const std::string &e)
Definition: RangeSpec.h:116
void set_split_point(const std::string &sp)
Sets split point.
Definition: RangeState.h:279
Range state.
Definition: RangeState.h:48
RangeSpecManaged m_spec
Range spec
void clear_state()
Clears range state object.
void set_state_bits(uint8_t bits)
Sets bits of range state.
Wrapper for RangeSpec providing member storage.
Definition: RangeSpec.h:89
MetaLogEntityRange(const MetaLog::EntityHeader &header_)
Constructor initialized from Metalog entity header.
Range state with memory management.
Definition: RangeState.h:166
MetaLog framework.
Definition: MetaLog.h:44
void decode(const uint8_t **bufp, size_t *remainp, uint16_t definition_version) override
Reads serialized encoding of the entity.
void set_state(uint8_t state, const String &source)
Sets range state.
void get_range_spec(RangeSpecManaged &spec)
Gets range specification.
static bool encountered_upgrade
Flag indicating that old entity was encountered.