~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/innobase/handler/ha_innodb.cc

  • Committer: Brian Aker
  • Date: 2011-02-12 06:56:00 UTC
  • mto: This revision was merged to the branch mainline in revision 2161.
  • Revision ID: brian@tangent.org-20110212065600-m6c68fybw51rflhj
Further strip out includes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
    in Windows?
39
39
*/
40
40
 
41
 
#include <config.h>
 
41
#include "config.h"
42
42
 
43
43
#include <limits.h>
44
44
#include <fcntl.h>
45
45
 
46
 
#include <drizzled/error.h>
47
 
#include <drizzled/errmsg_print.h>
48
 
#include <drizzled/charset_info.h>
49
 
#include <drizzled/internal/m_string.h>
50
 
#include <drizzled/internal/my_sys.h>
51
 
#include <drizzled/my_hash.h>
52
 
#include <drizzled/plugin.h>
53
 
#include <drizzled/show.h>
54
 
#include <drizzled/data_home.h>
55
 
#include <drizzled/error.h>
56
 
#include <drizzled/field.h>
57
 
#include <drizzled/charset.h>
58
 
#include <drizzled/session.h>
59
 
#include <drizzled/current_session.h>
60
 
#include <drizzled/table.h>
61
 
#include <drizzled/field/blob.h>
62
 
#include <drizzled/field/varstring.h>
63
 
#include <drizzled/plugin/xa_storage_engine.h>
64
 
#include <drizzled/plugin/daemon.h>
65
 
#include <drizzled/memory/multi_malloc.h>
66
 
#include <drizzled/pthread_globals.h>
67
 
#include <drizzled/named_savepoint.h>
 
46
#include "drizzled/error.h"
 
47
#include "drizzled/errmsg_print.h"
 
48
#include "drizzled/charset_info.h"
 
49
#include "drizzled/internal/m_string.h"
 
50
#include "drizzled/internal/my_sys.h"
 
51
#include "drizzled/my_hash.h"
 
52
#include "drizzled/plugin.h"
 
53
#include "drizzled/show.h"
 
54
#include "drizzled/data_home.h"
 
55
#include "drizzled/error.h"
 
56
#include "drizzled/field.h"
 
57
#include "drizzled/charset.h"
 
58
#include "drizzled/session.h"
 
59
#include "drizzled/current_session.h"
 
60
#include "drizzled/table.h"
 
61
#include "drizzled/field/blob.h"
 
62
#include "drizzled/field/varstring.h"
 
63
#include "drizzled/plugin/xa_storage_engine.h"
 
64
#include "drizzled/plugin/daemon.h"
 
65
#include "drizzled/memory/multi_malloc.h"
 
66
#include "drizzled/pthread_globals.h"
 
67
#include "drizzled/named_savepoint.h"
68
68
 
69
69
#include <drizzled/transaction_services.h>
70
 
#include <drizzled/message/statement_transform.h>
 
70
#include "drizzled/message/statement_transform.h"
71
71
 
72
72
#include <boost/algorithm/string.hpp>
73
73
#include <boost/program_options.hpp>
125
125
#include <sstream>
126
126
#include <string>
127
127
 
128
 
#include <plugin/innobase/handler/status_function.h>
129
 
#include <plugin/innobase/handler/replication_log.h>
 
128
#include "plugin/innobase/handler/status_function.h"
 
129
#include "plugin/innobase/handler/replication_log.h"
130
130
 
