Skip to content

Commit 56129ce

Browse files
author
sasha@mysql.sashanet.com
committed
Here comes a nasty patch, although I am not ready to push it yet. I will
first pull, merge,test, and get it to work. The main change is the new replication code - now we have two slave threads SQL thread and I/O thread. I have also re-written a lot of the code to prepare for multi-master implementation. I also documented IO_CACHE quite extensively and to some extend, THD class.
1 parent f481272 commit 56129ce

39 files changed

+2467
-1035
lines changed

.bzrignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,3 +446,9 @@ vio/test-sslclient
446446
vio/test-sslserver
447447
vio/viotest-ssl
448448
sql-bench/test-transactions
449+
mysql-test/r/rpl000002.eval
450+
mysql-test/r/rpl000014.eval
451+
mysql-test/r/rpl000015.eval
452+
mysql-test/r/rpl000016.eval
453+
mysql-test/r/slave-running.eval
454+
mysql-test/r/slave-stopped.eval

Makefile.am

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,11 @@ bin-dist: all
7474
$(top_builddir)/scripts/make_binary_distribution
7575

7676
tags:
77-
rm -f TAGS
78-
find -not -path \*SCCS\* -and \
79-
\( -name \*.cc -or -name \*.h -or -name \*.yy -or -name \*.c \) \
80-
-print -exec etags -o TAGS --append {} \;
81-
77+
support-files/build-tags
8278
.PHONY: init-db bin-dist
8379

8480
# Test installation
8581

8682
test:
8783
cd mysql-test ; ./mysql-test-run
84+

include/my_sys.h

Lines changed: 76 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -296,35 +296,105 @@ typedef int (*IO_CACHE_CALLBACK)(struct st_io_cache*);
296296

