summaryrefslogtreecommitdiff
path: root/storage/federated
diff options
context:
space:
mode:
Diffstat (limited to 'storage/federated')
-rw-r--r--[-rwxr-xr-x]storage/federated/CMakeLists.txt18
-rw-r--r--storage/federated/Makefile.am51
-rw-r--r--storage/federated/ha_federated.cc134
-rw-r--r--storage/federated/ha_federated.h9
-rw-r--r--storage/federated/plug.in4
5 files changed, 110 insertions, 106 deletions
diff --git a/storage/federated/CMakeLists.txt b/storage/federated/CMakeLists.txt
index 3f3201d351c..9bd5b6b45d7 100755..100644
--- a/storage/federated/CMakeLists.txt
+++ b/storage/federated/CMakeLists.txt
@@ -1,18 +1,22 @@
-# Copyright (C) 2006 MySQL AB
-#
+# Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
+#
# 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; version 2 of the License.
-#
+#
# 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-INCLUDE("${PROJECT_SOURCE_DIR}/storage/mysql_storage_engine.cmake")
SET(FEDERATED_SOURCES ha_federated.cc)
-MYSQL_STORAGE_ENGINE(FEDERATED)
+IF(NOT WITH_FEDERATED AND NOT WITH_FEDERATED_STORAGE_ENGINE)
+ # Bug#45488- federated uses symbols that are not used anywhere in
+ # mysqld and are optimized away by the linker.
+ SET(FEDERATED_SOURCES ${FEDERATED_SOURCES} ${CMAKE_SOURCE_DIR}/mysys/string.c)
+ENDIF()
+MYSQL_ADD_PLUGIN(federated ${FEDERATED_SOURCES} STORAGE_ENGINE MODULE_ONLY)
diff --git a/storage/federated/Makefile.am b/storage/federated/Makefile.am
deleted file mode 100644
index 48d86dded69..00000000000
--- a/storage/federated/Makefile.am
+++ /dev/null
@@ -1,51 +0,0 @@
-# Copyright (C) 2006 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; version 2 of the License.
-#
-# 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-
-#called from the top level Makefile
-
-MYSQLDATAdir = $(localstatedir)
-MYSQLSHAREdir = $(pkgdatadir)
-MYSQLBASEdir= $(prefix)
-MYSQLLIBdir= $(pkglibdir)
-pkgplugindir = $(pkglibdir)/plugin
-INCLUDES = -I$(top_srcdir)/include -I$(top_builddir)/include \
- -I$(top_srcdir)/regex \
- -I$(top_srcdir)/sql \
- -I$(srcdir)
-WRAPLIBS=
-
-DEFS = @DEFS@
-
-noinst_HEADERS = ha_federated.h
-
-EXTRA_LTLIBRARIES = libfederated.la libfederated_embedded.la ha_federated.la
-pkgplugin_LTLIBRARIES = @plugin_federated_shared_target@
-ha_federated_la_LDFLAGS = -module -rpath $(pkgplugindir) \
- -L$(top_builddir)/libservices -lmysqlservices
-ha_federated_la_CXXFLAGS= -shared $(AM_CXXFLAGS) -DMYSQL_DYNAMIC_PLUGIN
-ha_federated_la_CFLAGS = -shared $(AM_CFLAGS) -DMYSQL_DYNAMIC_PLUGIN
-ha_federated_la_SOURCES = ha_federated.cc $(top_srcdir)/mysys/string.c
-
-
-noinst_LTLIBRARIES = @plugin_federated_static_target@ @plugin_federated_embedded_static_target@
-libfederated_la_CXXFLAGS = $(AM_CXXFLAGS)
-libfederated_la_SOURCES= ha_federated.cc
-
-libfederated_embedded_la_CXXFLAGS = $(AM_CXXFLAGS) @plugin_embedded_defs@
-libfederated_embedded_la_CFLAGS = $(AM_CFLAGS) @plugin_embedded_defs@
-libfederated_embedded_la_SOURCES= ha_federated.cc
-
-
-EXTRA_DIST = CMakeLists.txt plug.in
diff --git a/storage/federated/ha_federated.cc b/storage/federated/ha_federated.cc
index 34509e04799..0756b77180a 100644
--- a/storage/federated/ha_federated.cc
+++ b/storage/federated/ha_federated.cc
@@ -372,7 +372,10 @@
#define MYSQL_SERVER 1
-#include "mysql_priv.h"
+#include "sql_priv.h"
+#include "sql_servers.h" // FOREIGN_SERVER, get_server_by_name
+#include "sql_class.h" // SSV
+#include "sql_analyse.h" // append_escaped
#include <mysql/plugin.h>
#ifdef USE_PRAGMA_IMPLEMENTATION
@@ -382,12 +385,19 @@
#include "ha_federated.h"
#include "m_string.h"
+#include "key.h" // key_copy
#include <mysql/plugin.h>
+#ifdef I_AM_PARANOID
+#define MIN_PORT 1023
+#else
+#define MIN_PORT 0
+#endif
+
/* Variables for federated share methods */
static HASH federated_open_tables; // To track open tables
-pthread_mutex_t federated_mutex; // To init the hash
+mysql_mutex_t federated_mutex; // To init the hash
static char ident_quote_char= '`'; // Character for quoting
// identifiers
static char value_quote_char= '\''; // Character for quoting
@@ -426,6 +436,28 @@ static uchar *federated_get_key(FEDERATED_SHARE *share, size_t *length,
return (uchar*) share->share_key;
}
+#ifdef HAVE_PSI_INTERFACE
+static PSI_mutex_key fe_key_mutex_federated, fe_key_mutex_FEDERATED_SHARE_mutex;
+
+static PSI_mutex_info all_federated_mutexes[]=
+{
+ { &fe_key_mutex_federated, "federated", PSI_FLAG_GLOBAL},
+ { &fe_key_mutex_FEDERATED_SHARE_mutex, "FEDERATED_SHARE::mutex", 0}
+};
+
+static void init_federated_psi_keys(void)
+{
+ const char* category= "federated";
+ int count;
+
+ if (PSI_server == NULL)
+ return;
+
+ count= array_elements(all_federated_mutexes);
+ PSI_server->register_mutex(category, all_federated_mutexes, count);
+}
+#endif /* HAVE_PSI_INTERFACE */
+
/*
Initialize the federated handler.
@@ -441,6 +473,11 @@ static uchar *federated_get_key(FEDERATED_SHARE *share, size_t *length,
int federated_db_init(void *p)
{
DBUG_ENTER("federated_db_init");
+
+#ifdef HAVE_PSI_INTERFACE
+ init_federated_psi_keys();
+#endif /* HAVE_PSI_INTERFACE */
+
handlerton *federated_hton= (handlerton *)p;
federated_hton->state= SHOW_OPTION_YES;
federated_hton->db_type= DB_TYPE_FEDERATED_DB;
@@ -456,15 +493,16 @@ int federated_db_init(void *p)
federated_hton->commit= 0;
federated_hton->rollback= 0;
- if (pthread_mutex_init(&federated_mutex, MY_MUTEX_INIT_FAST))
+ if (mysql_mutex_init(fe_key_mutex_federated,
+ &federated_mutex, MY_MUTEX_INIT_FAST))
goto error;
- if (!hash_init(&federated_open_tables, &my_charset_bin, 32, 0, 0,
- (hash_get_key) federated_get_key, 0, 0))
+ if (!my_hash_init(&federated_open_tables, &my_charset_bin, 32, 0, 0,
+ (my_hash_get_key) federated_get_key, 0, 0))
{
DBUG_RETURN(FALSE);
}
- VOID(pthread_mutex_destroy(&federated_mutex));
+ mysql_mutex_destroy(&federated_mutex);
error:
DBUG_RETURN(TRUE);
}
@@ -482,8 +520,8 @@ error:
int federated_done(void *p)
{
- hash_free(&federated_open_tables);
- VOID(pthread_mutex_destroy(&federated_mutex));
+ my_hash_free(&federated_open_tables);
+ mysql_mutex_destroy(&federated_mutex);
return 0;
}
@@ -591,11 +629,7 @@ int get_connection(MEM_ROOT *mem_root, FEDERATED_SHARE *share)
share->username= server->username;
share->password= server->password;
share->database= server->db;
-#ifndef I_AM_PARANOID
- share->port= server->port > 0 && server->port < 65536 ?
-#else
- share->port= server->port > 1023 && server->port < 65536 ?
-#endif
+ share->port= server->port > MIN_PORT && server->port < 65536 ?
(ushort) server->port : MYSQL_PORT;
share->hostname= server->host;
if (!(share->socket= server->socket) &&
@@ -1483,7 +1517,7 @@ static FEDERATED_SHARE *get_share(const char *table_name, TABLE *table)
init_alloc_root(&mem_root, 256, 0);
- pthread_mutex_lock(&federated_mutex);
+ mysql_mutex_lock(&federated_mutex);
tmp_share.share_key= table_name;
tmp_share.share_key_length= (uint) strlen(table_name);
@@ -1491,10 +1525,10 @@ static FEDERATED_SHARE *get_share(const char *table_name, TABLE *table)
goto error;
/* TODO: change tmp_share.scheme to LEX_STRING object */
- if (!(share= (FEDERATED_SHARE *) hash_search(&federated_open_tables,
- (uchar*) tmp_share.share_key,
- tmp_share.
- share_key_length)))
+ if (!(share= (FEDERATED_SHARE *) my_hash_search(&federated_open_tables,
+ (uchar*) tmp_share.share_key,
+ tmp_share.
+ share_key_length)))
{
query.set_charset(system_charset_info);
query.append(STRING_WITH_LEN("SELECT "));
@@ -1525,18 +1559,19 @@ static FEDERATED_SHARE *get_share(const char *table_name, TABLE *table)
if (my_hash_insert(&federated_open_tables, (uchar*) share))
goto error;
thr_lock_init(&share->lock);
- pthread_mutex_init(&share->mutex, MY_MUTEX_INIT_FAST);
+ mysql_mutex_init(fe_key_mutex_FEDERATED_SHARE_mutex,
+ &share->mutex, MY_MUTEX_INIT_FAST);
}
else
free_root(&mem_root, MYF(0)); /* prevents memory leak */
share->use_count++;
- pthread_mutex_unlock(&federated_mutex);
+ mysql_mutex_unlock(&federated_mutex);
DBUG_RETURN(share);
error:
- pthread_mutex_unlock(&federated_mutex);
+ mysql_mutex_unlock(&federated_mutex);
free_root(&mem_root, MYF(0));
DBUG_RETURN(NULL);
}
@@ -1553,15 +1588,15 @@ static int free_share(FEDERATED_SHARE *share)
MEM_ROOT mem_root= share->mem_root;
DBUG_ENTER("free_share");
- pthread_mutex_lock(&federated_mutex);
+ mysql_mutex_lock(&federated_mutex);
if (!--share->use_count)
{
- hash_delete(&federated_open_tables, (uchar*) share);
+ my_hash_delete(&federated_open_tables, (uchar*) share);
thr_lock_delete(&share->lock);
- VOID(pthread_mutex_destroy(&share->mutex));
+ mysql_mutex_destroy(&share->mutex);
free_root(&mem_root, MYF(0));
}
- pthread_mutex_unlock(&federated_mutex);
+ mysql_mutex_unlock(&federated_mutex);
DBUG_RETURN(0);
}
@@ -2316,12 +2351,14 @@ int ha_federated::delete_row(const uchar *buf)
int ha_federated::index_read(uchar *buf, const uchar *key,
uint key_len, ha_rkey_function find_flag)
{
+ int rc;
DBUG_ENTER("ha_federated::index_read");
free_result();
- DBUG_RETURN(index_read_idx_with_result_set(buf, active_index, key,
- key_len, find_flag,
- &stored_result));
+ rc= index_read_idx_with_result_set(buf, active_index, key,
+ key_len, find_flag,
+ &stored_result);
+ DBUG_RETURN(rc);
}
@@ -2491,8 +2528,9 @@ int ha_federated::read_range_first(const key_range *start_key,
retval= HA_ERR_END_OF_FILE;
goto error;
}
-
- DBUG_RETURN(read_next(table->record[0], stored_result));
+
+ retval= read_next(table->record[0], stored_result);
+ DBUG_RETURN(retval);
error:
table->status= STATUS_NOT_FOUND;
@@ -2502,17 +2540,21 @@ error:
int ha_federated::read_range_next()
{
+ int retval;
DBUG_ENTER("ha_federated::read_range_next");
- DBUG_RETURN(rnd_next(table->record[0]));
+ retval= rnd_next_int(table->record[0]);
+ DBUG_RETURN(retval);
}
/* Used to read forward through the index. */
int ha_federated::index_next(uchar *buf)
{
+ int retval;
DBUG_ENTER("ha_federated::index_next");
ha_statistic_increment(&SSV::ha_read_next_count);
- DBUG_RETURN(read_next(buf, stored_result));
+ retval= read_next(buf, stored_result);
+ DBUG_RETURN(retval);
}
@@ -2604,7 +2646,15 @@ int ha_federated::index_end(void)
int ha_federated::rnd_next(uchar *buf)
{
+ int rc;
DBUG_ENTER("ha_federated::rnd_next");
+ rc= rnd_next_int(buf);
+ DBUG_RETURN(rc);
+}
+
+int ha_federated::rnd_next_int(uchar *buf)
+{
+ DBUG_ENTER("ha_federated::rnd_next_int");
if (stored_result == 0)
{
@@ -2689,9 +2739,9 @@ void ha_federated::position(const uchar *record __attribute__ ((unused)))
position_called= TRUE;
/* Store result set address. */
- memcpy_fixed(ref, &stored_result, sizeof(MYSQL_RES *));
+ memcpy(ref, &stored_result, sizeof(MYSQL_RES *));
/* Store data cursor position. */
- memcpy_fixed(ref + sizeof(MYSQL_RES *), &current_position,
+ memcpy(ref + sizeof(MYSQL_RES *), &current_position,
sizeof(MYSQL_ROW_OFFSET));
DBUG_VOID_RETURN;
}
@@ -2709,18 +2759,20 @@ void ha_federated::position(const uchar *record __attribute__ ((unused)))
int ha_federated::rnd_pos(uchar *buf, uchar *pos)
{
MYSQL_RES *result;
+ int ret_val;
DBUG_ENTER("ha_federated::rnd_pos");
-
+
ha_statistic_increment(&SSV::ha_read_rnd_count);
/* Get stored result set. */
- memcpy_fixed(&result, pos, sizeof(MYSQL_RES *));
+ memcpy(&result, pos, sizeof(MYSQL_RES *));
DBUG_ASSERT(result);
/* Set data cursor position. */
- memcpy_fixed(&result->data_cursor, pos + sizeof(MYSQL_RES *),
- sizeof(MYSQL_ROW_OFFSET));
+ memcpy(&result->data_cursor, pos + sizeof(MYSQL_RES *),
+ sizeof(MYSQL_ROW_OFFSET));
/* Read a row. */
- DBUG_RETURN(read_next(buf, result));
+ ret_val= read_next(buf, result);
+ DBUG_RETURN(ret_val);
}
@@ -2843,7 +2895,7 @@ int ha_federated::info(uint flag)
}
if (flag & HA_STATUS_AUTO)
- stats.auto_increment_value= mysql->last_used_con->insert_id;
+ stats.auto_increment_value= mysql->insert_id;
mysql_free_result(result);
@@ -3074,7 +3126,7 @@ int ha_federated::real_connect()
to establish Federated connection to guard against a trivial
Denial of Service scenerio.
*/
- safe_mutex_assert_not_owner(&LOCK_open);
+ mysql_mutex_assert_not_owner(&LOCK_open);
DBUG_ASSERT(mysql == NULL);
diff --git a/storage/federated/ha_federated.h b/storage/federated/ha_federated.h
index 142e0e95e2b..ad74521042e 100644
--- a/storage/federated/ha_federated.h
+++ b/storage/federated/ha_federated.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 2003 MySQL AB
+/* Copyright (C) 2003 MySQL AB, 2008-2009 Sun Microsystems, Inc
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
@@ -71,7 +71,7 @@ typedef struct st_federated_share {
ushort port;
size_t table_name_length, server_name_length, connect_string_length, use_count;
- pthread_mutex_t mutex;
+ mysql_mutex_t mutex;
THR_LOCK lock;
} FEDERATED_SHARE;
@@ -149,7 +149,8 @@ public:
HA_BINLOG_ROW_CAPABLE | HA_BINLOG_STMT_CAPABLE |
HA_NO_PREFIX_CHAR_KEYS | HA_PRIMARY_KEY_REQUIRED_FOR_DELETE |
HA_NO_TRANSACTIONS /* until fixed by WL#2952 */ |
- HA_PARTIAL_COLUMN_READ | HA_NULL_IN_KEY);
+ HA_PARTIAL_COLUMN_READ | HA_NULL_IN_KEY |
+ HA_CAN_REPAIR);
}
/*
This is a bitmap of flags that says how the storage engine
@@ -237,6 +238,7 @@ public:
int rnd_init(bool scan); //required
int rnd_end();
int rnd_next(uchar *buf); //required
+ int rnd_next_int(uchar *buf);
int rnd_pos(uchar *buf, uchar *pos); //required
void position(const uchar *record); //required
int info(uint); //required
@@ -247,6 +249,7 @@ public:
int optimize(THD* thd, HA_CHECK_OPT* check_opt);
int delete_all_rows(void);
+ int truncate();
int create(const char *name, TABLE *form,
HA_CREATE_INFO *create_info); //required
ha_rows records_in_range(uint inx, key_range *start_key,
diff --git a/storage/federated/plug.in b/storage/federated/plug.in
deleted file mode 100644
index 3db4a35de08..00000000000
--- a/storage/federated/plug.in
+++ /dev/null
@@ -1,4 +0,0 @@
-MYSQL_STORAGE_ENGINE(federated,,[Federated Storage Engine],
- [Connects to tables on remote MySQL servers], [])
-MYSQL_PLUGIN_STATIC(federated, [libfederated.la], [libfederated_embedded.la])
-MYSQL_PLUGIN_DYNAMIC(federated, [ha_federated.la])