summaryrefslogtreecommitdiff
path: root/sql/handler.cc
diff options
context:
space:
mode:
authorSergei Golubchik <sergii@pisem.net>2013-04-09 15:31:29 +0200
committerSergei Golubchik <sergii@pisem.net>2013-04-09 15:31:29 +0200
commit03dfb2c1210f75e234b5571a40a9aa92cb1afa45 (patch)
treeb6e97baed151432f30c12b30c28563aa1875327b /sql/handler.cc
parent2a9662b401405ee8f8f0849f7f90faac1081e26e (diff)
downloadmariadb-git-03dfb2c1210f75e234b5571a40a9aa92cb1afa45.tar.gz
file-based table discovery for discovering storage engines
also: * move few tests from archive/archive.test to archive/discover.test * fix (unintentionally) bug#34104, updated result files
Diffstat (limited to 'sql/handler.cc')
-rw-r--r--sql/handler.cc69
1 files changed, 67 insertions, 2 deletions
diff --git a/sql/handler.cc b/sql/handler.cc
index 56e9ec35ad8..8dd0a5d6995 100644
--- a/sql/handler.cc
+++ b/sql/handler.cc
@@ -433,6 +433,9 @@ int ha_finalize_handlerton(st_plugin_int *plugin)
hton2plugin[hton->slot]= NULL;
}
+ if (hton->discover_table_names)
+ my_atomic_add32(&engines_with_discover_table_names, -1);
+
my_free(hton);
end:
@@ -440,6 +443,13 @@ int ha_finalize_handlerton(st_plugin_int *plugin)
}
+static int hton_ext_based_table_discovery(handlerton *hton, LEX_STRING *db,
+ MY_DIR *dir, handlerton::discovered_list *result)
+{
+ return extension_based_table_discovery(dir, hton->tablefile_extensions[0],
+ result);
+}
+
int ha_initialize_handlerton(st_plugin_int *plugin)
{
handlerton *hton;
@@ -449,8 +459,6 @@ int ha_initialize_handlerton(st_plugin_int *plugin)
hton= (handlerton *)my_malloc(sizeof(handlerton),
MYF(MY_WME | MY_ZEROFILL));
- hton->tablefile_extensions= no_exts;
-
if (hton == NULL)
{
sql_print_error("Unable to allocate memory for plugin '%s' handlerton.",
@@ -468,6 +476,16 @@ int ha_initialize_handlerton(st_plugin_int *plugin)
goto err;
}
+ // default list file extensions: empty
+ if (!hton->tablefile_extensions)
+ hton->tablefile_extensions= no_exts;
+
+ // if the enfine can discover a single table and it is file-based
+ // then it can use a default file-based table names discovery
+ if (!hton->discover_table_names &&
+ hton->discover && hton->tablefile_extensions[0])
+ hton->discover_table_names= hton_ext_based_table_discovery;
+
/*
the switch below and hton->state should be removed when
command-line options for plugins will be implemented
@@ -557,6 +575,9 @@ int ha_initialize_handlerton(st_plugin_int *plugin)
break;
};
+ if (hton->discover_table_names)
+ my_atomic_add32(&engines_with_discover_table_names, 1);
+
DBUG_RETURN(0);
err_deinit:
@@ -4373,6 +4394,50 @@ int ha_discover(THD *thd, const char *db, const char *name,
}
+/**
+ Discover all table names in a given database
+*/
+volatile int32 engines_with_discover_table_names= 0;
+
+struct st_discover_names_args
+{
+ LEX_STRING *db;
+ MY_DIR *dirp;
+ handlerton::discovered_list *result;
+};
+
+static my_bool discover_names(THD *thd, plugin_ref plugin,
+ void *arg)
+{
+ st_discover_names_args *args= (st_discover_names_args *)arg;
+ handlerton *ht= plugin_data(plugin, handlerton *);
+ if (ht->state == SHOW_OPTION_YES && ht->discover_table_names &&
+ ht->discover_table_names(ht, args->db, args->dirp, args->result))
+ return 1;
+
+ return 0;
+}
+
+int ha_discover_table_names(THD *thd, LEX_STRING *db, MY_DIR *dirp,
+ handlerton::discovered_list *result)
+{
+ int error;
+ DBUG_ENTER("ha_discover_table_names");
+ st_discover_names_args args= {db, dirp, result};
+
+ if (engines_with_discover_table_names == 0)
+ DBUG_RETURN(ext_table_discovery_simple(dirp, reg_ext, result));
+
+ error= extension_based_table_discovery(dirp, reg_ext, result);
+
+ if (!error)
+ error= plugin_foreach(thd, discover_names, MYSQL_STORAGE_ENGINE_PLUGIN,
+ &args);
+
+ DBUG_RETURN(error);
+}
+
+
#ifdef HAVE_NDB_BINLOG
/*
TODO: change this into a dynamic struct