0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
TableMutatorShared.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; either version 3
9  * of the 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 Hypertable. If not, see <http://www.gnu.org/licenses/>
18  */
19 
20 #ifndef Hypertable_Lib_TableMutatorShared_h
21 #define Hypertable_Lib_TableMutatorShared_h
22 
23 #include "TableMutator.h"
24 
25 #include <chrono>
26 #include <memory>
27 #include <mutex>
28 
29 namespace Hypertable {
30 
32 
40 
41 public:
53  TableMutatorShared(PropertiesPtr &props, Comm *comm, Table *table,
54  RangeLocatorPtr &range_locator, ApplicationQueueInterfacePtr &app_queue,
55  uint32_t timeout_ms, uint32_t flush_interval_ms, uint32_t flags = 0);
56 
57  virtual ~TableMutatorShared();
58 
62  virtual void set(const KeySpec &key, const void *value, uint32_t value_len) {
63  std::lock_guard<std::recursive_mutex> lock(m_mutex);
64  Parent::set(key, value, value_len);
65  }
66 
70  virtual void set_delete(const KeySpec &key) {
71  std::lock_guard<std::recursive_mutex> lock(m_mutex);
72  Parent::set_delete(key);
73  }
74 
78  virtual void set_cells(const Cells &cells) {
79  std::lock_guard<std::recursive_mutex> lock(m_mutex);
80  Parent::set_cells(cells);
81  }
82 
86  virtual void flush() {
87  std::lock_guard<std::recursive_mutex> lock(m_mutex);
88  Parent::flush();
89  m_last_flush_ts = std::chrono::steady_clock::now();
90  }
91 
95  virtual bool retry(uint32_t timeout_ms = 0) {
96  std::lock_guard<std::recursive_mutex> lock(m_mutex);
97  return Parent::retry(timeout_ms);
98  }
99 
103  virtual uint64_t memory_used() {
104  std::lock_guard<std::recursive_mutex> lock(m_mutex);
105  return Parent::memory_used();
106  }
107 
111  virtual uint64_t get_resend_count() {
112  std::lock_guard<std::recursive_mutex> lock(m_mutex);
113  return Parent::get_resend_count();
114  }
115 
119  virtual void get_failed(FailedMutations &failed_mutations) {
120  std::lock_guard<std::recursive_mutex> lock(m_mutex);
121  return Parent::get_failed(failed_mutations);
122  }
123 
127  virtual bool need_retry() {
128  std::lock_guard<std::recursive_mutex> lock(m_mutex);
129  return Parent::need_retry();
130  }
131 
132  uint32_t flush_interval() { return m_flush_interval; }
133 
137  void interval_flush();
138 
139 private:
140  std::recursive_mutex m_mutex;
142  std::chrono::steady_clock::time_point m_last_flush_ts;
143  std::shared_ptr<TableMutatorIntervalHandler> m_tick_handler;
144 };
145 
146 }
147 
148 #endif /* Hypertable_Lib_TableMutatorShared_h */
virtual uint64_t memory_used()
Returns the amount of memory used by the collected mutations.
Definition: TableMutator.h:155
std::vector< Cell, CellAlloc > Cells
Definition: Cells.h:37
Timer handler for periodically flushing a shared mutator.
std::shared_ptr< RangeLocator > RangeLocatorPtr
Smart pointer to RangeLocator.
Definition: RangeLocator.h:198
std::shared_ptr< TableMutatorIntervalHandler > m_tick_handler
virtual void set_delete(const KeySpec &key)
Deletes an entire row, a column family in a particular row, or a specific cell within a row...
virtual void set(const KeySpec &key, const void *value, uint32_t value_len)
Inserts a cell into the table.
Definition: TableMutator.cc:86
Represents an open table.
Definition: Table.h:58
virtual void set_cells(const Cells &cells)
Insert a bunch of cells into the table (atomically if cells are in the same range/row) ...
Definition: TableMutator.h:124
Provides the ability to mutate a table in the form of adding and deleting rows and cells...
Definition: TableMutator.h:55
virtual void set(const KeySpec &key, const void *value, uint32_t value_len)
virtual void set_delete(const KeySpec &key)
std::shared_ptr< Properties > PropertiesPtr
Definition: Properties.h:447
std::shared_ptr< ApplicationQueueInterface > ApplicationQueueInterfacePtr
Smart pointer to ApplicationQueueInterface.
virtual void get_failed(FailedMutations &failed_mutations)
Returns the failed mutations.
Definition: TableMutator.h:173
std::chrono::steady_clock::time_point m_last_flush_ts
virtual bool retry(uint32_t timeout_ms=0)
Retries the last operation.
Hypertable definitions
void interval_flush()
Flush if necessary considering the flush interval.
Entry point to AsyncComm service.
Definition: Comm.h:61
uint64_t get_resend_count()
There are certain circumstances when mutations get flushed to the wrong range server due to stale ran...
Definition: TableMutator.h:166
TableMutatorShared(PropertiesPtr &props, Comm *comm, Table *table, RangeLocatorPtr &range_locator, ApplicationQueueInterfacePtr &app_queue, uint32_t timeout_ms, uint32_t flush_interval_ms, uint32_t flags=0)
virtual void flush()
Flushes the accumulated mutations to their respective range servers.
virtual void get_failed(FailedMutations &failed_mutations)
virtual void set_cells(const Cells &cells)
A TableMutator that can be shared from multiple threads and incidentally has an option to do periodic...
virtual bool retry(uint32_t timeout_ms=0)
virtual bool need_retry()
Checks for failed mutations.
Definition: TableMutator.h:145
std::vector< FailedMutation > FailedMutations
Definition: Cells.h:39