~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/statement/drop_table.cc

This patch completes the first step in the splitting of
the XA resource manager API from the storage engine API,
as outlined in the specification here:

http://drizzle.org/wiki/XaStorageEngine

* Splits plugin::StorageEngine into a base StorageEngine
  class and two derived classes, TransactionalStorageEngine
  and XaStorageEngine.  XaStorageEngine derives from
  TransactionalStorageEngine and creates the XA Resource
  Manager API for storage engines.

  - The methods moved from StorageEngine to TransactionalStorageEngine
    include releaseTemporaryLatches(), startConsistentSnapshot(), 
    commit(), rollback(), setSavepoint(), releaseSavepoint(),
    rollbackToSavepoint() and hasTwoPhaseCommit()
  - The methods moved from StorageEngine to XaStorageEngine
    include recover(), commitXid(), rollbackXid(), and prepare()

* Places all static "EngineVector"s into their proper
  namespaces (typedefs belong in header files, not implementation files)
  and places all static methods corresponding
  to either only transactional engines or only XA engines
  into their respective files in /drizzled/plugin/

* Modifies the InnoDB "handler" files to extend plugin::XaStorageEngine
  and not plugin::StorageEngine

The next step, as outlined in the wiki spec page above, is to isolate
the XA Resource Manager API into its own plugin class and modify
plugin::XaStorageEngine to implement plugin::XaResourceManager via
composition.  This is necessary to enable building plugins which can
participate in an XA transaction *without having to have that plugin
implement the entire storage engine API*

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2009 Sun Microsystems, Inc.
 
4
 *  Copyright (C) 2009 Sun Microsystems
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
18
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
19
 */
20
20
 
21
 
#include <config.h>
 
21
#include "config.h"
22
22
#include <drizzled/show.h>
23
23
#include <drizzled/session.h>
24
24
#include <drizzled/lock.h>
25
25
#include <drizzled/statement/drop_table.h>
26
 
#include <drizzled/sql_table.h>
 
26
#include <drizzled/plugin/info_schema_table.h>
 
27
#include "drizzled/sql_table.h"
27
28
 
28
29
namespace drizzled
29
30
{
33
34
 delete (drop) tables.
34
35
 
35
36
  SYNOPSIS
36
 
   rm_table()
 
37
   mysql_rm_table()
37
38
   session                      Thread handle
38
39
   tables               List of tables to delete
39
40
   if_exists            If 1, don't give error if one table doesn't exists
53
54
 
54
55
*/
55
56
 
56
 
static bool rm_table(Session *session, TableList *tables, bool if_exists, bool drop_temporary)
 
57
static bool mysql_rm_table(Session *session, TableList *tables, bool if_exists, bool drop_temporary)
57
58
{
58
59
  bool error, need_start_waiting= false;
59
60
 
 
61
  /**
 
62
   * @todo this is a result of retaining the behavior that was here before. This should be removed
 
63
   * and the correct error handling should be done in doDropTable for the I_S engine. There is an
 
64
   * issue here with dropping tables with the same name as an I_S table. How do we know if we are
 
65
   * attemping to drop an I_S table or a regular table with the same name as an I_S table? For now,
 
66
   * we simply check if the current database is information_schema
 
67
   */
 
68
  plugin::InfoSchemaTable *sch_table= plugin::InfoSchemaTable::getTable(tables->table_name);
 
69
  if (sch_table &&
 
70
      session->db.compare(INFORMATION_SCHEMA_NAME) == 0)
 
71
  {
 
72
    my_error(ER_DBACCESS_DENIED_ERROR, MYF(0), "", "", INFORMATION_SCHEMA_NAME.c_str());
 
73
    return true;
 
74
  }
 
75
 
60
76
  /* mark for close and remove all cached entries */
61
77
 
62
 
  if (not drop_temporary)
 
78
  if (! drop_temporary)
63
79
  {
64
 
    if (not (need_start_waiting= not session->wait_if_global_read_lock(false, true)))
 
80
    if (!(need_start_waiting= !wait_if_global_read_lock(session, false, true)))
65
81
      return true;
66
82
  }
67
83
 
68
84
  /*
69
 
    Acquire table::Cache::singleton().mutex() after wait_if_global_read_lock(). If we would hold
70
 
    table::Cache::singleton().mutex() during wait_if_global_read_lock(), other threads could not
 
85
    Acquire LOCK_open after wait_if_global_read_lock(). If we would hold
 
86
    LOCK_open during wait_if_global_read_lock(), other threads could not
71
87
    close their tables. This would make a pretty deadlock.
72
88
  */
73
 
  error= rm_table_part2(session, tables, if_exists, drop_temporary);
 
89
  error= mysql_rm_table_part2(session, tables, if_exists, drop_temporary);
74
90
 
75
91
  if (need_start_waiting)
76
 
  {
77
 
    session->startWaitingGlobalReadLock();
78
 
  }
 
92
    start_waiting_global_read_lock(session);
79
93
 
80
94
  if (error)
81
95
    return true;
87
101
 
88
102
bool statement::DropTable::execute()
89
103
{
90
 
  TableList *first_table= (TableList *) getSession()->getLex()->select_lex.table_list.first;
91
 
  TableList *all_tables= getSession()->getLex()->query_tables;
 
104
  TableList *first_table= (TableList *) session->lex->select_lex.table_list.first;
 
105
  TableList *all_tables= session->lex->query_tables;
92
106
  assert(first_table == all_tables && first_table != 0);
93
 
 
94
 
  if (not drop_temporary)
 
107
  if (! drop_temporary)
95
108
  {
96
 
    if (getSession()->inTransaction())
 
109
    if (! session->endActiveTransaction())
97
110
    {
98
 
      my_error(ER_TRANSACTIONAL_DDL_NOT_SUPPORTED, MYF(0));
99
111
      return true;
100
112
    }
101
113
  }
102
 
 
103
 
  /* DDL and binlog write order protected by table::Cache::singleton().mutex() */
104
 
 
105
 
  return rm_table(getSession(), first_table, drop_if_exists, drop_temporary);
 
114
  /* DDL and binlog write order protected by LOCK_open */
 
115
  bool res= mysql_rm_table(session,
 
116
                           first_table,
 
117
                           drop_if_exists,
 
118
                           drop_temporary);
 
119
  return res;
106
120
}
107
121
 
108
122
} /* namespace drizzled */