List:Commits« Previous MessageNext Message »
From:Sunny Bains Date:May 5 2010 6:31am
Subject:bzr commit into mysql-trunk-innodb branch (Sunny.Bains:3046)
View as plain text  
#At file:///Users/sunny/innodb/bzr/kernel_mutex_split/ based on revid:sunny.bains@stripped

 3046 Sunny Bains	2010-05-05
      Split trx_sys->mutex from kernel mutex. Some simple testing using Sysbench. 
      This is work in progress code.

    modified:
      storage/innobase/include/sync0sync.h
      storage/innobase/include/trx0sys.h
      storage/innobase/include/trx0sys.ic
      storage/innobase/include/univ.i
      storage/innobase/read/read0read.c
      storage/innobase/row/row0sel.c
      storage/innobase/srv/srv0start.c
      storage/innobase/sync/sync0sync.c
      storage/innobase/trx/trx0purge.c
      storage/innobase/trx/trx0rseg.c
      storage/innobase/trx/trx0sys.c
      storage/innobase/trx/trx0trx.c
      storage/innobase/usr/usr0sess.c
=== modified file 'storage/innobase/include/sync0sync.h'
--- a/storage/innobase/include/sync0sync.h	revid:sunny.bains@stripped
+++ b/storage/innobase/include/sync0sync.h	revid:sunny.bains@stripped
@@ -588,6 +588,9 @@ Kernel mutex				If a kernel operation ne
 |					fsp x-latch before acquiring the kernel
 |					mutex.
 V
+trx_sys_mutex				Mutex protecting trx_sys_t
+|
+V
 Threads mutex				Thread scheduling mutex
 |
 V
@@ -661,9 +664,10 @@ or row lock! */
 /*------------------------------------- MySQL binlog mutex */
 /*-------------------------------*/
 #define	SYNC_KERNEL		300
-#define SYNC_THREADS		299
-#define SYNC_REC_LOCK		298
-#define	SYNC_TRX_LOCK_HEAP	297
+#define SYNC_TRX_SYS		299
+#define SYNC_THREADS		298
+#define SYNC_REC_LOCK		297
+#define	SYNC_TRX_LOCK_HEAP	296
 #define SYNC_TRX_SYS_HEADER	290
 #define SYNC_LOG		170
 #define SYNC_LOG_FLUSH_ORDER	147

=== modified file 'storage/innobase/include/trx0sys.h'
--- a/storage/innobase/include/trx0sys.h	revid:sunny.bains@stripped
+++ b/storage/innobase/include/trx0sys.h	revid:sunny.bains@stripped
@@ -129,11 +129,17 @@ void
 trx_sys_init_at_db_start(void);
 /*==========================*/
 /*****************************************************************//**
-Creates and initializes the transaction system at the database creation. */
+Creates the trx_sys instance and initializes its mutex only. */
 UNIV_INTERN
 void
 trx_sys_create(void);
 /*================*/
+/*****************************************************************//**
+Creates and initializes the transaction system at the database creation. */
+UNIV_INTERN
+void
+trx_sys_create_sys_pages(void);
+/*==========================*/
 /****************************************************************//**
 Looks for a free slot for a rollback segment in the trx system file copy.
 @return	slot index or ULINT_UNDEFINED if not found */
@@ -598,6 +604,8 @@ struct trx_doublewrite_struct{
 /** The transaction system central memory data structure; protected by the
 kernel mutex */
 struct trx_sys_struct{
+	mutex_t		mutex;		/*!< mutex protecting all the fields
+					in this structure */
 	trx_id_t	max_trx_id;	/*!< The smallest number not yet
 					assigned as a transaction id or
 					transaction number */
@@ -632,6 +640,19 @@ page is updated */
 #define TRX_SYS_TRX_ID_WRITE_MARGIN	256
 #endif /* !UNIV_HOTBACKUP */
 
+/** Test if trx_sys->mutex mutex is owned. */
+#define trx_sys_mutex_own() mutex_own(&trx_sys->mutex)
+
+/** Acquire the trx_sys->mutex. */
+#define trx_sys_mutex_enter() do {		\
+	mutex_enter(&trx_sys->mutex);		\
+} while (0)
+
+/** Release the trx_sys->mutex. */
+#define trx_sys_mutex_exit() do {		\
+	mutex_exit(&trx_sys->mutex);		\
+} while (0)
+
 #ifndef UNIV_NONINL
 #include "trx0sys.ic"
 #endif

