46 #include <boost/algorithm/string.hpp>
50 #include <unordered_map>
60 static void init_options() {
62 "Dumps the contents of the CellStore contained in the FS <filename>."
63 "\n\nOptions").add_options()
64 (
"all,a",
"Dump everything, including key/value pairs")
65 (
"compact,c",
"Only prints the cellstore name and a status ('ok' or 'corrupt')")
66 (
"count,c",
"Count the number of key/value pairs")
67 (
"column-id-map",
str(),
"Column family id to name map, format = <id>=<name>[,<id>=<name>...]")
68 (
"end-key",
str(),
"Ignore keys that are greater than <arg>")
69 (
"start-key",
str(),
"Ignore keys that are less than or equal to <arg>")
70 (
"tsv-format",
"Output data in TSV format")
76 if (!
has(
"filename")) {
84 typedef Meta::list<AppPolicy, FsClientPolicy, DefaultCommPolicy>
Policies;
86 typedef std::unordered_map<uint32_t, String> ColumnIdMapT;
92 int main(
int argc,
char **argv) {
94 init_with_policies<Policies>(argc, argv);
96 bool dump_compact =
has(
"compact");
97 bool dump_all =
has(
"all");
98 bool count_keys =
has(
"count");
101 bool got_end_key =
has(
"end-key");
102 bool hit_start = start_key.empty();
103 int timeout = get_i32(
"timeout");
104 String fname = get_str(
"filename");
105 bool tsv_format =
has(
"tsv-format");
106 char *column_id_map[256];
112 if (!dfs->wait_for_connection(timeout)) {
113 cerr <<
"error: timed out waiting for FS broker" << endl;
124 std::cout << fname <<
": ok" << std::endl;
127 std::cout << fname <<
": corrupt" << std::endl;
128 quick_exit(EXIT_FAILURE);
130 quick_exit(EXIT_SUCCESS);
133 memset(column_id_map, 0, 256*
sizeof(
char *));
135 if (
has(
"column-id-map")) {
139 key = strtok((
char *)str.c_str(),
",=");
141 value = strtok(0,
",=");
143 column_id_map[id] = value;
146 key = strtok(0,
",=");
148 value = strtok(0,
",=");
150 column_id_map[id] = value;
172 uint64_t key_count = 0;
176 char *buf =
new char [ 1024 ];
177 size_t buf_len = 1024;
183 if (tsv_format || dump_all || count_keys) {
187 const char *unescaped_buf, *row_unescaped_buf;
188 size_t unescaped_len, row_unescaped_len;
191 cout <<
"#timestamp\trow\tcolumn\tvalue\n";
193 scanner = cellstore->create_scanner(scan_ctx.get());
194 while (scanner->get(key_comps, value)) {
197 if (strcmp(key_comps.
row, start_key.c_str()) <= 0) {
203 if (got_end_key && strcmp(key_comps.
row, end_key.c_str()) > 0)
210 &row_unescaped_buf, &row_unescaped_len);
217 &unescaped_buf, &unescaped_len);
218 cout <<
":" << unescaped_buf;
221 if (bslen >= buf_len) {
223 buf_len = bslen + 256;
224 buf =
new char [ buf_len ];
226 memcpy(buf, bsptr, bslen);
228 escaper.
escape(buf, bslen, &unescaped_buf, &unescaped_len);
229 cout <<
"\t" << (
char *)unescaped_buf <<
"\n";
232 cout << key_comps << endl;
242 cout << key_count << endl;
250 cout <<
"BLOCK INDEX:" << endl;
251 cellstore->display_block_info();
257 cout <<
"BLOOM FILTER SIZE: "
258 << cellstore->bloom_filter_size() << endl;
264 const vector<String> &replaced_files = cellstore->get_replaced_files();
265 cout <<
"REPLACED FILES: " << endl;
266 for(
size_t ii=0; ii < replaced_files.size(); ++ii)
267 cout << replaced_files[ii] << endl;
275 cout <<
"TRAILER:" << endl;
Retrieves system information (hardware, installation directory, etc)
Abstract base class for cell store trailer.
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.
void init(int argc, char *argv[], const Desc *desc=NULL)
Initialize with default policy.
Po::typed_value< String > * str(String *v=0)
int main(int argc, char **argv)
bool escape(const char *in_buf, size_t in_len, const char **out_bufp, size_t *out_lenp)
Scan context information.
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. ...
bool has(const String &name)
Check existence of a configuration value.
A class managing one or more serializable ByteStrings.
Declarations for CellStore.
static Hypertable::MemoryTracker * memory_tracker
std::shared_ptr< Client > ClientPtr
Smart pointer to Client.
Logging routines and macros.
Compatibility Macros for C/C++.
Initialization helper for applications.
static Hypertable::FilesystemPtr dfs
std::shared_ptr< CellStore > CellStorePtr
Smart pointer to CellStore.
Declarations for ConnectionManager.
size_t decode_length(const uint8_t **dptr) const
Retrieves the decoded length and returns a pointer to the string.
Provides access to internal components of opaque key.
uint32_t column_qualifier_len
Internet address wrapper classes and utility functions.
Meta::list< MyPolicy, DefaultPolicy > Policies
Declarations for ReactorFactory.
This is a generic exception class for Hypertable.
A serializable ByteString.
virtual void display_multiline(std::ostream &os)=0
Prints the trailer, one member per line, to the given ostream.
uint8_t column_family_code
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)
const char * column_qualifier
PositionalDesc & cmdline_positional_desc()
Get the command line positional options description.
std::shared_ptr< ScanContext > ScanContextPtr