0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Table.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_Table_h
23 #define Hypertable_Lib_Table_h
24 
28 #include <Hypertable/Lib/Schema.h>
32 
34 
35 #include <mutex>
36 
37 namespace Hyperspace {
38  class Session;
39 }
40 
41 namespace Hypertable {
42 
43  using namespace Lib;
44 
45  class ConnectionManager;
46  class ResultCallback;
47  class TableScannerAsync;
48  class TableScanner;
49  class TableMutator;
50  class TableMutatorAsync;
51  class Namespace;
52 
53  class Table;
54  typedef std::shared_ptr<Table> TablePtr;
55 
58  class Table : public ClientObject {
59 
60  public:
61 
62  enum {
63  OPEN_FLAG_BYPASS_TABLE_CACHE = 0x01,
64  OPEN_FLAG_REFRESH_TABLE_CACHE = 0x02,
65  OPEN_FLAG_NO_AUTO_TABLE_REFRESH = 0x04,
66  SCANNER_FLAG_IGNORE_INDEX = 0x01,
67  SCANNER_FLAG_PROFILE = 0x02
68  };
69 
70  enum {
73  };
74 
77  const std::string &name, int32_t flags = 0, uint32_t default_timeout_ms = 0);
78  virtual ~Table();
79 
90  TableMutator *create_mutator(uint32_t timeout_ms = 0,
91  uint32_t flags = 0,
92  uint32_t flush_interval_ms = 0);
102  TableMutatorAsync *create_mutator_async(ResultCallback *cb,
103  uint32_t timeout_ms = 0,
104  uint32_t flags = 0);
114  TableScanner *create_scanner(const ScanSpec &scan_spec,
115  uint32_t timeout_ms = 0, int32_t flags = 0);
116 
117 
128  TableScannerAsync *create_scanner_async(ResultCallback *cb,
129  const ScanSpec &scan_spec,
130  uint32_t timeout_ms = 0,
131  int32_t flags = 0);
132 
133  void get_identifier(TableIdentifier *table_id_p) {
134  std::lock_guard<std::mutex> lock(m_mutex);
135  refresh_if_required();
136  *table_id_p = m_table;
137  }
138 
139  const std::string& get_name() {
140  std::lock_guard<std::mutex> lock(m_mutex);
141  return m_name;
142  }
143 
145  std::lock_guard<std::mutex> lock(m_mutex);
146  refresh_if_required();
147  return m_schema;
148  }
149 
153  void refresh();
154 
161  void get(TableIdentifierManaged &table_identifier, SchemaPtr &schema);
162 
166  void refresh(TableIdentifierManaged &table_identifier, SchemaPtr &schema);
167 
168  bool need_refresh() {
169  std::lock_guard<std::mutex> lock(m_mutex);
170  return m_stale;
171  }
172 
173  void invalidate() {
174  std::lock_guard<std::mutex> lock(m_mutex);
175  m_stale = true;
176  }
177 
178  bool auto_refresh() {
179  return (m_flags & OPEN_FLAG_NO_AUTO_TABLE_REFRESH) == 0;
180  }
181 
182  int32_t get_flags() { return m_flags; }
183 
186  std::lock_guard<std::mutex> lock(m_mutex);
187  for (auto cf : m_schema->get_column_families()) {
188  if (cf->get_deleted())
189  continue;
190  if (cf->get_value_index())
191  return true;
192  }
193  return false;
194  }
195 
198  std::lock_guard<std::mutex> lock(m_mutex);
199  for (auto cf : m_schema->get_column_families()) {
200  if (cf->get_deleted())
201  continue;
202  if (cf->get_qualifier_index())
203  return true;
204  }
205  return false;
206  }
207 
210  std::lock_guard<std::mutex> lock(m_mutex);
211  return (m_index_table!=0);
212  }
213 
216  std::lock_guard<std::mutex> lock(m_mutex);
217  return (m_qualifier_index_table != 0);
218  }
219 
222  void set_index_table(TablePtr idx) {
223  std::lock_guard<std::mutex> lock(m_mutex);
224  HT_ASSERT(idx != 0 ? m_index_table == 0 : 1);
225  m_index_table = idx;
226  }
227 
229  void set_qualifier_index_table(TablePtr idx) {
230  std::lock_guard<std::mutex> lock(m_mutex);
231  HT_ASSERT(idx != 0 ? m_qualifier_index_table == 0 : 1);
232  m_qualifier_index_table = idx;
233  }
234 
235  TablePtr get_index_table() {
236  return m_index_table;
237  }
238 
240  return m_qualifier_index_table;
241  }
242 
244  m_namespace = ns;
245  }
246 
248  return m_namespace;
249  }
250 
251  RangeLocatorPtr get_range_locator() { return m_range_locator; }
252 
253  private:
254  void initialize();
255  void refresh_if_required();
256 
267  std::string m_name;
269  int32_t m_flags;
271  bool m_stale;
272  std::string m_toplevel_dir;
274  TablePtr m_index_table;
277  };
278 
279 }
280 
281 #endif // Hypertable_Lib_Table_h
static std::mutex mutex
Definition: Logger.cc:43
void initialize(const String &name)
Public initialization function - creates a singleton instance of LogWriter.
Definition: Logger.cc:45
bool has_qualifier_index_table()
returns true if this table has a qualifier index
Definition: Table.h:215
Namespace * get_namespace()
Definition: Table.h:247
bool auto_refresh()
Definition: Table.h:178
ConnectionManagerPtr m_conn_manager
Definition: Table.h:261
Hyperspace::SessionPtr m_hyperspace
Definition: Table.h:262
ApplicationQueueInterfacePtr m_app_queue
Definition: Table.h:265
void set_qualifier_index_table(TablePtr idx)
sets the qualifier index table
Definition: Table.h:229
bool needs_index_table()
returns true if this table requires a index table
Definition: Table.h:185
std::shared_ptr< RangeLocator > RangeLocatorPtr
Smart pointer to RangeLocator.
Definition: RangeLocator.h:198
Asynchronous table scanner.
Establishes and maintains a set of TCP connections.
int32_t m_flags
Definition: Table.h:269
Declarations for TableIdentifier and TableIdentifierManaged.
NameIdMapperPtr m_namemap
Definition: Table.h:266
TablePtr m_index_table
Definition: Table.h:274
TableIdentifierManaged m_table
Definition: Table.h:268
int32_t get_flags()
Definition: Table.h:182
bool need_refresh()
Definition: Table.h:168
bool needs_qualifier_index_table()
returns true if this table requires a qualifier index table
Definition: Table.h:197
RangeLocatorPtr get_range_locator()
Definition: Table.h:251
Declarations for Schema.
PropertiesPtr m_props
Definition: Table.h:259
Hyperspace definitions
#define HT_ASSERT(_e_)
Definition: Logger.h:396
Provides the ability to mutate a table in the form of adding and deleting rows and cells...
Wrapper for TableIdentifier providing member storage.
Scan predicate and control specification.
Definition: ScanSpec.h:56
Declarations for RangeServerProtocol.
Represents an open table.
Definition: Table.h:58
Provides the ability to mutate a table in the form of adding and deleting rows and cells...
Definition: TableMutator.h:55
std::shared_ptr< Session > SessionPtr
Definition: Session.h:734
void set_index_table(TablePtr idx)
sets the index table.
Definition: Table.h:222
std::shared_ptr< Properties > PropertiesPtr
Definition: Properties.h:447
Declarations for ClientObject.
std::shared_ptr< ApplicationQueueInterface > ApplicationQueueInterfacePtr
Smart pointer to ApplicationQueueInterface.
Synchronous table scanner.
Definition: TableScanner.h:39
bool has_index_table()
returns true if this table has an index
Definition: Table.h:209
Base class for Hypertable client objects.
Definition: ClientObject.h:44
Hyperspace session.
Definition: Session.h:148
size_t m_scanner_queue_size
Definition: Table.h:273
Hypertable definitions
SchemaPtr schema()
Definition: Table.h:144
Entry point to AsyncComm service.
Definition: Comm.h:61
std::string m_toplevel_dir
Definition: Table.h:272
void invalidate()
Definition: Table.h:173
SchemaPtr m_schema
Definition: Table.h:263
TablePtr get_index_table()
Definition: Table.h:235
RangeLocatorPtr m_range_locator
Definition: Table.h:264
TablePtr m_qualifier_index_table
Definition: Table.h:275
std::string m_name
Definition: Table.h:267
void set_namespace(Namespace *ns)
Definition: Table.h:243
std::mutex m_mutex
Mutex for serializing member access.
Definition: Table.h:258
int m_timeout_ms
Definition: Table.h:270
std::shared_ptr< Schema > SchemaPtr
Smart pointer to Schema.
Definition: Schema.h:465
const std::string & get_name()
Definition: Table.h:139
Declarations for ApplicationQueueInterface.
Comm * m_comm
Definition: Table.h:260
std::shared_ptr< ConnectionManager > ConnectionManagerPtr
Smart pointer to ConnectionManager.
Represents an open table.
std::shared_ptr< NameIdMapper > NameIdMapperPtr
Smart pointer to NameIdMapper.
Definition: NameIdMapper.h:121
std::shared_ptr< Table > TablePtr
Definition: Table.h:53
Namespace * m_namespace
Definition: Table.h:276
void get_identifier(TableIdentifier *table_id_p)
Definition: Table.h:133
TablePtr get_qualifier_index_table()
Definition: Table.h:239