Drizzled Public API Documentation

trx0trx.h
Go to the documentation of this file.
00001 /*****************************************************************************
00002 
00003 Copyright (C) 1996, 2010, Innobase Oy. All Rights Reserved.
00004 
00005 This program is free software; you can redistribute it and/or modify it under
00006 the terms of the GNU General Public License as published by the Free Software
00007 Foundation; version 2 of the License.
00008 
00009 This program is distributed in the hope that it will be useful, but WITHOUT
00010 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00011 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
00012 
00013 You should have received a copy of the GNU General Public License along with
00014 this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
00015 St, Fifth Floor, Boston, MA 02110-1301 USA
00016 
00017 *****************************************************************************/
00018 
00019 /**************************************************/
00026 #pragma once
00027 #ifndef trx0trx_h
00028 #define trx0trx_h
00029 
00030 #include "univ.i"
00031 #include "trx0types.h"
00032 #include "dict0types.h"
00033 #ifndef UNIV_HOTBACKUP
00034 #include "lock0types.h"
00035 #include "usr0types.h"
00036 #include "que0types.h"
00037 #include "mem0mem.h"
00038 #include "read0types.h"
00039 #include "trx0xa.h"
00040 #include "ut0vec.h"
00041 
00042 namespace drizzled { class Session; }
00043 
00045 extern sess_t*  trx_dummy_sess;
00046 
00049 extern ulint  trx_n_mysql_transactions;
00050 
00051 /********************************************************************/
00053 UNIV_INTERN
00054 void
00055 trx_search_latch_release_if_reserved(
00056 /*=================================*/
00057   trx_t*     trx); 
00058 /******************************************************************/
00060 UNIV_INTERN
00061 void
00062 trx_set_detailed_error(
00063 /*===================*/
00064   trx_t*    trx,  
00065   const char* msg); 
00066 /*************************************************************/
00069 UNIV_INTERN
00070 void
00071 trx_set_detailed_error_from_file(
00072 /*=============================*/
00073   trx_t*  trx,  
00074   FILE* file);  
00075 /****************************************************************/
00078 UNIV_INLINE
00079 ibool
00080 trx_log_commit_id(
00081 /*==============*/
00082   const trx_t*    trx);   
00083 /****************************************************************/
00086 UNIV_INLINE
00087 const dict_index_t*
00088 trx_get_error_info(
00089 /*===============*/
00090   const trx_t*  trx); 
00091 /****************************************************************/
00094 UNIV_INTERN
00095 trx_t*
00096 trx_create(
00097 /*=======*/
00098   sess_t* sess) 
00099   __attribute__((nonnull));
00100 /********************************************************************/
00103 UNIV_INTERN
00104 trx_t*
00105 trx_allocate_for_mysql(void);
00106 /*========================*/
00107 /********************************************************************/
00110 UNIV_INTERN
00111 trx_t*
00112 trx_allocate_for_background(void);
00113 /*=============================*/
00114 /********************************************************************/
00116 UNIV_INTERN
00117 void
00118 trx_free(
00119 /*=====*/
00120   trx_t*  trx); 
00121 /********************************************************************/
00123 UNIV_INTERN
00124 void
00125 trx_free_for_mysql(
00126 /*===============*/
00127   trx_t*  trx); 
00128 /********************************************************************/
00130 UNIV_INTERN
00131 void
00132 trx_free_for_background(
00133 /*====================*/
00134   trx_t*  trx); 
00135 /****************************************************************/
00141 UNIV_INTERN
00142 void
00143 trx_lists_init_at_db_start(void);
00144 /*============================*/
00145 /****************************************************************/
00149 UNIV_INTERN
00150 ibool
00151 trx_start(
00152 /*======*/
00153   trx_t*  trx,  
00154   ulint rseg_id);
00157 /****************************************************************/
00160 UNIV_INTERN
00161 ibool
00162 trx_start_low(
00163 /*==========*/
00164   trx_t*  trx,  
00165   ulint rseg_id);
00168 /*************************************************************/
00170 UNIV_INLINE
00171 void
00172 trx_start_if_not_started(
00173 /*=====================*/
00174   trx_t*  trx); 
00175 /*************************************************************/
00178 UNIV_INLINE
00179 void
00180 trx_start_if_not_started_low(
00181 /*=========================*/
00182   trx_t*  trx); 
00183 /****************************************************************/
00185 UNIV_INTERN
00186 void
00187 trx_commit_off_kernel(
00188 /*==================*/
00189   trx_t*  trx); 
00190 /****************************************************************/
00194 UNIV_INTERN
00195 void
00196 trx_cleanup_at_db_startup(
00197 /*======================*/
00198   trx_t*  trx); 
00199 /**********************************************************************/
00202 UNIV_INTERN
00203 ulint
00204 trx_commit_for_mysql(
00205 /*=================*/
00206   trx_t*  trx); 
00207 /**********************************************************************/
00210 UNIV_INTERN
00211 ulint
00212 trx_prepare_for_mysql(
00213 /*==================*/
00214   trx_t*  trx); 
00215 /**********************************************************************/
00219 UNIV_INTERN
00220 int
00221 trx_recover_for_mysql(
00222 /*==================*/
00223   XID*  xid_list, 
00224   ulint len);   
00225 /*******************************************************************/
00229 UNIV_INTERN
00230 trx_t *
00231 trx_get_trx_by_xid(
00232 /*===============*/
00233   XID*  xid); 
00234 /**********************************************************************/
00238 UNIV_INTERN
00239 ulint
00240 trx_commit_complete_for_mysql(
00241 /*==========================*/
00242   trx_t*  trx); 
00243 /**********************************************************************/
00245 UNIV_INTERN
00246 void
00247 trx_mark_sql_stat_end(
00248 /*==================*/
00249   trx_t*  trx); 
00250 /********************************************************************/
00255 UNIV_INTERN
00256 read_view_t*
00257 trx_assign_read_view(
00258 /*=================*/
00259   trx_t*  trx); 
00260 /***********************************************************/
00264 UNIV_INTERN
00265 void
00266 trx_end_lock_wait(
00267 /*==============*/
00268   trx_t*  trx); 
00269 /****************************************************************/
00271 UNIV_INTERN
00272 void
00273 trx_sig_send(
00274 /*=========*/
00275   trx_t*    trx,    
00276   ulint   type,   
00277   ulint   sender,   
00279   que_thr_t*  receiver_thr, 
00282   trx_savept_t* savept,   
00284   que_thr_t** next_thr);  
00290 /****************************************************************/
00293 UNIV_INTERN
00294 void
00295 trx_sig_reply(
00296 /*==========*/
00297   trx_sig_t*  sig,    
00298   que_thr_t** next_thr);  
00303 /****************************************************************/
00305 UNIV_INTERN
00306 void
00307 trx_sig_remove(
00308 /*===========*/
00309   trx_t*    trx,  
00310   trx_sig_t*  sig); 
00311 /****************************************************************/
00313 UNIV_INTERN
00314 void
00315 trx_sig_start_handle(
00316 /*=================*/
00317   trx_t*    trx,    
00318   que_thr_t** next_thr);  
00323 /****************************************************************/
00328 UNIV_INTERN
00329 void
00330 trx_end_signal_handling(
00331 /*====================*/
00332   trx_t*  trx); 
00333 /*********************************************************************/
00336 UNIV_INTERN
00337 commit_node_t*
00338 commit_node_create(
00339 /*===============*/
00340   mem_heap_t* heap);  
00341 /***********************************************************/
00344 UNIV_INTERN
00345 que_thr_t*
00346 trx_commit_step(
00347 /*============*/
00348   que_thr_t*  thr); 
00350 /**********************************************************************/
00353 UNIV_INTERN
00354 void
00355 trx_print(
00356 /*======*/
00357   FILE* f,    
00358   trx_t*  trx,    
00359   ulint max_query_len); 
00363 typedef enum trx_dict_op {
00365   TRX_DICT_OP_NONE = 0,
00370   TRX_DICT_OP_TABLE = 1,
00374   TRX_DICT_OP_INDEX = 2
00375 } trx_dict_op_t;
00376 
00377 /**********************************************************************/
00380 UNIV_INLINE
00381 enum trx_dict_op
00382 trx_get_dict_operation(
00383 /*===================*/
00384   const trx_t*  trx)  
00385   __attribute__((pure));
00386 /**********************************************************************/
00388 UNIV_INLINE
00389 void
00390 trx_set_dict_operation(
00391 /*===================*/
00392   trx_t*      trx,  
00393   enum trx_dict_op  op);  
00396 #ifndef UNIV_HOTBACKUP
00397 /**********************************************************************/
00400 UNIV_INTERN
00401 ibool
00402 trx_is_interrupted(
00403 /*===============*/
00404   trx_t*  trx); 
00405 /**********************************************************************/
00408 UNIV_INTERN
00409 ibool
00410 trx_is_strict(
00411 /*==========*/
00412   trx_t*  trx); 
00413 #else /* !UNIV_HOTBACKUP */
00414 #define trx_is_interrupted(trx) FALSE
00415 #endif /* !UNIV_HOTBACKUP */
00416 
00417 /*******************************************************************/
00422 #define TRX_WEIGHT(t) ((t)->undo_no + UT_LIST_GET_LEN((t)->trx_locks))
00423 
00424 /*******************************************************************/
00429 UNIV_INTERN
00430 ibool
00431 trx_weight_ge(
00432 /*==========*/
00433   const trx_t*  a,  
00434   const trx_t*  b); 
00436 /* Maximum length of a string that can be returned by
00437 trx_get_que_state_str(). */
00438 #define TRX_QUE_STATE_STR_MAX_LEN 12 /* "ROLLING BACK" */
00439 
00440 /*******************************************************************/
00444 UNIV_INLINE
00445 const char*
00446 trx_get_que_state_str(
00447 /*==================*/
00448   const trx_t*  trx); 
00450 /* Signal to a transaction */
00451 struct trx_sig_struct{
00452   unsigned  type:3;   
00453   unsigned  sender:1; 
00455   que_thr_t*  receiver; 
00458   trx_savept_t  savept;   
00459   UT_LIST_NODE_T(trx_sig_t)
00460       signals;  
00462   UT_LIST_NODE_T(trx_sig_t)
00463       reply_signals;  
00465 };
00466 
00467 #define TRX_MAGIC_N 91118598
00468 
00469 /* The transaction handle; every session has a trx object which is freed only
00470 when the session is freed; in addition there may be session-less transactions
00471 rolling back after a database recovery */
00472 
00473 struct trx_struct{
00474   ulint   magic_n;
00475 
00476   /* These fields are not protected by any mutex. */
00477   const char* op_info;  
00480   ulint   conc_state; 
00484   ulint   isolation_level;/* TRX_ISO_REPEATABLE_READ, ... */
00485   ulint   check_foreigns; /* normally TRUE, but if the user
00486           wants to suppress foreign key checks,
00487           (in table imports, for example) we
00488           set this FALSE */
00489   unsigned  check_unique_secondary;
00490           /* normally TRUE, but if the user
00491           wants to speed up inserts by
00492           suppressing unique key checks
00493           for secondary indexes when we decide
00494           if we can use the insert buffer for
00495           them, we set this FALSE */
00496   unsigned  support_xa; 
00501   unsigned  flush_log_later;/* In 2PC, we hold the
00502           prepare_commit mutex across
00503           both phases. In that case, we
00504           defer flush of the logs to disk
00505           until after we release the
00506           mutex. */
00507   unsigned  must_flush_log_later;/* this flag is set to TRUE in
00508           trx_commit_off_kernel() if
00509           flush_log_later was TRUE, and there
00510           were modifications by the transaction;
00511           in that case we must flush the log
00512           in trx_commit_complete_for_mysql() */
00513   ulint   duplicates; 
00514   unsigned  has_search_latch;
00515           /* TRUE if this trx has latched the
00516           search system latch in S-mode */
00517   ulint   deadlock_mark;  
00519   trx_dict_op_t dict_operation; 
00521   /* Fields protected by the srv_conc_mutex. */
00522   ulint   declared_to_be_inside_innodb;
00523           /* this is TRUE if we have declared
00524           this transaction in
00525           srv_conc_enter_innodb to be inside the
00526           InnoDB engine */
00527 
00528   /* Fields protected by dict_operation_lock. The very latch
00529   it is used to track. */
00530   ulint   dict_operation_lock_mode;
00535   /* All the next fields are protected by the kernel mutex, except the
00536   undo logs which are protected by undo_mutex */
00537   ulint   is_purge; 
00538   ulint   is_recovered; 
00540   ulint   que_state;  
00543   ulint   handling_signals;/* this is TRUE as long as the trx
00544           is handling signals */
00545   time_t    start_time; 
00548   trx_id_t  id;   
00549   XID   xid;    
00552   trx_id_t  no;   
00555   ib_uint64_t commit_lsn; 
00556   table_id_t  table_id; 
00558   /*------------------------------*/
00559         drizzled::Session *mysql_thd; 
00561   const char* mysql_log_file_name;
00562           /* if MySQL binlog is used, this field
00563           contains a pointer to the latest file
00564           name; this is NULL if binlog is not
00565           used */
00566   ib_int64_t  mysql_log_offset;/* if MySQL binlog is used, this field
00567           contains the end offset of the binlog
00568           entry */
00569   os_thread_id_t  mysql_thread_id;/* id of the MySQL thread associated
00570           with this transaction object */
00571   ulint   mysql_process_no;/* since in Linux, 'top' reports
00572           process id's and not thread id's, we
00573           store the process number too */
00574   ulint   mysql_n_tables_locked;
00575           /* how many tables the current SQL
00576           statement uses, except those
00577           in consistent read */
00578   ulint   search_latch_timeout;
00579           /* If we notice that someone is
00580           waiting for our S-lock on the search
00581           latch to be released, we wait in
00582           row0sel.c for BTR_SEA_TIMEOUT new
00583           searches until we try to keep
00584           the search latch again over
00585           calls from MySQL; this is intended
00586           to reduce contention on the search
00587           latch */
00588   /*------------------------------*/
00589   ulint   n_tickets_to_enter_innodb;
00590           /* this can be > 0 only when
00591           declared_to_... is TRUE; when we come
00592           to srv_conc_innodb_enter, if the value
00593           here is > 0, we decrement this by 1 */
00594   /*------------------------------*/
00595   UT_LIST_NODE_T(trx_t)
00596       trx_list; 
00597   UT_LIST_NODE_T(trx_t)
00598       mysql_trx_list; 
00600   /*------------------------------*/
00601   ulint   error_state;  
00606   const dict_index_t*error_info;  
00609   ulint   error_key_num;  
00612   sess_t*   sess;   
00613   que_t*    graph;    
00619   ulint   n_active_thrs;  
00620   que_t*    graph_before_signal_handling;
00621           /* value of graph when signal handling
00622           for this trx started: this is used to
00623           return control to the original query
00624           graph for error processing */
00625   trx_sig_t sig;    
00627   UT_LIST_BASE_NODE_T(trx_sig_t)
00628       signals;  
00630   UT_LIST_BASE_NODE_T(trx_sig_t)
00631       reply_signals;  
00636   /*------------------------------*/
00637   lock_t*   wait_lock;  
00641   ibool   was_chosen_as_deadlock_victim;
00642           /* when the transaction decides to wait
00643           for a lock, it sets this to FALSE;
00644           if another transaction chooses this
00645           transaction as a victim in deadlock
00646           resolution, it sets this to TRUE */
00647   time_t    wait_started; 
00648   UT_LIST_BASE_NODE_T(que_thr_t)
00649       wait_thrs;  
00652   /*------------------------------*/
00653   mem_heap_t* lock_heap;  
00655   UT_LIST_BASE_NODE_T(lock_t)
00656       trx_locks;  
00657   /*------------------------------*/
00658   mem_heap_t* global_read_view_heap;
00659           /* memory heap for the global read
00660           view */
00661   read_view_t*  global_read_view;
00662           /* consistent read view associated
00663           to a transaction or NULL */
00664   read_view_t*  read_view;  
00670   /*------------------------------*/
00671   UT_LIST_BASE_NODE_T(trx_named_savept_t)
00672       trx_savepoints; 
00674   /*------------------------------*/
00675   mutex_t   undo_mutex; 
00681   undo_no_t undo_no;  
00688   trx_savept_t  last_sql_stat_start;
00689           /* undo_no when the last sql statement
00690           was started: in case of an error, trx
00691           is rolled back down to this undo
00692           number; see note at undo_mutex! */
00693   trx_rseg_t* rseg;   
00696   trx_undo_t* insert_undo;  
00698   trx_undo_t* update_undo;  
00700   undo_no_t roll_limit; 
00702   ulint   pages_undone; 
00704   trx_undo_arr_t* undo_no_arr;  
00707   /*------------------------------*/
00708   ulint   n_autoinc_rows; 
00711   ib_vector_t*    autoinc_locks;  /* AUTOINC locks held by this
00712           transaction. Note that these are
00713           also in the lock list trx_locks. This
00714           vector needs to be freed explicitly
00715           when the trx_t instance is desrtoyed */
00716   /*------------------------------*/
00717   char detailed_error[256]; 
00720   ibool     log_commit_id;  
00722         inline drizzled::Session *session()
00723         {
00724           return mysql_thd;
00725         }
00726         inline drizzled::Session *session() const
00727         {
00728           return mysql_thd;
00729         }
00730 };
00731 
00732 #define TRX_MAX_N_THREADS 32  /* maximum number of
00733           concurrent threads running a
00734           single operation of a
00735           transaction, e.g., a parallel
00736           query */
00737 /* Transaction concurrency states (trx->conc_state) */
00738 #define TRX_NOT_STARTED   0
00739 #define TRX_ACTIVE    1
00740 #define TRX_COMMITTED_IN_MEMORY 2
00741 #define TRX_PREPARED    3 /* Support for 2PC/XA */
00742 
00743 /* Transaction execution states when trx->conc_state == TRX_ACTIVE */
00744 #define TRX_QUE_RUNNING   0 /* transaction is running */
00745 #define TRX_QUE_LOCK_WAIT 1 /* transaction is waiting for a lock */
00746 #define TRX_QUE_ROLLING_BACK  2 /* transaction is rolling back */
00747 #define TRX_QUE_COMMITTING  3 /* transaction is committing */
00748 
00749 /* Transaction isolation levels (trx->isolation_level) */
00750 #define TRX_ISO_READ_UNCOMMITTED  0 /* dirty read: non-locking
00751             SELECTs are performed so that
00752             we do not look at a possible
00753             earlier version of a record;
00754             thus they are not 'consistent'
00755             reads under this isolation
00756             level; otherwise like level
00757             2 */
00758 
00759 #define TRX_ISO_READ_COMMITTED    1 /* somewhat Oracle-like
00760             isolation, except that in
00761             range UPDATE and DELETE we
00762             must block phantom rows
00763             with next-key locks;
00764             SELECT ... FOR UPDATE and ...
00765             LOCK IN SHARE MODE only lock
00766             the index records, NOT the
00767             gaps before them, and thus
00768             allow free inserting;
00769             each consistent read reads its
00770             own snapshot */
00771 
00772 #define TRX_ISO_REPEATABLE_READ   2 /* this is the default;
00773             all consistent reads in the
00774             same trx read the same
00775             snapshot;
00776             full next-key locking used
00777             in locking reads to block
00778             insertions into gaps */
00779 
00780 #define TRX_ISO_SERIALIZABLE    3 /* all plain SELECTs are
00781             converted to LOCK IN SHARE
00782             MODE reads */
00783 
00784 /* Treatment of duplicate values (trx->duplicates; for example, in inserts).
00785 Multiple flags can be combined with bitwise OR. */
00786 #define TRX_DUP_IGNORE  1 /* duplicate rows are to be updated */
00787 #define TRX_DUP_REPLACE 2 /* duplicate rows are to be replaced */
00788 
00789 
00790 /* Types of a trx signal */
00791 #define TRX_SIG_NO_SIGNAL   0
00792 #define TRX_SIG_TOTAL_ROLLBACK    1
00793 #define TRX_SIG_ROLLBACK_TO_SAVEPT  2
00794 #define TRX_SIG_COMMIT      3
00795 #define TRX_SIG_ERROR_OCCURRED    4
00796 #define TRX_SIG_BREAK_EXECUTION   5
00797 
00798 /* Sender types of a signal */
00799 #define TRX_SIG_SELF    0 /* sent by the session itself, or
00800           by an error occurring within this
00801           session */
00802 #define TRX_SIG_OTHER_SESS  1 /* sent by another session (which
00803           must hold rights to this) */
00804 
00806 enum commit_node_state {
00807   COMMIT_NODE_SEND = 1, 
00809   COMMIT_NODE_WAIT  
00811 };
00812 
00814 struct commit_node_struct{
00815   que_common_t  common; 
00816   enum commit_node_state
00817       state;  
00818 };
00819 
00820 
00821 
00822 #ifndef UNIV_NONINL
00823 #include "trx0trx.ic"
00824 #endif
00825 #endif /* !UNIV_HOTBACKUP */
00826 
00827 #endif