51 static void init_options() {
53 " This program counts the number of cells that exist in CellStores\n"
54 " for a table. It does this by reading the Files columns for the\n"
55 " table in the METADATA table to learn of all the CellStores. It\n"
56 " then does a linear scan of each CellStore file, counting the\n"
57 " number of cells...\nOptions");
59 (
"table",
str(),
"name of the table to scan")
67 struct RangeCellStoreInfo {
70 std::vector<String> cell_stores;
73 struct cell_store_info {
81 std::vector<cell_store_info> &file_vector);
86 int main(
int argc,
char **argv) {
88 init_with_policy<AppPolicy>(argc, argv);
92 if (table_name.empty()) {
98 bool hit_start =
false;
99 uint64_t total_count = 0;
100 uint64_t store_count = 0;
101 int timeout = get_i32(
"FsBroker.Timeout");
104 ClientPtr hypertable_client = make_shared<Hypertable::Client>(argv[0]);
105 NamespacePtr ns = hypertable_client->open_namespace(
"/");
111 if (!dfs->wait_for_connection(timeout)) {
112 cerr <<
"error: timed out waiting for FS broker" << endl;
118 std::vector<cell_store_info> file_vector;
120 fill_cell_store_vector(hypertable_client, ns, table_name.c_str(), file_vector);
126 for (
size_t i=0; i<file_vector.size(); i++) {
133 hit_start = (file_vector[i].start_row ==
"") ?
true :
false;
135 scanner = cell_store_ptr->create_scanner(scan_context_ptr.get());
137 while (scanner->get(key, value)) {
139 if (strcmp(key.
row, file_vector[i].start_row.c_str()) <= 0) {
145 if (strcmp(key.
row, file_vector[i].end_row.c_str()) > 0)
152 cout << store_count <<
"\t" << file_vector[i].file <<
"["
153 << file_vector[i].start_row <<
".." << file_vector[i].end_row <<
"]"
155 total_count += store_count;
157 cout << total_count <<
"\tTOTAL" << endl;
171 std::vector<cell_store_info> &file_vector) {
180 RangeCellStoreInfo range_cell_store_info;
181 cell_store_info cell_store_info;
185 ns_system = client->open_namespace(
"sys");
187 table_ptr = ns_system->open_table(
"METADATA");
188 table_id = ns->get_table_id(table_name);
192 sprintf(start_row,
"%s:", table_id.c_str());
193 ri.
start = start_row;
198 scan_spec.
columns.push_back(
"Files");
199 scan_spec.
columns.push_back(
"StartRow");
202 scanner_ptr.reset( table_ptr->create_scanner(scan_spec) );
205 catch (std::exception &e) {
206 cerr <<
"error: " << e.what() << endl;
210 range_cell_store_info.start_row =
"";
211 range_cell_store_info.end_row =
"";
212 range_cell_store_info.cell_stores.clear();
215 while (scanner_ptr->next(cell)) {
216 if (strcmp(cell.
row_key, range_cell_store_info.end_row.c_str())) {
217 if (range_cell_store_info.end_row !=
"") {
218 const char *end_row_cstr =
219 strchr(range_cell_store_info.end_row.c_str(),
':');
220 if (end_row_cstr == 0) {
221 cerr <<
"error: mal-formed end row (missing colon) - "
222 << range_cell_store_info.end_row << endl;
226 cell_store_info.start_row = range_cell_store_info.start_row;
227 cell_store_info.end_row = end_row_cstr;
228 for (
size_t i=0; i<range_cell_store_info.cell_stores.size(); i++) {
229 cell_store_info.file = range_cell_store_info.cell_stores[i];
230 file_vector.push_back(cell_store_info);
233 range_cell_store_info.start_row =
"";
234 range_cell_store_info.end_row = cell.
row_key;
235 range_cell_store_info.cell_stores.clear();
239 range_cell_store_info.start_row =
243 char *ptr, *save_ptr;
244 ptr = strtok_r((
char *)files.c_str(),
"\n\r;", &save_ptr);
246 range_cell_store_info.cell_stores.push_back(ptr);
247 ptr = strtok_r(0,
"\n\r;", &save_ptr);
251 cerr <<
"Unexpected column family encountered: '" << cell.
column_family
257 if (!range_cell_store_info.cell_stores.empty()) {
258 const char *end_row_cstr = strchr(range_cell_store_info.end_row.c_str(),
260 if (end_row_cstr == 0) {
261 cerr <<
"error: mal-formed end row (missing colon) - "
262 << range_cell_store_info.end_row << endl;
266 cell_store_info.start_row = range_cell_store_info.start_row;
267 cell_store_info.end_row = end_row_cstr;
268 for (
size_t i=0; i<range_cell_store_info.cell_stores.size(); i++) {
269 cell_store_info.file = range_cell_store_info.cell_stores[i];
270 file_vector.push_back(cell_store_info);
Retrieves system information (hardware, installation directory, etc)
Interface and base of config policy.
Declarations for CellStoreFactory.
PropertiesPtr properties
This singleton map stores all options.
std::string String
A String is simply a typedef to std::string.
Helper class for printing usage banners on the command line.
Po::typed_value< String > * str(String *v=0)
Scan context information.
std::shared_ptr< TableScanner > TableScannerPtr
Smart pointer to TableScanner.
Tracks range server memory used.
Desc & cmdline_desc(const char *usage)
A macro which definds global functions like get_bool(), get_str(), get_i16() etc. ...
Represents a row interval.
std::shared_ptr< Namespace > NamespacePtr
Shared smart pointer to Namespace.
std::shared_ptr< Client > ClientPtr
A class managing one or more serializable ByteStrings.
Declarations for CellStore.
Scan predicate and control specification.
static Hypertable::MemoryTracker * memory_tracker
std::shared_ptr< Client > ClientPtr
Smart pointer to Client.
Helpers to compose init policies; allow to combine two policies into one.
Compatibility Macros for C/C++.
Initialization helper for applications.
static Hypertable::FilesystemPtr dfs
std::shared_ptr< CellStore > CellStorePtr
Smart pointer to CellStore.
const char * column_family
Provides access to internal components of opaque key.
RowIntervals row_intervals
This is a generic exception class for Hypertable.
std::shared_ptr< CellListScanner > CellListScannerPtr
std::shared_ptr< ConnectionManager > ConnectionManagerPtr
Smart pointer to ConnectionManager.
static CellStorePtr open(const String &name, const char *start_row, const char *end_row)
Creates a CellStore object from a given cell store file.
Desc & cmdline_hidden_desc()
Get the command line hidden options description (for positional options)
int main(int argc, char **argv)
Encapsulates decomposed key and value.
PositionalDesc & cmdline_positional_desc()
Get the command line positional options description.
static const char * END_ROW_MARKER
std::shared_ptr< Table > TablePtr
std::shared_ptr< ScanContext > ScanContextPtr