Reformat binlog router.
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@ -31,8 +31,8 @@
|
|||||||
* @verbatim
|
* @verbatim
|
||||||
* Revision History
|
* Revision History
|
||||||
*
|
*
|
||||||
* Date Who Description
|
* Date Who Description
|
||||||
* 07/04/2014 Mark Riddoch Initial implementation
|
* 07/04/2014 Mark Riddoch Initial implementation
|
||||||
*
|
*
|
||||||
* @endverbatim
|
* @endverbatim
|
||||||
*/
|
*/
|
||||||
@ -58,7 +58,7 @@
|
|||||||
* effect also determine the binlog file to read and the position to read
|
* effect also determine the binlog file to read and the position to read
|
||||||
* from.
|
* from.
|
||||||
*
|
*
|
||||||
* @param router The router instance
|
* @param router The router instance
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
blr_init_cache(ROUTER_INSTANCE *router)
|
blr_init_cache(ROUTER_INSTANCE *router)
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -24,13 +24,13 @@
|
|||||||
* @verbatim
|
* @verbatim
|
||||||
* Revision History
|
* Revision History
|
||||||
*
|
*
|
||||||
* Date Who Description
|
* Date Who Description
|
||||||
* 24/07/2015 Massimiliano Pinto Initial implementation
|
* 24/07/2015 Massimiliano Pinto Initial implementation
|
||||||
* 26/08/2015 Massimiliano Pinto Added mariadb10 option
|
* 26/08/2015 Massimiliano Pinto Added mariadb10 option
|
||||||
* for MariaDB 10 binlog compatibility
|
* for MariaDB 10 binlog compatibility
|
||||||
* Currently MariadDB 10 starting transactions
|
* Currently MariadDB 10 starting transactions
|
||||||
* are detected checking GTID event
|
* are detected checking GTID event
|
||||||
* with flags = 0
|
* with flags = 0
|
||||||
*
|
*
|
||||||
* @endverbatim
|
* @endverbatim
|
||||||
*/
|
*/
|
||||||
@ -68,13 +68,14 @@ extern uint32_t extract_field(uint8_t *src, int bits);
|
|||||||
static void printVersion(const char *progname);
|
static void printVersion(const char *progname);
|
||||||
static void printUsage(const char *progname);
|
static void printUsage(const char *progname);
|
||||||
|
|
||||||
static struct option long_options[] = {
|
static struct option long_options[] =
|
||||||
{"debug", no_argument, 0, 'd'},
|
{
|
||||||
{"version", no_argument, 0, 'V'},
|
{"debug", no_argument, 0, 'd'},
|
||||||
{"fix", no_argument, 0, 'f'},
|
{"version", no_argument, 0, 'V'},
|
||||||
{"mariadb10", no_argument, 0, 'M'},
|
{"fix", no_argument, 0, 'f'},
|
||||||
{"help", no_argument, 0, '?'},
|
{"mariadb10", no_argument, 0, 'M'},
|
||||||
{0, 0, 0, 0}
|
{"help", no_argument, 0, '?'},
|
||||||
|
{0, 0, 0, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
char *binlog_check_version = "1.1.0";
|
char *binlog_check_version = "1.1.0";
|
||||||
@ -82,119 +83,135 @@ char *binlog_check_version = "1.1.0";
|
|||||||
int
|
int
|
||||||
MaxScaleUptime()
|
MaxScaleUptime()
|
||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv)
|
||||||
ROUTER_INSTANCE *inst;
|
{
|
||||||
int fd;
|
ROUTER_INSTANCE *inst;
|
||||||
int ret;
|
int fd;
|
||||||
char *ptr;
|
int ret;
|
||||||
char path[PATH_MAX+1] = "";
|
char *ptr;
|
||||||
unsigned long filelen = 0;
|
char path[PATH_MAX + 1] = "";
|
||||||
struct stat statb;
|
unsigned long filelen = 0;
|
||||||
char c;
|
struct stat statb;
|
||||||
int option_index = 0;
|
char c;
|
||||||
int num_args = 0;
|
int option_index = 0;
|
||||||
int debug_out = 0;
|
int num_args = 0;
|
||||||
int fix_file = 0;
|
int debug_out = 0;
|
||||||
int mariadb10_compat = 0;
|
int fix_file = 0;
|
||||||
|
int mariadb10_compat = 0;
|
||||||
|
|
||||||
while ((c = getopt_long(argc, argv, "dVfM?", long_options, &option_index)) >= 0)
|
while ((c = getopt_long(argc, argv, "dVfM?", long_options, &option_index)) >= 0)
|
||||||
{
|
{
|
||||||
switch (c) {
|
switch (c)
|
||||||
case 'd':
|
{
|
||||||
debug_out = 1;
|
case 'd':
|
||||||
break;
|
debug_out = 1;
|
||||||
case 'V':
|
break;
|
||||||
printVersion(*argv);
|
case 'V':
|
||||||
exit(EXIT_SUCCESS);
|
printVersion(*argv);
|
||||||
break;
|
exit(EXIT_SUCCESS);
|
||||||
case 'f':
|
break;
|
||||||
fix_file = 1;
|
case 'f':
|
||||||
break;
|
fix_file = 1;
|
||||||
case 'M':
|
break;
|
||||||
mariadb10_compat = 1;
|
case 'M':
|
||||||
break;
|
mariadb10_compat = 1;
|
||||||
case '?':
|
break;
|
||||||
printUsage(*argv);
|
case '?':
|
||||||
exit(optopt ? EXIT_FAILURE : EXIT_SUCCESS);
|
printUsage(*argv);
|
||||||
}
|
exit(optopt ? EXIT_FAILURE : EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
num_args = optind;
|
num_args = optind;
|
||||||
|
|
||||||
mxs_log_init(NULL, NULL, LOG_TARGET_DEFAULT);
|
mxs_log_init(NULL, NULL, LOG_TARGET_DEFAULT);
|
||||||
mxs_log_set_augmentation(0);
|
mxs_log_set_augmentation(0);
|
||||||
mxs_log_set_priority_enabled(LOG_DEBUG, debug_out);
|
mxs_log_set_priority_enabled(LOG_DEBUG, debug_out);
|
||||||
|
|
||||||
if ((inst = calloc(1, sizeof(ROUTER_INSTANCE))) == NULL) {
|
if ((inst = calloc(1, sizeof(ROUTER_INSTANCE))) == NULL)
|
||||||
MXS_ERROR("Memory allocation failed for ROUTER_INSTANCE");
|
{
|
||||||
|
MXS_ERROR("Memory allocation failed for ROUTER_INSTANCE");
|
||||||
|
|
||||||
mxs_log_flush_sync();
|
mxs_log_flush_sync();
|
||||||
mxs_log_finish();
|
mxs_log_finish();
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argv[num_args] == NULL) {
|
if (argv[num_args] == NULL)
|
||||||
printf("ERROR: No binlog file was specified\n");
|
{
|
||||||
exit(EXIT_FAILURE);
|
printf("ERROR: No binlog file was specified\n");
|
||||||
}
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
strncpy(path, argv[num_args], PATH_MAX);
|
strncpy(path, argv[num_args], PATH_MAX);
|
||||||
|
|
||||||
if (fix_file)
|
if (fix_file)
|
||||||
fd = open(path, O_RDWR, 0666);
|
{
|
||||||
else
|
fd = open(path, O_RDWR, 0666);
|
||||||
fd = open(path, O_RDONLY, 0666);
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fd = open(path, O_RDONLY, 0666);
|
||||||
|
}
|
||||||
|
|
||||||
if (fd == -1)
|
if (fd == -1)
|
||||||
{
|
{
|
||||||
MXS_ERROR("Failed to open binlog file %s: %s",
|
MXS_ERROR("Failed to open binlog file %s: %s",
|
||||||
path, strerror(errno));
|
path, strerror(errno));
|
||||||
|
|
||||||
mxs_log_flush_sync();
|
mxs_log_flush_sync();
|
||||||
mxs_log_finish();
|
mxs_log_finish();
|
||||||
|
|
||||||
free(inst);
|
free(inst);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
inst->binlog_fd = fd;
|
inst->binlog_fd = fd;
|
||||||
|
|
||||||
if (mariadb10_compat == 1)
|
if (mariadb10_compat == 1)
|
||||||
inst->mariadb10_compat = 1;
|
{
|
||||||
|
inst->mariadb10_compat = 1;
|
||||||
|
}
|
||||||
|
|
||||||
ptr = strrchr(path, '/');
|
ptr = strrchr(path, '/');
|
||||||
if (ptr)
|
if (ptr)
|
||||||
strncpy(inst->binlog_name, ptr+1, BINLOG_FNAMELEN);
|
{
|
||||||
else
|
strncpy(inst->binlog_name, ptr + 1, BINLOG_FNAMELEN);
|
||||||
strncpy(inst->binlog_name, path, BINLOG_FNAMELEN);
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
strncpy(inst->binlog_name, path, BINLOG_FNAMELEN);
|
||||||
|
}
|
||||||
|
|
||||||
MXS_NOTICE("maxbinlogcheck %s", binlog_check_version);
|
MXS_NOTICE("maxbinlogcheck %s", binlog_check_version);
|
||||||
|
|
||||||
if (fstat(inst->binlog_fd, &statb) == 0)
|
if (fstat(inst->binlog_fd, &statb) == 0)
|
||||||
filelen = statb.st_size;
|
{
|
||||||
|
filelen = statb.st_size;
|
||||||
|
}
|
||||||
|
|
||||||
MXS_NOTICE("Checking %s (%s), size %lu bytes", path, inst->binlog_name, filelen);
|
MXS_NOTICE("Checking %s (%s), size %lu bytes", path, inst->binlog_name, filelen);
|
||||||
|
|
||||||
/* read binary log */
|
/* read binary log */
|
||||||
ret = blr_read_events_all_events(inst, fix_file, debug_out);
|
ret = blr_read_events_all_events(inst, fix_file, debug_out);
|
||||||
|
|
||||||
close(inst->binlog_fd);
|
close(inst->binlog_fd);
|
||||||
|
|
||||||
mxs_log_flush_sync();
|
mxs_log_flush_sync();
|
||||||
|
|
||||||
MXS_NOTICE("Check retcode: %i, Binlog Pos = %lu", ret, inst->binlog_position);
|
MXS_NOTICE("Check retcode: %i, Binlog Pos = %lu", ret, inst->binlog_position);
|
||||||
|
|
||||||
mxs_log_flush_sync();
|
mxs_log_flush_sync();
|
||||||
mxs_log_finish();
|
mxs_log_finish();
|
||||||
|
|
||||||
free(inst);
|
free(inst);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -203,7 +220,7 @@ int main(int argc, char **argv) {
|
|||||||
static void
|
static void
|
||||||
printVersion(const char *progname)
|
printVersion(const char *progname)
|
||||||
{
|
{
|
||||||
printf("%s Version %s\n", progname, binlog_check_version);
|
printf("%s Version %s\n", progname, binlog_check_version);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -212,14 +229,14 @@ printVersion(const char *progname)
|
|||||||
static void
|
static void
|
||||||
printUsage(const char *progname)
|
printUsage(const char *progname)
|
||||||
{
|
{
|
||||||
printVersion(progname);
|
printVersion(progname);
|
||||||
|
|
||||||
printf("The MaxScale binlog check utility.\n\n");
|
printf("The MaxScale binlog check utility.\n\n");
|
||||||
printf("Usage: %s [-f] [-d] [-v] [<binlog file>]\n\n", progname);
|
printf("Usage: %s [-f] [-d] [-v] [<binlog file>]\n\n", progname);
|
||||||
printf(" -f|--fix Fix binlog file, require write permissions (truncate)\n");
|
printf(" -f|--fix Fix binlog file, require write permissions (truncate)\n");
|
||||||
printf(" -d|--debug Print debug messages\n");
|
printf(" -d|--debug Print debug messages\n");
|
||||||
printf(" -M|--mariadb10 MariaDB 10 binlog compatibility\n");
|
printf(" -M|--mariadb10 MariaDB 10 binlog compatibility\n");
|
||||||
printf(" -V|--version print version information and exit\n");
|
printf(" -V|--version print version information and exit\n");
|
||||||
printf(" -?|--help Print this help text\n");
|
printf(" -?|--help Print this help text\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user