if (!(new_handler->ref= (uchar*) alloc_root(mem_root,
ALIGN_SIZE(ref_length)*2))) goto err;
if (new_handler->ha_open(table, name,
table->db_stat,
HA_OPEN_IGNORE_IF_LOCKED | HA_OPEN_NO_PSI_CALL)) goto err;
/* Reuse original storage engine data for duplicate key reference */
new_handler->ref= file->ref;
new_handler->ref_length= file->ref_length;
new_handler->dup_ref= file->dup_ref;
DBUG_RETURN((handler*) new_handler);
err: delete new_handler;
DBUG_RETURN(NULL);
}
/* Mapthecreatetabletotheoriginalstorageengine
*/
int ha_sequence::create(constchar *name, TABLE *form,
HA_CREATE_INFO *create_info)
{
DBUG_ASSERT(create_info->sequence); /* Sequence tables has one and only one row */
create_info->max_rows= create_info->min_rows= 1;
file->option_struct= option_struct; return (file->create(name, form, create_info));
}
int ha_sequence::write_row(const uchar *buf)
{ int error;
sequence_definition tmp_seq; bool sequence_locked;
THD *thd= table->in_use;
DBUG_ENTER("ha_sequence::write_row");
DBUG_ASSERT(table->record[0] == buf);
/* Logtobinarylogevenifthisfunctionhasbeencalledbefore (Thefunctionendsbysettingrow_loggingto0)
*/
row_logging= row_logging_init; if (unlikely(sequence->initialized == SEQUENCE::SEQ_IN_PREPARE))
{ /* This calls is from ha_open() as part of create table */
DBUG_RETURN(file->write_row(buf));
} if (unlikely(sequence->initialized == SEQUENCE::SEQ_IN_ALTER))
{ int error= 0; /* This is called from alter table */
tmp_seq.read_fields(table); if (tmp_seq.check_and_adjust(thd, 0))
DBUG_RETURN(HA_ERR_SEQUENCE_INVALID_DATA);
sequence->copy(&tmp_seq); if (likely(!(error= file->write_row(buf))))
sequence->initialized= SEQUENCE::SEQ_READY_TO_USE;
row_logging= 0;
DBUG_RETURN(error);
} if (unlikely(sequence->initialized != SEQUENCE::SEQ_READY_TO_USE))
DBUG_RETURN(HA_ERR_WRONG_COMMAND);
sequence_locked= write_locked; if (!write_locked) // If not from next_value()
{ /* Usertriestowriteafullrowdirectlytothesequencetablewith INSERTorLOADDATA.
-Getanexclusivelockforthetable.Thisisneededtoensurethat weexcuteallfullinserts(sameasALTERSEQUENCE)insameorder onmasterandslaves -CheckthatthenewrowisanaccurateSEQUENCEobject
*/ /* mark a full binlog image insert to force non-parallel slave */ #ifdef WITH_WSREP if (WSREP_ON && WSREP(thd) && wsrep_thd_is_applying(thd))
{
WSREP_DEBUG("skipped to mark trx as DDL due to sequence table insert");
} else #endif/* WITH_WSREP */
thd->transaction->stmt.mark_trans_did_ddl(); if (table->s->tmp_table == NO_TMP_TABLE &&
thd->mdl_context.upgrade_shared_lock(table->mdl_ticket,
MDL_EXCLUSIVE,
thd->variables.
lock_wait_timeout))
DBUG_RETURN(ER_LOCK_WAIT_TIMEOUT);
tmp_seq.read_fields(table); if (tmp_seq.check_and_adjust(thd, 0))
DBUG_RETURN(HA_ERR_SEQUENCE_INVALID_DATA);
if (likely(!(error= file->update_first_row(buf))))
{
Log_func *log_func= Write_rows_log_event::binlog_row_logging_function; if (!sequence_locked)
sequence->copy(&tmp_seq);
rows_stats.updated++; /* We have to do the logging while we hold the sequence mutex */
error= binlog_log_row(0, buf, log_func);
}
/* Row is already logged, don't log it again in ha_write_row() */
row_logging= 0;
sequence->all_values_used= 0; if (!sequence_locked)
sequence->write_unlock(table);
DBUG_RETURN(error);
}
int ha_sequence::info(uint flag)
{
DBUG_ENTER("ha_sequence::info");
file->info(flag); /* Inform optimizer that we have always only one record */
stats= file->stats;
stats.records= 1;
DBUG_RETURN(false);
}
int ha_sequence::extra(enum ha_extra_function operation)
{ if (operation == HA_EXTRA_PREPARE_FOR_ALTER_TABLE)
{ /* In case of ALTER TABLE allow ::write_row() to copy rows */
sequence->initialized= SEQUENCE::SEQ_IN_ALTER;
} return file->extra(operation);
}
bool ha_sequence::check_if_incompatible_data(HA_CREATE_INFO *create_info,
uint table_changes)
{ /* Table definition is locked for SEQUENCE tables */ return(COMPATIBLE_DATA_YES);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.