You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

121 lines
3.5 KiB

  1. /*****************************************************************************
  2. Copyright (c) 1996, 2009, Innobase Oy. All Rights Reserved.
  3. This program is free software; you can redistribute it and/or modify it under
  4. the terms of the GNU General Public License as published by the Free Software
  5. Foundation; version 2 of the License.
  6. This program is distributed in the hope that it will be useful, but WITHOUT
  7. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  8. FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  9. You should have received a copy of the GNU General Public License along with
  10. this program; if not, write to the Free Software Foundation, Inc., 59 Temple
  11. Place, Suite 330, Boston, MA 02111-1307 USA
  12. *****************************************************************************/
  13. /**************************************************//**
  14. @file include/lock0lock.ic
  15. The transaction lock system
  16. Created 5/7/1996 Heikki Tuuri
  17. *******************************************************/
  18. #include "sync0sync.h"
  19. #include "srv0srv.h"
  20. #include "dict0dict.h"
  21. #include "row0row.h"
  22. #include "trx0sys.h"
  23. #include "trx0trx.h"
  24. #include "buf0buf.h"
  25. #include "page0page.h"
  26. #include "page0cur.h"
  27. #include "row0vers.h"
  28. #include "que0que.h"
  29. #include "btr0cur.h"
  30. #include "read0read.h"
  31. #include "log0recv.h"
  32. /*********************************************************************//**
  33. Calculates the fold value of a page file address: used in inserting or
  34. searching for a lock in the hash table.
  35. @return folded value */
  36. UNIV_INLINE
  37. ulint
  38. lock_rec_fold(
  39. /*==========*/
  40. ulint space, /*!< in: space */
  41. ulint page_no)/*!< in: page number */
  42. {
  43. return(ut_fold_ulint_pair(space, page_no));
  44. }
  45. /*********************************************************************//**
  46. Calculates the hash value of a page file address: used in inserting or
  47. searching for a lock in the hash table.
  48. @return hashed value */
  49. UNIV_INLINE
  50. ulint
  51. lock_rec_hash(
  52. /*==========*/
  53. ulint space, /*!< in: space */
  54. ulint page_no)/*!< in: page number */
  55. {
  56. return(hash_calc_hash(lock_rec_fold(space, page_no),
  57. lock_sys->rec_hash));
  58. }
  59. /*********************************************************************//**
  60. Checks if some transaction has an implicit x-lock on a record in a clustered
  61. index.
  62. @return transaction which has the x-lock, or NULL */
  63. UNIV_INLINE
  64. trx_t*
  65. lock_clust_rec_some_has_impl(
  66. /*=========================*/
  67. const rec_t* rec, /*!< in: user record */
  68. dict_index_t* index, /*!< in: clustered index */
  69. const ulint* offsets)/*!< in: rec_get_offsets(rec, index) */
  70. {
  71. trx_id_t trx_id;
  72. ut_ad(mutex_own(&kernel_mutex));
  73. ut_ad(dict_index_is_clust(index));
  74. ut_ad(page_rec_is_user_rec(rec));
  75. trx_id = row_get_rec_trx_id(rec, index, offsets);
  76. if (trx_is_active(trx_id)) {
  77. /* The modifying or inserting transaction is active */
  78. return(trx_get_on_id(trx_id));
  79. }
  80. return(NULL);
  81. }
  82. /*********************************************************************//**
  83. Gets the heap_no of the smallest user record on a page.
  84. @return heap_no of smallest user record, or PAGE_HEAP_NO_SUPREMUM */
  85. UNIV_INLINE
  86. ulint
  87. lock_get_min_heap_no(
  88. /*=================*/
  89. const buf_block_t* block) /*!< in: buffer block */
  90. {
  91. const page_t* page = block->frame;
  92. if (page_is_comp(page)) {
  93. return(rec_get_heap_no_new(
  94. page
  95. + rec_get_next_offs(page + PAGE_NEW_INFIMUM,
  96. TRUE)));
  97. } else {
  98. return(rec_get_heap_no_old(
  99. page
  100. + rec_get_next_offs(page + PAGE_OLD_INFIMUM,
  101. FALSE)));
  102. }
  103. }