~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/db.cc

  • Committer: Brian Aker
  • Date: 2009-03-27 00:16:33 UTC
  • mfrom: (965.1.1 merge)
  • Revision ID: brian@tangent.org-20090327001633-qfvtqnccw5rh8qn5
Merge Brian

Show diffs side-by-side

added added

removed removed

Lines of Context:
309
309
 
310
310
  /*
311
311
    Do not create database if another thread is holding read lock.
312
 
    Wait for global read lock before acquiring LOCK_create_db.
 
312
    Wait for global read lock before acquiring LOCK_drizzleclient_create_db.
313
313
    After wait_if_global_read_lock() we have protection against another
314
 
    global read lock. If we would acquire LOCK_create_db first,
 
314
    global read lock. If we would acquire LOCK_drizzleclient_create_db first,
315
315
    another thread could step in and get the global read lock before we
316
316
    reach wait_if_global_read_lock(). If this thread tries the same as we
317
 
    (admin a db), it would then go and wait on LOCK_create_db...
 
317
    (admin a db), it would then go and wait on LOCK_drizzleclient_create_db...
318
318
    Furthermore wait_if_global_read_lock() checks if the current thread
319
319
    has the global read lock and refuses the operation with
320
320
    ER_CANT_UPDATE_WITH_READLOCK if applicable.
325
325
    goto exit2;
326
326
  }
327
327
 
328
 
  pthread_mutex_lock(&LOCK_create_db);
 
328
  pthread_mutex_lock(&LOCK_drizzleclient_create_db);
329
329
 
330
330
  /* Check directory */
331
331
  path_len= build_table_filename(path, sizeof(path), db, "", "", 0);
385
385
  }
386
386
 
387
387
exit:
388
 
  pthread_mutex_unlock(&LOCK_create_db);
 
388
  pthread_mutex_unlock(&LOCK_drizzleclient_create_db);
389
389
  start_waiting_global_read_lock(session);
390
390
exit2:
391
391
  return(error);
403
403
 
404
404
  /*
405
405
    Do not alter database if another thread is holding read lock.
406
 
    Wait for global read lock before acquiring LOCK_create_db.
 
406
    Wait for global read lock before acquiring LOCK_drizzleclient_create_db.
407
407
    After wait_if_global_read_lock() we have protection against another
408
 
    global read lock. If we would acquire LOCK_create_db first,
 
408
    global read lock. If we would acquire LOCK_drizzleclient_create_db first,
409
409
    another thread could step in and get the global read lock before we
410
410
    reach wait_if_global_read_lock(). If this thread tries the same as we
411
 
    (admin a db), it would then go and wait on LOCK_create_db...
 
411
    (admin a db), it would then go and wait on LOCK_drizzleclient_create_db...
412
412
    Furthermore wait_if_global_read_lock() checks if the current thread
413
413
    has the global read lock and refuses the operation with
414
414
    ER_CANT_UPDATE_WITH_READLOCK if applicable.
416
416
  if ((error=wait_if_global_read_lock(session,0,1)))
417
417
    goto exit;
418
418
 
419
 
  pthread_mutex_lock(&LOCK_create_db);
 
419
  pthread_mutex_lock(&LOCK_drizzleclient_create_db);
420
420
 
421
421
  /* Change options if current database is being altered. */
422
422
  path_len= build_table_filename(path, sizeof(path), db, "", "", 0);
426
426
  if (error && error != EEXIST)
427
427
  {
428
428
    /* TODO: find some witty way of getting back an error message */
429
 
    pthread_mutex_unlock(&LOCK_create_db);
 
429
    pthread_mutex_unlock(&LOCK_drizzleclient_create_db);
430
430
    goto exit;
431
431
  }
432
432
 
441
441
  (void)replicator_statement(session, session->query, session->query_length);
442
442
  session->my_ok(result);
443
443
 
444
 
  pthread_mutex_unlock(&LOCK_create_db);
 
444
  pthread_mutex_unlock(&LOCK_drizzleclient_create_db);
445
445
  start_waiting_global_read_lock(session);
446
446
exit:
447
447
  return(error);
482
482
 
483
483
  /*
484
484
    Do not drop database if another thread is holding read lock.
485
 
    Wait for global read lock before acquiring LOCK_create_db.
 
485
    Wait for global read lock before acquiring LOCK_drizzleclient_create_db.
486
486
    After wait_if_global_read_lock() we have protection against another
487
 
    global read lock. If we would acquire LOCK_create_db first,
 
487
    global read lock. If we would acquire LOCK_drizzleclient_create_db first,
488
488
    another thread could step in and get the global read lock before we
489
489
    reach wait_if_global_read_lock(). If this thread tries the same as we
490
 
    (admin a db), it would then go and wait on LOCK_create_db...
 
490
    (admin a db), it would then go and wait on LOCK_drizzleclient_create_db...
491
491
    Furthermore wait_if_global_read_lock() checks if the current thread
492
492
    has the global read lock and refuses the operation with
493
493
    ER_CANT_UPDATE_WITH_READLOCK if applicable.
498
498
    goto exit2;
499
499
  }
500
500
 
501
 
  pthread_mutex_lock(&LOCK_create_db);
 
501
  pthread_mutex_lock(&LOCK_drizzleclient_create_db);
502
502
 
503
503
  length= build_table_filename(path, sizeof(path), db, "", "", 0);
504
504
  strcpy(path+length, MY_DB_OPT_FILE);         // Append db option file name
574
574
      tbl_name_len= strlen(tbl->table_name) + 3;
575
575
      if (query_pos + tbl_name_len + 1 >= query_end)
576
576
      {
577
 
        /* These DDL methods and logging protected with LOCK_create_db */
 
577
        /* These DDL methods and logging protected with LOCK_drizzleclient_create_db */
578
578
        write_to_binlog(session, query, query_pos -1 - query, db, db_len);
579
579
        query_pos= query_data_start;
580
580
      }
587
587
 
588
588
    if (query_pos != query_data_start)
589
589
    {
590
 
      /* These DDL methods and logging protected with LOCK_create_db */
 
590
      /* These DDL methods and logging protected with LOCK_drizzleclient_create_db */
591
591
      write_to_binlog(session, query, query_pos -1 - query, db, db_len);
592
592
    }
593
593
  }
601
601
  */
602
602
  if (session->db && !strcmp(session->db, db))
603
603
    mysql_change_db_impl(session, NULL, session->variables.collation_server);
604
 
  pthread_mutex_unlock(&LOCK_create_db);
 
604
  pthread_mutex_unlock(&LOCK_drizzleclient_create_db);
605
605
  start_waiting_global_read_lock(session);
606
606
exit2:
607
607
  return(error);
651
651
        presumably this was to avoid deleting other user data... except if that
652
652
        data happened to be in files ending in .BAK, .opt or .TMD. *fun*
653
653
       */
 
654
      find_type(extension, ha_known_exts(),1+2);
654
655
      continue;
655
656
    }
656
657
    /* just for safety we use files_charset_info */