0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
TableDumper.cc
Go to the documentation of this file.
1 
22 #include "Common/Compat.h"
23 #include <vector>
24 
25 #include "Common/Error.h"
26 #include "Common/Random.h"
27 #include "Common/String.h"
28 
29 #include "Table.h"
30 #include "TableDumper.h"
31 
32 extern "C" {
33 #include <poll.h>
34 }
35 
36 using namespace Hypertable;
37 
38 
41 TableDumper::TableDumper(NamespacePtr &ns, const string &name,
42  ScanSpec &scan_spec, size_t target_node_count)
43  : m_scan_spec(scan_spec), m_eod(false) {
44  TableScannerPtr scanner;
45  RowInterval ri;
46 
47  ns->get_table_splits(name, m_splits);
48 
49  // Create random m_ordering
50  m_ordering.reserve(m_splits.size());
51  for (size_t i=0; i<m_splits.size(); ++i)
52  m_ordering.push_back(i);
53  uint32_t tmp, n;
54  for (size_t base=0,nleft=m_ordering.size(); base<m_ordering.size(); ++base,--nleft) {
55  n = Random::number32() % nleft;
56  if (n > 0) {
57  tmp = m_ordering[base];
58  m_ordering[base] = m_ordering[n];
59  m_ordering[n] = tmp;
60  }
61  }
62 
63  m_table = ns->open_table(name);
64 
65  for (m_next=0; m_next<target_node_count && m_next < m_ordering.size(); m_next++) {
66  m_scan_spec.row_intervals.clear();
67  ri.start = m_splits[m_ordering[m_next]].start_row;
68  ri.start_inclusive = false;
69  ri.end = m_splits[m_ordering[m_next]].end_row;
70  ri.end_inclusive = true;
71  m_scan_spec.row_intervals.push_back(ri);
72  scanner.reset( m_table->create_scanner(m_scan_spec) );
73  m_scanners.push_back( scanner );
74  }
75 
76  m_scanner_iter = m_scanners.begin();
77  if (m_scanner_iter == m_scanners.end())
78  m_eod = true;
79 
80 }
81 
82 
83 bool TableDumper::next(Cell &cell) {
84 
85  if (m_eod)
86  return false;
87 
88  do {
89 
90  if ((*m_scanner_iter)->next(cell)) {
91  if (++m_scanner_iter == m_scanners.end())
92  m_scanner_iter = m_scanners.begin();
93  return true;
94  }
95 
96  // add another scanner
97  if (m_next < m_ordering.size()) {
98  TableScannerPtr scanner;
99  ScanSpec tmp_scan_spec;
100  RowInterval ri;
101  tmp_scan_spec.columns = m_scan_spec.columns;
102  tmp_scan_spec.max_versions = m_scan_spec.max_versions;
103  tmp_scan_spec.time_interval = m_scan_spec.time_interval;
104  ri.start = m_splits[m_ordering[m_next]].start_row;
105  ri.start_inclusive = false;
106  ri.end = m_splits[m_ordering[m_next]].end_row;
107  ri.end_inclusive = true;
108  tmp_scan_spec.row_intervals.push_back(ri);
109  scanner.reset( m_table->create_scanner(tmp_scan_spec) );
110  m_scanners.push_back( scanner );
111  m_next++;
112  }
113 
115 
116  if (m_scanner_iter == m_scanners.end()) {
117  m_scanner_iter = m_scanners.begin();
118  if (m_scanner_iter == m_scanners.end())
119  break;
120  }
121 
122  } while (true);
123 
124  m_eod = true;
125  return false;
126 }
127 
128 
130  Cell cell;
131 
132  while (dumper.next(cell))
133  b.add(cell);
134 }
std::list< TableScannerPtr >::iterator m_scanner_iter
Definition: TableDumper.h:63
pair< int64_t, int64_t > time_interval
Definition: ScanSpec.h:278
std::vector< uint32_t > m_ordering
Definition: TableDumper.h:60
static uint32_t number32(uint32_t maximum=0)
Returns a random 32-bit unsigned integer.
Definition: Random.cc:55
std::shared_ptr< TableScanner > TableScannerPtr
Smart pointer to TableScanner.
Definition: TableScanner.h:124
Represents a row interval.
Definition: RowInterval.h:38
std::shared_ptr< Namespace > NamespacePtr
Shared smart pointer to Namespace.
Definition: Namespace.h:333
Scan predicate and control specification.
Definition: ScanSpec.h:56
Compatibility Macros for C/C++.
bool next(Cell &cell)
Get the next cell.
Definition: TableDumper.cc:83
std::list< TableScannerPtr > m_scanners
Definition: TableDumper.h:62
Hypertable definitions
void copy(TableDumper &, CellsBuilder &)
Definition: TableDumper.cc:129
TableDumper(NamespacePtr &ns, const std::string &name, ScanSpec &scan_spec, size_t target_node_count=20)
Constructs a TableDumper object.
Definition: TableDumper.cc:41
Random number generator for int32, int64, double and ascii arrays.
RowIntervals row_intervals
Definition: ScanSpec.h:275
A String class based on std::string.
void add(const Cell &cell, bool own=true)
Definition: Cells.h:69
Encapsulates decomposed key and value.
Definition: Cell.h:32
TableSplitsContainer m_splits
Definition: TableDumper.h:58
Error codes, Exception handling, error logging.