~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_table.cc

  • Committer: Brian Aker
  • Date: 2009-06-03 19:30:45 UTC
  • mfrom: (1046.1.6 merge)
  • Revision ID: brian@gaz-20090603193045-4xgeczyfixh07beg
MergeĀ forĀ Brian

Show diffs side-by-side

added added

removed removed

Lines of Context:
404
404
      built_query.append("DROP Table ");
405
405
  }
406
406
 
407
 
  pthread_mutex_lock(&LOCK_open);
 
407
  pthread_mutex_lock(&LOCK_open); /* Part 2 of rm a table */
408
408
 
409
409
  /*
410
410
    If we have the table in the definition cache, we don't have to check the
603
603
      */
604
604
    }
605
605
  }
606
 
  pthread_mutex_lock(&LOCK_open);
 
606
  pthread_mutex_lock(&LOCK_open); /* final bit in rm table lock */
607
607
err_with_placeholders:
608
608
  unlock_table_names(tables, NULL);
609
609
  pthread_mutex_unlock(&LOCK_open);
1737
1737
    goto err;
1738
1738
  }
1739
1739
 
1740
 
  pthread_mutex_lock(&LOCK_open);
 
1740
  pthread_mutex_lock(&LOCK_open); /* CREATE TABLE (some confussion on naming, double check) */
1741
1741
  if (!internal_tmp_table && !(create_info->options & HA_LEX_CREATE_TMP_TABLE))
