~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/db.cc

  • Committer: Brian Aker
  • Date: 2008-11-13 02:56:15 UTC
  • mfrom: (575.4.10 devel)
  • Revision ID: brian@tangent.org-20081113025615-snhsi52yb2ivmx6f
Merging Monty's code.

Show diffs side-by-side

added added

removed removed

Lines of Context:
535
535
  uint32_t path_len;
536
536
 
537
537
  /* do not create 'information_schema' db */
538
 
  if (!my_strcasecmp(system_charset_info, db, INFORMATION_SCHEMA_NAME.str))
 
538
  if (!my_strcasecmp(system_charset_info, db, INFORMATION_SCHEMA_NAME.c_str()))
539
539
  {
540
540
    my_error(ER_DB_CREATE_EXISTS, MYF(0), db);
541
541
    return(-1);
543
543
 
544
544
  /*
545
545
    Do not create database if another thread is holding read lock.
546
 
    Wait for global read lock before acquiring LOCK_mysql_create_db.
 
546
    Wait for global read lock before acquiring LOCK_drizzle_create_db.
547
547
    After wait_if_global_read_lock() we have protection against another
548
 
    global read lock. If we would acquire LOCK_mysql_create_db first,
 
548
    global read lock. If we would acquire LOCK_drizzle_create_db first,
549
549
    another thread could step in and get the global read lock before we
550
550
    reach wait_if_global_read_lock(). If this thread tries the same as we
551
 
    (admin a db), it would then go and wait on LOCK_mysql_create_db...
 
551
    (admin a db), it would then go and wait on LOCK_drizzle_create_db...
552
552
    Furthermore wait_if_global_read_lock() checks if the current thread
553
553
    has the global read lock and refuses the operation with
554
554
    ER_CANT_UPDATE_WITH_READLOCK if applicable.
559
559
    goto exit2;
560
560
  }
561
561
 
562
 
  pthread_mutex_lock(&LOCK_mysql_create_db);
 
562
  pthread_mutex_lock(&LOCK_drizzle_create_db);
563
563
 
564
564
  /* Check directory */
565
565
  path_len= build_table_filename(path, sizeof(path), db, "", "", 0);
658
658
      qinfo.db     = db;
659
659
      qinfo.db_len = strlen(db);
660
660
 
661
 
      /* These DDL methods and logging protected with LOCK_mysql_create_db */
 
661
      /* These DDL methods and logging protected with LOCK_drizzle_create_db */
662
662
      mysql_bin_log.write(&qinfo);
663
663
    }
664
664
    my_ok(session, result);
665
665
  }
666
666
 
667
667
exit:
668
 
  pthread_mutex_unlock(&LOCK_mysql_create_db);
 
668
  pthread_mutex_unlock(&LOCK_drizzle_create_db);
669
669
  start_waiting_global_read_lock(session);
670
670
exit2:
671
671
  return(error);
682
682
 
683
683
  /*
684
684
    Do not alter database if another thread is holding read lock.
685
 
    Wait for global read lock before acquiring LOCK_mysql_create_db.
 
685
    Wait for global read lock before acquiring LOCK_drizzle_create_db.
686
686
    After wait_if_global_read_lock() we have protection against another
687
 
    global read lock. If we would acquire LOCK_mysql_create_db first,
 
687
    global read lock. If we would acquire LOCK_drizzle_create_db first,
688
688
    another thread could step in and get the global read lock before we
689
689
    reach wait_if_global_read_lock(). If this thread tries the same as we
690
 
    (admin a db), it would then go and wait on LOCK_mysql_create_db...
 
690
    (admin a db), it would then go and wait on LOCK_drizzle_create_db...
691
691
    Furthermore wait_if_global_read_lock() checks if the current thread
692
692
    has the global read lock and refuses the operation with
693
693
    ER_CANT_UPDATE_WITH_READLOCK if applicable.
695
695
  if ((error=wait_if_global_read_lock(session,0,1)))
696
696
    goto exit2;
697
697
 
698
 
  pthread_mutex_lock(&LOCK_mysql_create_db);
 
698
  pthread_mutex_lock(&LOCK_drizzle_create_db);
699
699
 
700
700
  /* 
701
701
     Recreate db options file: /dbpath/.db.opt
730
730
    qinfo.db_len = strlen(db);
731
731
 
732
732
    session->clear_error();
733
 
    /* These DDL methods and logging protected with LOCK_mysql_create_db */
 
733
    /* These DDL methods and logging protected with LOCK_drizzle_create_db */
734
734
    mysql_bin_log.write(&qinfo);
735
735
  }
736
736
  my_ok(session, result);
737
737
 
738
738
exit:
739
 
  pthread_mutex_unlock(&LOCK_mysql_create_db);
 
739
  pthread_mutex_unlock(&LOCK_drizzle_create_db);
740
740
  start_waiting_global_read_lock(session);
741
741
exit2:
742
742
  return(error);
771
771
 
772
772
  if (db && (strcmp(db, "information_schema") == 0))
