0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ReceiverPlan.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 2 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 
22 #include "Common/Compat.h"
23 #include "ReceiverPlan.h"
24 
25 using namespace Hypertable;
27 using namespace std;
28 
29 
31  auto &location_index = other.container.get<ServerReceiverPlanByLocation>();
32  for (auto & entry : location_index) {
33  ServerReceiverPlan copied(arena, entry.location, entry.spec.table,
34  entry.spec.range, entry.state);
35  container.insert(copied);
36  }
37 }
38 
39 void ReceiverPlan::insert(const String &location, const TableIdentifier &table,
40  const RangeSpec &range, const RangeState &state) {
41  ServerReceiverPlan entry(arena, location, table, range, state);
42  auto &range_index = container.get<ServerReceiverPlanByRange>();
43  auto iter = range_index.find(entry.spec);
44  if (iter != range_index.end())
45  range_index.erase(iter);
46  container.insert(entry);
47 }
48 
49 
51  auto &range_index = container.get<ServerReceiverPlanByRange>();
52  auto iter = range_index.find(qrs);
53  if (iter != range_index.end())
54  range_index.erase(iter);
55 }
56 
57 
58 void ReceiverPlan::get_locations(StringSet &locations) const {
59  auto &location_index = container.get<ServerReceiverPlanByLocation>();
60  String last_location;
61  for (auto & entry : location_index) {
62  if (entry.location != last_location) {
63  last_location = entry.location;
64  locations.insert(last_location);
65  }
66  }
67 }
68 
69 bool ReceiverPlan::get_location(const QualifiedRangeSpec &spec, String &location) const {
70  auto &range_index = container.get<ServerReceiverPlanByRange>();
71  auto range_it = range_index.find(spec);
72  if (range_it != range_index.end()) {
73  location = range_it->location;
74  return true;
75  }
76  return false;
77 }
78 
79 
80 void ReceiverPlan::get_range_specs(vector<QualifiedRangeSpec> &specs) const {
81  auto &index = container.get<ServerReceiverPlanByLocation>();
82  for (auto & entry : index)
83  specs.push_back(entry.spec);
84 }
85 
86 void ReceiverPlan::get_range_specs(const String &location, vector<QualifiedRangeSpec> &specs) const {
87  auto &location_index = container.get<ServerReceiverPlanByLocation>();
88  pair<ServerReceiverPlanLocationIndex::iterator, ServerReceiverPlanLocationIndex::iterator> bounds =
89  location_index.equal_range(location);
90  for (auto iter = bounds.first; iter != bounds.second; ++iter)
91  specs.push_back(iter->spec);
92 }
93 
94 void ReceiverPlan::get_range_specs_and_states(vector<QualifiedRangeSpec> &specs,
95  vector<RangeState> &states) const {
96  auto &index = container.get<ServerReceiverPlanByLocation>();
97  for (auto & entry : index) {
98  specs.push_back(entry.spec);
99  states.push_back(entry.state);
100  }
101 }
102 
103 
105  vector<QualifiedRangeSpec> &specs,
106  vector<RangeState> &states) const {
107  auto &location_index = container.get<ServerReceiverPlanByLocation>();
108  pair<ServerReceiverPlanLocationIndex::iterator, ServerReceiverPlanLocationIndex::iterator> bounds =
109  location_index.equal_range(location);
110  for (auto iter = bounds.first; iter != bounds.second; ++iter) {
111  specs.push_back(iter->spec);
112  states.push_back(iter->state);
113  }
114 }
115 
116 bool ReceiverPlan::get_range_spec(const TableIdentifier &table, const char *row,
117  QualifiedRangeSpec &spec) const {
118  auto &range_index = container.get<ServerReceiverPlanByRange>();
119  QualifiedRangeSpec target(table, RangeSpec("",row));
120  auto range_it = range_index.lower_bound(target);
121 
122  bool found = false;
123 
124  while(range_it != range_index.end() && range_it->spec.table == table) {
125  if (strcmp(row, range_it->spec.range.start_row) > 0 &&
126  strcmp(row, range_it->spec.range.end_row) <= 0 ) {
127  spec = range_it->spec;
128  found = true;
129  break;
130  }
131  else if (strcmp(row, range_it->spec.range.start_row)<=0) {
132  // gone too far
133  break;
134  }
135  ++range_it;
136  }
149  return found;
150 }
151 
152 void ReceiverPlan::copy(ReceiverPlan &other) const {
153  auto &location_index = container.get<ServerReceiverPlanByLocation>();
154  for (auto & entry : location_index) {
155  ServerReceiverPlan copied(other.arena, entry.location, entry.spec.table,
156  entry.spec.range, entry.state);
157  other.container.insert(copied);
158  }
159 }
160 
162  return 1;
163 }
164 
166  auto &location_index = container.get<ServerReceiverPlanByLocation>();
167  size_t length = 4;
168  for (auto & entry : location_index)
169  length += entry.encoded_length();
170  return length;
171 }
172 
192 void ReceiverPlan::encode_internal(uint8_t **bufp) const {
193  auto &location_index = container.get<ServerReceiverPlanByLocation>();
194  Serialization::encode_i32(bufp, location_index.size());
195  for (auto & entry : location_index)
196  entry.encode(bufp);
197 }
198 
199 void ReceiverPlan::decode_internal(uint8_t version, const uint8_t **bufp,
200  size_t *remainp) {
201  size_t count = Serialization::decode_i32(bufp, remainp);
202  for (size_t i = 0; i<count; ++i) {
203  ServerReceiverPlan tmp;
204  tmp.decode(bufp, remainp);
205  ServerReceiverPlan entry(arena, tmp.location, tmp.spec.table,
206  tmp.spec.range, tmp.state);
207  container.insert(entry);
208  }
209 }
std::set< String > StringSet
STL Set managing Strings.
Definition: StringExt.h:42
uint8_t encoding_version() const override
Returns encoding version.
Range specification.
Definition: RangeSpec.h:40
std::string String
A String is simply a typedef to std::string.
Definition: String.h:44
void get_range_specs(vector< QualifiedRangeSpec > &specs) const
Definition: ReceiverPlan.cc:80
STL namespace.
bool get_location(const QualifiedRangeSpec &spec, String &location) const
Definition: ReceiverPlan.cc:69
uint32_t decode_i32(const uint8_t **bufp, size_t *remainp)
Decode a 32-bit integer in little-endian order.
void get_range_specs_and_states(vector< QualifiedRangeSpec > &specs, vector< RangeState > &states) const
Definition: ReceiverPlan.cc:94
void encode_i32(uint8_t **bufp, uint32_t val)
Encode a 32-bit integer in little-endian order.
Compatibility Macros for C/C++.
void decode_internal(uint8_t version, const uint8_t **bufp, size_t *remainp) override
Reads serialized representation of object from a buffer.
size_t encoded_length_internal() const override
Returns internal serialized length.
virtual void decode(const uint8_t **bufp, size_t *remainp)
Reads serialized representation of object from a buffer.
Definition: Serializable.cc:70
Hypertable definitions
void remove(const QualifiedRangeSpec &qrs)
Definition: ReceiverPlan.cc:50
void encode_internal(uint8_t **bufp) const override
Writes serialized representation of object to a buffer.
void insert(const String &location, const TableIdentifier &table, const RangeSpec &range, const RangeState &state)
Definition: ReceiverPlan.cc:39
Qualified (with table identifier) range specification.
Range state.
Definition: RangeState.h:48
void get_locations(StringSet &locations) const
Definition: ReceiverPlan.cc:58
bool get_range_spec(const TableIdentifier &table, const char *row, QualifiedRangeSpec &spec) const
RangeServer recovery receiver plan.
Definition: ReceiverPlan.h:48