~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/innobase/handler/ha_innodb.cc

  • Committer: Siddharth Prakash Singh
  • Date: 2010-03-26 19:25:23 UTC
  • mfrom: (1410 drizzle)
  • mto: This revision was merged to the branch mainline in revision 1425.
  • Revision ID: spsneo@spsneo-laptop-20100326192523-ibjlbt1p692vobtj
merging with trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
80
80
#include "drizzled/field/varstring.h"
81
81
#include "drizzled/field/timestamp.h"
82
82
#include "drizzled/plugin/xa_storage_engine.h"
 
83
#include "drizzled/plugin/daemon.h"
83
84
#include "drizzled/memory/multi_malloc.h"
84
85
#include "drizzled/pthread_globals.h"
85
86
#include "drizzled/named_savepoint.h"
260
261
class InnobaseEngine : public plugin::XaStorageEngine
261
262
{
262
263
public:
263
 
  InnobaseEngine(string name_arg) :
 
264
  explicit InnobaseEngine(string name_arg) :
264
265
    plugin::XaStorageEngine(name_arg,
265
 
                          HTON_NULL_IN_KEY |
266
 
                          HTON_CAN_INDEX_BLOBS |
267
 
                          HTON_PRIMARY_KEY_REQUIRED_FOR_POSITION |
268
 
                          HTON_PRIMARY_KEY_IN_READ_INDEX |
269
 
                          HTON_PARTIAL_COLUMN_READ |
270
 
                          HTON_TABLE_SCAN_ON_INDEX |
271
 
                          HTON_HAS_DOES_TRANSACTIONS)
 
266
                            HTON_NULL_IN_KEY |
 
267
                            HTON_CAN_INDEX_BLOBS |
 
268
                            HTON_PRIMARY_KEY_REQUIRED_FOR_POSITION |
 
269
                            HTON_PRIMARY_KEY_IN_READ_INDEX |
 
270
                            HTON_PARTIAL_COLUMN_READ |
 
271
                            HTON_TABLE_SCAN_ON_INDEX |
 
272
                            HTON_HAS_FOREIGN_KEYS |
 
273
                            HTON_HAS_DOES_TRANSACTIONS)
272
274
  {
273
275
    table_definition_ext= plugin::DEFAULT_DEFINITION_FILE_EXT;
274
276
    addAlias("INNOBASE");
275
277
  }
 
278
 
 
279
  virtual ~InnobaseEngine()
 
280
  {
 
281
    int err= 0;
 
282
    if (innodb_inited) {
 
283
 
 
284
      srv_fast_shutdown = (ulint) innobase_fast_shutdown;
 
285
      innodb_inited = 0;
 
286
      hash_table_free(innobase_open_tables);
 
287
      innobase_open_tables = NULL;
 
288
      if (innobase_shutdown_for_mysql() != DB_SUCCESS) {
 
289
        err = 1;
 
290
      }
 
291
      srv_free_paths_and_sizes();
 
292
      if (internal_innobase_data_file_path)
 
293
        free(internal_innobase_data_file_path);
 
294
      pthread_mutex_destroy(&innobase_share_mutex);
 
295
      pthread_mutex_destroy(&prepare_commit_mutex);
 
296
      pthread_mutex_destroy(&commit_threads_m);
 
297
      pthread_mutex_destroy(&commit_cond_m);
 
298
      pthread_cond_destroy(&commit_cond);
 
299
    }
 
300
  }
 
301
 
276
302
private:
277
303
  virtual int doStartTransaction(Session *session, start_transaction_option_t options);
278
304
  virtual void doStartStatement(Session *session);
396
422
                                Table& form,
397
423
                                drizzled::TableIdentifier &identifier,
398
424
                                message::Table&);
399
 
  UNIV_INTERN int doRenameTable(Session* session,
400
 
                                const char* from,
401
 
                                const char* to);
 
425
  UNIV_INTERN int doRenameTable(Session&, TableIdentifier &from, TableIdentifier &to);
402
426
  UNIV_INTERN int doDropTable(Session& session, TableIdentifier &identifier);
403
427
 
