0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
TableMutatorSyncDispatchHandler.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 
26 
27 #include <Common/Compat.h>
28 
30 
31 #include <Common/Error.h>
32 #include <Common/Logger.h>
33 
34 #include <AsyncComm/Protocol.h>
35 
37 
38 using namespace Hypertable;
39 
41  Comm *comm, TableIdentifierManaged &table_id, time_t timeout)
42  : m_client(comm, timeout), m_table_identifier(table_id) {
43 }
44 
46 
48  lock_guard<mutex> lock(m_mutex);
49 
50  try {
51  pair<CommAddressSet::iterator, bool> res = m_pending.insert(addr);
52  HT_ASSERT(res.second);
54  m_outstanding++;
55  }
56  catch (Exception &e) {
57  ErrorResult result;
58  result.addr = addr;
59  result.error = e.code();
60  result.msg = "Send error";
61  m_errors.push_back(result);
62  }
63 }
64 
65 
67  lock_guard<mutex> lock(m_mutex);
68  ErrorResult result;
69 
70  HT_ASSERT(event_ptr->proxy);
71 
72  result.addr.set_proxy(event_ptr->proxy);
73 
74  if (event_ptr->type == Event::MESSAGE) {
75  if ((result.error = Protocol::response_code(event_ptr)) != Error::OK) {
76  result.msg = Protocol::string_format_message(event_ptr);
77  m_errors.push_back(result);
78  }
79  else {
80  // Successful response
81  if (m_pending.erase(result.addr) == 0) {
83  << "Received 'commit log sync ack' from unexpected address '"
84  << result.addr.to_str() << "'" << HT_END ;
85  }
86  }
87  }
88  else {
89  result.error = event_ptr->error;
90  result.msg = "";
91  m_errors.push_back(result);
92  }
93  m_outstanding--;
94 
95  if (m_outstanding == 0)
96  m_cond.notify_all();
97 }
98 
99 
101  lock_guard<mutex> lock(m_mutex);
102 
103  m_errors.clear();
104  for (auto addr : m_pending) {
105  try {
107  }
108  catch (Exception &e) {
109  ErrorResult result;
110  result.addr = addr;
111  result.error = e.code();
112  result.msg = "Send error";
113  m_errors.push_back(result);
114  }
115  m_outstanding++;
116  }
117 
118 }
119 
120 
122  unique_lock<mutex> lock(m_mutex);
123  m_cond.wait(lock, [this](){ return m_outstanding == 0; });
124  return m_errors.empty();
125 }
126 
127 
129  errors = m_errors;
130 }
static int32_t response_code(const Event *event)
Returns the response code from an event event generated in response to a request message.
Definition: Protocol.cc:39
static String string_format_message(const Event *event)
Returns error message decoded standard error MESSAGE generated in response to a request message...
Definition: Protocol.cc:51
void commit_log_sync(const CommAddress &addr, uint64_t cluster_id, const TableIdentifier &table, DispatchHandler *handler)
Issues a "commit_log_sync" request asynchronously.
Definition: Client.cc:467
std::vector< String > errors
std::shared_ptr< Event > EventPtr
Smart pointer to Event.
Definition: Event.h:228
virtual void handle(EventPtr &event_ptr)
Dispatch method.
#define HT_ASSERT(_e_)
Definition: Logger.h:396
Wrapper for TableIdentifier providing member storage.
Declarations for TableMutatorSyncDispatchHandler.
Logging routines and macros.
void set_proxy(const String &str)
Sets address type to CommAddress::PROXY and proxy name to p.
Definition: CommAddress.h:76
static uint64_t get()
Gets the cluster ID.
Definition: ClusterId.h:85
Compatibility Macros for C/C++.
#define HT_END
Definition: Logger.h:220
String to_str() const
Returns string representation of address.
Definition: CommAddress.cc:34
Hypertable definitions
Entry point to AsyncComm service.
Definition: Comm.h:61
Declarations for Protocol.
Request/response message event.
Definition: Event.h:63
This is a generic exception class for Hypertable.
Definition: Error.h:314
TableMutatorSyncDispatchHandler(Comm *comm, TableIdentifierManaged &table_id, time_t timeout)
Constructor.
Error codes, Exception handling, error logging.
#define HT_FATAL_OUT
Definition: Logger.h:347
Declarations for ClusterId.
Address abstraction to hold either proxy name or IPv4:port address.
Definition: CommAddress.h:52
int code() const
Returns the error code.
Definition: Error.h:391