48 #include <boost/algorithm/string.hpp>
64 const uint8_t *ptr =
event->payload;
65 size_t remaining =
event->payload_len;
210 HT_INFOF(
"Entering AlterTable-%lld(%s) state=%s",
223 m_context->mml_writer->record_state(shared_from_this());
236 if (original_schema->get_generation() != alter_schema->get_generation())
238 "Expected altered schema generation %lld to match original"
239 " %lld", (
Lld)alter_schema->get_generation(),
240 (
Lld)original_schema->get_generation());
242 if (!alter_schema->clear_generation_if_changed(*original_schema)) {
250 alter_schema->update_generation(generation);
259 m_schema = alter_schema->render_xml(
true);
267 m_context->mml_writer->record_state(shared_from_this());
285 for (StringSet::iterator iter=servers.begin(); iter!=servers.end(); ++iter) {
299 op_handler = make_shared<DispatchHandlerOperationAlterTable>(
m_context, table,
m_schema);
301 if (!op_handler->wait_for_completion()) {
302 std::set<DispatchHandlerOperation::Result> results;
303 op_handler->get_results(results);
304 for (
const auto &result : results) {
311 HT_WARNF(
"Alter table error at %s - %s (%s)", result.location.c_str(),
321 m_context->mml_writer->record_state(shared_from_this());
323 this_thread::sleep_for(chrono::milliseconds(5000));
327 m_context->mml_writer->record_state(shared_from_this());
334 filename = m_context->toplevel_dir +
"/tables/" +
m_id;
340 m_context->mml_writer->record_state(shared_from_this());
377 HT_FATALF(
"Unrecognized state %d", state);
425 for (
size_t i=0; i<length; i++)
428 for (
size_t i=0; i<length; i++)
444 for (
size_t i=0; i<length; i++)
448 for (
size_t i=0; i<length; i++)
458 return "OperationAlterTable";
467 if (!original_schema || !alter_schema) {
471 m_context->hyperspace->attr_get(filename,
"schema", value_buf);
486 TableParts original_parts = original_schema->get_table_parts();
487 TableParts alter_parts = alter_schema->get_table_parts();
498 TableParts original_parts = original_schema->get_table_parts();
499 TableParts alter_parts = alter_schema->get_table_parts();
std::set< String > StringSet
STL Set managing Strings.
char * decode_vstr(const uint8_t **bufp, size_t *remainp)
Decode a vstr (vint64, data, null).
Declarations for OperationToggleTableMaintenance.
#define HT_WARNF(msg,...)
TableParts get_create_index_parts(SchemaPtr &original_schema, SchemaPtr &alter_schema)
Determines which index tables to create.
The FailureInducer simulates errors.
ContextPtr m_context
Pointer to Master context.
const bool OFF
Constant representing off
String m_id
Table identifier
Request parameters for alter table operation.
std::string String
A String is simply a typedef to std::string.
Declarations for OperationDropTable.
bool force()
Gets force flag.
String format(const char *fmt,...)
Returns a String using printf like format facilities Vanilla snprintf is about 1.5x faster than this...
bool validate_subops()
Handles the results of sub operations.
virtual size_t encoded_length() const
Returns serialized object length.
Declarations for OperationCreateTable.
void decode_state_old(uint8_t version, const uint8_t **bufp, size_t *remainp) override
std::shared_ptr< Event > EventPtr
Smart pointer to Event.
size_t encoded_length_vstr(size_t len)
Computes the encoded length of vstr (vint64, data, null)
OperationAlterTable(ContextPtr &context, const MetaLog::EntityHeader &header_)
Constructor for constructing object from MetaLog entry.
const char * get_text(int32_t state)
const string & schema() const
Gets table schema.
A dynamic, resizable and reference counted memory buffer.
Represents a set of table parts (sub-tables).
uint32_t decode_i32(const uint8_t **bufp, size_t *remainp)
Decode a 32-bit integer in little-endian order.
bool get_schemas(SchemaPtr &original_schema, SchemaPtr &alter_schema)
Gets schema objects.
Declarations for ReferenceManager.
std::shared_ptr< Context > ContextPtr
Smart pointer to Context.
virtual void dependencies(DependencySet &dependencies)
TableParts m_parts
Index tables to be created or dropped.
void encode_state(uint8_t **bufp) const override
Writes serialized encoding of object state.
virtual void encode(uint8_t **bufp) const
Writes serialized representation of object to a buffer.
void set_state(int32_t state)
bool decode_bool(const uint8_t **bufp, size_t *remainp)
Decodes a boolean value from the given buffer.
const char * get_text(int error)
Returns a descriptive error message.
void add_dependency(const String &dependency)
void encode_i32(uint8_t **bufp, uint32_t val)
Encode a 32-bit integer in little-endian order.
Compatibility Macros for C/C++.
void stage_subop(std::shared_ptr< Operation > operation)
Stages a sub operation for execution.
Functions to serialize/deserialize primitives to/from a memory buffer.
void record_state()
Records operation state to the MML.
const string & name() const
Gets name of table to alter.
Time related declarations.
virtual void decode(const uint8_t **bufp, size_t *remainp)
Reads serialized representation of object from a buffer.
void execute() override
Carries out the alter table operation.
void encode_vstr(uint8_t **bufp, const void *buf, size_t len)
Encode a buffer as variable length string (vint64, data, null)
static Schema * new_instance(const std::string &buf)
Creates schema object from XML schema string.
#define HT_FATALF(msg,...)
long long int Lld
Shortcut for printf formats.
Declarations for general-purpose utility functions.
TableParts get_drop_index_parts(SchemaPtr &original_schema, SchemaPtr &alter_schema)
Determines which index tables to drop.
const bool ON
Constant representing on
String m_schema
Schema for the table
DependencySet m_dependencies
Set of dependencies.
#define HT_INFOF(msg,...)
size_t encoded_length_state() const override
Returns serialized state length.
atomically open and lock file exclusive, fail if can't
#define HT_THROWF(_code_, _fmt_,...)
uint8_t * base
Pointer to the allocated memory buffer.
bool value_index() const
Test if value index is included in set.
void get_table_server_set(ContextPtr &context, const String &id, const String &row, StringSet &servers)
Gets set of servers holding ranges for a given table.
Abstract base class for master operations.
This is a generic exception class for Hypertable.
void display_state(std::ostream &os) override
Writes human readable representation of object to output stream.
uint8_t encoding_version_state() const override
Returns encoding version.
DependencySet m_exclusivities
Set of exclusivities.
std::shared_ptr< Schema > SchemaPtr
Smart pointer to Schema.
const String name() override
Returns name of operation ("OperationAlterTable")
std::set< String > DependencySet
Set of dependency string.
StringSet m_completed
Set of range servers that have completed operation.
#define HT_MAYBE_FAIL(_label_)
void complete_ok(std::vector< MetaLog::EntityPtr > &additional)
Declarations for OperationAlterTable.
uint8_t decode_byte(const uint8_t **bufp, size_t *remainp)
Decodes a single byte from the given buffer.
Error codes, Exception handling, error logging.
Lib::Master::Request::Parameters::AlterTable m_params
Request parmaeters.
const String label() override
Returns descriptive label for operation.
void complete_error(int error, const String &msg, std::vector< MetaLog::EntityPtr > &additional)
Completes operation with error.
void decode_state(uint8_t version, const uint8_t **bufp, size_t *remainp) override
Reads serialized encoding of object state.
std::shared_ptr< DispatchHandlerOperation > DispatchHandlerOperationPtr
Smart pointer to DispatchHandlerOperation.
int64_t get_ts64()
Returns the current time in nanoseconds as a 64bit number.
int code() const
Returns the error code.
Declarations for TableParts.
Executes user-defined functions when leaving the current scope.
StringSet m_servers
Set of participating range servers.
bool qualifier_index() const
Test if qualifier index is included in set.