Commit graph

34 commits

Author SHA1 Message Date
Luis Soares
8ce9f9b317 BUG#53893: RBR: nullable unique key can lead to out-of-sync slave
When using Unique Keys with nullable parts in RBR, the slave can
choose the wrong row to update. This happens because a table with
an unique key containing nullable parts cannot strictly guarantee 
uniqueness. As stated in the manual, for all engines, a UNIQUE 
index allows multiple NULL values for columns that can contain 
NULL.

We fix this at the slave by extending the checks before assuming
that the row found through an unique index is is the correct
one. This means that when a record (R) is fetched from the storage
engine and a key that is not primary (K) is used, the server does 
the following: 

 - If K is unique and has no nullable parts, it returns R;
 - Otherwise, if any field in the before image that is part of K
   is null do an index scan;
 - If there is no NULL field in the BI part of K, then return R.

A side change: renamed the existing test case file and added a
test case covering the changes in this patch.
2010-06-02 23:26:12 +01:00
Luis Soares
ddb5d63346 BUG#52868: Wrong handling of NULL value during update, replication out
of sync

In RBR, sometimes the table->s->last_null_bit_pos can be zero. This
has impact at the slave when it compares records fetched from the
storage engine against records in the binary log event. If
last_null_bit_pos is zero the slave, while comparing in
log_event.cc:record_compare function, would set all bits in the last
null_byte to 1 (assumed all 8 were unused) . Thence it would loose the
ability to distinguish records that were similar in contents except
for the fact that some field was null in one record, but not in the
other. Ultimately this would cause wrong matches, and in the specific
case depicted in the bug report the same record would be updated
twice, resulting in a lost update.

Additionally, in the record_compare function the slave was setting the
X bit unconditionally. There are cases that the X bit does not exist
in the record header. This could also lead to wrong matches between
records.

We fix both by conditionally resetting the bits: (i) unused null_bits
are set if last_null_bit_pos > 0; (ii) X bit is set if
HA_OPTION_PACK_RECORD is in use.
2010-04-21 13:47:55 +01:00
Staale Smedseng
3f4d8edb84 Bug #49829 Many "hides virtual function" warnings with
SunStudio
      
SunStudio compilers of late warn about methods that might hide
methods in base classes due to the use of overloading combined
with overriding. SunStudio also warns about variables defined
in local socpe or method arguments that have the same name as
a member attribute of the class.
      
This patch renames methods that might hide base class methods,
to make it easier both for humans and compilers to see what is
actually called. It also renames variables in local scope.
2010-03-14 17:01:45 +01:00
Staale Smedseng
5181551dee Bug #43414 Parenthesis (and other) warnings compiling
MySQL with gcc 4.3.2
      
This is the final patch in the context of this bug.
2010-02-22 14:23:47 +01:00
He Zhenxing
6bf8c119fe Backport Bug#37148 to 5.1 2010-01-24 15:03:23 +08:00
Luis Soares
22cff39274 Fix for BUG#49481 and BUG#49482 reverted.
PB2 run uncovered issue that needs further analysis.
2010-01-19 00:10:00 +00:00
Luis Soares
a0a5152fb3 Fix for BUG#49481 and BUG#49482.
BUG#49481: RBR: MyISAM and bit fields may cause slave to stop on delete: 
cant find record
      
BUG#49482: RBR: Replication may break on deletes when MyISAM tables + 
char field are used

When using MyISAM tables, despite the fact that the null bit is
set for some fields, their old value is still in the row. This
can cause the comparison of records to fail when the slave is
doing an index or range scan.

We fix this by avoiding memcmp for MyISAM tables when comparing
records. Additionally, when comparing field by field, we first
check if both fields are not null and if so, then we compare
them. If just one field is null we return failure immediately. If
both fields are null, we move on to the next field.
2010-01-14 14:26:51 +00:00
1fb18b5d4c Bug#46640: output from mysqlbinlog command in 5.1 breaks replication
Added parentheses around assignment used as truth value for suppressing warnings.
2009-10-23 11:13:42 +08:00
0ece5891a2 Bug#46640: output from mysqlbinlog command in 5.1 breaks replication
The BINLOG statement was sharing too much code with the slave SQL thread, introduced with
the patch for Bug#32407. This caused statements to be logged with the wrong server_id, the
id stored inside the events of the BINLOG statement rather than the id of the running 
server.
      
Fix by rearranging code a bit so that only relevant parts of the code are executed by
the BINLOG statement, and the server_id of the server executing the statements will 
not be overrided by the server_id stored in the 'format description BINLOG statement'.
2009-10-14 09:39:05 +08:00
Staale Smedseng
8b9843408d Bug #43414 Parenthesis (and other) warnings compiling MySQL
with gcc 4.3.2

