mariadb/trx/trx0purge.c
sunny 37312683cc branches/innodb+: Merge revisions r5971:6130 from branches/zip.
------------------------------------------------------------------------
  r5971 | marko | 2009-09-23 23:03:51 +1000 (Wed, 23 Sep 2009) | 2 lines

  branches/zip: os_file_pwrite(): Make the code compile in InnoDB Hot Backup
  when the pwrite system call is not available.
  ------------------------------------------------------------------------
  r5972 | marko | 2009-09-24 05:44:52 +1000 (Thu, 24 Sep 2009) | 5 lines

  branches/zip: fil_node_open_file(): In InnoDB Hot Backup,
  determine the page size of single-file tablespaces before computing
    the file node size.  Otherwise, the space->size of compressed tablespaces
  would be computed with UNIV_PAGE_SIZE instead of key_block_size.
  This should fix Issue #313.
  ------------------------------------------------------------------------
  r5973 | marko | 2009-09-24 05:53:21 +1000 (Thu, 24 Sep 2009) | 2 lines

  branches/zip: recv_add_to_hash_table():
  Simplify obfuscated pointer arithmetics.
  ------------------------------------------------------------------------
  r5978 | marko | 2009-09-24 17:47:56 +1000 (Thu, 24 Sep 2009) | 1 line

  branches/zip: Fix warnings and errors when UNIV_HOTBACKUP is defined.
  ------------------------------------------------------------------------
  r5979 | marko | 2009-09-24 20:16:10 +1000 (Thu, 24 Sep 2009) | 4 lines

  branches/zip: ha_innodb.cc: Define MYSQL_PLUGIN_IMPORT when necessary.
  This preprocessor symbol has been recently introduced in MySQL 5.1.
  The InnoDB Plugin should remain source compatible with MySQL 5.1.24
  and later.
  ------------------------------------------------------------------------
  r5988 | calvin | 2009-09-26 05:14:43 +1000 (Sat, 26 Sep 2009) | 8 lines

  branches/zip: fix bug#47055 unconditional exit(1) on ERROR_WORKING_SET_QUOTA
  1453 (0x5AD) for InnoDB backend

  When error ERROR_WORKING_SET_QUOTA or ERROR_NO_SYSTEM_RESOURCES
  occurs, yields for 100ms and retries the operation.

  Approved by: Heikki (on IM)

  ------------------------------------------------------------------------
  r5992 | vasil | 2009-09-28 17:10:29 +1000 (Mon, 28 Sep 2009) | 4 lines

  branches/zip:

  Add ChangeLog entry for c5988.

  ------------------------------------------------------------------------
  r5994 | marko | 2009-09-28 18:33:59 +1000 (Mon, 28 Sep 2009) | 17 lines

  branches/zip: Try to prevent the reuse of tablespace identifiers after
  InnoDB has crashed during table creation.  Also, refuse to start if
  files with duplicate tablespace identifiers are encountered.

    fil_node_create(): Update fil_system->max_assigned_id.  This should
  prevent the reuse of a space->id when InnoDB does a full crash
  recovery and invokes fil_load_single_table_tablespaces().  Normally,
  fil_system->max_assigned_id is initialized from
  SELECT MAX(ID) FROM SYS_TABLES.

  fil_open_single_table_tablespace(): Return FALSE when
  fil_space_create() fails.

  fil_load_single_table_tablespace(): Exit if fil_space_create() fails
  and innodb_force_recovery=0.

  rb://173 approved by Heikki Tuuri.  This addresses Issue #335.
  ------------------------------------------------------------------------
  r5995 | marko | 2009-09-28 18:52:25 +1000 (Mon, 28 Sep 2009) | 17 lines

  branches/zip: Do not write to PAGE_INDEX_ID after page creation,
  not even when restoring an uncompressed page after a compression failure.

  btr_page_reorganize_low(): On compression failure, do not restore
  those page header fields that should not be affected by the
  reorganization.  Instead, compare the fields.

  page_zip_decompress(): Add the parameter ibool all, for copying all
  page header fields.  Pass the parameter all=TRUE on block read
  completion, redo log application, and page_zip_validate(); pass
  all=FALSE in all other cases.

  page_zip_reorganize(): Do not restore the uncompressed page on
  failure.  It will be restored (to pre-modification state) by the
  caller anyway.

  rb://167, Issue #346
  ------------------------------------------------------------------------
  r5996 | marko | 2009-09-28 22:46:02 +1000 (Mon, 28 Sep 2009) | 4 lines

  branches/zip: Address Issue #350 in comments.

  lock_rec_queue_validate(), lock_rec_queue_validate(): Note that
  this debug code may violate the latching order and cause deadlocks.
  ------------------------------------------------------------------------
  r5997 | marko | 2009-09-28 23:03:58 +1000 (Mon, 28 Sep 2009) | 12 lines

  branches/zip: Remove an assertion failure when the InnoDB data dictionary
  is inconsistent with the MySQL .frm file.

  ha_innobase::index_read(): When the index cannot be found,
  return an error.

  ha_innobase::change_active_index(): When prebuilt->index == NULL,
  set also prebuilt->index_usable = FALSE.  This is not needed for
  correctness, because prebuilt->index_usable is only checked by
  row_search_for_mysql(), which requires prebuilt->index != NULL.

  This addresses Issue #349.  Approved by Heikki Tuuri over IM.
  ------------------------------------------------------------------------
  r6005 | vasil | 2009-09-29 18:09:52 +1000 (Tue, 29 Sep 2009) | 4 lines

  branches/zip:

  ChangeLog: wrap around 78th column, not earlier.

  ------------------------------------------------------------------------
  r6006 | vasil | 2009-09-29 20:15:25 +1000 (Tue, 29 Sep 2009) | 4 lines

  branches/zip:

  Add ChangeLog entry for the release of 1.0.4.

  ------------------------------------------------------------------------
  r6007 | vasil | 2009-09-29 23:19:59 +1000 (Tue, 29 Sep 2009) | 6 lines

  branches/zip:

  Fix the year, should be 2009.

  Pointed by:	Calvin

  ------------------------------------------------------------------------
  r6026 | marko | 2009-09-30 17:18:24 +1000 (Wed, 30 Sep 2009) | 1 line

  branches/zip: Add some debug assertions for checking FSEG_MAGIC_N.
  ------------------------------------------------------------------------
  r6028 | marko | 2009-09-30 23:55:23 +1000 (Wed, 30 Sep 2009) | 3 lines

  branches/zip: recv_no_log_write: New debug flag for tracking down
  Mantis Issue #347.  No modifications should be made to the database
  while recv_apply_hashed_log_recs() is about to complete.
  ------------------------------------------------------------------------
  r6029 | calvin | 2009-10-01 06:32:02 +1000 (Thu, 01 Oct 2009) | 4 lines

    branches/zip: non-functional changes

  Fix typo.

  ------------------------------------------------------------------------
  r6031 | marko | 2009-10-01 21:24:33 +1000 (Thu, 01 Oct 2009) | 49 lines

  branches/zip: Clean up after a crash during DROP INDEX.
  When InnoDB crashes while dropping an index, ensure that
  the index will be completely dropped during crash recovery.

  row_merge_drop_index(): Before dropping an index, rename the index to
  start with TEMP_INDEX_PREFIX_STR and commit the change, so that
  row_merge_drop_temp_indexes() will drop the index after crash
  recovery if the server crashes while dropping the index.

  fseg_inode_try_get(): New function, forked from fseg_inode_get().
  Return NULL if the file segment index node is free.

  fseg_inode_get(): Assert that the file segment index node is not free.

  fseg_free_step(): If the file segment index node is already free,
  print a diagnostic message and return TRUE.

  fsp_free_seg_inode(): Write a nonzero number to FSEG_MAGIC_N, so that
  allocated-and-freed file segment index nodes can be better
  distinguished from uninitialized ones.

  This is rb://174, addressing Issue #348.

  Tested by restarting mysqld upon the completion of the added
  log_write_up_to() invocation below, during DROP INDEX.  The index was
  dropped after crash recovery, and re-issuing the DROP INDEX did not
  crash the server.
    
    Index: btr/btr0btr.c
    ===================================================================
    --- btr/btr0btr.c	(revision 6026)
    +++ btr/btr0btr.c	(working copy)
    @@ -42,6 +42,7 @@ Created 6/2/1994 Heikki Tuuri
     #include "ibuf0ibuf.h"
     #include "trx0trx.h"
    +#include "log0log.h"
     
     /*
     Latching strategy of the InnoDB B-tree
     --------------------------------------
    @@ -873,6 +874,8 @@ leaf_loop:
     
   		  goto leaf_loop;
   	  }
    +
    +	log_write_up_to(mtr.end_lsn, LOG_WAIT_ALL_GROUPS, TRUE);
     top_loop:
   	  mtr_start(&mtr);

  ------------------------------------------------------------------------
  r6033 | calvin | 2009-10-02 06:19:46 +1000 (Fri, 02 Oct 2009) | 4 lines

  branches/zip: fix a typo in error message

  Reported as bug#47763.

  ------------------------------------------------------------------------
  r6043 | inaam | 2009-10-06 01:45:35 +1100 (Tue, 06 Oct 2009) | 12 lines

  branches/zip  rb://176

  Do not invalidate buffer pool while an LRU batch is active. Added
  code to buf_pool_invalidate() to wait for the running batches to finish.

  This patch also resets the state of buf_pool struct at invalidation. This
  addresses the concern where buf_pool->freed_page_clock becomes non-zero
  because we read in a system tablespace page for file format info at
  startup.

  Approved by: Marko

  ------------------------------------------------------------------------
  r6044 | pekka | 2009-10-07 01:44:54 +1100 (Wed, 07 Oct 2009) | 5 lines

  branches/zip:
  Add os_file_is_same() function for Hot Backup (inside ifdef UNIV_HOTBACKUP).
  This is part of the fix for Issue #186.
  Note! The Windows implementation is incomplete.

  ------------------------------------------------------------------------
  r6046 | pekka | 2009-10-08 20:24:56 +1100 (Thu, 08 Oct 2009) | 3 lines

  branches/zip: Revert r6044 which added os_file_is_same() function
  (issue#186). This functionality is moved to Hot Backup source tree.

  ------------------------------------------------------------------------
  r6048 | vasil | 2009-10-09 16:42:55 +1100 (Fri, 09 Oct 2009) | 16 lines

  branches/zip:

  When scanning a directory readdir() is called and stat() after it,
  if a file is deleted between the two calls stat will fail and the
  whole precedure will fail. Change this behavior to continue with the
  next entry if stat() fails because of nonexistent file. This is
  transparent change as it will make it look as if the file was deleted
  before the readdir() call.

  This change is needed in order to fix
  https://svn.innodb.com/mantis/view.php?id=174
  in which we need to abort if os_file_readdir_next_file()
  encounters "real" errors.

  Approved by:	Marko, Pekka (rb://177)

  ------------------------------------------------------------------------
  r6049 | vasil | 2009-10-10 03:05:26 +1100 (Sat, 10 Oct 2009) | 7 lines

  branches/zip:

  Fix compilation warning in Hot Backup:

  innodb/fil/fil0fil.c: In function 'fil_load_single_table_tablespace':
  innodb/fil/fil0fil.c:3253: warning: format '%lld' expects type 'long long int', but argument 6 has type 'ib_int64_t'

  ------------------------------------------------------------------------
  r6064 | calvin | 2009-10-14 02:23:35 +1100 (Wed, 14 Oct 2009) | 4 lines

  branches/zip: non-functional changes

  Changes from MySQL to fix build issue.

  ------------------------------------------------------------------------
  r6065 | inaam | 2009-10-14 04:43:13 +1100 (Wed, 14 Oct 2009) | 7 lines

  branches/zip rb://182

  Call fsync() on datafiles after a batch of pages is written to disk
  even when skip_innodb_doublewrite is set.

  Approved by: Heikki

  ------------------------------------------------------------------------
  r6080 | sunny | 2009-10-15 09:29:01 +1100 (Thu, 15 Oct 2009) | 3 lines

  branches/zip: Change page_mem_alloc_free() to inline.
  Fix Bug #47058 - Failure to compile innodb_plugin on solaris 10u7 + spro cc/CC 5.10

  ------------------------------------------------------------------------
  r6084 | vasil | 2009-10-15 16:21:17 +1100 (Thu, 15 Oct 2009) | 4 lines

  branches/zip:

  Add ChangeLog entry for r6080.

  ------------------------------------------------------------------------
  r6095 | vasil | 2009-10-20 00:04:59 +1100 (Tue, 20 Oct 2009) | 7 lines

  branches/zip:

  Fix Bug#47808 innodb_information_schema.test fails when run under valgrind 

  by using the wait_until_rows_count macro that loops until the number of
  rows becomes 14 instead of sleep 0.1, which is obviously very fragile.

  ------------------------------------------------------------------------
  r6096 | vasil | 2009-10-20 00:06:09 +1100 (Tue, 20 Oct 2009) | 4 lines

  branches/zip:

  Add ChangeLog entry for r6095.

  ------------------------------------------------------------------------
  r6099 | jyang | 2009-10-22 13:58:39 +1100 (Thu, 22 Oct 2009) | 7 lines

  branches/zip: Port bug #46000 related changes from 5.1 to zip
  branch. Due to different code path for creating index in zip
  branch comparing to 5.1), the index reserved name check function
  is extended to be used in ha_innobase::add_index(). 
  rb://190  Approved by: Marko


  ------------------------------------------------------------------------
  r6100 | jyang | 2009-10-22 14:51:07 +1100 (Thu, 22 Oct 2009) | 6 lines

  branches/zip: As a request from mysql, WARN_LEVEL_ERROR cannot
  be used for push_warning_* call any more. Switch to 
  WARN_LEVEL_WARN. Bug #47233.
  rb://172 approved by Sunny Bains and Marko.


  ------------------------------------------------------------------------
  r6101 | jyang | 2009-10-23 19:45:50 +1100 (Fri, 23 Oct 2009) | 7 lines
    
  branches/zip: Update test result with the WARN_LEVEL_ERROR
  to WARN_LEVEL_WARN change. This is the same result as 
  submitted in rb://172 review, which approved by Sunny Bains
  and Marko.

  ------------------------------------------------------------------------
  r6102 | marko | 2009-10-26 18:32:23 +1100 (Mon, 26 Oct 2009) | 1 line

  branches/zip: row_prebuilt_struct::prebuilts: Unused field, remove.
  ------------------------------------------------------------------------
  r6103 | marko | 2009-10-27 00:46:18 +1100 (Tue, 27 Oct 2009) | 4 lines

  branches/zip: row_ins_alloc_sys_fields(): Zero out the system columns
  DB_TRX_ID, DB_ROLL_PTR and DB_ROW_ID, in order to avoid harmless
  Valgrind warnings about uninitialized data.  (The warnings were
  harmless, because the fields would be initialized at a later stage.)
  ------------------------------------------------------------------------
  r6105 | calvin | 2009-10-28 09:05:52 +1100 (Wed, 28 Oct 2009) | 6 lines

  branches/zip: backport r3848 from 6.0 branch

  ----
      branches/6.0: innobase_start_or_create_for_mysql(): Make the 10 MB
      minimum tablespace limit independent of UNIV_PAGE_SIZE. (Bug #41490)

  ------------------------------------------------------------------------
  r6107 | marko | 2009-10-29 01:10:34 +1100 (Thu, 29 Oct 2009) | 5 lines

  branches/zip: buf_page_set_old(): Improve UNIV_LRU_DEBUG diagnostics
  in order to catch the buf_pool->LRU_old corruption reported in Issue #381.

  buf_LRU_old_init(): Set the property from the tail towards the front
  of the buf_pool->LRU list, in order not to trip the debug check.
  ------------------------------------------------------------------------
  r6108 | calvin | 2009-10-29 16:58:04 +1100 (Thu, 29 Oct 2009) | 5 lines

  branches/zip: close file handle when building with UNIV_HOTBACKUP

  The change does not affect regular InnoDB engine. Confirmed by
  Marko.

  ------------------------------------------------------------------------
  r6109 | jyang | 2009-10-29 19:37:32 +1100 (Thu, 29 Oct 2009) | 7 lines

  branches/zip: In os_mem_alloc_large(), if we fail to attach
  the shared memory, reset memory pointer ptr to NULL, and
   allocate memory from conventional pool.
  Bug #48237 Error handling in os_mem_alloc_large appears to be incorrect
  rb://198  Approved by: Marko


  ------------------------------------------------------------------------
  r6110 | marko | 2009-10-29 21:44:57 +1100 (Thu, 29 Oct 2009) | 2 lines

  branches/zip: Makefile.am (INCLUDES): Merge a change from MySQL:
  Use $(srcdir)/include instead of $(top_srcdir)/storage/innobase/include.
  ------------------------------------------------------------------------
  r6111 | marko | 2009-10-29 22:04:11 +1100 (Thu, 29 Oct 2009) | 33 lines

  branches/zip: Fix corruption of buf_pool->LRU_old and improve debug assertions.
  This was reported as Issue #381.

  buf_page_set_old(): Assert that blocks may only be set old if
  buf_pool->LRU_old is initialized and buf_pool->LRU_old_len is nonzero.
  Assert that buf_pool->LRU_old points to the block at the old/new boundary.

  buf_LRU_old_adjust_len(): Invoke buf_page_set_old() after adjusting
  buf_pool->LRU_old and buf_pool->LRU_old_len, in order not to violate
  the added assertions.

  buf_LRU_old_init(): Replace buf_page_set_old() with a direct
  assignment to bpage->old, because these loops that initialize all the
  blocks would temporarily violate the assertions about
  buf_pool->LRU_old.

  buf_LRU_remove_block(): When setting buf_pool->LRU_old = NULL, also
  clear all bpage->old flags and set buf_pool->LRU_old_len = 0.

  buf_LRU_add_block_to_end_low(), buf_LRU_add_block_low(): Move the
  buf_page_set_old() call later in order not to violate the debug
  assertions.  If buf_pool->LRU_old is NULL, set old=FALSE.

  buf_LRU_free_block(): Replace the UNIV_LRU_DEBUG assertion with a
  dummy buf_page_set_old() call that performs more thorough checks.

  buf_LRU_validate(): Do not tolerate garbage in buf_pool->LRU_old_len
  even if buf_pool->LRU_old is NULL.  Check that bpage->old is monotonic.

  buf_relocate(): Make the UNIV_LRU_DEBUG checks stricter.

  buf0buf.h: Revise the documentation of buf_page_t::old and
  buf_pool_t::LRU_old_len.
  ------------------------------------------------------------------------
  r6112 | calvin | 2009-10-30 01:21:15 +1100 (Fri, 30 Oct 2009) | 4 lines

  branches/zip: consideration for icc compilers

  Proposed by MySQL, and approved by Marko.

  ------------------------------------------------------------------------
  r6113 | vasil | 2009-10-30 03:15:50 +1100 (Fri, 30 Oct 2009) | 93 lines

  branches/zip: Merge r5912:6112 from branches/5.1:

  (after this merge the innodb-autoinc test starts to fail, but
  I commit anyway because it would be easier to investigate the
  failure this way)

    ------------------------------------------------------------------------
    r5952 | calvin | 2009-09-22 19:45:07 +0300 (Tue, 22 Sep 2009) | 7 lines
    Changed paths:
       M /branches/5.1/handler/ha_innodb.cc
    
    branches/5.1: fix bug#42383: Can't create table 'test.bug39438'
    
    For embedded server, MySQL may pass in full path, which is
    currently disallowed. It is needed to relax the condition by
    accepting full paths in the embedded case.
    
    Approved by: Heikki (on IM)
    ------------------------------------------------------------------------
    r6032 | vasil | 2009-10-01 15:55:49 +0300 (Thu, 01 Oct 2009) | 8 lines
    Changed paths:
       M /branches/5.1/handler/ha_innodb.cc
    
    branches/5.1:
    
    Fix Bug#38996 Race condition in ANALYZE TABLE
    
    by serializing ANALYZE TABLE inside InnoDB.
    
    Approved by:	Heikki (rb://175)
    
    ------------------------------------------------------------------------
    r6045 | jyang | 2009-10-08 02:27:08 +0300 (Thu, 08 Oct 2009) | 7 lines
    Changed paths:
       M /branches/5.1/handler/ha_innodb.cc
       A /branches/5.1/mysql-test/innodb_bug47777.result
       A /branches/5.1/mysql-test/innodb_bug47777.test
    
    branches/5.1: Fix bug #47777. Treat the Geometry data same as
    Binary BLOB in ha_innobase::store_key_val_for_row(), since the
    Geometry data is stored as Binary BLOB in Innodb.
    
    Review: rb://180 approved by Marko Makela.
    
    
      ------------------------------------------------------------------------
    r6051 | sunny | 2009-10-12 07:05:00 +0300 (Mon, 12 Oct 2009) | 6 lines
    Changed paths:
       M /branches/5.1/handler/ha_innodb.cc
       M /branches/5.1/mysql-test/innodb-autoinc.result
       M /branches/5.1/mysql-test/innodb-autoinc.test
    
    branches/5.1: Ignore negative values supplied by the user when calculating the
    next value to store in dict_table_t. Setting autoincrement columns top negative
    values is undefined behavior and this change should bring the behavior of
    InnoDB closer to what users expect. Added several tests to check.
    rb://162
    
    ------------------------------------------------------------------------
    r6052 | sunny | 2009-10-12 07:09:56 +0300 (Mon, 12 Oct 2009) | 4 lines
    Changed paths:
       M /branches/5.1/handler/ha_innodb.cc
       M /branches/5.1/mysql-test/innodb-autoinc.result
       M /branches/5.1/mysql-test/innodb-autoinc.test
    
    branches/5.1: Reset the statement level autoinc counter on ROLLBACK. Fix
    the test results too.
    rb://164
    
    ------------------------------------------------------------------------
    r6053 | sunny | 2009-10-12 07:37:49 +0300 (Mon, 12 Oct 2009) | 6 lines
    Changed paths:
       M /branches/5.1/handler/ha_innodb.cc
       M /branches/5.1/mysql-test/innodb-autoinc.result
       M /branches/5.1/mysql-test/innodb-autoinc.test
    
    branches/5.1: Copy the maximum AUTOINC value from the old table to the new
    table when MySQL does a CREATE INDEX ON T. This is required because MySQL
    does a table copy, rename and drops the old table.
    Fix Bug#47125: auto_increment start value is ignored if an index is created and engine=innodb
    rb://168
    
    ------------------------------------------------------------------------
    r6076 | vasil | 2009-10-14 19:30:12 +0300 (Wed, 14 Oct 2009) | 4 lines
    Changed paths:
       M /branches/5.1/row/row0mysql.c
    
    branches/5.1:
      
  Fix typo.
      
    ------------------------------------------------------------------------

  ------------------------------------------------------------------------
  r6114 | vasil | 2009-10-30 03:43:51 +1100 (Fri, 30 Oct 2009) | 6 lines

  branches/zip:

  * Add ChangeLog entries for latest changes
  * Obey alphabetical order in the list of the files
  * White-space fixup

  ------------------------------------------------------------------------
  r6121 | sunny | 2009-10-30 10:42:11 +1100 (Fri, 30 Oct 2009) | 7 lines

  branches/zip: This test has been problematic for sometime now. The underlying
  bug is that the data dictionaries get out of sync. In the AUTOINC code we
  try and apply salve to the symptoms. In the past MySQL made some unrelated
  change and the dictionaries stopped getting out of sync and this test started
  to fail. Now, it seems they have reverted that changed and the test is
  passing again. I suspect this is not he last time that this test will change.

  ------------------------------------------------------------------------
  r6124 | jyang | 2009-10-30 19:02:31 +1100 (Fri, 30 Oct 2009) | 5 lines

  branches/zip: Correct the bug number for -r6109 change
  from # 48273 to #48237



  ------------------------------------------------------------------------
  r6126 | vasil | 2009-10-30 19:36:07 +1100 (Fri, 30 Oct 2009) | 45 lines

  branches/zip: Merge r6112:6125 from branches/5.1:

  (skipping r6122 and r6123, Jimmy says these are already present and need
  not be merged):

    ------------------------------------------------------------------------
    r6122 | jyang | 2009-10-30 05:18:38 +0200 (Fri, 30 Oct 2009) | 7 lines
    Changed paths:
       M /branches/5.1/handler/ha_innodb.cc
       M /branches/5.1/mysql-test/innodb_bug44369.result
       M /branches/5.1/mysql-test/innodb_bug44369.test
       M /branches/5.1/mysql-test/innodb_bug46000.result
       M /branches/5.1/mysql-test/innodb_bug46000.test
    
    branches/5.1: Chnage WARN_LEVEL_ERROR to WARN_LEVEL_WARN
    for push_warning_printf() call in innodb.
    Fix Bug#47233: Innodb calls push_warning(MYSQL_ERROR::WARN_LEVEL_ERROR)
    
    rb://170 approved by Marko.
    
    
    ------------------------------------------------------------------------
    r6123 | jyang | 2009-10-30 05:43:06 +0200 (Fri, 30 Oct 2009) | 8 lines
    Changed paths:
       M /branches/5.1/os/os0proc.c
    
    branches/5.1: In os_mem_alloc_large(), if we fail to attach
    the shared memory, reset memory pointer ptr to NULL, and
    allocate memory from conventional pool. This is a port
    from branches/zip.
    Bug #48237 Error handling in os_mem_alloc_large appears to be incorrect
    rb://198  Approved by: Marko
    
    
    ------------------------------------------------------------------------
    r6125 | vasil | 2009-10-30 10:31:23 +0200 (Fri, 30 Oct 2009) | 4 lines
    Changed paths:
       M /branches/5.1/handler/ha_innodb.cc
    
    branches/5.1:
    
    White-space fixup.
    
    ------------------------------------------------------------------------

  ------------------------------------------------------------------------
  r6130 | marko | 2009-11-02 20:42:56 +1100 (Mon, 02 Nov 2009) | 9 lines

  branches/zip: Free all resources at shutdown. Set pointers to NULL, so
  that Valgrind will not complain about freed data structures that are
  reachable via pointers.  This addresses Bug #45992 and Bug #46656.

  This patch is mostly based on changes copied from branches/embedded-1.0,
  mainly c5432, c3439, c3134, c2994, c2978, but also some other code was
  copied.  Some added cleanup code is specific to MySQL/InnoDB.

  rb://199 approved by Sunny Bains
    ------------------------------------------------------------------------
2009-11-04 06:02:00 +00:00

1211 lines
30 KiB
C

/*****************************************************************************
Copyright (c) 1996, 2009, Innobase Oy. All Rights Reserved.
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place, Suite 330, Boston, MA 02111-1307 USA
*****************************************************************************/
/**************************************************//**
@file trx/trx0purge.c
Purge old versions
Created 3/26/1996 Heikki Tuuri
*******************************************************/
#include "trx0purge.h"
#ifdef UNIV_NONINL
#include "trx0purge.ic"
#endif
#include "fsp0fsp.h"
#include "mach0data.h"
#include "mtr0log.h"
#include "trx0rseg.h"
#include "trx0trx.h"
#include "trx0roll.h"
#include "read0read.h"
#include "fut0fut.h"
#include "que0que.h"
#include "row0purge.h"
#include "row0upd.h"
#include "trx0rec.h"
#include "srv0que.h"
#include "os0thread.h"
/** The global data structure coordinating a purge */
UNIV_INTERN trx_purge_t* purge_sys = NULL;
/** A dummy undo record used as a return value when we have a whole undo log
which needs no purge */
UNIV_INTERN trx_undo_rec_t trx_purge_dummy_rec;
/*****************************************************************//**
Checks if trx_id is >= purge_view: then it is guaranteed that its update
undo log still exists in the system.
@return TRUE if is sure that it is preserved, also if the function
returns FALSE, it is possible that the undo log still exists in the
system */
UNIV_INTERN
ibool
trx_purge_update_undo_must_exist(
/*=============================*/
trx_id_t trx_id) /*!< in: transaction id */
{
#ifdef UNIV_SYNC_DEBUG
ut_ad(rw_lock_own(&(purge_sys->latch), RW_LOCK_SHARED));
#endif /* UNIV_SYNC_DEBUG */
if (!read_view_sees_trx_id(purge_sys->view, trx_id)) {
return(TRUE);
}
return(FALSE);
}
/*=================== PURGE RECORD ARRAY =============================*/
/*******************************************************************//**
Stores info of an undo log record during a purge.
@return pointer to the storage cell */
static
trx_undo_inf_t*
trx_purge_arr_store_info(
/*=====================*/
trx_id_t trx_no, /*!< in: transaction number */
undo_no_t undo_no)/*!< in: undo number */
{
trx_undo_inf_t* cell;
trx_undo_arr_t* arr;
ulint i;
arr = purge_sys->arr;
for (i = 0;; i++) {
cell = trx_undo_arr_get_nth_info(arr, i);
if (!(cell->in_use)) {
/* Not in use, we may store here */
cell->undo_no = undo_no;
cell->trx_no = trx_no;
cell->in_use = TRUE;
arr->n_used++;
return(cell);
}
}
}
/*******************************************************************//**
Removes info of an undo log record during a purge. */
UNIV_INLINE
void
trx_purge_arr_remove_info(
/*======================*/
trx_undo_inf_t* cell) /*!< in: pointer to the storage cell */
{
trx_undo_arr_t* arr;
arr = purge_sys->arr;
cell->in_use = FALSE;
ut_ad(arr->n_used > 0);
arr->n_used--;
}
/*******************************************************************//**
Gets the biggest pair of a trx number and an undo number in a purge array. */
static
void
trx_purge_arr_get_biggest(
/*======================*/
trx_undo_arr_t* arr, /*!< in: purge array */
trx_id_t* trx_no, /*!< out: transaction number: ut_dulint_zero
if array is empty */
undo_no_t* undo_no)/*!< out: undo number */
{
trx_undo_inf_t* cell;
trx_id_t pair_trx_no;
undo_no_t pair_undo_no;
int trx_cmp;
ulint n_used;
ulint i;
ulint n;
n = 0;
n_used = arr->n_used;
pair_trx_no = ut_dulint_zero;
pair_undo_no = ut_dulint_zero;
for (i = 0;; i++) {
cell = trx_undo_arr_get_nth_info(arr, i);
if (cell->in_use) {
n++;
trx_cmp = ut_dulint_cmp(cell->trx_no, pair_trx_no);
if ((trx_cmp > 0)
|| ((trx_cmp == 0)
&& (ut_dulint_cmp(cell->undo_no,
pair_undo_no) >= 0))) {
pair_trx_no = cell->trx_no;
pair_undo_no = cell->undo_no;
}
}
if (n == n_used) {
*trx_no = pair_trx_no;
*undo_no = pair_undo_no;
return;
}
}
}
/****************************************************************//**
Builds a purge 'query' graph. The actual purge is performed by executing
this query graph.
@return own: the query graph */
static
que_t*
trx_purge_graph_build(void)
/*=======================*/
{
mem_heap_t* heap;
que_fork_t* fork;
que_thr_t* thr;
/* que_thr_t* thr2; */
heap = mem_heap_create(512);
fork = que_fork_create(NULL, NULL, QUE_FORK_PURGE, heap);
fork->trx = purge_sys->trx;
thr = que_thr_create(fork, heap);
thr->child = row_purge_node_create(thr, heap);
/* thr2 = que_thr_create(fork, fork, heap);
thr2->child = row_purge_node_create(fork, thr2, heap); */
return(fork);
}
/********************************************************************//**
Creates the global purge system control structure and inits the history
mutex. */
UNIV_INTERN
void
trx_purge_sys_create(void)
/*======================*/
{
ut_ad(mutex_own(&kernel_mutex));
purge_sys = mem_alloc(sizeof(trx_purge_t));
purge_sys->state = TRX_STOP_PURGE;
purge_sys->n_pages_handled = 0;
purge_sys->purge_trx_no = ut_dulint_zero;
purge_sys->purge_undo_no = ut_dulint_zero;
purge_sys->next_stored = FALSE;
rw_lock_create(&purge_sys->latch, SYNC_PURGE_LATCH);
mutex_create(&purge_sys->mutex, SYNC_PURGE_SYS);
purge_sys->heap = mem_heap_create(256);
purge_sys->arr = trx_undo_arr_create();
purge_sys->sess = sess_open();
purge_sys->trx = purge_sys->sess->trx;
purge_sys->trx->is_purge = 1;
ut_a(trx_start_low(purge_sys->trx, ULINT_UNDEFINED));
purge_sys->query = trx_purge_graph_build();
purge_sys->view = read_view_oldest_copy_or_open_new(ut_dulint_zero,
purge_sys->heap);
}
/************************************************************************
Frees the global purge system control structure. */
UNIV_INTERN
void
trx_purge_sys_close(void)
/*======================*/
{
ut_ad(!mutex_own(&kernel_mutex));
que_graph_free(purge_sys->query);
ut_a(purge_sys->sess->trx->is_purge);
purge_sys->sess->trx->conc_state = TRX_NOT_STARTED;
sess_close(purge_sys->sess);
purge_sys->sess = NULL;
if (purge_sys->view != NULL) {
/* Because acquiring the kernel mutex is a pre-condition
of read_view_close(). We don't really need it here. */
mutex_enter(&kernel_mutex);
read_view_close(purge_sys->view);
purge_sys->view = NULL;
mutex_exit(&kernel_mutex);
}
trx_undo_arr_free(purge_sys->arr);
rw_lock_free(&purge_sys->latch);
mutex_free(&purge_sys->mutex);
mem_heap_free(purge_sys->heap);
mem_free(purge_sys);
purge_sys = NULL;
}
/*================ UNDO LOG HISTORY LIST =============================*/
/********************************************************************//**
Adds the update undo log as the first log in the history list. Removes the
update undo log segment from the rseg slot if it is too big for reuse. */
UNIV_INTERN
void
trx_purge_add_update_undo_to_history(
/*=================================*/
trx_t* trx, /*!< in: transaction */
page_t* undo_page, /*!< in: update undo log header page,
x-latched */
mtr_t* mtr) /*!< in: mtr */
{
trx_undo_t* undo;
trx_rseg_t* rseg;
trx_rsegf_t* rseg_header;
trx_usegf_t* seg_header;
trx_ulogf_t* undo_header;
trx_upagef_t* page_header;
ulint hist_size;
undo = trx->update_undo;
ut_ad(undo);
rseg = undo->rseg;
ut_ad(mutex_own(&(rseg->mutex)));
rseg_header = trx_rsegf_get(rseg->space, rseg->zip_size,
rseg->page_no, mtr);
undo_header = undo_page + undo->hdr_offset;
seg_header = undo_page + TRX_UNDO_SEG_HDR;
page_header = undo_page + TRX_UNDO_PAGE_HDR;
if (undo->state != TRX_UNDO_CACHED) {
/* The undo log segment will not be reused */
if (undo->id >= TRX_RSEG_N_SLOTS) {
fprintf(stderr,
"InnoDB: Error: undo->id is %lu\n",
(ulong) undo->id);
ut_error;
}
trx_rsegf_set_nth_undo(rseg_header, undo->id, FIL_NULL, mtr);
hist_size = mtr_read_ulint(rseg_header + TRX_RSEG_HISTORY_SIZE,
MLOG_4BYTES, mtr);
ut_ad(undo->size == flst_get_len(
seg_header + TRX_UNDO_PAGE_LIST, mtr));
mlog_write_ulint(rseg_header + TRX_RSEG_HISTORY_SIZE,
hist_size + undo->size, MLOG_4BYTES, mtr);
}
/* Add the log as the first in the history list */
flst_add_first(rseg_header + TRX_RSEG_HISTORY,
undo_header + TRX_UNDO_HISTORY_NODE, mtr);
mutex_enter(&kernel_mutex);
trx_sys->rseg_history_len++;
mutex_exit(&kernel_mutex);
/* Write the trx number to the undo log header */
mlog_write_dulint(undo_header + TRX_UNDO_TRX_NO, trx->no, mtr);
/* Write information about delete markings to the undo log header */
if (!undo->del_marks) {
mlog_write_ulint(undo_header + TRX_UNDO_DEL_MARKS, FALSE,
MLOG_2BYTES, mtr);
}
if (rseg->last_page_no == FIL_NULL) {
rseg->last_page_no = undo->hdr_page_no;
rseg->last_offset = undo->hdr_offset;
rseg->last_trx_no = trx->no;
rseg->last_del_marks = undo->del_marks;
}
}
/**********************************************************************//**
Frees an undo log segment which is in the history list. Cuts the end of the
history list at the youngest undo log in this segment. */
static
void
trx_purge_free_segment(
/*===================*/
trx_rseg_t* rseg, /*!< in: rollback segment */
fil_addr_t hdr_addr, /*!< in: the file address of log_hdr */
ulint n_removed_logs) /*!< in: count of how many undo logs we
will cut off from the end of the
history list */
{
page_t* undo_page;
trx_rsegf_t* rseg_hdr;
trx_ulogf_t* log_hdr;
trx_usegf_t* seg_hdr;
ibool freed;
ulint seg_size;
ulint hist_size;
ibool marked = FALSE;
mtr_t mtr;
/* fputs("Freeing an update undo log segment\n", stderr); */
ut_ad(mutex_own(&(purge_sys->mutex)));
loop:
mtr_start(&mtr);
mutex_enter(&(rseg->mutex));
rseg_hdr = trx_rsegf_get(rseg->space, rseg->zip_size,
rseg->page_no, &mtr);
undo_page = trx_undo_page_get(rseg->space, rseg->zip_size,
hdr_addr.page, &mtr);
seg_hdr = undo_page + TRX_UNDO_SEG_HDR;
log_hdr = undo_page + hdr_addr.boffset;
/* Mark the last undo log totally purged, so that if the system
crashes, the tail of the undo log will not get accessed again. The
list of pages in the undo log tail gets inconsistent during the
freeing of the segment, and therefore purge should not try to access
them again. */
if (!marked) {
mlog_write_ulint(log_hdr + TRX_UNDO_DEL_MARKS, FALSE,
MLOG_2BYTES, &mtr);
marked = TRUE;
}
freed = fseg_free_step_not_header(seg_hdr + TRX_UNDO_FSEG_HEADER,
&mtr);
if (!freed) {
mutex_exit(&(rseg->mutex));
mtr_commit(&mtr);
goto loop;
}
/* The page list may now be inconsistent, but the length field
stored in the list base node tells us how big it was before we
started the freeing. */
seg_size = flst_get_len(seg_hdr + TRX_UNDO_PAGE_LIST, &mtr);
/* We may free the undo log segment header page; it must be freed
within the same mtr as the undo log header is removed from the
history list: otherwise, in case of a database crash, the segment
could become inaccessible garbage in the file space. */
flst_cut_end(rseg_hdr + TRX_RSEG_HISTORY,
log_hdr + TRX_UNDO_HISTORY_NODE, n_removed_logs, &mtr);
mutex_enter(&kernel_mutex);
ut_ad(trx_sys->rseg_history_len >= n_removed_logs);
trx_sys->rseg_history_len -= n_removed_logs;
mutex_exit(&kernel_mutex);
freed = FALSE;
while (!freed) {
/* Here we assume that a file segment with just the header
page can be freed in a few steps, so that the buffer pool
is not flooded with bufferfixed pages: see the note in
fsp0fsp.c. */
freed = fseg_free_step(seg_hdr + TRX_UNDO_FSEG_HEADER,
&mtr);
}
hist_size = mtr_read_ulint(rseg_hdr + TRX_RSEG_HISTORY_SIZE,
MLOG_4BYTES, &mtr);
ut_ad(hist_size >= seg_size);
mlog_write_ulint(rseg_hdr + TRX_RSEG_HISTORY_SIZE,
hist_size - seg_size, MLOG_4BYTES, &mtr);
ut_ad(rseg->curr_size >= seg_size);
rseg->curr_size -= seg_size;
mutex_exit(&(rseg->mutex));
mtr_commit(&mtr);
}
/********************************************************************//**
Removes unnecessary history data from a rollback segment. */
static
void
trx_purge_truncate_rseg_history(
/*============================*/
trx_rseg_t* rseg, /*!< in: rollback segment */
trx_id_t limit_trx_no, /*!< in: remove update undo logs whose
trx number is < limit_trx_no */
undo_no_t limit_undo_no) /*!< in: if transaction number is equal
to limit_trx_no, truncate undo records
with undo number < limit_undo_no */
{
fil_addr_t hdr_addr;
fil_addr_t prev_hdr_addr;
trx_rsegf_t* rseg_hdr;
page_t* undo_page;
trx_ulogf_t* log_hdr;
trx_usegf_t* seg_hdr;
int cmp;
ulint n_removed_logs = 0;
mtr_t mtr;
ut_ad(mutex_own(&(purge_sys->mutex)));
mtr_start(&mtr);
mutex_enter(&(rseg->mutex));
rseg_hdr = trx_rsegf_get(rseg->space, rseg->zip_size,
rseg->page_no, &mtr);
hdr_addr = trx_purge_get_log_from_hist(
flst_get_last(rseg_hdr + TRX_RSEG_HISTORY, &mtr));
loop:
if (hdr_addr.page == FIL_NULL) {
mutex_exit(&(rseg->mutex));
mtr_commit(&mtr);
return;
}
undo_page = trx_undo_page_get(rseg->space, rseg->zip_size,
hdr_addr.page, &mtr);
log_hdr = undo_page + hdr_addr.boffset;
cmp = ut_dulint_cmp(mach_read_from_8(log_hdr + TRX_UNDO_TRX_NO),
limit_trx_no);
if (cmp == 0) {
trx_undo_truncate_start(rseg, rseg->space, hdr_addr.page,
hdr_addr.boffset, limit_undo_no);
}
if (cmp >= 0) {
mutex_enter(&kernel_mutex);
ut_a(trx_sys->rseg_history_len >= n_removed_logs);
trx_sys->rseg_history_len -= n_removed_logs;
mutex_exit(&kernel_mutex);
flst_truncate_end(rseg_hdr + TRX_RSEG_HISTORY,
log_hdr + TRX_UNDO_HISTORY_NODE,
n_removed_logs, &mtr);
mutex_exit(&(rseg->mutex));
mtr_commit(&mtr);
return;
}
prev_hdr_addr = trx_purge_get_log_from_hist(
flst_get_prev_addr(log_hdr + TRX_UNDO_HISTORY_NODE, &mtr));
n_removed_logs++;
seg_hdr = undo_page + TRX_UNDO_SEG_HDR;
if ((mach_read_from_2(seg_hdr + TRX_UNDO_STATE) == TRX_UNDO_TO_PURGE)
&& (mach_read_from_2(log_hdr + TRX_UNDO_NEXT_LOG) == 0)) {
/* We can free the whole log segment */
mutex_exit(&(rseg->mutex));
mtr_commit(&mtr);
trx_purge_free_segment(rseg, hdr_addr, n_removed_logs);
n_removed_logs = 0;
} else {
mutex_exit(&(rseg->mutex));
mtr_commit(&mtr);
}
mtr_start(&mtr);
mutex_enter(&(rseg->mutex));
rseg_hdr = trx_rsegf_get(rseg->space, rseg->zip_size,
rseg->page_no, &mtr);
hdr_addr = prev_hdr_addr;
goto loop;
}
/********************************************************************//**
Removes unnecessary history data from rollback segments. NOTE that when this
function is called, the caller must not have any latches on undo log pages! */
static
void
trx_purge_truncate_history(void)
/*============================*/
{
trx_rseg_t* rseg;
trx_id_t limit_trx_no;
undo_no_t limit_undo_no;
ut_ad(mutex_own(&(purge_sys->mutex)));
trx_purge_arr_get_biggest(purge_sys->arr, &limit_trx_no,
&limit_undo_no);
if (ut_dulint_is_zero(limit_trx_no)) {
limit_trx_no = purge_sys->purge_trx_no;
limit_undo_no = purge_sys->purge_undo_no;
}
/* We play safe and set the truncate limit at most to the purge view
low_limit number, though this is not necessary */
if (ut_dulint_cmp(limit_trx_no, purge_sys->view->low_limit_no) >= 0) {
limit_trx_no = purge_sys->view->low_limit_no;
limit_undo_no = ut_dulint_zero;
}
ut_ad((ut_dulint_cmp(limit_trx_no,
purge_sys->view->low_limit_no) <= 0));
rseg = UT_LIST_GET_FIRST(trx_sys->rseg_list);
while (rseg) {
trx_purge_truncate_rseg_history(rseg, limit_trx_no,
limit_undo_no);
rseg = UT_LIST_GET_NEXT(rseg_list, rseg);
}
}
/********************************************************************//**
Does a truncate if the purge array is empty. NOTE that when this function is
called, the caller must not have any latches on undo log pages!
@return TRUE if array empty */
UNIV_INLINE
ibool
trx_purge_truncate_if_arr_empty(void)
/*=================================*/
{
ut_ad(mutex_own(&(purge_sys->mutex)));
if (purge_sys->arr->n_used == 0) {
trx_purge_truncate_history();
return(TRUE);
}
return(FALSE);
}
/***********************************************************************//**
Updates the last not yet purged history log info in rseg when we have purged
a whole undo log. Advances also purge_sys->purge_trx_no past the purged log. */
static
void
trx_purge_rseg_get_next_history_log(
/*================================*/
trx_rseg_t* rseg) /*!< in: rollback segment */
{
page_t* undo_page;
trx_ulogf_t* log_hdr;
trx_usegf_t* seg_hdr;
fil_addr_t prev_log_addr;
trx_id_t trx_no;
ibool del_marks;
mtr_t mtr;
ut_ad(mutex_own(&(purge_sys->mutex)));
mutex_enter(&(rseg->mutex));
ut_a(rseg->last_page_no != FIL_NULL);
purge_sys->purge_trx_no = ut_dulint_add(rseg->last_trx_no, 1);
purge_sys->purge_undo_no = ut_dulint_zero;
purge_sys->next_stored = FALSE;
mtr_start(&mtr);
undo_page = trx_undo_page_get_s_latched(rseg->space, rseg->zip_size,
rseg->last_page_no, &mtr);
log_hdr = undo_page + rseg->last_offset;
seg_hdr = undo_page + TRX_UNDO_SEG_HDR;
/* Increase the purge page count by one for every handled log */
purge_sys->n_pages_handled++;
prev_log_addr = trx_purge_get_log_from_hist(
flst_get_prev_addr(log_hdr + TRX_UNDO_HISTORY_NODE, &mtr));
if (prev_log_addr.page == FIL_NULL) {
/* No logs left in the history list */
rseg->last_page_no = FIL_NULL;
mutex_exit(&(rseg->mutex));
mtr_commit(&mtr);
mutex_enter(&kernel_mutex);
/* Add debug code to track history list corruption reported
on the MySQL mailing list on Nov 9, 2004. The fut0lst.c
file-based list was corrupt. The prev node pointer was
FIL_NULL, even though the list length was over 8 million nodes!
We assume that purge truncates the history list in moderate
size pieces, and if we here reach the head of the list, the
list cannot be longer than 20 000 undo logs now. */
if (trx_sys->rseg_history_len > 20000) {
ut_print_timestamp(stderr);
fprintf(stderr,
" InnoDB: Warning: purge reached the"
" head of the history list,\n"
"InnoDB: but its length is still"
" reported as %lu! Make a detailed bug\n"
"InnoDB: report, and submit it"
" to http://bugs.mysql.com\n",
(ulong) trx_sys->rseg_history_len);
}
mutex_exit(&kernel_mutex);
return;
}
mutex_exit(&(rseg->mutex));
mtr_commit(&mtr);
/* Read the trx number and del marks from the previous log header */
mtr_start(&mtr);
log_hdr = trx_undo_page_get_s_latched(rseg->space, rseg->zip_size,
prev_log_addr.page, &mtr)
+ prev_log_addr.boffset;
trx_no = mach_read_from_8(log_hdr + TRX_UNDO_TRX_NO);
del_marks = mach_read_from_2(log_hdr + TRX_UNDO_DEL_MARKS);
mtr_commit(&mtr);
mutex_enter(&(rseg->mutex));
rseg->last_page_no = prev_log_addr.page;
rseg->last_offset = prev_log_addr.boffset;
rseg->last_trx_no = trx_no;
rseg->last_del_marks = del_marks;
mutex_exit(&(rseg->mutex));
}
/***********************************************************************//**
Chooses the next undo log to purge and updates the info in purge_sys. This
function is used to initialize purge_sys when the next record to purge is
not known, and also to update the purge system info on the next record when
purge has handled the whole undo log for a transaction. */
static
void
trx_purge_choose_next_log(void)
/*===========================*/
{
trx_undo_rec_t* rec;
trx_rseg_t* rseg;
trx_rseg_t* min_rseg;
trx_id_t min_trx_no;
ulint space = 0; /* remove warning (??? bug ???) */
ulint zip_size = 0;
ulint page_no = 0; /* remove warning (??? bug ???) */
ulint offset = 0; /* remove warning (??? bug ???) */
mtr_t mtr;
ut_ad(mutex_own(&(purge_sys->mutex)));
ut_ad(purge_sys->next_stored == FALSE);
rseg = UT_LIST_GET_FIRST(trx_sys->rseg_list);
min_trx_no = ut_dulint_max;
min_rseg = NULL;
while (rseg) {
mutex_enter(&(rseg->mutex));
if (rseg->last_page_no != FIL_NULL) {
if ((min_rseg == NULL)
|| (ut_dulint_cmp(min_trx_no,
rseg->last_trx_no) > 0)) {
min_rseg = rseg;
min_trx_no = rseg->last_trx_no;
space = rseg->space;
zip_size = rseg->zip_size;
ut_a(space == 0); /* We assume in purge of
externally stored fields
that space id == 0 */
page_no = rseg->last_page_no;
offset = rseg->last_offset;
}
}
mutex_exit(&(rseg->mutex));
rseg = UT_LIST_GET_NEXT(rseg_list, rseg);
}
if (min_rseg == NULL) {
return;
}
mtr_start(&mtr);
if (!min_rseg->last_del_marks) {
/* No need to purge this log */
rec = &trx_purge_dummy_rec;
} else {
rec = trx_undo_get_first_rec(space, zip_size, page_no, offset,
RW_S_LATCH, &mtr);
if (rec == NULL) {
/* Undo log empty */
rec = &trx_purge_dummy_rec;
}
}
purge_sys->next_stored = TRUE;
purge_sys->rseg = min_rseg;
purge_sys->hdr_page_no = page_no;
purge_sys->hdr_offset = offset;
purge_sys->purge_trx_no = min_trx_no;
if (rec == &trx_purge_dummy_rec) {
purge_sys->purge_undo_no = ut_dulint_zero;
purge_sys->page_no = page_no;
purge_sys->offset = 0;
} else {
purge_sys->purge_undo_no = trx_undo_rec_get_undo_no(rec);
purge_sys->page_no = page_get_page_no(page_align(rec));
purge_sys->offset = page_offset(rec);
}
mtr_commit(&mtr);
}
/***********************************************************************//**
Gets the next record to purge and updates the info in the purge system.
@return copy of an undo log record or pointer to the dummy undo log record */
static
trx_undo_rec_t*
trx_purge_get_next_rec(
/*===================*/
mem_heap_t* heap) /*!< in: memory heap where copied */
{
trx_undo_rec_t* rec;
trx_undo_rec_t* rec_copy;
trx_undo_rec_t* rec2;
trx_undo_rec_t* next_rec;
page_t* undo_page;
page_t* page;
ulint offset;
ulint page_no;
ulint space;
ulint zip_size;
ulint type;
ulint cmpl_info;
mtr_t mtr;
ut_ad(mutex_own(&(purge_sys->mutex)));
ut_ad(purge_sys->next_stored);
space = purge_sys->rseg->space;
zip_size = purge_sys->rseg->zip_size;
page_no = purge_sys->page_no;
offset = purge_sys->offset;
if (offset == 0) {
/* It is the dummy undo log record, which means that there is
no need to purge this undo log */
trx_purge_rseg_get_next_history_log(purge_sys->rseg);
/* Look for the next undo log and record to purge */
trx_purge_choose_next_log();
return(&trx_purge_dummy_rec);
}
mtr_start(&mtr);
undo_page = trx_undo_page_get_s_latched(space, zip_size,
page_no, &mtr);
rec = undo_page + offset;
rec2 = rec;
for (;;) {
/* Try first to find the next record which requires a purge
operation from the same page of the same undo log */
next_rec = trx_undo_page_get_next_rec(rec2,
purge_sys->hdr_page_no,
purge_sys->hdr_offset);
if (next_rec == NULL) {
rec2 = trx_undo_get_next_rec(
rec2, purge_sys->hdr_page_no,
purge_sys->hdr_offset, &mtr);
break;
}
rec2 = next_rec;
type = trx_undo_rec_get_type(rec2);
if (type == TRX_UNDO_DEL_MARK_REC) {
break;
}
cmpl_info = trx_undo_rec_get_cmpl_info(rec2);
if (trx_undo_rec_get_extern_storage(rec2)) {
break;
}
if ((type == TRX_UNDO_UPD_EXIST_REC)
&& !(cmpl_info & UPD_NODE_NO_ORD_CHANGE)) {
break;
}
}
if (rec2 == NULL) {
mtr_commit(&mtr);
trx_purge_rseg_get_next_history_log(purge_sys->rseg);
/* Look for the next undo log and record to purge */
trx_purge_choose_next_log();
mtr_start(&mtr);
undo_page = trx_undo_page_get_s_latched(space, zip_size,
page_no, &mtr);
rec = undo_page + offset;
} else {
page = page_align(rec2);
purge_sys->purge_undo_no = trx_undo_rec_get_undo_no(rec2);
purge_sys->page_no = page_get_page_no(page);
purge_sys->offset = rec2 - page;
if (undo_page != page) {
/* We advance to a new page of the undo log: */
purge_sys->n_pages_handled++;
}
}
rec_copy = trx_undo_rec_copy(rec, heap);
mtr_commit(&mtr);
return(rec_copy);
}
/********************************************************************//**
Fetches the next undo log record from the history list to purge. It must be
released with the corresponding release function.
@return copy of an undo log record or pointer to trx_purge_dummy_rec,
if the whole undo log can skipped in purge; NULL if none left */
UNIV_INTERN
trx_undo_rec_t*
trx_purge_fetch_next_rec(
/*=====================*/
roll_ptr_t* roll_ptr,/*!< out: roll pointer to undo record */
trx_undo_inf_t** cell, /*!< out: storage cell for the record in the
purge array */
mem_heap_t* heap) /*!< in: memory heap where copied */
{
trx_undo_rec_t* undo_rec;
mutex_enter(&(purge_sys->mutex));
if (purge_sys->state == TRX_STOP_PURGE) {
trx_purge_truncate_if_arr_empty();
mutex_exit(&(purge_sys->mutex));
return(NULL);
}
if (!purge_sys->next_stored) {
trx_purge_choose_next_log();
if (!purge_sys->next_stored) {
purge_sys->state = TRX_STOP_PURGE;
trx_purge_truncate_if_arr_empty();
if (srv_print_thread_releases) {
fprintf(stderr,
"Purge: No logs left in the"
" history list; pages handled %lu\n",
(ulong) purge_sys->n_pages_handled);
}
mutex_exit(&(purge_sys->mutex));
return(NULL);
}
}
if (purge_sys->n_pages_handled >= purge_sys->handle_limit) {
purge_sys->state = TRX_STOP_PURGE;
trx_purge_truncate_if_arr_empty();
mutex_exit(&(purge_sys->mutex));
return(NULL);
}
if (ut_dulint_cmp(purge_sys->purge_trx_no,
purge_sys->view->low_limit_no) >= 0) {
purge_sys->state = TRX_STOP_PURGE;
trx_purge_truncate_if_arr_empty();
mutex_exit(&(purge_sys->mutex));
return(NULL);
}
/* fprintf(stderr, "Thread %lu purging trx %lu undo record %lu\n",
os_thread_get_curr_id(),
ut_dulint_get_low(purge_sys->purge_trx_no),
ut_dulint_get_low(purge_sys->purge_undo_no)); */
*roll_ptr = trx_undo_build_roll_ptr(FALSE, (purge_sys->rseg)->id,
purge_sys->page_no,
purge_sys->offset);
*cell = trx_purge_arr_store_info(purge_sys->purge_trx_no,
purge_sys->purge_undo_no);
ut_ad(ut_dulint_cmp(purge_sys->purge_trx_no,
(purge_sys->view)->low_limit_no) < 0);
/* The following call will advance the stored values of purge_trx_no
and purge_undo_no, therefore we had to store them first */
undo_rec = trx_purge_get_next_rec(heap);
mutex_exit(&(purge_sys->mutex));
return(undo_rec);
}
/*******************************************************************//**
Releases a reserved purge undo record. */
UNIV_INTERN
void
trx_purge_rec_release(
/*==================*/
trx_undo_inf_t* cell) /*!< in: storage cell */
{
trx_undo_arr_t* arr;
mutex_enter(&(purge_sys->mutex));
arr = purge_sys->arr;
trx_purge_arr_remove_info(cell);
mutex_exit(&(purge_sys->mutex));
}
/*******************************************************************//**
This function runs a purge batch.
@return number of undo log pages handled in the batch */
UNIV_INTERN
ulint
trx_purge(void)
/*===========*/
{
que_thr_t* thr;
/* que_thr_t* thr2; */
ulint old_pages_handled;
mutex_enter(&(purge_sys->mutex));
if (purge_sys->trx->n_active_thrs > 0) {
mutex_exit(&(purge_sys->mutex));
/* Should not happen */
ut_error;
return(0);
}
rw_lock_x_lock(&(purge_sys->latch));
mutex_enter(&kernel_mutex);
/* Close and free the old purge view */
read_view_close(purge_sys->view);
purge_sys->view = NULL;
mem_heap_empty(purge_sys->heap);
/* Determine how much data manipulation language (DML) statements
need to be delayed in order to reduce the lagging of the purge
thread. */
srv_dml_needed_delay = 0; /* in microseconds; default: no delay */
/* If we cannot advance the 'purge view' because of an old
'consistent read view', then the DML statements cannot be delayed.
Also, srv_max_purge_lag <= 0 means 'infinity'. */
if (srv_max_purge_lag > 0
&& !UT_LIST_GET_LAST(trx_sys->view_list)) {
float ratio = (float) trx_sys->rseg_history_len
/ srv_max_purge_lag;
if (ratio > ULINT_MAX / 10000) {
/* Avoid overflow: maximum delay is 4295 seconds */
srv_dml_needed_delay = ULINT_MAX;
} else if (ratio > 1) {
/* If the history list length exceeds the
innodb_max_purge_lag, the
data manipulation statements are delayed
by at least 5000 microseconds. */
srv_dml_needed_delay = (ulint) ((ratio - .5) * 10000);
}
}
purge_sys->view = read_view_oldest_copy_or_open_new(ut_dulint_zero,
purge_sys->heap);
mutex_exit(&kernel_mutex);
rw_lock_x_unlock(&(purge_sys->latch));
purge_sys->state = TRX_PURGE_ON;
/* Handle at most 20 undo log pages in one purge batch */
purge_sys->handle_limit = purge_sys->n_pages_handled + 20;
old_pages_handled = purge_sys->n_pages_handled;
mutex_exit(&(purge_sys->mutex));
mutex_enter(&kernel_mutex);
thr = que_fork_start_command(purge_sys->query);
ut_ad(thr);
/* thr2 = que_fork_start_command(purge_sys->query);
ut_ad(thr2); */
mutex_exit(&kernel_mutex);
/* srv_que_task_enqueue(thr2); */
if (srv_print_thread_releases) {
fputs("Starting purge\n", stderr);
}
que_run_threads(thr);
if (srv_print_thread_releases) {
fprintf(stderr,
"Purge ends; pages handled %lu\n",
(ulong) purge_sys->n_pages_handled);
}
return(purge_sys->n_pages_handled - old_pages_handled);
}
/******************************************************************//**
Prints information of the purge system to stderr. */
UNIV_INTERN
void
trx_purge_sys_print(void)
/*=====================*/
{
fprintf(stderr, "InnoDB: Purge system view:\n");
read_view_print(purge_sys->view);
fprintf(stderr, "InnoDB: Purge trx n:o " TRX_ID_FMT
", undo n:o " TRX_ID_FMT "\n",
TRX_ID_PREP_PRINTF(purge_sys->purge_trx_no),
TRX_ID_PREP_PRINTF(purge_sys->purge_undo_no));
fprintf(stderr,
"InnoDB: Purge next stored %lu, page_no %lu, offset %lu,\n"
"InnoDB: Purge hdr_page_no %lu, hdr_offset %lu\n",
(ulong) purge_sys->next_stored,
(ulong) purge_sys->page_no,
(ulong) purge_sys->offset,
(ulong) purge_sys->hdr_page_no,
(ulong) purge_sys->hdr_offset);
}