0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
MetadataNormal.cc
Go to the documentation of this file.
1 
22 #include "Common/Compat.h"
23 #include <cassert>
24 #include <cstring>
25 
26 #include "Common/Error.h"
27 
30 
31 #include "Global.h"
32 #include "MetadataNormal.h"
33 
34 using namespace Hypertable;
35 
40  const String &end_row) {
41  m_metadata_key = String("") + identifier->id + ":" + end_row;
42 }
43 
44 
45 
50 }
51 
52 
53 
55  ScanSpec scan_spec;
56  RowInterval ri;
57  Cell cell;
58 
59  m_ag_map.clear();
60 
61  scan_spec.row_limit = 1;
62  scan_spec.max_versions = 1;
63  ri.start = m_metadata_key.c_str();
64  ri.end = m_metadata_key.c_str();
65  scan_spec.row_intervals.push_back(ri);
66  scan_spec.columns.clear();
67  scan_spec.columns.push_back("Files");
68  scan_spec.columns.push_back("NextCSID");
69 
70  TableScannerPtr files_scanner(Global::metadata_table->create_scanner(scan_spec));
71 
72  String ag_name;
73 
74  while (files_scanner->next(cell)) {
75  if (!strcmp(cell.column_family, "Files")) {
76  ag_name = String(cell.column_qualifier);
77  m_ag_map[ag_name].files = String((const char *)cell.value, cell.value_len);
78  }
79  else if (!strcmp(cell.column_family, "NextCSID")) {
80  ag_name = String(cell.column_qualifier);
81  String idstr = String((const char *)cell.value, cell.value_len);
82  m_ag_map[ag_name].nextcsid = atoi(idstr.c_str());
83  }
84  }
85 
86  m_ag_map_iter = m_ag_map.begin();
87 
88  files_scanner = 0;
89 
90 }
91 
92 
93 
94 bool MetadataNormal::get_next_files(String &ag_name, String &files, uint32_t *nextcsidp) {
95 
96  if (m_ag_map_iter == m_ag_map.end())
97  return false;
98 
99  ag_name = m_ag_map_iter->first;
100  files = m_ag_map_iter->second.files;
101  *nextcsidp = m_ag_map_iter->second.nextcsid;
102 
103  m_ag_map_iter++;
104  return true;
105 }
106 
107 
108 
109 void MetadataNormal::write_files(const String &ag_name, const String &files, int64_t total_blocks) {
110  KeySpec key;
111  char buf[32];
112 
113  TableMutatorPtr mutator(Global::metadata_table->create_mutator());
114 
115  key.row = m_metadata_key.c_str();
116  key.row_len = m_metadata_key.length();
117  key.column_qualifier = ag_name.c_str();
118  key.column_qualifier_len = ag_name.length();
119 
120  key.column_family = "Files";
121  mutator->set(key, (uint8_t *)files.c_str(), files.length());
122 
123  sprintf(buf, "%llu", (Llu)total_blocks);
124  key.column_family = "BlockCount";
125  mutator->set(key, (uint8_t *)buf, strlen(buf));
126 
127  mutator->flush();
128 }
129 
130 
131 void MetadataNormal::write_files(const String &ag_name, const String &files, int64_t total_blocks, uint32_t nextcsid) {
132  KeySpec key;
133  char buf[32];
134 
135  TableMutatorPtr mutator(Global::metadata_table->create_mutator());
136 
137  key.row = m_metadata_key.c_str();
138  key.row_len = m_metadata_key.length();
139  key.column_qualifier = ag_name.c_str();
140  key.column_qualifier_len = ag_name.length();
141 
142  key.column_family = "Files";
143  mutator->set(key, (uint8_t *)files.c_str(), files.length());
144 
145  sprintf(buf, "%u", (unsigned)nextcsid);
146  key.column_family = "NextCSID";
147  mutator->set(key, (uint8_t *)buf, strlen(buf));
148 
149  sprintf(buf, "%llu", (Llu)total_blocks);
150  key.column_family = "BlockCount";
151  mutator->set(key, (uint8_t *)buf, strlen(buf));
152 
153  mutator->flush();
154 }
static TablePtr metadata_table
Definition: Global.h:91
std::string String
A String is simply a typedef to std::string.
Definition: String.h:44
virtual void reset_files_scan()
long long unsigned int Llu
Shortcut for printf formats.
Definition: String.h:50
const char * column_qualifier
Definition: KeySpec.h:128
const char * column_qualifier
Definition: Cell.h:68
virtual bool get_next_files(String &ag_name, String &files, uint32_t *nextcsidp)
size_t column_qualifier_len
Definition: KeySpec.h:129
const void * row
Definition: KeySpec.h:125
std::shared_ptr< TableScanner > TableScannerPtr
Smart pointer to TableScanner.
Definition: TableScanner.h:124
Represents a row interval.
Definition: RowInterval.h:38
Scan predicate and control specification.
Definition: ScanSpec.h:56
std::shared_ptr< TableMutator > TableMutatorPtr
Smart pointer to TableMutator.
Definition: TableMutator.h:257
MetadataNormal(const TableIdentifier *identifier, const String &end_row)
Compatibility Macros for C/C++.
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
Encapsulates decomposed key and value.
Definition: Cell.h:32
virtual void write_files(const String &ag_name, const String &files, int64_t total_blocks)
const char * column_family
Definition: KeySpec.h:127
Error codes, Exception handling, error logging.
AgMetadataMap::iterator m_ag_map_iter
const uint8_t * value
Definition: Cell.h:71