From 5f7956094c0f675f1714b602593cc01a1793fb89 Mon Sep 17 00:00:00 2001 From: "mats@mysql.com" <> Date: Thu, 26 Jan 2006 09:25:37 +0100 Subject: [PATCH] WL#3023 (RBR: Use locks in a statment-like manner): Interface changes pushed early. Separation of public and implementation interface for external_lock() in preparation for implementation. --- sql/handler.cc | 38 +++++++++++++++++++++++--------------- sql/handler.h | 8 +++++++- sql/lock.cc | 6 +++--- sql/opt_range.cc | 6 +++--- sql/sql_table.cc | 4 ++-- 5 files changed, 38 insertions(+), 24 deletions(-) diff --git a/sql/handler.cc b/sql/handler.cc index 7b86cafc367..c380ff3508e 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -3014,40 +3014,48 @@ template int binlog_log_row(TABLE *, const byte *, const #endif /* HAVE_ROW_BASED_REPLICATION */ +int handler::ha_external_lock(THD *thd, int lock_type) +{ + int error; + if (unlikely(error= external_lock(thd, lock_type))) + return error; + return 0; +} + int handler::ha_write_row(byte *buf) { int error; - if (likely(!(error= write_row(buf)))) - { + if (unlikely(error= write_row(buf))) + return error; #ifdef HAVE_ROW_BASED_REPLICATION - error= binlog_log_row(table, 0, buf); + if (unlikely(error= binlog_log_row(table, 0, buf))) + return error; #endif - } - return error; + return 0; } int handler::ha_update_row(const byte *old_data, byte *new_data) { int error; - if (likely(!(error= update_row(old_data, new_data)))) - { + if (unlikely(error= update_row(old_data, new_data))) + return error; #ifdef HAVE_ROW_BASED_REPLICATION - error= binlog_log_row(table, old_data, new_data); + if (unlikely(error= binlog_log_row(table, old_data, new_data))) + return error; #endif - } - return error; + return 0; } int handler::ha_delete_row(const byte *buf) { int error; - if (likely(!(error= delete_row(buf)))) - { + if (unlikely(error= delete_row(buf))) + return error; #ifdef HAVE_ROW_BASED_REPLICATION - error= binlog_log_row(table, buf, 0); + if (unlikely(error= binlog_log_row(table, buf, 0))) + return error; #endif - } - return error; + return 0; } diff --git a/sql/handler.h b/sql/handler.h index 8545d8c082c..8551ea64149 100644 --- a/sql/handler.h +++ b/sql/handler.h @@ -1237,6 +1237,7 @@ public: interface, see the (private) functions write_row(), update_row(), and delete_row() below. */ + int ha_external_lock(THD *thd, int lock_type); int ha_write_row(byte * buf); int ha_update_row(const byte * old_data, byte * new_data); int ha_delete_row(const byte * buf); @@ -1378,7 +1379,6 @@ public: { return 0; } virtual int extra_opt(enum ha_extra_function operation, ulong cache_size) { return extra(operation); } - virtual int external_lock(THD *thd, int lock_type) { return 0; } /* In an UPDATE or DELETE, if the row under the cursor was locked by another transaction, and the engine used an optimistic read of the last @@ -1626,6 +1626,12 @@ private: overridden by the storage engine class. To call these methods, use the corresponding 'ha_*' method above. */ + virtual int external_lock(THD *thd __attribute__((unused)), + int lock_type __attribute__((unused))) + { + return 0; + } + virtual int write_row(byte *buf __attribute__((unused))) { return HA_ERR_WRONG_COMMAND; diff --git a/sql/lock.cc b/sql/lock.cc index 8e24c56799d..edc76fbe660 100644 --- a/sql/lock.cc +++ b/sql/lock.cc @@ -229,12 +229,12 @@ static int lock_external(THD *thd, TABLE **tables, uint count) ((*tables)->reginfo.lock_type >= TL_READ && (*tables)->reginfo.lock_type <= TL_READ_NO_INSERT)) lock_type=F_RDLCK; - if ((error=(*tables)->file->external_lock(thd,lock_type))) + if ((error=(*tables)->file->ha_external_lock(thd,lock_type))) { print_lock_error(error, (*tables)->file->table_type()); for (; i-- ; tables--) { - (*tables)->file->external_lock(thd, F_UNLCK); + (*tables)->file->ha_external_lock(thd, F_UNLCK); (*tables)->current_lock=F_UNLCK; } DBUG_RETURN(error); @@ -562,7 +562,7 @@ static int unlock_external(THD *thd, TABLE **table,uint count) if ((*table)->current_lock != F_UNLCK) { (*table)->current_lock = F_UNLCK; - if ((error=(*table)->file->external_lock(thd, F_UNLCK))) + if ((error=(*table)->file->ha_external_lock(thd, F_UNLCK))) { error_code=error; print_lock_error(error_code, (*table)->file->table_type()); diff --git a/sql/opt_range.cc b/sql/opt_range.cc index 7dd694f3411..e99bb77c0c7 100644 --- a/sql/opt_range.cc +++ b/sql/opt_range.cc @@ -844,7 +844,7 @@ QUICK_RANGE_SELECT::~QUICK_RANGE_SELECT() DBUG_PRINT("info", ("Freeing separate handler %p (free=%d)", file, free_file)); file->ha_reset(); - file->external_lock(current_thd, F_UNLCK); + file->ha_external_lock(current_thd, F_UNLCK); file->close(); delete file; } @@ -1008,14 +1008,14 @@ int QUICK_RANGE_SELECT::init_ror_merged_scan(bool reuse_handler) /* Caller will free the memory */ goto failure; } - if (file->external_lock(thd, F_RDLCK)) + if (file->ha_external_lock(thd, F_RDLCK)) goto failure; if (file->extra(HA_EXTRA_KEYREAD) || file->ha_retrieve_all_pk() || init() || reset()) { - file->external_lock(thd, F_UNLCK); + file->ha_external_lock(thd, F_UNLCK); file->close(); goto failure; } diff --git a/sql/sql_table.cc b/sql/sql_table.cc index f2da98dcee2..f08c37ad40d 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -5254,7 +5254,7 @@ copy_data_between_tables(TABLE *from,TABLE *to, if (!(copy= new Copy_field[to->s->fields])) DBUG_RETURN(-1); /* purecov: inspected */ - if (to->file->external_lock(thd, F_WRLCK)) + if (to->file->ha_external_lock(thd, F_WRLCK)) DBUG_RETURN(-1); /* We can abort alter table for any table type */ @@ -5394,7 +5394,7 @@ copy_data_between_tables(TABLE *from,TABLE *to, free_io_cache(from); *copied= found_count; *deleted=delete_count; - if (to->file->external_lock(thd,F_UNLCK)) + if (to->file->ha_external_lock(thd,F_UNLCK)) error=1; DBUG_RETURN(error > 0 ? -1 : 0); }