1742
1742
  {
1743
1743
    if (table_proto_exists(path)==EEXIST)
1938
1938
unlock:
1939
1939
  if (name_lock)
1940
1940
  {
1941
 
    pthread_mutex_lock(&LOCK_open);
 
1941
    pthread_mutex_lock(&LOCK_open); /* Lock for removing name_lock during table create */
1942
1942
    unlink_open_table(session, name_lock, false);
1943
1943
    pthread_mutex_unlock(&LOCK_open);
1944
1944
  }
2116
2116
  if (session->lock)
2117
2117
  {
2118
2118
    mysql_unlock_tables(session, session->lock);
2119
 
    session->lock=0;                    // Start locked threads
 
2119
    session->lock= NULL;                        // Start locked threads
2120
2120
  }
2121
2121
  /* Close all copies of 'table'.  This also frees all LOCK TABLES lock */
2122
2122
  unlink_open_table(session, table, true);
2162
2162
    uint32_t key_length;
2163
2163
 
2164
2164
    key_length= create_table_def_key(key, table_list);
2165
 
    pthread_mutex_lock(&LOCK_open);
 
2165
    pthread_mutex_lock(&LOCK_open); /* Lock table for repair */
2166
2166
    if (!(share= (get_table_share(session, table_list, key, key_length, 0,
2167
2167
                                  &error))))
2168
2168
    {
2223
2223
  /* If we could open the table, close it */
2224
2224
  if (table_list->table)
2225
2225
  {
2226
 
    pthread_mutex_lock(&LOCK_open);
 
2226
    pthread_mutex_lock(&LOCK_open); /* Close for repair table */
2227
2227
    close_cached_table(session, table);
2228
2228
    pthread_mutex_unlock(&LOCK_open);
2229
2229
  }
2234
2234
  }
2235
2235
  if (my_rename(from, tmp, MYF(MY_WME)))
2236
2236
  {
2237
 
    pthread_mutex_lock(&LOCK_open);
 
2237
    pthread_mutex_lock(&LOCK_open); /* Lock during rename of table (aka we go to unlock ) */
2238
2238
    unlock_table_name(table_list);
2239
2239
    pthread_mutex_unlock(&LOCK_open);
2240
2240
    error= send_check_errmsg(session, table_list, "repair",
2243
2243
  }
2244
2244
  if (mysql_truncate(session, table_list, 1))
2245
2245
  {
2246
 
    pthread_mutex_lock(&LOCK_open);
 
2246
    pthread_mutex_lock(&LOCK_open); /* Lock during truncate of table during repair operation. */
2247
2247
    unlock_table_name(table_list);
2248
2248
    pthread_mutex_unlock(&LOCK_open);
2249
2249
    error= send_check_errmsg(session, table_list, "repair",
2252
2252
  }
2253
2253
  if (my_rename(tmp, from, MYF(MY_WME)))
2254
2254
  {
2255
 
    pthread_mutex_lock(&LOCK_open);
 
2255
    pthread_mutex_lock(&LOCK_open); /* Final repair of table for rename */
2256
2256
    unlock_table_name(table_list);
2257
2257
    pthread_mutex_unlock(&LOCK_open);
2258
2258
    error= send_check_errmsg(session, table_list, "repair",
2264
2264
    Now we should be able to open the partially repaired table
2265
2265
    to finish the repair in the handler later on.
2266
2266
  */
2267
 
  pthread_mutex_lock(&LOCK_open);
 
2267
  pthread_mutex_lock(&LOCK_open); /* Lock for opening partially repaired table */
2268
2268
  if (reopen_name_locked_table(session, table_list, true))
2269
2269
  {
2270
2270
    unlock_table_name(table_list);
2278
2278
end:
2279
2279
  if (table == &tmp_table)
2280
2280
  {
2281
 
    pthread_mutex_lock(&LOCK_open);
 
2281
    pthread_mutex_lock(&LOCK_open); /* Lock to close table after repair operation */
2282
2282
    table->closefrm(true);                              // Free allocated memory
2283
2283
    pthread_mutex_unlock(&LOCK_open);
2284
2284
  }
2425
2425
    /* Close all instances of the table to allow repair to rename files */
2426
2426
    if (lock_type == TL_WRITE && table->table->s->version)
2427
2427
    {
2428
 
      pthread_mutex_lock(&LOCK_open);
 
2428
      pthread_mutex_lock(&LOCK_open); /* Lock type is TL_WRITE and we lock to repair the table */
2429
2429
      const char *old_message=session->enter_cond(&COND_refresh, &LOCK_open,
2430
2430
                                              "Waiting to get writelock");
2431
2431
      mysql_lock_abort(session,table->table, true);
2892
2892
    Also some engines (e.g. NDB cluster) require that LOCK_open should be held
2893
2893
    during the call to ha_create_table(). See bug #28614 for more info.
2894
2894
  */
2895
 
  pthread_mutex_lock(&LOCK_open);
 
2895
  pthread_mutex_lock(&LOCK_open); /* We lock for CREATE TABLE LIKE to copy table definition */
2896
2896
  if (src_table->schema_table)
2897
2897
  {
2898
2898
    if (mysql_create_like_schema_frm(session, src_table, dst_path, create_info))
2979
2979
          of this function.
2980
2980
        */
2981
2981
        table->table= name_lock;
2982
 
        pthread_mutex_lock(&LOCK_open);
 
2982
        pthread_mutex_lock(&LOCK_open); /* Open new table we have just acquired */
2983
2983
        if (reopen_name_locked_table(session, table, false))
2984
2984
        {
2985
2985
          pthread_mutex_unlock(&LOCK_open);
2995
2995
      else                                      // Case 1
2996
2996
        write_bin_log(session, true, session->query, session->query_length);
2997
2997
    }
2998
 
    /*
2999
 
      Case 3 and 4 does nothing under RBR
3000
 
    */
3001
2998
  }
3002
2999
 
3003
3000
  res= false;
3019
3016
err:
3020
3017
  if (name_lock)
3021
3018
  {
3022
 
    pthread_mutex_lock(&LOCK_open);
 
3019
    pthread_mutex_lock(&LOCK_open); /* unlink open tables for create table like*/
3023
3020
    unlink_open_table(session, name_lock, false);
3024
3021
    pthread_mutex_unlock(&LOCK_open);
3025
3022
  }
3870
3867
        while the fact that the table is still open gives us protection
3871
3868
        from concurrent DDL statements.
3872
3869
      */
3873
 
      pthread_mutex_lock(&LOCK_open);
 
3870
      pthread_mutex_lock(&LOCK_open); /* DDL wait for/blocker */
3874
3871
      wait_while_table_is_used(session, table, HA_EXTRA_FORCE_REOPEN);
3875
3872
      pthread_mutex_unlock(&LOCK_open);
3876
3873
      error= table->file->ha_enable_indexes(HA_KEY_SWITCH_NONUNIQ_SAVE);
3877
3874
      /* COND_refresh will be signaled in close_thread_tables() */
3878
3875
      break;
3879
3876
    case DISABLE:
3880
 
      pthread_mutex_lock(&LOCK_open);
 
3877
      pthread_mutex_lock(&LOCK_open); /* DDL wait for/blocker */
3881
3878
      wait_while_table_is_used(session, table, HA_EXTRA_FORCE_REOPEN);
3882
3879
      pthread_mutex_unlock(&LOCK_open);
3883
3880
      error=table->file->ha_disable_indexes(HA_KEY_SWITCH_NONUNIQ_SAVE);
3896
3893
                          table->alias);
3897
3894
    }
3898
3895
 
3899
 
    pthread_mutex_lock(&LOCK_open);
 
3896
    pthread_mutex_lock(&LOCK_open); /* Lock to remove all instances of table from table cache before ALTER */
3900
3897
    /*
3901
3898
      Unlike to the above case close_cached_table() below will remove ALL
3902
3899
      instances of Table from table cache (it will also remove table lock
4074
4071
    intern_close_table(new_table);
4075
4072
    free(new_table);
4076
4073
  }
4077
 
  pthread_mutex_lock(&LOCK_open);
 
4074
  pthread_mutex_lock(&LOCK_open); /* ALTER TABLE */
4078
4075
  if (error)
4079
4076
  {
4080
4077
    quick_rm_table(new_db_type, new_db, tmp_name, true);
4193
4190
      from the list of open tables and table cache. If we are not under
4194
4191
      LOCK TABLES we can rely on close_thread_tables() doing this job.
4195
4192
    */
4196
 
    pthread_mutex_lock(&LOCK_open);
 
4193
    pthread_mutex_lock(&LOCK_open); /* LOCK for ALTER TABLE, but this locks for LOCK TABLES */
4197
4194
    unlink_open_table(session, table, false);
4198
4195
    unlink_open_table(session, name_lock, false);
4199
4196
    pthread_mutex_unlock(&LOCK_open);
4263
4260
  }
4264
4261
  if (name_lock)
4265
4262
  {
4266
 
    pthread_mutex_lock(&LOCK_open);
 
4263
    pthread_mutex_lock(&LOCK_open); /* ALTER TABLe */
4267
4264
    unlink_open_table(session, name_lock, false);
4268
4265
    pthread_mutex_unlock(&LOCK_open);
4269
4266
  }