297297
typedef struct st_io_cache /* Used when cacheing files */
298298
{
299+
/* pos_in_file is offset in file corresponding to the first byte of
300+
byte* buffer. end_of_file is the offset of end of file for READ_CACHE
301+
and WRITE_CACHE. For SEQ_READ_APPEND it the maximum of the actual
302+
end of file and the position represented by read_end.
303+
*/
299304
my_off_t pos_in_file,end_of_file;
305+
/* read_pos points to current read position in the buffer
306+
read_end is the non-inclusive boundary in the buffer for the currently
307+
valid read area
308+
buffer is the read buffer
309+
not sure about request_pos except that it is used in async_io
310+
*/
300311
byte *read_pos,*read_end,*buffer,*request_pos;
312+
/* write_buffer is used only in WRITE caches and in SEQ_READ_APPEND to
313+
buffer writes
314+
append_read_pos is only used in SEQ_READ_APPEND, and points to the
315+
current read position in the write buffer. Note that reads in
316+
SEQ_READ_APPEND caches can happen from both read buffer (byte* buffer),
317+
and write buffer (byte* write_buffer).
318+
write_pos points to current write position in the write buffer and
319+
write_end is the non-inclusive boundary of the valid write area
320+
*/
301321
byte *write_buffer, *append_read_pos, *write_pos, *write_end;
322+
/* current_pos and current_end are convenience variables used by
323+
my_b_tell() and other routines that need to know the current offset
324+
current_pos points to &write_pos, and current_end to &write_end in a
325+
WRITE_CACHE, and &read_pos and &read_end respectively otherwise
326+
*/
302327
byte **current_pos, **current_end;
303-
/* The lock is for append buffer used in READ_APPEND cache */
328+
/* The lock is for append buffer used in SEQ_READ_APPEND cache */
304329
#ifdef THREAD
305330
pthread_mutex_t append_buffer_lock;
306331
/* need mutex copying from append buffer to read buffer */
307-
#endif
332+
#endif
333+
/* a caller will use my_b_read() macro to read from the cache
334+
if the data is already in cache, it will be simply copied with
335+
memcpy() and internal variables will be accordinging updated with
336+
no functions invoked. However, if the data is not fully in the cache,
337+
my_b_read() will call read_function to fetch the data. read_function
338+
must never be invoked directly
339+
*/
308340
int (*read_function)(struct st_io_cache *,byte *,uint);
341+
/* same idea as in the case of read_function, except my_b_write() needs to
342+
be replaced with my_b_append() for a SEQ_READ_APPEND cache
343+
*/
309344
int (*write_function)(struct st_io_cache *,const byte *,uint);
345+
/* specifies the type of the cache. Depending on the type of the cache
346+
certain operations might not be available and yield unpredicatable
347+
results. Details to be documented later
348+
*/
310349
enum cache_type type;
311-
/* callbacks when the actual read I/O happens */
350+
/* callbacks when the actual read I/O happens. These were added and
351+
are currently used for binary logging of LOAD DATA INFILE - when a
352+
block is read from the file, we create a block create/append event, and
353+
when IO_CACHE is closed, we create an end event. These functions could,
354+
of course be used for other things
355+
*/
312356
IO_CACHE_CALLBACK pre_read;
313357
IO_CACHE_CALLBACK post_read;
314358
IO_CACHE_CALLBACK pre_close;
315359
void* arg; /* for use by pre/post_read */
316360
char *file_name; /* if used with 'open_cached_file' */
317361
char *dir,*prefix;
318-
File file;
362+
File file; /* file descriptor */
363+
/* seek_not_done is set by my_b_seek() to inform the upcoming read/write
364+
operation that a seek needs to be preformed prior to the actual I/O
365+
error is 0 if the cache operation was successful, -1 if there was a
366+
"hard" error, and the actual number of I/O-ed bytes if the read/write was
367+
partial
368+
*/
319369
int seek_not_done,error;
370+
/* buffer_length is the size of memory allocated for buffer or write_buffer
371+
read_length is the same as buffer_length except when we use async io
372+
not sure why we need it
373+
*/
320374
uint buffer_length,read_length;
321375
myf myflags; /* Flags used to my_read/my_write */
322376
/*
377+
alloced_buffer is 1 if the buffer was allocated by init_io_cache() and
378+
0 if it was supplied by the user
323379
Currently READ_NET is the only one that will use a buffer allocated
324380
somewhere else
325381
*/
326382
my_bool alloced_buffer;
383+
/* init_count is incremented every time we call init_io_cache()
384+
It is not reset in end_io_cache(). This variable
385+
was introduced for slave relay logs - RELAY_LOG_INFO stores a pointer
386+
to IO_CACHE that could in some cases refer to the IO_CACHE of the
387+
currently active relay log. The IO_CACHE then could be closed,
388+
re-opened and start pointing to a different log file. In that case,
389+
we could not know reliably if this happened without init_count
390+
one must be careful with bzero() prior to the subsequent init_io_cache()
391+
call
392+
*/
393+
int init_count;
327394
#ifdef HAVE_AIOWAIT
395+
/* as inidicated by ifdef, this is for async I/O, we will have
396+
Sinisa comment this some time
397+
*/
328398
uint inited;
329399
my_off_t aio_read_pos;
330400
my_aio_result aio_result;
@@ -369,6 +439,8 @@ typedef int (*qsort2_cmp)(const void *, const void *, const void *);
369439

370440
#define my_b_tell(info) ((info)->pos_in_file + \
371441
(uint) (*(info)->current_pos - (info)->request_pos))
442+
#define my_b_append_tell(info) ((info)->end_of_file + \
443+
(uint) ((info)->write_pos - (info)->write_buffer))
372444

373445
#define my_b_bytes_in_cache(info) (uint) (*(info)->current_end - \
374446
*(info)->current_pos)

