74 using namespace Error;
80 if ((error = m_context->comm->set_timer(m_context->timer_interval, shared_from_this())) !=
Error::OK)
93 if (m_context->shutdown_in_progress()) {
98 else if (m_context->startup_in_progress() ||
99 !m_context->master_file->lock_acquired()) {
110 (
Llu)event->header.command);
112 switch (event->header.command) {
114 operation = make_shared<OperationStatus>(m_context, event);
115 m_context->response_manager->add_delivery_info(operation->id(), event);
116 m_context->op->add_operation(operation);
118 case Lib::Master::Protocol::COMMAND_SYSTEM_STATUS:
119 operation = make_shared<OperationSystemStatus>(m_context, event);
120 m_context->response_manager->add_delivery_info(operation->id(), event);
121 m_context->op->add_operation(operation);
124 operation = make_shared<OperationCompact>(m_context, event);
127 operation = make_shared<OperationCreateTable>(m_context, event);
130 operation = make_shared<OperationDropTable>(m_context, event);
133 operation = make_shared<OperationAlterTable>(m_context, event);
136 operation = make_shared<OperationRenameTable>(m_context, event);
138 case Lib::Master::Protocol::COMMAND_REGISTER_SERVER:
139 operation = make_shared<OperationRegisterServer>(m_context, event);
140 m_context->op->add_operation(operation);
142 case Lib::Master::Protocol::COMMAND_MOVE_RANGE:
143 operation = make_shared<OperationMoveRange>(m_context, event);
144 if (!m_context->add_move_operation(operation)) {
145 HT_INFOF(
"Skipping %s because already in progress",
146 operation->label().c_str());
151 m_context->reference_manager->add(operation);
153 m_context->op->add_operation(operation);
155 case Lib::Master::Protocol::COMMAND_RELINQUISH_ACKNOWLEDGE:
156 operation = make_shared<OperationRelinquishAcknowledge>(m_context, event);
159 operation = make_shared<OperationBalance>(m_context, event);
161 case Lib::Master::Protocol::COMMAND_SET_STATE:
162 operation = make_shared<OperationSetState>(m_context, event);
165 operation = make_shared<OperationStop>(m_context, event);
168 HT_INFO(
"Received shutdown command");
169 m_context->start_shutdown();
170 send_ok_response(event,
true);
173 operation = make_shared<OperationCreateNamespace>(m_context, event);
176 operation = make_shared<OperationDropNamespace>(m_context, event);
178 case Lib::Master::Protocol::COMMAND_RECREATE_INDEX_TABLES:
179 operation = make_shared<OperationRecreateIndexTables>(m_context, event);
182 case Lib::Master::Protocol::COMMAND_FETCH_RESULT:
184 const uint8_t *ptr =
event->payload;
185 size_t remain =
event->payload_len;
187 params.
decode(&ptr, &remain);
188 m_context->response_manager->add_delivery_info(params.
get_id(), event);
191 case Lib::Master::Protocol::COMMAND_REPLAY_STATUS:
192 m_context->replay_status(event);
193 send_ok_response(event);
195 case Lib::Master::Protocol::COMMAND_REPLAY_COMPLETE:
196 m_context->replay_complete(event);
197 send_ok_response(event);
199 case Lib::Master::Protocol::COMMAND_PHANTOM_PREPARE_COMPLETE:
200 m_context->prepare_complete(event);
201 send_ok_response(event);
203 case Lib::Master::Protocol::COMMAND_PHANTOM_COMMIT_COMPLETE:
204 m_context->commit_complete(event);
205 send_ok_response(event);
209 (
Llu)event->header.command);
214 event->header.command != Lib::Master::Protocol::COMMAND_RELINQUISH_ACKNOWLEDGE);
215 if (send_id_response(event, operation) !=
Error::OK)
217 m_context->op->add_operation(operation);
222 format(
"Unimplemented command (%llu)",
223 (
Llu)event->header.command));
232 operation->set_ephemeral();
233 operation->complete_error(e.
code(), e.what());
234 m_context->response_manager->add_operation(operation);
241 time_t now = time(0);
243 if (m_context->shutdown_in_progress())
248 maybe_dump_op_statistics();
251 if (m_context->next_monitoring_time <= now) {
252 operation = make_shared<OperationGatherStatistics>(m_context);
253 m_context->op->add_operation(operation);
254 m_context->next_monitoring_time = now + (m_context->monitoring_interval/1000) - 1;
257 if (m_context->next_gc_time <= now) {
258 operation = make_shared<OperationCollectGarbage>(m_context);
259 m_context->op->add_operation(operation);
260 m_context->next_gc_time = now + (m_context->gc_interval/1000) - 1;
263 if (m_context->balancer->balance_needed()) {
264 operation = make_shared<OperationBalance>(m_context);
265 m_context->op->add_operation(operation);
276 if ((error = m_context->comm->set_timer(m_context->timer_interval, shared_from_this())) !=
Error::OK)
281 HT_INFOF(
"%s", event->to_str().c_str());
292 cbp->append_i64(operation->id());
293 error = m_context->comm->send_response(event->addr, cbp);
295 HT_ERRORF(
"Problem sending ID response back for %s operation (id=%lld) - %s",
305 int ret = m_context->comm->send_response(event->addr, cbp);
307 HT_ERRORF(
"Problem sending error response back to %s - %s",
316 cbp->append_i32(error);
317 cbp->append_vstr(msg);
318 int ret = m_context->comm->send_response(event->addr, cbp);
320 HT_ERRORF(
"Problem sending error response back to %s - %s",
331 out.open(output_fname.c_str());
332 m_context->op->state_description(description);
Declarations for FetchResult request parameters.
#define HT_WARNF(msg,...)
Request parameters for fetch result request.
The FailureInducer simulates errors.
std::string String
A String is simply a typedef to std::string.
Declarations for OperationDropTable.
static bool unlink(const String &fname)
Unlinks (deletes) a file or directory.
String format(const char *fmt,...)
Returns a String using printf like format facilities Vanilla snprintf is about 1.5x faster than this...
Declarations for OperationProcessor.
Declarations for Protocol.
Declarations for OperationCreateTable.
int32_t send_error_response(EventPtr &event, int32_t error, const String &msg)
Sends error response message back to client.
long long unsigned int Llu
Shortcut for printf formats.
static bool exists(const String &fname)
Checks if a file or directory exists.
std::shared_ptr< Event > EventPtr
Smart pointer to Event.
Declarations for OperationRecreateIndexTables.
size_t encoded_length_vstr(size_t len)
Computes the encoded length of vstr (vint64, data, null)
Declarations for ConnectionHandler.
Declarations for ReferenceManager.
Declarations for OperationCompact.
const char * get_text(int error)
Returns a descriptive error message.
std::shared_ptr< CommBuf > CommBufPtr
Smart pointer to CommBuf.
Compatibility Macros for C/C++.
int64_t get_id()
Gets operation ID.
Functions to serialize/deserialize primitives to/from a memory buffer.
Time related declarations.
virtual void decode(const uint8_t **bufp, size_t *remainp)
Reads serialized representation of object from a buffer.
This class is used to generate and deliver standard responses back to a client.
#define HT_FATALF(msg,...)
long long int Lld
Shortcut for printf formats.
virtual int error(int error, const String &msg)
Sends a standard error response back to the client.
#define HT_INFOF(msg,...)
Declarations for OperationSetState.
Declarations for OperationGatherStatistics.
#define HT_THROWF(_code_, _fmt_,...)
Request/response message event.
static String install_dir
The installation directory.
This is a generic exception class for Hypertable.
Message buffer for holding data to be transmitted over a network.
#define HT_MAYBE_FAIL_X(_label_, _exp_)
virtual void handle(EventPtr &event)
Responds to Master request events.
#define HT_ERRORF(msg,...)
int32_t send_id_response(EventPtr &event, OperationPtr &operation)
Sends operation ID back to client.
int32_t send_ok_response(EventPtr &event, bool silent=false)
Sends OK response message back to client.
#define HT_MAYBE_FAIL(_label_)
Declarations for OperationAlterTable.
std::shared_ptr< Operation > OperationPtr
Smart pointer to Operation.
Declarations for ResponseCallback.
String extensions and helpers: sets, maps, append operators etc.
Error codes, Exception handling, error logging.
void maybe_dump_op_statistics()
Maybe dumps OperationProcessor statistics.
int code() const
Returns the error code.