~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/innobase/include/trx0trx.h

  • Committer: Monty Taylor
  • Date: 2011-02-13 17:26:39 UTC
  • mfrom: (2157.2.2 give-in-to-pkg-config)
  • mto: This revision was merged to the branch mainline in revision 2166.
  • Revision ID: mordred@inaugust.com-20110213172639-nhy7i72sfhoq13ms
Merged in pkg-config fixes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*****************************************************************************
2
2
 
3
 
Copyright (c) 1996, 2009, Innobase Oy. All Rights Reserved.
 
3
Copyright (C) 1996, 2010, Innobase Oy. All Rights Reserved.
4
4
 
5
5
This program is free software; you can redistribute it and/or modify it under
6
6
the terms of the GNU General Public License as published by the Free Software
11
11
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12
12
 
13
13
You should have received a copy of the GNU General Public License along with
14
 
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
15
 
Place, Suite 330, Boston, MA 02111-1307 USA
 
14
this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
 
15
St, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
*****************************************************************************/
18
18
 
38
38
#include "trx0xa.h"
39
39
#include "ut0vec.h"
40
40
 
 
41
namespace drizzled { class Session; }
 
42
 
41
43
/** Dummy session used currently in MySQL interface */
42
44
extern sess_t*  trx_dummy_sess;
43
45
 
70
72
        trx_t*  trx,    /*!< in: transaction struct */
71
73
        FILE*   file);  /*!< in: file to read message from */
72
74
/****************************************************************//**
 
75
Checks if the commit id should be logged to the sys header file
 
76
@return TRUE if the commit id should be logged */ 
 
77
UNIV_INLINE
 
78
ibool
 
79
trx_log_commit_id(
 
80
/*==============*/
 
81
        const trx_t*    trx);   /*!< in: trx object */
 
82
/****************************************************************//**
73
83
Retrieves the error_info field from a trx.
74
84
@return the error info */
75
85
UNIV_INLINE
179
189
/****************************************************************//**
180
190
Cleans up a transaction at database startup. The cleanup is needed if
181
191
the transaction already got to the middle of a commit when the database
182
 
crashed, andf we cannot roll it back. */
 
