0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
CellStoreScanner.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 
26 
27 #include <Common/Compat.h>
28 #include "CellStoreScanner.h"
29 
34 
36 
37 #include <Common/Error.h>
38 #include <Common/System.h>
39 
40 using namespace Hypertable;
41 using namespace std;
42 
43 template <typename IndexT>
45  CellListScanner(scan_ctx), m_cellstore(cellstore), m_decrement_blockindex_refcount(index!=0) {
46  SerializedKey start_key, end_key;
47 
48  m_keys_only = (scan_ctx->spec) ? (scan_ctx->spec->keys_only && !scan_ctx->spec->value_regexp) : false;
49 
50  if (scan_ctx->has_cell_interval) {
51 
52  // maybe assert that there isn't more restrictive cellstore start/end row ?
53 
54  m_key_buf.grow(4*(scan_ctx->start_key.row_len +
55  scan_ctx->start_key.column_qualifier_len + 32));
56 
60  start_key.ptr = m_key_buf.ptr;
62  0, "", TIMESTAMP_MAX, scan_ctx->revision);
63 
64  end_key.ptr = m_key_buf.ptr;
66  scan_ctx->start_key.row, 0, "", TIMESTAMP_MAX,
67  scan_ctx->revision);
68 
70  make_unique<CellStoreScannerIntervalBlockIndex<IndexT>>(cellstore, index,
71  start_key, end_key,
72  scan_ctx);
73 
77  start_key.ptr = m_key_buf.ptr;
79  scan_ctx->start_key.row,
80  scan_ctx->start_key.column_family_code,
81  "", TIMESTAMP_MAX, scan_ctx->revision);
82 
83  end_key.ptr = m_key_buf.ptr;
85  scan_ctx->start_key.row,
86  scan_ctx->start_key.column_family_code,
87  "", TIMESTAMP_MAX, scan_ctx->revision);
88 
90  make_unique<CellStoreScannerIntervalBlockIndex<IndexT>>(cellstore, index,
91  start_key, end_key,
92  scan_ctx);
93 
94  if (strcmp(scan_ctx->end_key.row, cellstore->get_end_row()) > 0)
95  end_key.ptr = 0;
96  else
97  end_key.ptr = scan_ctx->end_serkey.ptr;
98 
99  if (scan_ctx->single_row)
100  m_interval_scanners[m_interval_max++] = make_unique<CellStoreScannerIntervalBlockIndex<IndexT>>(cellstore, index, scan_ctx->start_serkey, end_key, scan_ctx);
101  else
102  m_interval_scanners[m_interval_max++] = make_unique<CellStoreScannerIntervalReadahead<IndexT>>(cellstore, index, scan_ctx->start_serkey, scan_ctx->end_serkey, scan_ctx);
103  }
104  else {
105  String tmp_str;
106  bool readahead = false;
107  size_t buf_needed = 128 + strlen(cellstore->get_start_row()) + strlen(cellstore->get_end_row());
108 
109  m_key_buf.grow(buf_needed);
110 
111  if (strcmp(scan_ctx->start_key.row, cellstore->get_start_row()) < 0) {
112  tmp_str = cellstore->get_start_row();
113  if (tmp_str.length() > 0)
114  tmp_str.append(1, 1);
115  create_key_and_append(m_key_buf, 0, tmp_str.c_str(), 0, "", TIMESTAMP_MAX, 0);
116  start_key.ptr = m_key_buf.base;
117  readahead = true;
118  }
119  else {
120  start_key.ptr = scan_ctx->start_serkey.ptr;
121  readahead = scan_ctx->start_key.row_len == 0;
122  }
123 
124  if (strcmp(scan_ctx->end_key.row, cellstore->get_end_row()) > 0) {
125  end_key.ptr = m_key_buf.ptr;
126  tmp_str = cellstore->get_end_row();
127  tmp_str.append(1, 1);
128  create_key_and_append(m_key_buf, 0, tmp_str.c_str(), 0, "", TIMESTAMP_MAX, 0);
129  readahead = true;
130  }
131  else {
132  end_key.ptr = scan_ctx->end_serkey.ptr;
133  // if !readahead then readahead if scan_ctx->end_key.row == END_ROW_MARKER
134  readahead = readahead || (!strcmp(scan_ctx->end_key.row, Key::END_ROW_MARKER));
135  }
136 
137  // dont do readahead for single row scans
138  if (scan_ctx->single_row)
139  readahead = false;
140 
141  if (readahead)
142  m_interval_scanners[m_interval_max++] = make_unique<CellStoreScannerIntervalReadahead<IndexT>>(cellstore, index, start_key, end_key, scan_ctx);
143  else {
144  HT_ASSERT(index);
145  m_interval_scanners[m_interval_max++] = make_unique<CellStoreScannerIntervalBlockIndex<IndexT>>(cellstore, index, start_key, end_key, scan_ctx);
146  }
147  }
148 }
149 
150 
151 
152 template <typename IndexT>
154  if (m_decrement_blockindex_refcount)
155  m_cellstore->decrement_index_refcount();
156 }
157 
158 
159 
160 template <typename IndexT>
162 
163  if (m_eos)
164  return false;
165 
166  if (m_interval_scanners[m_interval_index]->get(key, value)) {
167  if (m_keys_only)
168  value = 0;
169  return true;
170  }
171 
172  m_interval_index++;
173 
174  while (m_interval_index < m_interval_max) {
175  if (m_interval_scanners[m_interval_index]->get(key, value)) {
176  if (m_keys_only)
177  value = 0;
178  return true;
179  }
180  m_interval_index++;
181  }
182 
183  m_eos = true;
184  return false;
185 }
186 
187 template <typename IndexT>
189  int64_t amount = 0;
190  for (size_t i=0; i<m_interval_max; i++)
191  amount += m_interval_scanners[i]->get_disk_read();
192  return amount;
193 }
194 
195 
196 
197 template <typename IndexT>
199  if (m_eos)
200  return;
201  m_interval_scanners[m_interval_index]->forward();
202 }
203 
204 namespace Hypertable {
207 }
Retrieves system information (hardware, installation directory, etc)
SerializedKey start_serkey
Definition: ScanContext.h:60
CellStoreScanner(CellStorePtr &&cellstore, ScanContext *scan_ctx, IndexT *indexp=0)
std::unique_ptr< CellStoreScannerInterval > m_interval_scanners[3]
const char * row
Definition: Key.h:129
Provides the ability to scan over (query) a cell store.
static const uint32_t FLAG_DELETE_ROW
Definition: KeySpec.h:40
std::string String
A String is simply a typedef to std::string.
Definition: String.h:44
Declarations for CellStoreScannerIntervalBlockIndex.
const char * value_regexp
Definition: ScanSpec.h:280
Declarations for CellStoreScanner.
static const uint32_t FLAG_DELETE_CELL
Definition: KeySpec.h:42
STL namespace.
Scan context information.
Definition: ScanContext.h:52
Declarations for CellStoreScannerIntervalReadahead.
Declarations for BlockHeader.
uint8_t * ptr
Pointer to the end of the used part of the buffer.
static const uint32_t FLAG_DELETE_COLUMN_FAMILY
Definition: KeySpec.h:41
A class managing one or more serializable ByteStrings.
Definition: ByteString.h:47
#define HT_ASSERT(_e_)
Definition: Logger.h:396
uint32_t row_len
Definition: Key.h:131
const ScanSpec * spec
Definition: ScanContext.h:55
void grow(size_t new_size, bool nocopy=false)
Grows the buffer and copies the data unless nocopy is true.
Compatibility Macros for C/C++.
bool get(Key &key, ByteString &value) override
int64_t get_disk_read() override
SerializedKey end_serkey
Definition: ScanContext.h:60
const uint8_t * ptr
The pointer to the serialized data.
Definition: ByteString.h:121
std::shared_ptr< CellStore > CellStorePtr
Smart pointer to CellStore.
Definition: CellStore.h:340
Hypertable definitions
void create_key_and_append(DynamicBuffer &dst_buf, const Key &key, bool time_order_asc)
Definition: Key.cc:105
static const int64_t TIMESTAMP_MAX
Definition: KeySpec.h:35
Provides access to internal components of opaque key.
Definition: Key.h:40
uint32_t column_qualifier_len
Definition: Key.h:132
uint8_t * base
Pointer to the allocated memory buffer.
uint8_t column_family_code
Definition: Key.h:127
Error codes, Exception handling, error logging.
static const char * END_ROW_MARKER
Definition: Key.h:49
Declarations for CellStoreBlockIndexArray.