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.

1214 lines
32 KiB

11 years ago
11 years ago
9 years ago
9 years ago
11 years ago
MDEV-12219 Discard temporary undo logs at transaction commit Starting with MySQL 5.7, temporary tables in InnoDB are handled differently from persistent tables. Because temporary tables are private to a connection, concurrency control and multi-versioning (MVCC) are not applicable. For performance reasons, purge is disabled as well. Rollback is supported for temporary tables; that is why we have the temporary undo logs in the first place. Because MVCC and purge are disabled for temporary tables, we should discard all temporary undo logs already at transaction commit, just like we discard the persistent insert_undo logs. Before this change, update_undo logs were being preserved. trx_temp_undo_t: A wrapper for temporary undo logs, comprising a rollback segment and a single temporary undo log. trx_rsegs_t::m_noredo: Use trx_temp_undo_t. (Instead of insert_undo, update_undo, there will be a single undo.) trx_is_noredo_rseg_updated(), trx_is_rseg_assigned(): Remove. trx_undo_add_page(): Remove the parameter undo_ptr. Acquire and release the rollback segment mutex inside the function. trx_undo_free_last_page(): Remove the parameter trx. trx_undo_truncate_end(): Remove the parameter trx, and add the parameter is_temp. Clean up the code a bit. trx_undo_assign_undo(): Split the parameter undo_ptr into rseg, undo. trx_undo_commit_cleanup(): Renamed from trx_undo_insert_cleanup(). Replace the parameter undo_ptr with undo. This will discard the temporary undo or insert_undo log at commit/rollback. trx_purge_add_update_undo_to_history(), trx_undo_update_cleanup(): Remove 3 parameters. Always operate on the persistent update_undo. trx_serialise(): Renamed from trx_serialisation_number_get(). trx_write_serialisation_history(): Simplify the code flow. If there are no persistent changes, do not update MONITOR_TRX_COMMIT_UNDO. trx_commit_in_memory(): Simplify the logic, and add assertions. trx_undo_page_report_modify(): Keep a direct reference to the persistent update_undo log. trx_undo_report_row_operation(): Simplify some code. Always assign TRX_UNDO_INSERT for temporary undo logs. trx_prepare_low(): Keep only one parameter. Prepare all 3 undo logs. trx_roll_try_truncate(): Remove the parameter undo_ptr. Try to truncate all 3 undo logs of the transaction. trx_roll_pop_top_rec_of_trx_low(): Remove. trx_roll_pop_top_rec_of_trx(): Remove the redundant parameter trx->roll_limit. Clear roll_limit when exhausting the undo logs. Consider all 3 undo logs at once, prioritizing the persistent undo logs. row_undo(): Minor cleanup. Let trx_roll_pop_top_rec_of_trx() reset the trx->roll_limit.
9 years ago
MDEV-12219 Discard temporary undo logs at transaction commit Starting with MySQL 5.7, temporary tables in InnoDB are handled differently from persistent tables. Because temporary tables are private to a connection, concurrency control and multi-versioning (MVCC) are not applicable. For performance reasons, purge is disabled as well. Rollback is supported for temporary tables; that is why we have the temporary undo logs in the first place. Because MVCC and purge are disabled for temporary tables, we should discard all temporary undo logs already at transaction commit, just like we discard the persistent insert_undo logs. Before this change, update_undo logs were being preserved. trx_temp_undo_t: A wrapper for temporary undo logs, comprising a rollback segment and a single temporary undo log. trx_rsegs_t::m_noredo: Use trx_temp_undo_t. (Instead of insert_undo, update_undo, there will be a single undo.) trx_is_noredo_rseg_updated(), trx_is_rseg_assigned(): Remove. trx_undo_add_page(): Remove the parameter undo_ptr. Acquire and release the rollback segment mutex inside the function. trx_undo_free_last_page(): Remove the parameter trx. trx_undo_truncate_end(): Remove the parameter trx, and add the parameter is_temp. Clean up the code a bit. trx_undo_assign_undo(): Split the parameter undo_ptr into rseg, undo. trx_undo_commit_cleanup(): Renamed from trx_undo_insert_cleanup(). Replace the parameter undo_ptr with undo. This will discard the temporary undo or insert_undo log at commit/rollback. trx_purge_add_update_undo_to_history(), trx_undo_update_cleanup(): Remove 3 parameters. Always operate on the persistent update_undo. trx_serialise(): Renamed from trx_serialisation_number_get(). trx_write_serialisation_history(): Simplify the code flow. If there are no persistent changes, do not update MONITOR_TRX_COMMIT_UNDO. trx_commit_in_memory(): Simplify the logic, and add assertions. trx_undo_page_report_modify(): Keep a direct reference to the persistent update_undo log. trx_undo_report_row_operation(): Simplify some code. Always assign TRX_UNDO_INSERT for temporary undo logs. trx_prepare_low(): Keep only one parameter. Prepare all 3 undo logs. trx_roll_try_truncate(): Remove the parameter undo_ptr. Try to truncate all 3 undo logs of the transaction. trx_roll_pop_top_rec_of_trx_low(): Remove. trx_roll_pop_top_rec_of_trx(): Remove the redundant parameter trx->roll_limit. Clear roll_limit when exhausting the undo logs. Consider all 3 undo logs at once, prioritizing the persistent undo logs. row_undo(): Minor cleanup. Let trx_roll_pop_top_rec_of_trx() reset the trx->roll_limit.
9 years ago
MDEV-12219 Discard temporary undo logs at transaction commit Starting with MySQL 5.7, temporary tables in InnoDB are handled differently from persistent tables. Because temporary tables are private to a connection, concurrency control and multi-versioning (MVCC) are not applicable. For performance reasons, purge is disabled as well. Rollback is supported for temporary tables; that is why we have the temporary undo logs in the first place. Because MVCC and purge are disabled for temporary tables, we should discard all temporary undo logs already at transaction commit, just like we discard the persistent insert_undo logs. Before this change, update_undo logs were being preserved. trx_temp_undo_t: A wrapper for temporary undo logs, comprising a rollback segment and a single temporary undo log. trx_rsegs_t::m_noredo: Use trx_temp_undo_t. (Instead of insert_undo, update_undo, there will be a single undo.) trx_is_noredo_rseg_updated(), trx_is_rseg_assigned(): Remove. trx_undo_add_page(): Remove the parameter undo_ptr. Acquire and release the rollback segment mutex inside the function. trx_undo_free_last_page(): Remove the parameter trx. trx_undo_truncate_end(): Remove the parameter trx, and add the parameter is_temp. Clean up the code a bit. trx_undo_assign_undo(): Split the parameter undo_ptr into rseg, undo. trx_undo_commit_cleanup(): Renamed from trx_undo_insert_cleanup(). Replace the parameter undo_ptr with undo. This will discard the temporary undo or insert_undo log at commit/rollback. trx_purge_add_update_undo_to_history(), trx_undo_update_cleanup(): Remove 3 parameters. Always operate on the persistent update_undo. trx_serialise(): Renamed from trx_serialisation_number_get(). trx_write_serialisation_history(): Simplify the code flow. If there are no persistent changes, do not update MONITOR_TRX_COMMIT_UNDO. trx_commit_in_memory(): Simplify the logic, and add assertions. trx_undo_page_report_modify(): Keep a direct reference to the persistent update_undo log. trx_undo_report_row_operation(): Simplify some code. Always assign TRX_UNDO_INSERT for temporary undo logs. trx_prepare_low(): Keep only one parameter. Prepare all 3 undo logs. trx_roll_try_truncate(): Remove the parameter undo_ptr. Try to truncate all 3 undo logs of the transaction. trx_roll_pop_top_rec_of_trx_low(): Remove. trx_roll_pop_top_rec_of_trx(): Remove the redundant parameter trx->roll_limit. Clear roll_limit when exhausting the undo logs. Consider all 3 undo logs at once, prioritizing the persistent undo logs. row_undo(): Minor cleanup. Let trx_roll_pop_top_rec_of_trx() reset the trx->roll_limit.
9 years ago
MDEV-12219 Discard temporary undo logs at transaction commit Starting with MySQL 5.7, temporary tables in InnoDB are handled differently from persistent tables. Because temporary tables are private to a connection, concurrency control and multi-versioning (MVCC) are not applicable. For performance reasons, purge is disabled as well. Rollback is supported for temporary tables; that is why we have the temporary undo logs in the first place. Because MVCC and purge are disabled for temporary tables, we should discard all temporary undo logs already at transaction commit, just like we discard the persistent insert_undo logs. Before this change, update_undo logs were being preserved. trx_temp_undo_t: A wrapper for temporary undo logs, comprising a rollback segment and a single temporary undo log. trx_rsegs_t::m_noredo: Use trx_temp_undo_t. (Instead of insert_undo, update_undo, there will be a single undo.) trx_is_noredo_rseg_updated(), trx_is_rseg_assigned(): Remove. trx_undo_add_page(): Remove the parameter undo_ptr. Acquire and release the rollback segment mutex inside the function. trx_undo_free_last_page(): Remove the parameter trx. trx_undo_truncate_end(): Remove the parameter trx, and add the parameter is_temp. Clean up the code a bit. trx_undo_assign_undo(): Split the parameter undo_ptr into rseg, undo. trx_undo_commit_cleanup(): Renamed from trx_undo_insert_cleanup(). Replace the parameter undo_ptr with undo. This will discard the temporary undo or insert_undo log at commit/rollback. trx_purge_add_update_undo_to_history(), trx_undo_update_cleanup(): Remove 3 parameters. Always operate on the persistent update_undo. trx_serialise(): Renamed from trx_serialisation_number_get(). trx_write_serialisation_history(): Simplify the code flow. If there are no persistent changes, do not update MONITOR_TRX_COMMIT_UNDO. trx_commit_in_memory(): Simplify the logic, and add assertions. trx_undo_page_report_modify(): Keep a direct reference to the persistent update_undo log. trx_undo_report_row_operation(): Simplify some code. Always assign TRX_UNDO_INSERT for temporary undo logs. trx_prepare_low(): Keep only one parameter. Prepare all 3 undo logs. trx_roll_try_truncate(): Remove the parameter undo_ptr. Try to truncate all 3 undo logs of the transaction. trx_roll_pop_top_rec_of_trx_low(): Remove. trx_roll_pop_top_rec_of_trx(): Remove the redundant parameter trx->roll_limit. Clear roll_limit when exhausting the undo logs. Consider all 3 undo logs at once, prioritizing the persistent undo logs. row_undo(): Minor cleanup. Let trx_roll_pop_top_rec_of_trx() reset the trx->roll_limit.
9 years ago
MDEV-12219 Discard temporary undo logs at transaction commit Starting with MySQL 5.7, temporary tables in InnoDB are handled differently from persistent tables. Because temporary tables are private to a connection, concurrency control and multi-versioning (MVCC) are not applicable. For performance reasons, purge is disabled as well. Rollback is supported for temporary tables; that is why we have the temporary undo logs in the first place. Because MVCC and purge are disabled for temporary tables, we should discard all temporary undo logs already at transaction commit, just like we discard the persistent insert_undo logs. Before this change, update_undo logs were being preserved. trx_temp_undo_t: A wrapper for temporary undo logs, comprising a rollback segment and a single temporary undo log. trx_rsegs_t::m_noredo: Use trx_temp_undo_t. (Instead of insert_undo, update_undo, there will be a single undo.) trx_is_noredo_rseg_updated(), trx_is_rseg_assigned(): Remove. trx_undo_add_page(): Remove the parameter undo_ptr. Acquire and release the rollback segment mutex inside the function. trx_undo_free_last_page(): Remove the parameter trx. trx_undo_truncate_end(): Remove the parameter trx, and add the parameter is_temp. Clean up the code a bit. trx_undo_assign_undo(): Split the parameter undo_ptr into rseg, undo. trx_undo_commit_cleanup(): Renamed from trx_undo_insert_cleanup(). Replace the parameter undo_ptr with undo. This will discard the temporary undo or insert_undo log at commit/rollback. trx_purge_add_update_undo_to_history(), trx_undo_update_cleanup(): Remove 3 parameters. Always operate on the persistent update_undo. trx_serialise(): Renamed from trx_serialisation_number_get(). trx_write_serialisation_history(): Simplify the code flow. If there are no persistent changes, do not update MONITOR_TRX_COMMIT_UNDO. trx_commit_in_memory(): Simplify the logic, and add assertions. trx_undo_page_report_modify(): Keep a direct reference to the persistent update_undo log. trx_undo_report_row_operation(): Simplify some code. Always assign TRX_UNDO_INSERT for temporary undo logs. trx_prepare_low(): Keep only one parameter. Prepare all 3 undo logs. trx_roll_try_truncate(): Remove the parameter undo_ptr. Try to truncate all 3 undo logs of the transaction. trx_roll_pop_top_rec_of_trx_low(): Remove. trx_roll_pop_top_rec_of_trx(): Remove the redundant parameter trx->roll_limit. Clear roll_limit when exhausting the undo logs. Consider all 3 undo logs at once, prioritizing the persistent undo logs. row_undo(): Minor cleanup. Let trx_roll_pop_top_rec_of_trx() reset the trx->roll_limit.
9 years ago
MDEV-12219 Discard temporary undo logs at transaction commit Starting with MySQL 5.7, temporary tables in InnoDB are handled differently from persistent tables. Because temporary tables are private to a connection, concurrency control and multi-versioning (MVCC) are not applicable. For performance reasons, purge is disabled as well. Rollback is supported for temporary tables; that is why we have the temporary undo logs in the first place. Because MVCC and purge are disabled for temporary tables, we should discard all temporary undo logs already at transaction commit, just like we discard the persistent insert_undo logs. Before this change, update_undo logs were being preserved. trx_temp_undo_t: A wrapper for temporary undo logs, comprising a rollback segment and a single temporary undo log. trx_rsegs_t::m_noredo: Use trx_temp_undo_t. (Instead of insert_undo, update_undo, there will be a single undo.) trx_is_noredo_rseg_updated(), trx_is_rseg_assigned(): Remove. trx_undo_add_page(): Remove the parameter undo_ptr. Acquire and release the rollback segment mutex inside the function. trx_undo_free_last_page(): Remove the parameter trx. trx_undo_truncate_end(): Remove the parameter trx, and add the parameter is_temp. Clean up the code a bit. trx_undo_assign_undo(): Split the parameter undo_ptr into rseg, undo. trx_undo_commit_cleanup(): Renamed from trx_undo_insert_cleanup(). Replace the parameter undo_ptr with undo. This will discard the temporary undo or insert_undo log at commit/rollback. trx_purge_add_update_undo_to_history(), trx_undo_update_cleanup(): Remove 3 parameters. Always operate on the persistent update_undo. trx_serialise(): Renamed from trx_serialisation_number_get(). trx_write_serialisation_history(): Simplify the code flow. If there are no persistent changes, do not update MONITOR_TRX_COMMIT_UNDO. trx_commit_in_memory(): Simplify the logic, and add assertions. trx_undo_page_report_modify(): Keep a direct reference to the persistent update_undo log. trx_undo_report_row_operation(): Simplify some code. Always assign TRX_UNDO_INSERT for temporary undo logs. trx_prepare_low(): Keep only one parameter. Prepare all 3 undo logs. trx_roll_try_truncate(): Remove the parameter undo_ptr. Try to truncate all 3 undo logs of the transaction. trx_roll_pop_top_rec_of_trx_low(): Remove. trx_roll_pop_top_rec_of_trx(): Remove the redundant parameter trx->roll_limit. Clear roll_limit when exhausting the undo logs. Consider all 3 undo logs at once, prioritizing the persistent undo logs. row_undo(): Minor cleanup. Let trx_roll_pop_top_rec_of_trx() reset the trx->roll_limit.
9 years ago
MDEV-12219 Discard temporary undo logs at transaction commit Starting with MySQL 5.7, temporary tables in InnoDB are handled differently from persistent tables. Because temporary tables are private to a connection, concurrency control and multi-versioning (MVCC) are not applicable. For performance reasons, purge is disabled as well. Rollback is supported for temporary tables; that is why we have the temporary undo logs in the first place. Because MVCC and purge are disabled for temporary tables, we should discard all temporary undo logs already at transaction commit, just like we discard the persistent insert_undo logs. Before this change, update_undo logs were being preserved. trx_temp_undo_t: A wrapper for temporary undo logs, comprising a rollback segment and a single temporary undo log. trx_rsegs_t::m_noredo: Use trx_temp_undo_t. (Instead of insert_undo, update_undo, there will be a single undo.) trx_is_noredo_rseg_updated(), trx_is_rseg_assigned(): Remove. trx_undo_add_page(): Remove the parameter undo_ptr. Acquire and release the rollback segment mutex inside the function. trx_undo_free_last_page(): Remove the parameter trx. trx_undo_truncate_end(): Remove the parameter trx, and add the parameter is_temp. Clean up the code a bit. trx_undo_assign_undo(): Split the parameter undo_ptr into rseg, undo. trx_undo_commit_cleanup(): Renamed from trx_undo_insert_cleanup(). Replace the parameter undo_ptr with undo. This will discard the temporary undo or insert_undo log at commit/rollback. trx_purge_add_update_undo_to_history(), trx_undo_update_cleanup(): Remove 3 parameters. Always operate on the persistent update_undo. trx_serialise(): Renamed from trx_serialisation_number_get(). trx_write_serialisation_history(): Simplify the code flow. If there are no persistent changes, do not update MONITOR_TRX_COMMIT_UNDO. trx_commit_in_memory(): Simplify the logic, and add assertions. trx_undo_page_report_modify(): Keep a direct reference to the persistent update_undo log. trx_undo_report_row_operation(): Simplify some code. Always assign TRX_UNDO_INSERT for temporary undo logs. trx_prepare_low(): Keep only one parameter. Prepare all 3 undo logs. trx_roll_try_truncate(): Remove the parameter undo_ptr. Try to truncate all 3 undo logs of the transaction. trx_roll_pop_top_rec_of_trx_low(): Remove. trx_roll_pop_top_rec_of_trx(): Remove the redundant parameter trx->roll_limit. Clear roll_limit when exhausting the undo logs. Consider all 3 undo logs at once, prioritizing the persistent undo logs. row_undo(): Minor cleanup. Let trx_roll_pop_top_rec_of_trx() reset the trx->roll_limit.
9 years ago
MDEV-12219 Discard temporary undo logs at transaction commit Starting with MySQL 5.7, temporary tables in InnoDB are handled differently from persistent tables. Because temporary tables are private to a connection, concurrency control and multi-versioning (MVCC) are not applicable. For performance reasons, purge is disabled as well. Rollback is supported for temporary tables; that is why we have the temporary undo logs in the first place. Because MVCC and purge are disabled for temporary tables, we should discard all temporary undo logs already at transaction commit, just like we discard the persistent insert_undo logs. Before this change, update_undo logs were being preserved. trx_temp_undo_t: A wrapper for temporary undo logs, comprising a rollback segment and a single temporary undo log. trx_rsegs_t::m_noredo: Use trx_temp_undo_t. (Instead of insert_undo, update_undo, there will be a single undo.) trx_is_noredo_rseg_updated(), trx_is_rseg_assigned(): Remove. trx_undo_add_page(): Remove the parameter undo_ptr. Acquire and release the rollback segment mutex inside the function. trx_undo_free_last_page(): Remove the parameter trx. trx_undo_truncate_end(): Remove the parameter trx, and add the parameter is_temp. Clean up the code a bit. trx_undo_assign_undo(): Split the parameter undo_ptr into rseg, undo. trx_undo_commit_cleanup(): Renamed from trx_undo_insert_cleanup(). Replace the parameter undo_ptr with undo. This will discard the temporary undo or insert_undo log at commit/rollback. trx_purge_add_update_undo_to_history(), trx_undo_update_cleanup(): Remove 3 parameters. Always operate on the persistent update_undo. trx_serialise(): Renamed from trx_serialisation_number_get(). trx_write_serialisation_history(): Simplify the code flow. If there are no persistent changes, do not update MONITOR_TRX_COMMIT_UNDO. trx_commit_in_memory(): Simplify the logic, and add assertions. trx_undo_page_report_modify(): Keep a direct reference to the persistent update_undo log. trx_undo_report_row_operation(): Simplify some code. Always assign TRX_UNDO_INSERT for temporary undo logs. trx_prepare_low(): Keep only one parameter. Prepare all 3 undo logs. trx_roll_try_truncate(): Remove the parameter undo_ptr. Try to truncate all 3 undo logs of the transaction. trx_roll_pop_top_rec_of_trx_low(): Remove. trx_roll_pop_top_rec_of_trx(): Remove the redundant parameter trx->roll_limit. Clear roll_limit when exhausting the undo logs. Consider all 3 undo logs at once, prioritizing the persistent undo logs. row_undo(): Minor cleanup. Let trx_roll_pop_top_rec_of_trx() reset the trx->roll_limit.
9 years ago
MDEV-12219 Discard temporary undo logs at transaction commit Starting with MySQL 5.7, temporary tables in InnoDB are handled differently from persistent tables. Because temporary tables are private to a connection, concurrency control and multi-versioning (MVCC) are not applicable. For performance reasons, purge is disabled as well. Rollback is supported for temporary tables; that is why we have the temporary undo logs in the first place. Because MVCC and purge are disabled for temporary tables, we should discard all temporary undo logs already at transaction commit, just like we discard the persistent insert_undo logs. Before this change, update_undo logs were being preserved. trx_temp_undo_t: A wrapper for temporary undo logs, comprising a rollback segment and a single temporary undo log. trx_rsegs_t::m_noredo: Use trx_temp_undo_t. (Instead of insert_undo, update_undo, there will be a single undo.) trx_is_noredo_rseg_updated(), trx_is_rseg_assigned(): Remove. trx_undo_add_page(): Remove the parameter undo_ptr. Acquire and release the rollback segment mutex inside the function. trx_undo_free_last_page(): Remove the parameter trx. trx_undo_truncate_end(): Remove the parameter trx, and add the parameter is_temp. Clean up the code a bit. trx_undo_assign_undo(): Split the parameter undo_ptr into rseg, undo. trx_undo_commit_cleanup(): Renamed from trx_undo_insert_cleanup(). Replace the parameter undo_ptr with undo. This will discard the temporary undo or insert_undo log at commit/rollback. trx_purge_add_update_undo_to_history(), trx_undo_update_cleanup(): Remove 3 parameters. Always operate on the persistent update_undo. trx_serialise(): Renamed from trx_serialisation_number_get(). trx_write_serialisation_history(): Simplify the code flow. If there are no persistent changes, do not update MONITOR_TRX_COMMIT_UNDO. trx_commit_in_memory(): Simplify the logic, and add assertions. trx_undo_page_report_modify(): Keep a direct reference to the persistent update_undo log. trx_undo_report_row_operation(): Simplify some code. Always assign TRX_UNDO_INSERT for temporary undo logs. trx_prepare_low(): Keep only one parameter. Prepare all 3 undo logs. trx_roll_try_truncate(): Remove the parameter undo_ptr. Try to truncate all 3 undo logs of the transaction. trx_roll_pop_top_rec_of_trx_low(): Remove. trx_roll_pop_top_rec_of_trx(): Remove the redundant parameter trx->roll_limit. Clear roll_limit when exhausting the undo logs. Consider all 3 undo logs at once, prioritizing the persistent undo logs. row_undo(): Minor cleanup. Let trx_roll_pop_top_rec_of_trx() reset the trx->roll_limit.
9 years ago
MDEV-12219 Discard temporary undo logs at transaction commit Starting with MySQL 5.7, temporary tables in InnoDB are handled differently from persistent tables. Because temporary tables are private to a connection, concurrency control and multi-versioning (MVCC) are not applicable. For performance reasons, purge is disabled as well. Rollback is supported for temporary tables; that is why we have the temporary undo logs in the first place. Because MVCC and purge are disabled for temporary tables, we should discard all temporary undo logs already at transaction commit, just like we discard the persistent insert_undo logs. Before this change, update_undo logs were being preserved. trx_temp_undo_t: A wrapper for temporary undo logs, comprising a rollback segment and a single temporary undo log. trx_rsegs_t::m_noredo: Use trx_temp_undo_t. (Instead of insert_undo, update_undo, there will be a single undo.) trx_is_noredo_rseg_updated(), trx_is_rseg_assigned(): Remove. trx_undo_add_page(): Remove the parameter undo_ptr. Acquire and release the rollback segment mutex inside the function. trx_undo_free_last_page(): Remove the parameter trx. trx_undo_truncate_end(): Remove the parameter trx, and add the parameter is_temp. Clean up the code a bit. trx_undo_assign_undo(): Split the parameter undo_ptr into rseg, undo. trx_undo_commit_cleanup(): Renamed from trx_undo_insert_cleanup(). Replace the parameter undo_ptr with undo. This will discard the temporary undo or insert_undo log at commit/rollback. trx_purge_add_update_undo_to_history(), trx_undo_update_cleanup(): Remove 3 parameters. Always operate on the persistent update_undo. trx_serialise(): Renamed from trx_serialisation_number_get(). trx_write_serialisation_history(): Simplify the code flow. If there are no persistent changes, do not update MONITOR_TRX_COMMIT_UNDO. trx_commit_in_memory(): Simplify the logic, and add assertions. trx_undo_page_report_modify(): Keep a direct reference to the persistent update_undo log. trx_undo_report_row_operation(): Simplify some code. Always assign TRX_UNDO_INSERT for temporary undo logs. trx_prepare_low(): Keep only one parameter. Prepare all 3 undo logs. trx_roll_try_truncate(): Remove the parameter undo_ptr. Try to truncate all 3 undo logs of the transaction. trx_roll_pop_top_rec_of_trx_low(): Remove. trx_roll_pop_top_rec_of_trx(): Remove the redundant parameter trx->roll_limit. Clear roll_limit when exhausting the undo logs. Consider all 3 undo logs at once, prioritizing the persistent undo logs. row_undo(): Minor cleanup. Let trx_roll_pop_top_rec_of_trx() reset the trx->roll_limit.
9 years ago
MDEV-12219 Discard temporary undo logs at transaction commit Starting with MySQL 5.7, temporary tables in InnoDB are handled differently from persistent tables. Because temporary tables are private to a connection, concurrency control and multi-versioning (MVCC) are not applicable. For performance reasons, purge is disabled as well. Rollback is supported for temporary tables; that is why we have the temporary undo logs in the first place. Because MVCC and purge are disabled for temporary tables, we should discard all temporary undo logs already at transaction commit, just like we discard the persistent insert_undo logs. Before this change, update_undo logs were being preserved. trx_temp_undo_t: A wrapper for temporary undo logs, comprising a rollback segment and a single temporary undo log. trx_rsegs_t::m_noredo: Use trx_temp_undo_t. (Instead of insert_undo, update_undo, there will be a single undo.) trx_is_noredo_rseg_updated(), trx_is_rseg_assigned(): Remove. trx_undo_add_page(): Remove the parameter undo_ptr. Acquire and release the rollback segment mutex inside the function. trx_undo_free_last_page(): Remove the parameter trx. trx_undo_truncate_end(): Remove the parameter trx, and add the parameter is_temp. Clean up the code a bit. trx_undo_assign_undo(): Split the parameter undo_ptr into rseg, undo. trx_undo_commit_cleanup(): Renamed from trx_undo_insert_cleanup(). Replace the parameter undo_ptr with undo. This will discard the temporary undo or insert_undo log at commit/rollback. trx_purge_add_update_undo_to_history(), trx_undo_update_cleanup(): Remove 3 parameters. Always operate on the persistent update_undo. trx_serialise(): Renamed from trx_serialisation_number_get(). trx_write_serialisation_history(): Simplify the code flow. If there are no persistent changes, do not update MONITOR_TRX_COMMIT_UNDO. trx_commit_in_memory(): Simplify the logic, and add assertions. trx_undo_page_report_modify(): Keep a direct reference to the persistent update_undo log. trx_undo_report_row_operation(): Simplify some code. Always assign TRX_UNDO_INSERT for temporary undo logs. trx_prepare_low(): Keep only one parameter. Prepare all 3 undo logs. trx_roll_try_truncate(): Remove the parameter undo_ptr. Try to truncate all 3 undo logs of the transaction. trx_roll_pop_top_rec_of_trx_low(): Remove. trx_roll_pop_top_rec_of_trx(): Remove the redundant parameter trx->roll_limit. Clear roll_limit when exhausting the undo logs. Consider all 3 undo logs at once, prioritizing the persistent undo logs. row_undo(): Minor cleanup. Let trx_roll_pop_top_rec_of_trx() reset the trx->roll_limit.
9 years ago
MDEV-12219 Discard temporary undo logs at transaction commit Starting with MySQL 5.7, temporary tables in InnoDB are handled differently from persistent tables. Because temporary tables are private to a connection, concurrency control and multi-versioning (MVCC) are not applicable. For performance reasons, purge is disabled as well. Rollback is supported for temporary tables; that is why we have the temporary undo logs in the first place. Because MVCC and purge are disabled for temporary tables, we should discard all temporary undo logs already at transaction commit, just like we discard the persistent insert_undo logs. Before this change, update_undo logs were being preserved. trx_temp_undo_t: A wrapper for temporary undo logs, comprising a rollback segment and a single temporary undo log. trx_rsegs_t::m_noredo: Use trx_temp_undo_t. (Instead of insert_undo, update_undo, there will be a single undo.) trx_is_noredo_rseg_updated(), trx_is_rseg_assigned(): Remove. trx_undo_add_page(): Remove the parameter undo_ptr. Acquire and release the rollback segment mutex inside the function. trx_undo_free_last_page(): Remove the parameter trx. trx_undo_truncate_end(): Remove the parameter trx, and add the parameter is_temp. Clean up the code a bit. trx_undo_assign_undo(): Split the parameter undo_ptr into rseg, undo. trx_undo_commit_cleanup(): Renamed from trx_undo_insert_cleanup(). Replace the parameter undo_ptr with undo. This will discard the temporary undo or insert_undo log at commit/rollback. trx_purge_add_update_undo_to_history(), trx_undo_update_cleanup(): Remove 3 parameters. Always operate on the persistent update_undo. trx_serialise(): Renamed from trx_serialisation_number_get(). trx_write_serialisation_history(): Simplify the code flow. If there are no persistent changes, do not update MONITOR_TRX_COMMIT_UNDO. trx_commit_in_memory(): Simplify the logic, and add assertions. trx_undo_page_report_modify(): Keep a direct reference to the persistent update_undo log. trx_undo_report_row_operation(): Simplify some code. Always assign TRX_UNDO_INSERT for temporary undo logs. trx_prepare_low(): Keep only one parameter. Prepare all 3 undo logs. trx_roll_try_truncate(): Remove the parameter undo_ptr. Try to truncate all 3 undo logs of the transaction. trx_roll_pop_top_rec_of_trx_low(): Remove. trx_roll_pop_top_rec_of_trx(): Remove the redundant parameter trx->roll_limit. Clear roll_limit when exhausting the undo logs. Consider all 3 undo logs at once, prioritizing the persistent undo logs. row_undo(): Minor cleanup. Let trx_roll_pop_top_rec_of_trx() reset the trx->roll_limit.
9 years ago
MDEV-12219 Discard temporary undo logs at transaction commit Starting with MySQL 5.7, temporary tables in InnoDB are handled differently from persistent tables. Because temporary tables are private to a connection, concurrency control and multi-versioning (MVCC) are not applicable. For performance reasons, purge is disabled as well. Rollback is supported for temporary tables; that is why we have the temporary undo logs in the first place. Because MVCC and purge are disabled for temporary tables, we should discard all temporary undo logs already at transaction commit, just like we discard the persistent insert_undo logs. Before this change, update_undo logs were being preserved. trx_temp_undo_t: A wrapper for temporary undo logs, comprising a rollback segment and a single temporary undo log. trx_rsegs_t::m_noredo: Use trx_temp_undo_t. (Instead of insert_undo, update_undo, there will be a single undo.) trx_is_noredo_rseg_updated(), trx_is_rseg_assigned(): Remove. trx_undo_add_page(): Remove the parameter undo_ptr. Acquire and release the rollback segment mutex inside the function. trx_undo_free_last_page(): Remove the parameter trx. trx_undo_truncate_end(): Remove the parameter trx, and add the parameter is_temp. Clean up the code a bit. trx_undo_assign_undo(): Split the parameter undo_ptr into rseg, undo. trx_undo_commit_cleanup(): Renamed from trx_undo_insert_cleanup(). Replace the parameter undo_ptr with undo. This will discard the temporary undo or insert_undo log at commit/rollback. trx_purge_add_update_undo_to_history(), trx_undo_update_cleanup(): Remove 3 parameters. Always operate on the persistent update_undo. trx_serialise(): Renamed from trx_serialisation_number_get(). trx_write_serialisation_history(): Simplify the code flow. If there are no persistent changes, do not update MONITOR_TRX_COMMIT_UNDO. trx_commit_in_memory(): Simplify the logic, and add assertions. trx_undo_page_report_modify(): Keep a direct reference to the persistent update_undo log. trx_undo_report_row_operation(): Simplify some code. Always assign TRX_UNDO_INSERT for temporary undo logs. trx_prepare_low(): Keep only one parameter. Prepare all 3 undo logs. trx_roll_try_truncate(): Remove the parameter undo_ptr. Try to truncate all 3 undo logs of the transaction. trx_roll_pop_top_rec_of_trx_low(): Remove. trx_roll_pop_top_rec_of_trx(): Remove the redundant parameter trx->roll_limit. Clear roll_limit when exhausting the undo logs. Consider all 3 undo logs at once, prioritizing the persistent undo logs. row_undo(): Minor cleanup. Let trx_roll_pop_top_rec_of_trx() reset the trx->roll_limit.
9 years ago
MDEV-12219 Discard temporary undo logs at transaction commit Starting with MySQL 5.7, temporary tables in InnoDB are handled differently from persistent tables. Because temporary tables are private to a connection, concurrency control and multi-versioning (MVCC) are not applicable. For performance reasons, purge is disabled as well. Rollback is supported for temporary tables; that is why we have the temporary undo logs in the first place. Because MVCC and purge are disabled for temporary tables, we should discard all temporary undo logs already at transaction commit, just like we discard the persistent insert_undo logs. Before this change, update_undo logs were being preserved. trx_temp_undo_t: A wrapper for temporary undo logs, comprising a rollback segment and a single temporary undo log. trx_rsegs_t::m_noredo: Use trx_temp_undo_t. (Instead of insert_undo, update_undo, there will be a single undo.) trx_is_noredo_rseg_updated(), trx_is_rseg_assigned(): Remove. trx_undo_add_page(): Remove the parameter undo_ptr. Acquire and release the rollback segment mutex inside the function. trx_undo_free_last_page(): Remove the parameter trx. trx_undo_truncate_end(): Remove the parameter trx, and add the parameter is_temp. Clean up the code a bit. trx_undo_assign_undo(): Split the parameter undo_ptr into rseg, undo. trx_undo_commit_cleanup(): Renamed from trx_undo_insert_cleanup(). Replace the parameter undo_ptr with undo. This will discard the temporary undo or insert_undo log at commit/rollback. trx_purge_add_update_undo_to_history(), trx_undo_update_cleanup(): Remove 3 parameters. Always operate on the persistent update_undo. trx_serialise(): Renamed from trx_serialisation_number_get(). trx_write_serialisation_history(): Simplify the code flow. If there are no persistent changes, do not update MONITOR_TRX_COMMIT_UNDO. trx_commit_in_memory(): Simplify the logic, and add assertions. trx_undo_page_report_modify(): Keep a direct reference to the persistent update_undo log. trx_undo_report_row_operation(): Simplify some code. Always assign TRX_UNDO_INSERT for temporary undo logs. trx_prepare_low(): Keep only one parameter. Prepare all 3 undo logs. trx_roll_try_truncate(): Remove the parameter undo_ptr. Try to truncate all 3 undo logs of the transaction. trx_roll_pop_top_rec_of_trx_low(): Remove. trx_roll_pop_top_rec_of_trx(): Remove the redundant parameter trx->roll_limit. Clear roll_limit when exhausting the undo logs. Consider all 3 undo logs at once, prioritizing the persistent undo logs. row_undo(): Minor cleanup. Let trx_roll_pop_top_rec_of_trx() reset the trx->roll_limit.
9 years ago
MDEV-12219 Discard temporary undo logs at transaction commit Starting with MySQL 5.7, temporary tables in InnoDB are handled differently from persistent tables. Because temporary tables are private to a connection, concurrency control and multi-versioning (MVCC) are not applicable. For performance reasons, purge is disabled as well. Rollback is supported for temporary tables; that is why we have the temporary undo logs in the first place. Because MVCC and purge are disabled for temporary tables, we should discard all temporary undo logs already at transaction commit, just like we discard the persistent insert_undo logs. Before this change, update_undo logs were being preserved. trx_temp_undo_t: A wrapper for temporary undo logs, comprising a rollback segment and a single temporary undo log. trx_rsegs_t::m_noredo: Use trx_temp_undo_t. (Instead of insert_undo, update_undo, there will be a single undo.) trx_is_noredo_rseg_updated(), trx_is_rseg_assigned(): Remove. trx_undo_add_page(): Remove the parameter undo_ptr. Acquire and release the rollback segment mutex inside the function. trx_undo_free_last_page(): Remove the parameter trx. trx_undo_truncate_end(): Remove the parameter trx, and add the parameter is_temp. Clean up the code a bit. trx_undo_assign_undo(): Split the parameter undo_ptr into rseg, undo. trx_undo_commit_cleanup(): Renamed from trx_undo_insert_cleanup(). Replace the parameter undo_ptr with undo. This will discard the temporary undo or insert_undo log at commit/rollback. trx_purge_add_update_undo_to_history(), trx_undo_update_cleanup(): Remove 3 parameters. Always operate on the persistent update_undo. trx_serialise(): Renamed from trx_serialisation_number_get(). trx_write_serialisation_history(): Simplify the code flow. If there are no persistent changes, do not update MONITOR_TRX_COMMIT_UNDO. trx_commit_in_memory(): Simplify the logic, and add assertions. trx_undo_page_report_modify(): Keep a direct reference to the persistent update_undo log. trx_undo_report_row_operation(): Simplify some code. Always assign TRX_UNDO_INSERT for temporary undo logs. trx_prepare_low(): Keep only one parameter. Prepare all 3 undo logs. trx_roll_try_truncate(): Remove the parameter undo_ptr. Try to truncate all 3 undo logs of the transaction. trx_roll_pop_top_rec_of_trx_low(): Remove. trx_roll_pop_top_rec_of_trx(): Remove the redundant parameter trx->roll_limit. Clear roll_limit when exhausting the undo logs. Consider all 3 undo logs at once, prioritizing the persistent undo logs. row_undo(): Minor cleanup. Let trx_roll_pop_top_rec_of_trx() reset the trx->roll_limit.
9 years ago
MDEV-12219 Discard temporary undo logs at transaction commit Starting with MySQL 5.7, temporary tables in InnoDB are handled differently from persistent tables. Because temporary tables are private to a connection, concurrency control and multi-versioning (MVCC) are not applicable. For performance reasons, purge is disabled as well. Rollback is supported for temporary tables; that is why we have the temporary undo logs in the first place. Because MVCC and purge are disabled for temporary tables, we should discard all temporary undo logs already at transaction commit, just like we discard the persistent insert_undo logs. Before this change, update_undo logs were being preserved. trx_temp_undo_t: A wrapper for temporary undo logs, comprising a rollback segment and a single temporary undo log. trx_rsegs_t::m_noredo: Use trx_temp_undo_t. (Instead of insert_undo, update_undo, there will be a single undo.) trx_is_noredo_rseg_updated(), trx_is_rseg_assigned(): Remove. trx_undo_add_page(): Remove the parameter undo_ptr. Acquire and release the rollback segment mutex inside the function. trx_undo_free_last_page(): Remove the parameter trx. trx_undo_truncate_end(): Remove the parameter trx, and add the parameter is_temp. Clean up the code a bit. trx_undo_assign_undo(): Split the parameter undo_ptr into rseg, undo. trx_undo_commit_cleanup(): Renamed from trx_undo_insert_cleanup(). Replace the parameter undo_ptr with undo. This will discard the temporary undo or insert_undo log at commit/rollback. trx_purge_add_update_undo_to_history(), trx_undo_update_cleanup(): Remove 3 parameters. Always operate on the persistent update_undo. trx_serialise(): Renamed from trx_serialisation_number_get(). trx_write_serialisation_history(): Simplify the code flow. If there are no persistent changes, do not update MONITOR_TRX_COMMIT_UNDO. trx_commit_in_memory(): Simplify the logic, and add assertions. trx_undo_page_report_modify(): Keep a direct reference to the persistent update_undo log. trx_undo_report_row_operation(): Simplify some code. Always assign TRX_UNDO_INSERT for temporary undo logs. trx_prepare_low(): Keep only one parameter. Prepare all 3 undo logs. trx_roll_try_truncate(): Remove the parameter undo_ptr. Try to truncate all 3 undo logs of the transaction. trx_roll_pop_top_rec_of_trx_low(): Remove. trx_roll_pop_top_rec_of_trx(): Remove the redundant parameter trx->roll_limit. Clear roll_limit when exhausting the undo logs. Consider all 3 undo logs at once, prioritizing the persistent undo logs. row_undo(): Minor cleanup. Let trx_roll_pop_top_rec_of_trx() reset the trx->roll_limit.
9 years ago
MDEV-12219 Discard temporary undo logs at transaction commit Starting with MySQL 5.7, temporary tables in InnoDB are handled differently from persistent tables. Because temporary tables are private to a connection, concurrency control and multi-versioning (MVCC) are not applicable. For performance reasons, purge is disabled as well. Rollback is supported for temporary tables; that is why we have the temporary undo logs in the first place. Because MVCC and purge are disabled for temporary tables, we should discard all temporary undo logs already at transaction commit, just like we discard the persistent insert_undo logs. Before this change, update_undo logs were being preserved. trx_temp_undo_t: A wrapper for temporary undo logs, comprising a rollback segment and a single temporary undo log. trx_rsegs_t::m_noredo: Use trx_temp_undo_t. (Instead of insert_undo, update_undo, there will be a single undo.) trx_is_noredo_rseg_updated(), trx_is_rseg_assigned(): Remove. trx_undo_add_page(): Remove the parameter undo_ptr. Acquire and release the rollback segment mutex inside the function. trx_undo_free_last_page(): Remove the parameter trx. trx_undo_truncate_end(): Remove the parameter trx, and add the parameter is_temp. Clean up the code a bit. trx_undo_assign_undo(): Split the parameter undo_ptr into rseg, undo. trx_undo_commit_cleanup(): Renamed from trx_undo_insert_cleanup(). Replace the parameter undo_ptr with undo. This will discard the temporary undo or insert_undo log at commit/rollback. trx_purge_add_update_undo_to_history(), trx_undo_update_cleanup(): Remove 3 parameters. Always operate on the persistent update_undo. trx_serialise(): Renamed from trx_serialisation_number_get(). trx_write_serialisation_history(): Simplify the code flow. If there are no persistent changes, do not update MONITOR_TRX_COMMIT_UNDO. trx_commit_in_memory(): Simplify the logic, and add assertions. trx_undo_page_report_modify(): Keep a direct reference to the persistent update_undo log. trx_undo_report_row_operation(): Simplify some code. Always assign TRX_UNDO_INSERT for temporary undo logs. trx_prepare_low(): Keep only one parameter. Prepare all 3 undo logs. trx_roll_try_truncate(): Remove the parameter undo_ptr. Try to truncate all 3 undo logs of the transaction. trx_roll_pop_top_rec_of_trx_low(): Remove. trx_roll_pop_top_rec_of_trx(): Remove the redundant parameter trx->roll_limit. Clear roll_limit when exhausting the undo logs. Consider all 3 undo logs at once, prioritizing the persistent undo logs. row_undo(): Minor cleanup. Let trx_roll_pop_top_rec_of_trx() reset the trx->roll_limit.
9 years ago
  1. /*****************************************************************************
  2. Copyright (c) 1996, 2017, Oracle and/or its affiliates. All Rights Reserved.
  3. Copyright (c) 2016, 2018, MariaDB Corporation.
  4. This program is free software; you can redistribute it and/or modify it under
  5. the terms of the GNU General Public License as published by the Free Software
  6. Foundation; version 2 of the License.
  7. This program is distributed in the hope that it will be useful, but WITHOUT
  8. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  10. You should have received a copy of the GNU General Public License along with
  11. this program; if not, write to the Free Software Foundation, Inc.,
  12. 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
  13. *****************************************************************************/
  14. /**************************************************//**
  15. @file trx/trx0roll.cc
  16. Transaction rollback
  17. Created 3/26/1996 Heikki Tuuri
  18. *******************************************************/
  19. #include "my_config.h"
  20. #include <my_systemd.h>
  21. #include "ha_prototypes.h"
  22. #include "trx0roll.h"
  23. #include <mysql/service_wsrep.h>
  24. #include "fsp0fsp.h"
  25. #include "lock0lock.h"
  26. #include "mach0data.h"
  27. #include "pars0pars.h"
  28. #include "que0que.h"
  29. #include "read0read.h"
  30. #include "row0mysql.h"
  31. #include "row0undo.h"
  32. #include "srv0mon.h"
  33. #include "srv0start.h"
  34. #include "trx0rec.h"
  35. #include "trx0rseg.h"
  36. #include "trx0sys.h"
  37. #include "trx0trx.h"
  38. #include "trx0undo.h"
  39. #include "ha_prototypes.h"
  40. /** This many pages must be undone before a truncate is tried within
  41. rollback */
  42. static const ulint TRX_ROLL_TRUNC_THRESHOLD = 1;
  43. /** true if trx_rollback_or_clean_all_recovered() thread is active */
  44. bool trx_rollback_or_clean_is_active;
  45. /** In crash recovery, the current trx to be rolled back; NULL otherwise */
  46. const trx_t* trx_roll_crash_recv_trx;
  47. /****************************************************************//**
  48. Finishes a transaction rollback. */
  49. static
  50. void
  51. trx_rollback_finish(
  52. /*================*/
  53. trx_t* trx); /*!< in: transaction */
  54. /*******************************************************************//**
  55. Rollback a transaction used in MySQL. */
  56. static
  57. void
  58. trx_rollback_to_savepoint_low(
  59. /*==========================*/
  60. trx_t* trx, /*!< in: transaction handle */
  61. trx_savept_t* savept) /*!< in: pointer to savepoint undo number, if
  62. partial rollback requested, or NULL for
  63. complete rollback */
  64. {
  65. que_thr_t* thr;
  66. mem_heap_t* heap;
  67. roll_node_t* roll_node;
  68. heap = mem_heap_create(512);
  69. roll_node = roll_node_create(heap);
  70. if (savept != NULL) {
  71. roll_node->partial = TRUE;
  72. roll_node->savept = *savept;
  73. check_trx_state(trx);
  74. } else {
  75. assert_trx_nonlocking_or_in_list(trx);
  76. }
  77. trx->error_state = DB_SUCCESS;
  78. if (trx->has_logged()) {
  79. ut_ad(trx->rsegs.m_redo.rseg != 0
  80. || trx->rsegs.m_noredo.rseg != 0);
  81. thr = pars_complete_graph_for_exec(roll_node, trx, heap, NULL);
  82. ut_a(thr == que_fork_start_command(
  83. static_cast<que_fork_t*>(que_node_get_parent(thr))));
  84. que_run_threads(thr);
  85. ut_a(roll_node->undo_thr != NULL);
  86. que_run_threads(roll_node->undo_thr);
  87. /* Free the memory reserved by the undo graph. */
  88. que_graph_free(static_cast<que_t*>(
  89. roll_node->undo_thr->common.parent));
  90. }
  91. if (savept == NULL) {
  92. trx_rollback_finish(trx);
  93. MONITOR_INC(MONITOR_TRX_ROLLBACK);
  94. } else {
  95. trx->lock.que_state = TRX_QUE_RUNNING;
  96. MONITOR_INC(MONITOR_TRX_ROLLBACK_SAVEPOINT);
  97. }
  98. ut_a(trx->error_state == DB_SUCCESS);
  99. ut_a(trx->lock.que_state == TRX_QUE_RUNNING);
  100. mem_heap_free(heap);
  101. /* There might be work for utility threads.*/
  102. srv_active_wake_master_thread();
  103. MONITOR_DEC(MONITOR_TRX_ACTIVE);
  104. }
  105. /*******************************************************************//**
  106. Rollback a transaction to a given savepoint or do a complete rollback.
  107. @return error code or DB_SUCCESS */
  108. dberr_t
  109. trx_rollback_to_savepoint(
  110. /*======================*/
  111. trx_t* trx, /*!< in: transaction handle */
  112. trx_savept_t* savept) /*!< in: pointer to savepoint undo number, if
  113. partial rollback requested, or NULL for
  114. complete rollback */
  115. {
  116. ut_ad(!trx_mutex_own(trx));
  117. trx_start_if_not_started_xa(trx, true);
  118. trx_rollback_to_savepoint_low(trx, savept);
  119. return(trx->error_state);
  120. }
  121. /*******************************************************************//**
  122. Rollback a transaction used in MySQL.
  123. @return error code or DB_SUCCESS */
  124. static
  125. dberr_t
  126. trx_rollback_for_mysql_low(
  127. /*=======================*/
  128. trx_t* trx) /*!< in/out: transaction */
  129. {
  130. trx->op_info = "rollback";
  131. /* If we are doing the XA recovery of prepared transactions,
  132. then the transaction object does not have an InnoDB session
  133. object, and we set a dummy session that we use for all MySQL
  134. transactions. */
  135. trx_rollback_to_savepoint_low(trx, NULL);
  136. trx->op_info = "";
  137. ut_a(trx->error_state == DB_SUCCESS);
  138. return(trx->error_state);
  139. }
  140. /** Rollback a transaction used in MySQL
  141. @param[in, out] trx transaction
  142. @return error code or DB_SUCCESS */
  143. dberr_t trx_rollback_for_mysql(trx_t* trx)
  144. {
  145. /* We are reading trx->state without holding trx_sys->mutex
  146. here, because the rollback should be invoked for a running
  147. active MySQL transaction (or recovered prepared transaction)
  148. that is associated with the current thread. */
  149. switch (trx->state) {
  150. case TRX_STATE_NOT_STARTED:
  151. trx->will_lock = 0;
  152. ut_ad(trx->in_mysql_trx_list);
  153. return(DB_SUCCESS);
  154. case TRX_STATE_ACTIVE:
  155. ut_ad(trx->in_mysql_trx_list);
  156. assert_trx_nonlocking_or_in_list(trx);
  157. return(trx_rollback_for_mysql_low(trx));
  158. case TRX_STATE_PREPARED:
  159. ut_ad(!trx_is_autocommit_non_locking(trx));
  160. if (trx->has_logged_persistent()) {
  161. /* Change the undo log state back from
  162. TRX_UNDO_PREPARED to TRX_UNDO_ACTIVE
  163. so that if the system gets killed,
  164. recovery will perform the rollback. */
  165. trx_undo_ptr_t* undo_ptr = &trx->rsegs.m_redo;
  166. mtr_t mtr;
  167. mtr.start();
  168. mutex_enter(&trx->rsegs.m_redo.rseg->mutex);
  169. if (undo_ptr->insert_undo != NULL) {
  170. trx_undo_set_state_at_prepare(
  171. trx, undo_ptr->insert_undo,
  172. true, &mtr);
  173. }
  174. if (undo_ptr->update_undo != NULL) {
  175. trx_undo_set_state_at_prepare(
  176. trx, undo_ptr->update_undo,
  177. true, &mtr);
  178. }
  179. mutex_exit(&trx->rsegs.m_redo.rseg->mutex);
  180. /* Persist the XA ROLLBACK, so that crash
  181. recovery will replay the rollback in case
  182. the redo log gets applied past this point. */
  183. mtr.commit();
  184. ut_ad(mtr.commit_lsn() > 0);
  185. }
  186. #ifdef ENABLED_DEBUG_SYNC
  187. if (trx->mysql_thd == NULL) {
  188. /* We could be executing XA ROLLBACK after
  189. XA PREPARE and a server restart. */
  190. } else if (!trx->has_logged_persistent()) {
  191. /* innobase_close_connection() may roll back a
  192. transaction that did not generate any
  193. persistent undo log. The DEBUG_SYNC
  194. would cause an assertion failure for a
  195. disconnected thread.
  196. NOTE: InnoDB will not know about the XID
  197. if no persistent undo log was generated. */
  198. } else {
  199. DEBUG_SYNC_C("trx_xa_rollback");
  200. }
  201. #endif /* ENABLED_DEBUG_SYNC */
  202. return(trx_rollback_for_mysql_low(trx));
  203. case TRX_STATE_COMMITTED_IN_MEMORY:
  204. check_trx_state(trx);
  205. break;
  206. }
  207. ut_error;
  208. return(DB_CORRUPTION);
  209. }
  210. /*******************************************************************//**
  211. Rollback the latest SQL statement for MySQL.
  212. @return error code or DB_SUCCESS */
  213. dberr_t
  214. trx_rollback_last_sql_stat_for_mysql(
  215. /*=================================*/
  216. trx_t* trx) /*!< in/out: transaction */
  217. {
  218. dberr_t err;
  219. /* We are reading trx->state without holding trx_sys->mutex
  220. here, because the statement rollback should be invoked for a
  221. running active MySQL transaction that is associated with the
  222. current thread. */
  223. ut_ad(trx->in_mysql_trx_list);
  224. switch (trx->state) {
  225. case TRX_STATE_NOT_STARTED:
  226. return(DB_SUCCESS);
  227. case TRX_STATE_ACTIVE:
  228. assert_trx_nonlocking_or_in_list(trx);
  229. trx->op_info = "rollback of SQL statement";
  230. err = trx_rollback_to_savepoint(
  231. trx, &trx->last_sql_stat_start);
  232. if (trx->fts_trx != NULL) {
  233. fts_savepoint_rollback_last_stmt(trx);
  234. }
  235. /* The following call should not be needed,
  236. but we play it safe: */
  237. trx_mark_sql_stat_end(trx);
  238. trx->op_info = "";
  239. return(err);
  240. case TRX_STATE_PREPARED:
  241. case TRX_STATE_COMMITTED_IN_MEMORY:
  242. /* The statement rollback is only allowed on an ACTIVE
  243. transaction, not a PREPARED or COMMITTED one. */
  244. break;
  245. }
  246. ut_error;
  247. return(DB_CORRUPTION);
  248. }
  249. /*******************************************************************//**
  250. Search for a savepoint using name.
  251. @return savepoint if found else NULL */
  252. static
  253. trx_named_savept_t*
  254. trx_savepoint_find(
  255. /*===============*/
  256. trx_t* trx, /*!< in: transaction */
  257. const char* name) /*!< in: savepoint name */
  258. {
  259. trx_named_savept_t* savep;
  260. for (savep = UT_LIST_GET_FIRST(trx->trx_savepoints);
  261. savep != NULL;
  262. savep = UT_LIST_GET_NEXT(trx_savepoints, savep)) {
  263. if (0 == ut_strcmp(savep->name, name)) {
  264. return(savep);
  265. }
  266. }
  267. return(NULL);
  268. }
  269. /*******************************************************************//**
  270. Frees a single savepoint struct. */
  271. static
  272. void
  273. trx_roll_savepoint_free(
  274. /*=====================*/
  275. trx_t* trx, /*!< in: transaction handle */
  276. trx_named_savept_t* savep) /*!< in: savepoint to free */
  277. {
  278. UT_LIST_REMOVE(trx->trx_savepoints, savep);
  279. ut_free(savep->name);
  280. ut_free(savep);
  281. }
  282. /*******************************************************************//**
  283. Frees savepoint structs starting from savep. */
  284. void
  285. trx_roll_savepoints_free(
  286. /*=====================*/
  287. trx_t* trx, /*!< in: transaction handle */
  288. trx_named_savept_t* savep) /*!< in: free all savepoints starting
  289. with this savepoint i*/
  290. {
  291. while (savep != NULL) {
  292. trx_named_savept_t* next_savep;
  293. next_savep = UT_LIST_GET_NEXT(trx_savepoints, savep);
  294. trx_roll_savepoint_free(trx, savep);
  295. savep = next_savep;
  296. }
  297. }
  298. /*******************************************************************//**
  299. Rolls back a transaction back to a named savepoint. Modifications after the
  300. savepoint are undone but InnoDB does NOT release the corresponding locks
  301. which are stored in memory. If a lock is 'implicit', that is, a new inserted
  302. row holds a lock where the lock information is carried by the trx id stored in
  303. the row, these locks are naturally released in the rollback. Savepoints which
  304. were set after this savepoint are deleted.
  305. @return if no savepoint of the name found then DB_NO_SAVEPOINT,
  306. otherwise DB_SUCCESS */
  307. static MY_ATTRIBUTE((nonnull, warn_unused_result))
  308. dberr_t
  309. trx_rollback_to_savepoint_for_mysql_low(
  310. /*====================================*/
  311. trx_t* trx, /*!< in/out: transaction */
  312. trx_named_savept_t* savep, /*!< in/out: savepoint */
  313. int64_t* mysql_binlog_cache_pos)
  314. /*!< out: the MySQL binlog
  315. cache position corresponding
  316. to this savepoint; MySQL needs
  317. this information to remove the
  318. binlog entries of the queries
  319. executed after the savepoint */
  320. {
  321. dberr_t err;
  322. ut_ad(trx_state_eq(trx, TRX_STATE_ACTIVE));
  323. ut_ad(trx->in_mysql_trx_list);
  324. /* Free all savepoints strictly later than savep. */
  325. trx_roll_savepoints_free(
  326. trx, UT_LIST_GET_NEXT(trx_savepoints, savep));
  327. *mysql_binlog_cache_pos = savep->mysql_binlog_cache_pos;
  328. trx->op_info = "rollback to a savepoint";
  329. err = trx_rollback_to_savepoint(trx, &savep->savept);
  330. /* Store the current undo_no of the transaction so that
  331. we know where to roll back if we have to roll back the
  332. next SQL statement: */
  333. trx_mark_sql_stat_end(trx);
  334. trx->op_info = "";
  335. #ifdef WITH_WSREP
  336. if (wsrep_on(trx->mysql_thd) &&
  337. trx->lock.was_chosen_as_deadlock_victim) {
  338. trx->lock.was_chosen_as_deadlock_victim = FALSE;
  339. }
  340. #endif
  341. return(err);
  342. }
  343. /*******************************************************************//**
  344. Rolls back a transaction back to a named savepoint. Modifications after the
  345. savepoint are undone but InnoDB does NOT release the corresponding locks
  346. which are stored in memory. If a lock is 'implicit', that is, a new inserted
  347. row holds a lock where the lock information is carried by the trx id stored in
  348. the row, these locks are naturally released in the rollback. Savepoints which
  349. were set after this savepoint are deleted.
  350. @return if no savepoint of the name found then DB_NO_SAVEPOINT,
  351. otherwise DB_SUCCESS */
  352. dberr_t
  353. trx_rollback_to_savepoint_for_mysql(
  354. /*================================*/
  355. trx_t* trx, /*!< in: transaction handle */
  356. const char* savepoint_name, /*!< in: savepoint name */
  357. int64_t* mysql_binlog_cache_pos) /*!< out: the MySQL binlog cache
  358. position corresponding to this
  359. savepoint; MySQL needs this
  360. information to remove the
  361. binlog entries of the queries
  362. executed after the savepoint */
  363. {
  364. trx_named_savept_t* savep;
  365. /* We are reading trx->state without holding trx_sys->mutex
  366. here, because the savepoint rollback should be invoked for a
  367. running active MySQL transaction that is associated with the
  368. current thread. */
  369. ut_ad(trx->in_mysql_trx_list);
  370. savep = trx_savepoint_find(trx, savepoint_name);
  371. if (savep == NULL) {
  372. return(DB_NO_SAVEPOINT);
  373. }
  374. switch (trx->state) {
  375. case TRX_STATE_NOT_STARTED:
  376. ib::error() << "Transaction has a savepoint "
  377. << savep->name
  378. << " though it is not started";
  379. return(DB_ERROR);
  380. case TRX_STATE_ACTIVE:
  381. return(trx_rollback_to_savepoint_for_mysql_low(
  382. trx, savep, mysql_binlog_cache_pos));
  383. case TRX_STATE_PREPARED:
  384. case TRX_STATE_COMMITTED_IN_MEMORY:
  385. /* The savepoint rollback is only allowed on an ACTIVE
  386. transaction, not a PREPARED or COMMITTED one. */
  387. break;
  388. }
  389. ut_error;
  390. return(DB_CORRUPTION);
  391. }
  392. /*******************************************************************//**
  393. Creates a named savepoint. If the transaction is not yet started, starts it.
  394. If there is already a savepoint of the same name, this call erases that old
  395. savepoint and replaces it with a new. Savepoints are deleted in a transaction
  396. commit or rollback.
  397. @return always DB_SUCCESS */
  398. dberr_t
  399. trx_savepoint_for_mysql(
  400. /*====================*/
  401. trx_t* trx, /*!< in: transaction handle */
  402. const char* savepoint_name, /*!< in: savepoint name */
  403. int64_t binlog_cache_pos) /*!< in: MySQL binlog cache
  404. position corresponding to this
  405. connection at the time of the
  406. savepoint */
  407. {
  408. trx_named_savept_t* savep;
  409. trx_start_if_not_started_xa(trx, false);
  410. savep = trx_savepoint_find(trx, savepoint_name);
  411. if (savep) {
  412. /* There is a savepoint with the same name: free that */
  413. UT_LIST_REMOVE(trx->trx_savepoints, savep);
  414. ut_free(savep->name);
  415. ut_free(savep);
  416. }
  417. /* Create a new savepoint and add it as the last in the list */
  418. savep = static_cast<trx_named_savept_t*>(
  419. ut_malloc_nokey(sizeof(*savep)));
  420. savep->name = mem_strdup(savepoint_name);
  421. savep->savept = trx_savept_take(trx);
  422. savep->mysql_binlog_cache_pos = binlog_cache_pos;
  423. UT_LIST_ADD_LAST(trx->trx_savepoints, savep);
  424. return(DB_SUCCESS);
  425. }
  426. /*******************************************************************//**
  427. Releases only the named savepoint. Savepoints which were set after this
  428. savepoint are left as is.
  429. @return if no savepoint of the name found then DB_NO_SAVEPOINT,
  430. otherwise DB_SUCCESS */
  431. dberr_t
  432. trx_release_savepoint_for_mysql(
  433. /*============================*/
  434. trx_t* trx, /*!< in: transaction handle */
  435. const char* savepoint_name) /*!< in: savepoint name */
  436. {
  437. trx_named_savept_t* savep;
  438. ut_ad(trx_state_eq(trx, TRX_STATE_ACTIVE, true)
  439. || trx_state_eq(trx, TRX_STATE_PREPARED, true));
  440. ut_ad(trx->in_mysql_trx_list);
  441. savep = trx_savepoint_find(trx, savepoint_name);
  442. if (savep != NULL) {
  443. trx_roll_savepoint_free(trx, savep);
  444. }
  445. return(savep != NULL ? DB_SUCCESS : DB_NO_SAVEPOINT);
  446. }
  447. /*******************************************************************//**
  448. Determines if this transaction is rolling back an incomplete transaction
  449. in crash recovery.
  450. @return TRUE if trx is an incomplete transaction that is being rolled
  451. back in crash recovery */
  452. ibool
  453. trx_is_recv(
  454. /*========*/
  455. const trx_t* trx) /*!< in: transaction */
  456. {
  457. return(trx == trx_roll_crash_recv_trx);
  458. }
  459. /*******************************************************************//**
  460. Returns a transaction savepoint taken at this point in time.
  461. @return savepoint */
  462. trx_savept_t
  463. trx_savept_take(
  464. /*============*/
  465. trx_t* trx) /*!< in: transaction */
  466. {
  467. trx_savept_t savept;
  468. savept.least_undo_no = trx->undo_no;
  469. return(savept);
  470. }
  471. /*******************************************************************//**
  472. Roll back an active transaction. */
  473. static
  474. void
  475. trx_rollback_active(
  476. /*================*/
  477. trx_t* trx) /*!< in/out: transaction */
  478. {
  479. mem_heap_t* heap;
  480. que_fork_t* fork;
  481. que_thr_t* thr;
  482. roll_node_t* roll_node;
  483. dict_table_t* table;
  484. ibool dictionary_locked = FALSE;
  485. const trx_id_t trx_id = trx->id;
  486. ut_ad(trx_id);
  487. heap = mem_heap_create(512);
  488. fork = que_fork_create(NULL, NULL, QUE_FORK_RECOVERY, heap);
  489. fork->trx = trx;
  490. thr = que_thr_create(fork, heap, NULL);
  491. roll_node = roll_node_create(heap);
  492. thr->child = roll_node;
  493. roll_node->common.parent = thr;
  494. trx->graph = fork;
  495. ut_a(thr == que_fork_start_command(fork));
  496. trx_roll_crash_recv_trx = trx;
  497. if (trx_get_dict_operation(trx) != TRX_DICT_OP_NONE) {
  498. row_mysql_lock_data_dictionary(trx);
  499. dictionary_locked = TRUE;
  500. }
  501. que_run_threads(thr);
  502. ut_a(roll_node->undo_thr != NULL);
  503. que_run_threads(roll_node->undo_thr);
  504. if (trx->error_state != DB_SUCCESS) {
  505. ut_ad(trx->error_state == DB_INTERRUPTED);
  506. ut_ad(!srv_is_being_started);
  507. ut_ad(!srv_undo_sources);
  508. ut_ad(srv_fast_shutdown);
  509. ut_ad(!dictionary_locked);
  510. que_graph_free(static_cast<que_t*>(
  511. roll_node->undo_thr->common.parent));
  512. goto func_exit;
  513. }
  514. trx_rollback_finish(thr_get_trx(roll_node->undo_thr));
  515. /* Free the memory reserved by the undo graph */
  516. que_graph_free(static_cast<que_t*>(
  517. roll_node->undo_thr->common.parent));
  518. ut_a(trx->lock.que_state == TRX_QUE_RUNNING);
  519. if (trx_get_dict_operation(trx) != TRX_DICT_OP_NONE
  520. && trx->table_id != 0) {
  521. ut_ad(dictionary_locked);
  522. /* If the transaction was for a dictionary operation,
  523. we drop the relevant table only if it is not flagged
  524. as DISCARDED. If it still exists. */
  525. table = dict_table_open_on_id(
  526. trx->table_id, TRUE, DICT_TABLE_OP_NORMAL);
  527. if (table && !dict_table_is_discarded(table)) {
  528. ib::warn() << "Dropping table '" << table->name
  529. << "', with id " << trx->table_id
  530. << " in recovery";
  531. dict_table_close_and_drop(trx, table);
  532. trx_commit_for_mysql(trx);
  533. }
  534. }
  535. ib::info() << "Rolled back recovered transaction " << trx_id;
  536. func_exit:
  537. if (dictionary_locked) {
  538. row_mysql_unlock_data_dictionary(trx);
  539. }
  540. mem_heap_free(heap);
  541. trx_roll_crash_recv_trx = NULL;
  542. }
  543. /*******************************************************************//**
  544. Rollback or clean up any resurrected incomplete transactions. It assumes
  545. that the caller holds the trx_sys_t::mutex and it will release the
  546. lock if it does a clean up or rollback.
  547. @return TRUE if the transaction was cleaned up or rolled back
  548. and trx_sys->mutex was released. */
  549. static
  550. ibool
  551. trx_rollback_resurrected(
  552. /*=====================*/
  553. trx_t* trx, /*!< in: transaction to rollback or clean */
  554. ibool* all) /*!< in/out: FALSE=roll back dictionary transactions;
  555. TRUE=roll back all non-PREPARED transactions */
  556. {
  557. ut_ad(trx_sys_mutex_own());
  558. /* The trx->is_recovered flag and trx->state are set
  559. atomically under the protection of the trx->mutex (and
  560. lock_sys->mutex) in lock_trx_release_locks(). We do not want
  561. to accidentally clean up a non-recovered transaction here. */
  562. trx_mutex_enter(trx);
  563. if (!trx->is_recovered) {
  564. func_exit:
  565. trx_mutex_exit(trx);
  566. return(FALSE);
  567. }
  568. switch (trx->state) {
  569. case TRX_STATE_COMMITTED_IN_MEMORY:
  570. trx_mutex_exit(trx);
  571. trx_sys_mutex_exit();
  572. ib::info() << "Cleaning up trx with id " << ib::hex(trx->id);
  573. trx_cleanup_at_db_startup(trx);
  574. trx_free_resurrected(trx);
  575. return(TRUE);
  576. case TRX_STATE_ACTIVE:
  577. if (!srv_is_being_started
  578. && !srv_undo_sources && srv_fast_shutdown) {
  579. fake_prepared:
  580. trx->state = TRX_STATE_PREPARED;
  581. trx_sys->n_prepared_trx++;
  582. trx_sys->n_prepared_recovered_trx++;
  583. *all = FALSE;
  584. goto func_exit;
  585. }
  586. trx_mutex_exit(trx);
  587. if (*all || trx_get_dict_operation(trx) != TRX_DICT_OP_NONE) {
  588. trx_sys_mutex_exit();
  589. trx_rollback_active(trx);
  590. if (trx->error_state != DB_SUCCESS) {
  591. ut_ad(trx->error_state == DB_INTERRUPTED);
  592. trx->error_state = DB_SUCCESS;
  593. ut_ad(!srv_undo_sources);
  594. ut_ad(srv_fast_shutdown);
  595. mutex_enter(&trx_sys->mutex);
  596. trx_mutex_enter(trx);
  597. goto fake_prepared;
  598. }
  599. trx_free_for_background(trx);
  600. return(TRUE);
  601. }
  602. return(FALSE);
  603. case TRX_STATE_PREPARED:
  604. goto func_exit;
  605. case TRX_STATE_NOT_STARTED:
  606. break;
  607. }
  608. ut_error;
  609. goto func_exit;
  610. }
  611. /** Report progress when rolling back a row of a recovered transaction.
  612. @return whether the rollback should be aborted due to pending shutdown */
  613. bool
  614. trx_roll_must_shutdown()
  615. {
  616. const trx_t* trx = trx_roll_crash_recv_trx;
  617. ut_ad(trx);
  618. ut_ad(trx_state_eq(trx, TRX_STATE_ACTIVE));
  619. ut_ad(trx->in_rollback);
  620. if (trx_get_dict_operation(trx) == TRX_DICT_OP_NONE
  621. && !srv_is_being_started
  622. && !srv_undo_sources && srv_fast_shutdown) {
  623. return true;
  624. }
  625. ib_time_t time = ut_time();
  626. mutex_enter(&trx_sys->mutex);
  627. mutex_enter(&recv_sys->mutex);
  628. if (recv_sys->report(time)) {
  629. ulint n_trx = 0;
  630. ulonglong n_rows = 0;
  631. for (const trx_t* t = UT_LIST_GET_FIRST(trx_sys->rw_trx_list);
  632. t != NULL;
  633. t = UT_LIST_GET_NEXT(trx_list, t)) {
  634. assert_trx_in_rw_list(t);
  635. if (t->is_recovered
  636. && trx_state_eq(t, TRX_STATE_ACTIVE)) {
  637. n_trx++;
  638. n_rows += t->undo_no;
  639. }
  640. }
  641. ib::info() << "To roll back: " << n_trx << " transactions, "
  642. << n_rows << " rows";
  643. sd_notifyf(0, "STATUS=To roll back: " ULINTPF " transactions, "
  644. "%llu rows", n_trx, n_rows);
  645. }
  646. mutex_exit(&recv_sys->mutex);
  647. mutex_exit(&trx_sys->mutex);
  648. return false;
  649. }
  650. /*******************************************************************//**
  651. Rollback or clean up any incomplete transactions which were
  652. encountered in crash recovery. If the transaction already was
  653. committed, then we clean up a possible insert undo log. If the
  654. transaction was not yet committed, then we roll it back. */
  655. void
  656. trx_rollback_or_clean_recovered(
  657. /*============================*/
  658. ibool all) /*!< in: FALSE=roll back dictionary transactions;
  659. TRUE=roll back all non-PREPARED transactions */
  660. {
  661. trx_t* trx;
  662. ut_a(srv_force_recovery < SRV_FORCE_NO_TRX_UNDO);
  663. if (trx_sys_get_n_rw_trx() == 0) {
  664. return;
  665. }
  666. if (all) {
  667. ib::info() << "Starting in background the rollback"
  668. " of recovered transactions";
  669. }
  670. /* Note: For XA recovered transactions, we rely on MySQL to
  671. do rollback. They will be in TRX_STATE_PREPARED state. If the server
  672. is shutdown and they are still lingering in trx_sys_t::trx_list
  673. then the shutdown will hang. */
  674. /* Loop over the transaction list as long as there are
  675. recovered transactions to clean up or recover. */
  676. do {
  677. trx_sys_mutex_enter();
  678. for (trx = UT_LIST_GET_FIRST(trx_sys->rw_trx_list);
  679. trx != NULL;
  680. trx = UT_LIST_GET_NEXT(trx_list, trx)) {
  681. assert_trx_in_rw_list(trx);
  682. /* If this function does a cleanup or rollback
  683. then it will release the trx_sys->mutex, therefore
  684. we need to reacquire it before retrying the loop. */
  685. if (trx_rollback_resurrected(trx, &all)) {
  686. trx_sys_mutex_enter();
  687. break;
  688. }
  689. }
  690. trx_sys_mutex_exit();
  691. } while (trx != NULL);
  692. if (all) {
  693. ib::info() << "Rollback of non-prepared transactions"
  694. " completed";
  695. }
  696. }
  697. /*******************************************************************//**
  698. Rollback or clean up any incomplete transactions which were
  699. encountered in crash recovery. If the transaction already was
  700. committed, then we clean up a possible insert undo log. If the
  701. transaction was not yet committed, then we roll it back.
  702. Note: this is done in a background thread.
  703. @return a dummy parameter */
  704. extern "C"
  705. os_thread_ret_t
  706. DECLARE_THREAD(trx_rollback_or_clean_all_recovered)(
  707. /*================================================*/
  708. void* arg MY_ATTRIBUTE((unused)))
  709. /*!< in: a dummy parameter required by
  710. os_thread_create */
  711. {
  712. my_thread_init();
  713. ut_ad(!srv_read_only_mode);
  714. #ifdef UNIV_PFS_THREAD
  715. pfs_register_thread(trx_rollback_clean_thread_key);
  716. #endif /* UNIV_PFS_THREAD */
  717. trx_rollback_or_clean_recovered(TRUE);
  718. trx_rollback_or_clean_is_active = false;
  719. my_thread_end();
  720. /* We count the number of threads in os_thread_exit(). A created
  721. thread should always use that to exit and not use return() to exit. */
  722. os_thread_exit();
  723. OS_THREAD_DUMMY_RETURN;
  724. }
  725. /** Try to truncate the undo logs.
  726. @param[in,out] trx transaction */
  727. static
  728. void
  729. trx_roll_try_truncate(trx_t* trx)
  730. {
  731. ut_ad(mutex_own(&trx->undo_mutex));
  732. trx->pages_undone = 0;
  733. undo_no_t undo_no = trx->undo_no;
  734. trx_undo_t* insert_undo = trx->rsegs.m_redo.insert_undo;
  735. trx_undo_t* update_undo = trx->rsegs.m_redo.update_undo;
  736. if (insert_undo || update_undo) {
  737. mutex_enter(&trx->rsegs.m_redo.rseg->mutex);
  738. if (insert_undo) {
  739. ut_ad(insert_undo->rseg == trx->rsegs.m_redo.rseg);
  740. trx_undo_truncate_end(insert_undo, undo_no, false);
  741. }
  742. if (update_undo) {
  743. ut_ad(update_undo->rseg == trx->rsegs.m_redo.rseg);
  744. trx_undo_truncate_end(update_undo, undo_no, false);
  745. }
  746. mutex_exit(&trx->rsegs.m_redo.rseg->mutex);
  747. }
  748. if (trx_undo_t* undo = trx->rsegs.m_noredo.undo) {
  749. ut_ad(undo->rseg == trx->rsegs.m_noredo.rseg);
  750. mutex_enter(&undo->rseg->mutex);
  751. trx_undo_truncate_end(undo, undo_no, true);
  752. mutex_exit(&undo->rseg->mutex);
  753. }
  754. #ifdef WITH_WSREP_OUT
  755. if (wsrep_on(trx->mysql_thd)) {
  756. trx->lock.was_chosen_as_deadlock_victim = FALSE;
  757. }
  758. #endif /* WITH_WSREP */
  759. }
  760. /***********************************************************************//**
  761. Pops the topmost undo log record in a single undo log and updates the info
  762. about the topmost record in the undo log memory struct.
  763. @return undo log record, the page s-latched */
  764. static
  765. trx_undo_rec_t*
  766. trx_roll_pop_top_rec(
  767. /*=================*/
  768. trx_t* trx, /*!< in: transaction */
  769. trx_undo_t* undo, /*!< in: undo log */
  770. mtr_t* mtr) /*!< in: mtr */
  771. {
  772. ut_ad(mutex_own(&trx->undo_mutex));
  773. page_t* undo_page = trx_undo_page_get_s_latched(
  774. page_id_t(undo->space, undo->top_page_no), mtr);
  775. ulint offset = undo->top_offset;
  776. trx_undo_rec_t* prev_rec = trx_undo_get_prev_rec(
  777. undo_page + offset, undo->hdr_page_no, undo->hdr_offset,
  778. true, mtr);
  779. if (prev_rec == NULL) {
  780. undo->empty = TRUE;
  781. } else {
  782. page_t* prev_rec_page = page_align(prev_rec);
  783. if (prev_rec_page != undo_page) {
  784. trx->pages_undone++;
  785. }
  786. undo->top_page_no = page_get_page_no(prev_rec_page);
  787. undo->top_offset = prev_rec - prev_rec_page;
  788. undo->top_undo_no = trx_undo_rec_get_undo_no(prev_rec);
  789. }
  790. return(undo_page + offset);
  791. }
  792. /** Get the last undo log record of a transaction (for rollback).
  793. @param[in,out] trx transaction
  794. @param[out] roll_ptr DB_ROLL_PTR to the undo record
  795. @param[in,out] heap memory heap for allocation
  796. @return undo log record copied to heap
  797. @retval NULL if none left or the roll_limit (savepoint) was reached */
  798. trx_undo_rec_t*
  799. trx_roll_pop_top_rec_of_trx(trx_t* trx, roll_ptr_t* roll_ptr, mem_heap_t* heap)
  800. {
  801. mutex_enter(&trx->undo_mutex);
  802. if (trx->pages_undone >= TRX_ROLL_TRUNC_THRESHOLD) {
  803. trx_roll_try_truncate(trx);
  804. }
  805. trx_undo_t* undo;
  806. trx_undo_t* insert = trx->rsegs.m_redo.insert_undo;
  807. trx_undo_t* update = trx->rsegs.m_redo.update_undo;
  808. trx_undo_t* temp = trx->rsegs.m_noredo.undo;
  809. const undo_no_t limit = trx->roll_limit;
  810. ut_ad(!insert || !update || insert->empty || update->empty
  811. || insert->top_undo_no != update->top_undo_no);
  812. ut_ad(!insert || !temp || insert->empty || temp->empty
  813. || insert->top_undo_no != temp->top_undo_no);
  814. ut_ad(!update || !temp || update->empty || temp->empty
  815. || update->top_undo_no != temp->top_undo_no);
  816. if (insert && !insert->empty && limit <= insert->top_undo_no) {
  817. if (update && !update->empty
  818. && update->top_undo_no > insert->top_undo_no) {
  819. undo = update;
  820. } else {
  821. undo = insert;
  822. }
  823. } else if (update && !update->empty && limit <= update->top_undo_no) {
  824. undo = update;
  825. } else if (temp && !temp->empty && limit <= temp->top_undo_no) {
  826. undo = temp;
  827. } else {
  828. trx_roll_try_truncate(trx);
  829. /* Mark any ROLLBACK TO SAVEPOINT completed, so that
  830. if the transaction object is committed and reused
  831. later, we will default to a full ROLLBACK. */
  832. trx->roll_limit = 0;
  833. ut_d(trx->in_rollback = false);
  834. mutex_exit(&trx->undo_mutex);
  835. return(NULL);
  836. }
  837. ut_ad(!undo->empty);
  838. ut_ad(limit <= undo->top_undo_no);
  839. *roll_ptr = trx_undo_build_roll_ptr(
  840. false, undo->rseg->id, undo->top_page_no, undo->top_offset);
  841. mtr_t mtr;
  842. mtr.start();
  843. trx_undo_rec_t* undo_rec = trx_roll_pop_top_rec(trx, undo, &mtr);
  844. const undo_no_t undo_no = trx_undo_rec_get_undo_no(undo_rec);
  845. if (trx_undo_rec_get_type(undo_rec) == TRX_UNDO_INSERT_REC) {
  846. ut_ad(undo == insert || undo == temp);
  847. *roll_ptr |= 1ULL << ROLL_PTR_INSERT_FLAG_POS;
  848. } else {
  849. ut_ad(undo == update || undo == temp);
  850. }
  851. ut_ad(trx_roll_check_undo_rec_ordering(
  852. undo_no, undo->rseg->space, trx));
  853. trx->undo_no = undo_no;
  854. trx->undo_rseg_space = undo->rseg->space;
  855. mutex_exit(&trx->undo_mutex);
  856. trx_undo_rec_t* undo_rec_copy = trx_undo_rec_copy(undo_rec, heap);
  857. mtr.commit();
  858. return(undo_rec_copy);
  859. }
  860. /****************************************************************//**
  861. Builds an undo 'query' graph for a transaction. The actual rollback is
  862. performed by executing this query graph like a query subprocedure call.
  863. The reply about the completion of the rollback will be sent by this
  864. graph.
  865. @return own: the query graph */
  866. static
  867. que_t*
  868. trx_roll_graph_build(
  869. /*=================*/
  870. trx_t* trx) /*!< in/out: transaction */
  871. {
  872. mem_heap_t* heap;
  873. que_fork_t* fork;
  874. que_thr_t* thr;
  875. ut_ad(trx_mutex_own(trx));
  876. heap = mem_heap_create(512);
  877. fork = que_fork_create(NULL, NULL, QUE_FORK_ROLLBACK, heap);
  878. fork->trx = trx;
  879. thr = que_thr_create(fork, heap, NULL);
  880. thr->child = row_undo_node_create(trx, thr, heap);
  881. return(fork);
  882. }
  883. /*********************************************************************//**
  884. Starts a rollback operation, creates the UNDO graph that will do the
  885. actual undo operation.
  886. @return query graph thread that will perform the UNDO operations. */
  887. static
  888. que_thr_t*
  889. trx_rollback_start(
  890. /*===============*/
  891. trx_t* trx, /*!< in: transaction */
  892. ib_id_t roll_limit) /*!< in: rollback to undo no (for
  893. partial undo), 0 if we are rolling back
  894. the entire transaction */
  895. {
  896. ut_ad(trx_mutex_own(trx));
  897. /* Initialize the rollback field in the transaction */
  898. ut_ad(!trx->roll_limit);
  899. ut_ad(!trx->in_rollback);
  900. trx->roll_limit = roll_limit;
  901. ut_d(trx->in_rollback = true);
  902. ut_a(trx->roll_limit <= trx->undo_no);
  903. trx->pages_undone = 0;
  904. /* Build a 'query' graph which will perform the undo operations */
  905. que_t* roll_graph = trx_roll_graph_build(trx);
  906. trx->graph = roll_graph;
  907. trx->lock.que_state = TRX_QUE_ROLLING_BACK;
  908. return(que_fork_start_command(roll_graph));
  909. }
  910. /****************************************************************//**
  911. Finishes a transaction rollback. */
  912. static
  913. void
  914. trx_rollback_finish(
  915. /*================*/
  916. trx_t* trx) /*!< in: transaction */
  917. {
  918. trx_commit(trx);
  919. trx->mod_tables.clear();
  920. trx->lock.que_state = TRX_QUE_RUNNING;
  921. }
  922. /*********************************************************************//**
  923. Creates a rollback command node struct.
  924. @return own: rollback node struct */
  925. roll_node_t*
  926. roll_node_create(
  927. /*=============*/
  928. mem_heap_t* heap) /*!< in: mem heap where created */
  929. {
  930. roll_node_t* node;
  931. node = static_cast<roll_node_t*>(mem_heap_zalloc(heap, sizeof(*node)));
  932. node->state = ROLL_NODE_SEND;
  933. node->common.type = QUE_NODE_ROLLBACK;
  934. return(node);
  935. }
  936. /***********************************************************//**
  937. Performs an execution step for a rollback command node in a query graph.
  938. @return query thread to run next, or NULL */
  939. que_thr_t*
  940. trx_rollback_step(
  941. /*==============*/
  942. que_thr_t* thr) /*!< in: query thread */
  943. {
  944. roll_node_t* node;
  945. node = static_cast<roll_node_t*>(thr->run_node);
  946. ut_ad(que_node_get_type(node) == QUE_NODE_ROLLBACK);
  947. if (thr->prev_node == que_node_get_parent(node)) {
  948. node->state = ROLL_NODE_SEND;
  949. }
  950. if (node->state == ROLL_NODE_SEND) {
  951. trx_t* trx;
  952. ib_id_t roll_limit;
  953. trx = thr_get_trx(thr);
  954. trx_mutex_enter(trx);
  955. node->state = ROLL_NODE_WAIT;
  956. ut_a(node->undo_thr == NULL);
  957. roll_limit = node->partial ? node->savept.least_undo_no : 0;
  958. trx_commit_or_rollback_prepare(trx);
  959. node->undo_thr = trx_rollback_start(trx, roll_limit);
  960. trx_mutex_exit(trx);
  961. } else {
  962. ut_ad(node->state == ROLL_NODE_WAIT);
  963. thr->run_node = que_node_get_parent(node);
  964. }
  965. return(thr);
  966. }