0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
TableMutatorAsyncDispatchHandler.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 
26 
27 #include <AsyncComm/Protocol.h>
28 
29 #include <Common/Error.h>
30 #include <Common/Logger.h>
31 
32 using namespace Hypertable;
33 using namespace Serialization;
34 
37  uint32_t scatter_buffer, TableMutatorAsyncSendBuffer *send_buffer, bool auto_refresh)
38  : m_app_queue(app_queue), m_mutator(mutator),
39  m_scatter_buffer(scatter_buffer), m_send_buffer(send_buffer),
40  m_auto_refresh(auto_refresh) {
41 }
42 
44  int32_t error;
45 
46  if (event_ptr->type == Event::MESSAGE) {
47  error = Protocol::response_code(event_ptr);
48  if (error != Error::OK) {
49  if (m_auto_refresh &&
51  error == Error::TABLE_NOT_FOUND))
52  m_send_buffer->add_retries_all(true, error);
53  else
55  }
56  else {
57  const uint8_t *decode_ptr = event_ptr->payload + 4;
58  size_t decode_remain = event_ptr->payload_len - 4;
59  uint32_t count, offset, len;
60 
61  if (decode_remain == 0) {
63  }
64  else {
65  while (decode_remain) {
66  try {
67  error = decode_i32(&decode_ptr, &decode_remain);
68  count = decode_i32(&decode_ptr, &decode_remain);
69  offset = decode_i32(&decode_ptr, &decode_remain);
70  len = decode_i32(&decode_ptr, &decode_remain);
71  }
72  catch (Exception &e) {
73  HT_ERROR_OUT << e << HT_END;
74  break;
75  }
76  if (error == Error::RANGESERVER_OUT_OF_RANGE ||
79  m_send_buffer->add_retries(count, offset, len);
80  else {
81  m_send_buffer->add_errors(error, count, offset, len);
82  }
83  }
84  }
85  }
86  }
87  else if (event_ptr->type == Event::ERROR) {
89  HT_WARNF("%s, will retry ...", event_ptr->to_str().c_str());
90  }
91  else {
92  // this should never happen
93  HT_ERRORF("%s", event_ptr->to_str().c_str());
94  }
95 
96  bool complete = m_send_buffer->counterp->decrement();
97  if (complete) {
99  m_app_queue->add(handler);
100  }
101 }
102 
#define HT_WARNF(msg,...)
Definition: Logger.h:290
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
void add_retries_all(bool with_error=false, uint32_t error=0)
void add_retries(uint32_t count, uint32_t offset, uint32_t len)
std::shared_ptr< Event > EventPtr
Smart pointer to Event.
Definition: Event.h:228
Error event
Definition: Event.h:64
uint32_t decode_i32(const uint8_t **bufp, size_t *remainp)
Decode a 32-bit integer in little-endian order.
Provides the ability to mutate a table in the form of adding and deleting rows and cells...
virtual void handle(EventPtr &event_ptr)
Dispatch method.
TableMutatorAsyncCompletionCounter * counterp
Logging routines and macros.
Compatibility Macros for C/C++.
#define HT_END
Definition: Logger.h:220
std::shared_ptr< ApplicationQueueInterface > ApplicationQueueInterfacePtr
Smart pointer to ApplicationQueueInterface.
#define HT_ERROR_OUT
Definition: Logger.h:301
Hypertable definitions
TableMutatorAsyncDispatchHandler(ApplicationQueueInterfacePtr &app_queue, TableMutatorAsync *mutator, uint32_t scatter_buffer, TableMutatorAsyncSendBuffer *send_buffer, bool auto_refresh)
Constructor.
Declarations for Protocol.
Request/response message event.
Definition: Event.h:63
This is a generic exception class for Hypertable.
Definition: Error.h:314
#define HT_ERRORF(msg,...)
Definition: Logger.h:300
void add_errors(int error, uint32_t count, uint32_t offset, uint32_t len)
Error codes, Exception handling, error logging.
This class is a DispatchHandler.