Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion sql/ha_sequence.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "sql_update.h"
#include "sql_base.h"
#include "log_event.h"
#include <debug_sync.h>

#ifdef WITH_WSREP
#include "wsrep_trans_observer.h" /* wsrep_start_transaction() */
Expand Down Expand Up @@ -83,6 +84,7 @@ int ha_sequence::open(const char *name, int mode, uint flags)
int error;
DBUG_ENTER("ha_sequence::open");
DBUG_ASSERT(table->s == table_share && file);
sql_print_information("ha_sequence::open");

file->table= table;
if (likely(!(error= file->open(name, mode, flags))))
Expand Down Expand Up @@ -144,6 +146,7 @@ handler *ha_sequence::clone(const char *name, MEM_ROOT *mem_root)
{
ha_sequence *new_handler;
DBUG_ENTER("ha_sequence::clone");
sql_print_information("ha_sequence::clone");
if (!(new_handler= new (mem_root) ha_sequence(ht, table_share)))
DBUG_RETURN(NULL);

Expand Down Expand Up @@ -216,6 +219,8 @@ int ha_sequence::write_row(const uchar *buf)
Log to binary log even if this function has been called before
(The function ends by setting row_logging to 0)
*/
sql_print_information("write_row sequence initialized state: %d ",
sequence->initialized);
row_logging= row_logging_init;
if (unlikely(sequence->initialized == SEQUENCE::SEQ_IN_PREPARE))
{
Expand All @@ -226,9 +231,13 @@ int ha_sequence::write_row(const uchar *buf)
{
int error= 0;
/* This is called from alter table */
sql_print_information("write_row alter read_fields");
tmp_seq.read_fields(table);
if (tmp_seq.check_and_adjust(0))
{
sql_print_information("write_row alter HA_ERR_SEQUENCE_INVALID_DATA");
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;
Expand Down Expand Up @@ -257,11 +266,19 @@ int ha_sequence::write_row(const uchar *buf)
MDL_EXCLUSIVE,
thd->variables.
lock_wait_timeout))
DBUG_RETURN(ER_LOCK_WAIT_TIMEOUT);
{
sql_print_information("write_row write_locked ER_LOCK_WAIT_TIMEOUT");
DBUG_RETURN(ER_LOCK_WAIT_TIMEOUT);
}

sql_print_information("write_row write_locked read_fields");
tmp_seq.read_fields(table);
if (tmp_seq.check_and_adjust(0))
{
sql_print_information("write_row write_locked "
"HA_ERR_SEQUENCE_INVALID_DATA");
DBUG_RETURN(HA_ERR_SEQUENCE_INVALID_DATA);
}

/*
Lock sequence to ensure that no one can come in between
Expand Down Expand Up @@ -295,6 +312,7 @@ int ha_sequence::write_row(const uchar *buf)

if (likely(!(error= file->update_first_row(buf))))
{
sql_print_information("write_row update_first_row");
Log_func *log_func= Write_rows_log_event::binlog_row_logging_function;
if (!sequence_locked)
sequence->copy(&tmp_seq);
Expand Down Expand Up @@ -375,6 +393,7 @@ int ha_sequence::external_lock(THD *thd, int lock_type)

int ha_sequence::discard_or_import_tablespace(my_bool discard)
{
sql_print_information("ha_sequence::discard_or_import_tablespace");
int error= file->discard_or_import_tablespace(discard);
if (!error && !discard)
{
Expand Down
15 changes: 13 additions & 2 deletions sql/item_func.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7115,6 +7115,7 @@ longlong Item_func_nextval::val_int()
{
/* Alter table checking if function works */
null_value= 0;
sql_print_information("Item_func_nextval::val_int CHECK_FIELD_EXPRESSION");
DBUG_RETURN(0);
}

Expand All @@ -7133,20 +7134,30 @@ longlong Item_func_nextval::val_int()
if (!(entry= ((SEQUENCE_LAST_VALUE*)
my_hash_search(&thd->sequences, (uchar*) key, length))))
{
if (!(key= (char*) my_memdup(PSI_INSTRUMENT_ME, key, length, MYF(MY_WME))) ||
!(entry= new SEQUENCE_LAST_VALUE((uchar*) key, length)))
if (!(key= (char*) my_memdup(PSI_INSTRUMENT_ME, key, length, MYF(MY_WME))))
{
/* EOM, error given */
my_free((char*) key);
delete entry;
null_value= 1;
sql_print_information("Item_func_nextval::val_int error key");
DBUG_RETURN(0);
}
if (!(entry= new SEQUENCE_LAST_VALUE((uchar*) key, length)))
{
/* EOM, error given */
my_free((char*) key);
delete entry;
null_value= 1;
sql_print_information("Item_func_nextval::val_int error last_value");
DBUG_RETURN(0);
}
if (my_hash_insert(&thd->sequences, (uchar*) entry))
{
/* EOM, error given */
delete entry;
null_value= 1;
sql_print_information("Item_func_nextval::val_int error my_hash_insert");
DBUG_RETURN(0);
}
}
Expand Down
48 changes: 48 additions & 0 deletions sql/sql_sequence.cc
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,13 @@ bool sequence_definition::check_and_adjust(bool set_reserved_until)
llabs(real_increment) :
MAX_AUTO_INCREMENT_VALUE);

sql_print_information("Check sequence values check_and_adjust: "
"max_value: %lld min_value: %lld start: %lld "
"cache: %lld real_increment: %lld max_increment: %lld "
"reserved_until: %lld next_free_value: %lld.",
max_value, min_value, start, cache, real_increment,
max_increment, reserved_until, next_free_value);

