MXS-154: make gtid and file MARIADB_GTID_INFO fields static

gtid and file MARIADB_GTID_INFO fields are now a fixed size
This commit is contained in:
MassimilianoPinto
2017-11-27 17:46:26 +01:00
parent 23cd294dad
commit ba22e3b1db
4 changed files with 26 additions and 37 deletions

View File

@ -1064,15 +1064,14 @@ createInstance(SERVICE *service, char **options)
inst->current_pos <= 4) inst->current_pos <= 4)
{ {
MARIADB_GTID_INFO last_gtid = {}; MARIADB_GTID_INFO last_gtid = {};
memset(&last_gtid, 0, sizeof(last_gtid));
/* Get last MariaDB GTID from repo */ /* Get last MariaDB GTID from repo */
if (blr_load_last_mariadb_gtid(inst, &last_gtid) && if (blr_load_last_mariadb_gtid(inst, &last_gtid) &&
last_gtid.gtid != NULL) last_gtid.gtid[0])
{ {
/* Set MariaDB GTID */ /* Set MariaDB GTID */
strcpy(inst->last_mariadb_gtid, last_gtid.gtid); strcpy(inst->last_mariadb_gtid, last_gtid.gtid);
MXS_FREE(last_gtid.gtid);
MXS_FREE(last_gtid.file);
} }
else else
{ {

View File

@ -335,8 +335,8 @@ typedef struct mariadb_gtid_elems
/** MariaDB GTID info */ /** MariaDB GTID info */
typedef struct mariadb_gtid_info typedef struct mariadb_gtid_info
{ {
char *gtid; /** MariaDB 10.x GTID, string value */ char gtid[GTID_MAX_LEN + 1]; /** MariaDB 10.x GTID, string value */
char *file; /** The binlog file */ char file[BINLOG_FNAMELEN + 1]; /** The binlog file */
uint64_t start; /** The BEGIN pos: i.e the GTID event */ uint64_t start; /** The BEGIN pos: i.e the GTID event */
uint64_t end; /** The next_pos in COMMIT event */ uint64_t end; /** The next_pos in COMMIT event */
MARIADB_GTID_ELEMS gtid_elms; /** MariaDB 10.x GTID components */ MARIADB_GTID_ELEMS gtid_elms; /** MariaDB 10.x GTID components */

View File

@ -367,11 +367,13 @@ blr_file_init(ROUTER_INSTANCE *router)
/* - 2 - Get last file in GTID maps repo */ /* - 2 - Get last file in GTID maps repo */
else else
{ {
MARIADB_GTID_INFO last_gtid = {};
char f_prefix[BINLOG_FILE_EXTRA_INFO] = ""; char f_prefix[BINLOG_FILE_EXTRA_INFO] = "";
MARIADB_GTID_INFO last_gtid;
memset(&last_gtid, 0, sizeof(last_gtid));
// SELECT LAST FILE // SELECT LAST FILE
if (!blr_get_last_file(router, &last_gtid) || if (!blr_get_last_file(router, &last_gtid) ||
last_gtid.gtid == NULL) !last_gtid.gtid[0])
{ {
MXS_INFO("%s: cannot find any GTID in GTID maps repo", MXS_INFO("%s: cannot find any GTID in GTID maps repo",
router->service->name); router->service->name);
@ -412,9 +414,6 @@ blr_file_init(ROUTER_INSTANCE *router)
ret = blr_file_create(router, last_gtid.file); ret = blr_file_create(router, last_gtid.file);
} }
MXS_FREE(last_gtid.gtid);
MXS_FREE(last_gtid.file);
return ret; return ret;
} }
return 0; return 0;
@ -1597,8 +1596,9 @@ blr_file_next_exists(ROUTER_INSTANCE *router,
"rep_domain = %" PRIu32 " AND " "rep_domain = %" PRIu32 " AND "
"server_id = %" PRIu32 ")) + 1;"; "server_id = %" PRIu32 ")) + 1;";
MARIADB_GTID_INFO result = {};
MARIADB_GTID_ELEMS gtid_elms = {}; MARIADB_GTID_ELEMS gtid_elms = {};
MARIADB_GTID_INFO result;
memset(&result, 0, sizeof(result));
if ((sptr = strrchr(slave->binlogfile, '.')) == NULL) if ((sptr = strrchr(slave->binlogfile, '.')) == NULL)
{ {
@ -1675,16 +1675,10 @@ blr_file_next_exists(ROUTER_INSTANCE *router,
* Update GTID elems in the slave->f_info struct: * Update GTID elems in the slave->f_info struct:
* file and domain_id / server_id * file and domain_id / server_id
*/ */
if (slave->f_info.file)
{
MXS_FREE(slave->f_info.file);
slave->f_info.file = MXS_STRDUP_A(result.file);
}
strcpy(slave->f_info.file, result.file);
slave->f_info.gtid_elms.domain_id = result.gtid_elms.domain_id; slave->f_info.gtid_elms.domain_id = result.gtid_elms.domain_id;
slave->f_info.gtid_elms.server_id = result.gtid_elms.server_id; slave->f_info.gtid_elms.server_id = result.gtid_elms.server_id;
MXS_FREE(result.file);
} }
else else
{ {
@ -2572,9 +2566,10 @@ blr_read_events_all_events(ROUTER_INSTANCE *router,
char f_prefix[BINLOG_FILE_EXTRA_INFO] = ""; char f_prefix[BINLOG_FILE_EXTRA_INFO] = "";
if (hdr.event_type == MARIADB10_GTID_GTID_LIST_EVENT) if (hdr.event_type == MARIADB10_GTID_GTID_LIST_EVENT)
{ {
char mariadb_gtid[GTID_MAX_LEN + 1] = "";
MARIADB_GTID_INFO gtid_info = {};
unsigned long n_gtids; unsigned long n_gtids;
char mariadb_gtid[GTID_MAX_LEN + 1] = "";
MARIADB_GTID_INFO gtid_info;
memset(&gtid_info, 0, sizeof(gtid_info));
n_gtids = extract_field(ptr, 32); n_gtids = extract_field(ptr, 32);
/* The lower 28 bits are the number of GTIDs */ /* The lower 28 bits are the number of GTIDs */
@ -2621,7 +2616,7 @@ blr_read_events_all_events(ROUTER_INSTANCE *router,
/* Try loading last found GTID */ /* Try loading last found GTID */
if (router->mariadb10_gtid && if (router->mariadb10_gtid &&
blr_load_last_mariadb_gtid(router, &gtid_info) && blr_load_last_mariadb_gtid(router, &gtid_info) &&
gtid_info.gtid != NULL) gtid_info.gtid[0])
{ {
snprintf(mariadb_gtid, snprintf(mariadb_gtid,
GTID_MAX_LEN, GTID_MAX_LEN,
@ -3971,8 +3966,8 @@ bool blr_save_mariadb_gtid(ROUTER_INSTANCE *inst)
MARIADB_GTID_INFO gtid_info; MARIADB_GTID_INFO gtid_info;
MARIADB_GTID_ELEMS gtid_elms; MARIADB_GTID_ELEMS gtid_elms;
gtid_info.gtid = inst->pending_transaction.gtid; strcpy(gtid_info.gtid, inst->pending_transaction.gtid);
gtid_info.file = inst->binlog_name; strcpy(gtid_info.file, inst->binlog_name);
gtid_info.start = inst->pending_transaction.start_pos; gtid_info.start = inst->pending_transaction.start_pos;
gtid_info.end = inst->pending_transaction.end_pos; gtid_info.end = inst->pending_transaction.end_pos;
memcpy(&gtid_elms, memcpy(&gtid_elms,
@ -4080,8 +4075,8 @@ static int gtid_select_cb(void *data,
values[2] && values[2] &&
values[3]) values[3])
{ {
result->gtid = MXS_STRDUP_A(values[0]); strcpy(result->gtid, values[0]);
result->file = MXS_STRDUP_A(values[1]); strcpy(result->file, values[1]);
result->start = atoll(values[2]); result->start = atoll(values[2]);
result->end = atoll(values[3]); result->end = atoll(values[3]);
@ -4177,7 +4172,7 @@ bool blr_fetch_mariadb_gtid(ROUTER_SLAVE *slave,
} }
else else
{ {
if (result->gtid) if (result->gtid[0])
{ {
MXS_INFO("Binlog file to read from is %" PRIu32 "/%" PRIu32 "/%s", MXS_INFO("Binlog file to read from is %" PRIu32 "/%" PRIu32 "/%s",
result->gtid_elms.domain_id, result->gtid_elms.domain_id,
@ -4185,7 +4180,7 @@ bool blr_fetch_mariadb_gtid(ROUTER_SLAVE *slave,
result->file); result->file);
} }
} }
return result->gtid ? true : false; return result->gtid[0] ? true : false;
} }
/** /**
@ -4352,7 +4347,7 @@ static int gtid_file_select_cb(void *data,
values[2] && values[2] &&
values[3]) values[3])
{ {
result->file = MXS_STRDUP_A(values[3]); strcpy(result->file, values[3]);
result->gtid_elms.domain_id = atoll(values[1]); result->gtid_elms.domain_id = atoll(values[1]);
result->gtid_elms.server_id = atoll(values[2]); result->gtid_elms.server_id = atoll(values[2]);
} }

View File

@ -6742,6 +6742,8 @@ static bool blr_slave_gtid_request(ROUTER_INSTANCE *router,
char router_curr_file[BINLOG_FNAMELEN + 1]; char router_curr_file[BINLOG_FNAMELEN + 1];
char last_gtid[GTID_MAX_LEN + 1]; char last_gtid[GTID_MAX_LEN + 1];
memset(&f_gtid, 0, sizeof(f_gtid));
spinlock_acquire(&router->binlog_lock); spinlock_acquire(&router->binlog_lock);
// Set gtid as current router gtid // Set gtid as current router gtid
strcpy(last_gtid, router->last_mariadb_gtid); strcpy(last_gtid, router->last_mariadb_gtid);
@ -6800,9 +6802,6 @@ static bool blr_slave_gtid_request(ROUTER_INSTANCE *router,
snprintf(dbpath, sizeof(dbpath), "/%s/%s", snprintf(dbpath, sizeof(dbpath), "/%s/%s",
router->binlogdir, GTID_MAPS_DB); router->binlogdir, GTID_MAPS_DB);
/* Result set init */
f_gtid.gtid = NULL;
/* Open GTID maps read-only database */ /* Open GTID maps read-only database */
if (sqlite3_open_v2(dbpath, if (sqlite3_open_v2(dbpath,
&slave->gtid_maps, &slave->gtid_maps,
@ -6842,7 +6841,7 @@ static bool blr_slave_gtid_request(ROUTER_INSTANCE *router,
} }
/* Requested GTID Not Found */ /* Requested GTID Not Found */
if (!f_gtid.gtid) if (!f_gtid.gtid[0])
{ {
char errmsg[BINLOG_ERROR_MSG_LEN + 1]; char errmsg[BINLOG_ERROR_MSG_LEN + 1];
snprintf(errmsg, snprintf(errmsg,
@ -6961,10 +6960,6 @@ static bool blr_slave_gtid_request(ROUTER_INSTANCE *router,
/* Set GTID details in f_info*/ /* Set GTID details in f_info*/
memcpy(&slave->f_info, &f_gtid, sizeof(MARIADB_GTID_INFO)); memcpy(&slave->f_info, &f_gtid, sizeof(MARIADB_GTID_INFO));
/* Free gtid and file from result */
MXS_FREE(f_gtid.gtid);
MXS_FREE(f_gtid.file);
} }
} }