131
131
#include <google/protobuf/io/zero_copy_stream.h>
132
132
#include <google/protobuf/io/zero_copy_stream_impl.h>
523
523
{
524
524
  CachedDirectory::Entries entries= directory.getEntries();
525
525
 
526
 
  std::string search_string(schema_identifier.getSchemaName());
527
 
 
528
 
  boost::algorithm::to_lower(search_string);
529
 
 
530
 
  if (search_string.compare("data_dictionary") == 0)
531
 
  {
532
 
    set_of_identifiers.push_back(identifier::Table(schema_identifier.getSchemaName(), "SYS_REPLICATION_LOG"));
533
 
  }
534
 
 
535
526
  for (CachedDirectory::Entries::iterator entry_iter= entries.begin(); 
536
527
       entry_iter != entries.end(); ++entry_iter)
537
528
  {
574
565
  if (session.getMessageCache().doesTableMessageExist(identifier))
575
566
    return true;
576
567
 
577
 
  std::string search_string(identifier.getPath());
578
 
  boost::algorithm::to_lower(search_string);
579
 
 
580
 
  if (search_string.compare("data_dictionary/sys_replication_log") == 0)
581
 
    return true;
582
 
 
583
568
  if (access(proto_path.c_str(), F_OK))
584
569
  {
585
570
    return false;
599
584
  if (session.getMessageCache().getTableMessage(identifier, table_proto))
600
585
    return EEXIST;
601
586
 
602
 
  if (read_replication_log_table_message(identifier.getTableName().c_str(), &table_proto) == 0)
603
 
    return EEXIST;
604
 
 
605
587
  if (access(proto_path.c_str(), F_OK))
606
588
  {
607
589
    return errno;
890
872
/*==========*/
891
873
  const drizzled::Session *session)  /*!< in: thread handle (Session*) */
892
874
{
893
 
  return(session->getSqlCommand() == SQLCOM_SELECT);
 
875
  return(session_sql_command(session) == SQLCOM_SELECT);
894
876
}
895
877
 
896
878
/******************************************************************//**
961
943
 
962
944
  uint64_t trx_id= message.transaction_context().transaction_id();
963
945
  uint32_t seg_id= message.segment_id();
964
 
  uint64_t end_timestamp= message.transaction_context().end_timestamp();
965
 
  bool is_end_segment= message.end_segment();
966
 
  trx->log_commit_id= TRUE;
967
 
  ulint error= insert_replication_message(data, message.ByteSize(), trx, trx_id,
968
 
               end_timestamp, is_end_segment, seg_id);
 
946
  ulint error= insert_replication_message(data, message.ByteSize(), trx, trx_id, seg_id);
969
947
  (void)error;
970
948
 
971
949
  delete[] data;
1076
1054
    tell it also to MySQL so that MySQL knows to empty the
1077
1055
    cached binlog for this transaction */
1078
1056
 
1079
 
    session->markTransactionForRollback(TRUE);
 
1057
    mark_transaction_to_rollback(session, TRUE);
1080
1058
 
1081
1059
    return(HA_ERR_LOCK_DEADLOCK);
1082
1060
 
1085
1063
    latest SQL statement in a lock wait timeout. Previously, we
1086
1064
    rolled back the whole transaction. */
1087
1065
 
1088
 
    session->markTransactionForRollback((bool)row_rollback_on_timeout);
 
1066
    mark_transaction_to_rollback(session, (bool)row_rollback_on_timeout);
1089
1067
 
1090
1068
    return(HA_ERR_LOCK_WAIT_TIMEOUT);
1091
1069
 
1132
1110
    tell it also to MySQL so that MySQL knows to empty the
1133
1111
    cached binlog for this transaction */
1134
1112
 
1135
 
    session->markTransactionForRollback(TRUE);
 
1113
    mark_transaction_to_rollback(session, TRUE);
1136
1114
 
1137
1115
    return(HA_ERR_LOCK_TABLE_FULL);
1138
1116
 
1181
1159
          "Drizzle thread %"PRIu64", query id %"PRIu64", %s, %s, %s ",
1182
1160
          static_cast<uint64_t>(in_session->getSessionId()),
1183
1161
          static_cast<uint64_t>(in_session->getQueryId()),
1184
 
          getServerHostname().c_str(),
 
1162
          glob_hostname,
1185
1163
          user_identifier->address().c_str(),
1186
1164
          user_identifier->username().c_str()
1187
1165
  );
3249
3227
 
3250
3228
  user_session = NULL;
3251
3229
 
3252
 
  std::string search_string(identifier.getSchemaName());
3253
 
  boost::algorithm::to_lower(search_string);
 
3230
  if (!(share=get_share(identifier.getKeyPath().c_str()))) {
3254
3231
 
3255
 
  if (search_string.compare("data_dictionary") == 0)
3256
 
  {
3257
 
    std::string table_name(identifier.getTableName());
3258
 
    boost::algorithm::to_upper(table_name);
3259
 
    if (!(share=get_share(table_name.c_str())))
3260
 
    {
3261
 
      return 1;
3262
 
    }
3263
 
  }
3264
 
  else
3265
 
  {
3266
 
    if (!(share=get_share(identifier.getKeyPath().c_str())))
3267
 
    {
3268
 
      return(1);
3269
 
    }
 
3232
    return(1);
3270
3233
  }
3271
3234
 
3272
3235
  /* Create buffers for packing the fields of a record. Why
3293
3256
  }
3294
3257
 
3295
3258
  /* Get pointer to a table object in InnoDB dictionary cache */
3296
 
  if (search_string.compare("data_dictionary") == 0)
3297
 
  {
3298
 
    std::string table_name(identifier.getTableName());
3299
 
    boost::algorithm::to_upper(table_name);
3300
 
    ib_table = dict_table_get(table_name.c_str(), TRUE);
3301
 
  }
3302
 
  else
3303
 
  {
3304
 
    ib_table = dict_table_get(identifier.getKeyPath().c_str(), TRUE);
3305
 
  }
 
3259
  ib_table = dict_table_get(identifier.getKeyPath().c_str(), TRUE);
3306
3260
  
3307
3261
  if (NULL == ib_table) {
3308
3262
    errmsg_printf(error::ERROR, "Cannot find or open table %s from\n"
3328
3282
    return(HA_ERR_NO_SUCH_TABLE);
3329
3283
  }
3330
3284
 
3331
 
  if (ib_table->ibd_file_missing && ! session->doing_tablespace_operation()) {
 
3285
  if (ib_table->ibd_file_missing && !session_tablespace_op(session)) {
3332
3286
    errmsg_printf(error::ERROR, "MySQL is trying to open a table handle but "
3333
3287
        "the .ibd file for\ntable %s does not exist.\n"
3334
3288
        "Have you deleted the .ibd file from the "
4337
4291
    ut_error;
4338
4292
  }
4339
4293
 
4340
 
  sql_command = user_session->getSqlCommand();
 
4294
  sql_command = session_sql_command(user_session);
4341
4295
 
4342
4296
  if ((sql_command == SQLCOM_ALTER_TABLE
4343
4297
       || sql_command == SQLCOM_CREATE_INDEX
4784
4738
  if (error == DB_SUCCESS
4785
4739
      && getTable()->next_number_field
4786
4740
      && new_row == getTable()->getInsertRecord()
4787
 
      && user_session->getSqlCommand() == SQLCOM_INSERT
 
4741
      && session_sql_command(user_session) == SQLCOM_INSERT
4788
4742
      && (trx->duplicates & (TRX_DUP_IGNORE | TRX_DUP_REPLACE))
4789
4743
    == TRX_DUP_IGNORE)  {
4790
4744
 
6041
5995
  const char* stmt;
6042
5996
  size_t stmt_len;
6043
5997
 
6044
 
  std::string search_string(identifier.getSchemaName());
6045
 
  boost::algorithm::to_lower(search_string);
6046
 
 
6047
 
  if (search_string.compare("data_dictionary") == 0)
6048
 
  {
6049
 
    return HA_WRONG_CREATE_OPTION;
6050
 
  }
6051
 
 
6052
5998
  if (form.getShare()->sizeFields() > 1000) {
6053
5999
    /* The limit probably should be REC_MAX_N_FIELDS - 3 = 1020,
6054
6000
      but we play safe here */
6224
6170
    string generated_create_table;
6225
6171
    const char *query= stmt;
6226
6172
 
6227
 
    if (session.getSqlCommand() == SQLCOM_CREATE_TABLE)
 
6173
    if (session_sql_command(&session) == SQLCOM_CREATE_TABLE)
6228
6174
    {
6229
6175
      message::transformTableDefinitionToSql(create_proto,
6230
6176
                                             generated_create_table,
6299
6245
    does a table copy too. */
6300
6246
 
6301
6247
  if ((create_proto.options().has_auto_increment_value()
6302
 
       || session.getSqlCommand() == SQLCOM_ALTER_TABLE
6303
 
       || session.getSqlCommand() == SQLCOM_CREATE_INDEX)
 
6248
       || session_sql_command(&session) == SQLCOM_ALTER_TABLE
 
6249
       || session_sql_command(&session) == SQLCOM_CREATE_INDEX)
6304
6250
      && create_proto.options().auto_increment_value() != 0) {
6305
6251
 
6306
6252
    /* Query was one of :
6393
6339
 
6394
6340
  update_session(getTable()->in_use);
6395
6341
 
6396
 
  if (user_session->getSqlCommand() != SQLCOM_TRUNCATE) {
 
6342
  if (session_sql_command(user_session) != SQLCOM_TRUNCATE) {
6397
6343
  fallback:
6398
6344
    /* We only handle TRUNCATE TABLE t as a special case.
6399
6345
    DELETE FROM t will have to use ha_innobase::doDeleteRecord(),
6435
6381
 
6436
6382
  ut_a(identifier.getPath().length() < 1000);
6437
6383
 
6438
 
  std::string search_string(identifier.getSchemaName());
6439
 
  boost::algorithm::to_lower(search_string);
6440
 
 
6441
 
  if (search_string.compare("data_dictionary") == 0)
6442
 
  {
6443
 
    return HA_ERR_TABLE_READONLY;
6444
 
  }
6445
 
 
6446
6384
  /* Get the transaction associated with the current session, or create one
6447
6385
    if not yet created */
6448
6386
 
6460
6398
  /* Drop the table in InnoDB */
6461
6399
 
6462
6400
  error = row_drop_table_for_mysql(identifier.getKeyPath().c_str(), trx,
6463
 
                                   session.getSqlCommand()
 
6401
                                   session_sql_command(&session)
6464
6402
                                   == SQLCOM_DROP_DB);
6465
6403
 
6466
6404
  session.setXaId(trx->id);
6488
6426
    if (identifier.getType() == message::Table::TEMPORARY)
6489
6427
    {
6490
6428
      session.getMessageCache().removeTableMessage(identifier);
6491
 
      ulint sql_command = session.getSqlCommand();
 
6429
      ulint sql_command = session_sql_command(&session);
6492
6430
 
6493
6431
      // If this was the final removal to an alter table then we will need
6494
6432
      // to remove the .dfe that was left behind.
7131
7069
    n_rows can not be 0 unless the table is empty, set to 1
7132
7070
    instead. The original problem of bug#29507 is actually
7133
7071
    fixed in the server code. */
7134
 
    if (user_session->getSqlCommand() == SQLCOM_TRUNCATE) {
 
7072
    if (session_sql_command(user_session) == SQLCOM_TRUNCATE) {
7135
7073
 
7136
7074
      n_rows = 1;
7137
7075
 
8385
8323
  trx = check_trx_exists(session);
8386
8324
 
8387
8325
  assert(EQ_CURRENT_SESSION(session));
8388
 
  const uint32_t sql_command = session->getSqlCommand();
 
8326
  const uint32_t sql_command = session_sql_command(session);
8389
8327
 
8390
8328
  if (sql_command == SQLCOM_DROP_TABLE) {
8391
8329
 
8471
8409
 
8472
8410
    if ((lock_type >= TL_WRITE_CONCURRENT_INSERT
8473
8411
         && lock_type <= TL_WRITE)
8474
 
        && ! session->doing_tablespace_operation()
 
8412
        && !session_tablespace_op(session)
8475
8413
        && sql_command != SQLCOM_TRUNCATE
8476
8414
        && sql_command != SQLCOM_CREATE_TABLE) {
8477
8415
 
8787
8725
finds charset information and returns length of prefix_len characters in the
8788
8726
index field in bytes.
8789
8727
@return number of bytes occupied by the first n characters */
 
8728
UNIV_INTERN
 
8729
ulint
 
8730
innobase_get_at_most_n_mbchars(
 
8731
/*===========================*/
 
8732
  ulint charset_id, /*!< in: character set id */
 
8733
  ulint prefix_len, /*!< in: prefix length in bytes of the index
 
8734
        (this has to be divided by mbmaxlen to get the
 
8735
        number of CHARACTERS n in the prefix) */
 
8736
  ulint data_len,   /*!< in: length of the string in bytes */
 
8737
  const char* str); /*!< in: character string */
8790
8738
 
8791
8739
ulint
8792
8740
innobase_get_at_most_n_mbchars(
8870
8818
  trx->detailed_error[0]= '\0';
8871
8819
 
8872
8820
  /* Set the isolation level of the transaction. */
8873
 
  trx->isolation_level= innobase_map_isolation_level(session->getTxIsolation());
 
8821
  trx->isolation_level= innobase_map_isolation_level(session_tx_isolation(session));
8874
8822
}
8875
8823
 
8876
8824
void
8913
8861
    return(0);
8914
8862
  }
8915
8863
 
8916
 
  session->get_xid(reinterpret_cast<DrizzleXid*>(&trx->xid));
 
8864
  session->get_xid(reinterpret_cast<DRIZZLE_XID*>(&trx->xid));
8917
8865
 
8918
8866
  /* Release a possible FIFO ticket and search latch. Since we will
8919
8867
  reserve the kernel mutex, we have to release the search system latch