diff options
Diffstat (limited to 'sql/ha_sequence.cc')
-rw-r--r-- | sql/ha_sequence.cc | 33 |
1 files changed, 17 insertions, 16 deletions
diff --git a/sql/ha_sequence.cc b/sql/ha_sequence.cc index b500ce3c1f6..d5064af16c3 100644 --- a/sql/ha_sequence.cc +++ b/sql/ha_sequence.cc @@ -81,17 +81,21 @@ int ha_sequence::open(const char *name, int mode, uint flags) DBUG_ASSERT(table->s == table_share && file); file->table= table; - if (!(error= file->open(name, mode, flags))) + if (likely(!(error= file->open(name, mode, flags)))) { /* - Copy values set by handler::open() in the underlying handler - Reuse original storage engine data for duplicate key reference - It would be easier to do this if we would have another handler - call: fixup_after_open()... - */ - ref= file->ref; + Allocate ref in table's mem_root. We can't use table's ref + as it's allocated by ha_ caller that allocates this. + */ ref_length= file->ref_length; - dup_ref= file->dup_ref; + if (!(ref= (uchar*) alloc_root(&table->mem_root,ALIGN_SIZE(ref_length)*2))) + { + file->ha_close(); + error=HA_ERR_OUT_OF_MEM; + DBUG_RETURN(error); + } + file->ref= ref; + file->dup_ref= dup_ref= ref+ALIGN_SIZE(file->ref_length); /* ha_open() sets the following for us. We have to set this for the @@ -107,7 +111,7 @@ int ha_sequence::open(const char *name, int mode, uint flags) /* Don't try to read the inital row the call is part of create code */ if (!(flags & (HA_OPEN_FOR_CREATE | HA_OPEN_FOR_REPAIR))) { - if ((error= table->s->sequence->read_initial_values(table))) + if (unlikely((error= table->s->sequence->read_initial_values(table)))) file->ha_close(); } else @@ -212,7 +216,7 @@ int ha_sequence::write_row(uchar *buf) if (tmp_seq.check_and_adjust(0)) DBUG_RETURN(HA_ERR_SEQUENCE_INVALID_DATA); sequence->copy(&tmp_seq); - if (!(error= file->write_row(buf))) + if (likely(!(error= file->write_row(buf)))) sequence->initialized= SEQUENCE::SEQ_READY_TO_USE; DBUG_RETURN(error); } @@ -229,14 +233,10 @@ int ha_sequence::write_row(uchar *buf) - Get an exclusive lock for the table. This is needed to ensure that we excute all full inserts (same as ALTER SEQUENCE) in same order on master and slaves - - Check that we are only using one table. - This is to avoid deadlock problems when upgrading lock to exlusive. - Check that the new row is an accurate SEQUENCE object */ THD *thd= table->in_use; - if (thd->lock->table_count != 1) - DBUG_RETURN(ER_WRONG_INSERT_INTO_SEQUENCE); if (table->s->tmp_table == NO_TMP_TABLE && thd->mdl_context.upgrade_shared_lock(table->mdl_ticket, MDL_EXCLUSIVE, @@ -255,7 +255,7 @@ int ha_sequence::write_row(uchar *buf) sequence->write_lock(table); } - if (!(error= file->update_first_row(buf))) + if (likely(!(error= file->update_first_row(buf)))) { Log_func *log_func= Write_rows_log_event::binlog_row_logging_function; if (!sequence_locked) @@ -322,7 +322,8 @@ int ha_sequence::external_lock(THD *thd, int lock_type) Copy lock flag to satisfy DBUG_ASSERT checks in ha_* functions in handler.cc when we later call it with file->ha_..() */ - file->m_lock_type= lock_type; + if (!error) + file->m_lock_type= lock_type; return error; } |