Skip to content

Commit

Permalink
1) binlog_sync use random port; 2) set FLAGS_logbufsecs = 0; 3) 2.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
KernelMaker committed Aug 1, 2016
1 parent 9a5714c commit 0d8d776
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion include/pika_define.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#define PIKA_MAX_WORKER_THREAD_NUM 24


const std::string kPikaVersion = "2.1.0";
const std::string kPikaVersion = "2.1.1";
const std::string kPikaPidFile = "pika.pid";

struct ClientInfo {
Expand Down
2 changes: 2 additions & 0 deletions src/pika.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ static void PikaGlogInit() {
FLAGS_log_dir = g_pika_conf->log_path();
FLAGS_minloglevel = g_pika_conf->log_level();
FLAGS_max_log_size = 1800;
FLAGS_logbufsecs = 0;
::google::InitGoogleLogging("pika");
}

Expand Down Expand Up @@ -84,6 +85,7 @@ static void PikaSignalSetup() {
signal(SIGPIPE, SIG_IGN);
signal(SIGINT, &IntSigHandle);
signal(SIGQUIT, &IntSigHandle);
signal(SIGTERM, &IntSigHandle);
}

static void usage()
Expand Down
22 changes: 13 additions & 9 deletions tools/binlog_sync/main.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <glog/logging.h>
#include <random>
#include "binlog_sync.h"


Expand All @@ -15,6 +16,7 @@ static void GlogInit(std::string& log_path, bool is_daemon) {
FLAGS_log_dir = log_path;
FLAGS_minloglevel = 0;
FLAGS_max_log_size = 1800;
FLAGS_logbufsecs = 0;
::google::InitGoogleLogging("BinlogSync");
}

Expand Down Expand Up @@ -62,22 +64,22 @@ static void SignalSetup() {
signal(SIGPIPE, SIG_IGN);
signal(SIGINT, &IntSigHandle);
signal(SIGQUIT, &IntSigHandle);
signal(SIGTERM, &IntSigHandle);
}

static void Usage()
{
fprintf(stderr,
"Usage: binlog_sync [-h] [-p local_port -i master_ip -o master_port -f filenum -s offset -w password -l log_path]\n"
"\t-h -- show this help\n"
"\t-p -- local port(REQUIRED) \n"
"\t-i -- master ip(OPTIONAL default: 127.0.0.1) \n"
"\t-o -- master port(REQUIRED) \n"
"\t-p -- master port(REQUIRED) \n"
"\t-f -- binlog filenum(OPTIONAL default: local offset) \n"
"\t-s -- binlog offset(OPTIONAL default: local offset) \n"
"\t-w -- password for master(OPTIONAL) \n"
"\t-l -- local log path(OPTIONAL default: ./log) \n"
"\t-d -- daemonize(OPTIONAL) \n"
" example: ./binlog_sync -p 9222 -i 127.0.0.1 -o 9221 -f 0 -s 0 -w abc -l ./log -d\n"
" example: ./binlog_sync -i 127.0.0.1 -p 9221 -f 0 -s 0 -w abc -l ./log -d\n"
);
}

Expand All @@ -99,17 +101,13 @@ int main(int argc, char *argv[]) {
std::string log_path = "./log/";
bool is_daemon = false;
// std::cout << src_port << " " << dest_host << " " << dest_port << " " << filenum << " " << offset << " " << passwd << std::endl;
while (-1 != (c = getopt(argc, argv, "p:i:o:f:s:w:l:dh"))) {
while (-1 != (c = getopt(argc, argv, "i:p:f:s:w:l:dh"))) {
switch (c) {
case 'p':
snprintf(buf, 1024, "%s", optarg);
slash::string2l(buf, strlen(buf), &src_port);
break;
case 'i':
snprintf(buf, 1024, "%s", optarg);
dest_host = std::string(buf);
break;
case 'o':
case 'p':
snprintf(buf, 1024, "%s", optarg);
slash::string2l(buf, strlen(buf), &dest_port);
break;
Expand Down Expand Up @@ -144,6 +142,12 @@ int main(int argc, char *argv[]) {
}
}

std::random_device rd;
std::mt19937 mt(rd());
std::uniform_int_distribution<int> di(10000, 60000);
src_port = di(mt);
LOG(INFO) << "Use random port: " << src_port;

//std::cout << src_port << " " << dest_host << " " << dest_port << " " << filenum << " " << offset << " " << passwd << " " << log_path << std::endl;
if (src_port == -1 || dest_port == -1) {
fprintf (stderr, "Invalid Arguments\n" );
Expand Down

0 comments on commit 0d8d776

Please sign in to comment.