0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
LegacyDecoder.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 
22 #include <Common/Compat.h>
23 
24 #include "LegacyDecoder.h"
25 
26 #include <Common/Error.h>
27 #include <Common/Logger.h>
28 #include <Common/Serialization.h>
29 
30 using namespace Hypertable;
32 
33 void Hypertable::legacy_decode(const uint8_t **bufp, size_t *remainp, BalancePlan *plan) {
34  plan->algorithm = Serialization::decode_vstr(bufp, remainp);
35  size_t length = Serialization::decode_i32(bufp, remainp);
36  plan->moves.reserve(length);
37  for (size_t i=0; i<length; i++) {
38  RangeMoveSpecPtr move_spec = make_shared<RangeMoveSpec>();
39  legacy_decode(bufp, remainp, move_spec.get());
40  plan->moves.push_back(move_spec);
41  }
42  plan->duration_millis = Serialization::decode_i32(bufp, remainp);
43 }
44 
45 #define TABLE_IDENTIFIER_VERSION 2
46 
47 void Hypertable::legacy_decode(const uint8_t **bufp, size_t *remainp, TableIdentifier *tid) {
48  int16_t version;
49  HT_TRY("decoding table identitier version",
50  version = Serialization::decode_i16(bufp, remainp));
51  if (version != TABLE_IDENTIFIER_VERSION) {
52  *bufp -= 2;
53  *remainp += 2;
54  HT_TRY("decoding table identitier",
55  tid->id = Serialization::decode_vstr(bufp, remainp);
56  tid->generation = Serialization::decode_i32(bufp, remainp));
57  }
58  else {
59  HT_TRY("decoding table identitier",
60  tid->id = Serialization::decode_vstr(bufp, remainp);
61  tid->generation = Serialization::decode_i64(bufp, remainp));
62  }
63 }
64 
65 void Hypertable::legacy_decode(const uint8_t **bufp, size_t *remainp, TableIdentifierManaged *tid) {
66  legacy_decode(bufp, remainp, (TableIdentifier *)tid);
67  *tid = *tid;
68 }
69 
70 void Hypertable::legacy_decode(const uint8_t **bufp, size_t *remainp, RangeSpec *spec) {
71  HT_TRY("decoding range spec",
72  spec->start_row = Serialization::decode_vstr(bufp, remainp);
73  spec->end_row = Serialization::decode_vstr(bufp, remainp));
74 }
75 
76 void Hypertable::legacy_decode(const uint8_t **bufp, size_t *remainp, RangeSpecManaged *spec) {
77  legacy_decode(bufp, remainp, (RangeSpec *)spec);
78  *spec = *spec;
79 }
80 
81 void Hypertable::legacy_decode(const uint8_t **bufp, size_t *remainp, QualifiedRangeSpec *spec) {
82  legacy_decode(bufp, remainp, &spec->table);
83  legacy_decode(bufp, remainp, &spec->range);
84 }
85 
86 void Hypertable::legacy_decode(const uint8_t **bufp, size_t *remainp, RangeMoveSpec *spec) {
87  TableIdentifier table;
88  legacy_decode(bufp, remainp, &table);
89  spec->table = table;
90  RangeSpec range;
91  legacy_decode(bufp, remainp, &range);
92  spec->range = range;
93  spec->source_location = Serialization::decode_vstr(bufp, remainp);
94  spec->dest_location = Serialization::decode_vstr(bufp, remainp);
95  spec->error = Serialization::decode_i32(bufp, remainp);
96  spec->complete = Serialization::decode_bool(bufp, remainp);
97 }
98 
99 #define RANGESTATE_VERSION 100
100 
101 void Hypertable::legacy_decode(const uint8_t **bufp, size_t *remainp, RangeState *state) {
102  uint8_t version;
103  try {
104  version = Serialization::decode_byte(bufp, remainp);
105  if (version == RANGESTATE_VERSION)
106  state->state = Serialization::decode_byte(bufp, remainp);
107  else
108  state->state = version;
109  state->timestamp = Serialization::decode_i64(bufp, remainp);
110  state->soft_limit = Serialization::decode_i64(bufp, remainp);
111  state->transfer_log = Serialization::decode_vstr(bufp, remainp);
112  state->split_point = Serialization::decode_vstr(bufp, remainp);
113  state->old_boundary_row = Serialization::decode_vstr(bufp, remainp);
114  if (version == RANGESTATE_VERSION)
115  state->source = Serialization::decode_vstr(bufp, remainp);
116  }
117  HT_RETHROW("decoding range state")
118 }
119 
120 void Hypertable::legacy_decode(const uint8_t **bufp, size_t *remainp, RangeStateManaged *state) {
121  legacy_decode(bufp, remainp, (RangeState *)state);
122  *state = *state;
123 }
124 
125 void Hypertable::legacy_decode(const uint8_t **bufp, size_t *remainp, FragmentReplayPlan *plan) {
126  plan->location = Serialization::decode_vstr(bufp, remainp);
127  plan->fragment = Serialization::decode_i32(bufp, remainp);
128 }
129 
130 void Hypertable::legacy_decode(const uint8_t **bufp, size_t *remainp, ReplayPlan *plan) {
131  size_t count = Serialization::decode_i32(bufp, remainp);
132  for (size_t i=0; i<count; ++i) {
133  FragmentReplayPlan entry;
134  legacy_decode(bufp, remainp, &entry);
135  plan->container.insert(entry);
136  }
137 }
138 
139 void Hypertable::legacy_decode(const uint8_t **bufp, size_t *remainp, ServerReceiverPlan *plan) {
140  plan->location = Serialization::decode_vstr(bufp, remainp);
141  legacy_decode(bufp, remainp, &plan->spec);
142  legacy_decode(bufp, remainp, &plan->state);
143 }
144 
145 void Hypertable::legacy_decode(const uint8_t **bufp, size_t *remainp, ReceiverPlan *plan) {
146  size_t count = Serialization::decode_i32(bufp, remainp);
147  for (size_t i = 0; i<count; ++i) {
148  ServerReceiverPlan tmp;
149  legacy_decode(bufp, remainp, &tmp);
150  ServerReceiverPlan entry(plan->arena, tmp.location, tmp.spec.table,
151  tmp.spec.range, tmp.state);
152  plan->container.insert(entry);
153  }
154 }
155 
156 void Hypertable::legacy_decode(const uint8_t **bufp, size_t *remainp, Plan *plan) {
157  plan->type = Serialization::decode_i32(bufp, remainp);
158  legacy_decode(bufp, remainp, &plan->replay_plan);
159  legacy_decode(bufp, remainp, &plan->receiver_plan);
160 }
#define HT_RETHROW(_s_)
Definition: Error.h:514
char * decode_vstr(const uint8_t **bufp, size_t *remainp)
Decode a vstr (vint64, data, null).
TableIdentifierManaged table
Definition: RangeMoveSpec.h:68
#define RANGESTATE_VERSION
Range specification.
Definition: RangeSpec.h:40
Balance plan.
Definition: BalancePlan.h:38
uint64_t soft_limit
Soft split size limit.
Definition: RangeState.h:108
FragmentReplayPlanContainer container
Container holding fragment replay plans.
Definition: ReplayPlan.h:112
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
uint32_t decode_i32(const uint8_t **bufp, size_t *remainp)
Decode a 32-bit integer in little-endian order.
RangeServer recovery plan.
Definition: Plan.h:49
Range move specification.
Definition: RangeMoveSpec.h:43
Wrapper for TableIdentifier providing member storage.
ReplayPlan replay_plan
Replay plan.
Definition: Plan.h:70
uint64_t decode_i64(const uint8_t **bufp, size_t *remainp)
Decode a 64-bit integer in little-endian order.
const char * end_row
Definition: RangeSpec.h:60
bool decode_bool(const uint8_t **bufp, size_t *remainp)
Decodes a boolean value from the given buffer.
Definition: Serialization.h:96
uint16_t decode_i16(const uint8_t **bufp, size_t *remainp)
Decode a 16-bit integer in little-endian order.
RangeSpecManaged range
Definition: RangeMoveSpec.h:69
Logging routines and macros.
Compatibility Macros for C/C++.
const char * transfer_log
Full pathname of transfer log.
Definition: RangeState.h:111
uint8_t state
Range state value (see StateType)
Definition: RangeState.h:102
Functions to serialize/deserialize primitives to/from a memory buffer.
#define TABLE_IDENTIFIER_VERSION
int64_t timestamp
Timestamp
Definition: RangeState.h:105
Hypertable definitions
void legacy_decode(const uint8_t **bufp, size_t *remainp, BalancePlan *plan)
const char * start_row
Definition: RangeSpec.h:59
std::vector< RangeMoveSpecPtr > moves
Definition: BalancePlan.h:51
const char * split_point
Split point (row key)
Definition: RangeState.h:114
Qualified (with table identifier) range specification.
std::shared_ptr< RangeMoveSpec > RangeMoveSpecPtr
Range state.
Definition: RangeState.h:48
ReceiverPlan receiver_plan
Receiver plan.
Definition: Plan.h:73
#define HT_TRY(_s_, _code_)
Definition: Error.h:517
uint8_t decode_byte(const uint8_t **bufp, size_t *remainp)
Decodes a single byte from the given buffer.
Definition: Serialization.h:73
Error codes, Exception handling, error logging.
Wrapper for RangeSpec providing member storage.
Definition: RangeSpec.h:89
Holds a fragment replay plan for the recovery of a RangeServer.
Definition: ReplayPlan.h:53
Range state with memory management.
Definition: RangeState.h:166
RangeServer recovery receiver plan.
Definition: ReceiverPlan.h:48