Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
MariaDB
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
MariaDB
Commits
db13afd8
Commit
db13afd8
authored
Feb 09, 2005
by
serg@serg.mylan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto-ROLLBACK if binlog was not closed properly
auto-commit on Xid_log_event
parent
fb78bfeb
Changes
16
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
370 additions
and
297 deletions
+370
-297
client/mysqlbinlog.cc
client/mysqlbinlog.cc
+10
-3
mysql-test/r/ctype_ucs.result
mysql-test/r/ctype_ucs.result
+1
-0
mysql-test/r/mix_innodb_myisam_binlog.result
mysql-test/r/mix_innodb_myisam_binlog.result
+15
-25
mysql-test/r/mysqlbinlog2.result
mysql-test/r/mysqlbinlog2.result
+4
-0
mysql-test/r/rpl_relayrotate.result
mysql-test/r/rpl_relayrotate.result
+1
-1
mysql-test/r/user_var.result
mysql-test/r/user_var.result
+1
-0
mysql-test/t/ctype_ucs.test
mysql-test/t/ctype_ucs.test
+1
-0
mysql-test/t/user_var.test
mysql-test/t/user_var.test
+1
-0
sql/log.cc
sql/log.cc
+24
-42
sql/log_event.cc
sql/log_event.cc
+99
-84
sql/log_event.h
sql/log_event.h
+49
-24
sql/mysqld.cc
sql/mysqld.cc
+1
-1
sql/slave.cc
sql/slave.cc
+26
-13
sql/sql_class.h
sql/sql_class.h
+3
-3
sql/sql_repl.cc
sql/sql_repl.cc
+129
-100
sql/sql_repl.h
sql/sql_repl.h
+5
-1
No files found.
client/mysqlbinlog.cc
View file @
db13afd8
...
...
@@ -1086,7 +1086,7 @@ at offset %lu ; this could be a log format error or read error",
/* EOF can't be hit here normally, so it's a real error */
die
(
"Could not read a Rotate_log_event event \
at offset %lu ; this could be a log format error or read error"
,
tmp_pos
);
tmp_pos
);
}
else
break
;
...
...
@@ -1157,9 +1157,16 @@ static int dump_local_log_entries(const char* logname)
Log_event
*
ev
=
Log_event
::
read_log_event
(
file
,
description_event
);
if
(
!
ev
)
{
if
(
file
->
error
)
/*
if binlog wasn't closed properly ("in use" flag is set) don't complain
about a corruption, but issue a "ROLLBACK" to annihilate half-logged
transaction. Otherwise, treat it as EOF and move to the next binlog.
*/
if
(
description_event
->
flags
&
LOG_EVENT_BINLOG_IN_USE_F
)
fprintf
(
result_file
,
"ROLLBACK;
\n
"
);
else
if
(
file
->
error
)
{
fprintf
(
stderr
,
fprintf
(
stderr
,
"Could not read entry at offset %s:"
"Error in log format or read error
\n
"
,
llstr
(
old_off
,
llbuff
));
...
...
mysql-test/r/ctype_ucs.result
View file @
db13afd8
...
...
@@ -527,6 +527,7 @@ show binlog events from 96;
Log_name Pos Event_type Server_id End_log_pos Info
master-bin.000001 96 User var 1 136 @`v`=_ucs2 0x006100620063 COLLATE ucs2_general_ci
master-bin.000001 136 Query 1 219 use `test`; insert into t2 values (@v)
flush logs;
/*!40019 SET @@session.max_insert_delayed_threads=0*/;
SET @`v`:=_ucs2 0x006100620063 COLLATE ucs2_general_ci;
use test;
...
...
mysql-test/r/mix_innodb_myisam_binlog.result
View file @
db13afd8
...
...
@@ -11,8 +11,7 @@ Log_name Pos Event_type Server_id End_log_pos Info
master-bin.000001 96 Query 1 # use `test`; BEGIN
master-bin.000001 158 Query 1 # use `test`; insert into t1 values(1)
master-bin.000001 239 Query 1 # use `test`; insert into t2 select * from t1
master-bin.000001 327 Xid 1 # xid=7
master-bin.000001 354 Query 1 # use `test`; COMMIT
master-bin.000001 327 Xid 1 # COMMIT /* xid=7 */
delete from t1;
delete from t2;
reset master;
...
...
@@ -48,8 +47,7 @@ master-bin.000001 239 Query 1 # use `test`; savepoint my_savepoint
master-bin.000001 318 Query 1 # use `test`; insert into t1 values(4)
master-bin.000001 399 Query 1 # use `test`; insert into t2 select * from t1
master-bin.000001 487 Query 1 # use `test`; rollback to savepoint my_savepoint
master-bin.000001 578 Xid 1 # xid=24
master-bin.000001 605 Query 1 # use `test`; COMMIT
master-bin.000001 578 Xid 1 # COMMIT /* xid=24 */
delete from t1;
delete from t2;
reset master;
...
...
@@ -76,8 +74,7 @@ master-bin.000001 318 Query 1 # use `test`; insert into t1 values(6)
master-bin.000001 399 Query 1 # use `test`; insert into t2 select * from t1
master-bin.000001 487 Query 1 # use `test`; rollback to savepoint my_savepoint
master-bin.000001 578 Query 1 # use `test`; insert into t1 values(7)
master-bin.000001 659 Xid 1 # xid=36
master-bin.000001 686 Query 1 # use `test`; COMMIT
master-bin.000001 659 Xid 1 # COMMIT /* xid=36 */
delete from t1;
delete from t2;
reset master;
...
...
@@ -106,9 +103,8 @@ show binlog events from 96;
Log_name Pos Event_type Server_id End_log_pos Info
master-bin.000001 96 Query 1 # use `test`; BEGIN
master-bin.000001 158 Query 1 # use `test`; insert into t1 values(9)
master-bin.000001 239 Xid 1 # xid=59
master-bin.000001 266 Query 1 # use `test`; COMMIT
master-bin.000001 329 Query 1 # use `test`; insert into t2 select * from t1
master-bin.000001 239 Xid 1 # COMMIT /* xid=59 */
master-bin.000001 266 Query 1 # use `test`; insert into t2 select * from t1
delete from t1;
delete from t2;
reset master;
...
...
@@ -119,22 +115,19 @@ show binlog events from 96;
Log_name Pos Event_type Server_id End_log_pos Info
master-bin.000001 96 Query 1 # use `test`; BEGIN
master-bin.000001 158 Query 1 # use `test`; insert into t1 values(10)
master-bin.000001 240 Xid 1 # xid=65
master-bin.000001 267 Query 1 # use `test`; COMMIT
master-bin.000001 330 Query 1 # use `test`; insert into t2 select * from t1
master-bin.000001 240 Xid 1 # COMMIT /* xid=65 */
master-bin.000001 267 Query 1 # use `test`; insert into t2 select * from t1
insert into t1 values(11);
commit;
show binlog events from 96;
Log_name Pos Event_type Server_id End_log_pos Info
master-bin.000001 96 Query 1 # use `test`; BEGIN
master-bin.000001 158 Query 1 # use `test`; insert into t1 values(10)
master-bin.000001 240 Xid 1 # xid=65
master-bin.000001 267 Query 1 # use `test`; COMMIT
master-bin.000001 330 Query 1 # use `test`; insert into t2 select * from t1
master-bin.000001 418 Query 1 # use `test`; BEGIN
master-bin.000001 480 Query 1 # use `test`; insert into t1 values(11)
master-bin.000001 562 Xid 1 # xid=67
master-bin.000001 589 Query 1 # use `test`; COMMIT
master-bin.000001 240 Xid 1 # COMMIT /* xid=65 */
master-bin.000001 267 Query 1 # use `test`; insert into t2 select * from t1
master-bin.000001 355 Query 1 # use `test`; BEGIN
master-bin.000001 417 Query 1 # use `test`; insert into t1 values(11)
master-bin.000001 499 Xid 1 # COMMIT /* xid=67 */
alter table t2 engine=INNODB;
delete from t1;
delete from t2;
...
...
@@ -148,8 +141,7 @@ Log_name Pos Event_type Server_id End_log_pos Info
master-bin.000001 96 Query 1 # use `test`; BEGIN
master-bin.000001 158 Query 1 # use `test`; insert into t1 values(12)
master-bin.000001 240 Query 1 # use `test`; insert into t2 select * from t1
master-bin.000001 328 Xid 1 # xid=77
master-bin.000001 355 Query 1 # use `test`; COMMIT
master-bin.000001 328 Xid 1 # COMMIT /* xid=77 */
delete from t1;
delete from t2;
reset master;
...
...
@@ -173,8 +165,7 @@ show binlog events from 96;
Log_name Pos Event_type Server_id End_log_pos Info
master-bin.000001 96 Query 1 # use `test`; BEGIN
master-bin.000001 158 Query 1 # use `test`; insert into t1 values(14)
master-bin.000001 240 Xid 1 # xid=93
master-bin.000001 267 Query 1 # use `test`; COMMIT
master-bin.000001 240 Xid 1 # COMMIT /* xid=93 */
delete from t1;
delete from t2;
reset master;
...
...
@@ -195,8 +186,7 @@ Log_name Pos Event_type Server_id End_log_pos Info
master-bin.000001 96 Query 1 # use `test`; BEGIN
master-bin.000001 158 Query 1 # use `test`; insert into t1 values(16)
master-bin.000001 240 Query 1 # use `test`; insert into t1 values(18)
master-bin.000001 322 Xid 1 # xid=104
master-bin.000001 349 Query 1 # use `test`; COMMIT
master-bin.000001 322 Xid 1 # COMMIT /* xid=104 */
delete from t1;
delete from t2;
alter table t2 type=MyISAM;
...
...
mysql-test/r/mysqlbinlog2.result
View file @
db13afd8
...
...
@@ -144,6 +144,7 @@ SET TIMESTAMP=1579609943;
SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=1, @@session.unique_checks=1;
SET @@session.sql_mode=0;
insert into t1 values(null, "f");
ROLLBACK;
--- offset --
/*!40019 SET @@session.max_insert_delayed_threads=0*/;
...
...
@@ -171,6 +172,7 @@ SET TIMESTAMP=1579609943;
SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=1, @@session.unique_checks=1;
SET @@session.sql_mode=0;
insert into t1 values(null, "f");
ROLLBACK;
--- start-position --
/*!40019 SET @@session.max_insert_delayed_threads=0*/;
...
...
@@ -188,6 +190,7 @@ SET TIMESTAMP=1579609943;
SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=1, @@session.unique_checks=1;
SET @@session.sql_mode=0;
insert into t1 values(null, "f");
ROLLBACK;
--- stop-position --
/*!40019 SET @@session.max_insert_delayed_threads=0*/;
...
...
@@ -233,6 +236,7 @@ SET TIMESTAMP=1579609943;
SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=1, @@session.unique_checks=1;
SET @@session.sql_mode=0;
insert into t1 values(null, "f");
ROLLBACK;
--- stop-datetime --
/*!40019 SET @@session.max_insert_delayed_threads=0*/;
...
...
mysql-test/r/rpl_relayrotate.result
View file @
db13afd8
...
...
@@ -18,5 +18,5 @@ max(a)
8000
show slave status;
Slave_IO_State Master_Host Master_User Master_Port Connect_Retry Master_Log_File Read_Master_Log_Pos Relay_Log_File Relay_Log_Pos Relay_Master_Log_File Slave_IO_Running Slave_SQL_Running Replicate_Do_DB Replicate_Ignore_DB Replicate_Do_Table Replicate_Ignore_Table Replicate_Wild_Do_Table Replicate_Wild_Ignore_Table Last_Errno Last_Error Skip_Counter Exec_Master_Log_Pos Relay_Log_Space Until_Condition Until_Log_File Until_Log_Pos Master_SSL_Allowed Master_SSL_CA_File Master_SSL_CA_Path Master_SSL_Cert Master_SSL_Cipher Master_SSL_Key Seconds_Behind_Master
# 127.0.0.1 root MASTER_MYPORT 1 master-bin.000001 687
235 # # master-bin.000001 Yes Yes 0 0 687235
# None 0 No #
# 127.0.0.1 root MASTER_MYPORT 1 master-bin.000001 687
172 # # master-bin.000001 Yes Yes 0 0 687172
# None 0 No #
drop table t1;
mysql-test/r/user_var.result
View file @
db13afd8
...
...
@@ -179,6 +179,7 @@ master-bin.000001 96 User var 1 137 @`a b`=_latin1 0x68656C6C6F COLLATE latin1_s
master-bin.000001 137 Query 1 223 use `test`; INSERT INTO t1 VALUES(@`a b`)
master-bin.000001 223 User var 1 265 @`var1`=_latin1 0x273B616161 COLLATE latin1_swedish_ci
master-bin.000001 265 Query 1 351 use `test`; insert into t1 values (@var1)
flush logs;
/*!40019 SET @@session.max_insert_delayed_threads=0*/;
SET @`a b`:=_latin1 0x68656C6C6F COLLATE latin1_swedish_ci;
use test;
...
...
mysql-test/t/ctype_ucs.test
View file @
db13afd8
...
...
@@ -339,6 +339,7 @@ set @v=convert('abc' using ucs2);
reset
master
;
insert
into
t2
values
(
@
v
);
show
binlog
events
from
96
;
flush
logs
;
# more important than SHOW BINLOG EVENTS, mysqlbinlog (where we
# absolutely need variables names to be quoted and strings to be
# escaped).
...
...
mysql-test/t/user_var.test
View file @
db13afd8
...
...
@@ -110,6 +110,7 @@ INSERT INTO t1 VALUES(@`a b`);
set
@
var1
=
"';aaa"
;
insert
into
t1
values
(
@
var1
);
show
binlog
events
from
96
;
flush
logs
;
# more important than SHOW BINLOG EVENTS, mysqlbinlog (where we
# absolutely need variables names to be quoted and strings to be
# escaped).
...
...
sql/log.cc
View file @
db13afd8
...
...
@@ -119,7 +119,7 @@ static int binlog_commit(THD *thd, bool all)
}
/* Update the binary log as we have cached some queries */
error
=
mysql_bin_log
.
write
(
thd
,
trans_log
,
1
);
error
=
mysql_bin_log
.
write
(
thd
,
trans_log
);
binlog_cleanup_trans
(
trans_log
);
DBUG_RETURN
(
error
);
}
...
...
@@ -142,7 +142,11 @@ static int binlog_rollback(THD *thd, bool all)
non-transactional table inside a transaction...)
*/
if
(
unlikely
(
thd
->
options
&
OPTION_STATUS_NO_TRANS_UPDATE
))
error
=
mysql_bin_log
.
write
(
thd
,
trans_log
,
0
);
{
Query_log_event
qev
(
thd
,
"ROLLBACK"
,
8
,
TRUE
,
FALSE
);
qev
.
write
(
trans_log
);
error
=
mysql_bin_log
.
write
(
thd
,
trans_log
);
}
binlog_cleanup_trans
(
trans_log
);
DBUG_RETURN
(
error
);
}
...
...
@@ -425,7 +429,6 @@ const char *MYSQL_LOG::generate_name(const char *log_name,
const
char
*
suffix
,
bool
strip_ext
,
char
*
buff
)
{
DBUG_ASSERT
(
!
strip_ext
||
(
log_name
&&
log_name
[
0
]));
if
(
!
log_name
||
!
log_name
[
0
])
{
/*
...
...
@@ -611,6 +614,7 @@ bool MYSQL_LOG::open(const char *log_name,
even if this is not the very first binlog.
*/
Format_description_log_event
s
(
BINLOG_VERSION
);
s
.
flags
|=
LOG_EVENT_BINLOG_IN_USE_F
;
if
(
!
s
.
is_valid
())
goto
err
;
if
(
null_created_arg
)
...
...
@@ -1779,8 +1783,6 @@ uint MYSQL_LOG::next_file_id()
write()
thd
cache The cache to copy to the binlog
is_commit If true, will write "COMMIT" in the end, if false will
write "ROLLBACK".
NOTE
- We only come here if there is something in the cache.
...
...
@@ -1799,7 +1801,7 @@ uint MYSQL_LOG::next_file_id()
same updates are run on the slave.
*/
bool
MYSQL_LOG
::
write
(
THD
*
thd
,
IO_CACHE
*
cache
,
bool
is_commit
)
bool
MYSQL_LOG
::
write
(
THD
*
thd
,
IO_CACHE
*
cache
)
{
VOID
(
pthread_mutex_lock
(
&
LOCK_log
));
DBUG_ENTER
(
"MYSQL_LOG::write(cache"
);
...
...
@@ -1809,18 +1811,10 @@ bool MYSQL_LOG::write(THD *thd, IO_CACHE *cache, bool is_commit)
uint
length
;
/*
Add the "BEGIN" and "COMMIT" in the binlog around transactions
which may contain more than 1 SQL statement. If we run with
AUTOCOMMIT=1, then MySQL immediately writes each SQL statement to
the binlog when the statement has been completed. No need to add
"BEGIN" ... "COMMIT" around such statements. Otherwise, MySQL uses
trans_log (that is thd->ha_data[binlog_hton.slot]) to cache
the SQL statements until the explicit commit, and at the commit writes
the contents in trans_log to the binlog.
We write the "BEGIN" mark first in the buffer (trans_log) where we
store the SQL statements for a transaction. At the transaction commit
we will add the "COMMIT mark and write the buffer to the binlog.
Log "BEGIN" at the beginning of the transaction.
which may contain more than 1 SQL statement.
There is no need to append "COMMIT", as it's already in the 'cache'
(in fact, Xid_log_event is there which does the commit on slaves)
*/
{
Query_log_event
qinfo
(
thd
,
"BEGIN"
,
5
,
TRUE
,
FALSE
);
...
...
@@ -1846,6 +1840,7 @@ bool MYSQL_LOG::write(THD *thd, IO_CACHE *cache, bool is_commit)
if
(
reinit_io_cache
(
cache
,
READ_CACHE
,
0
,
0
,
0
))
goto
err
;
length
=
my_b_bytes_in_cache
(
cache
);
DBUG_EXECUTE_IF
(
"half_binlogged_transaction"
,
length
-=
100
;);
do
{
/* Write data to the binary log file */
...
...
@@ -1854,21 +1849,9 @@ bool MYSQL_LOG::write(THD *thd, IO_CACHE *cache, bool is_commit)
cache
->
read_pos
=
cache
->
read_end
;
// Mark buffer used up
}
while
((
length
=
my_b_fill
(
cache
)));
/*
We write the command "COMMIT" as the last SQL command in the
binlog segment cached for this transaction
*/
{
Query_log_event
qinfo
(
thd
,
is_commit
?
"COMMIT"
:
"ROLLBACK"
,
is_commit
?
6
:
8
,
TRUE
,
FALSE
);
qinfo
.
error_code
=
0
;
if
(
qinfo
.
write
(
&
log_file
)
||
flush_io_cache
(
&
log_file
)
||
sync_binlog
(
&
log_file
))
if
(
flush_io_cache
(
&
log_file
)
||
sync_binlog
(
&
log_file
))
goto
err
;
}
DBUG_EXECUTE_IF
(
"half_binlogged_transaction"
,
abort
(););
if
(
cache
->
error
)
// Error on read
{
sql_print_error
(
ER
(
ER_ERROR_ON_READ
),
cache
->
file_name
,
errno
);
...
...
@@ -2093,10 +2076,10 @@ void MYSQL_LOG::close(uint exiting)
end_io_cache
(
&
log_file
);
/* don't pwrite in a file opened with O_APPEND - it doesn't work */
if
(
log_file
.
type
==
WRITE_CACHE
)
if
(
log_file
.
type
==
WRITE_CACHE
&&
log_type
==
LOG_BIN
)
{
my_off_t
offset
=
BIN_LOG_HEADER_SIZE
+
FLAGS_OFFSET
;
char
flags
=
LOG_EVENT_BINLOG_CLOSED_F
;
char
flags
=
0
;
// clearing LOG_EVENT_BINLOG_IN_USE_F
my_pwrite
(
log_file
.
file
,
&
flags
,
1
,
offset
,
MYF
(
0
));
}
...
...
@@ -2944,15 +2927,12 @@ int TC_LOG_BINLOG::open(const char *opt_name)
goto
err
;
}
if
(((
ev
=
Log_event
::
read_log_event
(
&
log
,
0
,
&
fdle
)))
&&
(
ev
->
get_type_code
()
==
FORMAT_DESCRIPTION_EVENT
))
{
if
(
ev
->
flags
&
LOG_EVENT_BINLOG_CLOSED_F
)
error
=
0
;
else
if
((
ev
=
Log_event
::
read_log_event
(
&
log
,
0
,
&
fdle
))
&&
ev
->
get_type_code
()
==
FORMAT_DESCRIPTION_EVENT
&&
ev
->
flags
&
LOG_EVENT_BINLOG_IN_USE_F
)
error
=
recover
(
&
log
,
(
Format_description_log_event
*
)
ev
);
}
// else nothing to do (probably MySQL 4.x binlog)
else
error
=
0
;
delete
ev
;
end_io_cache
(
&
log
);
...
...
@@ -3009,6 +2989,8 @@ int TC_LOG_BINLOG::recover(IO_CACHE *log, Format_description_log_event *fdle)
init_alloc_root
(
&
mem_root
,
tc_log_page_size
,
tc_log_page_size
);
fdle
->
flags
&=
~
LOG_EVENT_BINLOG_IN_USE_F
;
// abort on the first error
while
((
ev
=
Log_event
::
read_log_event
(
log
,
0
,
fdle
))
&&
ev
->
is_valid
())
{
if
(
ev
->
get_type_code
()
==
XID_EVENT
)
...
...
sql/log_event.cc
View file @
db13afd8
This diff is collapsed.
Click to expand it.
sql/log_event.h
View file @
db13afd8
...
...
@@ -303,15 +303,38 @@ struct sql_ex_info
#endif
/*
This flag only makes sense for Format_description_log_event.
It is set not when the event is written, but when a binlog file
is closed. It serves as a reliable indicator that binlog was
closed correctly. (Stop_log_event is not enough, there's always
a small chance that mysqld crashes in the middle of insert
and end of the binlog would look like a Stop_log_event)
This flag only makes sense for Format_description_log_event. It is set
when the event is written, and *reset* when a binlog file is
closed (yes, it's the only case when MySQL modifies already written
part of binlog). Thus it is a reliable indicator that binlog was
closed correctly. (Stop_log_event is not enough, there's always a
small chance that mysqld crashes in the middle of insert and end of
the binlog would look like a Stop_log_event).
This flag is used to detect a restart after a crash,
and to provide "unbreakable" binlog. The problem is that on a crash
storage engines rollback automatically, while binlog does not.
To solve this we use this flag and automatically append ROLLBACK
to every non-closed binlog (append virtually, on reading, file itself
is not changed). If this flag is found, mysqlbinlog simply prints "ROLLBACK"
Replication master does not abort on binlog corruption, but takes it as EOF,
and replication slave forces a rollback in this case (see below).
Note, that old binlogs does not have this flag set, so we get a
a backward-compatible behaviour.
*/
#define LOG_EVENT_BINLOG_CLOSED_F 0x1
#define LOG_EVENT_BINLOG_IN_USE_F 0x1
/*
This flag is only used for fake Rotate_log_event. When a master, doing
binlog dump, reaches the end of the binlog and fakes a rotate to make
the slave to go to a new file, this flag is used if there was no
"natural" Rotate_log_event.
If this flag is set, slave will execute ROLLBACK before going further
*/
#define LOG_EVENT_FORCE_ROLLBACK_F 0x1
/*
If the query depends on the thread (for example: TEMPORARY TABLE).
...
...
@@ -335,21 +358,22 @@ struct sql_ex_info
#define LOG_EVENT_SUPPRESS_USE_F 0x8
/*
OPTIONS_WRITTEN_TO_BIN_LOG are the bits of thd->options which must be written
to the binlog. OPTIONS_WRITTEN_TO_BINLOG could be written into the
Format_description_log_event, so that if later we don't want to replicate a
variable we did replicate, or the contrary, it's doable. But it should not be
too hard to decide once for all of what we replicate and what we don't, among
the fixed 32 bits of thd->options.
OPTIONS_WRITTEN_TO_BIN_LOG are the bits of thd->options which must be
written to the binlog. OPTIONS_WRITTEN_TO_BINLOG could be written
into the Format_description_log_event, so that if later we don't want
to replicate a variable we did replicate, or the contrary, it's
doable. But it should not be too hard to decide once for all of what
we replicate and what we don't, among the fixed 32 bits of
thd->options.
I (Guilhem) have read through every option's usage, and it looks like
OPTION_AUTO_IS_NULL and OPTION_NO_FOREIGN_KEYS are the only ones
which alter
how the query modifies the table. It's good to replicate
OPTION_RELAXED_UNIQUE_CHECKS too because otherwise, the slave may
insert data
slower than the master, in InnoDB.
OPTION_AUTO_IS_NULL and OPTION_NO_FOREIGN_KEYS are the only ones
which alter
how the query modifies the table. It's good to replicate
OPTION_RELAXED_UNIQUE_CHECKS too because otherwise, the slave may
insert data
slower than the master, in InnoDB.
OPTION_BIG_SELECTS is not needed (the slave thread runs with
max_join_size=HA_POS_ERROR) and OPTION_BIG_TABLES is not needed
either, as
the manual says (because a too big in-memory temp table is automatically
written to disk).
max_join_size=HA_POS_ERROR) and OPTION_BIG_TABLES is not needed
either, as the manual says (because a too big in-memory temp table is
automatically
written to disk).
*/
#define OPTIONS_WRITTEN_TO_BIN_LOG (OPTION_AUTO_IS_NULL | \
OPTION_NO_FOREIGN_KEY_CHECKS | OPTION_RELAXED_UNIQUE_CHECKS)
...
...
@@ -470,14 +494,15 @@ class Log_event
ulong
data_written
;
/*
The master's server id (is preserved in the relay log; used to
prevent from
infinite loops in circular replication).
The master's server id (is preserved in the relay log; used to
prevent from
infinite loops in circular replication).
*/
uint32
server_id
;
/*
Some 16 flags. Look above for LOG_EVENT_TIME_F, LOG_EVENT_FORCED_ROTATE_F,
LOG_EVENT_THREAD_SPECIFIC_F, and LOG_EVENT_SUPPRESS_USE_F for notes.
Some 16 flags. Look above for LOG_EVENT_TIME_F,
LOG_EVENT_FORCED_ROTATE_F, LOG_EVENT_THREAD_SPECIFIC_F, and
LOG_EVENT_SUPPRESS_USE_F for notes.
*/
uint16
flags
;
...
...
sql/mysqld.cc
View file @
db13afd8
...
...
@@ -2684,7 +2684,7 @@ server.");
ln
=
mysql_bin_log
.
generate_name
(
opt_bin_logname
,
"-bin"
,
1
,
buf
);
if
(
ln
==
buf
)
{
my_free
(
opt_bin_logname
,
MYF
(
0
));
my_free
(
opt_bin_logname
,
MYF
(
MY_ALLOW_ZERO_PTR
));
opt_bin_logname
=
my_strdup
(
buf
,
MYF
(
0
));
}
mysql_bin_log
.
open_index_file
(
opt_binlog_index_name
,
ln
);
...
...
sql/slave.cc
View file @
db13afd8
...
...
@@ -670,11 +670,11 @@ int terminate_slave_thread(THD* thd, pthread_mutex_t* term_lock,
}
}
DBUG_ASSERT
(
thd
!=
0
);
THD_CHECK_SENTRY
(
thd
);
/*
Is is critica
te
to test if the slave is running. Otherwise, we might
Is is critica
l
to test if the slave is running. Otherwise, we might
be referening freed memory trying to kick it
*/
THD_CHECK_SENTRY
(
thd
);
while
(
*
slave_running
)
// Should always be true
{
...
...
@@ -2935,8 +2935,7 @@ static ulong read_event(MYSQL* mysql, MASTER_INFO *mi, bool* suppress_warnings)
*
suppress_warnings
=
TRUE
;
}
else
sql_print_error
(
"Error reading packet from server: %s (\
server_errno=%d)"
,
sql_print_error
(
"Error reading packet from server: %s ( server_errno=%d)"
,
mysql_error
(
mysql
),
mysql_errno
(
mysql
));
return
packet_error
;
}
...
...
@@ -3167,7 +3166,21 @@ static int exec_relay_log_event(THD* thd, RELAY_LOG_INFO* rli)
thd
->
set_time
();
// time the query
thd
->
lex
->
current_select
=
0
;
if
(
!
ev
->
when
)
{
ev
->
when
=
time
(
NULL
);
/*
fake Rotate: it means that normal execution flow of statements is
interrupted. Let's fake ROLLBACK to undo any half-executed transaction
*/
if
(
ev
->
get_type_code
()
==
ROTATE_EVENT
&&
ev
->
flags
&
LOG_EVENT_FORCE_ROLLBACK_F
)
{
ha_rollback_stmt
(
thd
);
ha_rollback
(
thd
);
thd
->
options
&=
~
(
ulong
)
(
OPTION_BEGIN
|
OPTION_STATUS_NO_TRANS_UPDATE
);
thd
->
server_status
&=
~
SERVER_STATUS_IN_TRANS
;
}
}
ev
->
thd
=
thd
;
exec_res
=
ev
->
exec_event
(
rli
);
DBUG_ASSERT
(
rli
->
sql_thd
==
thd
);
...
...
@@ -3260,7 +3273,6 @@ extern "C" pthread_handler_decl(handle_slave_io,arg)
goto
err
;
}
thd
->
proc_info
=
"Connecting to master"
;
// we can get killed during safe_connect
if
(
!
safe_connect
(
thd
,
mysql
,
mi
))
...
...
@@ -3354,9 +3366,9 @@ after reconnect");
bool
suppress_warnings
=
0
;
/*
We say "waiting" because read_event() will wait if there's nothing to
read. But if there's something to read, it will not wait. The
important
thing is to not confuse users by saying "reading" whereas we're in fact
receiving nothing.
read. But if there's something to read, it will not wait. The
important thing is to not confuse users by saying "reading" whereas
we're in fact
receiving nothing.
*/
thd
->
proc_info
=
"Waiting for master to send event"
;
ulong
event_len
=
read_event
(
mysql
,
mi
,
&
suppress_warnings
);
...
...
@@ -3870,6 +3882,7 @@ static int process_io_rotate(MASTER_INFO *mi, Rotate_log_event *rev)
if
(
disconnect_slave_event_count
)
events_till_disconnect
++
;
#endif
/*
If description_event_for_queue is format <4, there is conversion in the
relay log to the slave's format (4). And Rotate can mean upgrade or
...
...
@@ -3893,8 +3906,8 @@ static int process_io_rotate(MASTER_INFO *mi, Rotate_log_event *rev)
}
/*
Reads a 3.23 event and converts it to the slave's format. This code was
copied
from MySQL 4.0.
Reads a 3.23 event and converts it to the slave's format. This code was
copied
from MySQL 4.0.
*/
static
int
queue_binlog_ver_1_event
(
MASTER_INFO
*
mi
,
const
char
*
buf
,
ulong
event_len
)
...
...
@@ -4157,9 +4170,9 @@ int queue_event(MASTER_INFO* mi,const char* buf, ulong event_len)
to write this event again).
*/
/*
We are the only thread which reads/writes description_event_for_queue.
The
relay_log struct does not move (though some members of it can change), so
we needn't any lock (no rli->data_lock, no log lock).
We are the only thread which reads/writes description_event_for_queue.
The relay_log struct does not move (though some members of it can
change), so
we needn't any lock (no rli->data_lock, no log lock).
*/
Format_description_log_event
*
tmp
;
const
char
*
errmsg
;
...
...
sql/sql_class.h
View file @
db13afd8
...
...
@@ -301,7 +301,7 @@ class MYSQL_LOG: public TC_LOG
bool
write
(
THD
*
thd
,
const
char
*
query
,
uint
query_length
,
time_t
query_start
=
0
);
bool
write
(
Log_event
*
event_info
);
// binary log write
bool
write
(
THD
*
thd
,
IO_CACHE
*
cache
,
bool
commit_or_rollback
);
bool
write
(
THD
*
thd
,
IO_CACHE
*
cache
);
/*
v stands for vector
...
...
@@ -314,11 +314,11 @@ class MYSQL_LOG: public TC_LOG
void
make_log_name
(
char
*
buf
,
const
char
*
log_ident
);
bool
is_active
(
const
char
*
log_file_name
);
int
update_log_index
(
LOG_INFO
*
linfo
,
bool
need_update_threads
);
int
purge_logs
(
const
char
*
to_log
,
bool
included
,
int
purge_logs
(
const
char
*
to_log
,
bool
included
,
bool
need_mutex
,
bool
need_update_threads
,
ulonglong
*
decrease_log_space
);
int
purge_logs_before_date
(
time_t
purge_time
);
int
purge_first_log
(
struct
st_relay_log_info
*
rli
,
bool
included
);
int
purge_first_log
(
struct
st_relay_log_info
*
rli
,
bool
included
);
bool
reset_logs
(
THD
*
thd
);
void
close
(
uint
exiting
);
...
...
sql/sql_repl.cc
View file @
db13afd8
This diff is collapsed.
Click to expand it.
sql/sql_repl.h
View file @
db13afd8
...
...
@@ -36,7 +36,11 @@ extern I_List<i_string> binlog_do_db, binlog_ignore_db;
extern
int
max_binlog_dump_events
;
extern
my_bool
opt_sporadic_binlog_dump_fail
;
#define KICK_SLAVE(thd) { pthread_mutex_lock(&(thd)->LOCK_delete); (thd)->awake(THD::NOT_KILLED); pthread_mutex_unlock(&(thd)->LOCK_delete); }
#define KICK_SLAVE(thd) do { \
pthread_mutex_lock(&(thd)->LOCK_delete); \
(thd)->awake(THD::NOT_KILLED); \
pthread_mutex_unlock(&(thd)->LOCK_delete); \
} while(0)
int
start_slave
(
THD
*
thd
,
MASTER_INFO
*
mi
,
bool
net_report
);
int
stop_slave
(
THD
*
thd
,
MASTER_INFO
*
mi
,
bool
net_report
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment