~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/statement/alter_table.cc

  • Committer: Brian Aker
  • Date: 2010-11-29 04:42:53 UTC
  • mto: (2017.3.1 catalogs)
  • mto: This revision was merged to the branch mainline in revision 1962.
  • Revision ID: brian@tangent.org-20101129044253-e46xw0y04xv7nx3a
Remove dead code in wait, pass session.

Show diffs side-by-side

added added

removed removed

Lines of Context:
107
107
  assert(select_lex->db);
108
108
 
109
109
  /* Chicken/Egg... we need to search for the table, to know if the table exists, so we can build a full identifier from it */
110
 
  message::TablePtr original_table_message;
 
110
  message::table::shared_ptr original_table_message;
111
111
  {
112
112
    TableIdentifier identifier(first_table->getSchemaName(), first_table->getTableName());
113
113
    if (plugin::StorageEngine::getTableDefinition(*session, identifier, original_table_message) != EEXIST)
114
114
    {
115
 
      my_error(ER_BAD_TABLE_ERROR, MYF(0), identifier.getSQLPath().c_str());
 
115
      std::string path;
 
116
      identifier.getSQLPath(path);
 
117
      my_error(ER_BAD_TABLE_ERROR, MYF(0), path.c_str());
116
118
      return true;
117
119
    }
118
120
 
123
125
 
124
126
      if (not create_info.db_type)
125
127
      {
126
 
        my_error(ER_BAD_TABLE_ERROR, MYF(0), identifier.getSQLPath().c_str());
 
128
        std::string path;
 
129
        identifier.getSQLPath(path);
 
130
        my_error(ER_BAD_TABLE_ERROR, MYF(0), path.c_str());
127
131
        return true;
128
132
      }
129
133
    }
416
420
      */
417
421
      if (alter_info->build_method == HA_BUILD_ONLINE)
418
422
      {
419
 
        my_error(ER_NOT_SUPPORTED_YET, MYF(0), session->query.c_str());
 
423
        my_error(ER_NOT_SUPPORTED_YET, MYF(0), session->getQueryString()->c_str());
420
424
        goto err;
421
425
      }
422
426
      alter_info->build_method= HA_BUILD_OFFLINE;
715
719
 
716
720
  /* The ALTER Table is always in its own transaction */
717
721
  error= transaction_services.autocommitOrRollback(session, false);
718
 
  if (! session->endActiveTransaction())
 
722
  if (not session->endActiveTransaction())
719
723
    error=1;
 
724
 
720
725
  if (error)
721
726
    goto err;
722
 
  write_bin_log(session, session->query.c_str());
 
727
 
 
728
  write_bin_log(session, *session->getQueryString());
723
729
 
724
730
err:
725
731
  (void) transaction_services.autocommitOrRollback(session, error);
792
798
 
793
799
      if (session.find_temporary_table(new_table_identifier))
794
800
      {
795
 
        my_error(ER_TABLE_EXISTS_ERROR, MYF(0), new_table_identifier.getSQLPath().c_str());
 
801
        std::string path;
 
802
        new_table_identifier.getSQLPath(path);
 
803
        my_error(ER_TABLE_EXISTS_ERROR, MYF(0), path.c_str());
796
804
        return false;
797
805
      }
798
806
    }
805
813
 
806
814
      if (not name_lock)
807
815
      {
808
 
        my_error(ER_TABLE_EXISTS_ERROR, MYF(0), new_table_identifier.getSQLPath().c_str());
 
816
        std::string path;
 
817
        new_table_identifier.getSQLPath(path);
 
818
        my_error(ER_TABLE_EXISTS_ERROR, MYF(0), path.c_str());
809
819
        return false;
810
820
      }
811
821
 
812
822
      if (plugin::StorageEngine::doesTableExist(session, new_table_identifier))
813
823
      {
 
824
        std::string path;
 
825
        new_table_identifier.getSQLPath(path);
 
826
 
814
827
        /* Table will be closed by Session::executeCommand() */
815
 
        my_error(ER_TABLE_EXISTS_ERROR, MYF(0), new_table_identifier.getSQLPath().c_str());
 
828
        my_error(ER_TABLE_EXISTS_ERROR, MYF(0), path.c_str());
816
829
 
817
 
        LOCK_open.lock(); /* ALTER TABLe */
 
830
        table::Cache::singleton().mutex().lock(); /* ALTER TABLe */
818
831
        session.unlink_open_table(name_lock);
819
 
        LOCK_open.unlock();
 
832
        table::Cache::singleton().mutex().unlock();
820
833
 
821
834
        return false;
822
835
      }