773
773
  {
774
 
    my_error(ER_DBACCESS_DENIED_ERROR, MYF(0), "", "", INFORMATION_SCHEMA_NAME.str);
 
774
    my_error(ER_DBACCESS_DENIED_ERROR, MYF(0), "", "", INFORMATION_SCHEMA_NAME.c_str());
775
775
    return(true);
776
776
  }
777
777
 
778
778
  /*
779
779
    Do not drop database if another thread is holding read lock.
780
 
    Wait for global read lock before acquiring LOCK_mysql_create_db.
 
780
    Wait for global read lock before acquiring LOCK_drizzle_create_db.
781
781
    After wait_if_global_read_lock() we have protection against another
782
 
    global read lock. If we would acquire LOCK_mysql_create_db first,
 
782
    global read lock. If we would acquire LOCK_drizzle_create_db first,
783
783
    another thread could step in and get the global read lock before we
784
784
    reach wait_if_global_read_lock(). If this thread tries the same as we
785
 
    (admin a db), it would then go and wait on LOCK_mysql_create_db...
 
785
    (admin a db), it would then go and wait on LOCK_drizzle_create_db...
786
786
    Furthermore wait_if_global_read_lock() checks if the current thread
787
787
    has the global read lock and refuses the operation with
788
788
    ER_CANT_UPDATE_WITH_READLOCK if applicable.
793
793
    goto exit2;
794
794
  }
795
795
 
796
 
  pthread_mutex_lock(&LOCK_mysql_create_db);
 
796
  pthread_mutex_lock(&LOCK_drizzle_create_db);
797
797
 
798
798
  /*
799
799
    This statement will be replicated as a statement, even when using
864
864
      qinfo.db_len = strlen(db);
865
865
 
866
866
      session->clear_error();
867
 
      /* These DDL methods and logging protected with LOCK_mysql_create_db */
 
867
      /* These DDL methods and logging protected with LOCK_drizzle_create_db */
868
868
      mysql_bin_log.write(&qinfo);
869
869
    }
870
870
    session->clear_error();
892
892
      tbl_name_len= strlen(tbl->table_name) + 3;
893
893
      if (query_pos + tbl_name_len + 1 >= query_end)
894
894
      {
895
 
        /* These DDL methods and logging protected with LOCK_mysql_create_db */
 
895
        /* These DDL methods and logging protected with LOCK_drizzle_create_db */
896
896
        write_to_binlog(session, query, query_pos -1 - query, db, db_len);
897
897
        query_pos= query_data_start;
898
898
      }
905
905
 
906
906
    if (query_pos != query_data_start)
907
907
    {
908
 
      /* These DDL methods and logging protected with LOCK_mysql_create_db */
 
908
      /* These DDL methods and logging protected with LOCK_drizzle_create_db */
909
909
      write_to_binlog(session, query, query_pos -1 - query, db, db_len);
910
910
    }
911
911
  }
919
919
  */
920
920
  if (session->db && !strcmp(session->db, db))
921
921
    mysql_change_db_impl(session, NULL, session->variables.collation_server);
922
 
  pthread_mutex_unlock(&LOCK_mysql_create_db);
 
922
  pthread_mutex_unlock(&LOCK_drizzle_create_db);
923
923
  start_waiting_global_read_lock(session);
924
924
exit2:
925
925
  return(error);
1107
1107
 
1108
1108
    session->set_db(NULL, 0);
1109
1109
  }
1110
 
  else if (new_db_name == &INFORMATION_SCHEMA_NAME)
 
1110
  else if (my_strcasecmp(system_charset_info, new_db_name->str,
 
1111
                         INFORMATION_SCHEMA_NAME.c_str()) == 0)
1111
1112
  {
1112
1113
    /*
1113
1114
      Here we must use Session::set_db(), because we want to copy
1114
1115
      INFORMATION_SCHEMA_NAME constant.
1115
1116
    */
1116
1117
 
1117
 
    session->set_db(INFORMATION_SCHEMA_NAME.str, INFORMATION_SCHEMA_NAME.length);
 
1118
    session->set_db(INFORMATION_SCHEMA_NAME.c_str(),
 
1119
                    INFORMATION_SCHEMA_NAME.length());
1118
1120
  }
1119
1121
  else
1120
1122
  {
1290
1292
  }
1291
1293
 
1292
1294
  if (my_strcasecmp(system_charset_info, new_db_name->str,
1293
 
                    INFORMATION_SCHEMA_NAME.str) == 0)
 
1295
                    INFORMATION_SCHEMA_NAME.c_str()) == 0)
1294
1296
  {
1295
1297
    /* Switch the current database to INFORMATION_SCHEMA. */
1296
 
 
1297
 
    mysql_change_db_impl(session, &INFORMATION_SCHEMA_NAME, system_charset_info);
 
1298
    /* const_cast<> is safe here: mysql_change_db_impl does a copy */
 
1299
    LEX_STRING is_name= { const_cast<char *>(INFORMATION_SCHEMA_NAME.c_str()),
 
1300
                          INFORMATION_SCHEMA_NAME.length() };
 
1301
    mysql_change_db_impl(session, &is_name, system_charset_info);
1298
1302
 
1299
1303
    return(false);
1300
1304
  }