50 using namespace boost;
56 "Usage: ht_balance_plan_generator [options] <rs_metrics_file>\n\n"
58 " This program is used to generate a load balancing plan.\n"
59 " The <rs_metrics_file> argument indicates the location of the file containing the dump\n"
60 " of the 'sys/RS_METRICS' table.\n\n"
64 static void init_options() {
67 (
"help,h",
"Show this help message and exit")
68 (
"help-config",
"Show help message for config properties")
69 (
"namespace",
str()->default_value(
"/"),
70 "Namespace in which to create the dummy RS_METRICS table if needed")
71 (
"table",
str()->default_value(
"DUMMY_RS_METRICS"),
72 "Name of the table in which to load the rs_metrics_file")
73 (
"rs-metrics-loaded",
boo()->zero_tokens()->default_value(
false),
74 "If true then assume RS_METRICS is already loaded in namespace/table")
75 (
"load-balancer",
str()->default_value(
"basic-distribute-load"),
76 "Type of load balancer to be used.")
77 (
"verbose,v",
boo()->zero_tokens()->default_value(
false),
78 "Show more verbose output")
79 (
"balance-plan-file,b",
str()->default_value(
""),
80 "File in which to dump balance plan.")
81 (
"rs-metrics-dump",
str(),
"File containing dump of 'sys/RS_METRICS' table.");
88 typedef Meta::list<AppPolicy, DefaultCommPolicy>
Policies;
94 int main(
int argc,
char **argv) {
95 String ns_str, table_str, load_balancer, rs_metrics_file;
100 init_with_policies<Policies>(argc, argv);
102 if (
has(
"verbose")) {
103 verbose = get_bool(
"verbose");
106 table_str = get_str(
"table");
107 ns_str = get_str(
"namespace");
108 balance_plan_file = get_str(
"balance-plan-file");
109 load_balancer = get_str(
"load-balancer");
110 bool loaded = get_bool(
"rs-metrics-loaded");
111 if (
has(
"rs-metrics-dump")) {
113 rs_metrics_file = get_str(
"rs-metrics-dump");
119 table_str =
"RS_METRICS";
124 TablePtr rs_metrics = ns->open_table(table_str);
127 context->rsc_manager.reset();
128 context->rs_metrics_table = rs_metrics;
132 if (balance_plan_file.size() == 0)
135 oo =
new ofstream(balance_plan_file.c_str(), ios_base::app);
139 *oo <<
"BalancePlan: { ";
140 if (plan->moves.size()>0) {
141 for(ii=0; ii<plan->moves.size()-1; ++ii) {
142 *oo <<
"(" << plan->moves[ii]->table.id <<
"[" << plan->moves[ii]->range.start_row
143 <<
".." << plan->moves[ii]->range.end_row <<
"], " << plan->moves[ii]->source_location
144 <<
", " << plan->moves[ii]->dest_location <<
"), ";
147 *oo <<
"(" << plan->moves[ii]->table.id <<
"[" << plan->moves[ii]->range.start_row
148 <<
".." << plan->moves[ii]->range.end_row <<
"], " << plan->moves[ii]->source_location
149 <<
", " << plan->moves[ii]->dest_location <<
")";
159 quick_exit(EXIT_SUCCESS);
165 if (load_balancer !=
"basic-distribute-load")
167 (
String)
"Only 'basic-distribute-load' balancer is supported. '" + load_balancer
168 +
"' balancer not supported.");
170 std::vector<RangeServerStatistics> range_server_stats;
174 std::vector<RangeServerConnectionPtr> balanced;
182 " DROP TABLE IF EXISTS " + table +
";\n" +
183 " CREATE TABLE " + table +
"(\n" +
184 " server MAX_VERSIONS=336,\n" +
185 " range MAX_VERSIONS=24,\n" +
186 " \'range_start_row\' MAX_VERSIONS=1,\n" +
187 " \'range_move\' MAX_VERSIONS=1,\n" +
188 " ACCESS GROUP server (server),\n" +
189 " ACCESS GROUP range (range, \'range_start_row\', \'range_move\')\n" +
191 " LOAD DATA INFILE \'" + rs_metrics_file +
"\' INTO TABLE " + table +
";";
195 String cmd_str = install_dir + (
String)
"/bin/ht_hypertable --test-mode --exec \""+ hql +
"\"";
197 HT_INFOF(
"Running command: %s", cmd_str.c_str());
Retrieves system information (hardware, installation directory, etc)
Interface and base of config policy.
int main(int argc, char **argv)
PropertiesPtr properties
This singleton map stores all options.
std::string String
A String is simply a typedef to std::string.
std::shared_ptr< BalancePlan > BalancePlanPtr
Meta::list< AppPolicy, DefaultCommPolicy > Policies
static void initialize(const String &install_directory=String())
Initializes the static class members; checks header version vs.
Po::typed_value< String > * str(String *v=0)
virtual void compute_plan(BalancePlanPtr &plan, std::vector< RangeServerConnectionPtr > &balanced)
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.
std::shared_ptr< Context > ContextPtr
Smart pointer to Context.
#define HT_EXPECT(_e_, _code_)
std::shared_ptr< Namespace > NamespacePtr
Shared smart pointer to Namespace.
std::shared_ptr< Client > ClientPtr
void create_table(String &ns, String &tablename, String &rs_metrics_file)
std::shared_ptr< Properties > PropertiesPtr
Compatibility Macros for C/C++.
Po::typed_value< bool > * boo(bool *v=0)
Initialization helper for applications.
bool allow_unregistered_options(bool choice)
Toggle allow unregistered options.
void generate_balance_plan(PropertiesPtr &props, const String &load_balancer, ContextPtr &context, BalancePlanPtr &plan)
static String locate_install_dir(const char *argv0)
Returns the installation directory.
#define HT_INFOF(msg,...)
static String install_dir
The installation directory.
This is a generic exception class for Hypertable.
Error codes, Exception handling, error logging.
#define HT_THROW(_code_, _msg_)
std::shared_ptr< Table > TablePtr