0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Key.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 
22 #ifndef HYPERTABLE_KEY_H
23 #define HYPERTABLE_KEY_H
24 
25 #include <iostream>
26 
27 #include <boost/shared_array.hpp>
28 #include <boost/detail/endian.hpp>
29 
30 #include "Common/ByteString.h"
31 #include "Common/DynamicBuffer.h"
32 
33 #include "KeySpec.h"
34 #include "SerializedKey.h"
35 
36 
37 namespace Hypertable {
40  class Key {
41  public:
42 
43  static const uint8_t HAVE_REVISION = 0x80;
44  static const uint8_t HAVE_TIMESTAMP = 0x40;
45  static const uint8_t AUTO_TIMESTAMP = 0x20;
46  static const uint8_t REV_IS_TS = 0x10;
47  static const uint8_t TS_CHRONOLOGICAL = 0x1;
48 
49  static const char *END_ROW_MARKER;
50  static const char *END_ROOT_ROW;
51 
52  static inline void encode_ts64(uint8_t **bufp, int64_t val,
53  bool ascending=true) {
54  if (ascending)
55  val = ~val;
56 #ifdef HT_LITTLE_ENDIAN
57  *(*bufp)++ = (uint8_t)(val >> 56);
58  *(*bufp)++ = (uint8_t)(val >> 48);
59  *(*bufp)++ = (uint8_t)(val >> 40);
60  *(*bufp)++ = (uint8_t)(val >> 32);
61  *(*bufp)++ = (uint8_t)(val >> 24);
62  *(*bufp)++ = (uint8_t)(val >> 16);
63  *(*bufp)++ = (uint8_t)(val >> 8);
64  *(*bufp)++ = (uint8_t)val;
65 #else
66  memcpy(*bufp, &val, 8);
67  *bufp += 8;
68 #endif
69  }
70 
71  static inline int64_t decode_ts64(const uint8_t **bufp,
72  bool ascending=true) {
73  int64_t val;
74 #ifdef HT_LITTLE_ENDIAN
75  val = ((int64_t)*(*bufp)++ << 56);
76  val |= ((int64_t)(*(*bufp)++) << 48);
77  val |= ((int64_t)(*(*bufp)++) << 40);
78  val |= ((int64_t)(*(*bufp)++) << 32);
79  val |= ((int64_t)(*(*bufp)++) << 24);
80  val |= (*(*bufp)++ << 16);
81  val |= (*(*bufp)++ << 8);
82  val |= *(*bufp)++;
83 #else
84  memcpy(&val, *bufp, 8);
85  *bufp += 8;
86 #endif
87  return (ascending ? ~val : val);
88  }
89 
96 
103  Key(const SerializedKey& key);
104 
111  bool load(const SerializedKey& key);
112 
113  size_t len_row() const { return row_len; }
114 
115  size_t len_column_family() const {
116  return(column_qualifier - row);
117  }
118 
119  size_t len_cell() const {
121  }
122 
124  uint32_t length; // length of serialized key
125  uint8_t flag;
126  uint8_t control;
129  const char *row;
130  const char *column_qualifier;
131  uint32_t row_len; // excluding null byte
132  uint32_t column_qualifier_len; // ditto
133  const uint8_t *flag_ptr;
134  int64_t timestamp;
135  int64_t revision;
136  };
137 
138 
146  std::ostream &operator<<(std::ostream &os, const Key &key);
147 
151  inline std::ostream &
152  operator<<(std::ostream &os, const SerializedKey &serkey) {
153  Key key(serkey);
154  os << key;
155  return os;
156  }
157 
158  void create_key_and_append(DynamicBuffer &dst_buf, const char *row,
159  bool time_order_asc = true);
160 
161  void create_key_and_append(DynamicBuffer &dst_buf, uint8_t flag,
162  const char *row, uint8_t column_family_code,
163  const char *column_qualifier,
164  int64_t timestamp = AUTO_ASSIGN,
165  int64_t revision = AUTO_ASSIGN,
166  bool time_order_asc = true);
167 
168  void create_key_and_append(DynamicBuffer &dst_buf, const Key& key,
169  bool time_order_asc = true);
170 
171 } // namespace Hypertable
172 
173 #endif // HYPERTABLE_KEY_H
static int64_t decode_ts64(const uint8_t **bufp, bool ascending=true)
Definition: Key.h:71
int64_t timestamp
Definition: Key.h:134
const char * row
Definition: Key.h:129
uint8_t control
Definition: Key.h:126
uint32_t length
Definition: Key.h:124
static const uint32_t FLAG_INSERT
Definition: KeySpec.h:47
static const uint8_t HAVE_REVISION
Definition: Key.h:43
uint32_t row_len
Definition: Key.h:131
const uint8_t * flag_ptr
Definition: Key.h:133
A dynamic, resizable memory buffer.
Key()
Constructor (for implicit construction).
Definition: Key.h:93
static const uint8_t HAVE_TIMESTAMP
Definition: Key.h:44
std::ostream & operator<<(std::ostream &os, const crontab_entry &entry)
Helper function to write crontab_entry to an ostream.
Definition: Crontab.cc:301
bool load(const SerializedKey &key)
Parses the opaque key and loads the components into the member variables.
Definition: Key.cc:158
static const uint8_t TS_CHRONOLOGICAL
Definition: Key.h:47
Hypertable definitions
SerializedKey serial
Definition: Key.h:123
static const uint8_t AUTO_TIMESTAMP
Definition: Key.h:45
void create_key_and_append(DynamicBuffer &dst_buf, const Key &key, bool time_order_asc)
Definition: Key.cc:105
size_t len_column_family() const
Definition: Key.h:115
Provides access to internal components of opaque key.
Definition: Key.h:40
uint32_t column_qualifier_len
Definition: Key.h:132
static void encode_ts64(uint8_t **bufp, int64_t val, bool ascending=true)
Definition: Key.h:52
bool row_key_set
Definition: Key.h:128
static const char * END_ROOT_ROW
Definition: Key.h:50
A serializable ByteString.
int64_t revision
Definition: Key.h:135
uint8_t column_family_code
Definition: Key.h:127
static const int64_t AUTO_ASSIGN
Definition: KeySpec.h:38
uint8_t flag
Definition: Key.h:125
size_t len_row() const
Definition: Key.h:113
size_t len_cell() const
Definition: Key.h:119
const char * column_qualifier
Definition: Key.h:130
static const char * END_ROW_MARKER
Definition: Key.h:49
static const uint8_t REV_IS_TS
Definition: Key.h:46