~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/db.cc

  • Committer: Brian Aker
  • Date: 2011-01-11 07:12:09 UTC
  • mfrom: (2068.5.6 catalogs)
  • Revision ID: brian@gir-3-20110111071209-ntbex8btgayoq00v
MergeĀ inĀ catalogs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
46
46
 
47
47
#include <boost/thread/mutex.hpp>
48
48
 
49
 
boost::mutex LOCK_create_db;
50
 
 
51
49
#include "drizzled/internal/my_sys.h"
52
50
 
53
51
#define MAX_DROP_TABLE_Q_LEN      1024
88
86
 
89
87
  /*
90
88
    Do not create database if another thread is holding read lock.
91
 
    Wait for global read lock before acquiring LOCK_create_db.
 
89
    Wait for global read lock before acquiring session->catalog()->schemaLock().
92
90
    After wait_if_global_read_lock() we have protection against another
93
 
    global read lock. If we would acquire LOCK_create_db first,
 
91
    global read lock. If we would acquire session->catalog()->schemaLock() first,
94
92
    another thread could step in and get the global read lock before we
95
93
    reach wait_if_global_read_lock(). If this thread tries the same as we
96
 
    (admin a db), it would then go and wait on LOCK_create_db...
 
94
    (admin a db), it would then go and wait on session->catalog()->schemaLock()...
97
95
    Furthermore wait_if_global_read_lock() checks if the current thread
98
96
    has the global read lock and refuses the operation with
99
97
    ER_CANT_UPDATE_WITH_READLOCK if applicable.
108
106
 
109
107
  // @todo push this lock down into the engine
110
108
  {
111
 
    boost::mutex::scoped_lock scopedLock(LOCK_create_db);
 
109
    boost::mutex::scoped_lock scopedLock(session->catalog().schemaLock());
112
110
 
113
111
    // Check to see if it exists already.  
114
112
    SchemaIdentifier schema_identifier(schema_message.name());
152
150
 
153
151
  /*
154
152
    Do not alter database if another thread is holding read lock.
155
 
    Wait for global read lock before acquiring LOCK_create_db.
 
153
    Wait for global read lock before acquiring session->catalog()->schemaLock().
156
154
    After wait_if_global_read_lock() we have protection against another
157
 
    global read lock. If we would acquire LOCK_create_db first,
 
155
    global read lock. If we would acquire session->catalog()->schemaLock() first,
158
156
    another thread could step in and get the global read lock before we
159
157
    reach wait_if_global_read_lock(). If this thread tries the same as we
160
 
    (admin a db), it would then go and wait on LOCK_create_db...
 
158
    (admin a db), it would then go and wait on session->catalog()->schemaLock()...
161
159
    Furthermore wait_if_global_read_lock() checks if the current thread
162
160
    has the global read lock and refuses the operation with
163
161
    ER_CANT_UPDATE_WITH_READLOCK if applicable.
167
165
 
168
166
  bool success;
169
167
  {
170
 
    boost::mutex::scoped_lock scopedLock(LOCK_create_db);
 
168
    boost::mutex::scoped_lock scopedLock(session->catalog().schemaLock());
171
169
 
172
170
    SchemaIdentifier schema_idenifier(schema_message.name());
173
171
    if (not plugin::StorageEngine::doesSchemaExist(schema_idenifier))
218
216
 
219
217
  /*
220
218
    Do not drop database if another thread is holding read lock.
221
 
    Wait for global read lock before acquiring LOCK_create_db.
 
219
    Wait for global read lock before acquiring session->catalog()->schemaLock().
222
220
    After wait_if_global_read_lock() we have protection against another
223
 
    global read lock. If we would acquire LOCK_create_db first,
 
221
    global read lock. If we would acquire session->catalog()->schemaLock() first,
224
222
    another thread could step in and get the global read lock before we
225
223
    reach wait_if_global_read_lock(). If this thread tries the same as we
226
 
    (admin a db), it would then go and wait on LOCK_create_db...
 
224
    (admin a db), it would then go and wait on session->catalog()->schemaLock()...
227
225
    Furthermore wait_if_global_read_lock() checks if the current thread
228
226
    has the global read lock and refuses the operation with
229
227
    ER_CANT_UPDATE_WITH_READLOCK if applicable.
235
233
 
236
234
  do
237
235
  {
238
 
    boost::mutex::scoped_lock scopedLock(LOCK_create_db);
 
236
    boost::mutex::scoped_lock scopedLock(session->catalog().schemaLock());
239
237
 
240
238
    /* See if the schema exists */
241
239
    if (not plugin::StorageEngine::doesSchemaExist(schema_identifier))