libmysqld/lib_sql.cc

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -396,8 +396,8 @@ int STDCALL mysql_server_init(int argc, char **argv, char **groups)
396396
(void) pthread_mutex_init(&LOCK_bytes_sent,MY_MUTEX_INIT_FAST);
397397
(void) pthread_mutex_init(&LOCK_bytes_received,MY_MUTEX_INIT_FAST);
398398
(void) pthread_mutex_init(&LOCK_timezone,MY_MUTEX_INIT_FAST);
399-
(void) pthread_mutex_init(&LOCK_binlog_update, MY_MUTEX_INIT_FAST); // QQ NOT USED
400-
(void) pthread_mutex_init(&LOCK_slave, MY_MUTEX_INIT_FAST);
399+
(void) pthread_mutex_init(&LOCK_slave_io, MY_MUTEX_INIT_FAST);
400+
(void) pthread_mutex_init(&LOCK_slave_sql, MY_MUTEX_INIT_FAST);
401401
(void) pthread_mutex_init(&LOCK_server_id, MY_MUTEX_INIT_FAST);
402402
(void) pthread_mutex_init(&LOCK_user_conn, MY_MUTEX_INIT_FAST);
403403
(void) pthread_cond_init(&COND_thread_count,NULL);
@@ -406,8 +406,11 @@ int STDCALL mysql_server_init(int argc, char **argv, char **groups)
406406
(void) pthread_cond_init(&COND_flush_thread_cache,NULL);
407407
(void) pthread_cond_init(&COND_manager,NULL);
408408
(void) pthread_cond_init(&COND_binlog_update, NULL);
409-
(void) pthread_cond_init(&COND_slave_stopped, NULL);
410-
(void) pthread_cond_init(&COND_slave_start, NULL);
409+
(void) pthread_cond_init(&COND_slave_log_update, NULL);
410+
(void) pthread_cond_init(&COND_slave_sql_stop, NULL);
411+
(void) pthread_cond_init(&COND_slave_sql_start, NULL);
412+
(void) pthread_cond_init(&COND_slave_sql_stop, NULL);
413+
(void) pthread_cond_init(&COND_slave_sql_start, NULL);
411414

