0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
MaprBroker.h
Go to the documentation of this file.
1 /* -*- c++ -*-
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 
22 #ifndef FsBroker_mapr_MaprBroker_h
23 #define FsBroker_mapr_MaprBroker_h
24 
25 #include <FsBroker/Lib/Broker.h>
27 
28 #include <Common/Properties.h>
29 #include <Common/Status.h>
30 #include <Common/String.h>
31 
32 #include <hdfs.h>
33 
34 #include <atomic>
35 #include <string>
36 
37 extern "C" {
38 #include <unistd.h>
39 }
40 
41 namespace Hypertable {
42 namespace FsBroker {
43  using namespace Lib;
44 
45  class OpenFileDataMapr : public OpenFileData {
46  public:
47  OpenFileDataMapr(hdfsFS _fs, const String &fname, hdfsFile _file, int _flags)
48  : fs(_fs), file(_file), flags(_flags), filename(fname) { }
49  virtual ~OpenFileDataMapr() {
50  if (hdfsCloseFile(fs, file) != 0) {
51  HT_ERRORF("Error closing file '%s' - %s", filename.c_str(), strerror(errno));
52  }
53  }
54  hdfsFS fs;
55  hdfsFile file;
56  int flags;
58  };
59 
61  public:
64  : OpenFileDataPtr(ofdl) { }
66  return (OpenFileDataMapr *)get();
67  }
68  };
69 
70 
71  class MaprBroker : public FsBroker::Broker {
72  public:
73  MaprBroker(PropertiesPtr &props);
74  virtual ~MaprBroker();
75 
76  virtual void open(Response::Callback::Open *cb, const char *fname,
77  uint32_t flags, uint32_t bufsz);
78  virtual void create(Response::Callback::Open *cb, const char *fname, uint32_t flags,
79  int32_t bufsz, int16_t replication, int64_t blksz);
80  virtual void close(ResponseCallback *cb, uint32_t fd);
81  virtual void read(Response::Callback::Read *cb, uint32_t fd, uint32_t amount);
82  virtual void append(Response::Callback::Append *cb, uint32_t fd,
83  uint32_t amount, const void *data, Filesystem::Flags flags);
84  virtual void seek(ResponseCallback *cb, uint32_t fd, uint64_t offset);
85  virtual void remove(ResponseCallback *cb, const char *fname);
86  virtual void length(Response::Callback::Length *cb, const char *fname,
87  bool accurate = true);
88  virtual void pread(Response::Callback::Read *cb, uint32_t fd, uint64_t offset,
89  uint32_t amount, bool verify_checksum);
90  virtual void mkdirs(ResponseCallback *cb, const char *dname);
91  virtual void rmdir(ResponseCallback *cb, const char *dname);
92  virtual void readdir(Response::Callback::Readdir *cb, const char *dname);
93  virtual void flush(ResponseCallback *cb, uint32_t fd);
94  virtual void sync(ResponseCallback *cb, uint32_t fd);
95  virtual void status(Response::Callback::Status *cb);
96  virtual void shutdown(ResponseCallback *cb);
97  virtual void exists(Response::Callback::Exists *cb, const char *fname);
98  virtual void rename(ResponseCallback *cb, const char *src, const char *dst);
99  virtual void debug(ResponseCallback *, int32_t command,
100  StaticBuffer &serialized_parameters);
101 
102 
103  private:
104 
105  static atomic<int> ms_next_fd;
106 
107  virtual void report_error(ResponseCallback *cb);
108 
111 
114 
115  bool m_verbose;
116  hdfsFS m_filesystem;
120  uint16_t m_namenode_port;
121  };
122 
123 }}
124 
125 #endif // FsBroker_mapr_MaprBroker_h
A memory buffer of static size.
Definition: StaticBuffer.h:45
static String filename
Definition: Config.cc:48
Application handler for append function.
Definition: Append.h:45
Holds Nagios-style program status information.
Definition: Status.h:42
std::string String
A String is simply a typedef to std::string.
Definition: String.h:44
MetricsHandlerPtr m_metrics_handler
Metrics collection handler.
Definition: MaprBroker.h:110
Declarations for Status.
Abstract class to be implemented by brokers.
Definition: Broker.h:51
std::shared_ptr< OpenFileData > OpenFileDataPtr
Definition: OpenFileMap.h:45
Flags
Enumeration type for append flags.
Definition: Filesystem.h:76
Application handler for exists function.
Definition: Exists.h:45
Program options handling.
OpenFileDataMapr * operator->() const
Definition: MaprBroker.h:65
Hypertable::Status m_status
Server status information.
Definition: MaprBroker.h:113
Application handler for length function.
Definition: Length.h:45
bool status(ContextPtr &context, Timer &timer, Status &status)
Runs a status check on the master.
Definition: Utility.cc:408
std::shared_ptr< Properties > PropertiesPtr
Definition: Properties.h:447
OpenFileDataMapr(hdfsFS _fs, const String &fname, hdfsFile _file, int _flags)
Definition: MaprBroker.h:47
This class is used to generate and deliver standard responses back to a client.
Application handler for readdir function.
Definition: Readdir.h:48
Hypertable definitions
Application handler for open function.
Definition: Open.h:45
Declarations for MetricsHandler.
Application handler for read function.
Definition: Read.h:47
OpenFileDataMaprPtr(OpenFileDataMapr *ofdl)
Definition: MaprBroker.h:63
Application handler for open function.
Definition: Status.h:50
A String class based on std::string.
#define HT_ERRORF(msg,...)
Definition: Logger.h:300
static atomic< int > ms_next_fd
Definition: MaprBroker.h:105
std::shared_ptr< MetricsHandler > MetricsHandlerPtr
Smart pointer to MetricsHandler.