~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_table.cc

  • Committer: Monty
  • Date: 2008-10-02 05:41:33 UTC
  • mfrom: (398.1.10 codestyle)
  • Revision ID: mordred@scylla.inaugust.com-20081002054133-tyxv5bmqpazfaqqi
Merged up to 408 of stdint-includes-fix.

Show diffs side-by-side

added added

removed removed

Lines of Context:
162
162
  if (flags & FN_IS_TMP) // FN_FROM_IS_TMP | FN_TO_IS_TMP
163
163
    my_stpncpy(tbbuff, table_name, sizeof(tbbuff));
164
164
  else
165
 
    VOID(tablename_to_filename(table_name, tbbuff, sizeof(tbbuff)));
 
165
    tablename_to_filename(table_name, tbbuff, sizeof(tbbuff));
166
166
 
167
 
  VOID(tablename_to_filename(db, dbbuff, sizeof(dbbuff)));
 
167
  tablename_to_filename(db, dbbuff, sizeof(dbbuff));
168
168
 
169
169
  char *end = buff + bufflen;
170
170
  /* Don't add FN_ROOTDIR if mysql_data_home already includes it */
1788
1788
    goto err;
1789
1789
  }
1790
1790
 
1791
 
  VOID(pthread_mutex_lock(&LOCK_open));
 
1791
  pthread_mutex_lock(&LOCK_open);
1792
1792
  if (!internal_tmp_table && !(create_info->options & HA_LEX_CREATE_TMP_TABLE))
1793
1793
  {
1794
1794
    if (!access(path,F_OK))
1904
1904
    write_bin_log(thd, true, thd->query, thd->query_length);
1905
1905
  error= false;
1906
1906
unlock_and_end:
1907
 
  VOID(pthread_mutex_unlock(&LOCK_open));
 
1907
  pthread_mutex_unlock(&LOCK_open);
1908
1908
 
1909
1909
err:
1910
1910
  thd_proc_info(thd, "After create");
2146
2146
 
2147
2147
  safe_mutex_assert_owner(&LOCK_open);
2148
2148
 
2149
 
  VOID(table->file->extra(function));
 
2149
  table->file->extra(function);
2150
2150
  /* Mark all tables that are in use as 'old' */
2151
2151
  mysql_lock_abort(thd, table, true);   /* end threads waiting on lock */
2152
2152
 
2972
2972
    Also some engines (e.g. NDB cluster) require that LOCK_open should be held
2973
2973
    during the call to ha_create_table(). See bug #28614 for more info.
2974
2974
  */
2975
 
  VOID(pthread_mutex_lock(&LOCK_open));
 
2975
  pthread_mutex_lock(&LOCK_open);
2976
2976
  if (src_table->schema_table)
2977
2977
  {
2978
2978
    if (mysql_create_like_schema_frm(thd, src_table, dst_path, create_info))
2979
2979
    {
2980
 
      VOID(pthread_mutex_unlock(&LOCK_open));
 
2980
      pthread_mutex_unlock(&LOCK_open);
2981
2981
      goto err;
2982
2982
    }
2983
2983
  }
2987
2987
      my_error(ER_BAD_DB_ERROR,MYF(0),db);
2988
2988
    else
2989
2989
      my_error(ER_CANT_CREATE_FILE,MYF(0),dst_path,my_errno);
2990
 
    VOID(pthread_mutex_unlock(&LOCK_open));
 
2990
    pthread_mutex_unlock(&LOCK_open);
2991
2991
    goto err;
2992
2992
  }
2993
2993
 
3000
3000
  if (thd->variables.keep_files_on_create)
3001
3001
    create_info->options|= HA_CREATE_KEEP_FILES;
3002
3002
  err= ha_create_table(thd, dst_path, db, table_name, create_info, 1);
3003
 
  VOID(pthread_mutex_unlock(&LOCK_open));
 
3003
  pthread_mutex_unlock(&LOCK_open);
3004
3004
 
3005
3005
  if (create_info->options & HA_LEX_CREATE_TMP_TABLE)
