0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Client.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; 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 #ifndef Hypertable_Lib_Master_Client_h
28 #define Hypertable_Lib_Master_Client_h
29 
35 
37 #include <Hyperspace/Session.h>
38 
40 #include <AsyncComm/Comm.h>
41 #include <AsyncComm/CommBuf.h>
43 
44 #include <Common/StatsSystem.h>
45 #include <Common/Status.h>
46 #include <Common/Timer.h>
47 
48 #include <condition_variable>
49 #include <memory>
50 #include <mutex>
51 
52 namespace Hypertable {
53 namespace Lib {
54 namespace Master {
55 
56  class Client;
57 
60 
62  public:
65  void safe() {}
66  void expired() {}
67  void jeopardy() {}
68  void disconnected();
69  void reconnected();
70 
71  private:
72  friend class Client;
74  };
75 
80  class Client {
81  public:
82 
83  Client(ConnectionManagerPtr &conn_mgr,
84  Hyperspace::SessionPtr &hyperspace,
85  const String &toplevel_dir, uint32_t timeout_ms,
88 
89  Client(ConnectionManagerPtr &conn_mgr, InetAddr &addr,
90  uint32_t timeout_ms);
91 
92  Client(Comm *comm, InetAddr &addr, uint32_t timeout_ms);
93 
94  ~Client();
95 
96  bool wait_for_connection(uint32_t max_wait_ms);
97  bool wait_for_connection(Timer &timer);
98 
99  void create_namespace(const String &name, int32_t flags, Timer *timer=0);
100 
101  void drop_namespace(const String &name, int32_t flags, Timer *timer=0);
102 
103  void compact(const String &tablename, const String &row,
104  int32_t range_types, Timer *timer = 0);
105  void create_table(const String &name, const String &schema,
106  Timer *timer = 0);
107  void alter_table(const String &tablename, const String &schema,
108  bool force, Timer *timer = 0);
109  void rename_table(const String &from, const String &to,
110  Timer *timer = 0);
111 
112  void status(Status &status, Timer *timer=0);
113 
114  void move_range(const String &source, int64_t range_id,
115  TableIdentifier &table,
116  RangeSpec &range, const String &transfer_log,
117  uint64_t soft_limit, bool split, Timer *timer=0);
118 
119  void relinquish_acknowledge(const String &source, int64_t range_id,
120  TableIdentifier &table,
121  RangeSpec &range, Timer *timer=0);
122 
123  void drop_table(const String &name, bool if_exists, Timer *timer=0);
124 
131  void recreate_index_tables(const std::string &name,
132  TableParts parts, Timer *timer=0);
133 
134  void shutdown(Timer *timer=0);
135 
136  void balance(BalancePlan &plan, Timer *timer = 0);
137 
142  void set_state(const std::vector<SystemVariable::Spec> &specs,
143  Timer *timer = 0);
144 
145  void stop(const String &rsname, Timer *timer = 0);
146 
147  void reload_master();
148 
149  void set_verbose_flag(bool verbose) { m_verbose = verbose; }
150 
151  void replay_status(int64_t op_id, const String &location,
152  int32_t plan_generation);
153 
154  void replay_complete(int64_t op_id, const String &location,
155  int32_t plan_generation, int32_t error, const String message);
156 
157  void phantom_prepare_complete(int64_t op_id, const String &location,
158  int plan_generation, int32_t error, const String message);
159 
160  void phantom_commit_complete(int64_t op_id, const String &location,
161  int plan_generation, int32_t error, const String message);
162 
163  void system_status(Status &status, Timer *timer=0);
164 
165 
166  private:
168 
170  void hyperspace_reconnected();
171  void send_message_async(CommBufPtr &cbp, DispatchHandler *handler, Timer *timer,
172  const String &label);
173  bool send_message(CommBufPtr &cbp, Timer *timer, EventPtr &event, const String &label);
174  void fetch_result(int64_t id, Timer *timer, EventPtr &event, const String &label);
175  void initialize_hyperspace();
176  void initialize(Timer *&timer, Timer &tmp_timer);
177 
179  std::condition_variable m_cond;
180  bool m_verbose {};
185  uint64_t m_master_file_handle {};
194  uint32_t m_timeout_ms {};
197  uint32_t m_retry_interval {};
198  };
199 
201  typedef std::shared_ptr<Client> ClientPtr;
202 
204 
205 }}}
206 
207 #endif // Hypertable_Lib_Master_Client_h
Hyperspace::HandleCallbackPtr m_master_file_callback
Definition: Client.h:186
uint32_t m_timeout_ms
Definition: Client.h:148
static std::mutex mutex
Definition: Logger.cc:43
void drop_namespace(const std::string &name, Namespace *base=NULL, bool if_exists=false)
Removes a namespace.
Definition: Client.cc:150
Hyperspace::SessionPtr m_hyperspace
Definition: Client.h:183
DispatchHandlerPtr m_dispatcher_handler
Definition: Client.h:189
A callback object derived from this class gets passed into the constructor of Hyperspace.
Definition: Session.h:94
Range specification.
Definition: RangeSpec.h:40
Holds Nagios-style program status information.
Definition: Status.h:42
Balance plan.
Definition: BalancePlan.h:38
void alter_table(const String &tablename, const String &schema, bool force, Timer *timer=0)
Definition: Client.cc:343
std::string String
A String is simply a typedef to std::string.
Definition: String.h:44
ConnectionManagerPtr m_conn_manager
Definition: Client.h:182
Declarations for Status.
Abstract base class for application dispatch handlers registered with AsyncComm.
Declarations for SystemVariable.
void init(int argc, char *argv[], const Desc *desc=NULL)
Initialize with default policy.
Definition: Init.h:95
Declarations for TableIdentifier and TableIdentifierManaged.
bool send_message(CommBufPtr &cbp, Timer *timer, EventPtr &event, const String &label)
Definition: Client.cc:796
std::shared_ptr< Event > EventPtr
Smart pointer to Event.
Definition: Event.h:228
Collecting and (de)serializing system-wide statistics.
Client(const std::string &install_dir, const std::string &config_file, uint32_t default_timeout_ms=0)
Constructs the object using the specified config file.
Definition: Client.cc:60
void fetch_result(int64_t id, Timer *timer, EventPtr &event, const String &label)
Definition: Client.cc:815
Represents a set of table parts (sub-tables).
Definition: TableParts.h:47
bool wait_for_connection(uint32_t max_wait_ms)
Definition: Client.cc:1041
void stop(const String &rsname, Timer *timer=0)
Definition: Client.cc:695
void create_table(String &ns, String &tablename, String &rs_metrics_file)
void rename_table(const String &from, const String &to, Timer *timer=0)
Definition: Client.cc:490
void compact(const String &tablename, const String &row, int32_t range_types, Timer *timer=0)
Definition: Client.cc:270
std::shared_ptr< Session > SessionPtr
Definition: Session.h:734
ApplicationQueueInterfacePtr m_app_queue
Definition: Client.h:184
bool status(ContextPtr &context, Timer &timer, Status &status)
Runs a status check on the master.
Definition: Utility.cc:408
void send_message_async(CommBufPtr &cbp, DispatchHandler *handler, Timer *timer, const String &label)
Definition: Client.cc:762
Encapsulate an internet address.
Definition: InetAddr.h:66
void set_state(const std::vector< SystemVariable::Spec > &specs, Timer *timer=0)
Set system state variables synchronously.
Definition: Client.cc:661
std::shared_ptr< CommBuf > CommBufPtr
Smart pointer to CommBuf.
Definition: CommBuf.h:305
A timer class to keep timeout states across AsyncComm related calls.
void initialize()
Definition: Client.cc:198
ConnectionInitializerPtr m_connection_initializer
Definition: Client.h:190
std::shared_ptr< ApplicationQueueInterface > ApplicationQueueInterfacePtr
Smart pointer to ApplicationQueueInterface.
void drop_table(const String &name, bool if_exists, Timer *timer=0)
Definition: Client.cc:526
void recreate_index_tables(const std::string &name, TableParts parts, Timer *timer=0)
Carries out a recreate index tables Master operation.
Definition: Client.cc:560
void initialize_hyperspace()
Assumes access is serialized via m_hyperspace_mutex.
Definition: Client.cc:159
Declarations for RangeSpec and RangeSpecManaged.
void relinquish_acknowledge(const String &source, int64_t range_id, TableIdentifier &table, RangeSpec &range, Timer *timer=0)
Definition: Client.cc:449
std::shared_ptr< HandleCallback > HandleCallbackPtr
Hypertable definitions
Entry point to AsyncComm service.
Definition: Comm.h:61
void set_verbose_flag(bool verbose)
Definition: Client.h:149
Declarations for CommBuf.
Declarations for ConnectionManager.
std::shared_ptr< Client > ClientPtr
Smart pointer to Client.
Definition: Client.h:201
std::condition_variable m_cond
Definition: Client.h:179
Declarations for Comm.
void create_namespace(const std::string &name, Namespace *base=NULL, bool create_intermediate=false, bool if_not_exists=false)
Creates a namespace.
Definition: Client.cc:86
bool split(int flags)
Tests the SPLIT bit of flags
void balance(BalancePlan &plan, Timer *timer=0)
Definition: Client.cc:617
A timer class to keep timeout states across AsyncComm related calls.
Definition: Timer.h:44
std::shared_ptr< DispatchHandler > DispatchHandlerPtr
Smart pointer to DispatchHandler.
void move_range(const String &source, int64_t range_id, TableIdentifier &table, RangeSpec &range, const String &transfer_log, uint64_t soft_limit, bool split, Timer *timer=0)
Definition: Client.cc:406
Declarations for ApplicationQueueInterface.
ClientHyperspaceSessionCallback m_hyperspace_session_callback
Definition: Client.h:195
std::shared_ptr< ConnectionManager > ConnectionManagerPtr
Smart pointer to ConnectionManager.
std::shared_ptr< ConnectionInitializer > ConnectionInitializerPtr
Smart pointer to ConnectionInitializer.
Declarations for TableParts.