~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

Merged trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
50
50
***********************************************************************/
51
51
 
52
52
/* TODO list for the InnoDB Cursor in 5.0:
53
 
  - Remove the flag trx->active_trans and look at trx->conc_state
54
53
  - fix savepoint functions to use savepoint storage area
55
54
  - Find out what kind of problems the OS X case-insensitivity causes to
56
55
    table and database names; should we 'normalize' the names like we do
220
219
#endif /* UNIV_LOG_ARCHIVE */
221
220
static my_bool  innobase_use_doublewrite                = TRUE;
222
221
static my_bool  innobase_use_checksums                  = TRUE;
223
 
static my_bool  innobase_locks_unsafe_for_binlog        = TRUE;
224
222
static my_bool  innobase_rollback_on_timeout            = FALSE;
225
223
static my_bool  innobase_create_status_file             = FALSE;
226
224
static my_bool  innobase_stats_on_metadata              = TRUE;
294
292
                                     drizzled::NamedSavepoint &savepoint);
295
293
  virtual int doReleaseSavepoint(Session* session,
296
294
                                     drizzled::NamedSavepoint &savepoint);
 
295
  virtual int doXaCommit(Session* session, bool all)
 
296
  {
 
297
    return doCommit(session, all); /* XA commit just does a SQL COMMIT */
 
298
  }
 
299
  virtual int doXaRollback(Session *session, bool all)
 
300
  {
 
301
    return doRollback(session, all); /* XA rollback just does a SQL ROLLBACK */
 
302
  }
297
303
  virtual int doCommit(Session* session, bool all);
298
304
  virtual int doRollback(Session* session, bool all);
299
305
 
301
307
  This function is used to prepare X/Open XA distributed transaction   */
302
308
  virtual
303
309
  int