192
crashed, and we cannot roll it back. */
183
193
UNIV_INTERN
184
194
void
185
195
trx_cleanup_at_db_startup(
338
348
 
339
349
/**********************************************************************//**
340
350
Prints info about a transaction to the given file. The caller must own the
341
 
kernel mutex and must have called
342
 
innobase_mysql_prepare_print_arbitrary_thd(), unless he knows that MySQL
343
 
or InnoDB cannot meanwhile change the info printed here. */
 
351
kernel mutex. */
344
352
UNIV_INTERN
345
353
void
346
354
trx_print(
351
359
                                   use the default max length */
352
360
 
353
361
/** Type of data dictionary operation */
354
 
enum trx_dict_op {
 
362
typedef enum trx_dict_op {
355
363
        /** The transaction is not modifying the data dictionary. */
356
364
        TRX_DICT_OP_NONE = 0,
357
365
        /** The transaction is creating a table or an index, or
363
371
        existing table.  In crash recovery, the the data dictionary
364
372
        must be locked, but the table must not be dropped. */
365
373
        TRX_DICT_OP_INDEX = 2
366
 
};
 
374
} trx_dict_op_t;
367
375
 
368
376
/**********************************************************************//**
369
377
Determine if a transaction is a dictionary operation.
393
401
trx_is_interrupted(
394
402
/*===============*/
395
403
        trx_t*  trx);   /*!< in: transaction */
 
404
/**********************************************************************//**
 
405
Determines if the currently running transaction is in strict mode.
 
406
@return TRUE if strict */
 
407
UNIV_INTERN
 
408
ibool
 
409
trx_is_strict(
 
410
/*==========*/
 
411
        trx_t*  trx);   /*!< in: transaction */
396
412
#else /* !UNIV_HOTBACKUP */
397
413
#define trx_is_interrupted(trx) FALSE
398
414
#endif /* !UNIV_HOTBACKUP */
402
418
is estimated as the number of altered rows + the number of locked rows.
403
419
@param t        transaction
404
420
@return         transaction weight */
405
 
#define TRX_WEIGHT(t)   \
406
 
        ut_dulint_add((t)->undo_no, UT_LIST_GET_LEN((t)->trx_locks))
 
421
#define TRX_WEIGHT(t)   ((t)->undo_no + UT_LIST_GET_LEN((t)->trx_locks))
407
422
 
408
423
/*******************************************************************//**
409
424
Compares the "weight" (or size) of two transactions. Transactions that
410
425
have edited non-transactional tables are considered heavier than ones
411
426
that have not.
412
 
@return <0, 0 or >0; similar to strcmp(3) */
 
427
@return TRUE if weight(a) >= weight(b) */
413
428
UNIV_INTERN
414
 
int
415
 
trx_weight_cmp(
416
 
/*===========*/
 
429
ibool
 
430
trx_weight_ge(
 
431
/*==========*/
417
432
        const trx_t*    a,      /*!< in: the first transaction to be compared */
418
433
        const trx_t*    b);     /*!< in: the second transaction to be compared */
419
434
 
420
 
/*******************************************************************//**
421
 
Retrieves transacion's id, represented as unsigned long long.
422
 
@return transaction's id */
423
 
UNIV_INLINE
424
 
ullint
425
 
trx_get_id(
426
 
/*=======*/
427
 
        const trx_t*    trx);   /*!< in: transaction */
428
 
 
429
435
/* Maximum length of a string that can be returned by
430
436
trx_get_que_state_str(). */
431
437
#define TRX_QUE_STATE_STR_MAX_LEN       12 /* "ROLLING BACK" */
465
471
 
466
472
struct trx_struct{
467
473
        ulint           magic_n;
468
 
        /* All the next fields are protected by the kernel mutex, except the
469
 
        undo logs which are protected by undo_mutex */
 
474
 
 
475
        /* These fields are not protected by any mutex. */
470
476
        const char*     op_info;        /*!< English text describing the
471
477
                                        current operation, or an empty
472
478
                                        string */
473
 
        unsigned        is_purge:1;     /*!< 0=user transaction, 1=purge */
474
 
        unsigned        is_recovered:1; /*!< 0=normal transaction,
475
 
                                        1=recovered, must be rolled back */
476
 
        unsigned        conc_state:2;   /*!< state of the trx from the point
 
479
        ulint           conc_state;     /*!< state of the trx from the point
477
480
                                        of view of concurrency control:
478
481
                                        TRX_ACTIVE, TRX_COMMITTED_IN_MEMORY,
479
482
                                        ... */
480
 
        unsigned        que_state:2;    /*!< valid when conc_state == TRX_ACTIVE:
481
 
                                        TRX_QUE_RUNNING, TRX_QUE_LOCK_WAIT,
482
 
                                        ... */
483
 
        unsigned        isolation_level:2;/* TRX_ISO_REPEATABLE_READ, ... */
484
 
        unsigned        check_foreigns:1;/* normally TRUE, but if the user
 
483
        ulint           isolation_level;/* TRX_ISO_REPEATABLE_READ, ... */
 
484
        ulint           check_foreigns; /* normally TRUE, but if the user
485
485
                                        wants to suppress foreign key checks,
486
486
                                        (in table imports, for example) we
487
487
                                        set this FALSE */
488
 
        unsigned        check_unique_secondary:1;
 
488
        unsigned        check_unique_secondary;
489
489
                                        /* normally TRUE, but if the user
490
490
                                        wants to speed up inserts by
491
491
                                        suppressing unique key checks
492
492
                                        for secondary indexes when we decide
493
493
                                        if we can use the insert buffer for
494
494
                                        them, we set this FALSE */
495
 
        unsigned        support_xa:1;   /*!< normally we do the XA two-phase
 
495
        unsigned        support_xa;     /*!< normally we do the XA two-phase
496
496
                                        commit steps, but by setting this to
497
497
                                        FALSE, one can save CPU time and about
498
498
                                        150 bytes in the undo log size as then
499
499
                                        we skip XA steps */
500
 
        unsigned        flush_log_later:1;/* In 2PC, we hold the
 
500
        unsigned        flush_log_later;/* In 2PC, we hold the
501
501
                                        prepare_commit mutex across
502
502
                                        both phases. In that case, we
503
503
                                        defer flush of the logs to disk
504
504
                                        until after we release the
505
505
                                        mutex. */
506
 
        unsigned        must_flush_log_later:1;/* this flag is set to TRUE in
 
506
        unsigned        must_flush_log_later;/* this flag is set to TRUE in
507
507
                                        trx_commit_off_kernel() if
508
508
                                        flush_log_later was TRUE, and there
509
509
                                        were modifications by the transaction;
510
510
                                        in that case we must flush the log
511
511
                                        in trx_commit_complete_for_mysql() */
512
 
        unsigned        dict_operation:2;/**< @see enum trx_dict_op */
513
 
        unsigned        duplicates:2;   /*!< TRX_DUP_IGNORE | TRX_DUP_REPLACE */
514
 
        unsigned        has_search_latch:1;
 
512
        ulint           duplicates;     /*!< TRX_DUP_IGNORE | TRX_DUP_REPLACE */
 
513
        unsigned        has_search_latch;
515
514
                                        /* TRUE if this trx has latched the
516
515
                                        search system latch in S-mode */
517
 
        unsigned        declared_to_be_inside_innodb:1;
 
516
        ulint           deadlock_mark;  /*!< a mark field used in deadlock
 
517
                                        checking algorithm.  */
 
518
        trx_dict_op_t   dict_operation; /**< @see enum trx_dict_op */
 
519
 
 
520
        /* Fields protected by the srv_conc_mutex. */
 
521
        ulint           declared_to_be_inside_innodb;
518
522
                                        /* this is TRUE if we have declared
519
523
                                        this transaction in
520
524
                                        srv_conc_enter_innodb to be inside the
521
525
                                        InnoDB engine */
522
 
        unsigned        handling_signals:1;/* this is TRUE as long as the trx
523
 
                                        is handling signals */
524
 
        unsigned        dict_operation_lock_mode:2;
525
 
                                        /* 0, RW_S_LATCH, or RW_X_LATCH:
 
526
 
 
527
        /* Fields protected by dict_operation_lock. The very latch
 
528
        it is used to track. */
 
529
        ulint           dict_operation_lock_mode;
 
530
                                        /*!< 0, RW_S_LATCH, or RW_X_LATCH:
526
531
                                        the latch mode trx currently holds
527
532
                                        on dict_operation_lock */
 
533
 
 
534
        /* All the next fields are protected by the kernel mutex, except the
 
535
        undo logs which are protected by undo_mutex */
 
536
        ulint           is_purge;       /*!< 0=user transaction, 1=purge */
 
537
        ulint           is_recovered;   /*!< 0=normal transaction,
 
538
                                        1=recovered, must be rolled back */
 
539
        ulint           que_state;      /*!< valid when conc_state
 
540
                                        == TRX_ACTIVE: TRX_QUE_RUNNING,
 
541
                                        TRX_QUE_LOCK_WAIT, ... */
 
542
        ulint           handling_signals;/* this is TRUE as long as the trx
 
543
                                        is handling signals */
528
544
        time_t          start_time;     /*!< time the trx object was created
529
545
                                        or the state last time became
530
546
                                        TRX_ACTIVE */
536
552
                                        max trx id when the transaction is
537
553
                                        moved to COMMITTED_IN_MEMORY state */
538
554
        ib_uint64_t     commit_lsn;     /*!< lsn at the time of the commit */
539
 
        trx_id_t        table_id;       /*!< Table to drop iff dict_operation
540
 
                                        is TRUE, or ut_dulint_zero. */
 
555
        table_id_t      table_id;       /*!< Table to drop iff dict_operation
 
556
                                        is TRUE, or 0. */
541
557
        /*------------------------------*/
542
 
        void*           mysql_thd;      /*!< MySQL thread handle corresponding
 
558
        drizzled::Session *mysql_thd;   /*!< MySQL thread handle corresponding
543
559
                                        to this trx, or NULL */
544
 
        const char*     mysql_query_str;/* pointer to the field in mysqld_thd
545
 
                                        which contains the pointer to the
546
 
                                        current SQL query string */
547
560
        const char*     mysql_log_file_name;
548
561
                                        /* if MySQL binlog is used, this field
549
562
                                        contains a pointer to the latest file
635
648
                        wait_thrs;      /*!< query threads belonging to this
636
649
                                        trx that are in the QUE_THR_LOCK_WAIT
637
650
                                        state */
638
 
        ulint           deadlock_mark;  /*!< a mark field used in deadlock
639
 
                                        checking algorithm.  This must be
640
 
                                        in its own machine word, because
641
 
                                        it can be changed by other
642
 
                                        threads while holding kernel_mutex. */
643
651
        /*------------------------------*/
644
652
        mem_heap_t*     lock_heap;      /*!< memory heap for the locks of the
645
653
                                        transaction */
707
715
        /*------------------------------*/
708
716
        char detailed_error[256];       /*!< detailed error message for last
709
717
                                        error, or empty. */
 
718
 
 
719
        ibool           log_commit_id;  /*!< log the commit id to the sys
 
720
                                        file */
 
721
        inline drizzled::Session *session()
 
722
        {
 
723
          return mysql_thd;
 
724
        }
 
725
        inline drizzled::Session *session() const
 
726
        {
 
727
          return mysql_thd;
 
728
        }
710
729
};
711
730
 
712
731
#define TRX_MAX_N_THREADS       32      /* maximum number of