922
935
  if (original_engine->check_flag(HTON_BIT_ALTER_NOT_SUPPORTED) ||
923
936
      new_engine->check_flag(HTON_BIT_ALTER_NOT_SUPPORTED))
924
937
  {
925
 
    my_error(ER_ILLEGAL_HA, MYF(0), new_table_identifier.getSQLPath().c_str());
 
938
    std::string path;
 
939
    new_table_identifier.getSQLPath(path);
 
940
    my_error(ER_ILLEGAL_HA, MYF(0), path.c_str());
926
941
 
927
942
    return true;
928
943
  }
956
971
          while the fact that the table is still open gives us protection
957
972
          from concurrent DDL statements.
958
973
        */
959
 
        LOCK_open.lock(); /* DDL wait for/blocker */
 
974
        table::Cache::singleton().mutex().lock(); /* DDL wait for/blocker */
960
975
        wait_while_table_is_used(session, table, HA_EXTRA_FORCE_REOPEN);
961
 
        LOCK_open.unlock();
 
976
        table::Cache::singleton().mutex().unlock();
962
977
        error= table->cursor->ha_enable_indexes(HA_KEY_SWITCH_NONUNIQ_SAVE);
963
978
        /* COND_refresh will be signaled in close_thread_tables() */
964
979
        break;
965
980
      case DISABLE:
966
 
        LOCK_open.lock(); /* DDL wait for/blocker */
 
981
        table::Cache::singleton().mutex().lock(); /* DDL wait for/blocker */
967
982
        wait_while_table_is_used(session, table, HA_EXTRA_FORCE_REOPEN);
968
 
        LOCK_open.unlock();
 
983
        table::Cache::singleton().mutex().unlock();
969
984
        error=table->cursor->ha_disable_indexes(HA_KEY_SWITCH_NONUNIQ_SAVE);
970
985
        /* COND_refresh will be signaled in close_thread_tables() */
971
986
        break;
983
998
                            table->getAlias());
984
999
      }
985
1000
 
986
 
      LOCK_open.lock(); /* Lock to remove all instances of table from table cache before ALTER */
 
1001
      table::Cache::singleton().mutex().lock(); /* Lock to remove all instances of table from table cache before ALTER */
987
1002
      /*
988
1003
        Unlike to the above case close_cached_table() below will remove ALL
989
1004
        instances of Table from table cache (it will also remove table lock
990
1005
        held by this thread). So to make actual table renaming and writing
991
1006
        to binlog atomic we have to put them into the same critical section
992
 
        protected by LOCK_open mutex. This also removes gap for races between
 
1007
        protected by table::Cache::singleton().mutex() mutex. This also removes gap for races between
993
1008
        access() and mysql_rename_table() calls.
994
1009
      */
995
1010
 
1011
1026
        */
1012
1027
        if (plugin::StorageEngine::doesTableExist(*session, new_table_identifier))
1013
1028
        {
1014
 
          my_error(ER_TABLE_EXISTS_ERROR, MYF(0), new_table_identifier.getSQLPath().c_str());
 
1029
          std::string path;
 
1030
          new_table_identifier.getSQLPath(path);
 
1031
          my_error(ER_TABLE_EXISTS_ERROR, MYF(0), path.c_str());
1015
1032
          error= -1;
1016
1033
        }
1017
1034
        else
1033
1050
 
1034
1051
      if (error == 0)
1035
1052
      {
1036
 
        write_bin_log(session, session->query.c_str());
 
1053
        TransactionServices &transaction_services= TransactionServices::singleton();
 
1054
        transaction_services.allocateNewTransactionId();
 
1055
        write_bin_log(session, *session->getQueryString());
1037
1056
        session->my_ok();
1038
1057
      }
1039
1058
      else if (error > 0)
1042
1061
        error= -1;
1043
1062
      }