Cleaning up warnings not present in 5.0.
2009-09-23 15:21:29 +02:00
Ignacio Galarza
2d9421c3bb Bug#29125 Windows Server X64: so many compiler warnings
- Remove bothersome warning messages.  This change focuses on the warnings 
that are covered by the ignore file: support-files/compiler_warnings.supp.
- Strings are guaranteed to be max uint in length
2009-02-13 11:41:47 -05:00
Mats Kindahl
95833a74d0 Bug #40004 Replication failure with no PK + no indexes
In certain situations, a scan of the table will return the error
code HA_ERR_RECORD_DELETED, and this error code is not 
correctly caught in the Rows_log_event::find_row() function, which
causes an error to be returned for this case.

This patch fixes the problem by adding code to either ignore the
record and continuing with the next one, the the event of a table
scan, or change the error code to HA_ERR_KEY_NOT_FOUND, in the event
that a key lookup is attempted.
2008-10-20 20:50:08 +02:00
mats@mats-laptop.(none)
812fa8b24c BUG#36197: flush tables (or little table cache) can cause crash on slave
When flushing tables, there were a slight chance that the flush was occuring
between processing of two table map events. Since the tables are opened
one by one, it might result in that the tables were not valid and that sub-
sequent locking of tables would cause the slave to crash.

The problem is solved by opening and locking all tables at once using
simple_open_n_lock_tables(). Also, the patch contain a change to open_tables()
so that pre-locking only takes place when the trg_event_map is not zero, which
was not the case before (this caused the lock to be placed in thd->locked_tables
instead of thd->lock since the assumption was that triggers would be called
later and therefore the tables should be pre-locked).
2008-05-12 19:50:53 +02:00
davi@mysql.com/endora.local
41545137ef Bug#34655 Compile error
Rename client_last_error to last_error and client_last_errno to last_errno
to not break connectors which use the internal net structure for error handling.
2008-02-28 14:55:46 -03:00
mkindahl@dl145h.mysql.com
7e0f4a6fa7 Merge mkindahl@bk-internal.mysql.com:/home/bk/mysql-5.1-new-rpl
into  dl145h.mysql.com:/data0/mkindahl/mysql-5.1-rpl
2008-02-05 14:52:20 +01:00
aelkin/elkin@koti.dsl.inet.fi
c9461608e7 Bug #32971 No user level error message from slave sql thread when ER_NO_DEFAULT_FOR_FIELD
The error message due to lack of the default value for an extra field
was not as informative as it should be.