if (max_value >= start &&
max_value > min_value &&
start >= min_value &&
Expand Down Expand Up @@ -154,6 +161,11 @@ void sequence_definition::read_fields(TABLE *table)
round= table->field[7]->val_int();
dbug_tmp_restore_column_map(&table->read_set, old_map);
used_fields= ~(uint) 0;
sql_print_information("Check sequence values read_fields: "
"max_value: %lld min_value: %lld start: %lld "
"increment: %lld cache: %lld reserved: %lld.",
max_value, min_value,
start, increment, cache, reserved_until);
print_dbug();
}

Expand All @@ -178,6 +190,11 @@ void sequence_definition::store_fields(TABLE *table)
table->field[7]->store((longlong) round, 1);

dbug_tmp_restore_column_map(&table->write_set, old_map);
sql_print_information("Check sequence values store_fields: "
"max_value: %lld min_value: %lld start: %lld "
"increment: %lld cache: %lld reserved: %lld.",
max_value, min_value,
start, increment, cache, reserved_until);
print_dbug();
}

Expand Down Expand Up @@ -363,6 +380,7 @@ bool sequence_insert(THD *thd, LEX *lex, TABLE_LIST *org_table_list)
{
lex->restore_backup_query_tables_list(&query_tables_list_backup);
thd->restore_backup_open_tables_state(&open_tables_backup);
sql_print_information("Check sequence_insert error open");
DBUG_RETURN(error);
}
table= table_list.table;
Expand All @@ -372,6 +390,11 @@ bool sequence_insert(THD *thd, LEX *lex, TABLE_LIST *org_table_list)

seq->reserved_until= seq->start;
error= seq->write_initial_sequence(table);
sql_print_information("Check sequence values write_initial_sequence: "
"query: %s max_value: %lld min_value: %lld start: %lld "
"cache: %lld error: %d.",
thd->query(), seq->max_value, seq->min_value,
seq->start, seq->cache, error);
{
uint save_unsafe_rollback_flags=
thd->transaction->stmt.m_unsafe_rollback_flags;
Expand Down Expand Up @@ -629,6 +652,13 @@ void sequence_definition::adjust_values(longlong next_value)
DBUG_ASSERT(llabs(next_free_value % real_increment) == offset);
}
}
sql_print_information("sequence_definition::adjust_values : "
"max_value: %lld min_value: %lld start: %lld "
"cache: %lld reserved_until: %lld real_increment: %lld "
"global.auto_increment_increment: %lld ",
max_value, min_value, start, cache,
reserved_until, real_increment,
global_system_variables.auto_increment_increment);
}


Expand Down Expand Up @@ -754,6 +784,9 @@ longlong SEQUENCE::next_value(TABLE *table, bool second_round, int *error)
(real_increment < 0 && res_value > reserved_until))
{
write_unlock(table);
sql_print_information("SEQUENCE::next_value error real_increment: %lld "
"res_value: %lld reserved_until: %lld",
real_increment, res_value, reserved_until);
DBUG_RETURN(res_value);
}

Expand Down Expand Up @@ -803,6 +836,7 @@ longlong SEQUENCE::next_value(TABLE *table, bool second_round, int *error)
We have to do everything again to ensure that the given range was
not empty, which could happen if increment == 0
*/
sql_print_information("SEQUENCE::next_value Fix next_free_value");
DBUG_RETURN(next_value(table, 1, error));
}

Expand All @@ -823,6 +857,7 @@ longlong SEQUENCE::next_value(TABLE *table, bool second_round, int *error)
table->s->table_name.str);
*error= ER_SEQUENCE_RUN_OUT;
all_values_used= 1;
sql_print_information("SEQUENCE::next_value error all_values_used");
DBUG_RETURN(0);
}

Expand Down Expand Up @@ -1022,6 +1057,19 @@ bool Sql_cmd_alter_sequence::execute(THD *thd)
seq->write_lock(table);
new_seq->reserved_until= seq->reserved_until;

sql_print_information("Check sequence values execute: "
"query: %s Old(max_value: %lld min_value: %lld start: %lld "
"cache: %lld reserved_until: %lld) "
"New(max_value: %lld min_value: %lld start: %lld "
"cache: %lld reserved_until: %lld) "
"global.auto_increment_increment: %lld ",
thd->query(),
seq->max_value, seq->min_value, seq->start, seq->cache,
seq->reserved_until,
new_seq->max_value, new_seq->min_value, new_seq->start,
new_seq->cache, new_seq->reserved_until,
global_system_variables.auto_increment_increment);

/* Copy from old sequence those fields that the user didn't specified */
if (!(new_seq->used_fields & seq_field_used_increment))
new_seq->increment= seq->increment;
Expand Down
6 changes: 6 additions & 0 deletions sql/sql_sequence.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ class SEQUENCE :public sequence_definition
sequence_definition::operator= (*seq);
adjust_values(reserved_until);
all_values_used= 0;
fprintf(stderr, "Check sequence values copy: "
"max_value: %lld min_value: %lld start: %lld "
"cache: %lld real_increment: %lld "
"reserved_until: %lld next_free_value: %lld.",
max_value, min_value, start, cache, real_increment,
reserved_until, next_free_value);
}
longlong next_value(TABLE *table, bool second_round, int *error);
int set_value(TABLE *table, longlong next_value, ulonglong round_arg,
Expand Down