Commit d79485a9 authored by unknown's avatar unknown
Browse files

This changes the order of the universe, black is now the new white.

In practice this means that handlerton is now created by the server and is passed to the engine. Plugin startups can now also control how plugins are inited (and can optionally pass values). Bit more flexibility to those who want to write plugin interfaces to the database. 


include/mysql/plugin.h:
  Optional to pass parameter now to init and deinit functions
sql/ha_ndbcluster.cc:
  Cleanup, handlerton is now a pointer.
sql/ha_ndbcluster_binlog.cc:
  Cleanup (handlerton is now a pointer)
sql/ha_ndbcluster_binlog.h:
  Cleanup (handlerton is now a pointer)
sql/ha_partition.cc:
  Cleaned up handlerton change
sql/handler.cc:
  Cheanup of handlerton change
sql/item_sum.cc:
  Cleanedup of handlerton change
sql/log.cc:
  Cleanup of handlerton change
sql/mysql_priv.h:
  Reverted patch for variables (what would have happen previously if a have_ would have been called that was dynamically loaded? boom!)
sql/mysqld.cc:
  Cleanup of handlerton changes and reverted have variable patch
sql/partition_info.cc:
  Cleanup of handlerton (we need to clean this up a bit more).
sql/set_var.cc:
  Cleanup related to handlerton changes
sql/sql_cache.cc:
  Handlerton changes cleanup
sql/sql_insert.cc:
  Handlerton changes cleanup.
sql/sql_partition.cc:
  Handlerton cleanup changes
sql/sql_plugin.cc:
  Handlerton changes.
  
  init() can now be controlled by a plugin specific startup. 
  
  There was also an issue with how we deinited the status variables. It should have been occuring before we shut down the engines.
sql/sql_select.cc:
  Handlerton cleanup changes
sql/sql_show.cc:
  Handlerton cleanup changes
sql/sql_table.cc:
  Handlerton cleanup changes
sql/table.cc:
  Cleanup
storage/archive/ha_archive.cc:
  Cleanup
storage/archive/ha_archive.h:
  Cleanup
storage/blackhole/ha_blackhole.cc:
  Cleanup
storage/csv/ha_tina.cc:
  Cleanup
storage/example/ha_example.cc:
  Cleanup
storage/federated/ha_federated.cc:
  Cleanup
storage/heap/ha_heap.cc:
  Cleanup
storage/innobase/handler/ha_innodb.cc:
  Cleanup
storage/myisam/ha_myisam.cc:
  Cleanup
storage/myisammrg/ha_myisammrg.cc:
  Cleanup
parent e7a27b6a
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -88,8 +88,8 @@ struct st_mysql_plugin
  const char *name;     /* plugin name                                  */
  const char *author;   /* plugin author (for SHOW PLUGINS)             */
  const char *descr;    /* general descriptive text (for SHOW PLUGINS ) */
  int (*init)(void);    /* the function to invoke when plugin is loaded */
  int (*deinit)(void);  /* the function to invoke when plugin is unloaded */
  int (*init)(void *);  /* the function to invoke when plugin is loaded */
  int (*deinit)(void *);/* the function to invoke when plugin is unloaded */
  unsigned int version; /* plugin version (for SHOW PLUGINS)            */
  struct st_mysql_show_var *status_vars;
  void * __reserved1;   /* placeholder for system variables             */
+32 −29
Original line number Diff line number Diff line
@@ -74,13 +74,13 @@ static const int max_transactions= 3; // should really be 2 but there is a trans

static uint ndbcluster_partition_flags();
static uint ndbcluster_alter_table_flags(uint flags);
static int ndbcluster_init(void);
static int ndbcluster_init(void *);
static int ndbcluster_end(ha_panic_function flag);
static bool ndbcluster_show_status(THD*,stat_print_fn *,enum ha_stat_type);
static int ndbcluster_alter_tablespace(THD* thd, st_alter_tablespace *info);
static int ndbcluster_fill_files_table(THD *thd, TABLE_LIST *tables, COND *cond);

