Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MDEV-15935 Add redirection support #1472

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions mysql-test/main/mysqld--help.result
Original file line number Diff line number Diff line change
Expand Up @@ -976,6 +976,15 @@ The following specify which files/extra groups are read (specified before remain
--read-rnd-buffer-size=#
When reading rows in sorted order after a sort, the rows
are read through this buffer to avoid a disk seeks
--redirect-enabled Return redirection information to client.
--redirect-server-host[=name]
The server host that client can choose to redirect to.
--redirect-server-port[=name]
The server host port that client can choose to redirect
to.
--redirect-server-ttl[=name]
The life time of the validity of redirected information
with unit second.
--relay-log=name The location and name to use for relay logs.
--relay-log-index=name
The location and name to use for the file that keeps a
Expand Down Expand Up @@ -1725,6 +1734,10 @@ read-binlog-speed-limit 0
read-buffer-size 131072
read-only FALSE
read-rnd-buffer-size 262144
redirect-enabled FALSE
redirect-server-host
redirect-server-port
redirect-server-ttl 0
relay-log (No default value)
relay-log-index (No default value)
relay-log-info-file relay-log.info
Expand Down
8 changes: 8 additions & 0 deletions sql/mysqld.cc
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,10 @@ my_bool locked_in_memory;
bool opt_using_transactions;
bool volatile abort_loop;
uint volatile global_disable_checkpoint;
my_bool redirect_enabled;
const char *redirect_server_host;
const char *redirect_server_port;
const char *redirect_server_ttl;
#if defined(_WIN32) && !defined(EMBEDDED_LIBRARY)
ulong slow_start_timeout;
#endif
Expand Down Expand Up @@ -7845,6 +7849,10 @@ static int mysql_init_variables(void)
opt_endinfo= using_udf_functions= 0;
opt_using_transactions= 0;
abort_loop= select_thread_in_use= signal_thread_in_use= 0;
redirect_enabled= 0;
redirect_server_host= NullS;
redirect_server_port= NullS;
redirect_server_ttl= NullS;
grant_option= 0;
aborted_threads= aborted_connects= aborted_connects_preauth= 0;
subquery_cache_miss= subquery_cache_hit= 0;
Expand Down
4 changes: 4 additions & 0 deletions sql/mysqld.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ extern bool opt_ignore_builtin_innodb;
extern my_bool opt_character_set_client_handshake;
extern my_bool debug_assert_on_not_freed_memory;
extern bool volatile abort_loop;
extern my_bool redirect_enabled;
extern const char *redirect_server_host;
extern const char *redirect_server_port;
extern const char *redirect_server_ttl;
shih-che marked this conversation as resolved.
Show resolved Hide resolved
extern Atomic_counter<uint> connection_count;
extern my_bool opt_safe_user_create;
extern my_bool opt_safe_show_db, opt_local_infile, opt_myisam_use_mmap;
Expand Down
17 changes: 17 additions & 0 deletions sql/sql_acl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
#include "sql_plugin_compat.h"

#define MAX_SCRAMBLE_LENGTH 1024
#define MAX_REDIRECTION_LEN 512

bool mysql_user_table_is_in_short_password_format= false;
bool using_global_priv_table= true;
Expand Down Expand Up @@ -14312,6 +14313,22 @@ bool acl_authenticate(THD *thd, uint com_change_user_pkt_len)

if (res == CR_OK_HANDSHAKE_COMPLETE)
thd->get_stmt_da()->disable_status();
else if (redirect_enabled)
{
char msg[MAX_REDIRECTION_LEN];
size_t len = 0;

msg[0] = '\0';
len = snprintf(msg + 1, MAX_REDIRECTION_LEN - 1, "Location: mysql://[%s]:%s/user=%s&ttl=%s",
shih-che marked this conversation as resolved.
Show resolved Hide resolved
redirect_server_host, redirect_server_port, sctx->user, redirect_server_ttl);
shih-che marked this conversation as resolved.
Show resolved Hide resolved

if (len >= MAX_REDIRECTION_LEN - 1){
sql_print_error("redirection info is too large to return to client (len= %u)",len);
my_ok(thd);
shih-che marked this conversation as resolved.
Show resolved Hide resolved
}
else
my_ok(thd, 0, 0, msg);
}
else
my_ok(thd);

shih-che marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
25 changes: 25 additions & 0 deletions sql/sys_vars.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6683,3 +6683,28 @@ static Sys_var_ulonglong Sys_max_rowid_filter_size(
SESSION_VAR(max_rowid_filter_size), CMD_LINE(REQUIRED_ARG),
VALID_RANGE(1024, (ulonglong)~(intptr)0), DEFAULT(128*1024),
BLOCK_SIZE(1));

static Sys_var_mybool Sys_redirect_enabled(
"redirect_enabled",
"Return redirection information to client.",
GLOBAL_VAR(redirect_enabled), CMD_LINE(OPT_ARG),
DEFAULT(FALSE), NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0),
ON_UPDATE(0));

static Sys_var_charptr Sys_redirect_server_host(
"redirect_server_host",
"The server host that client can choose to redirect to.",
READ_ONLY GLOBAL_VAR(redirect_server_host), CMD_LINE(OPT_ARG),
DEFAULT(""));

static Sys_var_charptr Sys_redirect_server_port(
shih-che marked this conversation as resolved.
Show resolved Hide resolved
"redirect_server_port",
"The server host port that client can choose to redirect to.",
READ_ONLY GLOBAL_VAR(redirect_server_port), CMD_LINE(OPT_ARG),
DEFAULT(""));

static Sys_var_charptr Sys_redirect_server_ttl(
"redirect_server_ttl",
"The life time of the validity of redirected information with unit second.",
shih-che marked this conversation as resolved.
Show resolved Hide resolved
READ_ONLY GLOBAL_VAR(redirect_server_ttl), CMD_LINE(OPT_ARG),
DEFAULT("0"));