45 #include <boost/algorithm/string.hpp>
51 #include <unordered_map>
60 static void init_options() {
62 " This program dumps a textual representation of\n"
63 " the given metalog. If the last path component\n"
64 " is a number, then the it is assumed to be an\n"
65 " individual log file, otherwise the path is assumed\n"
66 " to be the metalog directory\n\nOptions")
68 (
"all",
"Display all entities in log (not just latest state)")
69 (
"metadata-tsv",
"For each Range, dump StartRow and Location .tsv lines")
70 (
"location",
str()->default_value(
""),
71 "Used with --metadata-tsv to specify location proxy")
72 (
"print-logs",
boo()->zero_tokens()->default_value(
false),
"Print log files, one per line")
73 (
"show-version",
"Display log version number and exit")
79 if (!
has(
"log-path")) {
86 typedef Meta::list<FsClientPolicy, DefaultCommPolicy, AppPolicy>
Policies;
89 bool check_file=
false;
90 boost::trim_right_if(path, boost::is_any_of(
"/"));
94 const char *base, *ptr;
95 if ((base = strrchr(path.c_str(),
'/')) != (
const char *)0) {
96 for (ptr=base+1; *ptr && isdigit(*ptr); ptr++)
103 std::vector<Filesystem::Dirent> listing;
104 fs->readdir(path, listing);
105 if (!listing.empty()) {
106 path +=
String(
"/") + listing[0].name;
111 if (*is_file || check_file) {
115 const uint8_t *ptr = buf;
122 "Short read of header for '%s' (expected %d, got %d)",
125 header.
decode(&ptr, &remaining);
137 int main(
int argc,
char **argv) {
139 init_with_policies<Policies>(argc, argv);
143 String log_path = get_str(
"log-path");
145 int timeout =
has(
"dfs-timeout") ? get_i32(
"dfs-timeout") : 10000;
146 bool dump_all =
has(
"all");
147 bool show_version =
has(
"show-version");
148 bool metadata_tsv =
has(
"metadata-tsv");
149 bool print_logs = get_bool(
"print-logs");
153 if (
has(
"location") && get_str(
"location").size()>0)
154 location = get_str(
"location");
164 if (log_host.length()) {
165 int log_port = get_i16(
"log-port");
168 dfs_client = std::make_shared<FsBroker::Lib::Client>(conn_manager_ptr, addr, timeout);
171 dfs_client = std::make_shared<FsBroker::Lib::Client>(conn_manager_ptr,
properties);
174 if (!dfs_client->wait_for_connection(timeout)) {
175 HT_ERROR(
"Unable to connect to DFS Broker, exiting...");
180 std::unordered_map<String, MetaLog::DefinitionPtr> defmap;
182 defmap[def->name()] = def;
183 def = make_shared<MetaLog::DefinitionMaster>(
"");
184 defmap[def->name()] = def;
191 determine_log_type(fs, log_path, name, &is_file);
193 auto iter = defmap.find(name);
194 if (iter == defmap.end()) {
195 cerr <<
"No definition for log type '" << name <<
"'" << endl;
202 rsml_reader = make_shared<MetaLog::Reader>(fs, def, reader_flags);
203 rsml_reader->load_file(log_path);
206 rsml_reader = make_shared<MetaLog::Reader>(fs, def, log_path, reader_flags);
208 if (!metadata_tsv && !print_logs)
209 cout <<
"log version: " << rsml_reader->version() <<
"\n";
212 quick_exit(EXIT_SUCCESS);
214 std::vector<MetaLog::EntityPtr> entities;
217 rsml_reader->get_all_entities(entities);
219 rsml_reader->get_entities(entities);
223 for (
size_t i=0; i<entities.size(); i++) {
227 String start_row, end_row;
230 cout << table.
id <<
":" << end_row <<
"\tStartRow\t" << start_row <<
"\n";
231 cout << table.
id <<
":" << end_row <<
"\tLocation\t" << location <<
"\n";
235 else if (print_logs) {
236 for (
auto &entity : entities) {
241 std::cout << log <<
"\n";
244 std::cout << std::flush;
247 for (
size_t i=0; i<entities.size(); i++)
248 cout << *entities[i] <<
"\n";
258 quick_exit(EXIT_SUCCESS);
Interface and base of config policy.
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)
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.
File system utility functions.
Encapsulate an internet address.
std::shared_ptr< Client > ClientPtr
Smart pointer to Client.
Logging routines and macros.
Compatibility Macros for C/C++.
Po::typed_value< bool > * boo(bool *v=0)
Initialization helper for applications.
std::shared_ptr< Reader > ReaderPtr
Smart pointer to Reader.
Declarations for ConnectionManager.
std::shared_ptr< Filesystem > FilesystemPtr
Smart pointer to Filesystem.
#define HT_THROWF(_code_, _fmt_,...)
Internet address wrapper classes and utility functions.
Meta::list< MyPolicy, DefaultPolicy > Policies
static String install_dir
The installation directory.
This is a generic exception class for Hypertable.
std::shared_ptr< ConnectionManager > ConnectionManagerPtr
Smart pointer to ConnectionManager.
Desc & cmdline_hidden_desc()
Get the command line hidden options description (for positional options)
PositionalDesc & cmdline_positional_desc()
Get the command line positional options description.
Error codes, Exception handling, error logging.
static String file_to_string(const String &fname)
Reads a full file into a String.
std::shared_ptr< Definition > DefinitionPtr
Smart pointer to Definition.