134
134
len= snprintf(slider, buff_end - slider,
135
135
_(" %s, Error_code: %d;"), err->msg, err->code);
138
138
rli->report(level, session->is_error()? session->main_da.sql_errno() : 0,
139
139
_("Could not execute %s event on table %s.%s;"
140
140
"%s handler error %s; "
324
324
if (!(dirp=my_dir(slave_load_tmpdir,MYF(MY_WME))))
328
328
When we are deleting temporary files, we should only remove
329
329
the files associated with the server id of our server.
330
330
We don't use event_server_id here because since we've disabled
331
331
direct binlogging of Create_file/Append_file/Exec_load events
332
we cannot meet Start_log event in the middle of events from one
332
we cannot meet Start_log event in the middle of events from one
335
335
p= strncpy(prefbuf, STRING_WITH_LEN("SQL_LOAD-")) + 9;
1286
1286
db_len = (db) ? (uint32_t) strlen(db) : 0;
1287
1287
if (session_arg->variables.collation_database != session_arg->db_charset)
1288
1288
charset_database_number= session_arg->variables.collation_database->number;
1291
1291
If we don't use flags2 for anything else than options contained in
1292
1292
session_arg->options, it would be more efficient to flags2=session_arg->options
1356
1356
common_header_len= description_event->common_header_len;
1357
1357
post_header_len= description_event->post_header_len[event_type-1];
1360
1360
We test if the event's length is sensible, and if so we compute data_len.
1361
1361
We cannot rely on QUERY_HEADER_LEN here as it would not be format-tolerant.
1362
1362
We use QUERY_HEADER_MINIMAL_LEN which is the same for 3.23, 4.0 & 5.0.
1364
1364
if (event_len < (uint)(common_header_len + post_header_len))
1366
1366
data_len = event_len - (common_header_len + post_header_len);
1367
1367
buf+= common_header_len;
1369
1369
slave_proxy_id= thread_id = uint4korr(buf + Q_THREAD_ID_OFFSET);
1370
1370
exec_time = uint4korr(buf + Q_EXEC_TIME_OFFSET);
1371
1371
db_len = (uint)buf[Q_DB_LEN_OFFSET]; // TODO: add a check of all *_len vars
1459
1459
my_alloc call above? /sven
1462
/* A 2nd variable part; this is common to all versions */
1462
/* A 2nd variable part; this is common to all versions */
1463
1463
memcpy(start, end, data_len); // Copy db and query
1464
1464
start[data_len]= '\0'; // End query with \0 (For safetly)
1465
1465
db= (char *)start;
1648
1648
session->is_slave_error= 1;
1651
If we get the same error code as expected, or they should be ignored.
1651
If we get the same error code as expected, or they should be ignored.
1653
1653
else if (expected_error == actual_error ||
1654
1654
ignored_error_code(actual_error))
1698
1698
Probably we have set session->query, session->db, session->catalog to point to places
1699
1699
in the data_buf of this event. Now the event is going to be deleted
1700
1700
probably, so data_buf will be freed, so the session->... listed above will be
1701
pointers to freed memory.
1701
pointers to freed memory.
1702
1702
So we must set them to 0, so that those bad pointers values are not later
1703
1703
used. Note that "cleanup" queries like automatic DROP TEMPORARY Table
1704
1704
don't suffer from these assignments to 0 as DROP TEMPORARY
1709
1709
session->query= 0; // just to be sure
1710
1710
session->query_length= 0;
1711
1711
pthread_mutex_unlock(&LOCK_thread_count);
1712
close_thread_tables(session);
1712
close_thread_tables(session);
1713
1713
session->first_successful_insert_id_in_prev_stmt= 0;
1714
1714
free_root(session->mem_root,MYF(MY_KEEP_PREALLOC));
1715
1715
return session->is_slave_error;
2305
2305
pos= my_stpcpy(pos, " IGNORE ");
2306
2306
pos= int64_t10_to_str((int64_t) skip_lines, pos, 10);
2307
pos= my_stpcpy(pos," LINES ");
2307
pos= my_stpcpy(pos," LINES ");
2310
2310
if (num_fields)
2545
2545
Load_log_event::set_fields()
2548
This function can not use the member variable
2548
This function can not use the member variable
2549
2549
for the database, since LOAD DATA INFILE on the slave
2550
2550
can be for a different database than the current one.
2551
2551
This is the reason for the affected_db argument to this method.
2554
void Load_log_event::set_fields(const char* affected_db,
2554
void Load_log_event::set_fields(const char* affected_db,
2555
2555
List<Item> &field_list,
2556
2556
Name_resolution_context *context)
2774
2774
"log position %s in log '%s' produced %ld "
2775
2775
"warning(s). Default database: '%s'"),
2776
2776
(char*) table_name,
2777
llstr(log_pos,llbuff), RPL_LOG_NAME,
2777
llstr(log_pos,llbuff), RPL_LOG_NAME,
2778
2778
(ulong) session->cuted_fields,
2779
2779
print_slave_db_safe(session->db));
2897
2897
buf += header_size;
2898
2898
pos = post_header_len ? uint8korr(buf + R_POS_OFFSET) : 4;
2899
2899
ident_len = (uint)(event_len -
2900
(header_size+post_header_len));
2901
ident_offset = post_header_len;
2900
(header_size+post_header_len));
2901
ident_offset = post_header_len;
2902
2902
set_if_smaller(ident_len,FN_REFLEN-1);
2903
2903
new_log_ident= my_strndup(buf + ident_offset, (uint) ident_len, MYF(MY_WME));
3283
3283
as these Load events are not changed between 4.0 and 5.0 (as logging of
3284
3284
LOAD DATA INFILE does not use Load_log_event in 5.0).
3286
The + 1 is for \0 terminating fname
3286
The + 1 is for \0 terminating fname
3288
3288
block_offset= (description_event->common_header_len +
3289
3289
Load_log_event::get_data_size() +
3421
3421
const Format_description_log_event* description_event)
3422
3422
:Log_event(buf, description_event),block(0)
3424
uint8_t common_header_len= description_event->common_header_len;
3424
uint8_t common_header_len= description_event->common_header_len;
3425
3425
uint8_t append_block_header_len=
3426
3426
description_event->post_header_len[APPEND_BLOCK_EVENT-1];
3427
3427
uint32_t total_header_len= common_header_len+append_block_header_len;
3633
3633
unsigned char buf[EXEC_LOAD_HEADER_LEN];
3634
3634
int4store(buf + EL_FILE_ID_OFFSET, file_id);
3635
return (write_header(file, sizeof(buf)) ||
3635
return (write_header(file, sizeof(buf)) ||
3636
3636
my_b_safe_write(file, buf, sizeof(buf)));
4014
4014
m_table(tbl_arg),
4015
4015
m_table_id(tid),
4016
4016
m_width(tbl_arg ? tbl_arg->s->fields : 1),
4017
m_rows_buf(0), m_rows_cur(0), m_rows_end(0), m_flags(0)
4017
m_rows_buf(0), m_rows_cur(0), m_rows_end(0), m_flags(0)
4018
4018
, m_curr_row(NULL), m_curr_row_end(NULL), m_key(NULL)
4197
4197
size_t const block_size= 1024;
4198
4198
my_ptrdiff_t const cur_size= m_rows_cur - m_rows_buf;
4199
my_ptrdiff_t const new_alloc=
4199
my_ptrdiff_t const new_alloc=
4200
4200
block_size * ((cur_size + length + block_size - 1) / block_size);
4202
4202
unsigned char* const new_buf= (unsigned char*)my_realloc((unsigned char*)m_rows_buf, (uint) new_alloc,
4438
4438
session->options|= OPTION_RELAXED_UNIQUE_CHECKS;
4440
4440
session->options&= ~OPTION_RELAXED_UNIQUE_CHECKS;
4442
4442
if (slave_allow_batching)
4443
4443
session->options|= OPTION_ALLOW_BATCH;
4445
4445
session->options&= ~OPTION_ALLOW_BATCH;
4447
4447
/* A small test to verify that objects have consistent types */
4448
4448
assert(sizeof(session->options) == sizeof(OPTION_RELAXED_UNIQUE_CHECKS));
4461
4461
if ( m_width == table->s->fields && bitmap_is_set_all(&m_cols))
4462
4462
set_flags(COMPLETE_ROWS_F);
4465
4465
Set tables write and read sets.
4467
4467
Read_set contains all slave columns (in case we are going to fetch
4468
4468
a complete record from slave)
4470
Write_set equals the m_cols bitmap sent from master but it can be
4471
longer if slave has extra columns.
4470
Write_set equals the m_cols bitmap sent from master but it can be
4471
longer if slave has extra columns.
4474
4474
bitmap_set_all(table->read_set);
4475
4475
bitmap_set_all(table->write_set);
4501
4501
The following list of "idempotent" errors
4502
4502
means that an error from the list might happen
4503
because of idempotent (more than once)
4503
because of idempotent (more than once)
4504
4504
applying of a binlog file.
4505
4505
Notice, that binlog has a ddl operation its
4506
4506
second applying may cause
4508
4508
case HA_ERR_TABLE_DEF_CHANGED:
4509
4509
case HA_ERR_CANNOT_ADD_FOREIGN:
4511
4511
which are not included into to the list.
4513
4513
case HA_ERR_RECORD_CHANGED:
4538
4538
If m_curr_row_end was not set during event execution (e.g., because
4539
4539
of errors) we can't proceed to the next row. If the error is transient
4540
(i.e., error==0 at this point) we must call unpack_current_row() to set
4540
(i.e., error==0 at this point) we must call unpack_current_row() to set
4541
4541
m_curr_row_end.
4543
4543
if (!m_curr_row_end && !error)
4544
4544
unpack_current_row(rli, &m_cols);
4546
4546
// at this moment m_curr_row_end should be set
4547
assert(error || m_curr_row_end != NULL);
4547
assert(error || m_curr_row_end != NULL);
4548
4548
assert(error || m_curr_row < m_curr_row_end);
4549
4549
assert(error || m_curr_row_end <= m_rows_end);
4551
4551
m_curr_row= m_curr_row_end;
4553
4553
} // row processing loop
4555
4555
error= do_after_row_operations(rli, error);
4567
4567
const_cast<Relay_log_info*>(rli)->clear_tables_to_lock();
4568
4568
/* reset OPTION_ALLOW_BATCH as not affect later events */
4569
4569
session->options&= ~OPTION_ALLOW_BATCH;
4572
4572
{ /* error has occured during the transaction */
4573
4573
slave_rows_error_report(ERROR_LEVEL, error, rli, session, table,
4774
4774
@page How replication of field metadata works.
4776
When a table map is created, the master first calls
4777
Table_map_log_event::save_field_metadata() which calculates how many
4778
values will be in the field metadata. Only those fields that require the
4779
extra data are added. The method also loops through all of the fields in
4776
When a table map is created, the master first calls
4777
Table_map_log_event::save_field_metadata() which calculates how many
4778
values will be in the field metadata. Only those fields that require the
4779
extra data are added. The method also loops through all of the fields in
4780
4780
the table calling the method Field::save_field_metadata() which returns the
4781
4781
values for the field that will be saved in the metadata and replicated to
4782
4782
the slave. Once all fields have been processed, the table map is written to
4783
4783
the binlog adding the size of the field metadata and the field metadata to
4784
4784
the end of the body of the table map.
4786
When a table map is read on the slave, the field metadata is read from the
4787
table map and passed to the table_def class constructor which saves the
4788
field metadata from the table map into an array based on the type of the
4789
field. Field metadata values not present (those fields that do not use extra
4790
data) in the table map are initialized as zero (0). The array size is the
4786
When a table map is read on the slave, the field metadata is read from the
4787
table map and passed to the table_def class constructor which saves the
4788
field metadata from the table map into an array based on the type of the
4789
field. Field metadata values not present (those fields that do not use extra
4790
data) in the table map are initialized as zero (0). The array size is the
4791
4791
same as the columns for the table on the slave.
4793
Additionally, values saved for field metadata on the master are saved as a
4793
Additionally, values saved for field metadata on the master are saved as a
4794
4794
string of bytes (unsigned char) in the binlog. A field may require 1 or more bytes
4795
to store the information. In cases where values require multiple bytes
4796
(e.g. values > 255), the endian-safe methods are used to properly encode
4795
to store the information. In cases where values require multiple bytes
4796
(e.g. values > 255), the endian-safe methods are used to properly encode
4797
4797
the values on the master and decode them on the slave. When the field
4798
4798
metadata values are captured on the slave, they are stored in an array of
4799
4799
type uint16_t. This allows the least number of casts to prevent casting bugs
4800
4800
when the field metadata is used in comparisons of field attributes. When
4801
4801
the field metadata is used for calculating addresses in pointer math, the
4802
type used is uint32_t.
4802
type used is uint32_t.
4807
4807
The metadata saved depends on the type of the field. Some fields
4808
4808
store a single byte for pack_length() while others store two bytes
4809
4809
for field_length (max length).
4814
4814
We may want to consider changing the encoding of the information.
4815
Currently, the code attempts to minimize the number of bytes written to
4816
the tablemap. There are at least two other alternatives; 1) using
4815
Currently, the code attempts to minimize the number of bytes written to
4816
the tablemap. There are at least two other alternatives; 1) using
4817
4817
net_store_length() to store the data allowing it to choose the number of
4818
bytes that are appropriate thereby making the code much easier to
4818
bytes that are appropriate thereby making the code much easier to
4819
4819
maintain (only 1 place to change the encoding), or 2) use a fixed number
4820
4820
of bytes for each field. The problem with option 1 is that net_store_length()
4821
4821
will use one byte if the value < 251, but 3 bytes if it is > 250. Thus,
4908
4908
plus one or two bytes for number of elements in the field metadata array.
4910
4910
if (m_field_metadata_size > 255)
4911
m_data_size+= m_field_metadata_size + 2;
4911
m_data_size+= m_field_metadata_size + 2;
4913
m_data_size+= m_field_metadata_size + 1;
4913
m_data_size+= m_field_metadata_size + 1;
4915
4915
memset(m_null_bits, 0, num_null_bytes);
4916
4916
for (unsigned int i= 0 ; i < m_table->s->fields ; ++i)
5125
5125
inside Relay_log_info::clear_tables_to_lock() by calling the
5126
5126
table_def destructor explicitly.
5128
new (&table_list->m_tabledef) table_def(m_coltype, m_colcnt,
5128
new (&table_list->m_tabledef) table_def(m_coltype, m_colcnt,
5129
5129
m_field_metadata, m_field_metadata_size, m_null_bits);
5130
5130
table_list->m_tabledef_valid= true;
5260
5260
when writing rows, that is: new rows replace old rows. We need to
5261
5261
inform the storage engine that it should use this behaviour.
5264
5264
/* Tell the storage engine that we are using REPLACE semantics. */
5265
5265
session->lex->duplicates= DUP_REPLACE;
5268
5268
Pretend we're executing a REPLACE command: this is needed for
5269
5269
InnoDB since it is not (properly) checking the
5270
5270
lex->duplicates flag.
5272
5272
session->lex->sql_command= SQLCOM_REPLACE;
5274
5274
Do not raise the error flag in case of hitting to an unique attribute
5276
5276
m_table->file->extra(HA_EXTRA_IGNORE_DUP_KEY);
5307
5307
m_table->file->extra(HA_EXTRA_NO_IGNORE_DUP_KEY);
5308
5308
m_table->file->extra(HA_EXTRA_WRITE_CANNOT_REPLACE);
5310
resetting the extra with
5311
table->file->extra(HA_EXTRA_NO_IGNORE_NO_KEY);
5310
resetting the extra with
5311
table->file->extra(HA_EXTRA_NO_IGNORE_NO_KEY);
5312
5312
fires bug#27077
5313
5313
explanation: file->reset() performs this duty
5314
5314
ultimately. Still todo: fix
5363
5363
Write the current row into event's table.
5365
5365
The row is located in the row buffer, pointed by @c m_curr_row member.
5366
Number of columns of the row is stored in @c m_width member (it can be
5367
different from the number of columns in the table to which we insert).
5368
Bitmap @c m_cols indicates which columns are present in the row. It is assumed
5366
Number of columns of the row is stored in @c m_width member (it can be
5367
different from the number of columns in the table to which we insert).
5368
Bitmap @c m_cols indicates which columns are present in the row. It is assumed
5369
5369
that event's table is already open and pointed by @c m_table.
5371
If the same record already exists in the table it can be either overwritten
5372
or an error is reported depending on the value of @c overwrite flag
5371
If the same record already exists in the table it can be either overwritten
5372
or an error is reported depending on the value of @c overwrite flag
5373
5373
(error reporting not yet implemented). Note that the matching record can be
5374
5374
different from the row we insert if we use primary keys to identify records in
5377
The row to be inserted can contain values only for selected columns. The
5378
missing columns are filled with default values using @c prepare_record()
5377
The row to be inserted can contain values only for selected columns. The
5378
missing columns are filled with default values using @c prepare_record()
5379
5379
function. If a matching record is found in the table and @c overwritte is
5380
5380
true, the missing columns are taken from it.
5382
5382
@param rli Relay log info (needed for row unpacking).
5384
Shall we overwrite if the row already exists or signal
5384
Shall we overwrite if the row already exists or signal
5385
5385
error (currently ignored).
5387
5387
@returns Error code on failure, 0 on success.
5389
5389
This method, if successful, sets @c m_curr_row_end pointer to point at the
5390
next row in the rows buffer. This is done when unpacking the row to be
5390
next row in the rows buffer. This is done when unpacking the row to be
5393
@note If a matching record is found, it is either updated using
5393
@note If a matching record is found, it is either updated using
5394
5394
@c ha_update_row() or first deleted and then new record written.
5398
5398
Rows_log_event::write_row(const Relay_log_info *const rli,
5420
5420
if ((error= prepare_record(table, &m_cols, m_width, true)))
5423
5423
/* unpack row into table->record[0] */
5424
5424
error= unpack_current_row(rli, &m_cols);
5426
5426
// Temporary fix to find out why it fails [/Matz]
5427
5427
memcpy(m_table->write_set->bitmap, m_cols.bitmap, (m_table->write_set->n_bits + 7) / 8);
5430
5430
Try to write record. If a corresponding record already exists in the table,
5431
5431
we try to change it using ha_update_row() if possible. Otherwise we delete
5432
it and repeat the whole process again.
5432
it and repeat the whole process again.
5434
TODO: Add safety measures against infinite looping.
5434
TODO: Add safety measures against infinite looping.
5437
5437
while ((error= table->file->ha_write_row(table->record[0])))
5588
5588
Write_rows_log_event::do_exec_row(const Relay_log_info *const rli)
5590
5590
assert(m_table != NULL);
5592
5592
write_row(rli, /* if 1 then overwrite */
5593
5593
bit_is_set(slave_exec_mode, SLAVE_EXEC_MODE_IDEMPOTENT) == 1);
5595
5595
if (error && !session->is_error())
5598
5598
my_error(ER_UNKNOWN_ERROR, MYF(0));
5687
5687
Locate the current row in event's table.
5689
The current row is pointed by @c m_curr_row. Member @c m_width tells how many
5690
columns are there in the row (this can be differnet from the number of columns
5691
in the table). It is assumed that event's table is already open and pointed
5689
The current row is pointed by @c m_curr_row. Member @c m_width tells how many
5690
columns are there in the row (this can be differnet from the number of columns
5691
in the table). It is assumed that event's table is already open and pointed
5694
If a corresponding record is found in the table it is stored in
5695
@c m_table->record[0]. Note that when record is located based on a primary
5694
If a corresponding record is found in the table it is stored in
5695
@c m_table->record[0]. Note that when record is located based on a primary
5696
5696
key, it is possible that the record found differs from the row being located.
5698
If no key is specified or table does not have keys, a table scan is used to
5698
If no key is specified or table does not have keys, a table scan is used to
5699
5699
find the row. In that case the row should be complete and contain values for
5700
all columns. However, it can still be shorter than the table, i.e. the table
5701
can contain extra columns not present in the row. It is also possible that
5702
the table has fewer columns than the row being located.
5704
@returns Error code on failure, 0 on success.
5706
@post In case of success @c m_table->record[0] contains the record found.
5700
all columns. However, it can still be shorter than the table, i.e. the table
5701
can contain extra columns not present in the row. It is also possible that
5702
the table has fewer columns than the row being located.
5704
@returns Error code on failure, 0 on success.
5706
@post In case of success @c m_table->record[0] contains the record found.
5707
5707
Also, the internal "cursor" of the table is positioned at the record found.
5709
5709
@note If the engine allows random access of the records, a combination of
5710
@c position() and @c rnd_pos() will be used.
5710
@c position() and @c rnd_pos() will be used.
5713
5713
int Rows_log_event::find_row(const Relay_log_info *rli)
5720
5720
/* unpack row - missing fields get default values */
5721
prepare_record(table, &m_cols, m_width, false/* don't check errors */);
5721
prepare_record(table, &m_cols, m_width, false/* don't check errors */);
5722
5722
error= unpack_current_row(rli, &m_cols);
5724
5724
// Temporary fix to find out why it fails [/Matz]
5757
5757
// We can't use position() - try other methods.
5760
Save copy of the record in table->record[1]. It might be needed
5760
Save copy of the record in table->record[1]. It might be needed
5761
5761
later if linear search is used to find exact match.
5763
store_record(table,record[1]);
5763
store_record(table,record[1]);
5765
5765
if (table->s->keys > 0)