304
 
  doPrepare(
 
310
  doXaPrepare(
305
311
  /*================*/
306
312
                        /* out: 0 or error number */
307
313
        Session*        session,        /* in: handle to the MySQL thread of the user
312
318
  This function is used to recover X/Open XA distributed transactions   */
313
319
  virtual
314
320
  int
315
 
  doRecover(
 
321
  doXaRecover(
316
322
  /*================*/
317
323
                                /* out: number of prepared transactions
318
324
                                stored in xid_list */
323
329
  which is in the prepared state */
324
330
  virtual
325
331
  int
326
 
  doCommitXid(
 
332
  doXaCommitXid(
327
333
  /*===================*/
328
334
                        /* out: 0 or error number */
329
335
        ::drizzled::XID*        xid);   /* in: X/Open XA transaction identification */
332
338
  which is in the prepared state */
333
339
  virtual
334
340
  int
335
 
  doRollbackXid(
 
341
  doXaRollbackXid(
336
342
  /*=====================*/
337
343
                        /* out: 0 or error number */
338
344
        ::drizzled::XID *xid);  /* in: X/Open XA transaction identification */
1918
1924
 
1919
1925
        row_rollback_on_timeout = (ibool) innobase_rollback_on_timeout;
1920
1926
 
1921
 
        srv_locks_unsafe_for_binlog = (ibool) innobase_locks_unsafe_for_binlog;
 
1927
        srv_locks_unsafe_for_binlog = (ibool) TRUE;
1922
1928
 
1923
1929
        srv_max_n_open_files = (ulint) innobase_open_files;
1924
1930
        srv_innodb_status = (ibool) innobase_create_status_file;
2109
2115
  if (options == START_TRANS_OPT_WITH_CONS_SNAPSHOT)
2110
2116
          trx_assign_read_view(trx);
2111
2117
 
2112
 
        /* Set the Drizzle flag to mark that there is an active transaction */
2113
 
        if (trx->active_trans == 0) {
2114
 
                trx->active_trans= 1;
2115
 
        }
2116
 
 
2117
2118
        return 0;
2118
2119
}
2119
2120
 
2142
2143
                trx_search_latch_release_if_reserved(trx);
2143
2144
        }
2144
2145
 
2145
 
        /* The flag trx->active_trans is set to 1 in
2146
 
 
2147
 
        1. ::external_lock()
2148
 
  2  InnobaseEngine::doStartStatement()
2149
 
        3. InnobaseEngine::setSavepoint()
2150
 
        4. InnobaseEngine::doStartTransaction()
2151
 
 
2152
 
        and it is only set to 0 in a commit or a rollback. If it is 0 we know
2153
 
        there cannot be resources to be freed and we could return immediately.
2154
 
        For the time being, we play safe and do the cleanup though there should
2155
 
        be nothing to clean up. */
2156
 
 
2157
 
        if (trx->active_trans == 0
2158
 
                && trx->conc_state != TRX_NOT_STARTED) {
2159
 
 
2160
 
                errmsg_printf(ERRMSG_LVL_ERROR, "trx->active_trans == 0, but"
2161
 
                        " trx->conc_state != TRX_NOT_STARTED");
2162
 
        }
2163
2146
        if (all
2164
2147
                || (!session_test_options(session, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))) {
2165
2148
 
2206
2189
                        pthread_mutex_unlock(&commit_cond_m);
2207
2190
                }
2208
2191
 
2209
 
                if (trx->active_trans == 2) {
 
2192
                if (trx->conc_state == TRX_PREPARED) {
2210
2193
 
2211
2194
                        pthread_mutex_unlock(&prepare_commit_mutex);
2212
2195
                }
2213
2196
 
2214
2197
                /* Now do a write + flush of logs. */
2215
2198
                trx_commit_complete_for_mysql(trx);
2216
 
                trx->active_trans = 0;
2217
2199
 
2218
2200
        } else {
2219
2201
                /* We just mark the SQL statement ended and do not do a
2280
2262
                || !session_test_options(session, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)) {
2281
2263
 
2282
2264
                error = trx_rollback_for_mysql(trx);
2283
 
                trx->active_trans = 0;
2284
2265
        } else {
2285
2266
                error = trx_rollback_last_sql_stat_for_mysql(trx);
2286
2267
        }
2341
2322
 
2342
2323
        innobase_release_stat_resources(trx);
2343
2324
 
2344
 
        /* TODO: use provided savepoint data area to store savepoint data */
2345
2325
        error= (int)trx_rollback_to_savepoint_for_mysql(trx, named_savepoint.getName().c_str(),
2346
2326
                                                        &mysql_binlog_cache_pos);
2347
2327
        return(convert_error_code_to_mysql(error, 0, NULL));
2365
2345
 
2366
2346
        trx = check_trx_exists(session);
2367
2347
 
2368
 
        /* TODO: use provided savepoint data area to store savepoint data */
2369
2348
        error = (int) trx_release_savepoint_for_mysql(trx, named_savepoint.getName().c_str());
2370
2349
 
2371
2350
        return(convert_error_code_to_mysql(error, 0, NULL));
2400
2379
        innobase_release_stat_resources(trx);
2401
2380
 
2402
2381
        /* cannot happen outside of transaction */
2403
 
        assert(trx->active_trans);
 
2382
        assert(trx->conc_state != TRX_NOT_STARTED);
2404
2383
 
2405
 
        /* TODO: use provided savepoint data area to store savepoint data */
2406
2384
        error = (int) trx_savepoint_for_mysql(trx, named_savepoint.getName().c_str(), (ib_int64_t)0);
2407
2385
 
2408
2386
        return(convert_error_code_to_mysql(error, 0, NULL));
2424
2402
 
2425
2403
        ut_a(trx);
2426
2404
 
2427
 
        if (trx->active_trans == 0
2428
 
                && trx->conc_state != TRX_NOT_STARTED) {
2429
 
 
2430
 
                errmsg_printf(ERRMSG_LVL_ERROR, "trx->active_trans == 0, but"
2431
 
                        " trx->conc_state != TRX_NOT_STARTED");
2432
 
        }
2433
 
 
2434
 
 
2435
 
        if (trx->conc_state != TRX_NOT_STARTED &&
2436
 
                global_system_variables.log_warnings) {
2437
 
                errmsg_printf(ERRMSG_LVL_WARN, 
2438
 
                        "MySQL is closing a connection that has an active "
2439
 
                        "InnoDB transaction.  %lu row modifications will "
2440
 
                        "roll back.",
2441
 
                        (ulong) trx->undo_no.low);
2442
 
        }
 
2405
  assert(session->killed != Session::NOT_KILLED ||
 
2406
         trx->conc_state == TRX_NOT_STARTED);
 
2407
 
 
2408
  /* Warn if rolling back some things... */
 
2409
        if (session->killed != Session::NOT_KILLED &&
 
2410
      trx->conc_state != TRX_NOT_STARTED &&
 
2411
      trx->undo_no.low > 0 &&
 
2412
      global_system_variables.log_warnings)
 
2413
  {
 
2414
      errmsg_printf(ERRMSG_LVL_WARN, 
 
2415
      "Drizzle is closing a connection during a KILL operation\n"
 
2416
      "that has an active InnoDB transaction.  %lu row modifications will "
 
2417
      "roll back.\n",
 
2418
      (ulong) trx->undo_no.low);
 
2419
  }
2443
2420
 
2444
2421
        innobase_rollback_trx(trx);
2445
2422
 
3847
3824
 
3848
3825
                        /* Altering to InnoDB format */
3849
3826
                        getTransactionalEngine()->commit(user_session, 1);
3850
 
                        /* Note that this transaction is still active. */
3851
 
                        prebuilt->trx->active_trans = 1;
3852
3827
                        /* We will need an IX lock on the destination table. */
3853
3828
                        prebuilt->sql_stat_start = TRUE;
3854
3829
                } else {
3863
3838
                        /* Commit the transaction.  This will release the table
3864
3839
                        locks, so they have to be acquired again. */
3865
3840
                        getTransactionalEngine()->commit(user_session, 1);
3866
 
                        /* Note that this transaction is still active. */
3867
 
                        prebuilt->trx->active_trans = 1;
3868
3841
                        /* Re-acquire the table lock on the source table. */
3869
3842
                        row_lock_table_for_mysql(prebuilt, src_table, mode);
3870
3843
                        /* We will need an IX lock on the destination table. */
7993
7966
 
7994
7967
        /* Set the isolation level of the transaction. */
7995
7968
  trx->isolation_level= innobase_map_isolation_level((enum_tx_isolation) session_tx_isolation(session));
7996
 
 
7997
 
  /* 
7998
 
   * Set the Drizzle flag to mark that there is an active
7999
 
   * transaction.
8000
 
   *
8001
 
   * @todo this should go away
8002
 
   */
8003
 
  if (trx->active_trans == 0) {
8004
 
    trx->active_trans= 1;
8005
 
  }
8006
7969
}
8007
7970
 
8008
7971
void
8019
7982
 
8020
7983
  if (! session_test_options(session, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))
8021
7984
  {
8022
 
    if (trx->active_trans != 0)
 
7985
    if (trx->conc_state != TRX_NOT_STARTED)
8023
7986
    {
8024
7987
      commit(session, TRUE);
8025
 
      trx->active_trans= 0;
8026
7988
    }
8027
7989
  }
8028
7990
  else
8041
8003
This function is used to prepare an X/Open XA distributed transaction.
8042
8004
@return 0 or error number */
8043
8005
int
8044
 
InnobaseEngine::doPrepare(
 
8006
InnobaseEngine::doXaPrepare(
8045
8007
/*================*/
8046
8008
        Session*        session,/*!< in: handle to the MySQL thread of
8047
8009
                                the user whose XA transaction should
8071
8033
 
8072
8034
        innobase_release_stat_resources(trx);
8073
8035
 
8074
 
        if (trx->active_trans == 0 && trx->conc_state != TRX_NOT_STARTED) {
8075
 
 
8076
 
          errmsg_printf(ERRMSG_LVL_ERROR,
8077
 
                        "trx->active_trans == 0, but trx->conc_state != "
8078
 
                        "TRX_NOT_STARTED");
8079
 
        }
8080
 
 
8081
8036
        if (all
8082
8037
                || (!session_test_options(session, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))) {
8083
8038
 
8084
8039
                /* We were instructed to prepare the whole transaction, or
8085
8040
                this is an SQL statement end and autocommit is on */
8086
8041
 
8087
 
                ut_ad(trx->active_trans);
 
8042
                ut_ad(trx->conc_state != TRX_NOT_STARTED);
8088
8043
 
8089
8044
                error = (int) trx_prepare_for_mysql(trx);
8090
8045
        } else {
8131
8086
                to block for undefined period of time.
8132
8087
                */
8133
8088
                pthread_mutex_lock(&prepare_commit_mutex);
8134
 
                trx->active_trans = 2;
 
8089
                trx->conc_state = TRX_PREPARED;
8135
8090
        }
8136
8091
        return(error);
8137
8092
}
8140
8095
This function is used to recover X/Open XA distributed transactions.
8141
8096
@return number of prepared transactions stored in xid_list */
8142
8097
int
8143
 
InnobaseEngine::doRecover(
 
8098
InnobaseEngine::doXaRecover(
8144
8099
/*================*/
8145
8100
        ::drizzled::XID*        xid_list,/*!< in/out: prepared transactions */
8146
8101
        size_t len)     /*!< in: number of slots in xid_list */
8160
8115
which is in the prepared state
8161
8116
@return 0 or error number */
8162
8117
int
8163
 
InnobaseEngine::doCommitXid(
 
8118
InnobaseEngine::doXaCommitXid(
8164
8119
/*===================*/
8165
8120
        ::drizzled::XID*        xid)    /*!< in: X/Open XA transaction identification */
8166
8121
{
8184
8139
which is in the prepared state
8185
8140
@return 0 or error number */
8186
8141
int
8187
 
InnobaseEngine::doRollbackXid(
 
8142
InnobaseEngine::doXaRollbackXid(
8188
8143
/*=====================*/
8189
8144
        ::drizzled::XID*                xid)    /*!< in: X/Open XA transaction
8190
8145
                                identification */
8628
8583
  PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
8629
8584
  "With which method to flush data.", NULL, NULL, NULL);
8630
8585
 
8631
 
static DRIZZLE_SYSVAR_BOOL(locks_unsafe_for_binlog, innobase_locks_unsafe_for_binlog,
8632
 
  PLUGIN_VAR_NOCMDARG | PLUGIN_VAR_READONLY,
8633
 
  "Force InnoDB to not use next-key locking, to use only row-level locking.",
8634
 
  NULL, NULL, TRUE);
8635
 
 
8636
8586
#ifdef UNIV_LOG_ARCHIVE
8637
8587
static DRIZZLE_SYSVAR_STR(log_arch_dir, innobase_log_arch_dir,
8638
8588
  PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
8843
8793
  DRIZZLE_SYSVAR(flush_log_at_trx_commit),
8844
8794
  DRIZZLE_SYSVAR(flush_method),
8845
8795
  DRIZZLE_SYSVAR(force_recovery),
8846
 
  DRIZZLE_SYSVAR(locks_unsafe_for_binlog),
8847
8796
  DRIZZLE_SYSVAR(lock_wait_timeout),
8848
8797
#ifdef UNIV_LOG_ARCHIVE
8849
8798
  DRIZZLE_SYSVAR(log_arch_dir),