forked from bluethinking/InnoSQL
-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathbatch_commit.patch
More file actions
3690 lines (3613 loc) · 117 KB
/
batch_commit.patch
File metadata and controls
3690 lines (3613 loc) · 117 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Index: mysql-test/suite/innosql/r/rpl_batch_commit.result
===================================================================
--- mysql-test/suite/innosql/r/rpl_batch_commit.result (.../mysql-5.5.20_relay.info_table) (revision 0)
+++ mysql-test/suite/innosql/r/rpl_batch_commit.result (.../mysql-5.5.20.batch_commit) (revision 632)
@@ -0,0 +1,96 @@
+include/master-slave.inc
+[connection master]
+"-----------batch Query commit-------------"
+create table t(a int);
+set global batch_commit_max=3;
+set global debug="+d,skip_relay_end";
+insert into t select 1;
+insert into t select 2;
+include/wait_for_slave_param.inc [Read_Master_Log_Pos]
+ok
+insert into t select 3;
+select * from t;
+a
+1
+2
+3
+set global debug="";
+delete from t;
+"-----------batch Xid commit-------------"
+"-----rotate change master log file-----"
+stop slave SQL_THREAD;
+include/wait_for_slave_sql_to_stop.inc
+set global batch_commit_max=4;
+use test;
+insert into t select 6;
+insert into t select 7;
+flush logs;
+start slave SQL_THREAD;
+include/wait_for_slave_sql_to_start.inc
+select a from t;
+a
+6
+7
+ok
+delete from t;
+stop slave SQL_THREAD;
+include/wait_for_slave_sql_to_stop.inc
+set global batch_commit_max=4;
+use test;
+insert into t select 8;
+insert into t select 9;
+flush logs;
+insert into t select 10;
+insert into t select 11;
+start slave SQL_THREAD;
+include/wait_for_slave_sql_to_start.inc
+select a from t;
+a
+8
+9
+10
+11
+ok
+delete from t;
+"---------reach_relay_log_end------------"
+stop slave;
+include/wait_for_slave_to_stop.inc
+set global batch_commit_max=10;
+use test;
+insert into t select 4;
+flush logs;
+start slave;
+include/wait_for_slave_to_start.inc
+use test;
+select a from t;
+a
+4
+stop slave;
+include/wait_for_slave_to_stop.inc
+use test;
+create table t1(c int);
+flush logs;
+start slave;
+include/wait_for_slave_to_start.inc
+use test;
+show tables;
+Tables_in_test
+t
+t1
+drop table t1;
+stop slave SQL_THREAD;
+include/wait_for_slave_sql_to_stop.inc
+use test;
+insert into t select 5;
+include/wait_for_slave_param.inc [Read_Master_Log_Pos]
+flush relay logs;
+start slave SQL_THREAD;
+include/wait_for_slave_sql_to_start.inc
+select a from t;
+a
+4
+5
+"-----------------clean-----------------"
+drop table t;
+set global batch_commit_max=1;
+include/rpl_end.inc
Index: mysql-test/suite/innosql/t/rpl_batch_commit-slave.opt
===================================================================
--- mysql-test/suite/innosql/t/rpl_batch_commit-slave.opt (.../mysql-5.5.20_relay.info_table) (revision 0)
+++ mysql-test/suite/innosql/t/rpl_batch_commit-slave.opt (.../mysql-5.5.20.batch_commit) (revision 632)
@@ -0,0 +1 @@
+--enable-table-relay-info
Index: mysql-test/suite/innosql/t/rpl_batch_commit.test
===================================================================
--- mysql-test/suite/innosql/t/rpl_batch_commit.test (.../mysql-5.5.20_relay.info_table) (revision 0)
+++ mysql-test/suite/innosql/t/rpl_batch_commit.test (.../mysql-5.5.20.batch_commit) (revision 632)
@@ -0,0 +1,158 @@
+--source include/master-slave.inc
+echo "-----------batch Query commit-------------";
+connection master;
+create table t(a int);
+sync_slave_with_master;
+connection slave;
+let $old_value = query_get_value("select @@batch_commit_max",@@batch_commit_max,1);
+set global batch_commit_max=3;
+set global debug="+d,skip_relay_end";
+connection master;
+let $master_pos1= query_get_value("show master status",Position,1);
+insert into t select 1;
+insert into t select 2;
+let $master_pos2= query_get_value("show master status",Position,1);
+connection slave;
+let $slave_param=Read_Master_Log_Pos;
+let $slave_param_value=$master_pos2;
+source include/wait_for_slave_param.inc;
+let $relay_master_pos= query_get_value("show slave status",Exec_Master_Log_Pos,1);
+if($master_pos1==$relay_master_pos)
+{
+ echo ok;
+}
+
+connection master;
+insert into t select 3;
+sync_slave_with_master;
+select * from t;
+
+set global debug="";
+connection master;
+delete from t;
+sync_slave_with_master;
+echo "-----------batch Xid commit-------------";
+
+echo "-----rotate change master log file-----";
+connection slave;
+stop slave SQL_THREAD;
+source include/wait_for_slave_sql_to_stop.inc;
+set global batch_commit_max=4;
+connection master;
+use test;
+insert into t select 6;
+insert into t select 7;
+flush logs;
+let $master_log_file= query_get_value("show master status",File,1);
+connection slave;
+start slave SQL_THREAD;
+source include/wait_for_slave_sql_to_start.inc;
+connection master;
+sync_slave_with_master;
+select a from t;
+replace_regex /^\s*// /$\s*//;
+let $exc_master_log_file= query_get_value("show slave status",Relay_Master_Log_File,1);
+if($master_log_file==$exc_master_log_file)
+{
+ echo ok;
+}
+if($master_log_file!=$exc_master_log_file)
+{
+ echo wrong;
+}
+connection master;
+delete from t;
+sync_slave_with_master;
+
+connection slave;
+stop slave SQL_THREAD;
+source include/wait_for_slave_sql_to_stop.inc;
+set global batch_commit_max=4;
+connection master;
+use test;
+insert into t select 8;
+insert into t select 9;
+flush logs;
+insert into t select 10;
+insert into t select 11;
+let $master_log_file= query_get_value("show master status",File,1);
+connection slave;
+start slave SQL_THREAD;
+source include/wait_for_slave_sql_to_start.inc;
+connection master;
+sync_slave_with_master;
+select a from t;
+let $exc_master_log_file= query_get_value("show slave status",Relay_Master_Log_File,1);
+if($master_log_file==$exc_master_log_file)
+{
+ echo ok;
+}
+if($master_log_file!=$exc_master_log_file)
+{
+ echo wrong;
+}
+connection master;
+delete from t;
+sync_slave_with_master;
+
+echo "---------reach_relay_log_end------------";
+connection slave;
+stop slave;
+source include/wait_for_slave_to_stop.inc;
+set global batch_commit_max=10;
+
+connection master;
+use test;
+insert into t select 4;
+flush logs;
+connection slave;
+start slave;
+source include/wait_for_slave_to_start.inc;
+connection master;
+sync_slave_with_master;
+use test;
+select a from t;
+
+connection slave;
+stop slave;
+source include/wait_for_slave_to_stop.inc;
+connection master;
+use test;
+create table t1(c int);
+flush logs;
+connection slave;
+start slave;
+source include/wait_for_slave_to_start.inc;
+connection master;
+sync_slave_with_master;
+use test;
+show tables;
+connection master;
+drop table t1;
+sync_slave_with_master;
+
+connection slave;
+stop slave SQL_THREAD;
+source include/wait_for_slave_sql_to_stop.inc;
+connection master;
+use test;
+insert into t select 5;
+let $file_pos= query_get_value("show master status",Position,1);
+connection slave;
+let $slave_param=Read_Master_Log_Pos;
+let $slave_param_value=$file_pos;
+source include/wait_for_slave_param.inc;
+flush relay logs;
+start slave SQL_THREAD;
+source include/wait_for_slave_sql_to_start.inc;
+connection master;
+sync_slave_with_master;
+select a from t;
+
+echo "-----------------clean-----------------";
+connection master;
+drop table t;
+sync_slave_with_master;
+let $error = query_get_value("show slave status",Last_SQL_Error,1);
+eval set global batch_commit_max=$old_value;
+--source include/rpl_end.inc
Index: mysql-test/suite/sys_vars/r/batch_commit_max_basic.result
===================================================================
--- mysql-test/suite/sys_vars/r/batch_commit_max_basic.result (.../mysql-5.5.20_relay.info_table) (revision 0)
+++ mysql-test/suite/sys_vars/r/batch_commit_max_basic.result (.../mysql-5.5.20.batch_commit) (revision 632)
@@ -0,0 +1,3 @@
+select @@global.batch_commit_max;
+@@global.batch_commit_max
+1
Index: mysql-test/suite/sys_vars/r/enable_table_relay_info_basic.result
===================================================================
--- mysql-test/suite/sys_vars/r/enable_table_relay_info_basic.result (.../mysql-5.5.20_relay.info_table) (revision 0)
+++ mysql-test/suite/sys_vars/r/enable_table_relay_info_basic.result (.../mysql-5.5.20.batch_commit) (revision 632)
@@ -0,0 +1,6 @@
+select @@global.enable_table_relay_info;
+@@global.enable_table_relay_info
+0
+"--------------read only-------------"
+--error ER_INCORRECT_GLOBAL_LOCAL_VAR
+set global.enable_table_relay_info=1
Index: mysql-test/suite/sys_vars/t/enable_table_relay_info_basic.test
===================================================================
--- mysql-test/suite/sys_vars/t/enable_table_relay_info_basic.test (.../mysql-5.5.20_relay.info_table) (revision 0)
+++ mysql-test/suite/sys_vars/t/enable_table_relay_info_basic.test (.../mysql-5.5.20.batch_commit) (revision 632)
@@ -0,0 +1,6 @@
+
+select @@global.enable_table_relay_info;
+
+echo "--------------read only-------------"
+--error ER_INCORRECT_GLOBAL_LOCAL_VAR
+set global.enable_table_relay_info=1;
Index: mysql-test/suite/sys_vars/t/batch_commit_max_basic.test
===================================================================
--- mysql-test/suite/sys_vars/t/batch_commit_max_basic.test (.../mysql-5.5.20_relay.info_table) (revision 0)
+++ mysql-test/suite/sys_vars/t/batch_commit_max_basic.test (.../mysql-5.5.20.batch_commit) (revision 632)
@@ -0,0 +1,2 @@
+
+select @@global.batch_commit_max;
Index: mysql-test/mysql-test-run.pl
===================================================================
--- mysql-test/mysql-test-run.pl (.../mysql-5.5.20_relay.info_table) (revision 493)
+++ mysql-test/mysql-test-run.pl (.../mysql-5.5.20.batch_commit) (revision 632)
@@ -163,7 +163,7 @@
# If you add a new suite, please check TEST_DIRS in Makefile.am.
#
-my $DEFAULT_SUITES= "main,sys_vars,binlog,federated,rpl,innodb,perfschema";
+my $DEFAULT_SUITES= "main,sys_vars,binlog,federated,rpl,innodb,perfschema,innosql";
my $opt_suites;
our $opt_verbose= 0; # Verbose output, enable with --verbose
Index: mysys/array.c
===================================================================
--- mysys/array.c (.../mysql-5.5.20_relay.info_table) (revision 493)
+++ mysys/array.c (.../mysql-5.5.20.batch_commit) (revision 632)
@@ -92,7 +92,7 @@
FALSE Ok
*/
-my_bool insert_dynamic(DYNAMIC_ARRAY *array, uchar* element)
+my_bool insert_dynamic(DYNAMIC_ARRAY *array, const void *element)
{
uchar* buffer;
if (array->elements == array->max_element)
Index: scripts/mysql_system_tables.sql
===================================================================
--- scripts/mysql_system_tables.sql (.../mysql-5.5.20_relay.info_table) (revision 493)
+++ scripts/mysql_system_tables.sql (.../mysql-5.5.20.batch_commit) (revision 632)
@@ -100,6 +100,7 @@
CREATE TABLE IF NOT EXISTS ndb_binlog_index (Position BIGINT UNSIGNED NOT NULL, File VARCHAR(255) NOT NULL, epoch BIGINT UNSIGNED NOT NULL, inserts BIGINT UNSIGNED NOT NULL, updates BIGINT UNSIGNED NOT NULL, deletes BIGINT UNSIGNED NOT NULL, schemaops BIGINT UNSIGNED NOT NULL, PRIMARY KEY(epoch)) ENGINE=MYISAM;
+CREATE TABLE IF NOT EXISTS slave_relay_log_info (key_id INTEGER UNSIGNED NOT NULL, Number_of_lines INTEGER UNSIGNED NOT NULL, Relay_log_name TEXT CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, Relay_log_pos BIGINT UNSIGNED NOT NULL, Master_log_name TEXT CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, Master_log_pos BIGINT UNSIGNED NOT NULL, PRIMARY KEY(key_id)) ENGINE=INNODB DEFAULT CHARSET=utf8 COMMENT 'Relay Log Information';
--
-- PERFORMANCE SCHEMA INSTALLATION
-- Note that this script is also reused by mysql_upgrade,
Index: scripts/mysql_install_db.sh
===================================================================
--- scripts/mysql_install_db.sh (.../mysql-5.5.20_relay.info_table) (revision 493)
+++ scripts/mysql_install_db.sh (.../mysql-5.5.20.batch_commit) (revision 632)
@@ -394,7 +394,7 @@
# Configure mysqld command line
mysqld_bootstrap="${MYSQLD_BOOTSTRAP-$mysqld}"
mysqld_install_cmd_line="$mysqld_bootstrap $defaults $mysqld_opt --bootstrap \
- --basedir=$basedir --datadir=$ldata --log-warnings=0 --loose-skip-innodb \
+ --basedir=$basedir --datadir=$ldata --log-warnings=0 \
--loose-skip-ndbcluster $args --max_allowed_packet=8M \
--default-storage-engine=myisam \
--net_buffer_length=16K"
Index: storage/innobase/handler/ha_innodb.cc
===================================================================
--- storage/innobase/handler/ha_innodb.cc (.../mysql-5.5.20_relay.info_table) (revision 493)
+++ storage/innobase/handler/ha_innodb.cc (.../mysql-5.5.20.batch_commit) (revision 632)
@@ -2765,7 +2765,7 @@
/* We were instructed to commit the whole transaction, or
this is an SQL statement end and autocommit is on */
-
+ DBUG_PRINT("rlh",("do transaction commit"));
/* We need current binlog position for ibbackup to work.
Note, the position is current because of
prepare_commit_mutex */
@@ -2825,10 +2825,10 @@
/* Now do a write + flush of logs. */
trx_commit_complete_for_mysql(trx);
- } else {
+ } else {
/* We just mark the SQL statement ended and do not do a
transaction commit */
-
+ DBUG_PRINT("rlh",("mark sql ended"));
/* If we had reserved the auto-inc lock for some
table in this SQL statement we release it now */
@@ -10377,17 +10377,17 @@
XID* xid) /*!< in: X/Open XA transaction identification */
{
trx_t* trx;
-
+ DBUG_ENTER("innobase_commit_by_xid");
DBUG_ASSERT(hton == innodb_hton_ptr);
-
+ DBUG_PRINT("rlh",("innobase_commit_by_xid"));
trx = trx_get_trx_by_xid(xid);
if (trx) {
innobase_commit_low(trx);
trx_free_for_background(trx);
- return(XA_OK);
+ DBUG_RETURN(XA_OK);
} else {
- return(XAER_NOTA);
+ DBUG_RETURN(XAER_NOTA);
}
}
Index: include/my_sys.h
===================================================================
--- include/my_sys.h (.../mysql-5.5.20_relay.info_table) (revision 493)
+++ include/my_sys.h (.../mysql-5.5.20.batch_commit) (revision 632)
@@ -763,7 +763,7 @@
/* init_dynamic_array() function is deprecated */
extern my_bool init_dynamic_array(DYNAMIC_ARRAY *array, uint element_size,
uint init_alloc, uint alloc_increment);
-extern my_bool insert_dynamic(DYNAMIC_ARRAY *array,uchar * element);
+extern my_bool insert_dynamic(DYNAMIC_ARRAY *array,const void * element);
extern uchar *alloc_dynamic(DYNAMIC_ARRAY *array);
extern uchar *pop_dynamic(DYNAMIC_ARRAY*);
extern my_bool set_dynamic(DYNAMIC_ARRAY *array,uchar * element,uint array_index);
Index: sql/slave.cc
===================================================================
--- sql/slave.cc (.../mysql-5.5.20_relay.info_table) (revision 493)
+++ sql/slave.cc (.../mysql-5.5.20.batch_commit) (revision 632)
@@ -52,6 +52,7 @@
// Create_file_log_event,
// Format_description_log_event
+#include "server_ids.h"
#ifdef HAVE_REPLICATION
#include "rpl_tblmap.h"
@@ -522,10 +523,13 @@
thd_proc_info(current_thd, "Flushing relay-log info file.");
if (flush_relay_log_info(&mi->rli))
DBUG_RETURN(ER_ERROR_DURING_FLUSH_LOGS);
-
- if (my_sync(mi->rli.info_fd, MYF(MY_WME)))
- DBUG_RETURN(ER_ERROR_DURING_FLUSH_LOGS);
-
+
+ if (mi->rli.info_fd >= 0)
+ {
+ if (my_sync(mi->rli.info_fd, MYF(MY_WME)))
+ DBUG_RETURN(ER_ERROR_DURING_FLUSH_LOGS);
+ }
+
mysql_mutex_unlock(log_lock);
}
if (thread_mask & (SLAVE_IO|SLAVE_FORCE_ALL))
@@ -2293,6 +2297,7 @@
int apply_event_and_update_pos(Log_event* ev, THD* thd, Relay_log_info* rli)
{
int exec_res= 0;
+ bool no_skip_event= true;
DBUG_ENTER("apply_event_and_update_pos");
@@ -2337,10 +2342,15 @@
int reason= ev->shall_skip(rli);
if (reason == Log_event::EVENT_SKIP_COUNT)
- sql_slave_skip_counter= --rli->slave_skip_counter;
+ {
+ sql_slave_skip_counter= --rli->slave_skip_counter;
+ no_skip_event=false;
+ }
mysql_mutex_unlock(&rli->data_lock);
if (reason == Log_event::EVENT_SKIP_NOT)
- exec_res= ev->apply_event(rli);
+ {
+ DBUG_PRINT("rlh",("%s",ev->get_type_str()));
+ exec_res= ev->apply_event(rli);}
#ifndef DBUG_OFF
/*
@@ -2366,7 +2376,10 @@
DBUG_PRINT("info", ("apply_event error = %d", exec_res));
if (exec_res == 0)
{
- int error= ev->update_pos(rli);
+ int error= 0;
+ if(!(ev->get_type_code()==XID_EVENT &&
+ rli->is_transactional() && no_skip_event))
+ error = ev->update_pos(rli);
#ifdef HAVE_purify
if (!rli->is_fake)
#endif
@@ -3870,6 +3883,17 @@
mysql_mutex_lock(&mi->data_lock);
switch (buf[EVENT_TYPE_OFFSET]) {
+ /*
+ record newest commit position in master binlog
+ */
+ case QUERY_EVENT:
+ case XID_EVENT:
+ {
+ mi->master_last_commit_pos =(my_off_t)uint4korr(buf + LOG_POS_OFFSET);
+ DBUG_PRINT("cccc",("master_last_commit_Pos:%lld",mi->master_last_commit_pos));
+ inc_pos= event_len;
+ break;
+ }
case STOP_EVENT:
/*
We needn't write this event to the relay log. Indeed, it just indicates a
@@ -4205,8 +4229,8 @@
mysql_options(mysql, MYSQL_SET_CHARSET_DIR, (char *) charsets_dir);
/* Set MYSQL_PLUGIN_DIR in case master asks for an external authentication plugin */
- if (opt_plugin_dir_ptr && *opt_plugin_dir_ptr)
- mysql_options(mysql, MYSQL_PLUGIN_DIR, opt_plugin_dir_ptr);
+ if (opt_plugin_dir_ptr && *opt_plugin_dir_ptr)
+ mysql_options(mysql, MYSQL_PLUGIN_DIR, opt_plugin_dir_ptr);
/* we disallow empty users */
if (mi->user == NULL || mi->user[0] == 0)
@@ -4395,44 +4419,12 @@
bool flush_relay_log_info(Relay_log_info* rli)
{
- bool error=0;
DBUG_ENTER("flush_relay_log_info");
- if (unlikely(rli->no_storage))
- DBUG_RETURN(0);
-
- IO_CACHE *file = &rli->info_file;
- char buff[FN_REFLEN*2+22*2+4], *pos;
-
- my_b_seek(file, 0L);
- pos=strmov(buff, rli->group_relay_log_name);
- *pos++='\n';
- pos=longlong2str(rli->group_relay_log_pos, pos, 10);
- *pos++='\n';
- pos=strmov(pos, rli->group_master_log_name);
- *pos++='\n';
- pos=longlong2str(rli->group_master_log_pos, pos, 10);
- *pos='\n';
- if (my_b_write(file, (uchar*) buff, (size_t) (pos-buff)+1))
- error=1;
- if (flush_io_cache(file))
- error=1;
- if (sync_relayloginfo_period &&
- !error &&
- ++(rli->sync_counter) >= sync_relayloginfo_period)
- {
- if (my_sync(rli->info_fd, MYF(MY_WME)))
- error=1;
- rli->sync_counter= 0;
- }
- /*
- Flushing the relay log is done by the slave I/O thread
- or by the user on STOP SLAVE.
- */
+ bool error=rli->flush_info();
DBUG_RETURN(error);
}
-
/*
Called when we notice that the current "hot" log got rotated under our feet.
*/
@@ -5037,3 +5029,61 @@
*/
#endif /* HAVE_REPLICATION */
+
+Server_ids::Server_ids()
+{
+ my_init_dynamic_array(&server_ids, sizeof(::server_id), 16, 16);
+}
+
+Server_ids::~Server_ids()
+{
+ delete_dynamic(&server_ids);
+}
+
+bool Server_ids::unpack_server_ids(char *param_server_ids)
+{
+ char *token= NULL, *last= NULL;
+ uint num_items= 0;
+
+ DBUG_ENTER("Server_ids::unpack_server_ids");
+
+ token= strtok_r((char *)const_cast<const char*>(param_server_ids),
+ " ", &last);
+
+ if (token == NULL)
+ DBUG_RETURN(TRUE);
+
+ num_items= atoi(token);
+ for (uint i=0; i < num_items; i++)
+ {
+ token= strtok_r(NULL, " ", &last);
+ if (token == NULL)
+ DBUG_RETURN(TRUE);
+ else
+ {
+ ulong val= atol(token);
+ insert_dynamic(&server_ids, &val);
+ }
+ }
+ DBUG_RETURN(FALSE);
+}
+
+bool Server_ids::pack_server_ids(String *buffer)
+{
+ DBUG_ENTER("Server_ids::pack_server_ids");
+
+ if (buffer->set_int(server_ids.elements, FALSE, &my_charset_bin))
+ DBUG_RETURN(TRUE);
+
+ for (ulong i= 0;
+ i < server_ids.elements; i++)
+ {
+ ulong s_id;
+ get_dynamic(&server_ids, (uchar*) &s_id, i);
+ if (buffer->append(" ") ||
+ buffer->append_ulonglong(s_id))
+ DBUG_RETURN(TRUE);
+ }
+
+ DBUG_RETURN(FALSE);
+}
Index: sql/sql_parse.h
===================================================================
--- sql/sql_parse.h (.../mysql-5.5.20_relay.info_table) (revision 493)
+++ sql/sql_parse.h (.../mysql-5.5.20.batch_commit) (revision 632)
@@ -81,6 +81,7 @@
bool sqlcom_can_generate_row_events(const THD *thd);
bool is_update_query(enum enum_sql_command command);
bool is_log_table_write_query(enum enum_sql_command command);
+bool is_rpl_info_table_write_query(enum enum_sql_command command);
bool alloc_query(THD *thd, const char *packet, uint packet_length);
void mysql_init_select(LEX *lex);
void mysql_parse(THD *thd, char *rawbuf, uint length,
Index: sql/rpl_info_table_access.h
===================================================================
--- sql/rpl_info_table_access.h (.../mysql-5.5.20_relay.info_table) (revision 0)
+++ sql/rpl_info_table_access.h (.../mysql-5.5.20.batch_commit) (revision 632)
@@ -0,0 +1,57 @@
+/* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; version 2 of the License.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+#ifndef RPL_INFO_TABLE_ACCESS_H
+#define RPL_INFO_TABLE_ACCESS_H
+
+#include "my_global.h"
+#include "sql_priv.h"
+#include <table.h>
+#include <key.h>
+#include <sql_base.h>
+#include "rpl_info_handler.h"
+#include "rpl_info_values.h"
+
+#define FOUND_ID 1
+#define NOT_FOUND_ID 2
+#define ERROR_ID 3
+
+class Rpl_info_table_access
+{
+public:
+ Rpl_info_table_access() { };
+ virtual ~Rpl_info_table_access() { };
+
+ bool open_table(THD* thd, const LEX_STRING dbstr, const LEX_STRING tbstr,
+ uint max_num_field, enum thr_lock_type lock_type,
+ TABLE** table, Open_tables_backup* backup);
+ bool close_table(THD* thd, TABLE* table, Open_tables_backup* backup,
+ bool error);
+ int find_info_for_server_id(ulong server_id, uint idx, Rpl_info_values *,
+ TABLE *table);
+ bool load_info_values(uint max_num_field, Field **fields,
+ Rpl_info_values *field_values);
+ bool store_info_values(uint max_num_field, Field **fields,
+ Rpl_info_values *field_values);
+ THD *create_thd();
+ bool drop_thd(THD* thd);
+
+private:
+ THD *saved_current_thd;
+
+ Rpl_info_table_access& operator=(const Rpl_info_table_access& info);
+ Rpl_info_table_access(const Rpl_info_table_access& info);
+};
+
+#endif /* RPL_INFO_TABLE_ACCESS_H */
Index: sql/sql_class.h
===================================================================
--- sql/sql_class.h (.../mysql-5.5.20_relay.info_table) (revision 493)
+++ sql/sql_class.h (.../mysql-5.5.20.batch_commit) (revision 632)
@@ -3610,6 +3610,11 @@
*/
#define CF_CAN_GENERATE_ROW_EVENTS (1U << 9)
+/**
+ Identifies statements that can directly update a rpl info table.
+*/
+#define CF_WRITE_RPL_INFO_COMMAND (1U << 12)
+
/* Bits in server_command_flags */
/**
Index: sql/table.cc
===================================================================
--- sql/table.cc (.../mysql-5.5.20_relay.info_table) (revision 493)
+++ sql/table.cc (.../mysql-5.5.20.batch_commit) (revision 632)
@@ -52,6 +52,10 @@
/* SLOW_LOG name */
LEX_STRING SLOW_LOG_NAME= {C_STRING_WITH_LEN("slow_log")};
+/* RLI_INFO name */
+LEX_STRING RLI_INFO_NAME= {C_STRING_WITH_LEN("slave_relay_log_info")};
+
+
/* Functions defined in this file */
void open_table_error(TABLE_SHARE *share, int error, int db_errno,
@@ -261,6 +265,12 @@
SLOW_LOG_NAME.str,
name->str) == 0))
return TABLE_CATEGORY_LOG;
+
+ if ((name->length == RLI_INFO_NAME.length) &&
+ (my_strcasecmp(system_charset_info,
+ RLI_INFO_NAME.str,
+ name->str) == 0))
+ return TABLE_CATEGORY_RPL_INFO;
}
return TABLE_CATEGORY_USER;
Index: sql/rpl_info_values.cc
===================================================================
--- sql/rpl_info_values.cc (.../mysql-5.5.20_relay.info_table) (revision 0)
+++ sql/rpl_info_values.cc (.../mysql-5.5.20.batch_commit) (revision 632)
@@ -0,0 +1,46 @@
+/* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; version 2 of the License.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+#include "rpl_info_values.h"
+
+Rpl_info_values::Rpl_info_values(int param_ninfo): value(0),
+ ninfo(param_ninfo) { }
+
+/**
+ Initializes a sequence of values to be read from or stored into a repository.
+ The number of values created and initialized are determined by the property
+ @c ninfo which is set while calling the constructor. Each value is created
+ with the default size of @c FN_REFLEN.
+
+ @retval FALSE No error
+ @retval TRUE Failure
+*/
+bool Rpl_info_values::init()
+{
+ DBUG_ENTER("Rpl_info_values::init");
+
+ if (!value && !(value= new String[ninfo]))
+ DBUG_RETURN(TRUE);
+
+ DBUG_RETURN(FALSE);
+}
+
+Rpl_info_values::~Rpl_info_values()
+{
+ for (int pos= 0; pos < ninfo; pos++)
+ value[pos].~String();
+
+ delete [] value;
+}
Index: sql/rpl_rli.cc
===================================================================
--- sql/rpl_rli.cc (.../mysql-5.5.20_relay.info_table) (revision 493)
+++ sql/rpl_rli.cc (.../mysql-5.5.20.batch_commit) (revision 632)
@@ -28,7 +28,19 @@
#include "sql_parse.h" // end_trans, ROLLBACK
#include <mysql/plugin.h>
#include <mysql/service_thd_wait.h>
+#include "rpl_info_table.h"
+#include "rpl_info_fake.h"
+const char* info_rli_fields[]=
+{
+ "number_of_lines",
+ "group_relay_log_name",
+ "group_relay_log_pos",
+ "group_master_log_name",
+ "group_master_log_pos",
+};
+my_bool opt_enable_table_relay_info = 0;
+
static int count_relay_log_space(Relay_log_info* rli);
// Defined in slave.cc
@@ -66,6 +78,7 @@
group_relay_log_name[0]= event_relay_log_name[0]=
group_master_log_name[0]= 0;
+ tmp_group_master_log_name[0]= 0;
until_log_name[0]= ign_master_log_name_end[0]= 0;
bzero((char*) &info_file, sizeof(info_file));
bzero((char*) &cache_buf, sizeof(cache_buf));
@@ -80,6 +93,15 @@
mysql_cond_init(key_relay_log_info_stop_cond, &stop_cond, NULL);
mysql_cond_init(key_relay_log_info_log_space_cond, &log_space_cond, NULL);
relay_log.init_pthread_objects();
+ if(opt_enable_table_relay_info)
+ {
+ handler= new Rpl_info_table((uint)(get_number_info_rli_fields() + 1),
+ RLI_FIELD_ID, RLI_SCHEMA, RLI_TABLE);
+ }
+ else
+ {
+ handler= new Rpl_info_fake();
+ }
DBUG_VOID_RETURN;
}
@@ -87,7 +109,7 @@
Relay_log_info::~Relay_log_info()
{
DBUG_ENTER("Relay_log_info::~Relay_log_info");
-
+ delete handler;
mysql_mutex_destroy(&run_lock);
mysql_mutex_destroy(&data_lock);
mysql_mutex_destroy(&log_space_lock);
@@ -99,12 +121,9 @@
DBUG_VOID_RETURN;
}
-
int init_relay_log_info(Relay_log_info* rli,
const char* info_fname)
{
- char fname[FN_REFLEN+128];
- int info_fd;
const char* msg = 0;
int error = 0;
DBUG_ENTER("init_relay_log_info");
@@ -112,9 +131,7 @@
if (rli->inited) // Set if this function called
DBUG_RETURN(0);
- fn_format(fname, info_fname, mysql_data_home, "", 4+32);
mysql_mutex_lock(&rli->data_lock);
- info_fd = rli->info_fd;
rli->cur_log_fd = -1;
rli->slave_skip_counter=0;
rli->abort_pos_wait=0;
@@ -122,8 +139,7 @@
rli->log_space_total= 0;
rli->tables_to_lock= 0;
rli->tables_to_lock_count= 0;
-
- char pattern[FN_REFLEN];
+ char pattern[FN_REFLEN];
(void) my_realpath(pattern, slave_load_tmpdir, 0);
if (fn_format(pattern, PREFIX_SQL_LOAD, pattern, "",
MY_SAFE_PATH | MY_RETURN_REAL_PATH) == NullS)
@@ -213,124 +229,24 @@
rli->relay_log.is_relay_log= TRUE;
}
- /* if file does not exist */
- if (access(fname,F_OK))
+ if(!opt_enable_table_relay_info)
{
- /*
- If someone removed the file from underneath our feet, just close
- the old descriptor and re-create the old file
- */
- if (info_fd >= 0)
- mysql_file_close(info_fd, MYF(MY_WME));
- if ((info_fd= mysql_file_open(key_file_relay_log_info,
- fname, O_CREAT|O_RDWR|O_BINARY, MYF(MY_WME))) < 0)
- {
- sql_print_error("Failed to create a new relay log info file (\
-file '%s', errno %d)", fname, my_errno);
- msg= current_thd->stmt_da->message();
+ if (rli->read_file_info(info_fname))
+ {
+ msg= "Error reading relay log configuration";
+ error= 1;
goto err;
}
- if (init_io_cache(&rli->info_file, info_fd, IO_SIZE*2, READ_CACHE, 0L,0,
- MYF(MY_WME)))
- {
- sql_print_error("Failed to create a cache on relay log info file '%s'",
- fname);
- msg= current_thd->stmt_da->message();
- goto err;
- }
-
- /* Init relay log with first entry in the relay index file */
- if (init_relay_log_pos(rli,NullS,BIN_LOG_HEADER_SIZE,0 /* no data lock */,
- &msg, 0))
- {
- sql_print_error("Failed to open the relay log 'FIRST' (relay_log_pos 4)");
- goto err;
- }
- rli->group_master_log_name[0]= 0;
- rli->group_master_log_pos= 0;
- rli->info_fd= info_fd;
}
- else // file exists
+ else
{
- if (info_fd >= 0)
- reinit_io_cache(&rli->info_file, READ_CACHE, 0L,0,0);
- else
- {
- int error=0;
- if ((info_fd= mysql_file_open(key_file_relay_log_info,
- fname, O_RDWR|O_BINARY, MYF(MY_WME))) < 0)
- {
- sql_print_error("\
-Failed to open the existing relay log info file '%s' (errno %d)",
- fname, my_errno);
- error= 1;
- }
- else if (init_io_cache(&rli->info_file, info_fd,
- IO_SIZE*2, READ_CACHE, 0L, 0, MYF(MY_WME)))
- {
- sql_print_error("Failed to create a cache on relay log info file '%s'",
- fname);
- error= 1;
- }
- if (error)
- {
- if (info_fd >= 0)
- mysql_file_close(info_fd, MYF(0));
- rli->info_fd= -1;
- rli->relay_log.close(LOG_CLOSE_INDEX | LOG_CLOSE_STOP_EVENT);
- mysql_mutex_unlock(&rli->data_lock);
- DBUG_RETURN(1);
- }
- }
-
- rli->info_fd = info_fd;
- int relay_log_pos, master_log_pos;
- if (init_strvar_from_file(rli->group_relay_log_name,
- sizeof(rli->group_relay_log_name),
- &rli->info_file, "") ||
- init_intvar_from_file(&relay_log_pos,
- &rli->info_file, BIN_LOG_HEADER_SIZE) ||
- init_strvar_from_file(rli->group_master_log_name,
- sizeof(rli->group_master_log_name),
- &rli->info_file, "") ||
- init_intvar_from_file(&master_log_pos, &rli->info_file, 0))
- {
- msg="Error reading slave log configuration";
+ if (rli->read_table_info())
+ {
+ msg= "Error reading relay log configuration";
+ error= 1;
goto err;
- }
- strmake(rli->event_relay_log_name,rli->group_relay_log_name,
- sizeof(rli->event_relay_log_name)-1);
- rli->group_relay_log_pos= rli->event_relay_log_pos= relay_log_pos;
- rli->group_master_log_pos= master_log_pos;
-
- if (rli->is_relay_log_recovery && init_recovery(rli->mi, &msg))
- goto err;
-
- if (init_relay_log_pos(rli,
- rli->group_relay_log_name,
- rli->group_relay_log_pos,
- 0 /* no data lock*/,
- &msg, 0))
- {
- char llbuf[22];
- sql_print_error("Failed to open the relay log '%s' (relay_log_pos %s)",
- rli->group_relay_log_name,
- llstr(rli->group_relay_log_pos, llbuf));