summaryrefslogtreecommitdiff
path: root/mysql-test/t/log_tables.test
blob: a9e161f644c5a5e8bdfce328a09aa3b6da44f03c (plain)
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
#
# Basic log tables test
#

# check that CSV engine was compiled in
--source include/have_csv.inc

use mysql;

#
# Check that log tables work and we can do basic selects. This also
# tests truncate, which works in a special mode with the log tables
#

truncate table general_log;
--replace_column 1 TIMESTAMP
select * from general_log;
truncate table slow_log;
--replace_column 1 TIMESTAMP
select * from slow_log;

#
# We want to check that a record newly written to a log table shows up for
# the query: since log tables use concurrent insert machinery and log tables
# are always locked by artificial THD, this feature requires additional
# check in ha_tina::write_row. This simple test should prove that the
# log table flag in the table handler is triggered and working.
#

truncate table general_log;
--replace_column 1 TIMESTAMP
select * from general_log where argument like '%general_log%';


#
# Check some basic queries interfering with the log tables.
# In our test we'll use a tbale with verbose comments to the short
# command type names, used in the tables
#

create table join_test (verbose_comment varchar (80), command_type varchar(64));

insert into join_test values ("User performed a usual SQL query", "Query");
insert into join_test values ("New DB connection was registered", "Connect");
insert into join_test values ("Get the table info", "Field List");

select verbose_comment, user_host, argument
  from  mysql.general_log join join_test
    on (mysql.general_log.command_type = join_test.command_type);

drop table join_test;

#
# check that flush of the log table work fine
#

flush logs;

#
# check locking of the log tables
#

--error 1532
lock tables mysql.general_log WRITE;

--error 1532
lock tables mysql.slow_log WRITE;

#
# This attemts to get TL_READ_NO_INSERT lock, which is incompatible with
# TL_WRITE_CONCURRENT_INSERT. This should fail. We issue this error as log
# tables are always opened and locked by the logger.
#

--error 1533
lock tables mysql.general_log READ;

--error 1533
lock tables mysql.slow_log READ;

#
# This call should result in TL_READ lock on the log table. This is ok and
# should pass.
#

lock tables mysql.slow_log READ LOCAL, mysql.general_log READ LOCAL;

unlock tables;

#
# check that FLUSH LOGS waits for all readers of the log table to vanish
#

connect (con1,localhost,root,,);
connect (con2,localhost,root,,);

connection con1;

lock tables mysql.general_log READ LOCAL;

connection con2;

# this should wait for log tables to unlock
send flush logs;

connection con1;

unlock tables;

# this connection should be alive by the time
connection con2;

reap;

select "Mark that we woke up from flush logs in the test"
       as "test passed";

#
# perform the same check for TRUNCATE: it should also wait for readers
# to disappear
#

connection con1;

lock tables mysql.general_log READ LOCAL;

connection con2;

# this should wait for log tables to unlock
send truncate mysql.general_log;

connection con1;

unlock tables;

# this connection should be alive by the time
connection con2;

reap;

select "Mark that we woke up from TRUNCATE in the test"
       as "test passed";

disconnect con2;
disconnect con1;