Commit 354e567c authored by Sergei Golubchik's avatar Sergei Golubchik

federatedx small cleanup

* reduce code duplication
* change int->void for the function that doesn't return an error
* use ha_thd()
parent e05883bf
...@@ -1639,6 +1639,7 @@ static FEDERATEDX_SHARE *get_share(const char *table_name, TABLE *table) ...@@ -1639,6 +1639,7 @@ static FEDERATEDX_SHARE *get_share(const char *table_name, TABLE *table)
} }
static federatedx_txn zero_txn;
static int free_server(federatedx_txn *txn, FEDERATEDX_SERVER *server) static int free_server(federatedx_txn *txn, FEDERATEDX_SERVER *server)
{ {
bool destroy; bool destroy;
...@@ -1654,11 +1655,8 @@ static int free_server(federatedx_txn *txn, FEDERATEDX_SERVER *server) ...@@ -1654,11 +1655,8 @@ static int free_server(federatedx_txn *txn, FEDERATEDX_SERVER *server)
MEM_ROOT mem_root; MEM_ROOT mem_root;
if (!txn) if (!txn)
{ txn= &zero_txn;
federatedx_txn tmp_txn;
tmp_txn.close(server);
}
else
txn->close(server); txn->close(server);
DBUG_ASSERT(server->io_count == 0); DBUG_ASSERT(server->io_count == 0);
...@@ -1678,7 +1676,7 @@ static int free_server(federatedx_txn *txn, FEDERATEDX_SERVER *server) ...@@ -1678,7 +1676,7 @@ static int free_server(federatedx_txn *txn, FEDERATEDX_SERVER *server)
free memory associated with it. free memory associated with it.
*/ */
static int free_share(federatedx_txn *txn, FEDERATEDX_SHARE *share) static void free_share(federatedx_txn *txn, FEDERATEDX_SHARE *share)
{ {
bool destroy; bool destroy;
DBUG_ENTER("free_share"); DBUG_ENTER("free_share");
...@@ -1701,7 +1699,7 @@ static int free_share(federatedx_txn *txn, FEDERATEDX_SHARE *share) ...@@ -1701,7 +1699,7 @@ static int free_share(federatedx_txn *txn, FEDERATEDX_SHARE *share)
free_server(txn, server); free_server(txn, server);
} }
DBUG_RETURN(0); DBUG_VOID_RETURN;
} }
...@@ -1767,7 +1765,7 @@ int ha_federatedx::disconnect(handlerton *hton, MYSQL_THD thd) ...@@ -1767,7 +1765,7 @@ int ha_federatedx::disconnect(handlerton *hton, MYSQL_THD thd)
int ha_federatedx::open(const char *name, int mode, uint test_if_locked) int ha_federatedx::open(const char *name, int mode, uint test_if_locked)
{ {
int error; int error;
THD *thd= current_thd; THD *thd= ha_thd();
DBUG_ENTER("ha_federatedx::open"); DBUG_ENTER("ha_federatedx::open");
if (!(share= get_share(name, table))) if (!(share= get_share(name, table)))
...@@ -1811,8 +1809,8 @@ int ha_federatedx::open(const char *name, int mode, uint test_if_locked) ...@@ -1811,8 +1809,8 @@ int ha_federatedx::open(const char *name, int mode, uint test_if_locked)
int ha_federatedx::close(void) int ha_federatedx::close(void)
{ {
int retval= 0, error; int retval= 0;
THD *thd= current_thd; THD *thd= ha_thd();
DBUG_ENTER("ha_federatedx::close"); DBUG_ENTER("ha_federatedx::close");
/* free the result set */ /* free the result set */
...@@ -1822,24 +1820,13 @@ int ha_federatedx::close(void) ...@@ -1822,24 +1820,13 @@ int ha_federatedx::close(void)
/* Disconnect from mysql */ /* Disconnect from mysql */
if (!thd || !(txn= get_txn(thd, true))) if (!thd || !(txn= get_txn(thd, true)))
{ txn= &zero_txn;
federatedx_txn tmp_txn;
tmp_txn.release(&io);
DBUG_ASSERT(io == NULL);
if ((error= free_share(&tmp_txn, share)))
retval= error;
}
else
{
txn->release(&io); txn->release(&io);
DBUG_ASSERT(io == NULL); DBUG_ASSERT(io == NULL);
if ((error= free_share(txn, share))) free_share(txn, share);
retval= error;
}
DBUG_RETURN(retval); DBUG_RETURN(retval);
} }
...@@ -1862,8 +1849,7 @@ int ha_federatedx::close(void) ...@@ -1862,8 +1849,7 @@ int ha_federatedx::close(void)
0 otherwise 0 otherwise
*/ */
static inline uint field_in_record_is_null(TABLE *table, static inline uint field_in_record_is_null(TABLE *table, Field *field,
Field *field,
char *record) char *record)
{ {
int null_offset; int null_offset;
...@@ -2203,7 +2189,7 @@ int ha_federatedx::end_bulk_insert() ...@@ -2203,7 +2189,7 @@ int ha_federatedx::end_bulk_insert()
*/ */
void ha_federatedx::update_auto_increment(void) void ha_federatedx::update_auto_increment(void)
{ {
THD *thd= current_thd; THD *thd= ha_thd();
DBUG_ENTER("ha_federatedx::update_auto_increment"); DBUG_ENTER("ha_federatedx::update_auto_increment");
ha_federatedx::info(HA_STATUS_AUTO); ha_federatedx::info(HA_STATUS_AUTO);
...@@ -3058,7 +3044,7 @@ int ha_federatedx::rnd_pos(uchar *buf, uchar *pos) ...@@ -3058,7 +3044,7 @@ int ha_federatedx::rnd_pos(uchar *buf, uchar *pos)
int ha_federatedx::info(uint flag) int ha_federatedx::info(uint flag)
{ {
uint error_code; uint error_code;
THD *thd= current_thd; THD *thd= ha_thd();
federatedx_txn *tmp_txn; federatedx_txn *tmp_txn;
federatedx_io *tmp_io= 0, **iop= 0; federatedx_io *tmp_io= 0, **iop= 0;
DBUG_ENTER("ha_federatedx::info"); DBUG_ENTER("ha_federatedx::info");
...@@ -3189,7 +3175,7 @@ int ha_federatedx::reset(void) ...@@ -3189,7 +3175,7 @@ int ha_federatedx::reset(void)
federatedx_io *tmp_io= 0, **iop; federatedx_io *tmp_io= 0, **iop;
// external_lock may not have been called so txn may not be set // external_lock may not have been called so txn may not be set
tmp_txn= get_txn(current_thd); tmp_txn= get_txn(ha_thd());
if (!*(iop= &io) && (error= tmp_txn->acquire(share, TRUE, (iop= &tmp_io)))) if (!*(iop= &io) && (error= tmp_txn->acquire(share, TRUE, (iop= &tmp_io))))
{ {
...@@ -3364,7 +3350,7 @@ int ha_federatedx::create(const char *name, TABLE *table_arg, ...@@ -3364,7 +3350,7 @@ int ha_federatedx::create(const char *name, TABLE *table_arg,
HA_CREATE_INFO *create_info) HA_CREATE_INFO *create_info)
{ {
int retval; int retval;
THD *thd= current_thd; THD *thd= ha_thd();
FEDERATEDX_SHARE tmp_share; // Only a temporary share, to test the url FEDERATEDX_SHARE tmp_share; // Only a temporary share, to test the url
federatedx_txn *tmp_txn; federatedx_txn *tmp_txn;
federatedx_io *tmp_io= NULL; federatedx_io *tmp_io= NULL;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment