0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
TableScanner.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 "Table.h"
25 #include "TableScanner.h"
26 #include "TableScannerQueue.h"
27 
28 #include <Common/Error.h>
29 #include <Common/String.h>
30 
31 #include <vector>
32 
33 using namespace Hypertable;
34 
36  RangeLocatorPtr &range_locator, const ScanSpec &scan_spec,
37  uint32_t timeout_ms)
38  : m_callback(this), m_cur_cells(0), m_cur_cells_index(0), m_cur_cells_size(0),
39  m_error(Error::OK), m_eos(false) {
40 
41  m_queue = make_shared<TableScannerQueue>();
43  m_scanner =
44  make_shared<TableScannerAsync>(comm, app_queue, table, range_locator,
45  scan_spec, timeout_ms, &m_callback);
46 }
47 
48 
49 bool TableScanner::next(Cell &cell) {
50 
51  if (m_ungot.row_key) {
52  cell = m_ungot;
53  m_ungot.row_key = 0;
54  return true;
55  }
56 
57  if (m_eos)
58  return false;
59 
60  while (true) {
61 
62  // serve out ready results
64  m_cur_cells->get_cell_unchecked(cell, m_cur_cells_index);
66  return true;
67  }
68 
69  if (m_cur_cells != 0) {
70  m_eos = m_cur_cells->get_eos();
71  if (m_eos) {
72  return false;
73  }
74  }
75 
76  m_queue->next_result(m_cur_cells, &m_error, m_error_msg);
77  if (m_error != Error::OK) {
78  m_eos = true;
80  }
81 
82  m_cur_cells_size = m_cur_cells->size();
84  }
85 }
86 
87 void TableScanner::unget(const Cell &cell) {
88  if (m_ungot.row_key)
90 
91  m_ungot = cell;
92 }
93 
95  m_queue->add_cells(cells);
96 }
97 
98 void TableScanner::scan_error(int error, const string &error_msg) {
99  m_queue->set_error(error, error_msg);
100 }
101 
103  Cell cell;
104 
105  while (scanner.next(cell))
106  b.add(cell);
107 }
TableScannerAsyncPtr m_scanner
Definition: TableScanner.h:112
std::shared_ptr< RangeLocator > RangeLocatorPtr
Smart pointer to RangeLocator.
Definition: RangeLocator.h:198
TableScannerQueuePtr m_queue
Definition: TableScanner.h:111
void unget(const Cell &cell)
Ungets one cell.
Definition: TableScanner.cc:87
Scan predicate and control specification.
Definition: ScanSpec.h:56
Represents an open table.
Definition: Table.h:58
std::shared_ptr< ScanCells > ScanCellsPtr
Smart pointer to ScanCells.
Definition: ScanCells.h:143
bool next(Cell &cell)
Gets the next cell.
Definition: TableScanner.cc:49
Compatibility Macros for C/C++.
const char * row_key
Definition: Cell.h:66
std::shared_ptr< ApplicationQueueInterface > ApplicationQueueInterfacePtr
Smart pointer to ApplicationQueueInterface.
Synchronous table scanner.
Definition: TableScanner.h:39
#define HT_THROW_(_code_)
Definition: Error.h:481
Hypertable definitions
void copy(TableDumper &, CellsBuilder &)
Definition: TableDumper.cc:129
Entry point to AsyncComm service.
Definition: Comm.h:61
TableScanner(Comm *comm, Table *table, RangeLocatorPtr &range_locator, const ScanSpec &scan_spec, uint32_t timeout_ms)
Constructor.
Definition: TableScanner.cc:35
A String class based on std::string.
void add(const Cell &cell, bool own=true)
Definition: Cells.h:69
Encapsulates decomposed key and value.
Definition: Cell.h:32
void scan_error(int error, const std::string &error_msg)
Callback for scan errors.
Definition: TableScanner.cc:98
TableCallback m_callback
Definition: TableScanner.h:110
Error codes, Exception handling, error logging.
#define HT_THROW(_code_, _msg_)
Definition: Error.h:478
void scan_ok(ScanCellsPtr &cells)
Callback for successful scan.
Definition: TableScanner.cc:94