Skip to content

Commit 2c299ad

Browse files
Luqun Loufacebook-github-bot
authored andcommitted
add select into files options for mysqldump
Summary: Currently mysqldump doesn't support passing configuration for select into files. Expose these options for mysqldump. by default, it is disabled(use mysqld server default value instead). Differential Revision: D50845347 fbshipit-source-id: 1d641307cb7057dca0025dc15f0ee7b1d9db4c1a
1 parent 46759c8 commit 2c299ad

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

client/client_priv.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,11 @@ enum options_client {
208208
OPT_ORDER_BY_PRIMARY_FORCE_INDEX,
209209
OPT_READ_FROM_BINLOG_SERVER,
210210
OPT_DATA_PATH,
211+
OPT_SELECT_INTO_BUFFER_SIZE,
212+
OPT_SELECT_INTO_DISK_SYNC,
213+
OPT_SELECT_INTO_DISK_SYNC_DELAY,
214+
OPT_SELECT_INTO_FILE_FSYNC_SIZE,
215+
OPT_SELECT_INTO_FILE_FSYNC_TIMEOUT,
211216
/* Add new option above this */
212217
OPT_MAX_CLIENT_OPTION
213218
};

client/mysqldump.cc

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,11 @@ static uint opt_mysql_port = 0, opt_master_data;
168168
static uint opt_slave_data;
169169
static bool opt_compress_data = false;
170170
static ulonglong opt_compression_chunk_size = 0;
171+
static ulong opt_select_into_buffer_size = 0;
172+
static bool opt_select_into_disk_sync = false;
173+
static uint opt_select_into_disk_sync_delay = 0;
174+
static ulong opt_select_into_file_fsync_size = 0;
175+
static uint opt_select_into_file_fsync_timeout = 0;
171176
static bool do_compress = 0;
172177
static ulong opt_lra_size = 0;
173178
static ulong opt_lra_sleep = 0;
@@ -773,6 +778,32 @@ static struct my_option my_long_options[] = {
773778
"stored in --tab path.",
774779
&opt_data_path, &opt_data_path, nullptr, GET_STR, OPT_ARG, 0, 0, 0,
775780
nullptr, 0, nullptr},
781+
{"select_into_buffer_size", OPT_SELECT_INTO_BUFFER_SIZE,
782+
"For mysqldump session, Buffer size for SELECT INTO OUTFILE/DUMPFILE."
783+
"(default server setting, if 0)",
784+
&opt_select_into_buffer_size, &opt_select_into_buffer_size, 0, GET_ULONG,
785+
OPT_ARG, 0, 0, (ulong)(~(my_off_t)0), nullptr, IO_SIZE, nullptr},
786+
{"select_into_disk_sync", OPT_SELECT_INTO_DISK_SYNC,
787+
"For mysqldump session, Synchronize flushed buffer with disk for SELECT "
788+
"INTO OUTFILE/DUMPFILE. (default server setting, if 0)",
789+
&opt_select_into_disk_sync, &opt_select_into_disk_sync, 0, GET_BOOL,
790+
OPT_ARG, 0, 0, 0, nullptr, 0, nullptr},
791+
{"select_into_disk_sync_delay", OPT_SELECT_INTO_DISK_SYNC_DELAY,
792+
"For mysqldump session, The delay in milliseconds after each buffer sync "
793+
"for SELECT INTO OUTFILE/DUMPFILE. Requires select_into_sync_disk = ON."
794+
"(default server setting, if 0)",
795+
&opt_select_into_disk_sync_delay, &opt_select_into_disk_sync_delay, 0,
796+
GET_UINT, OPT_ARG, 0, 0, LONG_TIMEOUT, nullptr, 1, nullptr},
797+
{"select_into_file_fsync_size", OPT_SELECT_INTO_FILE_FSYNC_SIZE,
798+
"For mysqldump session, Do an fsync to disk when the buffer grows by these"
799+
"many bytes for SELECT INTO OUTFILE. (default server setting, if 0)",
800+
&opt_select_into_file_fsync_size, &opt_select_into_file_fsync_size, 0,
801+
GET_ULONG, OPT_ARG, 0, 0, (ulong)(~(my_off_t)0), nullptr, 1024, nullptr},
802+
{"select_into_file_fsync_timeout", OPT_SELECT_INTO_FILE_FSYNC_TIMEOUT,
803+
"For mysqldump session, The timeout/sleep in milliseconds after each fsync"
804+
" with SELECT INTO OUTFILE, (default server setting, if 0)",
805+
&opt_select_into_file_fsync_timeout, &opt_select_into_file_fsync_timeout,
806+
0, GET_UINT, OPT_ARG, 0, 0, UINT_MAX, nullptr, 1, nullptr},
776807
{nullptr, 0, nullptr, nullptr, nullptr, nullptr, GET_NO_ARG, NO_ARG, 0, 0,
777808
0, nullptr, 0, nullptr}};
778809

@@ -1955,6 +1986,33 @@ static int connect_to_db(char *host, char *user) {
19551986
if (mysql_query_with_error_report(mysql, 0, buff)) return 1;
19561987
}
19571988

1989+
if (opt_select_into_buffer_size) {
1990+
snprintf(buff, sizeof(buff), "SET session select_into_buffer_size=%lu",
1991+
opt_select_into_buffer_size);
1992+
if (mysql_query_with_error_report(mysql, 0, buff)) return 1;
1993+
}
1994+
if (opt_select_into_disk_sync) {
1995+
snprintf(buff, sizeof(buff), "SET session select_into_disk_sync=%d",
1996+
opt_select_into_disk_sync);
1997+
if (mysql_query_with_error_report(mysql, 0, buff)) return 1;
1998+
}
1999+
if (opt_select_into_disk_sync_delay) {
2000+
snprintf(buff, sizeof(buff), "SET session select_into_disk_sync_delay=%d",
2001+
opt_select_into_disk_sync_delay);
2002+
if (mysql_query_with_error_report(mysql, 0, buff)) return 1;
2003+
}
2004+
if (opt_select_into_file_fsync_size) {
2005+
snprintf(buff, sizeof(buff), "SET session select_into_file_fsync_size=%lu",
2006+
opt_select_into_file_fsync_size);
2007+
if (mysql_query_with_error_report(mysql, 0, buff)) return 1;
2008+
}
2009+
if (opt_select_into_file_fsync_timeout) {
2010+
snprintf(buff, sizeof(buff),
2011+
"SET session select_into_file_fsync_timeout=%d",
2012+
opt_select_into_file_fsync_timeout);
2013+
if (mysql_query_with_error_report(mysql, 0, buff)) return 1;
2014+
}
2015+
19582016
return 0;
19592017
} /* connect_to_db */
19602018

0 commit comments

Comments
 (0)