3006
3006
  {
3055
3055
          of this function.
3056
3056
        */
3057
3057
        table->table= name_lock;
3058
 
        VOID(pthread_mutex_lock(&LOCK_open));
 
3058
        pthread_mutex_lock(&LOCK_open);
3059
3059
        if (reopen_name_locked_table(thd, table, false))
3060
3060
        {
3061
 
          VOID(pthread_mutex_unlock(&LOCK_open));
 
3061
          pthread_mutex_unlock(&LOCK_open);
3062
3062
          goto err;
3063
3063
        }
3064
 
        VOID(pthread_mutex_unlock(&LOCK_open));
 
3064
        pthread_mutex_unlock(&LOCK_open);
3065
3065
 
3066
3066
        int result= store_create_info(thd, table, &query,
3067
3067
                                               create_info);
3845
3845
    The final .frm file is already created as a temporary file
3846
3846
    and will be renamed to the original table name.
3847
3847
  */
3848
 
  VOID(pthread_mutex_lock(&LOCK_open));
 
3848
  pthread_mutex_lock(&LOCK_open);
3849
3849
  wait_while_table_is_used(thd, table, HA_EXTRA_FORCE_REOPEN);
3850
3850
  alter_table_manage_keys(table, table->file->indexes_are_disabled(),
3851
3851
                          keys_onoff);
3859
3859
                         table->s->table_name.str, FN_FROM_IS_TMP))
3860
3860
  {
3861
3861
    error= 1;
3862
 
    VOID(pthread_mutex_unlock(&LOCK_open));
 
3862
    pthread_mutex_unlock(&LOCK_open);
3863
3863
    goto err;
3864
3864
  }
3865
3865
  broadcast_refresh();
3866
 
  VOID(pthread_mutex_unlock(&LOCK_open));
 
3866
  pthread_mutex_unlock(&LOCK_open);
3867
3867
 
3868
3868
  /*
3869
3869
    The ALTER Table is always in its own transaction.
3879
3879
    goto err;
3880
3880
  if (online)
3881
3881
  {
3882
 
    VOID(pthread_mutex_lock(&LOCK_open));
 
3882
    pthread_mutex_lock(&LOCK_open);
3883
3883
    if (reopen_table(table))
3884
3884
    {
3885
3885
      error= -1;
3886
3886
      goto err;
3887
3887
    }
3888
 
    VOID(pthread_mutex_unlock(&LOCK_open));
 
3888
    pthread_mutex_unlock(&LOCK_open);
3889
3889
    t_table= table;
3890
3890
 
3891
3891
   /*
3904
3904
    */
3905
3905
    assert(t_table == table);
3906
3906
    table->open_placeholder= 1;
3907
 
    VOID(pthread_mutex_lock(&LOCK_open));
 
3907
    pthread_mutex_lock(&LOCK_open);
3908
3908
    close_handle_and_leave_table_as_lock(table);
3909
 
    VOID(pthread_mutex_unlock(&LOCK_open));
 
3909
    pthread_mutex_unlock(&LOCK_open);
3910
3910
  }
3911
3911
 
3912
3912
 err:
4526
4526
        while the fact that the table is still open gives us protection
4527
4527
        from concurrent DDL statements.
4528
4528
      */
4529
 
      VOID(pthread_mutex_lock(&LOCK_open));
 
4529
      pthread_mutex_lock(&LOCK_open);
4530
4530
      wait_while_table_is_used(thd, table, HA_EXTRA_FORCE_REOPEN);
4531
 
      VOID(pthread_mutex_unlock(&LOCK_open));
 
4531
      pthread_mutex_unlock(&LOCK_open);
4532
4532
      error= table->file->ha_enable_indexes(HA_KEY_SWITCH_NONUNIQ_SAVE);
4533
4533
      /* COND_refresh will be signaled in close_thread_tables() */
4534
4534
      break;
4535
4535
    case DISABLE:
4536
 
      VOID(pthread_mutex_lock(&LOCK_open));
 
4536
      pthread_mutex_lock(&LOCK_open);
4537
4537
      wait_while_table_is_used(thd, table, HA_EXTRA_FORCE_REOPEN);
4538
 
      VOID(pthread_mutex_unlock(&LOCK_open));
 
4538
      pthread_mutex_unlock(&LOCK_open);
4539
4539
      error=table->file->ha_disable_indexes(HA_KEY_SWITCH_NONUNIQ_SAVE);
4540
4540
      /* COND_refresh will be signaled in close_thread_tables() */
4541
4541
      break;
4552
4552
                          table->alias);
4553
4553
    }
4554
4554
 
4555
 
    VOID(pthread_mutex_lock(&LOCK_open));
 
4555
    pthread_mutex_lock(&LOCK_open);
4556
4556
    /*
4557
4557
      Unlike to the above case close_cached_table() below will remove ALL
4558
4558
      instances of Table from table cache (it will also remove table lock
4590
4590
          error= -1;
4591
4591
        else if (0)
4592
4592
      {
4593
 
          VOID(mysql_rename_table(old_db_type, new_db, new_alias, db,
4594
 
                                  table_name, 0));
 
4593
          mysql_rename_table(old_db_type, new_db, new_alias, db,
 
4594
                             table_name, 0);
4595
4595
          error= -1;
4596
4596
      }
4597
4597
    }
4617
4617
    }
4618
4618
    if (name_lock)
4619
4619
      unlink_open_table(thd, name_lock, false);
4620
 
    VOID(pthread_mutex_unlock(&LOCK_open));
 
4620
    pthread_mutex_unlock(&LOCK_open);
4621
4621
    table_list->table= NULL;                    // For query cache
4622
4622
    return(error);
4623
4623
  }
4832
4832
  }
4833
4833
  else
4834
4834
  {
4835
 
    VOID(pthread_mutex_lock(&LOCK_open));
 
4835
    pthread_mutex_lock(&LOCK_open);
4836
4836
    wait_while_table_is_used(thd, table, HA_EXTRA_FORCE_REOPEN);
4837
 
    VOID(pthread_mutex_unlock(&LOCK_open));
 
4837
    pthread_mutex_unlock(&LOCK_open);
4838
4838
    alter_table_manage_keys(table, table->file->indexes_are_disabled(),
4839
4839
                            alter_info->keys_onoff);
4840
4840
    error= ha_autocommit_or_rollback(thd, 0);
4874
4874
    intern_close_table(new_table);
4875
4875
    my_free(new_table,MYF(0));
4876
4876
  }
4877
 
  VOID(pthread_mutex_lock(&LOCK_open));
 
4877
  pthread_mutex_lock(&LOCK_open);
4878
4878
  if (error)
4879
4879
  {
4880
 
    VOID(quick_rm_table(new_db_type, new_db, tmp_name, FN_IS_TMP));
4881
 
    VOID(pthread_mutex_unlock(&LOCK_open));
 
4880
    quick_rm_table(new_db_type, new_db, tmp_name, FN_IS_TMP);
 
4881
    pthread_mutex_unlock(&LOCK_open);
4882
4882
    goto err;
4883
4883
  }
4884
4884
 
4927
4927
                         FN_TO_IS_TMP))
4928
4928
  {
4929
4929
    error=1;
4930
 
    VOID(quick_rm_table(new_db_type, new_db, tmp_name, FN_IS_TMP));
 
4930
    quick_rm_table(new_db_type, new_db, tmp_name, FN_IS_TMP);
4931
4931
  }
4932
4932
  else if (mysql_rename_table(new_db_type, new_db, tmp_name, new_db,
4933
4933
                              new_alias, FN_FROM_IS_TMP) || ((new_name != table_name || new_db != db) && 0))
4934
4934
  {
4935
4935
    /* Try to get everything back. */
4936
4936
    error=1;
4937
 
    VOID(quick_rm_table(new_db_type,new_db,new_alias, 0));
4938
 
    VOID(quick_rm_table(new_db_type, new_db, tmp_name, FN_IS_TMP));
4939
 
    VOID(mysql_rename_table(old_db_type, db, old_name, db, alias,
4940
 
                            FN_FROM_IS_TMP));
 
4937
    quick_rm_table(new_db_type,new_db,new_alias, 0);
 
4938
    quick_rm_table(new_db_type, new_db, tmp_name, FN_IS_TMP);
 
4939
    mysql_rename_table(old_db_type, db, old_name, db, alias,
 
4940
                       FN_FROM_IS_TMP);
4941
4941
  }
4942
4942
 
4943
4943
  if (error)
4946
4946
    goto err_with_placeholders;
4947
4947
  }
4948
4948
 
4949
 
  VOID(quick_rm_table(old_db_type, db, old_name, FN_IS_TMP));
 
4949
  quick_rm_table(old_db_type, db, old_name, FN_IS_TMP);
4950
4950
 
4951
4951
end_online:
4952
4952
  if (thd->locked_tables && new_name == table_name && new_db == db)
4957
4957
    if (error)
4958
4958
      goto err_with_placeholders;
4959
4959
  }
4960
 
  VOID(pthread_mutex_unlock(&LOCK_open));
 
4960
  pthread_mutex_unlock(&LOCK_open);
4961
4961
 
4962
4962
  thd_proc_info(thd, "end");
4963
4963
 
5022
5022
    close_temporary_table(thd, new_table, 1, 1);
5023
5023
  }
5024
5024
  else
5025
 
    VOID(quick_rm_table(new_db_type, new_db, tmp_name, FN_IS_TMP));
 
5025
    quick_rm_table(new_db_type, new_db, tmp_name, FN_IS_TMP);
5026
5026
 
5027
5027
err:
5028
5028
  /*
5073
5073
  unlink_open_table(thd, table, false);
5074
5074
  if (name_lock)
5075
5075
    unlink_open_table(thd, name_lock, false);
5076
 
  VOID(pthread_mutex_unlock(&LOCK_open));
 
5076
  pthread_mutex_unlock(&LOCK_open);
5077
5077
  return(true);
5078
5078
}
5079
5079
/* mysql_alter_table */