Fixed with improving the scheme of gathering, propagating and reporting
errors in applying rows events. 
The scheme is in the following.
Any kind of error of processing of a row event incidents are to be 
registered with my_error().
In the end Rows_log_event::do_apply_event() invokes rli->report() with the 
message to display consisting of all the errors.
This mimics `show warnings' displaying.
A simple test checks three errors in processing an event.
Two hunks - a user level error and pushing it into the list - 
have been devoted to already fixed Bug@31702.

Some open issues relating to this artifact listed on BUG@21842 page and
on WL@3679.
Todo: to synchronize the statement in the tests comments on Update and Delete
events may not stop when an extra field does not have a default with wl@3228 spec.
2008-01-31 14:54:03 +02:00
mats@capulet.kindahl.net
6e94fb84ae Post-merge fixes to make tests pass. 2008-01-09 12:55:04 +01:00
mkindahl@dl145h.mysql.com
bdea24f483 Merge dl145h.mysql.com:/data0/mkindahl/mysql-5.1-rpl
into  dl145h.mysql.com:/data0/mkindahl/mysql-5.1-rpl-merge
2007-12-19 18:51:46 +01:00
kostja@bodhi.(none)
ebb9c5d983 Bug#12713 "Error in a stored function called from a SELECT doesn't
cause ROLLBACK of statement", part 1. Review fixes.

Do not send OK/EOF packets to the client until we reached the end of 
the current statement.
This is a consolidation, to keep the functionality that is shared by all 
SQL statements in one place in the server.
Currently this functionality includes:
- close_thread_tables()
- log_slow_statement().

After this patch and the subsequent patch for Bug#12713, it shall also include:
- ha_autocommit_or_rollback()
- net_end_statement()
- query_cache_end_of_result().

In future it may also include:
- mysql_reset_thd_for_next_command().
2007-12-12 18:21:01 +03:00
mats@kindahl-laptop.dnsalias.net
eca0172010 BUG#31583 (5.1-telco-6.1 -> 5.1.22. Slave returns Error in unknown event):
In the patch for BUG#21842, the code for handling old rows events were
refactored.  There were a bug in the refactored code (possibly introduced
after the patch for BUG#21842) that caused caused the refactored old events
to read a columns bitmap after image even though there is no such bitmap
for old events. As a result, the reading got out of sync, and started reading
invalid data.

This patch removes all trace of the after image column bitmap from the refactored
old events and removes functions that are no longer needed because they are empty.
2007-12-05 20:00:14 +01:00
sven@riska.(none)
a820324569 BUG#31581: 5.1-telco-6.1 -> 5.1.22. Slave crashes during starting
The patch I previously pushed for this bug did not compile because
a field in class THD had been renamed.
This patch renames thd->query_error to thd->is_slave_error in
log_event_old.cc by applying the same patch to log_event_old.cc as
was previously applied to log_event.cc.
2007-11-21 16:53:46 +01:00
sven@riska.(none)
c26a136ed3 Merge riska.(none):/home/sven/bkroot/5.1-new-rpl
into  riska.(none):/home/sven/bk/b31581-5.1.22-rbr_slave_crash
2007-11-21 15:27:12 +01:00
sven@riska.(none)
bdc80e8272 BUG#31581: 5.1-telco-6.1 -> 5.1.22. Slave crashes during starting
This patch has two purposes:
(1) To refactor the code so that
   {Write|Update|Delete}_rows_log_event_old does not use code from
   {Write|Update|Delete}_rows_log_event. Before refactoring there
   was the following problem: whenever we modifed the code for new
   events, it affected the old events. This is bad, as it makes
   maintainance difficult. After refactoring, we can safely edit the
   new code without affecting old events. So, if we for instance
   modify the binary format of new events, we no longer need to worry
   about how the new code reads old events.
(2) To fix BUG#31581.

These two objectives are reached by the following changes:
 - Merged Rows_log_event into Old_rows_log_event and
   {Write|Update|Delete}_rows_log_event into
   {Write|Update|Delete}_rows_log_event_old.
 - Fixed the bug by replacing {WRITE|UPDATE|DELETE}_ROWS_EVENT by
   PRE_GA_{WRITE|UPDATE|DELETE}_ROWS_EVENT.
 - Added comments to log_event_old.h

(This patch is identical to the previously committed patch which was
a collapse of three changesets, except that it adds assert(0) to
constructors for old types of row log events that should never be
called.)
2007-11-20 19:49:35 +01:00
kostja@bodhi.(none)
7c00f8a3b4 Rename: query_error -> is_slave_error.
Add comments.
2007-10-20 01:20:38 +04:00
tsmith@sita.local
653f7341bb Post-merge fixes, and disable buggy test case on embedded 2007-08-29 16:58:00 -06:00
tsmith@sita.local
e32bdff6f0 Merge sita.local:/Users/tsmith/m/bk/maint/51-target22
into  sita.local:/Users/tsmith/m/bk/maint/51
2007-08-29 15:28:38 -06:00
rafal@quant.(none)
f8b64e17f9 BUG#21842 (Cluster fails to replicate to innodb or myisam with err 134
using TPC-B):
 
Problem: A RBR event can contain incomplete row data (only key value and
fields which have been changed). In that case, when the row is unpacked
into record and written to a table, the missing fields get incorrect NULL
values leading to master-slave inconsistency.
 
Solution: Use values found in slave's table for columns which are not given
in the rows event. The code for writing a single row uses the following 
algorithm: 

1. unpack row_data into table->record[0],
2. try to insert record,
3. if duplicate record found, fetch it into table->record[0],
4. unpack row_data into table->record[0],
5. write table->record[0] into the table.

Where row_data is the row as stored in the data area of a rows event. 
Thus:

a) unpacking of row_data happens at the time when row is written into 
 a table,

b) when unpacking (in step 4), only columns present in row_data are 
 overwritten - all other columns remain as they were found in the table.
 
Since all data needed for the above algorithm is stored inside 
Rows_log_event class, functions which locate and write rows are turned 
into methods of that class.

replace_record()     -> Rows_log_event::write_row()
find_and_fetch_row() -> Rows_log_event::find_row()

Both methods take row data from event's data buffer - the row being 
processed is pointed by m_curr_row. They unpack the data as needed into 
table's record buffers record[0] or record[1]. When row is unpacked, 
m_curr_row_end is set to point at next row in the data buffer.

Other changes introduced in this changeset:

- Change signature of unpack_row(): don't report errors and don't
setup table's rw_set here. Errors can happen only when setting default 
values in prepare_record() function and are detected there.
 
- In Rows_log_event and derived classes, don't pass arguments to
the execution primitives (do_...() member functions) but use class
members instead.

- Move old row handling code into log_event_old.cc to be used by 
*_rows_log_event_old classes.

Also, a new test rpl_ndb_2other is added which tests basic replication 
from master using ndb tables to slave storing the same tables using 
(possibly) different engine (myisam,innodb).
  
Test is based on existing tests rpl_ndb_2myisam and rpl_ndb_2innodb. 
However, these tests doesn't work for various reasons and currently are 
disabled (see BUG#19227).
  
The new test differs from the ones it is based on as follows:
  
1. Single test tests replication with different storage engines on slave 
(myisam, innodb, ndb).
  
2. Include file extra/rpl_tests/rpl_ndb_2multi_eng.test containing 
original tests is replaced by extra/rpl_tests/rpl_ndb_2multi_basic.test 
which doesn't contain tests using partitioned tables as these don't work 
currently. Instead, it tests replication to a slave which has more or 
less columns than master.
  
3. Include file include/rpl_multi_engine3.inc is replaced with 
include/rpl_multi_engine2.inc. The later differs by performing slightly 
different operations (updating more than one row in the table) and 
clearing table with "TRUNCATE TABLE" statement instead of "DELETE FROM" 
as replication of "DELETE" doesn't work well in this setting.
  
4. Slave must use option --log-slave-updates=0 as otherwise execution of 
replication events generated by ndb fails if table uses a different 
storage engine on slave (see BUG#29569).
2007-08-26 14:31:10 +02:00
jani@hynda.mysql.fi
2fd7a743e4 Merge hynda.mysql.fi:/home/my/mysql-5.1-main
into  hynda.mysql.fi:/home/my/mysql-5.1-marvel
2007-08-21 19:03:28 +03:00
mats@kindahl-laptop.dnsalias.net
9c4ef25c55 Renaming RELAY_LOG_INFO and st_relay_log_info to follow coding standards
(and be more friendly to Doxygen by removing unnecessary typedefs).
2007-08-16 07:37:50 +02:00
monty@mysql.com/nosik.monty.fi
e53a73e26c Fixed a lot of compiler warnings and errors detected by Forte C++ on Solaris
Faster thr_alarm()
Added 'Opened_files' status variable to track calls to my_open()
Don't give warnings when running mysql_install_db
Added option --source-install to mysql_install_db

I had to do the following renames() as used polymorphism didn't work with Forte compiler on 64 bit systems
index_read()      -> index_read_map()
index_read_idx()  -> index_read_idx_map()
index_read_last() -> index_read_last_map()
2007-08-13 16:11:25 +03:00
monty@mysql.com/narttu.mysql.fi
088e2395f1 WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:

- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t

Removed declaration of byte, gptr, my_string, my_size_t and size_s. 

Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
  instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
  as this requires fewer casts in the code and is more in line with how the
  standard functions work.
- Added extra length argument to dirname_part() to return the length of the
  created string.
- Changed (at least) following functions to take uchar* as argument:
  - db_dump()
  - my_net_write()
  - net_write_command()
  - net_store_data()
  - DBUG_DUMP()
  - decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
  argument to my_uncompress() from a pointer to a value as we only return
  one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
  the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
  casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.

Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
  needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
  explicitely as this conflict was often hided by casting the function to
  hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
  get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
  size_t. This was needed to properly detect errors (which are
  returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
  (portability fix)
- Removed windows specific code to restore cursor position as this
  causes slowdown on windows and we should not mix read() and pread()
  calls anyway as this is not thread safe. Updated function comment to
  reflect this. Changed function that depended on original behavior of
  my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
  m_size is the number of elements in the array, not a string/memory
  length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
  Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
  - Replaced some calls to alloc_root + memcpy to use
    strmake_root()/strdup_root().
  - Changed some calls from memdup() to strmake() (Safety fix)
  - Simpler loops in client-simple.c
2007-05-10 12:59:39 +03:00
iggy@alf.
0f43ac0d2a Minor fixes. 2007-04-24 12:41:08 -04:00
mats@romeo.(none)
84ec7be2c7 WL#2735: Refactor replication
Factoring out pack_row() and unpack_row() into new files
rpl_record.{cc,h}.
2007-04-13 14:55:28 +02:00
mats@romeo.(none)
06faf8f411 BUG#27779 (Slave cannot read old rows log events):
Taking code from before BUG#22583 and incorporating as events to be able
to read old events. Also incorporating old pack and unpack functions
into patch.
2007-04-12 15:50:54 +02:00