Skip to content

Commit 8381c6d

Browse files
author
Sergey Glukhov
committed
WL#13926 Periodic synchronization with storage device for select into outfile/dumpfile controlled by system variables.
The patch implements periodic synchronization with storage device for select into outfile/dumfile controlled by system variables. Based on the contribution provided by Facebook. Added system variables: select_into_buffer_size Buffer size for SELECT INTO OUTFILE/DUMPFILE. select_into_disk_sync Synchronize flushed buffer with disk for SELECT INTO OUTFILE/DUMPFILE. select_into_disk_sync_delay The delay in milliseconds after each buffer sync for SELECT INTO OUTFILE/DUMPFILE. Requires select_into_sync_disk = ON. Added fields into IO_CACHE struct bool disk_sync{false}; // Synchronize flushed buffer with disk. uint disk_sync_delay{0}; // Delay after disk synchronization of the flushed buffer. // Requirew disk_sync = true. Function my_b_flush_io_cache() is modified so that it performs synchronization with storage device after buffer flushing if 'select_into_disk_sync' variable is set ON and optionally delay after synchronization if 'select_into_disk_sync_delay' variable is non-zero. Function query_result.cc, create_file() is modified to use 'select_into_buffer_size' value for the buffer size for 'select into' command. Variables IO_CACHE::disk_sync, IO_CACHE::disc_sync_delay fields are set to the system variable values(select_into_disk_sync, select_into_disk_sync_delay). Reviewed-by: Tor Didriksen <tor.didriksen@oracle.com> Change-Id: I8e8c7031891a349b9c8c2dd42c8628c5ba568c8a
1 parent adb101d commit 8381c6d

20 files changed

+1179
-8
lines changed

include/my_sys.h

+5
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,11 @@ struct IO_CACHE /* Used when cacheing files */
456456
Stream_cipher *m_encryptor = nullptr;
457457
// This is a decryptor for decrypting the temporary file of the IO cache.
458458
Stream_cipher *m_decryptor = nullptr;
459+
// Synchronize flushed buffer with disk.
460+
bool disk_sync{false};
461+
// Delay in milliseconds after disk synchronization of the flushed buffer.
462+
// Requires disk_sync = true.
463+
uint disk_sync_delay{0};
459464
};
460465

461466
typedef int (*qsort2_cmp)(const void *, const void *, const void *);

mysql-test/include/outfile_fsync.inc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
eval select "Outfile OK" into outfile "$MYSQLTEST_VARDIR/tmp/outfile.test";

mysql-test/r/all_persisted_variables.result

