@@ -244,13 +244,6 @@ trx_sys_close(void);
244244@return whether the creation succeeded */
245245bool
246246trx_sys_create_rsegs ();
247- /* ****************************************************************/ /* *
248- Get the number of transaction in the system, independent of their state.
249- @return count of transactions in trx_sys_t::trx_list */
250- UNIV_INLINE
251- ulint
252- trx_sys_get_n_rw_trx (void );
253- /* ======================*/
254247
255248/* ********************************************************************
256249Check if there are any active (non-prepared) transactions.
@@ -506,6 +499,35 @@ class rw_trx_hash_t
506499 }
507500
508501
502+ /* *
503+ Destructor callback for lock-free allocator.
504+
505+ This destructor is used at shutdown. It frees remaining transaction
506+ objects.
507+
508+ XA PREPARED transactions may remain if they haven't been committed or
509+ rolled back. ACTIVE transactions may remain if startup was interrupted or
510+ server is running in read-only mode or for certain srv_force_recovery
511+ levels.
512+ */
513+
514+ static void rw_trx_hash_shutdown_destructor (uchar *arg)
515+ {
516+ rw_trx_hash_element_t *element=
517+ reinterpret_cast <rw_trx_hash_element_t *>(arg + LF_HASH_OVERHEAD);
518+ if (trx_t *trx= element->trx )
519+ {
520+ ut_ad (trx_state_eq (trx, TRX_STATE_PREPARED) ||
521+ (trx_state_eq (trx, TRX_STATE_ACTIVE) &&
522+ (!srv_was_started ||
523+ srv_read_only_mode ||
524+ srv_force_recovery >= SRV_FORCE_NO_TRX_UNDO)));
525+ trx_free_prepared (trx);
526+ }
527+ element->~rw_trx_hash_element_t ();
528+ }
529+
530+
509531 /* *
510532 Initializer callback for lock-free hash.
511533
@@ -522,6 +544,7 @@ class rw_trx_hash_t
522544 rw_trx_hash_element_t *element,
523545 trx_t *trx)
524546 {
547+ ut_ad (element->trx == 0 );
525548 element->trx = trx;
526549 element->id = trx->id ;
527550 trx->rw_trx_hash_element = element;
@@ -562,6 +585,7 @@ class rw_trx_hash_t
562585
563586 void destroy ()
564587 {
588+ hash.alloc .destructor = rw_trx_hash_shutdown_destructor;
565589 lf_hash_destroy (&hash);
566590 }
567591
0 commit comments