Skip to content

Commit

Permalink
SQL, IB: single check of vers_update_trt [#305]
Browse files Browse the repository at this point in the history
Warnings cleanup in vtmd.cc
Stale thd->vers_update_trt after rollback to savepoint fix
  • Loading branch information
midenok committed Nov 21, 2017
1 parent c31aa75 commit 2b16681
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 38 deletions.
5 changes: 2 additions & 3 deletions sql/handler.h
Expand Up @@ -1392,9 +1392,8 @@ struct handlerton
*/
/** Fill TRT record for update.
@param[out] trt TRT table which record[0] will be filled with
transaction data.
@return TRUE if update of TRT is required, FALSE otherwise */
bool (*vers_get_trt_data)(TR_table &trt);
transaction data. */
void (*vers_get_trt_data)(TR_table &trt);
};


Expand Down
4 changes: 2 additions & 2 deletions sql/sql_class.cc
Expand Up @@ -716,9 +716,9 @@ Time_zone * thd_get_timezone(THD * thd)
return thd->variables.time_zone;
}

void thd_vers_update_trt(THD * thd)
void thd_vers_update_trt(THD * thd, bool value)
{
thd->vers_update_trt= true;
thd->vers_update_trt= value;
}

THD::THD(my_thread_id id, bool is_wsrep_applier)
Expand Down
16 changes: 7 additions & 9 deletions sql/table.cc
Expand Up @@ -8557,18 +8557,16 @@ bool TR_table::update()
handlerton *hton= table->s->db_type();
DBUG_ASSERT(hton);
DBUG_ASSERT(hton->flags & HTON_NATIVE_SYS_VERSIONING);
DBUG_ASSERT(thd->vers_update_trt);

bool updated;
if ((updated= hton->vers_get_trt_data(*this)))
hton->vers_get_trt_data(*this);
int error= table->file->ha_write_row(table->record[0]);
if (error)
{
int error= table->file->ha_write_row(table->record[0]);
if (error)
{
table->file->print_error(error, MYF(0));
}
return error;
table->file->print_error(error, MYF(0));
}
return false;
thd->vers_update_trt= false;
return error;
}

#define newx new (thd->mem_root)
Expand Down
1 change: 1 addition & 0 deletions sql/vtmd.cc
Expand Up @@ -257,6 +257,7 @@ VTMD_table::update(THD *thd, const char* archive_name)
quit:
if (!result && opt_transaction_registry)
{
DBUG_ASSERT(thd->vers_update_trt);
TR_table trt(thd, true);
result= trt.update();
}
Expand Down
2 changes: 1 addition & 1 deletion sql/vtmd.h
@@ -1,10 +1,10 @@
#ifndef VTMD_INCLUDED
#define VTMD_INCLUDED

#include "unireg.h"
#include <mysqld_error.h>
#include "my_sys.h"
#include "table.h"
#include "unireg.h"

#include "vers_utils.h"

Expand Down
40 changes: 19 additions & 21 deletions storage/innobase/handler/ha_innodb.cc
Expand Up @@ -3627,28 +3627,24 @@ static const char* ha_innobase_exts[] = {
NullS
};

bool innodb_get_trt_data(TR_table &trt)
void innodb_get_trt_data(TR_table &trt)
{
THD *thd = trt.get_thd();
trx_t *trx = thd_to_trx(thd);
ut_a(trx);
if (trx->vers_update_trt)
{
mutex_enter(&trx_sys->mutex);
trx_id_t commit_id = trx_sys_get_new_trx_id();
ulint sec = 0;
ulint usec = 0;
ut_usectime(&sec, &usec);
mutex_exit(&trx_sys->mutex);

// silent downgrade cast warning on win64
timeval commit_ts = {static_cast<int>(sec),
static_cast<int>(usec)};
trt.store_data(trx->id, commit_id, commit_ts);
trx->vers_update_trt = false;
return true;
}
return false;
ut_a(trx->vers_update_trt);
mutex_enter(&trx_sys->mutex);
trx_id_t commit_id = trx_sys_get_new_trx_id();
ulint sec = 0;
ulint usec = 0;
ut_usectime(&sec, &usec);
mutex_exit(&trx_sys->mutex);

// silent downgrade cast warning on win64
timeval commit_ts = {static_cast<int>(sec),
static_cast<int>(usec)};
trt.store_data(trx->id, commit_id, commit_ts);
trx->vers_update_trt = false;
}

/*********************************************************************//**
Expand Down Expand Up @@ -4904,6 +4900,8 @@ innobase_rollback_to_savepoint(
dberr_t error = trx_rollback_to_savepoint_for_mysql(
trx, name, &mysql_binlog_cache_pos);

thd_vers_update_trt(thd, trx->vers_update_trt);

if (error == DB_SUCCESS && trx->fts_trx != NULL) {
fts_savepoint_rollback(trx, name);
}
Expand Down Expand Up @@ -8381,7 +8379,7 @@ ha_innobase::write_row(
error = row_insert_for_mysql((byte*) record, m_prebuilt, vers_set_fields);

if (m_prebuilt->trx->vers_update_trt)
thd_vers_update_trt(m_user_thd);
thd_vers_update_trt(m_user_thd, true);

DEBUG_SYNC(m_user_thd, "ib_after_row_insert");

Expand Down Expand Up @@ -9203,7 +9201,7 @@ ha_innobase::update_row(
}

if (m_prebuilt->trx->vers_update_trt)
thd_vers_update_trt(m_user_thd);
thd_vers_update_trt(m_user_thd, true);

if (error == DB_SUCCESS && autoinc) {
/* A value for an AUTO_INCREMENT column
Expand Down Expand Up @@ -9325,7 +9323,7 @@ ha_innobase::delete_row(
error = row_update_for_mysql(m_prebuilt, vers_set_fields);

if (m_prebuilt->trx->vers_update_trt)
thd_vers_update_trt(m_user_thd);
thd_vers_update_trt(m_user_thd, true);

innobase_srv_conc_exit_innodb(m_prebuilt);

Expand Down
2 changes: 1 addition & 1 deletion storage/innobase/handler/ha_innodb.h
Expand Up @@ -586,7 +586,7 @@ bool thd_is_strict_mode(const MYSQL_THD thd);
*/
extern void mysql_bin_log_commit_pos(THD *thd, ulonglong *out_pos, const char **out_file);

extern void thd_vers_update_trt(THD * thd);
extern void thd_vers_update_trt(THD * thd, bool value);

/** Get the partition_info working copy.
@param thd Thread object.
Expand Down
2 changes: 1 addition & 1 deletion storage/innobase/handler/handler0alter.cc
Expand Up @@ -7080,7 +7080,7 @@ ha_innobase::inplace_alter_table(
ha_alter_info->handler_flags & Alter_inplace_info::ALTER_DROP_HISTORICAL);

if (m_prebuilt->trx->vers_update_trt)
thd_vers_update_trt(m_user_thd);
thd_vers_update_trt(m_user_thd, true);

#ifndef DBUG_OFF
oom:
Expand Down

0 comments on commit 2b16681

Please sign in to comment.