+4-4
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,17 @@ include/assert.inc [Expect 500+ variables in the table. Due to open Bugs, we are
3838

3939
# Test SET PERSIST
4040

41-
include/assert.inc [Expect 403 persisted variables in the table.]
41+
include/assert.inc [Expect 406 persisted variables in the table.]
4242

4343
************************************************************
4444
* 3. Restart server, it must preserve the persisted variable
4545
* settings. Verify persisted configuration.
4646
************************************************************
4747
# restart
4848

49-
include/assert.inc [Expect 403 persisted variables in persisted_variables table.]
50-
include/assert.inc [Expect 403 persisted variables shown as PERSISTED in variables_info table.]
51-
include/assert.inc [Expect 403 persisted variables with matching peristed and global values.]
49+
include/assert.inc [Expect 406 persisted variables in persisted_variables table.]
50+
include/assert.inc [Expect 406 persisted variables shown as PERSISTED in variables_info table.]
51+
include/assert.inc [Expect 406 persisted variables with matching peristed and global values.]
5252

5353
************************************************************
5454
* 4. Test RESET PERSIST IF EXISTS. Verify persisted variable

mysql-test/r/mysqld--help-notwin.result

+12
Original file line numberDiff line numberDiff line change
@@ -1162,6 +1162,15 @@ The following options may be given as the first argument:
11621162
--secure-file-priv=name
11631163
Limit LOAD DATA, SELECT ... OUTFILE, and LOAD_FILE() to
11641164
files within specified directory
1165+
--select-into-buffer-size[=#]
1166+
Buffer size for SELECT INTO OUTFILE/DUMPFILE.
1167+
--select-into-disk-sync
1168+
Synchronize flushed buffer with disk for SELECT INTO
1169+
OUTFILE/DUMPFILE.
1170+
--select-into-disk-sync-delay[=#]
1171+
The delay in milliseconds after each buffer sync for
1172+
SELECT INTO OUTFILE/DUMPFILE. Requires
1173+
select_into_sync_disk = ON.
11651174
--server-id=# Uniquely identifies the server instance in the community
11661175
of replication partners
11671176
--server-id-bits=# Set number of significant bits in server-id
@@ -1732,6 +1741,9 @@ rpl-stop-slave-timeout 31536000
17321741
safe-user-create FALSE
17331742
schema-definition-cache 256
17341743
secondary-engine-cost-threshold 100000
1744+
select-into-buffer-size 131072
1745+
select-into-disk-sync FALSE
1746+
select-into-disk-sync-delay 0
17351747
server-id 1
17361748
server-id-bits 32
17371749
session-track-gtids OFF

mysql-test/r/mysqld--help-win.result

+12
Original file line numberDiff line numberDiff line change
@@ -1165,6 +1165,15 @@ The following options may be given as the first argument:
11651165
--secure-file-priv=name
11661166
Limit LOAD DATA, SELECT ... OUTFILE, and LOAD_FILE() to
11671167
files within specified directory
1168+
--select-into-buffer-size[=#]
1169+
Buffer size for SELECT INTO OUTFILE/DUMPFILE.
1170+
--select-into-disk-sync
1171+
Synchronize flushed buffer with disk for SELECT INTO
1172+
OUTFILE/DUMPFILE.
1173+
--select-into-disk-sync-delay[=#]
1174+
The delay in milliseconds after each buffer sync for
1175+
SELECT INTO OUTFILE/DUMPFILE. Requires
1176+
select_into_sync_disk = ON.
11681177
--server-id=# Uniquely identifies the server instance in the community
11691178
of replication partners
11701179
--server-id-bits=# Set number of significant bits in server-id
@@ -1744,6 +1753,9 @@ rpl-stop-slave-timeout 31536000
17441753
safe-user-create FALSE
17451754
schema-definition-cache 256
17461755
secondary-engine-cost-threshold 100000
1756+
select-into-buffer-size 131072
1757+
select-into-disk-sync FALSE
1758+
select-into-disk-sync-delay 0
17471759
server-id 1
17481760
server-id-bits 32
17491761
session-track-gtids OFF
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# restart
2+
SET SESSION select_into_buffer_size=262144;
3+
CREATE TABLE t1 (a TEXT, b TEXT) ENGINE=INNODB;
4+
CREATE TABLE t2 (a TEXT, b TEXT) ENGINE=INNODB;
5+
include/diff_tables.inc [test.t1, test.t2]
6+
ERROR HY000: Query execution was interrupted, maximum statement execution time exceeded
7+
include/assert_grep.inc [Found expected number of select_to_file]
8+
include/assert_grep.inc [Found expected number of select_to_file]
9+
include/assert_grep.inc [Found expected number of select_to_file]
10+
SET GLOBAL debug = '-d,print_select_into_flush_stats';
11+
SELECT /*+ SET_VAR(select_into_disk_sync_delay = 5000)
12+
SET_VAR(select_into_disk_sync = ON)
13+
SET_VAR(select_into_buffer_size = 16384) */
14+
@@select_into_disk_sync_delay, @@select_into_disk_sync, @@select_into_buffer_size;
15+
@@select_into_disk_sync_delay @@select_into_disk_sync @@select_into_buffer_size
16+
5000 1 16384
17+
SET SESSION select_into_buffer_size=default;
18+
DROP TABLE t1, t2;

mysql-test/suite/sys_vars/r/all_vars.result

+6
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ regexp_stack_limit
5353
regexp_time_limit
5454
regexp_time_limit
5555
resultset_metadata
56+
select_into_buffer_size
57+
select_into_buffer_size
58+
select_into_disk_sync
59+
select_into_disk_sync
60+
select_into_disk_sync_delay
61+
select_into_disk_sync_delay
5662
sql_require_primary_key
5763
sql_require_primary_key
5864
temptable_use_mmap
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
SET @start_global_value = @@global.select_into_buffer_size;
2+
SELECT @start_global_value;
3+
@start_global_value
4+
131072
5+
SET @start_session_value = @@session.select_into_buffer_size;
6+
SELECT @start_session_value;
7+
@start_session_value
8+
131072
9+
'#--------------------FN_DYNVARS_002_01-------------------------#'
10+
SET @@global.select_into_buffer_size = 1024;
11+
Warnings:
12+
Warning 1292 Truncated incorrect select_into_buffer_size value: '1024'
13+
SET @@global.select_into_buffer_size = DEFAULT;
14+
SELECT @@global.select_into_buffer_size;
15+
@@global.select_into_buffer_size
16+
131072
17+
SET @@session.select_into_buffer_size = 2048;
18+
Warnings:
19+
Warning 1292 Truncated incorrect select_into_buffer_size value: '2048'
20+
SET @@session.select_into_buffer_size = DEFAULT;
21+
SELECT @@session.select_into_buffer_size;
22+
@@session.select_into_buffer_size
23+
131072
24+
'#--------------------FN_DYNVARS_002_02-------------------------#'
25+
SET @@global.select_into_buffer_size = @start_global_value;
26+
SELECT @@global.select_into_buffer_size = 4096;
27+
@@global.select_into_buffer_size = 4096
28+
0
29+
SET @@session.select_into_buffer_size = @start_session_value;
30+
SELECT @@session.select_into_buffer_size = 2048;
31+
@@session.select_into_buffer_size = 2048
32+
0
33+
'#--------------------FN_DYNVARS_002_03-------------------------#'
34+
SET @@global.select_into_buffer_size = 16384;
35+
SELECT @@global.select_into_buffer_size;
36+
@@global.select_into_buffer_size
37+
16384
38+
SET @@global.select_into_buffer_size = 4096;
39+
Warnings:
40+
Warning 1292 Truncated incorrect select_into_buffer_size value: '4096'
41+
SELECT @@global.select_into_buffer_size;
42+
@@global.select_into_buffer_size
43+
8192
44+
SET @@global.select_into_buffer_size = 8192;
45+
SELECT @@global.select_into_buffer_size;
46+
@@global.select_into_buffer_size
47+
8192
48+
'#--------------------FN_DYNVARS_002_04-------------------------#'
49+
SET @@session.select_into_buffer_size = 4096;
50+
Warnings:
51+
Warning 1292 Truncated incorrect select_into_buffer_size value: '4096'
52+
SELECT @@session.select_into_buffer_size;
53+
@@session.select_into_buffer_size
54+
8192
55+
SET @@session.select_into_buffer_size = 8192;
56+
SELECT @@session.select_into_buffer_size;
57+
@@session.select_into_buffer_size
58+
8192
59+
SET @@session.select_into_buffer_size = 16384;
60+
SELECT @@session.select_into_buffer_size;
61+
@@session.select_into_buffer_size
62+
16384
63+
'#------------------FN_DYNVARS_002_05-----------------------#'
64+
SET @@global.select_into_buffer_size = -1;
65+
Warnings:
66+
Warning 1292 Truncated incorrect select_into_buffer_size value: '-1'
67+
SELECT @@global.select_into_buffer_size;
68+
@@global.select_into_buffer_size
69+
8192
70+
SET @@global.select_into_buffer_size = -1024;
71+
Warnings:
72+
Warning 1292 Truncated incorrect select_into_buffer_size value: '-1024'
73+
SELECT @@global.select_into_buffer_size;
74+
@@global.select_into_buffer_size
75+
8192
76+
SET @@global.select_into_buffer_size = 13;
77+
Warnings:
78+
Warning 1292 Truncated incorrect select_into_buffer_size value: '13'
79+
SELECT @@global.select_into_buffer_size;
80+
@@global.select_into_buffer_size
81+
8192
82+
SET @@global.select_into_buffer_size = ON;
83+
ERROR 42000: Incorrect argument type to variable 'select_into_buffer_size'
84+
SELECT @@global.select_into_buffer_size;
85+
@@global.select_into_buffer_size
86+
8192
87+
SET @@global.select_into_buffer_size = OFF;
88+
ERROR 42000: Incorrect argument type to variable 'select_into_buffer_size'
89+
SELECT @@global.select_into_buffer_size;
90+
@@global.select_into_buffer_size
91+
8192
92+
SET @@global.select_into_buffer_size = test;
93+
ERROR 42000: Incorrect argument type to variable 'select_into_buffer_size'
94+
SELECT @@global.select_into_buffer_size;
95+
@@global.select_into_buffer_size
96+
8192
97+
SET @@session.select_into_buffer_size = 23;
98+
Warnings:
99+
Warning 1292 Truncated incorrect select_into_buffer_size value: '23'
100+
SELECT @@session.select_into_buffer_size;
101+
@@session.select_into_buffer_size
102+
8192
103+
SET @@session.select_into_buffer_size = -2;
104+
Warnings:
105+
Warning 1292 Truncated incorrect select_into_buffer_size value: '-2'
106+
SELECT @@session.select_into_buffer_size;
107+
@@session.select_into_buffer_size
108+
8192
109+
SET @@session.select_into_buffer_size = 65550;
110+
Warnings:
111+
Warning 1292 Truncated incorrect select_into_buffer_size value: '65550'
112+
SELECT @@session.select_into_buffer_size;
113+
@@session.select_into_buffer_size
114+
65536
115+
SET @@session.select_into_buffer_size = ON;
116+
ERROR 42000: Incorrect argument type to variable 'select_into_buffer_size'
117+
SELECT @@session.select_into_buffer_size;
118+
@@session.select_into_buffer_size
119+
65536
120+
SET @@session.select_into_buffer_size = OFF;
121+
ERROR 42000: Incorrect argument type to variable 'select_into_buffer_size'
122+
SELECT @@session.select_into_buffer_size;
123+
@@session.select_into_buffer_size
124+
65536
125+
SET @@session.select_into_buffer_size = test;
126+
ERROR 42000: Incorrect argument type to variable 'select_into_buffer_size'
127+
SELECT @@session.select_into_buffer_size;
128+
@@session.select_into_buffer_size
129+
65536
130+
'#------------------FN_DYNVARS_002_06-----------------------#'
131+
SELECT @@global.select_into_buffer_size = VARIABLE_VALUE
132+
FROM performance_schema.global_variables
133+
WHERE VARIABLE_NAME='select_into_buffer_size';
134+
@@global.select_into_buffer_size = VARIABLE_VALUE
135+
1
136+
'#------------------FN_DYNVARS_002_07-----------------------#'
137+
SELECT @@session.select_into_buffer_size = VARIABLE_VALUE
138+
FROM performance_schema.session_variables
139+
WHERE VARIABLE_NAME='select_into_buffer_size';
140+
@@session.select_into_buffer_size = VARIABLE_VALUE
141+
1
142+
'#------------------FN_DYNVARS_002_08-----------------------#'
143+
SET @@global.select_into_buffer_size = TRUE;
144+
Warnings:
145+
Warning 1292 Truncated incorrect select_into_buffer_size value: '1'
146+
SELECT @@global.select_into_buffer_size;
147+
@@global.select_into_buffer_size
148+
8192
149+
SET @@global.select_into_buffer_size = FALSE;
150+
Warnings:
151+
Warning 1292 Truncated incorrect select_into_buffer_size value: '0'
152+
SELECT @@global.select_into_buffer_size;
153+
@@global.select_into_buffer_size
154+
8192
155+
'#---------------------FN_DYNVARS_001_09----------------------#'
156+
SET @@global.select_into_buffer_size = 16384;
157+
SET @@session.select_into_buffer_size = 8192;
158+
SELECT @@select_into_buffer_size = @@global.select_into_buffer_size;
159+
@@select_into_buffer_size = @@global.select_into_buffer_size
160+
0
161+
'#---------------------FN_DYNVARS_001_10----------------------#'
162+
SET @@select_into_buffer_size = 16384;
163+
SELECT @@select_into_buffer_size = @@local.select_into_buffer_size;
164+
@@select_into_buffer_size = @@local.select_into_buffer_size
165+
1
166+
SELECT @@local.select_into_buffer_size = @@session.select_into_buffer_size;
167+
@@local.select_into_buffer_size = @@session.select_into_buffer_size
168+
1
169+
'#---------------------FN_DYNVARS_001_11----------------------#'
170+
SET select_into_buffer_size = 1024;
171+
Warnings:
172+
Warning 1292 Truncated incorrect select_into_buffer_size value: '1024'
173+
SELECT @@select_into_buffer_size;
174+
@@select_into_buffer_size
175+
8192
176+
SELECT local.select_into_buffer_size;
177+
ERROR 42S02: Unknown table 'local' in field list
178+
SELECT session.select_into_buffer_size;
179+
ERROR 42S02: Unknown table 'session' in field list
180+
SELECT select_into_buffer_size = @@session.select_into_buffer_size;
181+
ERROR 42S22: Unknown column 'select_into_buffer_size' in 'field list'
182+
SET @@global.select_into_buffer_size = @start_global_value;
183+
SELECT @@global.select_into_buffer_size;
184+
@@global.select_into_buffer_size
185+
131072
186+
SET @@session.select_into_buffer_size = @start_session_value;
187+
SELECT @@session.select_into_buffer_size;
188+
@@session.select_into_buffer_size
189+
131072

0 commit comments

Comments
 (0)