0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
BalancePlanAuthority.h
Go to the documentation of this file.
1 /*
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 
28 #ifndef Hypertable_Master_BalancePlanAuthority_h
29 #define Hypertable_Master_BalancePlanAuthority_h
30 
31 #include <map>
32 
33 #include <boost/thread/condition.hpp>
34 
38 
39 #include "Context.h"
40 
41 namespace Hypertable {
42 
43  using namespace Lib;
44 
47 
68  public:
69 
77 
86  const MetaLog::EntityHeader &header_);
87 
89  virtual ~BalancePlanAuthority() { }
90 
97  bool is_empty();
98 
124  void create_recovery_plan(const String &location,
125  const vector<QualifiedRangeSpec> &root_specs,
126  const vector<RangeState> &root_states,
127  const vector<QualifiedRangeSpec> &metadata_specs,
128  const vector<RangeState> &metadata_states,
129  const vector<QualifiedRangeSpec> &system_specs,
130  const vector<RangeState> &system_states,
131  const vector<QualifiedRangeSpec> &user_specs,
132  const vector<RangeState> &user_states);
133 
142  void copy_recovery_plan(const String &location, int type,
143  RangeServerRecovery::Plan &out, int &plan_generation);
144 
152  void remove_recovery_plan(const String &location);
153 
162  void remove_from_receiver_plan(const String &location, int type,
163  const vector<QualifiedRangeSpec> &ranges);
164 
171  void remove_table_from_receiver_plan(const String &table_id);
172 
182  void change_receiver_plan_location(const String &location, int type,
183  const String &old_destination,
184  const String &new_destination);
185 
191  void get_receiver_plan_locations(const String &location, int type,
192  StringSet &locations);
193 
200  bool recovery_complete(const String &location, int type);
201 
207  int get_generation() { std::lock_guard<std::mutex> lock(m_mutex); return m_generation; }
208 
212  void set_generation(int new_generation) {
213  std::lock_guard<std::mutex> lock(m_mutex);
214  m_generation = new_generation;
215  }
216 
220  m_current_set.clear();
221  }
222 
236  bool register_balance_plan(BalancePlanPtr &plan, int generation,
237  std::vector<MetaLog::EntityPtr> &entities);
238 
252  bool get_balance_destination(const TableIdentifier &table,
253  const RangeSpec &range, String &location);
254 
261  void balance_move_complete(const TableIdentifier &table,
262  const RangeSpec &range);
263 
268  void set_mml_writer(MetaLog::WriterPtr &mml_writer);
269 
273  const String name() override { return "BalancePlanAuthority"; }
274 
281  void display(std::ostream &os) override;
282 
293  void decode(const uint8_t **bufp, size_t *remainp,
294  uint16_t definition_version) override;
295 
296  private:
297 
298  uint8_t encoding_version() const override;
299 
300  size_t encoded_length_internal() const override;
301 
302  void encode_internal(uint8_t **bufp) const override;
303 
304  void decode_internal(uint8_t version, const uint8_t **bufp,
305  size_t *remainp) override;
306 
307  void decode_old(const uint8_t **bufp, size_t *remainp);
308 
327  RangeServerRecovery::PlanPtr create_range_plan(const String &location, int type,
328  const vector<QualifiedRangeSpec> &specs,
329  const vector<RangeState> &states);
330 
342  void update_range_plan(RangeServerRecovery::PlanPtr &plan, const String &location,
343  const vector<QualifiedRangeSpec> &new_specs);
344 
347 
350 
353 
356 
358  StringSet::iterator m_active_iter;
359 
364  struct RecoveryPlans {
366  };
367 
369  typedef std::map<String, RecoveryPlans> RecoveryPlanMap;
370 
372  RecoveryPlanMap m_map;
373 
377  struct lt_move_spec {
378  bool operator()(const RangeMoveSpecPtr &ms1,
379  const RangeMoveSpecPtr &ms2) const {
380  int cmp = strcmp(ms1->table.id, ms2->table.id);
381  if (cmp < 0)
382  return true;
383  else if (cmp == 0) {
384  if (ms1->range < ms2->range)
385  return true;
386  }
387  return false;
388  }
389  };
390 
392  typedef std::set<RangeMoveSpecPtr, lt_move_spec> MoveSetT;
393 
395  MoveSetT m_current_set;
396  };
397 
399  typedef std::shared_ptr<BalancePlanAuthority> BalancePlanAuthorityPtr;
400 
402 
403 }
404 
405 #endif // Hypertable_Master_BalancePlanAuthority_h
std::set< String > StringSet
STL Set managing Strings.
Definition: StringExt.h:42
void set_generation(int new_generation)
Sets the generation number (TESTING ONLY).
Range specification.
Definition: RangeSpec.h:40
int get_generation()
Returns the current generation number.
Declarations for Plan.
std::string String
A String is simply a typedef to std::string.
Definition: String.h:44
std::shared_ptr< BalancePlan > BalancePlanPtr
Definition: BalancePlan.h:81
std::set< RangeMoveSpecPtr, lt_move_spec > MoveSetT
Set of RangeMoveSpecPtr.
MetaLog::WriterPtr m_mml_writer
Pointer to MML writer.
RangeServer recovery plan.
Definition: Plan.h:49
std::shared_ptr< Context > ContextPtr
Smart pointer to Context.
Definition: Context.h:265
Base class for MetaLog entities.
Definition: MetaLogEntity.h:62
bool operator()(const RangeMoveSpecPtr &ms1, const RangeMoveSpecPtr &ms2) const
MoveSetT m_current_set
Current set of move specifications for move operations.
ContextPtr m_context
Pointer to master context.
Hypertable definitions
Declarations for MetaLog::Writer.
Central authority for balance plans.
std::map< String, RecoveryPlans > RecoveryPlanMap
Server-to-plan map.
const String name() override
Returns the name of this entity ("BalancePlanAuthority")
std::shared_ptr< Writer > WriterPtr
Smart pointer to Writer.
std::shared_ptr< Plan > PlanPtr
Smart pointer to Plan.
Definition: Plan.h:102
StrictWeakOrdering class for set of RangeMoveSpecs.
virtual ~BalancePlanAuthority()
Destructor.
std::shared_ptr< RangeMoveSpec > RangeMoveSpecPtr
void clear_current_set()
Clears the m_current_set of move specifications (TESTING ONLY).
int m_generation
Generation number (incremented with each new failover plan)
std::shared_ptr< BalancePlanAuthority > BalancePlanAuthorityPtr
Smart pointer to BalancePlanAuthority.
StringSet::iterator m_active_iter
Iterator pointing into m_active.
Declarations for Context.
RecoveryPlanMap m_map
Mapping from failed range server to recovery plan.
StringSet m_active
Cache of active (available) servers.