=== modified file 'storage/innobase/include/trx0sys.ic'
--- a/storage/innobase/include/trx0sys.ic	revid:sunny.bains@stripped
+++ b/storage/innobase/include/trx0sys.ic	revid:sunny.bains@stripped
@@ -80,7 +80,6 @@ trx_sys_get_nth_rseg(
 	trx_sys_t*	sys,	/*!< in: trx system */
 	ulint		n)	/*!< in: index of slot */
 {
-	ut_ad(mutex_own(&(kernel_mutex)));
 	ut_ad(n < TRX_SYS_N_RSEGS);
 
 	return(sys->rseg_array[n]);
@@ -137,7 +136,6 @@ trx_sysf_rseg_get_space(
 	ulint		i,		/*!< in: slot index == rseg id */
 	mtr_t*		mtr)		/*!< in: mtr */
 {
-	ut_ad(mutex_own(&(kernel_mutex)));
 	ut_ad(sys_header);
 	ut_ad(i < TRX_SYS_N_RSEGS);
 
@@ -159,7 +157,6 @@ trx_sysf_rseg_get_page_no(
 	mtr_t*		mtr)		/*!< in: mtr */
 {
 	ut_ad(sys_header);
-	ut_ad(mutex_own(&(kernel_mutex)));
 	ut_ad(i < TRX_SYS_N_RSEGS);
 
 	return(mtr_read_ulint(sys_header + TRX_SYS_RSEGS
@@ -179,7 +176,6 @@ trx_sysf_rseg_set_space(
 	ulint		space,		/*!< in: space id */
 	mtr_t*		mtr)		/*!< in: mtr */
 {
-	ut_ad(mutex_own(&(kernel_mutex)));
 	ut_ad(sys_header);
 	ut_ad(i < TRX_SYS_N_RSEGS);
 
@@ -203,7 +199,6 @@ trx_sysf_rseg_set_page_no(
 					slot is reset to unused */
 	mtr_t*		mtr)		/*!< in: mtr */
 {
-	ut_ad(mutex_own(&(kernel_mutex)));
 	ut_ad(sys_header);
 	ut_ad(i < TRX_SYS_N_RSEGS);
 
@@ -261,19 +256,23 @@ trx_get_on_id(
 {
 	trx_t*	trx;
 
-	ut_ad(mutex_own(&(kernel_mutex)));
+	trx_sys_mutex_enter();
 
 	trx = UT_LIST_GET_FIRST(trx_sys->trx_list);
 
 	while (trx != NULL) {
 		if (0 == ut_dulint_cmp(trx_id, trx->id)) {
 
+			trx_sys_mutex_exit();
+
 			return(trx);
 		}
 
 		trx = UT_LIST_GET_NEXT(trx_list, trx);
 	}
 
+	trx_sys_mutex_exit();
+
 	return(NULL);
 }
 
@@ -288,18 +287,22 @@ trx_id_t
 trx_list_get_min_trx_id(void)
 /*=========================*/
 {
+	dulint	id;
 	trx_t*	trx;
 
-	ut_ad(mutex_own(&(kernel_mutex)));
+	trx_sys_mutex_enter();
 
 	trx = UT_LIST_GET_LAST(trx_sys->trx_list);
 
 	if (trx == NULL) {
-
-		return(trx_sys->max_trx_id);
+		id = trx_sys->max_trx_id;
+	} else {
+		id = trx->id;
 	}
 
-	return(trx->id);
+	trx_sys_mutex_exit();
+
+	return(id);
 }
 
 /****************************************************************//**
@@ -313,13 +316,13 @@ trx_is_active(
 {
 	trx_t*	trx;
 
-	ut_ad(mutex_own(&(kernel_mutex)));
-
 	if (ut_dulint_cmp(trx_id, trx_list_get_min_trx_id()) < 0) {
 
 		return(FALSE);
 	}
 
+	trx_sys_mutex_enter();
+
 	if (ut_dulint_cmp(trx_id, trx_sys->max_trx_id) >= 0) {
 
 		/* There must be corruption: we return TRUE because this
@@ -327,10 +330,15 @@ trx_is_active(
 		and row_vers_impl_x_locked_off_kernel() and they have
 		diagnostic prints in this case */
 
+		trx_sys_mutex_exit();
+
 		return(TRUE);
 	}
 
+	trx_sys_mutex_exit();
+
 	trx = trx_get_on_id(trx_id);
+
 	if (trx && (trx->conc_state == TRX_ACTIVE
 		    || trx->conc_state == TRX_PREPARED)) {
 
@@ -350,7 +358,7 @@ trx_sys_get_new_trx_id(void)
 {
 	trx_id_t	id;
 
-	ut_ad(mutex_own(&kernel_mutex));
+	trx_sys_mutex_enter();
 
 	/* VERY important: after the database is started, max_trx_id value is
 	divisible by TRX_SYS_TRX_ID_WRITE_MARGIN, and the following if
@@ -369,6 +377,8 @@ trx_sys_get_new_trx_id(void)
 
 	UT_DULINT_INC(trx_sys->max_trx_id);
 
+	trx_sys_mutex_exit();
+
 	return(id);
 }
 
@@ -380,8 +390,6 @@ trx_id_t
 trx_sys_get_new_trx_no(void)
 /*========================*/
 {
-	ut_ad(mutex_own(&kernel_mutex));
-
 	return(trx_sys_get_new_trx_id());
 }
 #endif /* !UNIV_HOTBACKUP */

=== modified file 'storage/innobase/include/univ.i'
--- a/storage/innobase/include/univ.i	revid:sunny.bains@stripped
+++ b/storage/innobase/include/univ.i	revid:sunny.bains@stripped
@@ -237,6 +237,9 @@ operations (very slow); also UNIV_DEBUG 
 						requests to the log. */
 #endif
 
+#define UNIV_DEBUG
+#define UNIV_SYNC_DEBUG
+
 #define UNIV_BTR_DEBUG				/* check B-tree links */
 #define UNIV_LIGHT_MEM_DEBUG			/* light memory debugging */
 

=== modified file 'storage/innobase/read/read0read.c'
--- a/storage/innobase/read/read0read.c	revid:sunny.bains@stripped
+++ b/storage/innobase/read/read0read.c	revid:sunny.bains@stripped
@@ -180,7 +180,7 @@ read_view_oldest_copy_or_open_new(
 	ulint		n;
 	ulint		i;
 
-	ut_ad(mutex_own(&kernel_mutex));
+	ut_ad(trx_sys_mutex_own());
 
 	old_view = UT_LIST_GET_LAST(trx_sys->view_list);
 
@@ -261,7 +261,7 @@ read_view_open_now(
 	trx_t*		trx;
 	ulint		n;
 
-	ut_ad(mutex_own(&kernel_mutex));
+	ut_ad(trx_sys_mutex_own());
 
 	view = read_view_create_low(UT_LIST_GET_LEN(trx_sys->trx_list), heap);
 
@@ -326,9 +326,11 @@ read_view_close(
 /*============*/
 	read_view_t*	view)	/*!< in: read view */
 {
-	ut_ad(mutex_own(&kernel_mutex));
+	trx_sys_mutex_enter();
 
 	UT_LIST_REMOVE(view_list, trx_sys->view_list, view);
+
+	trx_sys_mutex_exit();
 }
 
 /*********************************************************************//**
@@ -342,16 +344,12 @@ read_view_close_for_mysql(
 {
 	ut_a(trx->global_read_view);
 
-	mutex_enter(&kernel_mutex);
-
 	read_view_close(trx->global_read_view);
 
 	mem_heap_empty(trx->global_read_view_heap);
 
 	trx->read_view = NULL;
 	trx->global_read_view = NULL;
-
-	mutex_exit(&kernel_mutex);
 }
 
 /*********************************************************************//**

=== modified file 'storage/innobase/row/row0sel.c'
--- a/storage/innobase/row/row0sel.c	revid:sunny.bains@stripped
+++ b/storage/innobase/row/row0sel.c	revid:sunny.bains@stripped
@@ -4542,8 +4542,6 @@ row_search_check_if_query_cache_permitte
 		return(FALSE);
 	}
 
-	mutex_enter(&kernel_mutex);
-
 	/* Start the transaction if it is not started yet */
 
 	trx_start_if_not_started_low(trx);
@@ -4553,6 +4551,8 @@ row_search_check_if_query_cache_permitte
 	We do not check what type locks there are on the table, though only
 	IX type locks actually would require ret = FALSE. */
 
+	mutex_enter(&kernel_mutex);
+
 	if (UT_LIST_GET_LEN(table->locks) == 0
 	    && ut_dulint_cmp(trx->id,
 			     table->query_cache_inv_trx_id) >= 0) {
@@ -4565,8 +4565,13 @@ row_search_check_if_query_cache_permitte
 		if (trx->isolation_level >= TRX_ISO_REPEATABLE_READ
 		    && !trx->read_view) {
 
+			trx_sys_mutex_enter();
+
 			trx->read_view = read_view_open_now(
 				trx->id, trx->global_read_view_heap);
+
+			trx_sys_mutex_exit();
+
 			trx->global_read_view = trx->read_view;
 		}
 	}

=== modified file 'storage/innobase/srv/srv0start.c'
--- a/storage/innobase/srv/srv0start.c	revid:sunny.bains@stripped
+++ b/storage/innobase/srv/srv0start.c	revid:sunny.bains@stripped
@@ -1531,6 +1531,8 @@ innobase_start_or_create_for_mysql(void)
 
 	trx_sys_file_format_init();
 
+	trx_sys_create();
+
 	if (create_new_db) {
 		mtr_start(&mtr);
 
@@ -1542,7 +1544,9 @@ innobase_start_or_create_for_mysql(void)
 		the first rollback segment before the double write buffer.
 		All the remaining rollback segments will be created later,
 		after the double write buffer has been created. */
-		trx_sys_create();
+		trx_sys_create_sys_pages();
+
+		trx_sys_init_at_db_start();
 
 		dict_create();
 

=== modified file 'storage/innobase/sync/sync0sync.c'
--- a/storage/innobase/sync/sync0sync.c	revid:sunny.bains@stripped
+++ b/storage/innobase/sync/sync0sync.c	revid:sunny.bains@stripped
@@ -1168,6 +1168,7 @@ sync_thread_add_level(
 	case SYNC_TRX_LOCK_HEAP:
 	case SYNC_KERNEL:
 	case SYNC_THREADS:
+	case SYNC_TRX_SYS:
 	case SYNC_IBUF_BITMAP_MUTEX:
 	case SYNC_RSEG:
 	case SYNC_TRX_UNDO:

=== modified file 'storage/innobase/trx/trx0purge.c'
--- a/storage/innobase/trx/trx0purge.c	revid:sunny.bains@stripped
+++ b/storage/innobase/trx/trx0purge.c	revid:sunny.bains@stripped
@@ -225,7 +225,7 @@ void
 trx_purge_sys_create(void)
 /*======================*/
 {
-	ut_ad(mutex_own(&kernel_mutex));
+	ibool	success;
 
 	purge_sys = mem_alloc(sizeof(trx_purge_t));
 
@@ -253,12 +253,16 @@ trx_purge_sys_create(void)
 
 	purge_sys->trx->is_purge = 1;
 
-	ut_a(trx_start_low(purge_sys->trx, ULINT_UNDEFINED));
+	success = trx_start_low(purge_sys->trx, ULINT_UNDEFINED);
+	ut_a(success);
 
 	purge_sys->query = trx_purge_graph_build();
 
-	purge_sys->view = read_view_oldest_copy_or_open_new(ut_dulint_zero,
-							    purge_sys->heap);
+	trx_sys_mutex_enter();
+
+	purge_sys->view = read_view_open_now(ut_dulint_zero, purge_sys->heap);
+
+	trx_sys_mutex_exit();
 }
 
 /************************************************************************
@@ -1125,12 +1129,12 @@ trx_purge(
 
 	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
@@ -1138,6 +1142,8 @@ trx_purge(
 	thread. */
 	srv_dml_needed_delay = 0; /* in microseconds; default: no delay */
 
+	trx_sys_mutex_enter();
+
 	/* 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'. */
@@ -1157,9 +1163,10 @@ trx_purge(
 		}
 	}
 
-	purge_sys->view = read_view_oldest_copy_or_open_new(ut_dulint_zero,
-							    purge_sys->heap);
-	mutex_exit(&kernel_mutex);
+	purge_sys->view = read_view_oldest_copy_or_open_new(
+		ut_dulint_zero, purge_sys->heap);
+
+	trx_sys_mutex_exit();
 
 	rw_lock_x_unlock(&(purge_sys->latch));
 

=== modified file 'storage/innobase/trx/trx0rseg.c'
--- a/storage/innobase/trx/trx0rseg.c	revid:sunny.bains@stripped
+++ b/storage/innobase/trx/trx0rseg.c	revid:sunny.bains@stripped
@@ -50,12 +50,16 @@ trx_rseg_get_on_id(
 {
 	trx_rseg_t*	rseg;
 
+	trx_sys_mutex_enter();
+
 	rseg = UT_LIST_GET_FIRST(trx_sys->rseg_list);
 
 	while (rseg && rseg->id != id) {
 		rseg = UT_LIST_GET_NEXT(rseg_list, rseg);
 	}
 
+	trx_sys_mutex_exit();
+
 	return(rseg);
 }
 
@@ -81,7 +85,6 @@ trx_rseg_header_create(
 	buf_block_t*	block;
 
 	ut_ad(mtr);
-	ut_ad(mutex_own(&kernel_mutex));
 	ut_ad(mtr_memo_contains(mtr, fil_space_get_latch(space, NULL),
 				MTR_MEMO_X_LOCK));
 
@@ -195,8 +198,6 @@ trx_rseg_mem_create(
 	trx_ulogf_t*	undo_log_hdr;
 	ulint		sum_of_undo_sizes;
 
-	ut_ad(mutex_own(&kernel_mutex));
-
 	rseg = mem_zalloc(sizeof(trx_rseg_t));
 
 	rseg->id = id;
@@ -271,8 +272,6 @@ trx_rseg_create_instance(
 			ulint		zip_size;
 			trx_rseg_t*	rseg = NULL;
 
-			ut_a(!trx_rseg_get_on_id(i));
-
 			space = trx_sysf_rseg_get_space(sys_header, i, mtr);
 
 			zip_size = space ? fil_space_get_zip_size(space) : 0;
@@ -300,11 +299,9 @@ trx_rseg_create(void)
 	mtr_start(&mtr);
 
 	/* To obey the latching order, acquire the file space
-	x-latch before the kernel mutex. */
+	x-latch before the trx_sys->mutex. */
 	mtr_x_lock(fil_space_get_latch(TRX_SYS_SPACE, NULL), &mtr);
 
-	mutex_enter(&kernel_mutex);
-
 	slot_no = trx_sysf_rseg_find_free(&mtr);
 
 	if (slot_no != ULINT_UNDEFINED) {
@@ -318,8 +315,6 @@ trx_rseg_create(void)
 
 		ut_a(page_no != FIL_NULL);
 
-		ut_ad(!trx_rseg_get_on_id(slot_no));
-
 		sys_header = trx_sysf_get(&mtr);
 
 		space = trx_sysf_rseg_get_space(sys_header, slot_no, &mtr);
@@ -330,7 +325,6 @@ trx_rseg_create(void)
 			slot_no, space, zip_size, page_no, &mtr);
 	}
 
-	mutex_exit(&kernel_mutex);
 	mtr_commit(&mtr);
 
 	return(rseg);

=== modified file 'storage/innobase/trx/trx0sys.c'
--- a/storage/innobase/trx/trx0sys.c	revid:sunny.bains@stripped
+++ b/storage/innobase/trx/trx0sys.c	revid:sunny.bains@stripped
@@ -131,6 +131,8 @@ static const ulint	FILE_FORMAT_NAME_N
 /* Key to register the mutex with performance schema */
 UNIV_INTERN mysql_pfs_key_t	trx_doublewrite_mutex_key;
 UNIV_INTERN mysql_pfs_key_t	file_format_max_mutex_key;
+/* Key to register the trx_sys->mutex with performance schema */
+UNIV_INTERN mysql_pfs_key_t	trx_sys_mutex_key;
 #endif /* UNIV_PFS_MUTEX */
 
 #ifndef UNIV_HOTBACKUP
@@ -655,10 +657,10 @@ void
 trx_sys_flush_max_trx_id(void)
 /*==========================*/
 {
-	trx_sysf_t*	sys_header;
 	mtr_t		mtr;
+	trx_sysf_t*	sys_header;
 
-	ut_ad(mutex_own(&kernel_mutex));
+	ut_ad(trx_sys_mutex_own());
 
 	mtr_start(&mtr);
 
@@ -843,15 +845,13 @@ trx_sysf_rseg_find_free(
 /*====================*/
 	mtr_t*	mtr)	/*!< in: mtr */
 {
-	trx_sysf_t*	sys_header;
-	ulint		page_no;
 	ulint		i;
-
-	ut_ad(mutex_own(&(kernel_mutex)));
+	trx_sysf_t*	sys_header;
 
 	sys_header = trx_sysf_get(mtr);
 
 	for (i = 0; i < TRX_SYS_N_RSEGS; i++) {
+		ulint	page_no;
 
 		page_no = trx_sysf_rseg_get_page_no(sys_header, i, mtr);
 
@@ -935,6 +935,7 @@ trx_sysf_create(
 	slot_no = trx_sysf_rseg_find_free(mtr);
 	page_no = trx_rseg_header_create(TRX_SYS_SPACE, 0, ULINT_MAX, slot_no,
 					 mtr);
+
 	ut_a(slot_no == TRX_SYS_SYSTEM_RSEG_ID);
 	ut_a(page_no == FSP_FIRST_RSEG_PAGE_NO);
 
@@ -952,17 +953,10 @@ trx_sys_init_at_db_start(void)
 	trx_sysf_t*	sys_header;
 	ib_int64_t	rows_to_undo	= 0;
 	const char*	unit		= "";
-	trx_t*		trx;
 	mtr_t		mtr;
 
 	mtr_start(&mtr);
 
-	ut_ad(trx_sys == NULL);
-
-	mutex_enter(&kernel_mutex);
-
-	trx_sys = mem_alloc(sizeof(trx_sys_t));
-
 	sys_header = trx_sysf_get(&mtr);
 
 	trx_rseg_list_and_array_init(sys_header, &mtr);
@@ -984,15 +978,19 @@ trx_sys_init_at_db_start(void)
 		2 * TRX_SYS_TRX_ID_WRITE_MARGIN);
 
 	UT_LIST_INIT(trx_sys->mysql_trx_list);
+
 	trx_dummy_sess = sess_open();
+
 	trx_lists_init_at_db_start();
 
 	if (UT_LIST_GET_LEN(trx_sys->trx_list) > 0) {
+		trx_t*	trx;
+
 		trx = UT_LIST_GET_FIRST(trx_sys->trx_list);
 
 		for (;;) {
 
-			if ( trx->conc_state != TRX_PREPARED) {
+			if (trx->conc_state != TRX_PREPARED) {
 				rows_to_undo += ut_conv_dulint_to_longlong(
 					trx->undo_no);
 			}
@@ -1024,18 +1022,30 @@ trx_sys_init_at_db_start(void)
 
 	trx_purge_sys_create();
 
-	mutex_exit(&kernel_mutex);
-
 	mtr_commit(&mtr);
 }
 
 /*****************************************************************//**
-Creates and initializes the transaction system at the database creation. */
+Creates the trx_sys instance and initializes its mutex only. */
 UNIV_INTERN
 void
 trx_sys_create(void)
 /*================*/
 {
+	ut_ad(trx_sys == NULL);
+
+	trx_sys = mem_zalloc(sizeof(*trx_sys));
+
+	mutex_create(trx_sys_mutex_key, &trx_sys->mutex, SYNC_TRX_SYS);
+}
+
+/*****************************************************************//**
+Creates and initializes the transaction system at the database creation. */
+UNIV_INTERN
+void
+trx_sys_create_sys_pages(void)
+/*==========================*/
+{
 	mtr_t	mtr;
 
 	mtr_start(&mtr);
@@ -1043,8 +1053,6 @@ trx_sys_create(void)
 	trx_sysf_create(&mtr);
 
 	mtr_commit(&mtr);
-
-	trx_sys_init_at_db_start();
 }
 
 /*****************************************************************//**

=== modified file 'storage/innobase/trx/trx0trx.c'
--- a/storage/innobase/trx/trx0trx.c	revid:sunny.bains@stripped
+++ b/storage/innobase/trx/trx0trx.c	revid:sunny.bains@stripped
@@ -93,7 +93,6 @@ trx_create(
 {
 	trx_t*	trx;
 
-	ut_ad(mutex_own(&kernel_mutex));
 	ut_ad(sess);
 
 	trx = mem_alloc(sizeof(trx_t));
@@ -105,7 +104,7 @@ trx_create(
 	trx->is_purge = 0;
 	trx->is_recovered = 0;
 	trx->conc_state = TRX_NOT_STARTED;
-	trx->start_time = time(NULL);
+	trx->start_time = ut_time();
 
 	trx->isolation_level = TRX_ISO_REPEATABLE_READ;
 
@@ -193,6 +192,17 @@ trx_create(
 }
 
 /********************************************************************//**
+Creates a transaction object for background operations by the master thread.
+@return	own: transaction object */
+UNIV_INTERN
+trx_t*
+trx_allocate_for_background(void)
+/*=============================*/
+{
+	return(trx_create(trx_dummy_sess));
+}
+
+/********************************************************************//**
 Creates a transaction object for MySQL.
 @return	own: transaction object */
 UNIV_INTERN
@@ -202,12 +212,16 @@ trx_allocate_for_mysql(void)
 {
 	trx_t*	trx;
 
-	mutex_enter(&kernel_mutex);
+	trx = trx_allocate_for_background();
 
-	trx = trx_create(trx_dummy_sess);
+	trx_sys_mutex_enter();
 
 	trx_n_mysql_transactions++;
 
+	trx_sys_mutex_exit();
+
+	mutex_enter(&kernel_mutex);
+
 	UT_LIST_ADD_FIRST(mysql_trx_list, trx_sys->mysql_trx_list, trx);
 
 	mutex_exit(&kernel_mutex);
@@ -220,25 +234,6 @@ trx_allocate_for_mysql(void)
 }
 
 /********************************************************************//**
-Creates a transaction object for background operations by the master thread.
-@return	own: transaction object */
-UNIV_INTERN
-trx_t*
-trx_allocate_for_background(void)
-/*=============================*/
-{
-	trx_t*	trx;
-
-	mutex_enter(&kernel_mutex);
-
-	trx = trx_create(trx_dummy_sess);
-
-	mutex_exit(&kernel_mutex);
-
-	return(trx);
-}
-
-/********************************************************************//**
 Releases the search latch if trx has reserved it. */
 UNIV_INTERN
 void
@@ -430,7 +425,6 @@ trx_lists_init_at_db_start(void)
 	trx_undo_t*	undo;
 	trx_t*		trx;
 
-	ut_ad(mutex_own(&kernel_mutex));
 	UT_LIST_INIT(trx_sys->trx_list);
 
 	/* Look from the rollback segments if there exist undo logs for
@@ -613,28 +607,31 @@ ulint
 trx_assign_rseg(void)
 /*=================*/
 {
-	trx_rseg_t*	rseg	= trx_sys->latest_rseg;
+	trx_rseg_t*	rseg;
 
-	ut_ad(mutex_own(&kernel_mutex));
-loop:
-	/* Get next rseg in a round-robin fashion */
+	trx_sys_mutex_enter();
 
-	rseg = UT_LIST_GET_NEXT(rseg_list, rseg);
+	rseg = trx_sys->latest_rseg;
 
-	if (rseg == NULL) {
-		rseg = UT_LIST_GET_FIRST(trx_sys->rseg_list);
-	}
+	do {
+		/* Get next rseg in a round-robin fashion */
 
-	/* If it is the SYSTEM rollback segment, and there exist others, skip
-	it */
+		rseg = UT_LIST_GET_NEXT(rseg_list, rseg);
 
-	if ((rseg->id == TRX_SYS_SYSTEM_RSEG_ID)
-	    && (UT_LIST_GET_LEN(trx_sys->rseg_list) > 1)) {
-		goto loop;
-	}
+		if (rseg == NULL) {
+			rseg = UT_LIST_GET_FIRST(trx_sys->rseg_list);
+		}
+
+		/* If it is the SYSTEM rollback segment, and there
+		exist others, skip it */
+
+	} while (rseg->id == TRX_SYS_SYSTEM_RSEG_ID
+	         && UT_LIST_GET_LEN(trx_sys->rseg_list) > 1);
 
 	trx_sys->latest_rseg = rseg;
 
+	trx_sys_mutex_exit();
+
 	return(rseg->id);
 }
 
@@ -652,14 +649,12 @@ trx_start_low(
 {
 	trx_rseg_t*	rseg;
 
-	ut_ad(mutex_own(&kernel_mutex));
 	ut_ad(trx->rseg == NULL);
 
 	if (trx->is_purge) {
 		trx->id = ut_dulint_zero;
 		trx->conc_state = TRX_ACTIVE;
 		trx->start_time = time(NULL);
-
 		return(TRUE);
 	}
 
@@ -682,10 +677,14 @@ trx_start_low(
 	trx->rseg = rseg;
 
 	trx->conc_state = TRX_ACTIVE;
-	trx->start_time = time(NULL);
+	trx->start_time = ut_time();
+
+	trx_sys_mutex_enter();
 
 	UT_LIST_ADD_FIRST(trx_list, trx_sys->trx_list, trx);
 
+	trx_sys_mutex_exit();
+
 	return(TRUE);
 }
 
@@ -711,12 +710,8 @@ trx_start(
 	generated by the same transaction, doesn't. */
 	trx->support_xa = thd_supports_xa(trx->mysql_thd);
 
-	mutex_enter(&kernel_mutex);
-
 	ret = trx_start_low(trx, rseg_id);
 
-	mutex_exit(&kernel_mutex);
-
 	return(ret);
 }
 
@@ -762,9 +757,7 @@ trx_commit_off_kernel(
 		undo = trx->update_undo;
 
 		if (undo) {
-			mutex_enter(&kernel_mutex);
-			trx->no = trx_sys_get_new_trx_no();
-			mutex_exit(&kernel_mutex);
+			trx->no = trx_sys_get_new_trx_id();
 
 			/* It is not necessary to obtain trx->undo_mutex here
 			because only a single OS thread is allowed to do the
@@ -992,16 +985,17 @@ trx_assign_read_view(
 		return(trx->read_view);
 	}
 
-	mutex_enter(&kernel_mutex);
-
 	if (!trx->read_view) {
+		trx_sys_mutex_enter();
+
 		trx->read_view = read_view_open_now(
 			trx->id, trx->global_read_view_heap);
+
+		trx_sys_mutex_exit();
+
 		trx->global_read_view = trx->read_view;
 	}
 
-	mutex_exit(&kernel_mutex);
-
 	return(trx->read_view);
 }
 

=== modified file 'storage/innobase/usr/usr0sess.c'
--- a/storage/innobase/usr/usr0sess.c	revid:sunny.bains@stripped
+++ b/storage/innobase/usr/usr0sess.c	revid:sunny.bains@stripped
@@ -41,8 +41,6 @@ sess_open(void)
 {
 	sess_t*	sess;
 
-	ut_ad(mutex_own(&kernel_mutex));
-
 	sess = mem_alloc(sizeof(sess_t));
 
 	sess->state = SESS_ACTIVE;


Attachment: [text/bzr-bundle] bzr/sunny.bains@oracle.com-20100505062049-na6ho1vvov7t2flc.bundle
Thread
bzr commit into mysql-trunk-innodb branch (Sunny.Bains:3046) Sunny Bains5 May