Below is the list of changes that have just been committed into a local
5.1 repository of patg. When patg does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html
ChangeSet
1.2116 06/02/09 18:29:05 patg@stripped +16 -0
WL# 3031
sql/sql_servers.h
1.1 06/02/09 18:29:00 patg@stripped +66 -0
WL# 3031
sql/sql_servers.cc
1.1 06/02/09 18:29:00 patg@stripped +1166 -0
WL# 3031
sql/sql_servers.h
1.0 06/02/09 18:29:00 patg@stripped +0 -0
BitKeeper file /home/patg/mysql-build/mysql-5.1-wl3031/sql/sql_servers.h
sql/sql_servers.cc
1.0 06/02/09 18:29:00 patg@stripped +0 -0
BitKeeper file /home/patg/mysql-build/mysql-5.1-wl3031/sql/sql_servers.cc
sql/sql_yacc.yy
1.449 06/02/09 18:28:59 patg@stripped +29 -10
WL# 3031
sql/sql_parse.cc
1.517 06/02/09 18:28:59 patg@stripped +37 -3
WL# 3031
sql/sql_lex.h
1.216 06/02/09 18:28:59 patg@stripped +8 -6
WL# 3031
sql/sql_lex.cc
1.171 06/02/09 18:28:59 patg@stripped +15 -0
WL# 3031
sql/sql_acl.cc
1.176 06/02/09 18:28:59 patg@stripped +1 -0
WL# 3031
sql/share/errmsg.txt
1.79 06/02/09 18:28:59 patg@stripped +4 -2
WL# 3031
sql/mysqld.cc
1.529 06/02/09 18:28:58 patg@stripped +2 -2
WL# 3031
sql/mysql_priv.h
1.376 06/02/09 18:28:58 patg@stripped +1 -1
WL# 3031
sql/ha_federated.h
1.27 06/02/09 18:28:58 patg@stripped +2 -2
WL# 3031
sql/ha_federated.cc
1.52 06/02/09 18:28:58 patg@stripped +28 -28
WL# 3031
sql/Makefile.am
1.131 06/02/09 18:28:58 patg@stripped +2 -2
WL# 3031
libmysqld/Makefile.am
1.80 06/02/09 18:28:58 patg@stripped +1 -1
WL# 3031
BitKeeper/deleted/.del-sql_connections.h~2ba1eb5726722a98
1.2 06/02/09 16:57:08 patg@stripped +11 -10
Delete: sql/sql_connections.h
BitKeeper/deleted/.del-sql_connections.cc~4ee6cd6ad37a5cd1
1.2 06/02/09 16:57:08 patg@stripped +143 -98
Delete: sql/sql_connections.cc
# This is a BitKeeper patch. What follows are the unified diffs for the
# set of deltas contained in the patch. The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User: patg
# Host: govinda.patg.net
# Root: /home/patg/mysql-build/mysql-5.1-wl3031
--- 1.130/sql/Makefile.am 2006-01-31 16:33:23 -08:00
+++ 1.131/sql/Makefile.am 2006-02-09 18:28:58 -08:00
@@ -66,7 +66,7 @@
parse_file.h sql_view.h sql_trigger.h \
sql_array.h sql_cursor.h event.h event_priv.h \
sql_plugin.h authors.h \
- sql_connections.h
+ sql_servers.h
mysqld_SOURCES = sql_lex.cc sql_handler.cc sql_partition.cc \
item.cc item_sum.cc item_buff.cc item_func.cc \
item_cmpfunc.cc item_strfunc.cc item_timefunc.cc \
@@ -103,7 +103,7 @@
event_executor.cc event.cc event_timed.cc \
sql_plugin.cc sql_binlog.cc \
handlerton.cc sql_tablespace.cc \
- sql_connections.cc
+ sql_servers.cc
EXTRA_mysqld_SOURCES = ha_innodb.cc ha_berkeley.cc ha_archive.cc \
ha_innodb.h ha_berkeley.h ha_archive.h \
ha_blackhole.cc ha_federated.cc ha_ndbcluster.cc \
--- 1.375/sql/mysql_priv.h 2006-01-31 16:33:23 -08:00
+++ 1.376/sql/mysql_priv.h 2006-02-09 18:28:58 -08:00
@@ -554,7 +554,7 @@
#include "tztime.h"
#ifdef MYSQL_SERVER
#include "opt_range.h"
-#include "sql_connections.h"
+#include "sql_servers.h"
#ifdef HAVE_QUERY_CACHE
struct Query_cache_query_flags
--- 1.528/sql/mysqld.cc 2006-01-31 16:33:23 -08:00
+++ 1.529/sql/mysqld.cc 2006-02-09 18:28:58 -08:00
@@ -1160,7 +1160,7 @@
my_tz_free();
my_dbopt_free();
#ifndef NO_EMBEDDED_ACCESS_CHECKS
- connections_free(1);
+ servers_free(1);
acl_free(1);
grant_free();
#endif
@@ -3640,7 +3640,7 @@
if (!opt_noacl)
(void) grant_init();
- if (connections_init(0))
+ if (servers_init(0))
{
}
if (!opt_noacl)
--- 1.175/sql/sql_acl.cc 2006-01-13 08:04:32 -08:00
+++ 1.176/sql/sql_acl.cc 2006-02-09 18:28:59 -08:00
@@ -166,6 +166,7 @@
by zeros at startup.
*/
return_val= acl_reload(thd);
+ DBUG_PRINT("info", ("acl_reload (to acl_init) returned %d", return_val));
delete thd;
/* Remember that we don't have a THD */
my_pthread_setspecific_ptr(THR_THD, 0);
--- 1.170/sql/sql_lex.cc 2006-01-18 13:18:37 -08:00
+++ 1.171/sql/sql_lex.cc 2006-02-09 18:28:59 -08:00
@@ -190,6 +190,21 @@
lex->nest_level=0 ;
lex->allow_sum_func= 0;
lex->in_sum_func= NULL;
+ /*
+ ok, there must be a better solution for this, long-term
+ I tried "bzero" in the sql_yacc.yy code, but that for
+ some reason made the values zero, even if they were set
+ */
+ lex->server_options.server_name= 0;
+ lex->server_options.server_name_length= 0;
+ lex->server_options.host= 0;
+ lex->server_options.db= 0;
+ lex->server_options.username= 0;
+ lex->server_options.password= 0;
+ lex->server_options.scheme= 0;
+ lex->server_options.socket= 0;
+ lex->server_options.owner= 0;
+ lex->server_options.port= -1;
DBUG_VOID_RETURN;
}
--- 1.215/sql/sql_lex.h 2006-01-31 16:33:24 -08:00
+++ 1.216/sql/sql_lex.h 2006-02-09 18:28:59 -08:00
@@ -99,7 +99,8 @@
SQLCOM_ALTER_TABLESPACE,
SQLCOM_INSTALL_PLUGIN, SQLCOM_UNINSTALL_PLUGIN,
SQLCOM_SHOW_AUTHORS, SQLCOM_BINLOG_BASE64_EVENT,
- SQLCOM_SHOW_PLUGINS, SQLCOM_CREATE_SERVER,
+ SQLCOM_SHOW_PLUGINS,
+ SQLCOM_CREATE_SERVER, SQLCOM_DROP_SERVER, SQLCOM_ALTER_SERVER,
SQLCOM_CREATE_EVENT, SQLCOM_ALTER_EVENT, SQLCOM_DROP_EVENT,
SQLCOM_SHOW_CREATE_EVENT, SQLCOM_SHOW_EVENTS,
@@ -164,11 +165,12 @@
typedef List<Item> List_item;
/* CONNECTION CACHE CHANGES */
-typedef struct st_lex_connection_options
+typedef struct st_lex_server_options
{
- ulong port;
- char *server_name, *host, *username, *password, *scheme, *socket, *owner;
-} LEX_CONNECTION_OPTIONS;
+ long port;
+ uint server_name_length;
+ char *server_name, *host, *db, *username, *password, *scheme, *socket, *owner;
+} LEX_SERVER_OPTIONS;
typedef struct st_lex_master_info
{
@@ -832,7 +834,7 @@
HA_CHECK_OPT check_opt; // check/repair options
HA_CREATE_INFO create_info;
LEX_MASTER_INFO mi; // used by CHANGE MASTER
- LEX_CONNECTION_OPTIONS conn_options;
+ LEX_SERVER_OPTIONS server_options;
USER_RESOURCES mqh;
ulong type;
/*
--- 1.516/sql/sql_parse.cc 2006-01-31 16:33:24 -08:00
+++ 1.517/sql/sql_parse.cc 2006-02-09 18:28:59 -08:00
@@ -4901,15 +4901,49 @@
}
case SQLCOM_CREATE_SERVER:
{
+ int error;
LEX *lex= thd->lex;
DBUG_PRINT("info", ("case SQLCOM_CREATE_SERVER"));
- if (create_server(&lex->conn_options))
+ if ((error= create_server(thd, &lex->server_options)))
{
- DBUG_PRINT("info", ("problem creating server"));
+ DBUG_PRINT("info", ("problem creating server",
+ lex->server_options.server_name));
+ my_error(error, MYF(0), lex->server_options.server_name);
+ break;
}
+ send_ok(thd, 1);
+ break;
+ }
+ case SQLCOM_ALTER_SERVER:
+ {
+ int error;
+ LEX *lex= thd->lex;
+ DBUG_PRINT("info", ("case SQLCOM_ALTER_SERVER"));
+ if ((error= alter_server(thd, &lex->server_options)))
+ {
+ DBUG_PRINT("info", ("problem altering server",
+ lex->server_options.server_name));
+ my_error(error, MYF(0), lex->server_options.server_name);
+ break;
+ }
+ send_ok(thd, 1);
+ break;
}
- send_ok(thd);
+ case SQLCOM_DROP_SERVER:
+ {
+ int err_code;
+ LEX *lex= thd->lex;
+ DBUG_PRINT("info", ("case SQLCOM_DROP_SERVER"));
+ if ((err_code= drop_server(thd, &lex->server_options)))
+ {
+ DBUG_PRINT("info", ("problem dropping server %s",
+ lex->server_options.server_name));
+ my_error(err_code, MYF(0), lex->server_options.server_name);
+ break;
+ }
+ send_ok(thd, 1);
break;
+ }
default:
DBUG_ASSERT(0); /* Impossible */
send_ok(thd);
--- 1.448/sql/sql_yacc.yy 2006-01-31 16:33:24 -08:00
+++ 1.449/sql/sql_yacc.yy 2006-02-09 18:28:59 -08:00
@@ -1417,14 +1417,15 @@
}
| CREATE server_def
{
- Lex->sql_command = SQLCOM_CREATE_SERVER;
+ Lex->sql_command= SQLCOM_CREATE_SERVER;
}
;
server_def:
- SERVER_SYM ident_or_text WRAPPER_SYM ident_or_text OPTIONS_SYM '(' server_options_list ')'
+ SERVER_SYM ident_or_text FOREIGN DATA_SYM WRAPPER_SYM ident_or_text OPTIONS_SYM '(' server_options_list ')'
{
- Lex->conn_options.server_name= $2.str;
- Lex->conn_options.scheme= $4.str;
+ Lex->server_options.server_name= $2.str;
+ Lex->server_options.server_name_length= $2.length;
+ Lex->server_options.scheme= $6.str;
}
;
@@ -1436,32 +1437,37 @@
server_option:
USER TEXT_STRING_sys
{
- Lex->conn_options.username= $2.str;
+ Lex->server_options.username= $2.str;
}
|
HOST_SYM TEXT_STRING_sys
{
- Lex->conn_options.username= $2.str;
+ Lex->server_options.host= $2.str;
+ }
+ |
+ DATABASE TEXT_STRING_sys
+ {
+ Lex->server_options.db= $2.str;
}
|
OWNER_SYM TEXT_STRING_sys
{
- Lex->conn_options.username= $2.str;
+ Lex->server_options.owner= $2.str;
}
|
PASSWORD TEXT_STRING_sys
{
- Lex->conn_options.password= $2.str;
+ Lex->server_options.password= $2.str;
}
|
SOCKET_SYM TEXT_STRING_sys
{
- Lex->conn_options.socket= $2.str;
+ Lex->server_options.socket= $2.str;
}
|
PORT_SYM ulong_num
{
- Lex->conn_options.port= $2;
+ Lex->server_options.port= $2;
}
;
@@ -4936,6 +4942,13 @@
LEX *lex= Lex;
lex->alter_tablespace_info->ts_cmd_type= ALTER_ACCESS_MODE_TABLESPACE;
}
+ | ALTER SERVER_SYM ident_or_text OPTIONS_SYM '(' server_options_list ')'
+ {
+ LEX *lex= Lex;
+ Lex->sql_command= SQLCOM_ALTER_SERVER;
+ Lex->server_options.server_name= $3.str;
+ Lex->server_options.server_name_length= $3.length;
+ }
;
ev_alter_on_schedule_completion: /* empty */ { $<ulong_num>$= 0;}
@@ -7763,6 +7776,12 @@
LEX *lex= Lex;
lex->alter_tablespace_info->ts_cmd_type= DROP_LOGFILE_GROUP;
}
+ | DROP SERVER_SYM ident_or_text
+ {
+ Lex->sql_command = SQLCOM_DROP_SERVER;
+ Lex->server_options.server_name= $3.str;
+ Lex->server_options.server_name_length= $3.length;
+ }
;
table_list:
--- 1.78/sql/share/errmsg.txt 2006-01-31 16:33:24 -08:00
+++ 1.79/sql/share/errmsg.txt 2006-02-09 18:28:59 -08:00
@@ -5759,8 +5759,8 @@
eng "Table definition on master and slave does not match"
ER_BINLOG_ROW_RBR_TO_SBR
eng "Slave running with --log-slave-updates must use row-based binary logging to be able to replicate row-based binary log events"
-ER_FOREIGN_CONNECTION_DOESNT_EXIST
- eng "The foreign connection name you are trying to reference does not exist. Data source error: %-.64s"
+ER_FOREIGN_SERVER_DOESNT_EXIST
+ eng "The foreign server name you are trying to reference does not exist. Data source error: %-.64s"
ger "Die externe Verbindung, auf die Sie zugreifen wollen, existiert nicht. Datenquellenfehlermeldung: %-.64s"
ER_EVENT_ALREADY_EXISTS
eng "Event '%-.64s' already exists"
@@ -5801,3 +5801,5 @@
eng "You can't write-lock a log table. Only read access is possible."
ER_CANT_READ_LOCK_LOG_TABLE
eng "You can't use usual read lock with log tables. Try READ LOCAL instead."
+ER_FOREIGN_SERVER_EXISTS
+ eng "The foreign server, %s, you are trying to create already exists."
--- 1.79/libmysqld/Makefile.am 2006-01-31 16:33:23 -08:00
+++ 1.80/libmysqld/Makefile.am 2006-02-09 18:28:58 -08:00
@@ -68,7 +68,7 @@
rpl_filter.cc sql_partition.cc handlerton.cc sql_plugin.cc \
sql_tablespace.cc \
rpl_injector.cc my_user.c \
- sql_connections.cc
+ sql_servers.cc
libmysqld_int_a_SOURCES= $(libmysqld_sources) $(libmysqlsources) $(sqlsources)
EXTRA_libmysqld_a_SOURCES = ha_innodb.cc ha_berkeley.cc ha_archive.cc \
--- New file ---
+++ sql/sql_servers.cc 06/02/09 18:29:00
/* Copyright (C) 2000-2003 MySQL AB
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; either version 2 of the License, or
(at your option) any later version.
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 */
/*
The servers are saved in the system table "servers"
*/
#include "mysql_priv.h"
#include "hash_filo.h"
#include <m_ctype.h>
#include <stdarg.h>
#include "sp_head.h"
#include "sp.h"
HASH servers_cache;
pthread_mutex_t servers_cache_mutex; // To init the hash
uint servers_cache_initialised=FALSE;
/* Version of server table. incremented by servers_load */
static uint servers_version=0;
static MEM_ROOT mem;
static rw_lock_t THR_LOCK_servers;
static bool initialized=0;
static byte *servers_cache_get_key(FOREIGN_SERVER *server, uint *length,
my_bool not_used __attribute__((unused)))
{
DBUG_ENTER("servers_cache_get_key");
DBUG_PRINT("info", ("server_name_length %d server_name %s",
server->server_name_length,
server->server_name));
*length= (uint) server->server_name_length;
DBUG_RETURN((byte*) server->server_name);
}
/*
Initialize structures responsible for servers used in federated
server scheme information for them from the server
table in the 'mysql' database.
SYNOPSIS
servers_init()
dont_read_server_table TRUE if we want to skip loading data from
server table and disable privilege checking.
NOTES
This function is mostly responsible for preparatory steps, main work
on initialization and grants loading is done in servers_reload().
RETURN VALUES
0 ok
1 Could not initialize servers
*/
my_bool servers_init(bool dont_read_servers_table)
{
THD *thd;
my_bool return_val= 0;
DBUG_ENTER("servers_init");
/* init the mutex */
if (pthread_mutex_init(&servers_cache_mutex, MY_MUTEX_INIT_FAST))
DBUG_RETURN(1);
/* initialise our servers cache */
if (hash_init(&servers_cache, system_charset_info, 32, 0, 0,
(hash_get_key) servers_cache_get_key, 0, 0))
{
return_val= 1; /* we failed, out of memory? */
goto end;
}
/* Initialize the mem root for data */
init_alloc_root(&mem, ACL_ALLOC_BLOCK_SIZE, 0);
/*
at this point, the cache is initialised, let it be known
*/
servers_cache_initialised= TRUE;
if (dont_read_servers_table)
goto end;
/*
To be able to run this from boot, we allocate a temporary THD
*/
if (!(thd=new THD))
DBUG_RETURN(1);
thd->thread_stack= (char*) &thd;
thd->store_globals();
/*
It is safe to call servers_reload() since servers_* arrays and hashes which
will be freed there are global static objects and thus are initialized
by zeros at startup.
*/
return_val= servers_reload(thd);
delete thd;
/* Remember that we don't have a THD */
my_pthread_setspecific_ptr(THR_THD, 0);
end:
DBUG_RETURN(return_val);
}
/*
Initialize server structures
SYNOPSIS
servers_load()
thd Current thread
tables List containing open "mysql.servers"
RETURN VALUES
FALSE Success
TRUE Error
*/
static my_bool servers_load(THD *thd, TABLE_LIST *tables)
{
TABLE *table;
READ_RECORD read_record_info;
my_bool return_val= TRUE;
DBUG_ENTER("servers_load");
if (!servers_cache_initialised)
DBUG_RETURN(0);
/* need to figure out how to utilise this variable */
servers_version++; /* servers updated */
/* first, send all cached rows to sleep with the fishes, oblivion!
I expect this crappy comment replaced */
free_root(&mem, MYF(MY_MARK_BLOCKS_FREE));
my_hash_reset(&servers_cache);
init_read_record(&read_record_info,thd,table=tables[0].table,NULL,1,0);
while (!(read_record_info.read_record(&read_record_info)))
{
/* return_val is already TRUE, so no need to set */
if ((get_server_from_table_to_cache(table)))
goto end;
}
return_val=0;
end:
end_read_record(&read_record_info);
DBUG_RETURN(return_val);
}
/*
Forget current servers cache and read new servers
from the conneciton table.
SYNOPSIS
servers_reload()
thd Current thread
NOTE
All tables of calling thread which were open and locked by LOCK TABLES
statement will be unlocked and closed.
This function is also used for initialization of structures responsible
for user/db-level privilege checking.
RETURN VALUE
FALSE Success
TRUE Failure
*/
my_bool servers_reload(THD *thd)
{
TABLE_LIST tables[1];
my_bool return_val= 1;
DBUG_ENTER("servers_reload");
if (thd->locked_tables)
{ // Can't have locked tables here
thd->lock=thd->locked_tables;
thd->locked_tables=0;
close_thread_tables(thd);
}
/*
To avoid deadlocks we should obtain table locks before
obtaining servers_cache->lock mutex.
*/
bzero((char*) tables, sizeof(tables));
tables[0].alias= tables[0].table_name= (char*) "servers";
tables[0].db= (char*) "mysql";
tables[0].lock_type= TL_READ;
if (simple_open_n_lock_tables(thd, tables))
{
sql_print_error("Fatal error: Can't open and lock privilege tables: %s",
thd->net.last_error);
goto end;
}
DBUG_PRINT("info", ("locking servers_cache"));
VOID(pthread_mutex_lock(&servers_cache_mutex));
//old_servers_cache= servers_cache;
//old_mem=mem;
if ((return_val= servers_load(thd, tables)))
{ // Error. Revert to old list
/* blast, for now, we have no servers, discuss later way to preserve */
DBUG_PRINT("error",("Reverting to old privileges"));
servers_free(); /* purecov: inspected */
}
DBUG_PRINT("info", ("unlocking servers_cache"));
VOID(pthread_mutex_unlock(&servers_cache_mutex));
end:
close_thread_tables(thd);
DBUG_RETURN(return_val);
}
/*
Initialize structures responsible for servers used in federated
server scheme information for them from the server
table in the 'mysql' database.
SYNOPSIS
get_server_from_table_to_cache()
TABLE *table open table pointer
NOTES
This function takes a TABLE pointer (pointing to an opened
table). With this open table, a FOREIGN_SERVER struct pointer
is allocated into root memory, then each member of the FOREIGN_SERVER
struct is populated. A char pointer takes the return value of get_field
for each column we're interested in obtaining, and if that pointer
isn't 0x0, the FOREIGN_SERVER member is set to that value, otherwise,
is set to the value of an empty string, since get_field would set it to
0x0 if the column's value is empty, even if the default value for that
column is NOT NULL.
RETURN VALUES
0 ok
1 could not insert server struct into global servers cache
*/
my_bool get_server_from_table_to_cache(TABLE *table)
{
/* alloc a server struct */
char *ptr;
char *blank= (char*)"";
FOREIGN_SERVER *server= (FOREIGN_SERVER *)alloc_root(&mem,
sizeof(FOREIGN_SERVER));
DBUG_ENTER("get_server_from_table_to_cache");
/* get each field into the server struct ptr */
server->server_name= get_field(&mem, table->field[0]);
server->server_name_length= strlen(server->server_name);
ptr= get_field(&mem, table->field[1]);
server->host= ptr ? ptr : blank;
ptr= get_field(&mem, table->field[2]);
server->db= ptr ? ptr : blank;
ptr= get_field(&mem, table->field[3]);
server->username= ptr ? ptr : blank;
ptr= get_field(&mem, table->field[4]);
server->password= ptr ? ptr : blank;
ptr= get_field(&mem, table->field[5]);
server->sport= ptr ? ptr : blank;
server->port= server->sport ? atoi(server->sport) : 0;
ptr= get_field(&mem, table->field[6]);
server->socket= ptr ? ptr : blank;
ptr= get_field(&mem, table->field[7]);
server->scheme= ptr ? ptr : blank;
ptr= get_field(&mem, table->field[8]);
server->owner= ptr ? ptr : blank;
DBUG_PRINT("info", ("server->server_name %s", server->server_name));
DBUG_PRINT("info", ("server->host %s", server->host));
DBUG_PRINT("info", ("server->db %s", server->db));
DBUG_PRINT("info", ("server->username %s", server->username));
DBUG_PRINT("info", ("server->password %s", server->password));
DBUG_PRINT("info", ("server->socket %s", server->socket));
if (my_hash_insert(&servers_cache, (byte*) server))
{
DBUG_PRINT("info", ("had a problem inserting server %s at %lx",
server->server_name, server));
// error handling needed here
DBUG_RETURN(TRUE);
}
DBUG_RETURN(FALSE);
}
/*
SYNOPSIS
server_exists_in_table()
THD *thd - thread pointer
LEX_SERVER_OPTIONS *server_options - pointer to Lex->server_options
NOTES
This function takes a LEX_SERVER_OPTIONS struct, which is very much the
same type of structure as a FOREIGN_SERVER, it contains the values parsed
in any one of the [CREATE|DELETE|DROP] SERVER statements. Using the
member "server_name", index_read_idx either founds the record and returns
1, or doesn't find the record, and returns 0
RETURN VALUES
0 record not found
1 record found
*/
my_bool server_exists_in_table(THD *thd, LEX_SERVER_OPTIONS *server_options)
{
byte server_key[MAX_KEY_LENGTH];
int result= 1;
int error;
TABLE_LIST tables;
TABLE *table;
DBUG_ENTER("server_exists");
bzero((char*) &tables, sizeof(tables));
tables.db= (char*) "mysql";
tables.alias= tables.table_name= (char*) "servers";
/* need to open before acquiring THR_LOCK_plugin or it will deadlock */
if (! (table= open_ltable(thd, &tables, TL_WRITE)))
DBUG_RETURN(TRUE);
rw_wrlock(&THR_LOCK_servers);
VOID(pthread_mutex_lock(&servers_cache_mutex));
/* set the field that's the PK to the value we're looking for */
table->field[0]->store(server_options->server_name,
server_options->server_name_length,
system_charset_info);
if ((error= table->file->index_read_idx(table->record[0], 0,
(byte *)table->field[0]->ptr,
table->key_info[0].key_length,
HA_READ_KEY_EXACT)))
{
if (error != HA_ERR_KEY_NOT_FOUND && error != HA_ERR_END_OF_FILE)
{
table->file->print_error(error, MYF(0));
result= -1;
}
result= 0;
DBUG_PRINT("info",("record for server '%s' not found!",
server_options->server_name));
}
VOID(pthread_mutex_unlock(&servers_cache_mutex));
rw_unlock(&THR_LOCK_servers);
DBUG_RETURN(result);
}
/*
SYNOPSIS
insert_server()
THD *thd - thread pointer
FOREIGN_SERVER *server - pointer to prepared FOREIGN_SERVER struct
NOTES
This function takes a server object that is ready to be inserted
both into the mysql.servers table and the servers cache.
RETURN VALUES
0 - no error
other - error code
*/
int insert_server(THD *thd, FOREIGN_SERVER *server)
{
byte server_key[MAX_KEY_LENGTH];
int error;
TABLE_LIST tables;
TABLE *table;
DBUG_ENTER("insert_server");
bzero((char*) &tables, sizeof(tables));
tables.db= (char*) "mysql";
tables.alias= tables.table_name= (char*) "servers";
/* need to open before acquiring THR_LOCK_plugin or it will deadlock */
if (! (table= open_ltable(thd, &tables, TL_WRITE)))
DBUG_RETURN(TRUE);
/* lock mutex to make sure no changes happen */
VOID(pthread_mutex_lock(&servers_cache_mutex));
/* lock table */
rw_wrlock(&THR_LOCK_servers);
/* insert the server into the table */
if ((error= insert_server_record(table, server)))
goto end;
/* insert the server into the cache */
if ((error= insert_server_record_into_cache(server)))
goto end;
end:
/* unlock the table */
rw_unlock(&THR_LOCK_servers);
VOID(pthread_mutex_unlock(&servers_cache_mutex));
DBUG_RETURN(error);
}
/*
SYNOPSIS
int insert_server_record_into_cache()
FOREIGN_SERVER *server
NOTES
This function takes a FOREIGN_SERVER pointer and inserts it into
the global servers cache
RETURN VALUE
0 - no error
>0 - error code
*/
int insert_server_record_into_cache(FOREIGN_SERVER *server)
{
int error=0;
DBUG_ENTER("insert_server_record_into_cache");
/*
We succeded in insertion of the server to the table, now insert
the server to the cache
*/
DBUG_PRINT("info", ("inserting server %s at %lx, length %d",
server->server_name, server,
server->server_name_length));
if (my_hash_insert(&servers_cache, (byte*) server))
{
DBUG_PRINT("info", ("had a problem inserting server %s at %lx",
server->server_name, server));
// error handling needed here
error= 1;
}
DBUG_RETURN(error);
}
/*
SYNOPSIS
store_server_fields()
TABLE *table
FOREIGN_SERVER *server
NOTES
RETURN VALUE
VOID
*/
void store_server_fields(TABLE *table, FOREIGN_SERVER *server)
{
/*
"server" has already been prepped by prepare_server_struct_for_<>
so, all we need to do is check if the value is set (> -1 for port)
If this happens to be an update, only the server members that
have changed will be set. If an insert, then all will be set,
even if with empty strings
*/
if (server->host)
table->field[1]->store(server->host,
(uint) strlen(server->host), system_charset_info);
if (server->db)
table->field[2]->store(server->db,
(uint) strlen(server->db), system_charset_info);
if (server->username)
table->field[3]->store(server->username,
(uint) strlen(server->username), system_charset_info);
if (server->password)
table->field[4]->store(server->password,
(uint) strlen(server->password), system_charset_info);
if (server->port > -1)
table->field[5]->store(server->port);
if (server->socket)
table->field[6]->store(server->socket,
(uint) strlen(server->socket), system_charset_info);
if (server->scheme)
table->field[7]->store(server->scheme,
(uint) strlen(server->scheme), system_charset_info);
if (server->owner)
table->field[8]->store(server->owner,
(uint) strlen(server->owner), system_charset_info);
}
/*
SYNOPSIS
insert_server_record()
TABLE *table
FOREIGN_SERVER *server
NOTES
RETURN VALUE
0 - no errors
*/
int insert_server_record(TABLE *table, FOREIGN_SERVER *server)
{
int error;
DBUG_ENTER("insert_server_record");
/* set the field that's the PK to the value we're looking for */
table->field[0]->store(server->server_name,
server->server_name_length,
system_charset_info);
if ((error= table->file->index_read_idx(table->record[0], 0,
(byte *)table->field[0]->ptr,
table->key_info[0].key_length,
HA_READ_KEY_EXACT)))
{
if (error != HA_ERR_KEY_NOT_FOUND && error != HA_ERR_END_OF_FILE)
{
table->file->print_error(error, MYF(0));
error= 1;
}
store_server_fields(table, server);
DBUG_PRINT("info",("record for server '%s' not found!",
server->server_name));
if ((error=table->file->ha_write_row(table->record[0])))
{
table->file->print_error(error, MYF(0));
}
else
error= 0;
}
else
error= ER_FOREIGN_SERVER_EXISTS;
DBUG_RETURN(error);
}
/*
SYNOPSIS
drop_server()
THD *thd
LEX_SERVER_OPTIONS *server_options
NOTES
RETURN VALUE
0 - no error
*/
int drop_server(THD *thd, LEX_SERVER_OPTIONS *server_options)
{
byte server_key[MAX_KEY_LENGTH];
int error;
TABLE_LIST tables;
TABLE *table;
DBUG_ENTER("drop_server");
DBUG_PRINT("info", ("server name server->server_name %s",
server_options->server_name));
bzero((char*) &tables, sizeof(tables));
tables.db= (char*) "mysql";
tables.alias= tables.table_name= (char*) "servers";
/* need to open before acquiring THR_LOCK_plugin or it will deadlock */
if (! (table= open_ltable(thd, &tables, TL_WRITE)))
DBUG_RETURN(TRUE);
rw_wrlock(&THR_LOCK_servers);
VOID(pthread_mutex_lock(&servers_cache_mutex));
if ((error= delete_server_record(table,
server_options->server_name,
server_options->server_name_length)))
goto end;
if ((error= delete_server_record_in_cache(server_options)))
goto end;
end:
VOID(pthread_mutex_unlock(&servers_cache_mutex));
rw_unlock(&THR_LOCK_servers);
DBUG_RETURN(error);
}
/*
SYNOPSIS
delete_server_record_in_cache()
LEX_SERVER_OPTIONS *server_options
NOTES
RETURN VALUE
0 - no error
*/
int delete_server_record_in_cache(LEX_SERVER_OPTIONS *server_options)
{
int error= 0;
FOREIGN_SERVER *server;
DBUG_ENTER("delete_server_record_in_cache");
DBUG_PRINT("info",("trying to obtain server name %s length %d",
server_options->server_name,
server_options->server_name_length));
if (!(server= (FOREIGN_SERVER *) hash_search(&servers_cache,
(byte*) server_options->server_name,
server_options->server_name_length)))
{
DBUG_PRINT("info", ("server_name %s length %d not found!",
server_options->server_name,
server_options->server_name_length));
// what should be done if not found in the cache?
}
/*
We succeded in deletion of the server to the table, now delete
the server from the cache
*/
DBUG_PRINT("info",("deleting server %s length %d",
server->server_name,
server->server_name_length));
if (server)
VOID(hash_delete(&servers_cache, (byte*) server));
servers_version++; /* servers updated */
DBUG_RETURN(error);
}
/*
SYNOPSIS
update_server()
THD *thd
FOREIGN_SERVER *existing
FOREIGN_SERVER *altered
NOTES
RETURN VALUE
0 - no error
*/
int update_server(THD *thd, FOREIGN_SERVER *existing, FOREIGN_SERVER *altered)
{
int error= 0;
TABLE *table;
TABLE_LIST tables;
DBUG_ENTER("update_server");
bzero((char*) &tables, sizeof(tables));
tables.db= (char*)"mysql";
tables.alias= tables.table_name= (char*)"servers";
if (!(table= open_ltable(thd, &tables, TL_WRITE)))
DBUG_RETURN(1);
rw_wrlock(&THR_LOCK_servers);
if ((error= update_server_record(table, altered)))
goto end;
update_server_record_in_cache(existing, altered);
end:
rw_unlock(&THR_LOCK_servers);
DBUG_RETURN(error);
}
/*
SYNOPSIS
update_server_record_in_cache()
FOREIGN_SERVER *existing
FOREIGN_SERVER *altered
NOTES
RETURN VALUE
0 - no error
*/
int update_server_record_in_cache(FOREIGN_SERVER *existing,
FOREIGN_SERVER *altered)
{
int error= 0;
DBUG_ENTER("update_server_record_in_cache");
/*
update the members that haven't been change in the altered server struct
with the values of the existing server struct
*/
merge_server_struct(existing, altered);
/*
delete the existing server struct from the server cache
*/
VOID(hash_delete(&servers_cache, (byte*)existing));
/*
Insert the altered server struct into the server cache
*/
if (my_hash_insert(&servers_cache, (byte*)altered))
{
DBUG_PRINT("info", ("had a problem inserting server %s at %lx",
altered->server_name, altered));
error= 1;
}
servers_version++; /* servers updated */
DBUG_RETURN(error);
}
/*
SYNOPSIS
merge_server_struct()
FOREIGN_SERVER *from
FOREIGN_SERVER *to
NOTES
RETURN VALUE
VOID
*/
void merge_server_struct(FOREIGN_SERVER *from, FOREIGN_SERVER *to)
{
DBUG_ENTER("merge_server_struct");
if (!to->host)
to->host= strdup_root(&mem, from->host);
if (!to->db)
to->db= strdup_root(&mem, from->db);
if (!to->username)
to->username= strdup_root(&mem, from->username);
if (!to->password)
to->password= strdup_root(&mem, from->password);
if (to->port == -1)
to->port= from->port;
if (!to->socket)
to->socket= strdup_root(&mem, from->socket);
if (!to->scheme)
to->scheme= strdup_root(&mem, from->scheme);
if (!to->owner)
to->owner= strdup_root(&mem, from->owner);
DBUG_VOID_RETURN;
}
/*
SYNOPSIS
update_server_record()
TABLE *table
FOREIGN_SERVER *server
NOTES
RETURN VALUE
0 - no error
*/
int update_server_record(TABLE *table, FOREIGN_SERVER *server)
{
int error=0;
DBUG_ENTER("update_server_record");
/* set the field that's the PK to the value we're looking for */
table->field[0]->store(server->server_name,
server->server_name_length,
system_charset_info);
if ((error= table->file->index_read_idx(table->record[0], 0,
(byte *)table->field[0]->ptr,
table->key_info[0].key_length,
HA_READ_KEY_EXACT)))
{
if (error != HA_ERR_KEY_NOT_FOUND && error != HA_ERR_END_OF_FILE)
{
table->file->print_error(error, MYF(0));
error= 1;
}
DBUG_PRINT("info",("server not found!"));
error= ER_FOREIGN_SERVER_DOESNT_EXIST;
}
else
{
/* ok, so we can update since the record exists in the table */
store_record(table,record[1]);
store_server_fields(table, server);
if ((error=table->file->ha_update_row(table->record[1],table->record[0])))
{
DBUG_PRINT("info",("problems with ha_update_row %d", error));
goto end;
}
}
end:
DBUG_RETURN(error);
}
/*
SYNOPSIS
delete_server_record()
TABLE *table
char *server_name
int server_name_length
NOTES
RETURN VALUE
0 - no error
*/
int delete_server_record(TABLE *table,
char *server_name,
int server_name_length)
{
int error= 0;
DBUG_ENTER("delete_server_record");
/* set the field that's the PK to the value we're looking for */
table->field[0]->store(server_name, server_name_length, system_charset_info);
if ((error= table->file->index_read_idx(table->record[0], 0,
(byte *)table->field[0]->ptr,
table->key_info[0].key_length,
HA_READ_KEY_EXACT)))
{
if (error != HA_ERR_KEY_NOT_FOUND && error != HA_ERR_END_OF_FILE)
{
table->file->print_error(error, MYF(0));
error= 1;
}
DBUG_PRINT("info",("server not found!"));
error= ER_FOREIGN_SERVER_DOESNT_EXIST;
}
else
{
if ((error= table->file->ha_delete_row(table->record[0])))
table->file->print_error(error, MYF(0));
}
end:
DBUG_RETURN(error);
}
/*
SYNOPSIS
create_server()
THD *thd
LEX_SERVER_OPTIONS *server_options
NOTES
RETURN VALUE
0 - no error
*/
int create_server(THD *thd, LEX_SERVER_OPTIONS *server_options)
{
int error;
FOREIGN_SERVER *server;
DBUG_ENTER("create_server");
DBUG_PRINT("info", ("server_options->server_name %s",
server_options->server_name));
server= (FOREIGN_SERVER *)alloc_root(&mem,
sizeof(FOREIGN_SERVER));
if ((error= prepare_server_struct_for_insert(server_options, server)))
goto end;
if ((error= insert_server(thd, server)))
goto end;
DBUG_PRINT("info", ("error returned %d", error));
end:
DBUG_RETURN(error);
}
/*
SYNOPSIS
alter_server()
THD *thd
LEX_SERVER_OPTIONS *server_options
NOTES
RETURN VALUE
0 - no error
*/
int alter_server(THD *thd, LEX_SERVER_OPTIONS *server_options)
{
int error= 0;
FOREIGN_SERVER *altered, *existing;
DBUG_ENTER("alter_server");
DBUG_PRINT("info", ("server_options->server_name %s",
server_options->server_name));
altered= (FOREIGN_SERVER *)alloc_root(&mem,
sizeof(FOREIGN_SERVER));
VOID(pthread_mutex_lock(&servers_cache_mutex));
if (!(existing= (FOREIGN_SERVER *) hash_search(&servers_cache,
(byte*) server_options->server_name,
server_options->server_name_length)))
{
error= ER_FOREIGN_SERVER_DOESNT_EXIST;
goto end;
}
if ((error= prepare_server_struct_for_update(server_options, existing, altered)))
goto end;
if ((error= update_server(thd, existing, altered)))
goto end;
end:
DBUG_PRINT("info", ("error returned %d", error));
VOID(pthread_mutex_unlock(&servers_cache_mutex));
DBUG_RETURN(error);
}
/*
SYNOPSIS
prepare_server_struct_for_insert()
LEX_SERVER_OPTIONS *server_options
FOREIGN_SERVER *server
NOTES
RETURN VALUE
0 - no error
*/
int prepare_server_struct_for_insert(LEX_SERVER_OPTIONS *server_options,
FOREIGN_SERVER *server)
{
int error;
char *unset_ptr= (char*)"";
DBUG_ENTER("prepare_server_struct");
error= 0;
/* these two MUST be set */
server->server_name= strdup_root(&mem, server_options->server_name);
server->server_name_length= server_options->server_name_length;
server->host= server_options->host ?
strdup_root(&mem, server_options->host) : unset_ptr;
server->db= server_options->db ?
strdup_root(&mem, server_options->db) : unset_ptr;
server->username= server_options->username ?
strdup_root(&mem, server_options->username) : unset_ptr;
server->password= server_options->password ?
strdup_root(&mem, server_options->password) : unset_ptr;
/* set to 0 if not specified */
server->port= server_options->port > -1 ?
server_options->port : 0;
server->socket= server_options->socket ?
strdup_root(&mem, server_options->socket) : unset_ptr;
server->scheme= server_options->scheme ?
strdup_root(&mem, server_options->scheme) : unset_ptr;
server->owner= server_options->owner ?
strdup_root(&mem, server_options->owner) : unset_ptr;
DBUG_RETURN(error);
}
/*
SYNOPSIS
prepare_server_struct_for_update()
LEX_SERVER_OPTIONS *server_options
NOTES
RETURN VALUE
0 - no error
*/
int prepare_server_struct_for_update(LEX_SERVER_OPTIONS *server_options,
FOREIGN_SERVER *existing,
FOREIGN_SERVER *altered)
{
int error;
DBUG_ENTER("prepare_server_struct_for_update");
error= 0;
altered->server_name= strdup_root(&mem, server_options->server_name);
altered->server_name_length= server_options->server_name_length;
DBUG_PRINT("info", ("existing name %s altered name %s",
existing->server_name, altered->server_name));
/*
The logic here is this: is this value set AND is it different
than the existing value?
*/
altered->host=
(server_options->host && (strcmp(server_options->host, existing->host))) ?
strdup_root(&mem, server_options->host) : 0;
altered->db=
(server_options->db && (strcmp(server_options->db, existing->db))) ?
strdup_root(&mem, server_options->db) : 0;
altered->username=
(server_options->username &&
(strcmp(server_options->username, existing->username))) ?
strdup_root(&mem, server_options->username) : 0;
altered->password=
(server_options->password &&
(strcmp(server_options->password, existing->password))) ?
strdup_root(&mem, server_options->password) : 0;
/*
port is initialised to -1, so if unset, it will be -1
*/
altered->port= (server_options->port > -1 &&
server_options->port != existing->port) ?
server_options->port : -1;
altered->socket=
(server_options->socket &&
(strcmp(server_options->socket, existing->socket))) ?
strdup_root(&mem, server_options->socket) : 0;
altered->scheme=
(server_options->scheme &&
(strcmp(server_options->scheme, existing->scheme))) ?
strdup_root(&mem, server_options->scheme) : 0;
altered->owner=
(server_options->owner &&
(strcmp(server_options->owner, existing->owner))) ?
strdup_root(&mem, server_options->owner) : 0;
DBUG_RETURN(error);
}
/*
SYNOPSIS
servers_free()
bool end
NOTES
RETURN VALUE
void
*/
void servers_free(bool end)
{
DBUG_ENTER("servers_free");
if (!servers_cache_initialised)
DBUG_VOID_RETURN;
VOID(pthread_mutex_destroy(&servers_cache_mutex));
servers_cache_initialised=0;
free_root(&mem,MYF(0));
hash_free(&servers_cache);
DBUG_VOID_RETURN;
}
/*
SYNOPSIS
get_server_by_name()
const char *server_name
NOTES
RETURN VALUE
FOREIGN_SERVER *
*/
FOREIGN_SERVER *get_server_by_name(const char *server_name)
{
ulong error_num=0;
uint i, server_name_length;
FOREIGN_SERVER *server;
DBUG_ENTER("get_server_by_name");
DBUG_PRINT("info", ("server_name %s", server_name));
server_name_length= strlen(server_name);
if (! server_name || !strlen(server_name))
{
DBUG_PRINT("info", ("server_name not defined!"));
error_num= 1;
DBUG_RETURN((FOREIGN_SERVER *)NULL);
}
DBUG_PRINT("info", ("locking servers_cache"));
VOID(pthread_mutex_lock(&servers_cache_mutex));
if (!(server= (FOREIGN_SERVER *) hash_search(&servers_cache,
(byte*) server_name,
server_name_length)))
{
DBUG_PRINT("info", ("server_name %s length %d not found!",
server_name, server_name_length));
server= (FOREIGN_SERVER *) NULL;
}
DBUG_PRINT("info", ("unlocking servers_cache"));
VOID(pthread_mutex_unlock(&servers_cache_mutex));
DBUG_RETURN(server);
}
--- New file ---
+++ sql/sql_servers.h 06/02/09 18:29:00
/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
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; either version 2 of the License, or
(at your option) any later version.
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 "slave.h" // for tables_ok(), rpl_filter
/* structs */
typedef struct st_federated_server
{
char *server_name;
long port;
uint server_name_length;
char *db, *scheme, *username, *password, *socket, *owner, *host, *sport;
} FOREIGN_SERVER;
/* cache handlers */
my_bool servers_init(bool dont_read_server_table);
static my_bool servers_load(THD *thd, TABLE_LIST *tables);
my_bool servers_reload(THD *thd);
my_bool get_server_from_table_to_cache(TABLE *table);
void servers_free(bool end=0);
/* insert functions */
int create_server(THD *thd, LEX_SERVER_OPTIONS *server_options);
int insert_server(THD *thd, FOREIGN_SERVER *server_options);
int insert_server_record(TABLE *table, FOREIGN_SERVER *server);
int insert_server_record_into_cache(FOREIGN_SERVER server);
void store_server_fields_for_insert(TABLE *table, FOREIGN_SERVER *server);
void store_server_fields_for_insert(TABLE *table,
FOREIGN_SERVER *existing,
FOREIGN_SERVER *altered);
int prepare_server_struct_for_insert(LEX_SERVER_OPTIONS *server_options,
FOREIGN_SERVER *server);
/* drop functions */
int drop_server(THD *thd, LEX_SERVER_OPTIONS *server_options);
int delete_server_record(TABLE *table,
char *server_name,
int server_name_length);
int delete_server_record_in_cache(LEX_SERVER_OPTIONS *server_options);
/* update functions */
int alter_server(THD *thd, LEX_SERVER_OPTIONS *server_options);
int prepare_server_struct_for_update(LEX_SERVER_OPTIONS *server_options,
FOREIGN_SERVER *existing,
FOREIGN_SERVER *altered);
int update_server(THD *thd, FOREIGN_SERVER *existing, FOREIGN_SERVER *altered);
int update_server_record(TABLE *table, FOREIGN_SERVER *server);
int update_server_record_in_cache(FOREIGN_SERVER *existing,
FOREIGN_SERVER *altered);
/* utility functions */
void merge_server_struct(FOREIGN_SERVER *from, FOREIGN_SERVER *to);
FOREIGN_SERVER *get_server_by_name(const char *server_name);
my_bool server_exists_in_table(THD *thd, char *server_name);
--- 1.1/sql/sql_connections.cc 2006-01-31 16:33:25 -08:00
+++ 1.2/BitKeeper/deleted/.del-sql_connections.cc~4ee6cd6ad37a5cd1 2006-02-09 16:57:08 -08:00
@@ -16,7 +16,7 @@
/*
- The connections are saved in the system table "connections"
+ The servers are saved in the system table "servers"
*/
#include "mysql_priv.h"
@@ -26,57 +26,57 @@
#include "sp_head.h"
#include "sp.h"
-HASH connections_cache;
-pthread_mutex_t connections_cache_mutex; // To init the hash
-uint connections_cache_initialised=FALSE;
-/* Version of connection table. incremented by connections_load */
-static uint connections_version=0;
+HASH servers_cache;
+pthread_mutex_t servers_cache_mutex; // To init the hash
+uint servers_cache_initialised=FALSE;
+/* Version of server table. incremented by servers_load */
+static uint servers_version=0;
static MEM_ROOT mem;
static bool initialized=0;
-static my_bool connections_load(THD *thd, TABLE_LIST *tables);
+static my_bool servers_load(THD *thd, TABLE_LIST *tables);
-static byte *connections_cache_get_key(SQL_CONNECTION *connection, uint *length,
+static byte *servers_cache_get_key(FOREIGN_SERVER *server, uint *length,
my_bool not_used __attribute__((unused)))
{
- DBUG_ENTER("connections_cache_get_key");
- DBUG_PRINT("info", ("connection_name_length %d connection_name %s",
- connection->connection_name_length,
- connection->connection_name));
+ DBUG_ENTER("servers_cache_get_key");
+ DBUG_PRINT("info", ("server_name_length %d server_name %s",
+ server->server_name_length,
+ server->server_name));
- *length= (uint) connection->connection_name_length;
- DBUG_RETURN((byte*) connection->connection_name);
+ *length= (uint) server->server_name_length;
+ DBUG_RETURN((byte*) server->server_name);
}
/*
- Initialize structures responsible for connections used in federated
- connection scheme information for them from the connection
+ Initialize structures responsible for servers used in federated
+ server scheme information for them from the server
table in the 'mysql' database.
SYNOPSIS
- connections_init()
- dont_read_connection_table TRUE if we want to skip loading data from
- connection table and disable privilege checking.
+ servers_init()
+ dont_read_server_table TRUE if we want to skip loading data from
+ server table and disable privilege checking.
NOTES
This function is mostly responsible for preparatory steps, main work
- on initialization and grants loading is done in connections_reload().
+ on initialization and grants loading is done in servers_reload().
RETURN VALUES
0 ok
- 1 Could not initialize connections
+ 1 Could not initialize servers
*/
-my_bool connections_init(bool dont_read_connections_table)
+my_bool servers_init(bool dont_read_servers_table)
{
THD *thd;
my_bool return_val= 0;
- DBUG_ENTER("connections_init");
+ DBUG_ENTER("servers_init");
- if (pthread_mutex_init(&connections_cache_mutex, MY_MUTEX_INIT_FAST))
+ if (pthread_mutex_init(&servers_cache_mutex, MY_MUTEX_INIT_FAST))
DBUG_RETURN(1);
- if (hash_init(&connections_cache, system_charset_info, 32, 0, 0,
- (hash_get_key) connections_cache_get_key, 0, 0))
+ if (hash_init(&servers_cache, system_charset_info, 32, 0, 0,
+ (hash_get_key) servers_cache_get_key, 0, 0))
{
return_val= 1; /* we failed, out of memory? */
goto end;
@@ -85,14 +85,14 @@
/* Initialize the mem root for data */
init_alloc_root(&mem, ACL_ALLOC_BLOCK_SIZE, 0);
- connections_cache_initialised= TRUE;
+ servers_cache_initialised= TRUE;
- if (dont_read_connections_table)
+ if (dont_read_servers_table)
{
DBUG_RETURN(0);
}
- if (dont_read_connections_table)
+ if (dont_read_servers_table)
goto end;
/*
@@ -103,11 +103,11 @@
thd->thread_stack= (char*) &thd;
thd->store_globals();
/*
- It is safe to call connections_reload() since connections_* arrays and hashes which
+ It is safe to call servers_reload() since servers_* arrays and hashes which
will be freed there are global static objects and thus are initialized
by zeros at startup.
*/
- return_val= connections_reload(thd);
+ return_val= servers_reload(thd);
delete thd;
/* Remember that we don't have a THD */
my_pthread_setspecific_ptr(THR_THD, 0);
@@ -117,35 +117,35 @@
}
/*
- Initialize connection structures
+ Initialize server structures
SYNOPSIS
- connections_load()
+ servers_load()
thd Current thread
- tables List containing open "mysql.connections"
+ tables List containing open "mysql.servers"
RETURN VALUES
FALSE Success
TRUE Error
*/
-static my_bool connections_load(THD *thd, TABLE_LIST *tables)
+static my_bool servers_load(THD *thd, TABLE_LIST *tables)
{
TABLE *table;
READ_RECORD read_record_info;
my_bool return_val= 1;
- DBUG_ENTER("connections_load");
+ DBUG_ENTER("servers_load");
- if (!connections_cache_initialised)
+ if (!servers_cache_initialised)
DBUG_RETURN(0);
- connections_version++; /* connections updated */
+ servers_version++; /* servers updated */
/* first, send all cached rows to sleep with the fishes, oblivion!
I expect this crappy comment replaced */
free_root(&mem, MYF(MY_MARK_BLOCKS_FREE));
- my_hash_reset(&connections_cache);
+ my_hash_reset(&servers_cache);
init_read_record(&read_record_info,thd,table=tables[0].table,NULL,1,0);
while (!(read_record_info.read_record(&read_record_info)))
@@ -154,34 +154,34 @@
/* simple mistake, my_hash_insert expects a pointer, it does
not copy the data anywhere. Now if you was using dynamic arrays
- it would be a different matter. So here, I allocate connection
+ it would be a different matter. So here, I allocate server
as a pointer. Obviously, remove this comment */
- SQL_CONNECTION *connection= (SQL_CONNECTION *)alloc_root(&mem,
- sizeof(SQL_CONNECTION));
+ FOREIGN_SERVER *server= (FOREIGN_SERVER *)alloc_root(&mem,
+ sizeof(FOREIGN_SERVER));
- connection->connection_name= get_field(&mem, table->field[0]);
- connection->connection_name_length= strlen(connection->connection_name);
+ server->server_name= get_field(&mem, table->field[0]);
+ server->server_name_length= strlen(server->server_name);
//table->field[0]->field_length
/// table->field[0]->charset()->mbmaxlen;
- connection->host= get_field(&mem, table->field[1]);
- connection->db= get_field(&mem, table->field[2]);
- connection->username= get_field(&mem, table->field[3]);
- connection->password= get_field(&mem, table->field[4]);
- connection->sport= get_field(&mem, table->field[5]);
- connection->port= connection->sport ? atoi(connection->sport) : 0;
- connection->socket= get_field(&mem, table->field[6]);
- connection->scheme= get_field(&mem, table->field[7]);
- connection->owner= get_field(&mem, table->field[8]);
- DBUG_PRINT("info", ("connection->connection_name %s", connection->connection_name));
- DBUG_PRINT("info", ("connection->host %s", connection->host));
- DBUG_PRINT("info", ("connection->db %s", connection->db));
- DBUG_PRINT("info", ("connection->username %s", connection->username));
- DBUG_PRINT("info", ("connection->password %s", connection->password));
- if (my_hash_insert(&connections_cache, (byte*) connection))
+ server->host= get_field(&mem, table->field[1]);
+ server->db= get_field(&mem, table->field[2]);
+ server->username= get_field(&mem, table->field[3]);
+ server->password= get_field(&mem, table->field[4]);
+ server->sport= get_field(&mem, table->field[5]);
+ server->port= server->sport ? atoi(server->sport) : 0;
+ server->socket= get_field(&mem, table->field[6]);
+ server->scheme= get_field(&mem, table->field[7]);
+ server->owner= get_field(&mem, table->field[8]);
+ DBUG_PRINT("info", ("server->server_name %s", server->server_name));
+ DBUG_PRINT("info", ("server->host %s", server->host));
+ DBUG_PRINT("info", ("server->db %s", server->db));
+ DBUG_PRINT("info", ("server->username %s", server->username));
+ DBUG_PRINT("info", ("server->password %s", server->password));
+ if (my_hash_insert(&servers_cache, (byte*) server))
{
- DBUG_PRINT("info", ("had a problem inserting connection %s at %lx",
- connection->connection_name, connection));
+ DBUG_PRINT("info", ("had a problem inserting server %s at %lx",
+ server->server_name, server));
// error handling needed here
return_val= 1;
goto end;
@@ -196,35 +196,78 @@
DBUG_RETURN(return_val);
}
-my_bool create_server(LEX_CONNECTION_OPTIONS *conn_options)
+/*
+ */
+my_bool server_exists(char *server_name)
+{
+ FOREIGN_SERVER *test_conn;
+ DBUG_ENTER("server_exists");
+
+ if ((test_conn= get_server_by_name(server_name)))
+ DBUG_RETURN(TRUE)
+
+ DBUG_RETURN(FALSE)
+}
+
+/*
+ Insert a server
+*/
+my_bool insert_server(LEX_CONNETION_OPTIONS *conn_options)
+{
+ DBUG_ENTER("insert_server");
+ FOREIGN_SERVER *server= (FOREIGN_SERVER *)alloc_root(&mem,
+ sizeof(FOREIGN_SERVER));
+ server->server_name= conn_options->server_name;
+
+
+ DBUG_RETURN(FALSE);
+}
+/*
+*/
+int create_server(LEX_CONNECTION_OPTIONS *conn_options)
{
- DBUG_ENTER("connection_create");
- DBUG_PRINT("info", ("conn_options->server_name %s", conn_options->server_name));
+ int err_code;
+ DBUG_ENTER("server_create");
+ DBUG_PRINT("info", ("conn_options->server_name %s",
+ conn_options->server_name));
DBUG_PRINT("info", ("conn_options->scheme %s", conn_options->scheme));
+ /*
+ first, check if the server exists before trying to create it
+ */
+ if (server_exists(conn_options->server_name))
+ {
+ DBUG_PRINT("info", ("server '%s' already exists",
+ conn_options->server_name));
+ err_code= ER_FOREIGN_SERVER_EXISTS;
+ DBUG_RETURN(err_code);
+ }
+ if (insert_server(conn_options))
+ {
+ }
DBUG_RETURN(FALSE);
}
-void connections_free(bool end)
+void servers_free(bool end)
{
- DBUG_ENTER("connections_free");
- if (!connections_cache_initialised)
+ DBUG_ENTER("servers_free");
+ if (!servers_cache_initialised)
DBUG_VOID_RETURN;
- VOID(pthread_mutex_destroy(&connections_cache_mutex));
- connections_cache_initialised=0; /* maybe too permanant?
+ VOID(pthread_mutex_destroy(&servers_cache_mutex));
+ servers_cache_initialised=0; /* maybe too permanant?
user will have to restart mysqld? */
free_root(&mem,MYF(0));
- hash_free(&connections_cache);
+ hash_free(&servers_cache);
DBUG_VOID_RETURN;
}
/*
- Forget current connections cache and read new connections
+ Forget current servers cache and read new servers
from the conneciton table.
SYNOPSIS
- connections_reload()
+ servers_reload()
thd Current thread
NOTE
@@ -238,11 +281,11 @@
TRUE Failure
*/
-my_bool connections_reload(THD *thd)
+my_bool servers_reload(THD *thd)
{
TABLE_LIST tables[1];
my_bool return_val= 1;
- DBUG_ENTER("connections_reload");
+ DBUG_ENTER("servers_reload");
if (thd->locked_tables)
{ // Can't have locked tables here
@@ -253,10 +296,10 @@
/*
To avoid deadlocks we should obtain table locks before
- obtaining connections_cache->lock mutex.
+ obtaining servers_cache->lock mutex.
*/
bzero((char*) tables, sizeof(tables));
- tables[0].alias= tables[0].table_name= (char*) "connections";
+ tables[0].alias= tables[0].table_name= (char*) "servers";
tables[0].db= (char*) "mysql";
tables[0].lock_type= TL_READ;
@@ -268,20 +311,20 @@
}
DBUG_PRINT("info", ("calling pthread_mutex_lock"));
- VOID(pthread_mutex_lock(&connections_cache_mutex));
+ VOID(pthread_mutex_lock(&servers_cache_mutex));
- //old_connections_cache= connections_cache;
+ //old_servers_cache= servers_cache;
//old_mem=mem;
- if ((return_val= connections_load(thd, tables)))
+ if ((return_val= servers_load(thd, tables)))
{ // Error. Revert to old list
- /* blast, for now, we have no connections, discuss later way to preserve */
+ /* blast, for now, we have no servers, discuss later way to preserve */
DBUG_PRINT("error",("Reverting to old privileges"));
- connections_free(); /* purecov: inspected */
+ servers_free(); /* purecov: inspected */
}
- VOID(pthread_mutex_unlock(&connections_cache_mutex));
+ VOID(pthread_mutex_unlock(&servers_cache_mutex));
end:
close_thread_tables(thd);
@@ -289,31 +332,33 @@
}
-SQL_CONNECTION *get_connection_by_name(const char *connection_name)
+FOREIGN_SERVER *get_server_by_name(const char *server_name)
{
ulong error_num=0;
- uint i, connection_name_length;
- SQL_CONNECTION *connection;
- DBUG_ENTER("get_connection_by_connection_name");
- DBUG_PRINT("info", ("conneciton_name %s", connection_name));
+ uint i, server_name_length;
+ FOREIGN_SERVER *server;
+ DBUG_ENTER("get_server_by_server_name");
+ DBUG_PRINT("info", ("conneciton_name %s", server_name));
- connection_name_length= strlen(connection_name);
+ server_name_length= strlen(server_name);
- if (! connection_name || !strlen(connection_name))
+ if (! server_name || !strlen(server_name))
{
- DBUG_PRINT("info", ("connection_name not defined!"));
+ DBUG_PRINT("info", ("server_name not defined!"));
error_num= 1;
- DBUG_RETURN((SQL_CONNECTION *)NULL);
+ DBUG_RETURN((FOREIGN_SERVER *)NULL);
}
- if (!(connection= (SQL_CONNECTION *) hash_search(&connections_cache,
- (byte*) connection_name,
- connection_name_length)))
+ VOID(pthread_mutex_lock(&servers_cache_mutex));
+ if (!(server= (FOREIGN_SERVER *) hash_search(&servers_cache,
+ (byte*) server_name,
+ server_name_length)))
{
- DBUG_PRINT("info", ("connection_name %s length %d not found!",
- connection_name, connection_name_length));
- DBUG_RETURN((SQL_CONNECTION *)NULL);
+ DBUG_PRINT("info", ("server_name %s length %d not found!",
+ server_name, server_name_length));
+ DBUG_RETURN((FOREIGN_SERVER *)NULL);
}
- DBUG_RETURN(connection);
+ VOID(pthread_mutex_unlock(&servers_cache_mutex));
+ DBUG_RETURN(server);
}
--- 1.1/sql/sql_connections.h 2006-01-31 16:33:26 -08:00
+++ 1.2/BitKeeper/deleted/.del-sql_connections.h~2ba1eb5726722a98 2006-02-09 16:57:08 -08:00
@@ -18,20 +18,21 @@
/* structs */
-typedef struct st_sql_connection
+typedef struct st_federated_server
{
- char *connection_name;
- uint connection_name_length;
+ char *server_name;
+ uint server_name_length;
uint table_name_length;
uint port;
char *db, *scheme, *username, *password, *socket, *sport, *table_name,
*owner, *host;
-} SQL_CONNECTION;
+} FOREIGN_SERVER;
/* prototypes */
-my_bool connections_init(bool dont_read_connection_table);
-my_bool connections_reload(THD *thd);
-my_bool create_server(LEX_CONNECTION_OPTIONS *conn_options);
-void connections_free(bool end=0);
-SQL_CONNECTION *get_connection_by_name(const char *connection_name);
-bool connections_check_host(const char *host, const char *ip);
+my_bool servers_init(bool dont_read_server_table);
+my_bool servers_reload(THD *thd);
+int create_server(LEX_SERVER_OPTIONS *server_options);
+void servers_free(bool end=0);
+FOREIGN_SERVER *get_server_by_name(const char *server_name);
+bool server_check_host(const char *host, const char *ip);
+my_bool server_exists(char *server_name);
--- 1.51/sql/ha_federated.cc 2006-01-31 16:33:23 -08:00
+++ 1.52/sql/ha_federated.cc 2006-02-09 18:28:58 -08:00
@@ -599,29 +599,29 @@
}
/*
- retrieve connection object which contains connection info
- from the system table given a connection name, set share
+ retrieve server object which contains server meta-data
+ from the system table given a server's name, set share
connection parameter members
*/
int get_connection(FEDERATED_SHARE *share)
{
- int error_num= ER_FOREIGN_CONNECTION_DOESNT_EXIST;
+ int error_num= ER_FOREIGN_SERVER_DOESNT_EXIST;
char error_buffer[FEDERATED_QUERY_BUFFER_SIZE];
- SQL_CONNECTION *connection;
+ FOREIGN_SERVER *server;
MYSQL *mysql_conn;
MYSQL_RES *result= 0;
MYSQL_ROW row;
DBUG_ENTER("ha_federated::get_connection");
- if (!(connection=
- get_connection_by_name(share->connection_string)))
+ if (!(server=
+ get_server_by_name(share->connection_string)))
{
- DBUG_PRINT("info", ("get_connection_by_connection_name returned > 0 error condition!"));
+ DBUG_PRINT("info", ("get_server_by_name returned > 0 error condition!"));
/* need to come up with error handling */
error_num=1;
goto error;
}
- DBUG_PRINT("info", ("get_connection_by_connection_name returned connection at %lx", connection));
+ DBUG_PRINT("info", ("get_server_by_name returned server at %lx", server));
/*
Most of these should never be empty strings, error handling will
@@ -630,25 +630,25 @@
except there are errors in the trace file of the share being overrun
at the address of the share.
*/
- if (connection->connection_name)
- share->connection_name= connection->connection_name;
- share->connection_name_length= connection->connection_name_length ?
- connection->connection_name_length : 0;
- if (connection->username)
- share->username= connection->username;
- if (connection->password)
- share->password= connection->password;
- if (connection->db)
- share->database= connection->db;
- if (connection->sport)
- share->sport= connection->sport;
- share->port= connection->port ? connection->port : 0;
- if (connection->host)
- share->hostname= connection->host;
- if (connection->socket)
- share->socket= connection->socket;
- if (connection->scheme)
- share->scheme= connection->scheme;
+ if (server->server_name)
+ share->server_name= server->server_name;
+ share->server_name_length= server->server_name_length ?
+ server->server_name_length : 0;
+ if (server->username)
+ share->username= server->username;
+ if (server->password)
+ share->password= server->password;
+ if (server->db)
+ share->database= server->db;
+ if (server->sport)
+ share->sport= server->sport;
+ share->port= server->port ? server->port : 0;
+ if (server->host)
+ share->hostname= server->host;
+ if (server->socket)
+ share->socket= server->socket;
+ if (server->scheme)
+ share->scheme= server->scheme;
else
share->scheme= NULL;
@@ -662,7 +662,7 @@
error:
my_sprintf(error_buffer,
- (error_buffer, "connection name: '%s' doesn't exist!",
+ (error_buffer, "server name: '%s' doesn't exist!",
share->connection_string));
my_error(error_num, MYF(0), error_buffer);
DBUG_RETURN(error_num);
--- 1.26/sql/ha_federated.h 2006-01-31 16:33:23 -08:00
+++ 1.27/sql/ha_federated.h 2006-02-09 18:28:58 -08:00
@@ -129,7 +129,7 @@
/*
remote host info, parse_url supplies
*/
- char *connection_name;
+ char *server_name;
char *connection_string;
char *scheme;
char *hostname;
@@ -141,7 +141,7 @@
char *socket;
char *sport;
ushort port;
- uint table_name_length, connection_name_length, use_count;
+ uint table_name_length, server_name_length, use_count;
pthread_mutex_t mutex;
THR_LOCK lock;
} FEDERATED_SHARE;
| Thread |
|---|
| • bk commit into 5.1 tree (patg:1.2116) | Patrick Galbraith | 10 Feb |