404
428
  UNIV_INTERN virtual bool get_error_message(int error, String *buf);
511
535
  NULL, NULL, 50, 1, 1024 * 1024 * 1024, 0);
512
536
 
513
537
 
514
 
/***********************************************************************
515
 
Closes an InnoDB database. */
516
 
static
517
 
int
518
 
innobase_deinit(plugin::Registry &registry);
519
 
 
520
538
/*****************************************************************//**
521
539
Commits a transaction in an InnoDB database. */
522
540
static
1680
1698
int
1681
1699
innobase_init(
1682
1700
/*==========*/
1683
 
        plugin::Registry        &registry)      /*!< in: Drizzle Plugin Registry */
 
1701
        plugin::Context &context)       /*!< in: Drizzle Plugin Context */
1684
1702
{
1685
1703
        static char     current_dir[3];         /*!< Set if using current lib */
1686
1704
        int             err;
1690
1708
 
1691
1709
        innodb_engine_ptr= new InnobaseEngine(innobase_engine_name);
1692
1710
 
1693
 
 
1694
1711
        ut_a(DATA_MYSQL_TRUE_VARCHAR == (ulint)DRIZZLE_TYPE_VARCHAR);
1695
1712
 
1696
1713
#ifdef UNIV_DEBUG
1961
1978
 
1962
1979
        status_table_function_ptr= new InnodbStatusTool;
1963
1980
 
1964
 
        registry.add(innodb_engine_ptr);
 
1981
        context.add(innodb_engine_ptr);
1965
1982
 
1966
 
        registry.add(status_table_function_ptr);
 
1983
        context.add(status_table_function_ptr);
1967
1984
 
1968
1985
        cmp_tool= new(std::nothrow)CmpTool(false);
1969
 
        registry.add(cmp_tool);
 
1986
        context.add(cmp_tool);
1970
1987
 
1971
1988
        cmp_reset_tool= new(std::nothrow)CmpTool(true);
1972
 
        registry.add(cmp_reset_tool);
 
1989
        context.add(cmp_reset_tool);
1973
1990
 
1974
1991
        cmp_mem_tool= new(std::nothrow)CmpmemTool(false);
1975
 
        registry.add(cmp_mem_tool);
 
1992
        context.add(cmp_mem_tool);
1976
1993
 
1977
1994
        cmp_mem_reset_tool= new(std::nothrow)CmpmemTool(true);
1978
 
        registry.add(cmp_mem_reset_tool);
 
1995
        context.add(cmp_mem_reset_tool);
1979
1996
 
1980
1997
        innodb_trx_tool= new(std::nothrow)InnodbTrxTool("INNODB_TRX");
1981
 
        registry.add(innodb_trx_tool);
 
1998
        context.add(innodb_trx_tool);
1982
1999
 
1983
2000
        innodb_locks_tool= new(std::nothrow)InnodbTrxTool("INNODB_LOCKS");
1984
 
        registry.add(innodb_locks_tool);
 
2001
        context.add(innodb_locks_tool);
1985
2002
 
1986
2003
        innodb_lock_waits_tool= new(std::nothrow)InnodbTrxTool("INNODB_LOCK_WAITS");
1987
 
        registry.add(innodb_lock_waits_tool);
 
2004
        context.add(innodb_lock_waits_tool);
1988
2005
 
1989
2006
        /* Get the current high water mark format. */
1990
2007
        innobase_file_format_check = (char*) trx_sys_file_format_max_get();
1994
2011
        return(TRUE);
1995
2012
}
1996
2013
 
1997
 
/*******************************************************************//**
1998
 
Closes an InnoDB database.
1999
 
@return TRUE if error */
2000
 
static
2001
 
int
2002
 
innobase_deinit(plugin::Registry &registry)
2003
 
