Commit e38b3e23 authored by serg@serg.mylan's avatar serg@serg.mylan

Merge bk-internal:/home/bk/mysql-5.0

into serg.mylan:/usr/home/serg/Abk/mysql-5.0
parents bef16908 9c9d1fd4
drop table if exists t1, t2;
reset master;
create table t1 (a int) engine=bdb;
create table t2 (a int) engine=innodb;
begin;
insert t1 values (5);
commit;
begin;
insert t2 values (5);
commit;
show binlog events from 96;
Log_name Pos Event_type Server_id End_log_pos Info
master-bin.000001 96 Query 1 194 use `test`; create table t1 (a int) engine=bdb
master-bin.000001 194 Query 1 295 use `test`; create table t2 (a int) engine=innodb
master-bin.000001 295 Query 1 364 use `test`; BEGIN
master-bin.000001 364 Query 1 84 use `test`; insert t1 values (5)
master-bin.000001 448 Query 1 518 use `test`; COMMIT
master-bin.000001 518 Query 1 587 use `test`; BEGIN
master-bin.000001 587 Query 1 84 use `test`; insert t2 values (5)
master-bin.000001 671 Xid 1 698 COMMIT /* xid=318 */
reset master;
drop table t1,t2;
...@@ -272,6 +272,10 @@ n ...@@ -272,6 +272,10 @@ n
7 7
rollback to savepoint `my_savepoint`; rollback to savepoint `my_savepoint`;
ERROR 42000: SAVEPOINT my_savepoint does not exist ERROR 42000: SAVEPOINT my_savepoint does not exist
insert into t1 values (8);
savepoint sv;
commit;
savepoint sv;
set autocommit=1; set autocommit=1;
rollback; rollback;
drop table t1; drop table t1;
...@@ -1717,7 +1721,7 @@ Variable_name Value ...@@ -1717,7 +1721,7 @@ Variable_name Value
Innodb_rows_deleted 2070 Innodb_rows_deleted 2070
show status like "Innodb_rows_inserted"; show status like "Innodb_rows_inserted";
Variable_name Value Variable_name Value
Innodb_rows_inserted 31708 Innodb_rows_inserted 31709
show status like "Innodb_rows_updated"; show status like "Innodb_rows_updated";
Variable_name Value Variable_name Value
Innodb_rows_updated 29530 Innodb_rows_updated 29530
......
...@@ -101,10 +101,9 @@ insert into t1 values(9); ...@@ -101,10 +101,9 @@ insert into t1 values(9);
insert into t2 select * from t1; insert into t2 select * from t1;
show binlog events from 96; show binlog events from 96;
Log_name Pos Event_type Server_id End_log_pos Info Log_name Pos Event_type Server_id End_log_pos Info
master-bin.000001 96 Query 1 # use `test`; BEGIN master-bin.000001 96 Query 1 # use `test`; insert into t1 values(9)
master-bin.000001 165 Query 1 # use `test`; insert into t1 values(9) master-bin.000001 184 Xid 1 # COMMIT /* xid=59 */
master-bin.000001 253 Xid 1 # COMMIT /* xid=59 */ master-bin.000001 211 Query 1 # use `test`; insert into t2 select * from t1
master-bin.000001 280 Query 1 # use `test`; insert into t2 select * from t1
delete from t1; delete from t1;
delete from t2; delete from t2;
reset master; reset master;
...@@ -113,21 +112,19 @@ begin; ...@@ -113,21 +112,19 @@ begin;
insert into t2 select * from t1; insert into t2 select * from t1;
show binlog events from 96; show binlog events from 96;
Log_name Pos Event_type Server_id End_log_pos Info Log_name Pos Event_type Server_id End_log_pos Info
master-bin.000001 96 Query 1 # use `test`; BEGIN master-bin.000001 96 Query 1 # use `test`; insert into t1 values(10)
master-bin.000001 165 Query 1 # use `test`; insert into t1 values(10) master-bin.000001 185 Xid 1 # COMMIT /* xid=65 */
master-bin.000001 254 Xid 1 # COMMIT /* xid=65 */ master-bin.000001 212 Query 1 # use `test`; insert into t2 select * from t1
master-bin.000001 281 Query 1 # use `test`; insert into t2 select * from t1
insert into t1 values(11); insert into t1 values(11);
commit; commit;
show binlog events from 96; show binlog events from 96;
Log_name Pos Event_type Server_id End_log_pos Info Log_name Pos Event_type Server_id End_log_pos Info
master-bin.000001 96 Query 1 # use `test`; BEGIN master-bin.000001 96 Query 1 # use `test`; insert into t1 values(10)
master-bin.000001 165 Query 1 # use `test`; insert into t1 values(10) master-bin.000001 185 Xid 1 # COMMIT /* xid=65 */
master-bin.000001 254 Xid 1 # COMMIT /* xid=65 */ master-bin.000001 212 Query 1 # use `test`; insert into t2 select * from t1
master-bin.000001 281 Query 1 # use `test`; insert into t2 select * from t1 master-bin.000001 307 Query 1 # use `test`; BEGIN
master-bin.000001 376 Query 1 # use `test`; BEGIN master-bin.000001 376 Query 1 # use `test`; insert into t1 values(11)
master-bin.000001 445 Query 1 # use `test`; insert into t1 values(11) master-bin.000001 465 Xid 1 # COMMIT /* xid=67 */
master-bin.000001 534 Xid 1 # COMMIT /* xid=67 */
alter table t2 engine=INNODB; alter table t2 engine=INNODB;
delete from t1; delete from t1;
delete from t2; delete from t2;
......
...@@ -203,7 +203,7 @@ master-bin.000001 9190 Query 1 9016 use `test`; insert into t1 values(4 + 4) ...@@ -203,7 +203,7 @@ master-bin.000001 9190 Query 1 9016 use `test`; insert into t1 values(4 + 4)
master-bin.000001 9282 Query 1 9108 use `test`; insert into t1 values(3 + 4) master-bin.000001 9282 Query 1 9108 use `test`; insert into t1 values(3 + 4)
master-bin.000001 9374 Query 1 9200 use `test`; insert into t1 values(2 + 4) master-bin.000001 9374 Query 1 9200 use `test`; insert into t1 values(2 + 4)
master-bin.000001 9466 Query 1 9292 use `test`; insert into t1 values(1 + 4) master-bin.000001 9466 Query 1 9292 use `test`; insert into t1 values(1 + 4)
master-bin.000001 9558 Xid 1 9319 COMMIT /* xid=146 */ master-bin.000001 9558 Xid 1 9585 COMMIT /* xid=146 */
master-bin.000001 9585 Rotate 1 9629 master-bin.000002;pos=4 master-bin.000001 9585 Rotate 1 9629 master-bin.000002;pos=4
show binlog events in 'master-bin.000002'; show binlog events in 'master-bin.000002';
Log_name Pos Event_type Server_id End_log_pos Info Log_name Pos Event_type Server_id End_log_pos Info
......
#
# misc binlogging tests that do not require a slave running
#
-- source include/have_bdb.inc
-- source include/have_innodb.inc
--disable_warnings
drop table if exists t1, t2;
--enable_warnings
reset master;
create table t1 (a int) engine=bdb;
create table t2 (a int) engine=innodb;
begin;
insert t1 values (5);
commit;
begin;
insert t2 values (5);
commit;
# first COMMIT must be Query_log_event, second - Xid_log_event
--replace_result "xid=891" "xid=318" "xid=11" "xid=318" "xid=18" "xid=318"
show binlog events from 96;
reset master;
drop table t1,t2;
...@@ -141,6 +141,10 @@ release savepoint `my_savepoint`; ...@@ -141,6 +141,10 @@ release savepoint `my_savepoint`;
select n from t1; select n from t1;
-- error 1305 -- error 1305
rollback to savepoint `my_savepoint`; rollback to savepoint `my_savepoint`;
insert into t1 values (8);
savepoint sv;
commit;
savepoint sv;
set autocommit=1; set autocommit=1;
# nop # nop
rollback; rollback;
......
...@@ -197,7 +197,7 @@ enum row_type { ROW_TYPE_NOT_USED=-1, ROW_TYPE_DEFAULT, ROW_TYPE_FIXED, ...@@ -197,7 +197,7 @@ enum row_type { ROW_TYPE_NOT_USED=-1, ROW_TYPE_DEFAULT, ROW_TYPE_FIXED,
#define HA_CREATE_USED_COMMENT (1L << 16) #define HA_CREATE_USED_COMMENT (1L << 16)
#define HA_CREATE_USED_PASSWORD (1L << 17) #define HA_CREATE_USED_PASSWORD (1L << 17)
typedef ulonglong my_xid; typedef ulonglong my_xid; // this line is the same as in log_event.h
#define MYSQL_XID_PREFIX "MySQLXid" #define MYSQL_XID_PREFIX "MySQLXid"
#define MYSQL_XID_PREFIX_LEN 8 // must be a multiple of 8 #define MYSQL_XID_PREFIX_LEN 8 // must be a multiple of 8
#define MYSQL_XID_OFFSET (MYSQL_XID_PREFIX_LEN+sizeof(server_id)) #define MYSQL_XID_OFFSET (MYSQL_XID_PREFIX_LEN+sizeof(server_id))
......
...@@ -80,8 +80,13 @@ static int binlog_close_connection(THD *thd) ...@@ -80,8 +80,13 @@ static int binlog_close_connection(THD *thd)
return 0; return 0;
} }
static inline void binlog_cleanup_trans(IO_CACHE *trans_log) static int binlog_end_trans(THD *thd, IO_CACHE *trans_log, Log_event *end_ev)
{ {
int error=0;
DBUG_ENTER("binlog_end_trans");
if (end_ev)
error= mysql_bin_log.write(thd, trans_log, end_ev);
statistic_increment(binlog_cache_use, &LOCK_status); statistic_increment(binlog_cache_use, &LOCK_status);
if (trans_log->disk_writes != 0) if (trans_log->disk_writes != 0)
{ {
...@@ -90,6 +95,7 @@ static inline void binlog_cleanup_trans(IO_CACHE *trans_log) ...@@ -90,6 +95,7 @@ static inline void binlog_cleanup_trans(IO_CACHE *trans_log)
} }
reinit_io_cache(trans_log, WRITE_CACHE, (my_off_t) 0, 0, 1); // cannot fail reinit_io_cache(trans_log, WRITE_CACHE, (my_off_t) 0, 0, 1); // cannot fail
trans_log->end_of_file= max_binlog_cache_size; trans_log->end_of_file= max_binlog_cache_size;
DBUG_RETURN(error);
} }
static int binlog_prepare(THD *thd, bool all) static int binlog_prepare(THD *thd, bool all)
...@@ -105,7 +111,6 @@ static int binlog_prepare(THD *thd, bool all) ...@@ -105,7 +111,6 @@ static int binlog_prepare(THD *thd, bool all)
static int binlog_commit(THD *thd, bool all) static int binlog_commit(THD *thd, bool all)
{ {
int error;
IO_CACHE *trans_log= (IO_CACHE*)thd->ha_data[binlog_hton.slot]; IO_CACHE *trans_log= (IO_CACHE*)thd->ha_data[binlog_hton.slot];
DBUG_ENTER("binlog_commit"); DBUG_ENTER("binlog_commit");
DBUG_ASSERT(mysql_bin_log.is_open() && DBUG_ASSERT(mysql_bin_log.is_open() &&
...@@ -116,11 +121,8 @@ static int binlog_commit(THD *thd, bool all) ...@@ -116,11 +121,8 @@ static int binlog_commit(THD *thd, bool all)
// we're here because trans_log was flushed in MYSQL_LOG::log() // we're here because trans_log was flushed in MYSQL_LOG::log()
DBUG_RETURN(0); DBUG_RETURN(0);
} }
Query_log_event qev(thd, "COMMIT", 6, TRUE, FALSE);
/* Update the binary log as we have cached some queries */ DBUG_RETURN(binlog_end_trans(thd, trans_log, &qev));
error= mysql_bin_log.write(thd, trans_log);
binlog_cleanup_trans(trans_log);
DBUG_RETURN(error);
} }
static int binlog_rollback(THD *thd, bool all) static int binlog_rollback(THD *thd, bool all)
...@@ -144,10 +146,10 @@ static int binlog_rollback(THD *thd, bool all) ...@@ -144,10 +146,10 @@ static int binlog_rollback(THD *thd, bool all)
if (unlikely(thd->options & OPTION_STATUS_NO_TRANS_UPDATE)) if (unlikely(thd->options & OPTION_STATUS_NO_TRANS_UPDATE))
{ {
Query_log_event qev(thd, "ROLLBACK", 8, TRUE, FALSE); Query_log_event qev(thd, "ROLLBACK", 8, TRUE, FALSE);
qev.write(trans_log); error= binlog_end_trans(thd, trans_log, &qev);
error= mysql_bin_log.write(thd, trans_log);
} }
binlog_cleanup_trans(trans_log); else
error= binlog_end_trans(thd, trans_log, 0);
DBUG_RETURN(error); DBUG_RETURN(error);
} }
...@@ -1822,11 +1824,11 @@ uint MYSQL_LOG::next_file_id() ...@@ -1822,11 +1824,11 @@ uint MYSQL_LOG::next_file_id()
that the same updates are run on the slave. that the same updates are run on the slave.
*/ */
bool MYSQL_LOG::write(THD *thd, IO_CACHE *cache) bool MYSQL_LOG::write(THD *thd, IO_CACHE *cache, Log_event *commit_event)
{ {
bool error= 0; bool error= 0;
VOID(pthread_mutex_lock(&LOCK_log)); VOID(pthread_mutex_lock(&LOCK_log));
DBUG_ENTER("MYSQL_LOG::write(THD *, IO_CACHE *)"); DBUG_ENTER("MYSQL_LOG::write(THD *, IO_CACHE *, Log_event *)");
if (likely(is_open())) // Should always be true if (likely(is_open())) // Should always be true
{ {
...@@ -1835,9 +1837,8 @@ bool MYSQL_LOG::write(THD *thd, IO_CACHE *cache) ...@@ -1835,9 +1837,8 @@ bool MYSQL_LOG::write(THD *thd, IO_CACHE *cache)
/* /*
Log "BEGIN" at the beginning of the transaction. Log "BEGIN" at the beginning of the transaction.
which may contain more than 1 SQL statement. 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)
*/ */
if (thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))
{ {
Query_log_event qinfo(thd, "BEGIN", 5, TRUE, FALSE); Query_log_event qinfo(thd, "BEGIN", 5, TRUE, FALSE);
/* /*
...@@ -1869,8 +1870,12 @@ bool MYSQL_LOG::write(THD *thd, IO_CACHE *cache) ...@@ -1869,8 +1870,12 @@ bool MYSQL_LOG::write(THD *thd, IO_CACHE *cache)
if (my_b_write(&log_file, cache->read_pos, length)) if (my_b_write(&log_file, cache->read_pos, length))
goto err; goto err;
cache->read_pos=cache->read_end; // Mark buffer used up cache->read_pos=cache->read_end; // Mark buffer used up
DBUG_EXECUTE_IF("half_binlogged_transaction", goto DBUG_skip_commit;);
} while ((length=my_b_fill(cache))); } while ((length=my_b_fill(cache)));
if (commit_event->write(&log_file))
goto err;
DBUG_skip_commit:
if (flush_io_cache(&log_file) || sync_binlog(&log_file)) if (flush_io_cache(&log_file) || sync_binlog(&log_file))
goto err; goto err;
DBUG_EXECUTE_IF("half_binlogged_transaction", abort();); DBUG_EXECUTE_IF("half_binlogged_transaction", abort(););
...@@ -2985,10 +2990,9 @@ void TC_LOG_BINLOG::close() ...@@ -2985,10 +2990,9 @@ void TC_LOG_BINLOG::close()
int TC_LOG_BINLOG::log(THD *thd, my_xid xid) int TC_LOG_BINLOG::log(THD *thd, my_xid xid)
{ {
Xid_log_event xle(thd, xid); Xid_log_event xle(thd, xid);
if (xle.write((IO_CACHE*)thd->ha_data[binlog_hton.slot])) IO_CACHE *trans_log= (IO_CACHE*)thd->ha_data[binlog_hton.slot];
return 0;
thread_safe_increment(prepared_xids, &LOCK_prep_xids); thread_safe_increment(prepared_xids, &LOCK_prep_xids);
return !binlog_commit(thd,1); // invert return value return !binlog_end_trans(thd, trans_log, &xle); // invert return value
} }
void TC_LOG_BINLOG::unlog(ulong cookie, my_xid xid) void TC_LOG_BINLOG::unlog(ulong cookie, my_xid xid)
......
...@@ -3140,10 +3140,9 @@ void Xid_log_event::print(FILE* file, bool short_form, LAST_EVENT_INFO* last_eve ...@@ -3140,10 +3140,9 @@ void Xid_log_event::print(FILE* file, bool short_form, LAST_EVENT_INFO* last_eve
#if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT) #if defined(HAVE_REPLICATION) && !defined(MYSQL_CLIENT)
int Xid_log_event::exec_event(struct st_relay_log_info* rli) int Xid_log_event::exec_event(struct st_relay_log_info* rli)
{ {
rli->inc_event_relay_log_pos();
/* For a slave Xid_log_event is COMMIT */ /* For a slave Xid_log_event is COMMIT */
mysql_log.write(thd,COM_QUERY,"COMMIT /* implicit, from Xid_log_event */"); mysql_log.write(thd,COM_QUERY,"COMMIT /* implicit, from Xid_log_event */");
return end_trans(thd, COMMIT); return end_trans(thd, COMMIT) || Log_event::exec_event(rli);
} }
#endif /* !MYSQL_CLIENT */ #endif /* !MYSQL_CLIENT */
......
...@@ -1077,7 +1077,7 @@ class Rand_log_event: public Log_event ...@@ -1077,7 +1077,7 @@ class Rand_log_event: public Log_event
****************************************************************************/ ****************************************************************************/
#ifdef MYSQL_CLIENT #ifdef MYSQL_CLIENT
typedef ulong my_xid; typedef ulonglong my_xid; // this line is the same as in handler.h
#endif #endif
class Xid_log_event: public Log_event class Xid_log_event: public Log_event
......
...@@ -309,7 +309,7 @@ public: ...@@ -309,7 +309,7 @@ public:
bool write(THD *thd, const char *query, uint query_length, bool write(THD *thd, const char *query, uint query_length,
time_t query_start=0); time_t query_start=0);
bool write(Log_event* event_info); // binary log write bool write(Log_event* event_info); // binary log write
bool write(THD *thd, IO_CACHE *cache); bool write(THD *thd, IO_CACHE *cache, Log_event *commit_event);
/* /*
v stands for vector v stands for vector
......
...@@ -129,13 +129,13 @@ static bool end_active_trans(THD *thd) ...@@ -129,13 +129,13 @@ static bool end_active_trans(THD *thd)
OPTION_TABLE_LOCK)) OPTION_TABLE_LOCK))
{ {
DBUG_PRINT("info",("options: 0x%lx", (ulong) thd->options)); DBUG_PRINT("info",("options: 0x%lx", (ulong) thd->options));
thd->options&= ~(ulong) (OPTION_BEGIN | OPTION_STATUS_NO_TRANS_UPDATE);
/* Safety if one did "drop table" on locked tables */ /* Safety if one did "drop table" on locked tables */
if (!thd->locked_tables) if (!thd->locked_tables)
thd->options&= ~OPTION_TABLE_LOCK; thd->options&= ~OPTION_TABLE_LOCK;
thd->server_status&= ~SERVER_STATUS_IN_TRANS; thd->server_status&= ~SERVER_STATUS_IN_TRANS;
if (ha_commit(thd)) if (ha_commit(thd))
error=1; error=1;
thd->options&= ~(ulong) (OPTION_BEGIN | OPTION_STATUS_NO_TRANS_UPDATE);
} }
DBUG_RETURN(error); DBUG_RETURN(error);
} }
...@@ -1337,9 +1337,9 @@ int end_trans(THD *thd, enum enum_mysql_completiontype completion) ...@@ -1337,9 +1337,9 @@ int end_trans(THD *thd, enum enum_mysql_completiontype completion)
even if there is a problem with the OPTION_AUTO_COMMIT flag even if there is a problem with the OPTION_AUTO_COMMIT flag
(Which of course should never happen...) (Which of course should never happen...)
*/ */
thd->options&= ~(ulong) (OPTION_BEGIN | OPTION_STATUS_NO_TRANS_UPDATE);
thd->server_status&= ~SERVER_STATUS_IN_TRANS; thd->server_status&= ~SERVER_STATUS_IN_TRANS;
res= ha_commit(thd); res= ha_commit(thd);
thd->options&= ~(ulong) (OPTION_BEGIN | OPTION_STATUS_NO_TRANS_UPDATE);
break; break;
case COMMIT_RELEASE: case COMMIT_RELEASE:
do_release= 1; /* fall through */ do_release= 1; /* fall through */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment