0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
TableScannerAsync.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_Lib_TableScannerAsync_h
23 #define Hypertable_Lib_TableScannerAsync_h
24 
25 #include <Hypertable/Lib/Cells.h>
32 #include <Hypertable/Lib/Schema.h>
34 #include <Hypertable/Lib/Table.h>
35 
37 
38 #include <condition_variable>
39 #include <mutex>
40 #include <vector>
41 
42 namespace Hypertable {
43 
44  class Table;
45 
48 
51 
52  public:
66  TableScannerAsync(Comm *comm, ApplicationQueueInterfacePtr &app_queue, Table *table,
67  RangeLocatorPtr &range_locator,
68  const ScanSpec &scan_spec, uint32_t timeout_ms,
69  ResultCallback *cb, int flags = 0);
70 
71  virtual ~TableScannerAsync();
72 
76  void cancel();
77 
78  bool is_cancelled();
79 
83  bool is_complete() {
84  std::unique_lock<std::mutex> lock(m_mutex);
85  return m_outstanding == 0;
86  }
87 
94  void handle_result(int scanner_id, EventPtr &event, bool is_create);
95 
104  void handle_error(int scanner_id, int error, const std::string &error_msg, bool is_create);
105 
113  void handle_timeout(int scanner_id, const std::string &error_msg, bool is_create);
114 
120  int64_t bytes_scanned() { return m_bytes_scanned; }
121 
125  std::string get_table_name() const;
126 
130  Table *get_table() {return m_table; }
131 
135  void get_profile_data(ProfileDataScanner &profile_data) {
136  std::unique_lock<std::mutex> lock(m_mutex);
137  profile_data = m_profile_data;
138  }
139 
140  private:
141  friend class IndexScannerCallback;
142 
143  void init(Comm *comm, ApplicationQueueInterfacePtr &app_queue, Table *table,
144  RangeLocatorPtr &range_locator, const ScanSpec &scan_spec,
145  uint32_t timeout_ms, ResultCallback *cb);
146  void maybe_callback_ok(int scanner_id, bool next,
147  bool do_callback, ScanCellsPtr &cells);
148  void maybe_callback_error(int scanner_id, bool next);
149  void wait_for_completion();
150  void move_to_next_interval_scanner(int current_scanner);
151  bool use_index(Table *table, const ScanSpec &primary_spec,
152  ScanSpecBuilder &index_spec,
153  std::vector<CellPredicate> &cell_predicates,
154  bool *use_qualifier, bool *row_intervals_applied);
155  void transform_primary_scan_spec(ScanSpecBuilder &primary_spec);
156  void add_index_row(ScanSpecBuilder &ssb, const char *row);
157 
158  std::vector<IntervalScannerAsyncPtr> m_interval_scanners;
159  uint32_t m_timeout_ms;
161  typedef std::set<const char *, LtCstr> CstrRowSet;
162  CstrRowSet m_rowset;
168  std::condition_variable m_cond;
170  int m_error;
171  std::string m_error_msg;
175  };
176 
178  typedef std::shared_ptr<TableScannerAsync> TableScannerAsyncPtr;
179 
181 
182 } // namespace Hypertable
183 
184 #endif // Hypertable_Lib_TableScannerAsync_h
static std::mutex mutex
Definition: Logger.cc:43
std::string get_table_name() const
Returns the name of the table as it was when the scanner was created.
std::shared_ptr< TableScannerAsync > TableScannerAsyncPtr
Smart pointer to TableScannerAsync.
void handle_error(int scanner_id, int error, const std::string &error_msg, bool is_create)
Deal with errors.
std::shared_ptr< RangeLocator > RangeLocatorPtr
Smart pointer to RangeLocator.
Definition: RangeLocator.h:198
void init(Comm *comm, ApplicationQueueInterfacePtr &app_queue, Table *table, RangeLocatorPtr &range_locator, const ScanSpec &scan_spec, uint32_t timeout_ms, ResultCallback *cb)
Asynchronous table scanner.
void move_to_next_interval_scanner(int current_scanner)
void handle_timeout(int scanner_id, const std::string &error_msg, bool is_create)
Deal with timeouts.
std::condition_variable m_cond
std::shared_ptr< Event > EventPtr
Smart pointer to Event.
Definition: Event.h:228
Declarations for Schema.
Scan predicate and control specification.
Definition: ScanSpec.h:56
Represents an open table.
Definition: Table.h:58
int64_t bytes_scanned()
Returns number of bytes scanned.
std::shared_ptr< ScanCells > ScanCellsPtr
Smart pointer to ScanCells.
Definition: ScanCells.h:143
Declarations for ProfileDataScanner.
bool use_index(Table *table, const ScanSpec &primary_spec, ScanSpecBuilder &index_spec, std::vector< CellPredicate > &cell_predicates, bool *use_qualifier, bool *row_intervals_applied)
void maybe_callback_error(int scanner_id, bool next)
Declarations for ClientObject.
std::shared_ptr< ApplicationQueueInterface > ApplicationQueueInterfacePtr
Smart pointer to ApplicationQueueInterface.
Helper class for building a ScanSpec.
Definition: ScanSpec.h:318
Declarations for CellPredicate.
std::set< const char *, LtCstr > CstrRowSet
Base class for Hypertable client objects.
Definition: ClientObject.h:44
Hypertable definitions
Entry point to AsyncComm service.
Definition: Comm.h:61
TableScannerAsync(Comm *comm, ApplicationQueueInterfacePtr &app_queue, Table *table, RangeLocatorPtr &range_locator, const ScanSpec &scan_spec, uint32_t timeout_ms, ResultCallback *cb, int flags=0)
Constructs a TableScannerAsync object.
void cancel()
Cancels the scanner.
void handle_result(int scanner_id, EventPtr &event, bool is_create)
Deal with results of a scanner.
Table * get_table()
Returns a pointer to the table.
void maybe_callback_ok(int scanner_id, bool next, bool do_callback, ScanCellsPtr &cells)
Declarations for ScanBlock.
ResultCallback for secondary indices; used by TableScannerAsync.
std::vector< IntervalScannerAsyncPtr > m_interval_scanners
Represents an open table.
void get_profile_data(ProfileDataScanner &profile_data)
Gets profile data.
void transform_primary_scan_spec(ScanSpecBuilder &primary_spec)
Declarations for DispatchHandlerSynchronizer.
void add_index_row(ScanSpecBuilder &ssb, const char *row)