0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
RangeState.cc
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 #include <Common/Compat.h>
29 
30 #include "RangeState.h"
31 
32 #include <Common/Logger.h>
33 #include <Common/Serialization.h>
34 
35 #include <string>
36 
37 using namespace Hypertable;
38 using namespace Serialization;
39 using namespace std;
40 
42  state = STEADY;
43  // timestmp shouldn't be cleared
44  soft_limit = 0;
45  transfer_log = split_point = old_boundary_row = source = 0;
46 }
47 
48 String RangeState::get_text(uint8_t state) {
49  string str;
50  switch (state & ~RangeState::PHANTOM) {
51  case RangeState::STEADY:
52  str = "STEADY";
53  break;
55  str = "SPLIT_LOG_INSTALLED";
56  break;
58  str = "SPLIT_SHRUNK";
59  break;
61  str = "RELINQUISH_LOG_INSTALLED";
62  break;
64  str = "RELINQUISH_COMPACTED";
65  break;
66  default:
67  str = format("UNKNOWN(%d)", (int)state);
68  }
69 
70  if (state & RangeState::PHANTOM)
71  str += String("|PHANTOM");
72  return str;
73 }
74 
75 
77  return 1;
78 }
79 
81  return 17 + Serialization::encoded_length_vstr(transfer_log) +
83  Serialization::encoded_length_vstr(old_boundary_row) +
85 }
86 
123 void RangeState::encode_internal(uint8_t **bufp) const {
124  Serialization::encode_i8(bufp, state);
125  Serialization::encode_i64(bufp, timestamp);
126  Serialization::encode_i64(bufp, soft_limit);
127  Serialization::encode_vstr(bufp, transfer_log);
128  Serialization::encode_vstr(bufp, split_point);
129  Serialization::encode_vstr(bufp, old_boundary_row);
130  Serialization::encode_vstr(bufp, source);
131 }
132 
133 void RangeState::decode_internal(uint8_t version, const uint8_t **bufp,
134  size_t *remainp) {
135  state = Serialization::decode_i8(bufp, remainp);
136  timestamp = Serialization::decode_i64(bufp, remainp);
137  soft_limit = Serialization::decode_i64(bufp, remainp);
138  transfer_log = Serialization::decode_vstr(bufp, remainp);
139  split_point = Serialization::decode_vstr(bufp, remainp);
140  old_boundary_row = Serialization::decode_vstr(bufp, remainp);
141  source = Serialization::decode_vstr(bufp, remainp);
142 }
143 
144 std::ostream& Hypertable::operator<<(std::ostream &out, const RangeState &st) {
145  out <<"{RangeState: state=" << RangeState::get_text(st.state);
146  out << " timestamp=" << st.timestamp;
147  out <<" soft_limit="<< st.soft_limit;
148  if (st.transfer_log)
149  out <<" transfer_log='"<< st.transfer_log << "'";
150  if (st.split_point)
151  out <<" split_point='"<< st.split_point << "'";
152  if (st.old_boundary_row)
153  out <<" old_boundary_row='"<< st.old_boundary_row << "'";
154  if (st.source)
155  out <<" source='"<< st.source << "'";
156  out <<"}";
157  return out;
158 }
159 
162  *this = *this;
163 }
164 
165 void RangeStateManaged::decode_internal(uint8_t version, const uint8_t **bufp,
166  size_t *remainp) {
167  RangeState::decode_internal(version, bufp, remainp);
168  *this = *this;
169 }
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
char * decode_vstr(const uint8_t **bufp, size_t *remainp)
Decode a vstr (vint64, data, null).
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
std::string String
A String is simply a typedef to std::string.
Definition: String.h:44
String format(const char *fmt,...)
Returns a String using printf like format facilities Vanilla snprintf is about 1.5x faster than this...
Definition: String.cc:37
Po::typed_value< String > * str(String *v=0)
Definition: Properties.h:166
uint64_t soft_limit
Soft split size limit.
Definition: RangeState.h:108
STL namespace.
size_t encoded_length_vstr(size_t len)
Computes the encoded length of vstr (vint64, data, null)
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
uint8_t decode_i8(const uint8_t **bufp, size_t *remainp)
Decode a 8-bit integer (a byte/character)
Definition: Serialization.h:60
uint64_t decode_i64(const uint8_t **bufp, size_t *remainp)
Decode a 64-bit integer in little-endian order.
uint8_t encoding_version() const override
Returns encoding version.
Definition: RangeState.cc:76
Declarations for RangeState.
Logging routines and macros.
Compatibility Macros for C/C++.
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
uint8_t state
Range state value (see StateType)
Definition: RangeState.h:102
void encode_i64(uint8_t **bufp, uint64_t val)
Encode a 64-bit integer in little-endian order.
Functions to serialize/deserialize primitives to/from a memory buffer.
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
void encode_vstr(uint8_t **bufp, const void *buf, size_t len)
Encode a buffer as variable length string (vint64, data, null)
Hypertable definitions
Relinquish - range compacted.
Definition: RangeState.h:57
Split - range shrunk.
Definition: RangeState.h:55
void clear() override
Clears state.
Definition: RangeState.cc:160
const char * split_point
Split point (row key)
Definition: RangeState.h:114
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 encode_i8(uint8_t **bufp, uint8_t val)
Encodes a byte into the given buffer.
Definition: Serialization.h:49