1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-30 16:24:05 +03:00

remove handler::open_read_view()

ht->start_consistent_snapshot() is also not a way,
because some engines (e.g. rocksdb) only do it readonly.
instead, downgrade the lock after reading the first row
(which implicitly opens a read view).
This commit is contained in:
Sergei Golubchik
2022-05-25 19:20:30 +02:00
parent 0b67af5a81
commit d767ed5c89
4 changed files with 144 additions and 177 deletions

View File

@ -3562,7 +3562,6 @@ public:
/** to be actually called to get 'check()' functionality*/
int ha_check(THD *thd, HA_CHECK_OPT *check_opt);
int ha_repair(THD* thd, HA_CHECK_OPT* check_opt);
virtual void open_read_view(){}
void ha_start_bulk_insert(ha_rows rows, uint flags= 0)
{
DBUG_ENTER("handler::ha_start_bulk_insert");

View File

@ -11623,52 +11623,11 @@ copy_data_between_tables(THD *thd, TABLE *from, TABLE *to,
*/
thd_progress_init(thd, MY_TEST(order) + 2 + 2 * MY_TEST(online));
#ifdef HAVE_REPLICATION
if (online)
{
from->s->online_alter_binlog= new (thd->mem_root) Cache_flip_event_log();
if (!from->s->online_alter_binlog)
DBUG_RETURN(1);
from->s->online_alter_binlog->init_pthread_objects();
error= from->s->online_alter_binlog->open(WRITE_CACHE);
if (!error)
{
/*
Some engines (for example, InnoDB) might not create a read view
until the first row is read. We need to be sure that we won't see any
table changes after we enable replication and downgrade the MDL.
So, we force the consistent snapshot to be created now.
*/
handlerton *ht= from->s->db_type();
if (ht->start_consistent_snapshot)
{
thd->tx_isolation= ISO_REPEATABLE_READ;
from->file->open_read_view();
}
}
if (error)
{
online_alter_cleanup_binlog(thd, from->s);
DBUG_RETURN(1);
}
from->mdl_ticket->downgrade_lock(MDL_SHARED_UPGRADABLE);
DEBUG_SYNC(thd, "alter_table_online_downgraded");
}
#else
DBUG_ASSERT(!online);
#endif // HAVE_REPLICATION
if (!(copy= new (thd->mem_root) Copy_field[to->s->fields]))
DBUG_RETURN(-1);
if (mysql_trans_prepare_alter_copy_data(thd))
{
online_alter_cleanup_binlog(thd, from->s);
delete [] copy;
DBUG_RETURN(-1);
}
@ -11676,7 +11635,6 @@ copy_data_between_tables(THD *thd, TABLE *from, TABLE *to,
/* We need external lock before we can disable/enable keys */
if (to->file->ha_external_lock(thd, F_WRLCK))
{
online_alter_cleanup_binlog(thd, from->s);
/* Undo call to mysql_trans_prepare_alter_copy_data() */
ha_enable_transaction(thd, TRUE);
delete [] copy;
@ -11822,9 +11780,31 @@ copy_data_between_tables(THD *thd, TABLE *from, TABLE *to,
if (!ignore) /* for now, InnoDB needs the undo log for ALTER IGNORE */
to->file->extra(HA_EXTRA_BEGIN_ALTER_COPY);
DEBUG_SYNC(thd, "alter_table_copy_start");
if (!(error= info.read_record()))
{
#ifdef HAVE_REPLICATION
if (online)
{
from->s->online_alter_binlog= new (thd->mem_root) Cache_flip_event_log();
if (!from->s->online_alter_binlog)
DBUG_RETURN(1);
from->s->online_alter_binlog->init_pthread_objects();
error= from->s->online_alter_binlog->open(WRITE_CACHE);
while (likely(!(error= info.read_record())))
if (error)
{
online_alter_cleanup_binlog(thd, from->s);
goto err;
}
from->mdl_ticket->downgrade_lock(MDL_SHARED_UPGRADABLE);
DEBUG_SYNC(thd, "alter_table_online_downgraded");
}
#else
DBUG_ASSERT(!online);
#endif // HAVE_REPLICATION
do
{
if (unlikely(thd->killed))
{
@ -11956,7 +11936,10 @@ copy_data_between_tables(THD *thd, TABLE *from, TABLE *to,
mysql_stage_set_work_completed(thd->m_stage_progress_psi, found_count);
}
thd->get_stmt_da()->inc_current_row_for_warning();
} while (!(error= info.read_record()));
}
else
online= false;
DEBUG_SYNC(thd, "alter_table_copy_end");

View File

@ -21165,17 +21165,3 @@ buf_pool_size_align(
return (size / m + 1) * m;
}
}
void ha_innobase::open_read_view()
{
trx_t *trx= m_prebuilt->trx;
auto thd_iso= thd_get_trx_isolation(m_user_thd);
trx->isolation_level= innobase_map_isolation_level(thd_iso);
ut_ad(trx->isolation_level == TRX_ISO_REPEATABLE_READ);
ut_ad(!trx_is_started(trx));
trx_start_if_not_started_xa(trx, false);
trx->read_view.open(m_prebuilt->trx);
}

View File

@ -438,7 +438,6 @@ public:
const KEY_PART_INFO& old_part,
const KEY_PART_INFO& new_part) const override;
void open_read_view() override;
protected:
bool
can_convert_string(const Field_string* field,