handlerton ndbcluster_hton;
handlerton *ndbcluster_hton;

static handler *ndbcluster_create_handler(TABLE_SHARE *table,
                                          MEM_ROOT *mem_root)
@@ -4005,7 +4005,7 @@ int ha_ndbcluster::external_lock(THD *thd, int lock_type)
        thd_ndb->init_open_tables();
        thd_ndb->stmt= trans;
	thd_ndb->query_state&= NDB_QUERY_NORMAL;
        trans_register_ha(thd, FALSE, &ndbcluster_hton);
        trans_register_ha(thd, FALSE, ndbcluster_hton);
      } 
      else 
      { 
@@ -4021,7 +4021,7 @@ int ha_ndbcluster::external_lock(THD *thd, int lock_type)
          thd_ndb->init_open_tables();
          thd_ndb->all= trans; 
	  thd_ndb->query_state&= NDB_QUERY_NORMAL;
          trans_register_ha(thd, TRUE, &ndbcluster_hton);
          trans_register_ha(thd, TRUE, ndbcluster_hton);

          /*
            If this is the start of a LOCK TABLE, a table look 
@@ -4175,7 +4175,7 @@ int ha_ndbcluster::start_stmt(THD *thd, thr_lock_type lock_type)
      ERR_RETURN(ndb->getNdbError());
    no_uncommitted_rows_reset(thd);
    thd_ndb->stmt= trans;
    trans_register_ha(thd, FALSE, &ndbcluster_hton);
    trans_register_ha(thd, FALSE, ndbcluster_hton);
  }
  thd_ndb->query_state&= NDB_QUERY_NORMAL;
  m_active_trans= trans;
@@ -5544,7 +5544,7 @@ void ha_ndbcluster::get_auto_increment(ulonglong offset, ulonglong increment,
                HA_HAS_RECORDS

ha_ndbcluster::ha_ndbcluster(TABLE_SHARE *table_arg):
  handler(&ndbcluster_hton, table_arg),
  handler(ndbcluster_hton, table_arg),
  m_active_trans(NULL),
  m_active_cursor(NULL),
  m_table(NULL),
@@ -6372,35 +6372,36 @@ static int connect_callback()

extern int ndb_dictionary_is_mysqld;

static int ndbcluster_init()
static int ndbcluster_init(void *p)
{
  int res;
  DBUG_ENTER("ndbcluster_init");

  ndb_dictionary_is_mysqld= 1;

  {
    handlerton &h= ndbcluster_hton;
    h.state=            have_ndbcluster;
    h.db_type=          DB_TYPE_NDBCLUSTER;
    h.close_connection= ndbcluster_close_connection;
    h.commit=           ndbcluster_commit;
    h.rollback=         ndbcluster_rollback;
    h.create=           ndbcluster_create_handler; /* Create a new handler */
    h.drop_database=    ndbcluster_drop_database;  /* Drop a database */
    h.panic=            ndbcluster_end;            /* Panic call */
    h.show_status=      ndbcluster_show_status;    /* Show status */
    h.alter_tablespace= ndbcluster_alter_tablespace;    /* Show status */
    h.partition_flags=  ndbcluster_partition_flags; /* Partition flags */
    h.alter_table_flags=ndbcluster_alter_table_flags; /* Alter table flags */
    h.fill_files_table= ndbcluster_fill_files_table;
  ndbcluster_hton= (handlerton *)p;

  {
    handlerton *h= ndbcluster_hton;
    h->state=            have_ndbcluster;
    h->db_type=          DB_TYPE_NDBCLUSTER;
    h->close_connection= ndbcluster_close_connection;
    h->commit=           ndbcluster_commit;
    h->rollback=         ndbcluster_rollback;
    h->create=           ndbcluster_create_handler; /* Create a new handler */
    h->drop_database=    ndbcluster_drop_database;  /* Drop a database */
    h->panic=            ndbcluster_end;            /* Panic call */
    h->show_status=      ndbcluster_show_status;    /* Show status */
    h->alter_tablespace= ndbcluster_alter_tablespace;    /* Show status */
    h->partition_flags=  ndbcluster_partition_flags; /* Partition flags */
    h->alter_table_flags=ndbcluster_alter_table_flags; /* Alter table flags */
    h->fill_files_table= ndbcluster_fill_files_table;
#ifdef HAVE_NDB_BINLOG
    ndbcluster_binlog_init_handlerton();
#endif
    h.flags=            HTON_CAN_RECREATE | HTON_TEMPORARY_NOT_SUPPORTED;
    h.discover=         ndbcluster_discover;
    h.find_files= ndbcluster_find_files;
    h.table_exists_in_engine= ndbcluster_table_exists_in_engine;
    h->flags=            HTON_CAN_RECREATE | HTON_TEMPORARY_NOT_SUPPORTED;
    h->discover=         ndbcluster_discover;
    h->find_files= ndbcluster_find_files;
    h->table_exists_in_engine= ndbcluster_table_exists_in_engine;
  }

  if (have_ndbcluster != SHOW_OPTION_YES)
@@ -6509,6 +6510,8 @@ static int ndbcluster_init()
    delete g_ndb_cluster_connection;
  g_ndb_cluster_connection= NULL;
  have_ndbcluster= SHOW_OPTION_DISABLED;	// If we couldn't use handler
  ndbcluster_hton->state= SHOW_OPTION_DISABLED;               // If we couldn't use handler

  DBUG_RETURN(TRUE);
}