1044
1063
 
1045
 
      LOCK_open.unlock();
 
1064
      table::Cache::singleton().mutex().unlock();
1046
1065
      table_list->table= NULL;
1047
1066
 
1048
1067
      return error;
1087
1106
 
1088
1107
  if (not new_table)
1089
1108
  {
1090
 
    quick_rm_table(*session, new_table_as_temporary);
 
1109
    plugin::StorageEngine::dropTable(*session, new_table_as_temporary);
1091
1110
    return true;
1092
1111
  }
1093
1112
 
1165
1184
      }
1166
1185
      else
1167
1186
      {
1168
 
        quick_rm_table(*session, new_table_as_temporary);
 
1187
        plugin::StorageEngine::dropTable(*session, new_table_as_temporary);
1169
1188
      }
1170
1189
 
1171
1190
      return true;
1187
1206
        delete new_table;
1188
1207
      }
1189
1208
 
1190
 
      LOCK_open.lock(); /* ALTER TABLE */
 
1209
      table::Cache::singleton().mutex().lock(); /* ALTER TABLE */
1191
1210
 
1192
 
      quick_rm_table(*session, new_table_as_temporary);
1193
 
      LOCK_open.unlock();
 
1211
      plugin::StorageEngine::dropTable(*session, new_table_as_temporary);
 
1212
      table::Cache::singleton().mutex().unlock();
1194
1213
 
1195
1214
      return true;
1196
1215
    }
1237
1256
      delete new_table;
1238
1257
    }
1239
1258
 
1240
 
    LOCK_open.lock(); /* ALTER TABLE */
 
1259
    table::Cache::singleton().mutex().lock(); /* ALTER TABLE */
1241
1260
 
1242
1261
    /*
1243
1262
      Data is copied. Now we:
1282
1301
    if (mysql_rename_table(*session, original_engine, original_table_identifier, original_table_to_drop))
1283
1302
    {
1284
1303
      error= 1;
1285
 
      quick_rm_table(*session, new_table_as_temporary);
 
1304
      plugin::StorageEngine::dropTable(*session, new_table_as_temporary);
1286
1305
    }
1287
1306
    else
1288
1307
    {
1291
1310
        /* Try to get everything back. */
1292
1311
        error= 1;
1293
1312
 
1294
 
        quick_rm_table(*session, new_table_identifier);
 
1313
        plugin::StorageEngine::dropTable(*session, new_table_identifier);
1295
1314
 
1296
 
        quick_rm_table(*session, new_table_as_temporary);
 
1315
        plugin::StorageEngine::dropTable(*session, new_table_as_temporary);
1297
1316
 
1298
1317
        mysql_rename_table(*session, original_engine, original_table_to_drop, original_table_identifier);
1299
1318
      }
1300
1319
      else
1301
1320
      {
1302
 
        quick_rm_table(*session, original_table_to_drop);
 
1321
        plugin::StorageEngine::dropTable(*session, original_table_to_drop);
1303
1322
      }
1304
1323
    }
1305
1324
 
1311
1330
        from list of open tables list and table cache.
1312
1331
      */
1313
1332
      session->unlink_open_table(table);
1314
 
      LOCK_open.unlock();
 
1333
      table::Cache::singleton().mutex().unlock();
1315
1334
 
1316
1335
      return true;
1317
1336
    }
1318
1337
 
1319
 
    LOCK_open.unlock();
 
1338
    table::Cache::singleton().mutex().unlock();
1320
1339
 
1321
1340
    session->set_proc_info("end");
1322
1341
 
1323
 
    write_bin_log(session, session->query.c_str());
 
1342
    write_bin_log(session, *session->getQueryString());
1324
1343
    table_list->table= NULL;
1325
1344
  }
1326
1345
 
1399
1418
 
1400
1419
    if (name_lock)
1401
1420
    {
1402
 
      LOCK_open.lock(); /* ALTER TABLe */
 
1421
      table::Cache::singleton().mutex().lock(); /* ALTER TABLe */
1403
1422
      session->unlink_open_table(name_lock);
1404
 
      LOCK_open.unlock();
 
1423
      table::Cache::singleton().mutex().unlock();
1405
1424
    }
1406
1425
  }
1407
1426