Central authority for balance plans. More...
#include <BalancePlanAuthority.h>
Classes | |
struct | lt_move_spec |
StrictWeakOrdering class for set of RangeMoveSpecs. More... | |
struct | RecoveryPlans |
Holds plans for each range type. More... | |
Public Member Functions | |
BalancePlanAuthority (ContextPtr context, MetaLog::WriterPtr &mml_writer) | |
Constructor. More... | |
BalancePlanAuthority (ContextPtr context, MetaLog::WriterPtr &mml_writer, const MetaLog::EntityHeader &header_) | |
Constructor with MetaLog header. More... | |
virtual | ~BalancePlanAuthority () |
Destructor. More... | |
bool | is_empty () |
Determines if there are any failover balance plans. More... | |
void | create_recovery_plan (const String &location, const vector< QualifiedRangeSpec > &root_specs, const vector< RangeState > &root_states, const vector< QualifiedRangeSpec > &metadata_specs, const vector< RangeState > &metadata_states, const vector< QualifiedRangeSpec > &system_specs, const vector< RangeState > &system_states, const vector< QualifiedRangeSpec > &user_specs, const vector< RangeState > &user_states) |
Creates a recovery plan for a failed range server. More... | |
void | copy_recovery_plan (const String &location, int type, RangeServerRecovery::Plan &out, int &plan_generation) |
Copies part of a recovery plan for a failed range server. More... | |
void | remove_recovery_plan (const String &location) |
Removes a recovery plan for a failed range server. More... | |
void | remove_from_receiver_plan (const String &location, int type, const vector< QualifiedRangeSpec > &ranges) |
Removes ranges from a failover plan. More... | |
void | remove_table_from_receiver_plan (const String &table_id) |
Removes range move specifications for a table. More... | |
void | change_receiver_plan_location (const String &location, int type, const String &old_destination, const String &new_destination) |
Modifies all failover plans by changing moves to a given destination to a new one. More... | |
void | get_receiver_plan_locations (const String &location, int type, StringSet &locations) |
Returns the list of receiver location for a recovery plan. More... | |
bool | recovery_complete (const String &location, int type) |
Checks if recovery plan of given type has been removed. More... | |
int | get_generation () |
Returns the current generation number. More... | |
void | set_generation (int new_generation) |
Sets the generation number (TESTING ONLY). More... | |
void | clear_current_set () |
Clears the m_current_set of move specifications (TESTING ONLY). More... | |
bool | register_balance_plan (BalancePlanPtr &plan, int generation, std::vector< MetaLog::EntityPtr > &entities) |
Registers a new balance plan for load balancing purposes. More... | |
bool | get_balance_destination (const TableIdentifier &table, const RangeSpec &range, String &location) |
Returns the balance plan destination for a given range. More... | |
void | balance_move_complete (const TableIdentifier &table, const RangeSpec &range) |
Signals that range move is complete. More... | |
void | set_mml_writer (MetaLog::WriterPtr &mml_writer) |
Sets the MML writer Sets m_mml_writer to mml_writer More... | |
const String | name () override |
Returns the name of this entity ("BalancePlanAuthority") More... | |
void | display (std::ostream &os) override |
Writes a human-readable represenation of object to an output stream. More... | |
void | decode (const uint8_t **bufp, size_t *remainp, uint16_t definition_version) override |
Reads serialized encoding of object. More... | |
Public Member Functions inherited from Hypertable::MetaLog::Entity | |
Entity (int32_t type) | |
Constructor from entity type. More... | |
Entity (const EntityHeader &header_) | |
Constructor from entity header. More... | |
virtual | ~Entity () |
Destructor. More... | |
void | lock () |
Locks the entity's mutex. More... | |
void | unlock () |
Unlocks the entity's mutex. More... | |
void | mark_for_removal () |
Marks entity for removal. More... | |
bool | marked_for_removal () |
Checks if entity is marked for removal. More... | |
int64_t | id () const |
Returns the entity ID. More... | |
Public Member Functions inherited from Hypertable::Serializable | |
virtual size_t | encoded_length () const |
Returns serialized object length. More... | |
virtual void | encode (uint8_t **bufp) const |
Writes serialized representation of object to a buffer. More... | |
virtual void | decode (const uint8_t **bufp, size_t *remainp) |
Reads serialized representation of object from a buffer. More... | |
Private Types | |
typedef std::map< String, RecoveryPlans > | RecoveryPlanMap |
Server-to-plan map. More... | |
typedef std::set < RangeMoveSpecPtr, lt_move_spec > | MoveSetT |
Set of RangeMoveSpecPtr. More... | |
Private Member Functions | |
uint8_t | encoding_version () const override |
Returns encoding version. More... | |
size_t | encoded_length_internal () const override |
Returns internal serialized length. More... | |
void | encode_internal (uint8_t **bufp) const override |
Writes serialized representation of object to a buffer. More... | |
void | decode_internal (uint8_t version, const uint8_t **bufp, size_t *remainp) override |
Reads serialized representation of object from a buffer. More... | |
void | decode_old (const uint8_t **bufp, size_t *remainp) |
RangeServerRecovery::PlanPtr | create_range_plan (const String &location, int type, const vector< QualifiedRangeSpec > &specs, const vector< RangeState > &states) |
Creates a recovery plan for a failed server. More... | |
void | update_range_plan (RangeServerRecovery::PlanPtr &plan, const String &location, const vector< QualifiedRangeSpec > &new_specs) |
Modifies recovery plan, replacing moves to location with a new destination. More... | |
Private Attributes | |
ContextPtr | m_context |
Pointer to master context. More... | |
MetaLog::WriterPtr | m_mml_writer |
Pointer to MML writer. More... | |
int | m_generation |
Generation number (incremented with each new failover plan) More... | |
StringSet | m_active |
Cache of active (available) servers. More... | |
StringSet::iterator | m_active_iter |
Iterator pointing into m_active. More... | |
RecoveryPlanMap | m_map |
Mapping from failed range server to recovery plan. More... | |
MoveSetT | m_current_set |
Current set of move specifications for move operations. More... | |
Additional Inherited Members | |
Protected Member Functions inherited from Hypertable::MetaLog::Entity | |
void | encode_entry (uint8_t **bufp) |
Encodes entity header plus serialized state. More... | |
Protected Attributes inherited from Hypertable::MetaLog::Entity | |
std::mutex | m_mutex |
Mutex for serializing access to members More... | |
EntityHeader | header |
Entity header More... | |
Central authority for balance plans.
This class maintains all currently active balance plans. A balance plan is a specification for the movement of a set of ranges from their current location to a new location. Balance plans are created in the following circumstances:
There is one object of this class maintained by the Master and it is persisted to the MML each time its state changes.
Definition at line 67 of file BalancePlanAuthority.h.
|
private |
Set of RangeMoveSpecPtr.
Definition at line 392 of file BalancePlanAuthority.h.
|
private |
Server-to-plan map.
Definition at line 369 of file BalancePlanAuthority.h.
BalancePlanAuthority::BalancePlanAuthority | ( | ContextPtr | context, |
MetaLog::WriterPtr & | mml_writer | ||
) |
Constructor.
This constructor constructs an empty object. Persists the object state in the MML.
context | Master context |
mml_writer | MML writer for persisting state changes |
Definition at line 45 of file BalancePlanAuthority.cc.
BalancePlanAuthority::BalancePlanAuthority | ( | ContextPtr | context, |
MetaLog::WriterPtr & | mml_writer, | ||
const MetaLog::EntityHeader & | header_ | ||
) |
Constructor with MetaLog header.
This constructor constructs an empty object to be populated by an MML entity.
context | Master context |
mml_writer | MML writer for persisting state changes |
header_ | MML entity header |
Definition at line 53 of file BalancePlanAuthority.cc.
|
inlinevirtual |
Destructor.
Definition at line 89 of file BalancePlanAuthority.h.
void BalancePlanAuthority::balance_move_complete | ( | const TableIdentifier & | table, |
const RangeSpec & | range | ||
) |
Signals that range move is complete.
This method removes the range identified by table
and range
from m_current_set.
table | Table identifer of range |
range | RangeSpec identifying range |
Definition at line 597 of file BalancePlanAuthority.cc.
void BalancePlanAuthority::change_receiver_plan_location | ( | const String & | location, |
int | type, | ||
const String & | old_destination, | ||
const String & | new_destination | ||
) |
Modifies all failover plans by changing moves to a given destination to a new one.
location | Proxy name of server identifying recovery plan ("*" implies all recovery plans) |
type | Type of failover plan to modify (see RangeSpec::Type) |
old_destination | Existing destination to replace |
new_destination | New destination to replace old_destination |
Definition at line 171 of file BalancePlanAuthority.cc.
|
inline |
Clears the m_current_set of move specifications (TESTING ONLY).
Definition at line 219 of file BalancePlanAuthority.h.
void BalancePlanAuthority::copy_recovery_plan | ( | const String & | location, |
int | type, | ||
RangeServerRecovery::Plan & | out, | ||
int & | plan_generation | ||
) |
Copies part of a recovery plan for a failed range server.
location | Proxy name of failed server |
type | Range type indicating portion of recovery plan to copy (see RangeSpec::Type). |
out | Out parameter to hold copy of recovery plan |
plan_generation | Out parameter filled in with current generation number |
Definition at line 97 of file BalancePlanAuthority.cc.
|
private |
Creates a recovery plan for a failed server.
Creates a new recovery plan for a failed server for the ranges of type type
. It allocates a RangeServerRecovery::Plan object and adds specs
and states
to the receiver plan and assigns destinations by walking m_active in round-robin fashion. It also populates the replay plan by reading the list of fragments of the failed servers commit log
/hypertable/servers/location
/log/type
and assigns each fragment to a server by walking m_active in round-robin fashion.
location | Proxy name of failed server |
type | Type of recovery plan (see RangeSpec::Type) |
specs | Vector of ranges to be moved |
states | Vector of range states (parallels specs ) |
Definition at line 453 of file BalancePlanAuthority.cc.
void BalancePlanAuthority::create_recovery_plan | ( | const String & | location, |
const vector< QualifiedRangeSpec > & | root_specs, | ||
const vector< RangeState > & | root_states, | ||
const vector< QualifiedRangeSpec > & | metadata_specs, | ||
const vector< RangeState > & | metadata_states, | ||
const vector< QualifiedRangeSpec > & | system_specs, | ||
const vector< RangeState > & | system_states, | ||
const vector< QualifiedRangeSpec > & | user_specs, | ||
const vector< RangeState > & | user_states | ||
) |
Creates a recovery plan for a failed range server.
When a range server fails, all of its ranges are reassigned to new range servers. Recovery of ranges needs to happen in the following order:
This method is called by OperationRecover to create and register a balance plan for a failed range server. This method sets the "removed" bit on the RangeServerConnection object associated with the failed server and persists the modified RangeServerConnection object and this object's state as a single write to the MML.
location | Proxy name for failed range server |
root_specs | Vector holding ROOT range spec |
root_states | Vector holding ROOT range state |
metadata_specs | Vector holding METADATA range specs |
metadata_states | Vector holding METADATA range states |
system_specs | Vector holding SYSTEM range specs |
system_states | Vector holding SYSTEM range states |
user_specs | Vector holding USER range specs |
user_states | Vector holding USER range states |
Put the RangeServerConnection object into the 'removed' state and then atomically persist both the RangeServerConnection object and the plan to the MML
Definition at line 342 of file BalancePlanAuthority.cc.
|
overridevirtual |
Reads serialized encoding of object.
This method restores the state of the object by decoding a serialized representation of the state from the memory location pointed to by *bufp
. See encode() for a description of the serialized format.
bufp | Address of source buffer pointer (advanced by call) |
remainp | Amount of remaining buffer pointed to by *bufp (decremented by call). |
definition_version | Version of DefinitionMaster |
Reimplemented from Hypertable::MetaLog::Entity.
Definition at line 79 of file BalancePlanAuthority.cc.
|
overrideprivatevirtual |
Reads serialized representation of object from a buffer.
This function is to be overridden by derived classes and should decode the object per-se as encoded with encode_internal().
version | Encoding version |
bufp | Address of destination buffer pointer (advanced by call) |
remainp | Address of integer holding amount of serialized encoding remaining |
Implements Hypertable::Serializable.
Definition at line 282 of file BalancePlanAuthority.cc.
|
private |
Definition at line 311 of file BalancePlanAuthority.cc.
|
overridevirtual |
Writes a human-readable represenation of object to an output stream.
This method writes a human-readable represenation of the object to the output stream os
. The string written starts with the generation number and is followed by all of the failover plans.
os | Output stream to write to |
Reimplemented from Hypertable::MetaLog::Entity.
Definition at line 61 of file BalancePlanAuthority.cc.
|
overrideprivatevirtual |
Writes serialized representation of object to a buffer.
This function is to be overridden by derived classes and should encode the object per-se.
bufp | Address of destination buffer pointer (advanced by call) |
Implements Hypertable::Serializable.
Definition at line 261 of file BalancePlanAuthority.cc.
|
overrideprivatevirtual |
Returns internal serialized length.
This function is to be overridden by derived classes and should return the length of the the serialized object per-se.
Implements Hypertable::Serializable.
Definition at line 243 of file BalancePlanAuthority.cc.
|
overrideprivatevirtual |
Returns encoding version.
Implements Hypertable::Serializable.
Definition at line 239 of file BalancePlanAuthority.cc.
bool BalancePlanAuthority::get_balance_destination | ( | const TableIdentifier & | table, |
const RangeSpec & | range, | ||
String & | location | ||
) |
Returns the balance plan destination for a given range.
This method looks up the range identified by table
and range
in m_current_set and returns the destination. If the range does not exist in m_current_set, a new destination is chosen and a new entry is added to m_current_set. If m_current_set was modified, the object state is persisted to the MML
table | Table identifier of range to look up |
range | RangeSpec of range to lookup |
location | Output parameter to hold destination |
Definition at line 566 of file BalancePlanAuthority.cc.
|
inline |
Returns the current generation number.
The generation number (m_generation) starts out at zero and is incremented each time a new plan is created for a failed range server.
Definition at line 207 of file BalancePlanAuthority.h.
void BalancePlanAuthority::get_receiver_plan_locations | ( | const String & | location, |
int | type, | ||
StringSet & | locations | ||
) |
Returns the list of receiver location for a recovery plan.
location | Proxy name of server identifying recovery plan |
type | Type of recovery plan (see RangeSpec::Type) |
locations | Output parameter filled in with recceiver locations |
Definition at line 212 of file BalancePlanAuthority.cc.
bool BalancePlanAuthority::is_empty | ( | ) |
Determines if there are any failover balance plans.
This method determines if there are any registered balance plans due to a range server failure. No failover plans are registered is m_map is empty
Definition at line 234 of file BalancePlanAuthority.cc.
|
inlineoverridevirtual |
Returns the name of this entity ("BalancePlanAuthority")
Implements Hypertable::MetaLog::Entity.
Definition at line 273 of file BalancePlanAuthority.h.
bool BalancePlanAuthority::recovery_complete | ( | const String & | location, |
int | type | ||
) |
Checks if recovery plan of given type has been removed.
location | Proxy name of server identifying recovery plan |
type | Type of recovery plan (see RangeSpec::Type) |
location
, type
has been removed, false otherwise. Definition at line 223 of file BalancePlanAuthority.cc.
bool BalancePlanAuthority::register_balance_plan | ( | BalancePlanPtr & | plan, |
int | generation, | ||
std::vector< MetaLog::EntityPtr > & | entities | ||
) |
Registers a new balance plan for load balancing purposes.
This method registers the balance plan plan
by adding all of the moves in plan
to m_current_set. It only registers the plan if generation
matches the current generation number. After successfully registering the balance plan, the object state is persisted to the MML along with the entities supplied in entities
.
plan | Balance plan to register |
generation | Required generation number |
entities | Additional entities to persist in MML. |
Definition at line 541 of file BalancePlanAuthority.cc.
void BalancePlanAuthority::remove_from_receiver_plan | ( | const String & | location, |
int | type, | ||
const vector< QualifiedRangeSpec > & | ranges | ||
) |
Removes ranges from a failover plan.
This method removes the set of ranges specified by ranges
from the failover plan for server location
. Once the ranges have been moved, the new state is persisted to the MML.
location | Proxy name identifying failover plan |
type | Type of failover plan (see RangeSpec::Type) |
ranges | Vector of ranges to remove from plan. |
Definition at line 129 of file BalancePlanAuthority.cc.
void BalancePlanAuthority::remove_recovery_plan | ( | const String & | location | ) |
Removes a recovery plan for a failed range server.
This method removes the recovery plan associated with server location
and persists the new state in the MML. This method is called after recovery is finished for location
.
location | Proxy name of plan to remove |
Definition at line 116 of file BalancePlanAuthority.cc.
void BalancePlanAuthority::remove_table_from_receiver_plan | ( | const String & | table_id | ) |
Removes range move specifications for a table.
This method removes all of the move specifications for the table identified by table_id
from all of the failover plans.
table_id | Table identifier of move specs to remove |
Definition at line 146 of file BalancePlanAuthority.cc.
|
inline |
Sets the generation number (TESTING ONLY).
new_generation | New generation number |
Definition at line 212 of file BalancePlanAuthority.h.
void BalancePlanAuthority::set_mml_writer | ( | MetaLog::WriterPtr & | mml_writer | ) |
Sets the MML writer Sets m_mml_writer to mml_writer
mml_writer | Smart pointer to MML writer |
Definition at line 90 of file BalancePlanAuthority.cc.
|
private |
Modifies recovery plan, replacing moves to location
with a new destination.
This method modifies the given recovery plan by replacing references to location
with other active servers. It is called by create_recovery_plan() to replace the failed server identified by location
from existing recovery plans.
plan | Recovery plan to modify |
location | Proxy name of server being recovered |
new_specs | Vector of QualifiedRangeSpec objects to remove from receiver plan |
Definition at line 499 of file BalancePlanAuthority.cc.
|
private |
Cache of active (available) servers.
Definition at line 355 of file BalancePlanAuthority.h.
|
private |
Iterator pointing into m_active.
Definition at line 358 of file BalancePlanAuthority.h.
|
private |
Pointer to master context.
Definition at line 346 of file BalancePlanAuthority.h.
|
private |
Current set of move specifications for move operations.
Definition at line 395 of file BalancePlanAuthority.h.
|
private |
Generation number (incremented with each new failover plan)
Definition at line 352 of file BalancePlanAuthority.h.
|
private |
Mapping from failed range server to recovery plan.
Definition at line 372 of file BalancePlanAuthority.h.
|
private |
Pointer to MML writer.
Definition at line 349 of file BalancePlanAuthority.h.