@@ -8113,7 +8116,7 @@ pthread_handler_t ndb_util_thread_func(void *arg __attribute__((unused)))
    Wait for cluster to start
  */
  pthread_mutex_lock(&LOCK_ndb_util_thread);
  while (!ndb_cluster_node_id && (ndbcluster_hton.slot != ~(uint)0))
  while (!ndb_cluster_node_id && (ndbcluster_hton->slot != ~(uint)0))
  {
    /* ndb not connected yet */
    set_timespec(abstime, 1);
@@ -10604,7 +10607,7 @@ SHOW_VAR ndb_status_variables_export[]= {
};

struct st_mysql_storage_engine ndbcluster_storage_engine=
{ MYSQL_HANDLERTON_INTERFACE_VERSION, &ndbcluster_hton };
{ MYSQL_HANDLERTON_INTERFACE_VERSION, ndbcluster_hton };

mysql_declare_plugin(ndbcluster)
{
+4 −4
Original line number Diff line number Diff line
@@ -662,9 +662,9 @@ static int ndbcluster_binlog_func(THD *thd, enum_binlog_func fn, void *arg)

void ndbcluster_binlog_init_handlerton()
{
  handlerton &h= ndbcluster_hton;
  h.binlog_func=      ndbcluster_binlog_func;
  h.binlog_log_query= ndbcluster_binlog_log_query;
  handlerton *h= ndbcluster_hton;
  h->binlog_func=      ndbcluster_binlog_func;
  h->binlog_log_query= ndbcluster_binlog_log_query;
}


@@ -3431,7 +3431,7 @@ pthread_handler_t ndb_binlog_thread_func(void *arg)

    if (thd_ndb == NULL)
    {
      DBUG_ASSERT(ndbcluster_hton.slot != ~(uint)0);
      DBUG_ASSERT(ndbcluster_hton->slot != ~(uint)0);
      if (!(thd_ndb= ha_ndbcluster::seize_thd_ndb()))
      {
        sql_print_error("Could not allocate Thd_ndb object");
+3 −3
Original line number Diff line number Diff line
@@ -103,7 +103,7 @@ extern pthread_mutex_t injector_mutex;
extern pthread_cond_t  injector_cond;

extern unsigned char g_node_id_map[max_ndb_nodes];
extern handlerton ndbcluster_hton;
extern handlerton *ndbcluster_hton;
extern pthread_t ndb_util_thread;
extern pthread_mutex_t LOCK_ndb_util_thread;
extern pthread_cond_t COND_ndb_util_thread;
@@ -212,10 +212,10 @@ inline void real_free_share(NDB_SHARE **share)

inline
Thd_ndb *
get_thd_ndb(THD *thd) { return (Thd_ndb *) thd->ha_data[ndbcluster_hton.slot]; }
get_thd_ndb(THD *thd) { return (Thd_ndb *) thd->ha_data[ndbcluster_hton->slot]; }

inline
void
set_thd_ndb(THD *thd, Thd_ndb *thd_ndb) { thd->ha_data[ndbcluster_hton.slot]= thd_ndb; }
set_thd_ndb(THD *thd, Thd_ndb *thd_ndb) { thd->ha_data[ndbcluster_hton->slot]= thd_ndb; }

Ndb* check_ndb_in_thd(THD* thd);
+17 −13
Original line number Diff line number Diff line
@@ -74,16 +74,20 @@ static handler *partition_create_handler(TABLE_SHARE *share,
static uint partition_flags();
static uint alter_table_flags(uint flags);

handlerton partition_hton;
handlerton *partition_hton;

static int partition_initialize()
static int partition_initialize(void *p)
{
  partition_hton.state= SHOW_OPTION_YES;
  partition_hton.db_type= DB_TYPE_PARTITION_DB;
  partition_hton.create= partition_create_handler;
  partition_hton.partition_flags= partition_flags;
  partition_hton.alter_table_flags= alter_table_flags;
  partition_hton.flags= HTON_NOT_USER_SELECTABLE | HTON_HIDDEN;

  partition_hton= (handlerton *)p;

  partition_hton->state= SHOW_OPTION_YES;
  partition_hton->db_type= DB_TYPE_PARTITION_DB;
  partition_hton->create= partition_create_handler;
  partition_hton->partition_flags= partition_flags;
  partition_hton->alter_table_flags= alter_table_flags;
  partition_hton->flags= HTON_NOT_USER_SELECTABLE | HTON_HIDDEN;

  return 0;
}

@@ -152,7 +156,7 @@ static uint alter_table_flags(uint flags __attribute__((unused)))
*/

ha_partition::ha_partition(TABLE_SHARE *share)
  :handler(&partition_hton, share), m_part_info(NULL), m_create_handler(FALSE),
  :handler(partition_hton, share), m_part_info(NULL), m_create_handler(FALSE),
   m_is_sub_partitioned(0)
{
  DBUG_ENTER("ha_partition::ha_partition(table)");
@@ -173,7 +177,7 @@ ha_partition::ha_partition(TABLE_SHARE *share)
*/

ha_partition::ha_partition(partition_info *part_info)
  :handler(&partition_hton, NULL), m_part_info(part_info),
  :handler(partition_hton, NULL), m_part_info(part_info),
   m_create_handler(TRUE),
   m_is_sub_partitioned(m_part_info->is_sub_partitioned())

@@ -2016,7 +2020,7 @@ bool ha_partition::create_handlers(MEM_ROOT *mem_root)
    DBUG_PRINT("info", ("engine_type: %u", m_engine_array[i]));
  }
  /* For the moment we only support partition over the same table engine */
  if (m_engine_array[0] == &myisam_hton)
  if (m_engine_array[0] == myisam_hton)
  {
    DBUG_PRINT("info", ("MyISAM"));
    m_myisam= TRUE;
@@ -2089,7 +2093,7 @@ bool ha_partition::new_handlers_from_part_info(MEM_ROOT *mem_root)
                 (uint) ha_legacy_type(part_elem->engine_type)));
    }
  } while (++i < m_part_info->no_parts);
  if (part_elem->engine_type == &myisam_hton)
  if (part_elem->engine_type == myisam_hton)
  {
    DBUG_PRINT("info", ("MyISAM"));
    m_myisam= TRUE;
@@ -5628,7 +5632,7 @@ static int free_share(PARTITION_SHARE *share)
#endif /* NOT_USED */

struct st_mysql_storage_engine partition_storage_engine=
{ MYSQL_HANDLERTON_INTERFACE_VERSION, &partition_hton };
{ MYSQL_HANDLERTON_INTERFACE_VERSION, partition_hton };

mysql_declare_plugin(partition)
{
Loading