Merge branch '1.2.1-binlog_router_trx' into release-1.4.2

This commit is contained in:
Markus Makela
2016-04-14 18:52:36 +03:00
7 changed files with 9579 additions and 8219 deletions

View File

@ -24,13 +24,13 @@
* @verbatim
* Revision History
*
* Date Who Description
* 24/07/2015 Massimiliano Pinto Initial implementation
* 26/08/2015 Massimiliano Pinto Added mariadb10 option
* for MariaDB 10 binlog compatibility
* Currently MariadDB 10 starting transactions
* are detected checking GTID event
* with flags = 0
* Date Who Description
* 24/07/2015 Massimiliano Pinto Initial implementation
* 26/08/2015 Massimiliano Pinto Added mariadb10 option
* for MariaDB 10 binlog compatibility
* Currently MariadDB 10 starting transactions
* are detected checking GTID event
* with flags = 0
*
* @endverbatim
*/
@ -68,127 +68,150 @@ extern uint32_t extract_field(uint8_t *src, int bits);
static void printVersion(const char *progname);
static void printUsage(const char *progname);
static struct option long_options[] = {
{"debug", no_argument, 0, 'd'},
{"version", no_argument, 0, 'V'},
{"fix", no_argument, 0, 'f'},
{"mariadb10", no_argument, 0, 'M'},
{"help", no_argument, 0, '?'},
{0, 0, 0, 0}
static struct option long_options[] =
{
{"debug", no_argument, 0, 'd'},
{"version", no_argument, 0, 'V'},
{"fix", no_argument, 0, 'f'},
{"mariadb10", no_argument, 0, 'M'},
{"help", no_argument, 0, '?'},
{0, 0, 0, 0}
};
char *binlog_check_version = "1.1.0";
int main(int argc, char **argv) {
ROUTER_INSTANCE *inst;
int fd;
int ret;
char *ptr;
char path[PATH_MAX+1] = "";
unsigned long filelen = 0;
struct stat statb;
char c;
int option_index = 0;
int num_args = 0;
int debug_out = 0;
int fix_file = 0;
int mariadb10_compat = 0;
int
maxscale_uptime()
{
return 1;
}
while ((c = getopt_long(argc, argv, "dVfM?", long_options, &option_index)) >= 0)
{
switch (c) {
case 'd':
debug_out = 1;
break;
case 'V':
printVersion(*argv);
exit(EXIT_SUCCESS);
break;
case 'f':
fix_file = 1;
break;
case 'M':
mariadb10_compat = 1;
break;
case '?':
printUsage(*argv);
exit(optopt ? EXIT_FAILURE : EXIT_SUCCESS);
}
}
int main(int argc, char **argv)
{
ROUTER_INSTANCE *inst;
int fd;
int ret;
char *ptr;
char path[PATH_MAX + 1] = "";
unsigned long filelen = 0;
struct stat statb;
char c;
int option_index = 0;
int num_args = 0;
int debug_out = 0;
int fix_file = 0;
int mariadb10_compat = 0;
num_args = optind;
while ((c = getopt_long(argc, argv, "dVfM?", long_options, &option_index)) >= 0)
{
switch (c)
{
case 'd':
debug_out = 1;
break;
case 'V':
printVersion(*argv);
exit(EXIT_SUCCESS);
break;
case 'f':
fix_file = 1;
break;
case 'M':
mariadb10_compat = 1;
break;
case '?':
printUsage(*argv);
exit(optopt ? EXIT_FAILURE : EXIT_SUCCESS);
}
}
mxs_log_init(NULL, NULL, MXS_LOG_TARGET_DEFAULT);
mxs_log_set_augmentation(0);
mxs_log_set_priority_enabled(LOG_DEBUG, debug_out);
num_args = optind;
if ((inst = calloc(1, sizeof(ROUTER_INSTANCE))) == NULL) {
MXS_ERROR("Memory allocation failed for ROUTER_INSTANCE");
mxs_log_init(NULL, NULL, MXS_LOG_TARGET_DEFAULT);
mxs_log_set_augmentation(0);
mxs_log_set_priority_enabled(LOG_DEBUG, debug_out);
mxs_log_flush_sync();
mxs_log_finish();
if ((inst = calloc(1, sizeof(ROUTER_INSTANCE))) == NULL)
{
MXS_ERROR("Memory allocation failed for ROUTER_INSTANCE");
return 1;
}
mxs_log_flush_sync();
mxs_log_finish();
if (argv[num_args] == NULL) {
printf("ERROR: No binlog file was specified\n");
exit(EXIT_FAILURE);
}
return 1;
}
strncpy(path, argv[num_args], PATH_MAX);
if (argv[num_args] == NULL)
{
printf("ERROR: No binlog file was specified\n");
exit(EXIT_FAILURE);
}
if (fix_file)
fd = open(path, O_RDWR, 0666);
else
fd = open(path, O_RDONLY, 0666);
strncpy(path, argv[num_args], PATH_MAX);
if (fd == -1)
{
MXS_ERROR("Failed to open binlog file %s: %s",
path, strerror(errno));
mxs_log_flush_sync();
mxs_log_finish();
if (fix_file)
{
fd = open(path, O_RDWR, 0666);
}
else
{
fd = open(path, O_RDONLY, 0666);
}
free(inst);
if (fd == -1)
{
MXS_ERROR("Failed to open binlog file %s: %s",
path, strerror(errno));
return 1;
}
mxs_log_flush_sync();
mxs_log_finish();
inst->binlog_fd = fd;
free(inst);
if (mariadb10_compat == 1)
inst->mariadb10_compat = 1;
return 1;
}
ptr = strrchr(path, '/');
if (ptr)
strncpy(inst->binlog_name, ptr+1, BINLOG_FNAMELEN);
else
strncpy(inst->binlog_name, path, BINLOG_FNAMELEN);
inst->binlog_fd = fd;
MXS_NOTICE("maxbinlogcheck %s", binlog_check_version);
if (mariadb10_compat == 1)
{
inst->mariadb10_compat = 1;
}
if (fstat(inst->binlog_fd, &statb) == 0)
filelen = statb.st_size;
ptr = strrchr(path, '/');
if (ptr)
{
strncpy(inst->binlog_name, ptr + 1, BINLOG_FNAMELEN);
}
else
{
strncpy(inst->binlog_name, path, BINLOG_FNAMELEN);
}
MXS_NOTICE("Checking %s (%s), size %lu bytes", path, inst->binlog_name, filelen);
MXS_NOTICE("maxbinlogcheck %s", binlog_check_version);
/* read binary log */
ret = blr_read_events_all_events(inst, fix_file, debug_out);
if (fstat(inst->binlog_fd, &statb) == 0)
{
filelen = statb.st_size;
}
close(inst->binlog_fd);
MXS_NOTICE("Checking %s (%s), size %lu bytes", path, inst->binlog_name, filelen);
mxs_log_flush_sync();
/* read binary log */
ret = blr_read_events_all_events(inst, fix_file, debug_out);
MXS_NOTICE("Check retcode: %i, Binlog Pos = %lu", ret, inst->binlog_position);
close(inst->binlog_fd);
mxs_log_flush_sync();
mxs_log_finish();
mxs_log_flush_sync();
free(inst);
MXS_NOTICE("Check retcode: %i, Binlog Pos = %lu", ret, inst->binlog_position);
return 0;
mxs_log_flush_sync();
mxs_log_finish();
free(inst);
return 0;
}
/**
@ -197,7 +220,7 @@ int main(int argc, char **argv) {
static void
printVersion(const char *progname)
{
printf("%s Version %s\n", progname, binlog_check_version);
printf("%s Version %s\n", progname, binlog_check_version);
}
/**
@ -206,14 +229,14 @@ printVersion(const char *progname)
static void
printUsage(const char *progname)
{
printVersion(progname);
printVersion(progname);
printf("The MaxScale binlog check utility.\n\n");
printf("Usage: %s [-f] [-d] [-v] [<binlog file>]\n\n", progname);
printf(" -f|--fix Fix binlog file, require write permissions (truncate)\n");
printf(" -d|--debug Print debug messages\n");
printf(" -M|--mariadb10 MariaDB 10 binlog compatibility\n");
printf(" -V|--version print version information and exit\n");
printf(" -?|--help Print this help text\n");
printf("The MaxScale binlog check utility.\n\n");
printf("Usage: %s [-f] [-d] [-v] [<binlog file>]\n\n", progname);
printf(" -f|--fix Fix binlog file, require write permissions (truncate)\n");
printf(" -d|--debug Print debug messages\n");
printf(" -M|--mariadb10 MariaDB 10 binlog compatibility\n");
printf(" -V|--version print version information and exit\n");
printf(" -?|--help Print this help text\n");
}