0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ReplayDispatchHandler.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 
22 #include <Common/Compat.h>
23 
24 #include "ReplayDispatchHandler.h"
25 
26 #include <AsyncComm/Protocol.h>
27 
28 using namespace std;
29 using namespace Hypertable;
30 
31 void ReplayDispatchHandler::handle(Hypertable::EventPtr &event) {
32  lock_guard<mutex> lock(m_mutex);
33  int32_t error;
34  QualifiedRangeSpec range;
35  String error_msg;
36  String msg;
37 
38  if (event->type == Event::MESSAGE) {
40  const uint8_t *decode_ptr = event->payload + 4;
41  size_t decode_remain = event->payload_len - 4;
42 
43  if (error != Error::OK) {
44  error_msg = Serialization::decode_str16(&decode_ptr, &decode_remain);
45  range.decode(&decode_ptr, &decode_remain);
47  HT_INFOF("%s - %s", Error::get_text(error), error_msg.c_str());
48  // Currently, this block should never be executed
49  }
50  else {
51  m_error_msg = format("Replay to %s failed - %s",
52  event->proxy ? event->proxy : event->addr.format().c_str(),
53  error_msg.c_str());
54  HT_INFOF("%s", m_error_msg.c_str());
55  m_error = error;
56  }
57  }
58  }
59  else {
60  m_error_msg = format("Replay to %s failed",
61  event->proxy ? event->proxy : event->addr.format().c_str());
62  HT_INFOF("%s", m_error_msg.c_str());
63  m_error = event->error;
64  }
65 
66  HT_ASSERT(m_outstanding>0);
67  m_outstanding--;
68  if (m_outstanding == 0)
69  m_cond.notify_all();
70 }
71 
73  const QualifiedRangeSpec &range, uint32_t fragment,
74  StaticBuffer &buffer) {
75  {
76  lock_guard<mutex> lock(m_mutex);
77  m_outstanding++;
78  }
79 
80  try {
81  m_rsclient.phantom_update(addr, m_recover_location, m_plan_generation,
82  range, fragment, buffer, this);
83  }
84  catch (Exception &e) {
85  lock_guard<mutex> lock(m_mutex);
86  HT_ERROR_OUT << "Error sending phantom updates for range " << range
87  << " to " << addr.to_str() << "-" << e << HT_END;
88  m_outstanding--;
89  HT_ASSERT(addr.is_proxy());
90  m_error_msg = e.what();
91  m_error = e.code();
92  }
93 }
94 
95 void ReplayDispatchHandler::wait_for_completion() {
96  unique_lock<mutex> lock(m_mutex);
97  m_cond.wait(lock, [this](){ return m_outstanding == 0; });
98  if (m_error != Error::OK)
99  HT_THROW(m_error, m_error_msg);
100 }
101 
A memory buffer of static size.
Definition: StaticBuffer.h:45
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
std::string String
A String is simply a typedef to std::string.
Definition: String.h:44
String format(const char *fmt,...)
Returns a String using printf like format facilities Vanilla snprintf is about 1.5x faster than this...
Definition: String.cc:37
std::shared_ptr< Event > EventPtr
Smart pointer to Event.
Definition: Event.h:228
STL namespace.
void add(const Key &key, uint8_t flag, const void *value, uint32_t value_len, TableMutatorAsync *value_index_mutator, TableMutatorAsync *qualifier_index_mutator)
Definition: IndexTables.cc:34
#define HT_ASSERT(_e_)
Definition: Logger.h:396
const char * get_text(int error)
Returns a descriptive error message.
Definition: Error.cc:330
Compatibility Macros for C/C++.
#define HT_END
Definition: Logger.h:220
const char * decode_str16(const uint8_t **bufp, size_t *remainp)
Decodes a c-style string from the given buffer.
#define HT_ERROR_OUT
Definition: Logger.h:301
String to_str() const
Returns string representation of address.
Definition: CommAddress.cc:34
virtual void decode(const uint8_t **bufp, size_t *remainp)
Reads serialized representation of object from a buffer.
Definition: Serializable.cc:70
Hypertable definitions
Declarations for Protocol.
#define HT_INFOF(msg,...)
Definition: Logger.h:272
This is a generic exception class for Hypertable.
Definition: Error.h:314
Qualified (with table identifier) range specification.
bool is_proxy() const
Returns true if address is of type CommAddress::PROXY.
Definition: CommAddress.h:147
#define HT_THROW(_code_, _msg_)
Definition: Error.h:478
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