{
2004
 
        int     err= 0;
2005
 
 
2006
 
        registry.remove(status_table_function_ptr);
2007
 
        delete status_table_function_ptr;
2008
 
 
2009
 
        registry.remove(cmp_tool);
2010
 
        delete cmp_tool;
2011
 
 
2012
 
        registry.remove(cmp_reset_tool);
2013
 
        delete cmp_reset_tool;
2014
 
 
2015
 
        registry.remove(cmp_mem_tool);
2016
 
        delete cmp_mem_tool;
2017
 
 
2018
 
        registry.remove(cmp_mem_reset_tool);
2019
 
        delete cmp_mem_reset_tool;
2020
 
 
2021
 
        registry.remove(innodb_trx_tool);
2022
 
        delete innodb_trx_tool;
2023
 
 
2024
 
        registry.remove(innodb_locks_tool);
2025
 
        delete innodb_locks_tool;
2026
 
 
2027
 
        registry.remove(innodb_lock_waits_tool);
2028
 
        delete innodb_lock_waits_tool;
2029
 
 
2030
 
        registry.remove(innodb_engine_ptr);
2031
 
        delete innodb_engine_ptr;
2032
 
 
2033
 
        if (innodb_inited) {
2034
 
 
2035
 
                srv_fast_shutdown = (ulint) innobase_fast_shutdown;
2036
 
                innodb_inited = 0;
2037
 
                hash_table_free(innobase_open_tables);
2038
 
                innobase_open_tables = NULL;
2039
 
                if (innobase_shutdown_for_mysql() != DB_SUCCESS) {
2040
 
                        err = 1;
2041
 
                }
2042
 
                srv_free_paths_and_sizes();
2043
 
                if (internal_innobase_data_file_path)
2044
 
                  free(internal_innobase_data_file_path);
2045
 
                pthread_mutex_destroy(&innobase_share_mutex);
2046
 
                pthread_mutex_destroy(&prepare_commit_mutex);
2047
 
                pthread_mutex_destroy(&commit_threads_m);
2048
 
                pthread_mutex_destroy(&commit_cond_m);
2049
 
                pthread_cond_destroy(&commit_cond);
2050
 
        }
2051
 
 
2052
 
        return(err);
2053
 
}
2054
2014
 
2055
2015
/****************************************************************//**
2056
2016
Flushes InnoDB logs to disk and makes a checkpoint. Really, a commit flushes
6081
6041
/*********************************************************************//**
6082
6042
Renames an InnoDB table.
6083
6043
@return 0 or error code */
6084
 
UNIV_INTERN
6085
 
int
6086
 
InnobaseEngine::doRenameTable(
6087
 
/*======================*/
6088
 
        Session*        session,
6089
 
        const char*     from,   /*!< in: old name of the table */
6090
 
        const char*     to)     /*!< in: new name of the table */
 
6044
UNIV_INTERN int InnobaseEngine::doRenameTable(Session &session, TableIdentifier &from, TableIdentifier &to)
6091
6045
{
6092
6046
        trx_t*  trx;
6093
6047
        int     error;
6096
6050
        /* Get the transaction associated with the current session, or create one
6097
6051
        if not yet created */
6098
6052
 
6099
 
        parent_trx = check_trx_exists(session);
 
6053
        parent_trx = check_trx_exists(&session);
6100
6054
 
6101
6055
        /* In case MySQL calls this in the middle of a SELECT query, release
6102
6056
        possible adaptive hash latch to avoid deadlocks of threads */
6103
6057
 
6104
6058
        trx_search_latch_release_if_reserved(parent_trx);
6105
6059
 
6106
 
        trx = innobase_trx_allocate(session);
 
6060
        trx = innobase_trx_allocate(&session);
6107
6061
 
6108
 
        error = innobase_rename_table(trx, from, to, TRUE);
 
6062
        error = innobase_rename_table(trx, from.getPath().c_str(), to.getPath().c_str(), TRUE);
6109
6063
 
6110
6064
        /* Tell the InnoDB server that there might be work for
6111
6065
        utility threads: */
8839
8793
  "Supports transactions, row-level locking, and foreign keys",
8840
8794
  PLUGIN_LICENSE_GPL,
8841
8795
  innobase_init, /* Plugin Init */
8842
 
  innobase_deinit, /* Plugin Deinit */
8843
8796
  innobase_system_variables, /* system variables */
8844
8797
  NULL /* reserved */
8845
8798
}