44 #include <boost/algorithm/string.hpp>
55 const uint8_t *ptr =
event->payload;
56 size_t remaining =
event->payload_len;
74 std::vector<SystemVariable::Spec> specs;
75 uint64_t generation {};
78 bool newly_created {};
88 HT_WARNF(
"Attempt to register server %s that has been removed",
98 uint64_t
id =
m_context->master_file->next_server_id();
104 newly_created =
true;
112 handle =
m_context->hyperspace->open(fname, oflags);
121 if (!
m_rsc->get_hyperspace_handle(&handle, &hyperspace_callback)) {
129 m_rsc->set_hyperspace_handle(handle, hyperspace_callback);
132 if (
m_context->rsc_manager->is_connected(m_location)) {
134 format(
"%s already connected", m_location.c_str()));
138 m_context->system_state->get(specs, &generation);
144 HT_ERRORF(
"Problem sending response (location=%s) back to %s",
150 if (difference > (3000000 +
m_context->max_allowable_skew)) {
151 String errstr =
format(
"Detected clock skew while registering server "
152 "%s (%s), as location %s register_ts=%llu, received_ts=%llu, "
153 "difference=%d > allowable skew %d",
158 String subject =
format(
"Clock skew detected while registering %s (%s)",
161 m_context->notification_hook(subject, errstr);
168 m_context->system_state->get(specs, &generation);
175 HT_ERRORF(
"Problem sending response (location=%s) back to %s",
180 HT_INFOF(
"%lld Leaving RegisterServer %s",
186 String message =
format(
"Registering server %s\nhost = %s\n"
187 "public addr = %s\nlocal addr = %s\n",
188 m_rsc->location().c_str(),
195 =
format(
"Registering server %s - %s (%s)", m_location.c_str(),
198 m_context->notification_hook(subject, message);
200 boost::replace_all(message,
"\n",
" ");
208 m_context->system_state->get(specs, &generation);
214 HT_ERRORF(
"Problem sending response (location=%s) back to %s",
221 if (!hyperspace_callback->wait_for_lock_acquisition(chrono::seconds(120))) {
222 String notification_body =
format(
"Timed out waiting for %s to acquire "
223 "lock on Hyperspace file",
225 HT_WARNF(
"%s, sending shutdown request...", notification_body.c_str());
230 String notification_subject =
231 format(
"Server registration error for %s (%s)", m_location.c_str(),
232 m_rsc->hostname().c_str());
233 m_context->notification_hook(notification_subject, notification_body);
236 m_context->op->add_operation(operation);
249 operation->complete_ok();
256 m_context->add_available_server(m_location);
259 operation = make_shared<OperationRegisterServerBlocker>(
m_context,
261 m_context->op->add_operation(operation);
263 if (!
m_rsc->get_balanced())
264 m_context->balancer->signal_new_server();
266 m_context->mml_writer->record_state(
m_rsc);
269 m_context->op->unblock(m_location);
272 HT_INFOF(
"%lld Leaving RegisterServer %s",
280 os <<
" local_addr=" <<
m_rsc->local_addr().format();
281 os <<
" public_addr=" <<
m_rsc->public_addr().format() <<
" ";
285 return "OperationRegisterServer";
293 std::vector<SystemVariable::Spec> &specs)
const {
305 std::vector<SystemVariable::Spec> &specs,
306 uint8_t **bufp)
const {
int64_t id()
Operation identifier.
int64_t now()
Gets server current time.
#define HT_WARNF(msg,...)
The FailureInducer simulates errors.
ContextPtr m_context
Pointer to Master context.
int64_t md5_hash(const char *input)
Returns a 64-bit hash checksum of a null terminated input buffer.
Abstract base class for ephemeral operations.
String m_error_msg
Result error message.
std::string String
A String is simply a typedef to std::string.
struct NetInfo net_info
Network information (host name, primary interface, gateway etc)
String format(const char *fmt,...)
Returns a String using printf like format facilities Vanilla snprintf is about 1.5x faster than this...
virtual size_t encoded_length() const
Returns serialized object length.
Declarations for OperationProcessor.
long long unsigned int Llu
Shortcut for printf formats.
void add_exclusivity(const String &exclusivity)
void execute() override
Executes (carries out) the operation.
std::shared_ptr< Event > EventPtr
Smart pointer to Event.
virtual void encode_response(uint64_t generation, std::vector< SystemVariable::Spec > &specs, uint8_t **bufp) const
OperationRegisterServer(ContextPtr &context, EventPtr &event)
uint16_t listen_port()
Gets listen port.
Declarations for RangeServerClient.
virtual size_t encoded_response_length(uint64_t generation, std::vector< SystemVariable::Spec > &specs) const
EventPtr m_event
Pointer to client event (if any) that originated the operation.
std::shared_ptr< Context > ContextPtr
Smart pointer to Context.
const String label() override
Human readable label for operation.
Callback class for range server lock files.
Declarations for RangeServerProtocol.
const StatsSystem & system_stats() const
Gets system stats.
virtual void encode(uint8_t **bufp) const
Writes serialized representation of object to a buffer.
size_t encoded_length_str16(const char *str)
Computes the encoded length of a string16 encoding.
Encapsulate an internet address.
int32_t m_error
Result error code.
void add_dependency(const String &dependency)
std::shared_ptr< CommBuf > CommBufPtr
Smart pointer to CommBuf.
void encode_i32(uint8_t **bufp, uint32_t val)
Encode a 32-bit integer in little-endian order.
void display_state(std::ostream &os) override
Write human readable operation state to output stream.
Compatibility Macros for C/C++.
Lib::Master::Request::Parameters::RegisterServer m_params
Request parmaeters.
Declarations for RangeServerHyperspaceCallback.
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.
String format(int sep= ':') const
Returns a string with a dotted notation ("127.0.0.1:8080") including the port.
std::shared_ptr< HandleCallback > HandleCallbackPtr
const char * RECOVERY_BLOCKER
long long int Lld
Shortcut for printf formats.
Declarations for general-purpose utility functions.
#define HT_INFOF(msg,...)
RangeServerConnectionPtr m_rsc
const string & location() const
Gets location (proxy name)
This is a generic exception class for Hypertable.
Message buffer for holding data to be transmitted over a network.
bool lock_held()
Gets lock held flag.
Response parameters for register server operation.
void encode_str16(uint8_t **bufp, const void *str, uint16_t len)
Encodes a string buffer into the given buffer.
#define HT_ERRORF(msg,...)
Create file if it does not exist.
void shutdown_rangeserver(ContextPtr &context, CommAddress &addr)
Sends a shutdown command to a rangeserver.
void complete_ok(std::vector< MetaLog::EntityPtr > &additional)
Declarations for RegisterServer response parameters.
const String name() override
Name of operation used for exclusivity.
std::shared_ptr< Operation > OperationPtr
Smart pointer to Operation.
String extensions and helpers: sets, maps, append operators etc.
Error codes, Exception handling, error logging.
void complete_error(int error, const String &msg, std::vector< MetaLog::EntityPtr > &additional)
Completes operation with error.
Address abstraction to hold either proxy name or IPv4:port address.
int64_t get_ts64()
Returns the current time in nanoseconds as a 64bit number.