0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
TableMutatorShared.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; 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 #include <Common/Compat.h>
21 
22 #include "TableMutatorShared.h"
24 
25 using namespace Hypertable;
26 using namespace std;
27 
29  Table *table, RangeLocatorPtr &range_locator,
30  ApplicationQueueInterfacePtr &app_queue, uint32_t timeout_ms,
31  uint32_t flush_interval_ms, uint32_t flags)
32  : Parent(props, comm, table, range_locator, timeout_ms, flags),
33  m_flush_interval(flush_interval_ms) {
34 
35  m_last_flush_ts = chrono::steady_clock::now();
36 
37  if (m_flush_interval) {
38  m_tick_handler = make_shared<TableMutatorIntervalHandler>(comm, app_queue.get(), this);
39  m_tick_handler->start();
40  }
41 }
42 
43 
45  if (m_tick_handler)
46  m_tick_handler->stop();
47 }
48 
49 
51  try {
52  lock_guard<recursive_mutex> lock(m_mutex);
53 
54  if (chrono::steady_clock::now() - m_last_flush_ts >= chrono::milliseconds(m_flush_interval)) {
55  HT_DEBUG_OUT <<"need to flush"<< HT_END;
56  Parent::flush();
57  m_last_flush_ts = chrono::steady_clock::now();
58  }
59  else
60  HT_DEBUG_OUT <<"no need to flush"<< HT_END;
61  }
62  HT_RETHROW("interval flush")
63 }
#define HT_RETHROW(_s_)
Definition: Error.h:514
Declarations for TableMutatorIntervalHandler.
std::shared_ptr< RangeLocator > RangeLocatorPtr
Smart pointer to RangeLocator.
Definition: RangeLocator.h:198
std::shared_ptr< TableMutatorIntervalHandler > m_tick_handler
STL namespace.
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< Properties > PropertiesPtr
Definition: Properties.h:447
Compatibility Macros for C/C++.
#define HT_END
Definition: Logger.h:220
std::shared_ptr< ApplicationQueueInterface > ApplicationQueueInterfacePtr
Smart pointer to ApplicationQueueInterface.
std::chrono::steady_clock::time_point m_last_flush_ts
Hypertable definitions
void interval_flush()
Flush if necessary considering the flush interval.
Entry point to AsyncComm service.
Definition: Comm.h:61
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.
#define HT_DEBUG_OUT
Definition: Logger.h:261