diff options
Diffstat (limited to 'storage/example')
-rw-r--r-- | storage/example/CMakeLists.txt | 10 | ||||
-rw-r--r-- | storage/example/Makefile.am | 43 | ||||
-rw-r--r-- | storage/example/ha_example.cc | 126 | ||||
-rw-r--r-- | storage/example/ha_example.h | 15 |
4 files changed, 147 insertions, 47 deletions
diff --git a/storage/example/CMakeLists.txt b/storage/example/CMakeLists.txt index a328da107bd..3d94d09f075 100644 --- a/storage/example/CMakeLists.txt +++ b/storage/example/CMakeLists.txt @@ -1,4 +1,4 @@ -# 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 @@ -11,10 +11,8 @@ # # 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 -SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DSAFEMALLOC -DSAFE_MUTEX") -SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DSAFEMALLOC -DSAFE_MUTEX") -INCLUDE("${PROJECT_SOURCE_DIR}/storage/mysql_storage_engine.cmake") +SET(EXAMPLE_PLUGIN_DYNAMIC "ha_example") SET(EXAMPLE_SOURCES ha_example.cc) -MYSQL_STORAGE_ENGINE(EXAMPLE) +MYSQL_ADD_PLUGIN(example ${EXAMPLE_SOURCES} STORAGE_ENGINE MODULE_ONLY) diff --git a/storage/example/Makefile.am b/storage/example/Makefile.am index dc499e2f9dd..a8b0506e8dd 100644 --- a/storage/example/Makefile.am +++ b/storage/example/Makefile.am @@ -1,5 +1,5 @@ -# Copyright (C) 2005-2006 MySQL AB -# +# Copyright (C) 2005-2006 MySQL AB, 2009 Sun Microsystems, Inc. +# 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. @@ -23,7 +23,7 @@ pkgplugindir = $(pkglibdir)/plugin INCLUDES = -I$(top_srcdir)/include -I$(top_builddir)/include \ -I$(top_srcdir)/regex \ -I$(top_srcdir)/sql \ - -I$(srcdir) + -I$(srcdir) WRAPLIBS= LDADD = @@ -45,5 +45,38 @@ libexample_a_SOURCES= ha_example.cc EXTRA_DIST = CMakeLists.txt plug.in -# Don't update the files from bitkeeper -%::SCCS/s.% + +if HAVE_DTRACE_DASH_G +# The object for static and dynamic linking of example differ +# For static linkage of example to mysqld +# That's actually not needed as example is only dynamic loadable, but for completion +libexample_a_LIBADD = probes_mysql.o +libexample_a_DEPENDENCIES = probes_mysql.o dtrace_files dtrace_providers +# For example as shared library +ha_example_la_LIBADD = probes_sh_mysql.o +# Hack: We "depend" on ".libs/" but have no rule for it, +# but it is created as a byproduct of the ".lo" +DTRACESHAREDDEPS = ha_example_la-ha_example.lo +DTRACESHAREDFILES = ha_example_la-ha_example.o +DTRACEPROVIDER = probes_mysql.d +ha_example_la_DEPENDENCIES = probes_sh_mysql.o $(DTRACESHAREDDEPS) dtrace_providers + +CLEANFILES = $(DTRACEPROVIDER) dtrace_files dtrace_providers $(DTRACESHAREDFILES) +DTRACEFILES = libexample_a-ha_example.o + +dtrace_files: + echo $(DTRACEFILES) > $@ +dtrace_providers: probes_mysql.d + echo $(DTRACEPROVIDER) > $@ +probes_mysql.d: + -$(RM) -f probes_mysql.d + $(CP) $(top_srcdir)/include/probes_mysql.d.base probes_mysql.d + echo timestamp > dtrace_sources + +probes_sh_mysql.o: $(DTRACEPROVIDER) $(DTRACESHAREDDEPS) + $(DTRACE) $(DTRACEFLAGS) -G -s $(DTRACEPROVIDER) $(DTRACESHAREDFILES) -o $@ + $(CP) $(DTRACESHAREDFILES) .libs +probes_mysql.o: $(DTRACEPROVIDER) $(DTRACEFILES) + $(DTRACE) $(DTRACEFLAGS) -G -s $(DTRACEPROVIDER) $(DTRACEFILES) -o $@ + +endif diff --git a/storage/example/ha_example.cc b/storage/example/ha_example.cc index f2aee1de70c..2a076f0dc14 100644 --- a/storage/example/ha_example.cc +++ b/storage/example/ha_example.cc @@ -91,10 +91,11 @@ #pragma implementation // gcc: Class implementation #endif -#define MYSQL_SERVER 1 -#include "mysql_priv.h" +#include "sql_priv.h" +#include "sql_class.h" // MYSQL_HANDLERTON_INTERFACE_VERSION #include "ha_example.h" -#include <mysql/plugin.h> +#include "probes_mysql.h" +#include "sql_plugin.h" static handler *example_create_handler(handlerton *hton, TABLE_SHARE *table, @@ -111,7 +112,7 @@ handlerton *example_hton; static HASH example_open_tables; /* The mutex used to init the hash; variable for example share methods */ -pthread_mutex_t example_mutex; +mysql_mutex_t example_mutex; /** @@ -195,15 +196,41 @@ static uchar* example_get_key(EXAMPLE_SHARE *share, size_t *length, return (uchar*) share->table_name; } +#ifdef HAVE_PSI_INTERFACE +static PSI_mutex_key ex_key_mutex_example, ex_key_mutex_EXAMPLE_SHARE_mutex; + +static PSI_mutex_info all_example_mutexes[]= +{ + { &ex_key_mutex_example, "example", PSI_FLAG_GLOBAL}, + { &ex_key_mutex_EXAMPLE_SHARE_mutex, "EXAMPLE_SHARE::mutex", 0} +}; + +static void init_example_psi_keys() +{ + const char* category= "example"; + int count; + + if (PSI_server == NULL) + return; + + count= array_elements(all_example_mutexes); + PSI_server->register_mutex(category, all_example_mutexes, count); +} +#endif + static int example_init_func(void *p) { DBUG_ENTER("example_init_func"); +#ifdef HAVE_PSI_INTERFACE + init_example_psi_keys(); +#endif + example_hton= (handlerton *)p; - VOID(pthread_mutex_init(&example_mutex,MY_MUTEX_INIT_FAST)); - (void) hash_init(&example_open_tables,system_charset_info,32,0,0, - (hash_get_key) example_get_key,0,0); + mysql_mutex_init(ex_key_mutex_example, &example_mutex, MY_MUTEX_INIT_FAST); + (void) my_hash_init(&example_open_tables,system_charset_info,32,0,0, + (my_hash_get_key) example_get_key,0,0); example_hton->state= SHOW_OPTION_YES; example_hton->create= example_create_handler; @@ -222,8 +249,8 @@ static int example_done_func(void *p) if (example_open_tables.records) error= 1; - hash_free(&example_open_tables); - pthread_mutex_destroy(&example_mutex); + my_hash_free(&example_open_tables); + mysql_mutex_destroy(&example_mutex); DBUG_RETURN(error); } @@ -243,12 +270,12 @@ static EXAMPLE_SHARE *get_share(const char *table_name, TABLE *table) uint length; char *tmp_name; - pthread_mutex_lock(&example_mutex); + mysql_mutex_lock(&example_mutex); length=(uint) strlen(table_name); - if (!(share=(EXAMPLE_SHARE*) hash_search(&example_open_tables, - (uchar*) table_name, - length))) + if (!(share=(EXAMPLE_SHARE*) my_hash_search(&example_open_tables, + (uchar*) table_name, + length))) { if (!(share=(EXAMPLE_SHARE *) my_multi_malloc(MYF(MY_WME | MY_ZEROFILL), @@ -256,7 +283,7 @@ static EXAMPLE_SHARE *get_share(const char *table_name, TABLE *table) &tmp_name, length+1, NullS))) { - pthread_mutex_unlock(&example_mutex); + mysql_mutex_unlock(&example_mutex); return NULL; } @@ -267,16 +294,17 @@ static EXAMPLE_SHARE *get_share(const char *table_name, TABLE *table) if (my_hash_insert(&example_open_tables, (uchar*) share)) goto error; thr_lock_init(&share->lock); - pthread_mutex_init(&share->mutex,MY_MUTEX_INIT_FAST); + mysql_mutex_init(ex_key_mutex_EXAMPLE_SHARE_mutex, + &share->mutex, MY_MUTEX_INIT_FAST); } share->use_count++; - pthread_mutex_unlock(&example_mutex); + mysql_mutex_unlock(&example_mutex); return share; error: - pthread_mutex_destroy(&share->mutex); - my_free(share, MYF(0)); + mysql_mutex_destroy(&share->mutex); + my_free(share); return NULL; } @@ -290,15 +318,15 @@ error: static int free_share(EXAMPLE_SHARE *share) { - pthread_mutex_lock(&example_mutex); + mysql_mutex_lock(&example_mutex); if (!--share->use_count) { - hash_delete(&example_open_tables, (uchar*) share); + my_hash_delete(&example_open_tables, (uchar*) share); thr_lock_delete(&share->lock); - pthread_mutex_destroy(&share->mutex); - my_free(share, MYF(0)); + mysql_mutex_destroy(&share->mutex); + my_free(share); } - pthread_mutex_unlock(&example_mutex); + mysql_mutex_unlock(&example_mutex); return 0; } @@ -438,7 +466,13 @@ int ha_example::close(void) int ha_example::write_row(uchar *buf) { DBUG_ENTER("ha_example::write_row"); - DBUG_RETURN(HA_ERR_WRONG_COMMAND); + /* + Example of a successful write_row. We don't store the data + anywhere; they are thrown away. A real implementation will + probably need to do something with 'buf'. We report a success + here, to pretend that the insert was successful. + */ + DBUG_RETURN(0); } @@ -511,8 +545,12 @@ int ha_example::index_read_map(uchar *buf, const uchar *key, enum ha_rkey_function find_flag __attribute__((unused))) { + int rc; DBUG_ENTER("ha_example::index_read"); - DBUG_RETURN(HA_ERR_WRONG_COMMAND); + MYSQL_INDEX_READ_ROW_START(table_share->db.str, table_share->table_name.str); + rc= HA_ERR_WRONG_COMMAND; + MYSQL_INDEX_READ_ROW_DONE(rc); + DBUG_RETURN(rc); } @@ -523,8 +561,12 @@ int ha_example::index_read_map(uchar *buf, const uchar *key, int ha_example::index_next(uchar *buf) { + int rc; DBUG_ENTER("ha_example::index_next"); - DBUG_RETURN(HA_ERR_WRONG_COMMAND); + MYSQL_INDEX_READ_ROW_START(table_share->db.str, table_share->table_name.str); + rc= HA_ERR_WRONG_COMMAND; + MYSQL_INDEX_READ_ROW_DONE(rc); + DBUG_RETURN(rc); } @@ -535,8 +577,12 @@ int ha_example::index_next(uchar *buf) int ha_example::index_prev(uchar *buf) { + int rc; DBUG_ENTER("ha_example::index_prev"); - DBUG_RETURN(HA_ERR_WRONG_COMMAND); + MYSQL_INDEX_READ_ROW_START(table_share->db.str, table_share->table_name.str); + rc= HA_ERR_WRONG_COMMAND; + MYSQL_INDEX_READ_ROW_DONE(rc); + DBUG_RETURN(rc); } @@ -552,8 +598,12 @@ int ha_example::index_prev(uchar *buf) */ int ha_example::index_first(uchar *buf) { + int rc; DBUG_ENTER("ha_example::index_first"); - DBUG_RETURN(HA_ERR_WRONG_COMMAND); + MYSQL_INDEX_READ_ROW_START(table_share->db.str, table_share->table_name.str); + rc= HA_ERR_WRONG_COMMAND; + MYSQL_INDEX_READ_ROW_DONE(rc); + DBUG_RETURN(rc); } @@ -569,8 +619,12 @@ int ha_example::index_first(uchar *buf) */ int ha_example::index_last(uchar *buf) { + int rc; DBUG_ENTER("ha_example::index_last"); - DBUG_RETURN(HA_ERR_WRONG_COMMAND); + MYSQL_INDEX_READ_ROW_START(table_share->db.str, table_share->table_name.str); + rc= HA_ERR_WRONG_COMMAND; + MYSQL_INDEX_READ_ROW_DONE(rc); + DBUG_RETURN(rc); } @@ -616,8 +670,13 @@ int ha_example::rnd_end() */ int ha_example::rnd_next(uchar *buf) { + int rc; DBUG_ENTER("ha_example::rnd_next"); - DBUG_RETURN(HA_ERR_END_OF_FILE); + MYSQL_READ_ROW_START(table_share->db.str, table_share->table_name.str, + TRUE); + rc= HA_ERR_END_OF_FILE; + MYSQL_READ_ROW_DONE(rc); + DBUG_RETURN(rc); } @@ -664,8 +723,13 @@ void ha_example::position(const uchar *record) */ int ha_example::rnd_pos(uchar *buf, uchar *pos) { + int rc; DBUG_ENTER("ha_example::rnd_pos"); - DBUG_RETURN(HA_ERR_WRONG_COMMAND); + MYSQL_READ_ROW_START(table_share->db.str, table_share->table_name.str, + TRUE); + rc= HA_ERR_WRONG_COMMAND; + MYSQL_READ_ROW_DONE(rc); + DBUG_RETURN(rc); } diff --git a/storage/example/ha_example.h b/storage/example/ha_example.h index dc47fac1f17..27b97395544 100644 --- a/storage/example/ha_example.h +++ b/storage/example/ha_example.h @@ -35,6 +35,11 @@ #pragma interface /* gcc class implementation */ #endif +#include "my_global.h" /* ulonglong */ +#include "thr_lock.h" /* THR_LOCK, THR_LOCK_DATA */ +#include "handler.h" /* handler */ +#include "my_base.h" /* ha_rows */ + /** @brief EXAMPLE_SHARE is a structure that will be shared among all open handlers. This example implements the minimum of what you will probably need. @@ -42,7 +47,7 @@ typedef struct st_example_share { char *table_name; uint table_name_length,use_count; - pthread_mutex_t mutex; + mysql_mutex_t mutex; THR_LOCK lock; } EXAMPLE_SHARE; @@ -83,11 +88,11 @@ public: ulonglong table_flags() const { /* - We are saying that this engine is just row capable to have an - engine that can only handle row-based logging. This is used in - testing. + We are saying that this engine is just statement capable to have + an engine that can only handle statement-based logging. This is + used in testing. */ - return HA_BINLOG_ROW_CAPABLE; + return HA_BINLOG_STMT_CAPABLE; } /** @brief |