List:Commits« Previous MessageNext Message »
From:Sunny Bains Date:June 11 2010 1:33am
Subject:bzr commit into mysql-5.6-sunny branch (Sunny.Bains:3142)
View as plain text  
#At file:///Users/sunny/innodb/bzr-new/5.6/ based on revid:sunny.bains@stripped

 3142 Sunny Bains	2010-06-11
      Reduce lock mutex coverage. Remove where it is unnecessary.

    modified:
      storage/innobase/include/lock0lock.ic
      storage/innobase/include/row0vers.h
      storage/innobase/lock/lock0lock.c
      storage/innobase/row/row0vers.c
=== modified file 'storage/innobase/include/lock0lock.ic'
--- a/storage/innobase/include/lock0lock.ic	revid:sunny.bains@stripped
+++ b/storage/innobase/include/lock0lock.ic	revid:sunny.bains@stripped
@@ -81,7 +81,7 @@ lock_clust_rec_some_has_impl(
 {
 	trx_id_t	trx_id;
 
-	ut_ad(lock_mutex_own());
+	ut_ad(!lock_mutex_own());
 	ut_ad(dict_index_is_clust(index));
 	ut_ad(page_rec_is_user_rec(rec));
 

=== modified file 'storage/innobase/include/row0vers.h'
--- a/storage/innobase/include/row0vers.h	revid:sunny.bains@stripped
+++ b/storage/innobase/include/row0vers.h	revid:sunny.bains@stripped
@@ -37,13 +37,12 @@ Created 2/6/1997 Heikki Tuuri
 
 /*****************************************************************//**
 Finds out if an active transaction has inserted or modified a secondary
-index record. NOTE: the kernel mutex is temporarily released in this
-function!
+index record.
 @return NULL if committed, else the active transaction */
 UNIV_INTERN
 trx_t*
-row_vers_impl_x_locked_off_kernel(
-/*==============================*/
+row_vers_impl_x_locked(
+/*===================*/
 	const rec_t*	rec,	/*!< in: record in a secondary index */
 	dict_index_t*	index,	/*!< in: the secondary index */
 	const ulint*	offsets);/*!< in: rec_get_offsets(rec, index) */

=== modified file 'storage/innobase/lock/lock0lock.c'
--- a/storage/innobase/lock/lock0lock.c	revid:sunny.bains@stripped
+++ b/storage/innobase/lock/lock0lock.c	revid:sunny.bains@stripped
@@ -49,9 +49,9 @@ graph of transactions */
 #define LOCK_MAX_DEPTH_IN_DEADLOCK_CHECK 200
 
 /* When releasing transaction locks, this specifies how often we release
-the kernel mutex for a moment to give also others access to it */
+the lock mutex for a moment to give also others access to it */
 
-#define LOCK_RELEASE_KERNEL_INTERVAL	1000
+#define LOCK_RELEASE_INTERVAL		1000
 
 /* Safety margin when creating a new record lock: this many extra records
 can be inserted to the page without need to create a lock with a bigger
@@ -511,8 +511,7 @@ lock_clust_rec_cons_read_sees(
 	ut_ad(rec_offs_validate(rec, index, offsets));
 
 	/* NOTE that we call this function while holding the search
-	system latch. To obey the latching order we must NOT reserve the
-	kernel mutex here! */
+	system latch. */
 
 	trx_id = row_get_rec_trx_id(rec, index, offsets);
 
@@ -543,8 +542,7 @@ lock_sec_rec_cons_read_sees(
 	ut_ad(page_rec_is_user_rec(rec));
 
 	/* NOTE that we might call this function while holding the search
-	system latch. To obey the latching order we must NOT reserve the
-	kernel mutex here! */
+	system latch. */
 
 	if (recv_recovery_is_on()) {
 
@@ -1567,15 +1565,15 @@ index.
 @return	transaction which has the x-lock, or NULL */
 static
 trx_t*
-lock_sec_rec_some_has_impl_off_kernel(
-/*==================================*/
+lock_sec_rec_some_has_impl(
+/*=======================*/
 	const rec_t*	rec,	/*!< in: user record */
 	dict_index_t*	index,	/*!< in: secondary index */
 	const ulint*	offsets)/*!< in: rec_get_offsets(rec, index) */
 {
 	const page_t*	page = page_align(rec);
 
-	ut_ad(lock_mutex_own());
+	ut_ad(!lock_mutex_own());
 	ut_ad(!dict_index_is_clust(index));
 	ut_ad(page_rec_is_user_rec(rec));
 	ut_ad(rec_offs_validate(rec, index, offsets));
@@ -1605,7 +1603,7 @@ lock_sec_rec_some_has_impl_off_kernel(
 		return(NULL);
 	}
 
-	return(row_vers_impl_x_locked_off_kernel(rec, index, offsets));
+	return(row_vers_impl_x_locked(rec, index, offsets));
 }
 
 /*********************************************************************//**
@@ -4084,14 +4082,15 @@ lock_release(
 /*=========*/
 	trx_t*	trx)	/*!< in: transaction */
 {
-	dict_table_t*	table;
 	lock_t*		lock;
+	dict_table_t*	table;
+	ulint		count = 0;
 
 	ut_ad(lock_mutex_own());
 
 	for (lock = UT_LIST_GET_LAST(trx->lock.trx_locks);
 	     lock != NULL;
-	     lock = UT_LIST_GET_LAST(trx->lock.trx_locks)) {
+	     lock = UT_LIST_GET_LAST(trx->lock.trx_locks), ++count) {
 
 		if (lock_get_type_low(lock) == LOCK_REC) {
 			lock_rec_dequeue_from_page(lock);
@@ -4114,6 +4113,18 @@ lock_release(
 
 			lock_table_dequeue(lock);
 		}
+
+
+		if (count == LOCK_RELEASE_INTERVAL) {
+			/* Release the  mutex for a while, so that we
+			do not monopolize it */
+
+			lock_mutex_exit();
+
+			lock_mutex_enter();
+
+			count = 0;
+		}
 	}
 
 	ut_a(ib_vector_size(trx->autoinc_locks) == 0);
@@ -4409,22 +4420,22 @@ lock_get_n_rec_locks(void)
 
 /*********************************************************************//**
 Prints info of locks for all transactions.
-@return FALSE if not able to obtain kernel mutex
+@return FALSE if not able to obtain lock mutex
 and exits without printing info */
 UNIV_INTERN
 ibool
 lock_print_info_summary(
 /*====================*/
 	FILE*	file,	/*!< in: file where to print */
-	ibool   nowait)	/*!< in: whether to wait for the kernel mutex */
+	ibool   nowait)	/*!< in: whether to wait for the lock mutex */
 {
-	/* if nowait is FALSE, wait on the kernel mutex,
+	/* if nowait is FALSE, wait on the lock mutex,
 	otherwise return immediately if fail to obtain the
 	mutex. */
 	if (!nowait) {
 		lock_mutex_enter();
 	} else if (lock_mutex_enter_nowait()) {
-		fputs("FAIL TO OBTAIN KERNEL MUTEX, "
+		fputs("FAIL TO OBTAIN LOCK MUTEX, "
 		      "SKIP LOCK INFO PRINTING\n", file);
 		return(FALSE);
 	}
@@ -4711,10 +4722,10 @@ lock_rec_queue_validate(
 
 	heap_no = page_rec_get_heap_no(rec);
 
-	lock_mutex_enter();
-
 	if (!page_rec_is_user_rec(rec)) {
 
+		lock_mutex_enter();
+
 		lock = lock_rec_get_first(block, heap_no);
 
 		while (lock) {
@@ -4750,6 +4761,8 @@ lock_rec_queue_validate(
 
 		impl_trx = lock_clust_rec_some_has_impl(rec, index, offsets);
 
+		lock_mutex_enter();
+
 		if (impl_trx
 		    && lock_rec_other_has_expl_req(LOCK_S, 0, LOCK_WAIT,
 						   block, heap_no, impl_trx)) {
@@ -4757,13 +4770,11 @@ lock_rec_queue_validate(
 			ut_a(lock_rec_has_expl(LOCK_X | LOCK_REC_NOT_GAP,
 					       block, heap_no, impl_trx));
 		}
+
+		lock_mutex_exit();
 #if 0
 	} else {
 
-		/* The kernel mutex may get released temporarily in the
-		next function call: we have to release lock table mutex
-		to obey the latching order */
-
 		/* If this thread is holding the file space latch
 		(fil_space_t::latch), the following check WILL break
 		latching order and may cause a deadlock of threads. */
@@ -4789,7 +4800,7 @@ lock_rec_queue_validate(
 		record may need to wait for a lock on the
 		corresponding record in a secondary index. */
 
-		impl_trx = lock_sec_rec_some_has_impl_off_kernel(
+		impl_trx = lock_sec_rec_some_has_impl(
 			rec, index, offsets);
 
 		if (impl_trx
@@ -4802,6 +4813,8 @@ lock_rec_queue_validate(
 #endif
 	}
 
+	lock_mutex_enter();
+
 	lock = lock_rec_get_first(block, heap_no);
 
 	while (lock) {
@@ -5180,8 +5193,7 @@ lock_rec_insert_check_and_lock(
 
 /*********************************************************************//**
 If a transaction has an implicit x-lock on a record, but no explicit x-lock
-set on the record, sets one for it. NOTE that in the case of a secondary
-index, the kernel mutex may get temporarily released. */
+set on the record, sets one for it. */
 static
 void
 lock_rec_convert_impl_to_expl(
@@ -5193,7 +5205,7 @@ lock_rec_convert_impl_to_expl(
 {
 	trx_t*	impl_trx;
 
-	ut_ad(lock_mutex_own());
+	ut_ad(!lock_mutex_own());
 	ut_ad(page_rec_is_user_rec(rec));
 	ut_ad(rec_offs_validate(rec, index, offsets));
 	ut_ad(!page_rec_is_comp(rec) == !rec_offs_comp(offsets));
@@ -5201,13 +5213,14 @@ lock_rec_convert_impl_to_expl(
 	if (dict_index_is_clust(index)) {
 		impl_trx = lock_clust_rec_some_has_impl(rec, index, offsets);
 	} else {
-		impl_trx = lock_sec_rec_some_has_impl_off_kernel(
-			rec, index, offsets);
+		impl_trx = lock_sec_rec_some_has_impl(rec, index, offsets);
 	}
 
 	if (impl_trx) {
 		ulint	heap_no = page_rec_get_heap_no(rec);
 
+		lock_mutex_enter();
+
 		/* If the transaction has no explicit x-lock set on the
 		record, set one for it */
 
@@ -5218,6 +5231,8 @@ lock_rec_convert_impl_to_expl(
 				LOCK_REC | LOCK_X | LOCK_REC_NOT_GAP,
 				block, heap_no, index, impl_trx);
 		}
+
+		lock_mutex_exit();
 	}
 }
 
@@ -5258,15 +5273,15 @@ lock_clust_rec_modify_check_and_lock(
 		? rec_get_heap_no_new(rec)
 		: rec_get_heap_no_old(rec);
 
-	lock_mutex_enter();
-
-	ut_ad(lock_table_has(thr_get_trx(thr), index->table, LOCK_IX));
-
 	/* If a transaction has no explicit x-lock set on the record, set one
 	for it */
 
 	lock_rec_convert_impl_to_expl(block, rec, index, offsets);
 
+	lock_mutex_enter();
+
+	ut_ad(lock_table_has(thr_get_trx(thr), index->table, LOCK_IX));
+
 	err = lock_rec_lock(TRUE, LOCK_X | LOCK_REC_NOT_GAP,
 			    block, heap_no, index, thr);
 
@@ -5403,13 +5418,6 @@ lock_sec_rec_read_check_and_lock(
 
 	heap_no = page_rec_get_heap_no(rec);
 
-	lock_mutex_enter();
-
-	ut_ad(mode != LOCK_X
-	      || lock_table_has(thr_get_trx(thr), index->table, LOCK_IX));
-	ut_ad(mode != LOCK_S
-	      || lock_table_has(thr_get_trx(thr), index->table, LOCK_IS));
-
 	/* Some transaction may have an implicit x-lock on the record only
 	if the max trx id for the page >= min trx id for the trx list or a
 	database recovery is running. */
@@ -5422,6 +5430,13 @@ lock_sec_rec_read_check_and_lock(
 		lock_rec_convert_impl_to_expl(block, rec, index, offsets);
 	}
 
+	lock_mutex_enter();
+
+	ut_ad(mode != LOCK_X
+	      || lock_table_has(thr_get_trx(thr), index->table, LOCK_IX));
+	ut_ad(mode != LOCK_S
+	      || lock_table_has(thr_get_trx(thr), index->table, LOCK_IS));
+
 	err = lock_rec_lock(FALSE, mode | gap_mode,
 			    block, heap_no, index, thr);
 
@@ -5480,6 +5495,11 @@ lock_clust_rec_read_check_and_lock(
 
 	heap_no = page_rec_get_heap_no(rec);
 
+	if (UNIV_LIKELY(heap_no != PAGE_HEAP_NO_SUPREMUM)) {
+
+		lock_rec_convert_impl_to_expl(block, rec, index, offsets);
+	}
+
 	lock_mutex_enter();
 
 	ut_ad(mode != LOCK_X
@@ -5487,11 +5507,6 @@ lock_clust_rec_read_check_and_lock(
 	ut_ad(mode != LOCK_S
 	      || lock_table_has(thr_get_trx(thr), index->table, LOCK_IS));
 
-	if (UNIV_LIKELY(heap_no != PAGE_HEAP_NO_SUPREMUM)) {
-
-		lock_rec_convert_impl_to_expl(block, rec, index, offsets);
-	}
-
 	err = lock_rec_lock(FALSE, mode | gap_mode,
 			    block, heap_no, index, thr);
 

=== modified file 'storage/innobase/row/row0vers.c'
--- a/storage/innobase/row/row0vers.c	revid:sunny.bains@stripped
+++ b/storage/innobase/row/row0vers.c	revid:sunny.bains@stripped
@@ -48,13 +48,12 @@ Created 2/6/1997 Heikki Tuuri
 
 /*****************************************************************//**
 Finds out if an active transaction has inserted or modified a secondary
-index record. NOTE: the kernel mutex is temporarily released in this
-function!
+index record.
 @return NULL if committed, else the active transaction */
 UNIV_INTERN
 trx_t*
-row_vers_impl_x_locked_off_kernel(
-/*==============================*/
+row_vers_impl_x_locked(
+/*===================*/
 	const rec_t*	rec,	/*!< in: record in a secondary index */
 	dict_index_t*	index,	/*!< in: the secondary index */
 	const ulint*	offsets)/*!< in: rec_get_offsets(rec, index) */
@@ -75,14 +74,10 @@ row_vers_impl_x_locked_off_kernel(
 	mtr_t		mtr;
 	ulint		comp;
 
-	ut_ad(lock_mutex_own());
-
 #ifdef UNIV_SYNC_DEBUG
 	ut_ad(!rw_lock_own(&(purge_sys->latch), RW_LOCK_SHARED));
 #endif /* UNIV_SYNC_DEBUG */
 
-	lock_mutex_exit();
-
 	mtr_start(&mtr);
 
 	/* Search for the clustered index record: this is a time-consuming
@@ -106,7 +101,6 @@ row_vers_impl_x_locked_off_kernel(
 		a rollback we always undo the modifications to secondary index
 		records before the clustered index record. */
 
-		lock_mutex_enter();
 		mtr_commit(&mtr);
 
 		return(NULL);
@@ -119,8 +113,6 @@ row_vers_impl_x_locked_off_kernel(
 
 	mtr_s_lock(&purge_sys->latch, &mtr);
 
-	lock_mutex_enter();
-
 	trx = NULL;
 	if (!trx_is_active(trx_id)) {
 		/* The transaction that modified or inserted clust_rec is no
@@ -159,8 +151,6 @@ row_vers_impl_x_locked_off_kernel(
 		row_ext_t*	ext;
 		trx_id_t	prev_trx_id;
 
-		lock_mutex_exit();
-
 		/* While we retrieve an earlier version of clust_rec, we
 		release the kernel mutex, because it may take time to access
 		the disk. After the release, we have to check if the trx_id
@@ -176,7 +166,6 @@ row_vers_impl_x_locked_off_kernel(
 		mem_heap_free(heap2); /* free version and clust_offsets */
 
 		if (prev_version == NULL) {
-			lock_mutex_enter();
 			if (!trx_is_active(trx_id)) {
 				/* Transaction no longer active: no
 				implicit x-lock */
@@ -211,7 +200,6 @@ row_vers_impl_x_locked_off_kernel(
 		cannot hold any implicit lock. */
 		if (vers_del && 0 != ut_dulint_cmp(trx_id, prev_trx_id)) {
 
-			lock_mutex_enter();
 			break;
 		}
 
@@ -227,8 +215,6 @@ row_vers_impl_x_locked_off_kernel(
 		prev_version should be NULL. */
 		ut_a(entry);
 
-		lock_mutex_enter();
-
 		if (!trx_is_active(trx_id)) {
 			/* Transaction no longer active: no implicit x-lock */
 


Attachment: [text/bzr-bundle] bzr/sunny.bains@oracle.com-20100611013325-ugq8j4m1czu2li0w.bundle
Thread
bzr commit into mysql-5.6-sunny branch (Sunny.Bains:3142) Sunny Bains11 Jun