0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ReaderTable.cc
Go to the documentation of this file.
1 /* -*- c++ -*-
2  * Copyright (C) 2007-2013 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; either version 3
9  * of the 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 
27 
28 #include <Common/Compat.h>
29 #include "ReaderTable.h"
30 
31 #include <Hypertable/Lib/Cell.h>
33 
34 #include <Common/Logger.h>
35 
36 #include <map>
37 #include <set>
38 
39 using namespace Hypertable;
40 using namespace Hypertable::Lib::RS_METRICS;
41 using namespace std;
42 
43 void ReaderTable::get_range_metrics(const char *server, RangeMetricsMap &range_metrics) {
44  ScanSpec scan_spec;
45  RowInterval ri;
46  Cell cell;
47  String scan_start_row = format("%s:", server);
48  String scan_end_row = format("%s::", server);
49  const char *table, *end_row;
50 
51  ri.start = scan_start_row.c_str();
52  ri.end = scan_end_row.c_str();
53  ri.end_inclusive = false;
54  scan_spec.row_intervals.push_back(ri);
55  scan_spec.columns.push_back("range");
56  scan_spec.columns.push_back("range_start_row");
57  scan_spec.columns.push_back("range_move");
58 
59  TableScannerPtr scanner( m_table->create_scanner(scan_spec) );
60  while (scanner->next(cell)) {
61  table = strchr(cell.row_key, ':') + 1;
62  end_row = cell.column_qualifier;
63  HT_ASSERT(!(table == NULL || end_row == NULL));
64  String key = format("%s:%s", table, end_row);
65 
66  RangeMetricsMap::iterator rm_it = range_metrics.find(key);
67 
68  if (rm_it == range_metrics.end()) {
69  RangeMetrics rm(server, table, end_row);
70  pair<RangeMetricsMap::iterator, bool> ret = range_metrics.insert(make_pair(key, rm));
71  rm_it = ret.first;
72  }
73 
74  if (!strcmp(cell.column_family, "range"))
75  rm_it->second.add_measurement((const char*) cell.value, cell.value_len);
76  else if (!strcmp(cell.column_family, "range_start_row"))
77  rm_it->second.set_start_row((const char*) cell.value, cell.value_len);
78  else if (!strcmp(cell.column_family, "range_move"))
79  rm_it->second.set_last_move((const char*) cell.value, cell.value_len);
80  }
81 }
82 
83 void ReaderTable::get_server_metrics(vector<ServerMetrics> &server_metrics) {
84  ScanSpec scan_spec;
85  scan_spec.columns.push_back("server");
86 
87  TableScannerPtr scanner( m_table->create_scanner(scan_spec) );
88  Cell cell;
89  bool empty=true;
90 
91  while (scanner->next(cell)) {
92  HT_ASSERT(!strcmp(cell.column_family,"server"));
93  if (empty || server_metrics.back().get_id() != cell.row_key) {
94  empty = false;
95  ServerMetrics sm(cell.row_key);
96  server_metrics.push_back(sm);
97  }
98  server_metrics.back().add_measurement((const char*)cell.value, cell.value_len);
99  }
100 }
std::string String
A String is simply a typedef to std::string.
Definition: String.h:44
String format(const char *fmt,...)
Returns a String using printf like format facilities Vanilla snprintf is about 1.5x faster than this...
Definition: String.cc:37
std::map< String, RangeMetrics > RangeMetricsMap
Definition: RangeMetrics.h:104
Facilities for reading and writing sys/RS_METRICS table.
const char * column_qualifier
Definition: Cell.h:68
STL namespace.
std::shared_ptr< TableScanner > TableScannerPtr
Smart pointer to TableScanner.
Definition: TableScanner.h:124
Represents a row interval.
Definition: RowInterval.h:38
#define HT_ASSERT(_e_)
Definition: Logger.h:396
Scan predicate and control specification.
Definition: ScanSpec.h:56
Logging routines and macros.
Declarations for ReaderTable.
Compatibility Macros for C/C++.
Aggregates metrics for an individual range.
Definition: RangeMetrics.h:66
const char * row_key
Definition: Cell.h:66
Hypertable definitions
const char * column_family
Definition: Cell.h:67
RowIntervals row_intervals
Definition: ScanSpec.h:275
uint32_t value_len
Definition: Cell.h:72
Aggregates metrics for an individual RangeServer.
Definition: ServerMetrics.h:68
virtual void get_range_metrics(const char *server_id, RangeMetricsMap &range_metrics)
Definition: ReaderTable.cc:43
Encapsulates decomposed key and value.
Definition: Cell.h:32
virtual void get_server_metrics(vector< ServerMetrics > &server_metrics)
Definition: ReaderTable.cc:83
const uint8_t * value
Definition: Cell.h:71