36 #include <boost/progress.hpp>
37 #include <boost/algorithm/string.hpp>
47 #include <sys/types.h>
58 "Usage: check_integrity [options]\n\n"
60 " This program checks the integrity of the cluster by scanning all \n"
61 " available ranges of all tables.\n"
64 " sleep: specifies a sleep time (in seconds) during the requests to\n"
65 " reduce the load that is caused by this tool.\n";
68 static void init_options() {
70 (
"sleep",
i32()->default_value(0),
71 "Time to sleep between each request (in milliseconds)")
72 (
"timeout",
i32()->default_value(0),
73 "Hypertable connection timeout (in milliseconds)")
105 lock_guard<mutex> lock(error_mutex);
106 errors.push_back(msg);
113 const String &location, boost::progress_display *progress,
114 const RangeInfoVec &ranges, uint32_t sleep_ms)
115 : m_namespace(ns), m_namemap(namemap), m_ranges(ranges),
116 m_progress(progress), m_sleep_ms(sleep_ms) {
122 for (
size_t i = 0; i < m_ranges.size(); i++) {
127 if (!m_namemap->id_to_name(m_ranges[i].tableid, table_name)) {
129 m_ranges[i].tableid.c_str()));
133 if (table_name != previous_table) {
134 previous_table = table_name;
136 table = m_namespace->open_table(table_name);
144 if (previous_end.empty() && m_ranges[i].endrow ==
"\xff\xff") {
148 else if (m_ranges[i].endrow !=
"\xff\xff") {
150 m_ranges[i].endrow.c_str(),
true);
156 HT_ASSERT(m_ranges[i].endrow ==
"\xff\xff");
158 m_ranges[i].endrow.c_str(),
true);
164 while (scanner->
next(cell))
171 && (previous_end !=
""
172 || m_ranges[i].endrow !=
"\xff\xff")) {
174 table_name.c_str(), previous_end.c_str(),
175 m_ranges[i].endrow.c_str()));
179 this_thread::sleep_for(chrono::milliseconds(m_sleep_ms));
181 previous_end = m_ranges[i].endrow;
193 int main(
int argc,
char **argv) {
194 typedef std::map<String, RangeInfoVec> RangeMap;
197 init_with_policies<Policies>(argc, argv);
199 uint32_t sleep_ms = get_i32(
"sleep");
200 uint32_t timeout_ms = get_i32(
"timeout");
206 TablePtr metatable = ns->open_table(
"sys/METADATA");
209 int total_ranges = 0;
213 TableScanner *scanner = metatable->create_scanner(ssb.
get(), timeout_ms);
215 while (scanner->
next(cell)) {
216 char *endrow = strstr((
char *)cell.
row_key,
":");
225 ranges[location].push_back(ri);
232 cout <<
"Checking " << total_ranges <<
" ranges... please wait..." << endl;
233 boost::progress_display progress(total_ranges);
236 boost::thread_group threads;
237 for (RangeMap::iterator it = ranges.begin(); it != ranges.end(); ++it)
239 it->first, &progress, it->second, sleep_ms));
251 cout << endl << endl <<
"Got " << errors.size() <<
" errors: " << endl;
252 for (
const auto &s : errors)
253 cout <<
" " << s << endl;
256 cout <<
"Success - all ranges are available." << endl;
258 quick_exit(errors.size());
LocationThread(NamespacePtr &ns, NameIdMapperPtr namemap, const String &location, boost::progress_display *progress, const RangeInfoVec &ranges, uint32_t sleep_ms)
NameIdMapperPtr get_nameid_mapper()
Interface and base of config policy.
ScanSpec & get()
Returns the built ScanSpec object.
NamespacePtr open_namespace(const std::string &name, Namespace *base=NULL)
Opens a Namespace.
NameIdMapperPtr m_namemap
PropertiesPtr properties
This singleton map stores all options.
std::string String
A String is simply a typedef to std::string.
String format(const char *fmt,...)
Returns a String using printf like format facilities Vanilla snprintf is about 1.5x faster than this...
std::vector< RangeInfo > RangeInfoVec
Helper class for printing usage banners on the command line.
void init(int argc, char *argv[], const Desc *desc=NULL)
Initialize with default policy.
std::vector< String > errors
boost::progress_display * m_progress
Desc & cmdline_desc(const char *usage)
A macro which definds global functions like get_bool(), get_str(), get_i16() etc. ...
std::shared_ptr< Namespace > NamespacePtr
Shared smart pointer to Namespace.
void set_cell_limit(int32_t n)
Sets the maximum number of cells to return.
const char * get_text(int error)
Returns a descriptive error message.
Po::typed_value< int32_t > * i32(int32_t *v=0)
Helpers to compose init policies; allow to combine two policies into one.
A timer class to keep timeout states across AsyncComm related calls.
Logging routines and macros.
bool next(Cell &cell)
Gets the next cell.
Compatibility Macros for C/C++.
Initialization helper for applications.
Helper class for building a ScanSpec.
bool defaulted(const String &name)
Check if a configuration value is defaulted.
Synchronous table scanner.
Holds pointer to range and cached start and end rows.
void add_column(const string &str)
Adds a column family to be returned by the scan.
void add_row_interval(const string &start, bool start_inclusive, const string &end, bool end_inclusive)
Adds a row interval to be returned in the scan.
Internet address wrapper classes and utility functions.
Meta::list< MyPolicy, DefaultPolicy > Policies
void add_error(const String &msg)
This is a generic exception class for Hypertable.
int main(int argc, char **argv)
Encapsulates decomposed key and value.
void set_max_versions(uint32_t n)
Sets the maximum number of revisions of each cell to return in the scan.
std::shared_ptr< NameIdMapper > NameIdMapperPtr
Smart pointer to NameIdMapper.
Error codes, Exception handling, error logging.
std::shared_ptr< Table > TablePtr
int code() const
Returns the error code.