0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Append.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 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 
29 #include "Append.h"
30 
33 
34 #include <AsyncComm/CommHeader.h>
35 
36 #include <Common/Error.h>
37 #include <Common/Filesystem.h>
38 #include <Common/Logger.h>
39 #include <Common/Serialization.h>
40 
41 using namespace Hypertable;
42 using namespace Hypertable::FsBroker::Lib;
44 
45 void Append::run() {
47  const uint8_t *ptr = m_event->payload;
48  size_t remain = m_event->payload_len;
49 
50  try {
52 
53  params.decode(&ptr, &remain);
54 
55  if (m_event->header.alignment) {
56  size_t padding = m_event->header.alignment - (ptr - m_event->payload);
57  remain -= padding;
58  ptr += padding;
59  }
60 
61  if (remain < params.get_size())
62  HT_THROW_INPUT_OVERRUN(remain, params.get_size());
63 
64  m_broker->append(&cb, params.get_fd(), params.get_size(),
65  ptr, static_cast<Filesystem::Flags>(params.get_flags()));
66 
67  }
68  catch (Exception &e) {
69  HT_ERROR_OUT << e << HT_END;
70  cb.error(e.code(), "Error handling APPEND message");
71  }
72 }
Request parameters for append requests.
Definition: Append.h:46
#define HT_THROW_INPUT_OVERRUN(_s_)
Application handler for append function.
Definition: Append.h:45
Abstract base class for a filesystem.
Flags
Enumeration type for append flags.
Definition: Filesystem.h:76
uint32_t get_size()
Gets size of data buffer.
Definition: Append.h:69
virtual void append(Response::Callback::Append *cb, uint32_t fd, uint32_t amount, const void *data, Filesystem::Flags flags)=0
Append data to open file.
int32_t get_fd()
Gets file descriptor.
Definition: Append.h:65
Logging routines and macros.
Compatibility Macros for C/C++.
#define HT_END
Definition: Logger.h:220
Broker * m_broker
Pointer to file system broker object.
Definition: Append.h:69
Functions to serialize/deserialize primitives to/from a memory buffer.
#define HT_ERROR_OUT
Definition: Logger.h:301
virtual void decode(const uint8_t **bufp, size_t *remainp)
Reads serialized representation of object from a buffer.
Definition: Serializable.cc:70
Declarations for Append response callback.
Hypertable definitions
virtual int error(int error, const String &msg)
Sends a standard error response back to the client.
This is a generic exception class for Hypertable.
Definition: Error.h:314
EventPtr m_event
MESSAGE Event from which handler was initialized.
virtual void run()
Invokes the append function.
Definition: Append.cc:45
File system broker framework and client library.
Definition: Broker.h:44
Comm * m_comm
Pointer to comm layer.
Definition: Append.h:66
Declarations for CommHeader.
Error codes, Exception handling, error logging.
Declarations for Append request parameters.
Declarations for Append request handler.
int code() const
Returns the error code.
Definition: Error.h:391