0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
TableInfo.h
Go to the documentation of this file.
1 /* -*- c++ -*-
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 
26 
27 #ifndef Hypertable_RangeServer_TableInfo_h
28 #define Hypertable_RangeServer_TableInfo_h
29 
32 
36 
37 #include <AsyncComm/Clock.h>
38 
39 #include <Common/StringExt.h>
40 
41 #include <algorithm>
42 #include <condition_variable>
43 #include <iterator>
44 #include <memory>
45 #include <mutex>
46 #include <set>
47 #include <string>
48 
49 namespace Hypertable {
50 
53 
55  class RangeData {
56  public:
61 
64 
67  };
68 
72  class Ranges {
73  public:
77  template<typename Func>
78  void remove_if(Func pred) {
79  std::vector<RangeData> stripped;
80  stripped.reserve(array.size());
81  remove_copy_if(array.begin(), array.end(), back_inserter(stripped), pred);
82  array.swap(stripped);
83  }
85  std::vector<RangeData> array;
88  };
89 
91  typedef std::shared_ptr<Ranges> RangesPtr;
92 
94  class RangeInfo {
95  public:
100  : start_row(start_row), end_row(end_row) { }
107  };
108 
110  inline bool operator < (const RangeInfo &lhs, const RangeInfo &rhs) {
111  return lhs.end_row.compare(rhs.end_row) < 0;
112  }
113 
114 
115  class Schema;
116 
118  class TableInfo : public RangeSet {
119  public:
120 
127  SchemaPtr &schema, bool maintenance_disabled);
128 
130  virtual ~TableInfo() { }
131 
137  virtual bool remove(const String &start_row, const String &end_row);
138 
147  virtual void change_end_row(const String &start_row, const String &old_end_row,
148  const String &new_end_row);
149 
158  virtual void change_start_row(const String &old_start_row, const String &new_start_row,
159  const String &end_row);
160 
164  std::lock_guard<std::mutex> lock(m_mutex);
165  return m_schema;
166  }
167 
172  std::lock_guard<std::mutex> lock(m_mutex);
173  return m_maintenance_disabled;
174  }
175 
178  void set_maintenance_disabled(bool val) {
179  std::lock_guard<std::mutex> lock(m_mutex);
181  }
182 
189  void update_schema(SchemaPtr &schema);
190 
195  bool get_range(const RangeSpec &range_spec, RangePtr &range);
196 
201  bool has_range(const RangeSpec &range_spec);
202 
207  bool remove_range(const RangeSpec &range_spec, RangePtr &range);
208 
223  void stage_range(const RangeSpec &range_spec,
225 
230  void unstage_range(const RangeSpec &range_spec);
231 
237  void promote_staged_range(RangePtr &range);
238 
247  void add_range(RangePtr &range, bool remove_if_exists = false);
248 
260  bool find_containing_range(const String &row, RangePtr &range,
261  String &start_row, String &end_row);
262 
270  bool includes_row(const String &row) const;
271 
274  void get_ranges(Ranges &ranges);
275 
278  size_t get_range_count();
279 
281  void clear();
282 
286 
287  private:
288 
291 
293  std::condition_variable m_cond;
294 
297 
300 
302  std::set<RangeInfo> m_active_set;
303 
305  std::set<RangeInfo> m_staged_set;
306 
309  };
310 
312  typedef std::shared_ptr<TableInfo> TableInfoPtr;
313 
315 
316 }
317 
318 #endif // Hypertable_RangeServer_TableInfo_h
void remove_if(Func pred)
Template function for removing ranges that satisfy a predicate.
Definition: TableInfo.h:78
bool remove_range(const RangeSpec &range_spec, RangePtr &range)
Removes the range specified by the given RangeSpec from the active set.
Definition: TableInfo.cc:141
RangePtr range
Smart pointer to Range object.
Definition: TableInfo.h:106
RangeData(RangePtr r, Range::MaintenanceData *md=0)
Constructor.
Definition: TableInfo.h:60
static std::mutex mutex
Definition: Logger.cc:43
void stage_range(const RangeSpec &range_spec, std::chrono::fast_clock::time_point deadline)
Stages a range to being added.
Definition: TableInfo.cc:163
Schema specification.
Definition: Schema.h:52
void clear()
Clears the active range set.
Definition: TableInfo.cc:272
bool has_range(const RangeSpec &range_spec)
Checks if range corresponding to the given RangeSpec exists in the active set.
Definition: TableInfo.cc:132
virtual void change_end_row(const String &start_row, const String &old_end_row, const String &new_end_row)
Changes the end row of a range in the active set.
Definition: TableInfo.cc:65
Range specification.
Definition: RangeSpec.h:40
Holds set of range objects for a table.
Definition: TableInfo.h:118
std::string String
A String is simply a typedef to std::string.
Definition: String.h:44
chrono::time_point< fast_clock > time_point
Definition: fast_clock.h:42
Declarations for TableIdentifier and TableIdentifierManaged.
void set_maintenance_disabled(bool val)
Sets the maintenance disabled flag.
Definition: TableInfo.h:178
std::condition_variable m_cond
Condition variable signalled on m_staged_set change.
Definition: TableInfo.h:293
void update_schema(SchemaPtr &schema)
Updates schema, propagating change to all ranges in active set.
Definition: TableInfo.cc:278
Interface for removing a range or changing its end row in a Range set.
Definition: RangeSet.h:32
String end_row
Cached end row of range.
Definition: TableInfo.h:104
std::set< RangeInfo > m_active_set
Set of active ranges.
Definition: TableInfo.h:302
Wrapper for TableIdentifier providing member storage.
Declaration of ClockT.
bool find_containing_range(const String &row, RangePtr &range, String &start_row, String &end_row)
Finds the range to which the given row belongs.
Definition: TableInfo.cc:234
void get_ranges(Ranges &ranges)
Fills Ranges vector with ranges from the active set.
Definition: TableInfo.cc:259
std::set< RangeInfo > m_staged_set
Set of staged ranges (soon to become active)
Definition: TableInfo.h:305
bool m_maintenance_disabled
Flag indicating if maintenance is disabled for table.
Definition: TableInfo.h:308
ByteArena arena
Memory arena.
Definition: TableInfo.h:87
std::vector< RangeData > array
Vector of RangeData objects.
Definition: TableInfo.h:85
TableIdentifier & identifier()
Returns a reference to the table identifier.
Definition: TableInfo.h:285
RangeInfo(const String &start_row, const String &end_row)
Constructor.
Definition: TableInfo.h:99
bool maintenance_disabled()
Checks if maintenance has been disabled for this table.
Definition: TableInfo.h:171
TableInfo(const TableIdentifier *identifier, SchemaPtr &schema, bool maintenance_disabled)
Constructor.
Definition: TableInfo.cc:35
bool get_range(const RangeSpec &range_spec, RangePtr &range)
Returns range object corresponding to the given RangeSpec.
Definition: TableInfo.cc:116
void add_range(RangePtr &range, bool remove_if_exists=false)
Adds a range to the active set.
Definition: TableInfo.cc:217
Declarations for Range.
void promote_staged_range(RangePtr &range)
Promotes a range from the staged set to the active set.
Definition: TableInfo.cc:204
Declarations for RangeSpec and RangeSpecManaged.
Holds pointer to range and cached start and end rows.
Definition: TableInfo.h:94
SchemaPtr get_schema()
Returns a pointer to the schema object.
Definition: TableInfo.h:163
bool operator<(const directory_entry< _Key, _Tp > &lhs, const directory_entry< _Key, _Tp > &rhs)
Definition: directory.h:128
Hypertable definitions
size_t get_range_count()
Returns the number of ranges in the active set.
Definition: TableInfo.cc:266
void unstage_range(const RangeSpec &range_spec)
Unstages a previously staged range.
Definition: TableInfo.cc:195
std::shared_ptr< TableInfo > TableInfoPtr
Smart pointer to TableInfo.
Definition: TableInfo.h:312
bool includes_row(const String &row) const
Checks to see if a given row belongs to any of the ranges in the active set.
Definition: TableInfo.cc:251
std::shared_ptr< Range > RangePtr
Smart pointer to Range.
Definition: Range.h:404
String start_row
Cached start row of range.
Definition: TableInfo.h:102
Declarations for MasterClient This file contains declarations for MasterClient, a client interface cl...
std::shared_ptr< Schema > SchemaPtr
Smart pointer to Schema.
Definition: Schema.h:465
virtual void change_start_row(const String &old_start_row, const String &new_start_row, const String &end_row)
Changes the start row of a range in the active set.
Definition: TableInfo.cc:90
TableIdentifierManaged m_identifier
Table identifier
Definition: TableInfo.h:296
std::mutex m_mutex
Mutex for serializing member access
Definition: TableInfo.h:290
String extensions and helpers: sets, maps, append operators etc.
Holds pointers to a Range and associated Range::MaintenanceData.
Definition: TableInfo.h:55
Range::MaintenanceData * data
Pointer to maintenance data for range.
Definition: TableInfo.h:66
SchemaPtr m_schema
Table schema object
Definition: TableInfo.h:299
virtual ~TableInfo()
Destructor.
Definition: TableInfo.h:130
Holds vector of RangeData objects and memory arena.
Definition: TableInfo.h:72
RangePtr range
Pointer to Range.
Definition: TableInfo.h:63
std::shared_ptr< Ranges > RangesPtr
Smart pointer to Ranges.
Definition: TableInfo.h:91