412415
if (set_default_charset_by_name(default_charset, MYF(MY_WME)))
413416
{

mysql-test/r/rpl000014.result

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,22 @@ show master status;
77
File Position Binlog_do_db Binlog_ignore_db
88
master-bin.001 79
99
show slave status;
10-
Master_Host Master_User Master_Port Connect_retry Log_File Pos Slave_Running Replicate_do_db Replicate_ignore_db Last_errno Last_error Skip_counter Last_log_seq
11-
127.0.0.1 root $MASTER_MYPORT 1 master-bin.001 79 Yes 0 0 1
10+
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 Last_errno Last_error Skip_counter Exec_master_log_pos
11+
127.0.0.1 root 9306 1 master-bin.001 79 mysql-relay-bin.002 120 master-bin.001 Yes Yes 0 0 79
1212
change master to master_log_pos=73;
1313
slave stop;
1414
change master to master_log_pos=73;
1515
show slave status;
16-
Master_Host Master_User Master_Port Connect_retry Log_File Pos Slave_Running Replicate_do_db Replicate_ignore_db Last_errno Last_error Skip_counter Last_log_seq
17-
127.0.0.1 root $MASTER_MYPORT 1 master-bin.001 73 No 0 0 1
16+
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 Last_errno Last_error Skip_counter Exec_master_log_pos
17+
127.0.0.1 root 9306 1 master-bin.001 73 mysql-relay-bin.001 4 master-bin.001 No No 0 0 73
1818
slave start;
1919
show slave status;
20-
Master_Host Master_User Master_Port Connect_retry Log_File Pos Slave_Running Replicate_do_db Replicate_ignore_db Last_errno Last_error Skip_counter Last_log_seq
21-
127.0.0.1 root $MASTER_MYPORT 1 master-bin.001 73 Yes 0 0 1
20+
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 Last_errno Last_error Skip_counter Exec_master_log_pos
21+
127.0.0.1 root 9306 1 master-bin.001 73 mysql-relay-bin.001 4 master-bin.001 Yes Yes 0 0 73
2222
change master to master_log_pos=173;
2323
show slave status;
24-
Master_Host Master_User Master_Port Connect_retry Log_File Pos Slave_Running Replicate_do_db Replicate_ignore_db Last_errno Last_error Skip_counter Last_log_seq
25-
127.0.0.1 root $MASTER_MYPORT 1 master-bin.001 173 Yes 0 0 1
24+
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 Last_errno Last_error Skip_counter Exec_master_log_pos
25+
127.0.0.1 root 9306 1 master-bin.001 173 mysql-relay-bin.001 4 master-bin.001 Yes Yes 0 0 173
2626
show master status;
2727
File Position Binlog_do_db Binlog_ignore_db
2828
master-bin.001 79

mysql-test/r/rpl000015.result

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,21 @@ File Position Binlog_do_db Binlog_ignore_db
44
master-bin.001 79
55
reset slave;
66
show slave status;
7-
Master_Host Master_User Master_Port Connect_retry Log_File Pos Slave_Running Replicate_do_db Replicate_ignore_db Last_errno Last_error Skip_counter Last_log_seq
8-
0 0 0 No 0 0 0
7+
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 Last_errno Last_error Skip_counter Exec_master_log_pos
8+
0 0 0 0 No No 0 0 0
99
change master to master_host='127.0.0.1';
1010
show slave status;
11-
Master_Host Master_User Master_Port Connect_retry Log_File Pos Slave_Running Replicate_do_db Replicate_ignore_db Last_errno Last_error Skip_counter Last_log_seq
12-
127.0.0.1 test 3306 60 4 No 0 0 0
11+
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 Last_errno Last_error Skip_counter Exec_master_log_pos
12+
127.0.0.1 test 3306 60 4 mysql-relay-bin.001 4 No No 0 0 0
1313
change master to master_host='127.0.0.1',master_user='root',
1414
master_password='',master_port=9306;
1515
show slave status;
16-
Master_Host Master_User Master_Port Connect_retry Log_File Pos Slave_Running Replicate_do_db Replicate_ignore_db Last_errno Last_error Skip_counter Last_log_seq
17-
127.0.0.1 root 9306 60 4 No 0 0 0
16+
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 Last_errno Last_error Skip_counter Exec_master_log_pos
17+
127.0.0.1 root 9306 60 4 mysql-relay-bin.001 4 No No 0 0 0
1818
slave start;
1919
show slave status;
20-
Master_Host Master_User Master_Port Connect_retry Log_File Pos Slave_Running Replicate_do_db Replicate_ignore_db Last_errno Last_error Skip_counter Last_log_seq
21-
127.0.0.1 root 9306 60 master-bin.001 79 Yes 0 0 1
20+
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 Last_errno Last_error Skip_counter Exec_master_log_pos
21+
127.0.0.1 root 9306 60 master-bin.001 79 mysql-relay-bin.001 120 master-bin.001 Yes Yes 0 0 79
2222
drop table if exists t1;
2323
create table t1 (n int);
2424
insert into t1 values (10),(45),(90);

mysql-test/r/rpl000016.result

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ drop table if exists t1;
1414
create table t1 (s text);
1515
insert into t1 values('Could not break slave'),('Tried hard');
1616
show slave status;
17-
Master_Host Master_User Master_Port Connect_retry Log_File Pos Slave_Running Replicate_do_db Replicate_ignore_db Last_errno Last_error Skip_counter Last_log_seq
18-
127.0.0.1 root 9306 60 master-bin.001 234 Yes 0 0 3
17+
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 Last_errno Last_error Skip_counter Exec_master_log_pos
18+
127.0.0.1 root 9306 60 master-bin.001 234 mysql-relay-bin.001 275 master-bin.001 Yes Yes 0 0 234
1919
select * from t1;
2020
s
2121
Could not break slave
@@ -42,8 +42,8 @@ Log_name
4242
master-bin.003
4343
insert into t2 values (65);
4444
show slave status;
45-
Master_Host Master_User Master_Port Connect_retry Log_File Pos Slave_Running Replicate_do_db Replicate_ignore_db Last_errno Last_error Skip_counter Last_log_seq
46-
127.0.0.1 root 9306 60 master-bin.003 155 Yes 0 0 3
45+
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 Last_errno Last_error Skip_counter Exec_master_log_pos
46+
127.0.0.1 root 9306 60 master-bin.003 155 mysql-relay-bin.001 793 master-bin.003 Yes Yes 0 0 155
4747
select * from t2;
4848
m
4949
34
@@ -65,8 +65,8 @@ master-bin.006 445
6565
slave stop;
6666
slave start;
6767
show slave status;
68-
Master_Host Master_User Master_Port Connect_retry Log_File Pos Slave_Running Replicate_do_db Replicate_ignore_db Last_errno Last_error Skip_counter Last_log_seq
69-
127.0.0.1 root 9306 60 master-bin.006 445 Yes 0 0 7
68+
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 Last_errno Last_error Skip_counter Exec_master_log_pos
69+
127.0.0.1 root 9306 60 master-bin.006 445 mysql-relay-bin.004 1376 master-bin.006 Yes Yes 0 0 445
7070
lock tables t3 read;
7171
select count(*) from t3 where n >= 4;
7272
count(*)

0 commit comments

Comments
 (0)