0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Range.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_Range_h
28 #define Hypertable_RangeServer_Range_h
29 
44 
47 #include <Hypertable/Lib/Key.h>
51 #include <Hypertable/Lib/Schema.h>
53 
54 #include <Common/Barrier.h>
55 #include <Common/fast_clock.h>
56 #include <Common/String.h>
57 
58 #include <map>
59 #include <memory>
60 #include <mutex>
61 #include <vector>
62 
63 namespace Hypertable {
64 
67 
69  class Range {
70 
71  public:
72 
74  public:
75  int64_t compactable_memory() {
76  int64_t total = 0;
77  for (AccessGroup::MaintenanceData *ag = agdata; ag; ag = ag->next)
78  total += ag->mem_used;
79  return total;
80  }
82  const char *table_id;
84  uint64_t cells_returned;
85  uint64_t bytes_returned;
87  int64_t compact_memory;
88  int64_t soft_limit;
90  int32_t priority;
91  int16_t state;
93  uint32_t file_count;
94  uint64_t cell_count;
95  uint64_t memory_used;
96  uint64_t memory_allocated;
97  int64_t key_bytes;
98  int64_t value_bytes;
100  uint64_t disk_used;
101  uint64_t disk_estimate;
109  bool busy;
111  bool is_system;
118  };
119 
120  typedef std::map<String, AccessGroupPtr> AccessGroupMap;
121  typedef std::vector<AccessGroupPtr> AccessGroupVector;
122 
124  const RangeSpec &, RangeSet *, const RangeState &, bool needs_compaction=false);
126  virtual ~Range() {}
127  void add(const Key &key, const ByteString value);
128 
129  void lock();
130  void unlock();
131 
133 
134  void create_scanner(ScanContextPtr &scan_ctx, MergeScannerRangePtr &scanner);
135 
153  const String &table_name);
154 
156 
157  void deferred_initialization(uint32_t timeout_millis);
158 
160 
161  void get_boundary_rows(String &start, String &end) {
162  m_metalog_entity->get_boundary_rows(start, end);
163  }
164 
166  return m_metalog_entity->get_end_row();
167  }
168 
169  int64_t get_scan_revision(uint32_t timeout_ms);
170 
171  void replay_transfer_log(CommitLogReader *commit_log_reader);
172 
173  MaintenanceData *get_maintenance_data(ByteArena &arena, time_t now,
174  int flags, TableMutator *mutator=0);
175 
178  }
179 
182  }
183 
184  void update_schema(SchemaPtr &schema);
185 
186  void split();
187 
188  void relinquish();
189 
190  void compact(MaintenanceFlag::Map &subtask_map);
191 
192  void purge_memory(MaintenanceFlag::Map &subtask_map);
193 
195  bool get_relinquish() const { return m_relinquish; }
196 
198  std::lock_guard<std::mutex> lock(m_mutex);
199  for (size_t i=0; i<m_access_group_vector.size(); i++)
201  }
202 
203  void recovery_finalize();
204 
206  if (m_dropped)
207  return false;
209  if (m_dropped) {
211  return false;
212  }
213  return true;
214  }
217  }
218 
220  if (m_dropped)
221  return false;
223  if (m_dropped) {
225  return false;
226  }
227  return true;
228  }
231  }
232 
242  bool get_transfer_info(RangeTransferInfo &transfer_info, CommitLogPtr &transfer_log,
243  int64_t *latest_revisionp, bool &wait_for_maintenance) {
244  bool retval = false;
245  std::lock_guard<std::mutex> lock(m_mutex);
246 
247  wait_for_maintenance = false;
248  *latest_revisionp = m_latest_revision;
249 
250  transfer_log = m_transfer_log;
251  if (m_transfer_log)
252  retval = true;
253 
254  if (!m_split_row.empty())
255  transfer_info.set_split(m_split_row, m_split_off_high);
256  else
257  transfer_info.clear();
258 
259  if (m_capacity_exceeded_throttle == true)
260  wait_for_maintenance = true;
261 
262  return retval;
263  }
264 
265  void add_read_data(uint64_t cells_scanned, uint64_t cells_returned,
266  uint64_t bytes_scanned, uint64_t bytes_returned,
267  uint64_t disk_bytes_read) {
268  m_cells_scanned += cells_scanned;
269  m_cells_returned += cells_returned;
270  m_bytes_scanned += bytes_scanned;
271  m_bytes_returned += bytes_returned;
272  m_disk_bytes_read += disk_bytes_read;
273  }
274 
275  void add_bytes_written(uint64_t n) {
276  m_bytes_written += n;
277  }
278 
279  void add_cells_written(uint64_t n) {
280  m_cells_written += n;
281  }
282 
283  bool need_maintenance();
284 
285  bool is_root() { return m_is_root; }
286 
287  bool is_metadata() { return m_is_metadata; }
288 
289  void drop() {
292  std::lock_guard<std::mutex> lock(m_mutex);
293  m_dropped = true;
294  }
295 
297  std::lock_guard<std::mutex> lock(m_mutex);
298  return (String)m_name;
299  }
300 
301  int get_state() {
302  return m_metalog_entity->get_state();
303  }
304 
305  int32_t get_error() {
306  std::lock_guard<std::mutex> lock(m_mutex);
307  if (!m_metalog_entity->get_load_acknowledged())
309  return m_error;
310  }
311 
312  void set_needs_compaction(bool needs_compaction) {
313  std::lock_guard<std::mutex> lock(m_mutex);
314  m_metalog_entity->set_needs_compaction(needs_compaction);
315  }
316 
321  void set_compaction_type_needed(int compaction_type_needed) {
322  std::lock_guard<std::mutex> lock(m_mutex);
323  m_compaction_type_needed = compaction_type_needed;
324  }
325 
326  void acknowledge_load(uint32_t timeout_ms);
327 
329  return m_metalog_entity->get_load_acknowledged();
330  }
331 
334  const std::string get_table_id() { return m_table.id; }
335 
336  private:
337 
338  void initialize();
339 
340  void load_cell_stores();
341 
343 
344  bool cancel_maintenance();
345 
346  void relinquish_install_log();
347  void relinquish_compact();
348  void relinquish_finalize();
349 
350  bool estimate_split_row(CellList::SplitRowDataMapT &split_row_data, String &row);
351 
352  void split_install_log();
354  void split_notify_master();
355 
356  // these need to be aligned
357  uint64_t m_scans {};
358  uint64_t m_cells_scanned {};
359  uint64_t m_cells_returned {};
360  uint64_t m_cells_written {};
361  uint64_t m_updates {};
362  uint64_t m_bytes_scanned {};
363  uint64_t m_bytes_returned {};
364  uint64_t m_bytes_written {};
365  uint64_t m_disk_bytes_read {};
366 
375  AccessGroupMap m_access_group_map;
376  AccessGroupVector m_access_group_vector;
377  std::vector<AccessGroupPtr> m_column_family_vector;
381  int64_t m_split_threshold {};
387  bool m_is_root {};
388  bool m_is_metadata {};
389  bool m_unsplittable {};
391  uint64_t m_added_inserts {};
393  int32_t m_error {};
397  bool m_dropped {};
399  bool m_relinquish {};
400  bool m_initialized {};
401  };
402 
404  typedef std::shared_ptr<Range> RangePtr;
405 
406  std::ostream &operator<<(std::ostream &os, const Range::MaintenanceData &mdata);
407 
409 
410 } // namespace Hypertable
411 
412 #endif // Hypertable_RangeServer_Range_h
void split_install_log()
Definition: Range.cc:960
bool need_maintenance()
Definition: Range.cc:537
uint64_t m_added_inserts
Definition: Range.h:391
void set_compaction_type_needed(int compaction_type_needed)
Sets type of compaction needed.
Definition: Range.h:321
static std::mutex mutex
Definition: Logger.cc:43
AccessGroupMap m_access_group_map
Definition: Range.h:375
uint64_t m_bytes_written
Definition: Range.h:364
Declarations for AccessGroup.
uint64_t m_cells_written
Definition: Range.h:360
Reads and writes access group "hints" file.
void schedule_relinquish()
Definition: Range.h:194
bool m_is_root
Definition: Range.h:387
String end_row()
Definition: Range.h:165
Range specification.
Definition: RangeSpec.h:40
MetaLogEntityRangePtr m_metalog_entity
Definition: Range.h:370
int64_t m_revision
Definition: Range.h:379
int64_t m_latest_revision
Definition: Range.h:380
int32_t get_error()
Definition: Range.h:305
AccessGroupHintsFile m_hints_file
Definition: Range.h:371
std::string String
A String is simply a typedef to std::string.
Definition: String.h:44
bool load_acknowledged()
Definition: Range.h:328
Declarations for MetaLogEntityRange.
chrono::time_point< fast_clock > time_point
Definition: fast_clock.h:42
void decrement_scan_counter()
Definition: Range.h:229
void split_install_log_rollback_metadata()
Definition: Range.cc:226
uint64_t m_scans
Definition: Range.h:357
std::vector< AccessGroupPtr > AccessGroupVector
Definition: Range.h:121
Declarations for CommitLogReader.
void add_read_data(uint64_t cells_scanned, uint64_t cells_returned, uint64_t bytes_scanned, uint64_t bytes_returned, uint64_t disk_bytes_read)
Definition: Range.h:265
Declarations for TableIdentifier and TableIdentifierManaged.
bool estimate_split_row(CellList::SplitRowDataMapT &split_row_data, String &row)
Definition: Range.cc:1086
void deferred_initialization()
Definition: Range.cc:179
void drop()
Definition: Range.h:289
Declarations for fast_clock.
uint64_t m_updates
Definition: Range.h:361
const std::string get_table_id()
Get table ID.
Definition: Range.h:334
void split_compact_and_shrink()
Definition: Range.cc:1128
MaintenanceData * get_maintenance_data(ByteArena &arena, time_t now, int flags, TableMutator *mutator=0)
Definition: Range.cc:561
int64_t get_scan_revision(uint32_t timeout_ms)
Definition: Range.cc:1699
Barrier m_update_barrier
Definition: Range.h:384
Maps object pointers to bit fields.
Interface for removing a range or changing its end row in a Range set.
Definition: RangeSet.h:32
void add_cells_written(uint64_t n)
Definition: Range.h:279
void relinquish_install_log()
Definition: Range.cc:712
uint64_t m_cells_scanned
Definition: Range.h:358
bool increment_update_counter()
Definition: Range.h:205
MetaLogEntityRangePtr metalog_entity()
Definition: Range.h:132
Lib::Master::ClientPtr m_master_client
Definition: Range.h:369
void acknowledge_load(uint32_t timeout_ms)
Definition: Range.cc:1708
A Barrier to block execution of code.
Definition: Barrier.h:44
CommitLogPtr m_transfer_log
Definition: Range.h:383
void set_split(const String &split_row, bool split_off_high)
TableIdentifier m_table
Definition: Range.h:374
Declarations for Schema.
static const int64_t TIMESTAMP_MIN
Definition: KeySpec.h:34
void exit()
Leaves the critical section; will wake up/notify waiting threads if necessary.
Definition: Barrier.h:61
uint64_t m_bytes_returned
Definition: Range.h:363
int64_t m_maintenance_generation
Definition: Range.h:395
Represents a table row range.
Definition: Range.h:69
std::map< String, AccessGroupPtr > AccessGroupMap
Definition: Range.h:120
std::shared_ptr< Client > ClientPtr
Definition: Client.h:156
A class managing one or more serializable ByteStrings.
Definition: ByteString.h:47
Range(Lib::Master::ClientPtr &, const TableIdentifier &, SchemaPtr &, const RangeSpec &, RangeSet *, const RangeState &, bool needs_compaction=false)
Definition: Range.cc:70
Declarations for CellStore.
Provides the ability to mutate a table in the form of adding and deleting rows and cells...
Definition: TableMutator.h:55
uint64_t m_cells_returned
Definition: Range.h:359
void add(const Key &key, const ByteString value)
This method must not fail.
Definition: Range.cc:445
void add_bytes_written(uint64_t n)
Definition: Range.h:275
void load_cell_stores()
Definition: Range.cc:263
virtual ~Range()
Definition: Range.h:126
Declarations for RangeState.
bool m_relinquish
Definition: Range.h:399
std::map< const char *, int64_t, LtCstr, SplitRowDataAlloc > SplitRowDataMapT
Definition: CellList.h:66
void disable_maintenance()
Definition: Range.h:176
void decrement_update_counter()
Definition: Range.h:215
int get_state()
Definition: Range.h:301
void initialize()
Definition: Range.cc:93
void enable_maintenance()
Definition: Range.h:180
String get_name()
Definition: Range.h:296
uint64_t m_disk_bytes_read
Definition: Range.h:365
void compact(MaintenanceFlag::Map &subtask_map)
Definition: Range.cc:1432
bool is_root()
Definition: Range.h:285
std::shared_ptr< MergeScannerRange > MergeScannerRangePtr
Smart pointer to MergeScannerRange.
A Barrier to block execution of code.
int m_compaction_type_needed
Definition: Range.h:394
void set_needs_compaction(bool needs_compaction)
Definition: Range.h:312
void create_scanner(ScanContextPtr &scan_ctx, MergeScannerRangePtr &scanner)
Definition: Range.cc:480
int64_t m_split_threshold
Definition: Range.h:381
void relinquish_finalize()
Definition: Range.cc:823
bool is_metadata()
Definition: Range.h:287
Barrier m_scan_barrier
Definition: Range.h:385
std::ostream & operator<<(std::ostream &os, const crontab_entry &entry)
Helper function to write crontab_entry to an ostream.
Definition: Crontab.cc:301
bool get_transfer_info(RangeTransferInfo &transfer_info, CommitLogPtr &transfer_log, int64_t *latest_revisionp, bool &wait_for_maintenance)
Definition: Range.h:242
bool m_dropped
Definition: Range.h:397
Declarations for AccessGroupHintsFile.
uint64_t m_added_deletes[KEYSPEC_DELETE_MAX]
Definition: Range.h:390
bool m_split_off_high
Definition: Range.h:386
void enter()
Enters the critical section.
Definition: Barrier.h:52
AccessGroupVector m_access_group_vector
Definition: Range.h:376
LoadMetricsRange m_load_metrics
Definition: Range.h:396
bool m_capacity_exceeded_throttle
Definition: Range.h:398
Provides sequential access to blocks in a commit log.
void split_notify_master()
Definition: Range.cc:1338
std::vector< AccessGroupPtr > m_column_family_vector
Definition: Range.h:377
Declarations for RangeSpec and RangeSpecManaged.
void wait_for_complete(bool disable=false)
Hypertable definitions
bool m_is_metadata
Definition: Range.h:388
SchemaPtr m_schema
Definition: Range.h:372
bool m_initialized
Definition: Range.h:400
std::shared_ptr< MetaLogEntityRange > MetaLogEntityRangePtr
Smart pointer to MetaLogEntityRange.
uint64_t m_bytes_scanned
Definition: Range.h:362
void update_schema(SchemaPtr &schema)
Definition: Range.cc:387
std::mutex m_schema_mutex
Definition: Range.h:368
bool cancel_maintenance()
Definition: Range.cc:555
Provides access to internal components of opaque key.
Definition: Key.h:40
std::shared_ptr< Range > RangePtr
Smart pointer to Range.
Definition: Range.h:404
AccessGroup::MaintenanceData * agdata
Definition: Range.h:81
std::shared_ptr< CommitLog > CommitLogPtr
Smart pointer to CommitLog.
Definition: CommitLog.h:223
bool get_relinquish() const
Definition: Range.h:195
RangeSet * m_range_set
Definition: Range.h:392
bool increment_scan_counter()
Definition: Range.h:219
String m_split_row
Definition: Range.h:382
std::mutex m_mutex
Definition: Range.h:367
void get_boundary_rows(String &start, String &end)
Definition: Range.h:161
void purge_memory(MaintenanceFlag::Map &subtask_map)
Definition: Range.cc:1524
Declarations for MasterClient This file contains declarations for MasterClient, a client interface cl...
A String class based on std::string.
Declarations for CommitLog.
CellListScanner * create_scanner_pseudo_table(ScanContextPtr &scan_ctx, const String &table_name)
Creates a scanner over the pseudo-table indicated by table_name.
Definition: Range.cc:505
bool m_unsplittable
Definition: Range.h:389
std::shared_ptr< Schema > SchemaPtr
Smart pointer to Schema.
Definition: Schema.h:465
Range state.
Definition: RangeState.h:48
String m_name
Definition: Range.h:373
Declarations for MaintenanceFlag This file contains declarations that are part of the MaintenanceFlag...
RangeMaintenanceGuard m_maintenance_guard
Definition: Range.h:378
int32_t m_error
Definition: Range.h:393
void relinquish_compact()
Definition: Range.cc:772
void replay_transfer_log(CommitLogReader *commit_log_reader)
Called before range has been flipped live so no locking needed.
Definition: Range.cc:1641
void relinquish()
Definition: Range.cc:660
Declarations for MergeScannerRange.
void recovery_initialize()
Definition: Range.h:197
std::shared_ptr< ScanContext > ScanContextPtr
Definition: ScanContext.h:169
A helper class to put up a barrier when entering a scope and take it down when leaving the scope...
Definition: Barrier.h:93
void recovery_finalize()
This method is called when the range is offline so no locking is needed.
Definition: Range.cc:1574
void split()
Definition: Range.cc:896