List:Internals« Previous MessageNext Message »
From:Jan Lindstrom Date:July 21 2005 10:44am
Subject:bk commit into 5.0 tree (jan:1.1965)
View as plain text  
Below is the list of changes that have just been committed into a local
5.0 repository of jan. When jan does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html

ChangeSet
  1.1965 05/07/21 13:44:34 jan@stripped +7 -0
  Implement MySQL framework to support consistent read views in
  cursors for InnoDB. The idea of the patch is that if MySQL requests
  a consistent read view, we open one when open a cursor, set is as the
  active view to a transaction when fetch from the cursor, and close
  together with cursor close. This patch is associated to bugs #11813, 
  #11832, and #11833.

  sql/ha_innodb.h
    1.98 05/07/21 13:44:15 jan@stripped +24 -0
    Implement MySQL framework to support consistent read views in
    cursors for InnoDB. The idea of the patch is that if MySQL requests
    a consistent read view, we open one when open a cursor, set is as the
    active view to a transaction when fetch from the cursor, and close
    together with cursor close. This patch is associated to bugs #11813, 
    #11832, and #11833.

  sql/ha_innodb.cc
    1.229 05/07/21 13:44:14 jan@stripped +37 -0
    Implement MySQL framework to support consistent read views in
    cursors for InnoDB. The idea of the patch is that if MySQL requests
    a consistent read view, we open one when open a cursor, set is as the
    active view to a transaction when fetch from the cursor, and close
    together with cursor close. This patch is associated to bugs #11813, 
    #11832, and #11833.

  innobase/trx/trx0trx.c
    1.58 05/07/21 13:44:14 jan@stripped +16 -0
    Implement MySQL framework to support consistent read views in
    cursors for InnoDB. The idea of the patch is that if MySQL requests
    a consistent read view, we open one when open a cursor, set is as the
    active view to a transaction when fetch from the cursor, and close
    together with cursor close. This patch is associated to bugs #11813, 
    #11832, and #11833.

  innobase/read/read0read.c
    1.7 05/07/21 13:44:14 jan@stripped +141 -0
    Implement MySQL framework to support consistent read views in
    cursors for InnoDB. The idea of the patch is that if MySQL requests
    a consistent read view, we open one when open a cursor, set is as the
    active view to a transaction when fetch from the cursor, and close
    together with cursor close. This patch is associated to bugs #11813, 
    #11832, and #11833.

  innobase/include/trx0trx.h
    1.51 05/07/21 13:44:14 jan@stripped +10 -1
    Implement MySQL framework to support consistent read views in
    cursors for InnoDB. The idea of the patch is that if MySQL requests
    a consistent read view, we open one when open a cursor, set is as the
    active view to a transaction when fetch from the cursor, and close
    together with cursor close. This patch is associated to bugs #11813, 
    #11832, and #11833.

  innobase/include/read0types.h
    1.2 05/07/21 13:44:14 jan@stripped +1 -0
    Implement MySQL framework to support consistent read views in
    cursors for InnoDB. The idea of the patch is that if MySQL requests
    a consistent read view, we open one when open a cursor, set is as the
    active view to a transaction when fetch from the cursor, and close
    together with cursor close. This patch is associated to bugs #11813, 
    #11832, and #11833.

  innobase/include/read0read.h
    1.4 05/07/21 13:44:14 jan@stripped +35 -0
    Implement MySQL framework to support consistent read views in
    cursors for InnoDB. The idea of the patch is that if MySQL requests
    a consistent read view, we open one when open a cursor, set is as the
    active view to a transaction when fetch from the cursor, and close
    together with cursor close. This patch is associated to bugs #11813, 
    #11832, and #11833.

# This is a BitKeeper patch.  What follows are the unified diffs for the
# set of deltas contained in the patch.  The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User:	jan
# Host:	hundin.mysql.fi
# Root:	/home/jan/mysql-5.0

--- 1.3/innobase/include/read0read.h	2002-10-29 23:09:21 +02:00
+++ 1.4/innobase/include/read0read.h	2005-07-21 13:44:14 +03:00
@@ -69,6 +69,30 @@
 /*============*/
 	read_view_t*	view);	/* in: read view */
 
+/*************************************************************************
+Create a consistent cursor view for mysql */
+
+cursor_view_t*
+read_cursor_view_create_for_mysql(
+/*==============================*/
+	trx_t*		cr_trx);/* in: trx where cursor view is created */
+
+/*************************************************************************
+Close a consistent cursor view for mysql */
+
+void
+read_cursor_view_close_for_mysql(
+/*=============================*/
+	trx_t*		trx,		/* in: trx */
+	cursor_view_t*	curview);	/* in: cursor view to be closed */
+/*************************************************************************
+Set a consistent cursor view to a transaction for mysql */
+
+void 
+read_cursor_set_for_mysql(
+/*======================*/
+	trx_t*		trx,	/* in: transaction where cursor is set */
+	cursor_view_t*	curview);/* in: consistent cursor view to be set */
 
 /* Read view lists the trx ids of those transactions for which a consistent
 read should not see the modifications to the database. */
@@ -98,6 +122,17 @@
 				NULL if used in purge */
 	UT_LIST_NODE_T(read_view_t) view_list;
 				/* List of read views in trx_sys */
+};
+
+/* Implement InnoDB framework to support consistent read views in
+cursors. This struct holds both heap where consistent read view
+is allocated and pointer to a read view. */
+
+struct cursor_view_struct{
+	mem_heap_t*	heap;
+				/* Memory heap for the cursor view */
+	read_view_t*	read_view;	
+				/* Consistent read view of the cursor*/
 };
 
 #ifndef UNIV_NONINL

--- 1.1/innobase/include/read0types.h	2001-02-17 14:19:06 +02:00
+++ 1.2/innobase/include/read0types.h	2005-07-21 13:44:14 +03:00
@@ -10,5 +10,6 @@
 #define read0types_h
 
 typedef struct read_view_struct	read_view_t;
+typedef struct cursor_view_struct	cursor_view_t;
 
 #endif

--- 1.50/innobase/include/trx0trx.h	2005-07-01 22:52:49 +03:00
+++ 1.51/innobase/include/trx0trx.h	2005-07-21 13:44:14 +03:00
@@ -603,7 +603,16 @@
 			trx_locks;	/* locks reserved by the transaction */
 	/*------------------------------*/
 	mem_heap_t*	read_view_heap;	/* memory heap for the read view */
-	read_view_t*	read_view;	/* consistent read view or NULL */
+	read_view_t*	global_read_view;
+					/* consistent read view used in the
+					transaction is stored here if
+					transaction is using a consistent
+					read view associated to a cursor */
+	read_view_t*	read_view;	/* consistent read view used in the
+					transaction or NULL, this read view
+					can be normal read view associated
+					to a transaction or read view
+					associated to a cursor */
 	/*------------------------------*/
 	UT_LIST_BASE_NODE_T(trx_named_savept_t) 
 			trx_savepoints;	/* savepoints set with SAVEPOINT ...,

--- 1.6/innobase/read/read0read.c	2005-01-16 14:16:09 +02:00
+++ 1.7/innobase/read/read0read.c	2005-07-21 13:44:14 +03:00
@@ -222,6 +222,12 @@
 
 	trx->read_view = NULL;
 
+	if (UNIV_LIKELY_NULL(trx->global_read_view)) {
+		trx->read_view = trx->global_read_view;
+	} else {
+		trx->read_view = NULL;
+	}
+
 	mutex_exit(&kernel_mutex);
 }
 	
@@ -257,4 +263,139 @@
 			(ulong) ut_dulint_get_high(read_view_get_nth_trx_id(view, i)),
 			(ulong) ut_dulint_get_low(read_view_get_nth_trx_id(view, i)));
 	}
+}
+
+/*************************************************************************
+Create a consistent cursor view for mysql */
+
+cursor_view_t*
+read_cursor_view_create_for_mysql(
+/*==============================*/
+	trx_t*	cr_trx)	/* in: trx where cursor view is created */
+{
+	cursor_view_t*	curview;
+	read_view_t*	view;
+	mem_heap_t*	heap;
+	trx_t*		trx;
+	ulint		n;
+
+	ut_a(cr_trx);
+
+	/* Use larger heap than in trx_create when creating a read_view 
+	because cursors are quite long. */
+
+	heap = mem_heap_create(512);
+
+	curview = (cursor_view_t*) mem_heap_alloc(heap, sizeof(cursor_view_t));
+	curview->heap = heap;
+
+	mutex_enter(&kernel_mutex);
+
+	curview->read_view = read_view_create_low(
+				UT_LIST_GET_LEN(trx_sys->trx_list), 
+					curview->heap);
+
+	cr_trx->global_read_view = cr_trx->read_view;
+	view = curview->read_view;
+	cr_trx->read_view = view;
+	
+	view->creator = cr_trx;
+
+	/* No future transactions should be visible in the view */
+
+  	view->low_limit_no = trx_sys->max_trx_id;
+	view->low_limit_id = view->low_limit_no;
+
+	view->can_be_too_old = FALSE;
+
+	n = 0;
+	trx = UT_LIST_GET_FIRST(trx_sys->trx_list);
+
+	/* No active transaction should be visible, not even cr_trx !*/
+
+	while (trx) {
+                if (trx->conc_state == TRX_ACTIVE ||
+			trx->conc_state == TRX_PREPARED) {
+
+			read_view_set_nth_trx_id(view, n, trx->id);
+
+			n++;
+
+			/* NOTE that a transaction whose trx number is <
+			trx_sys->max_trx_id can still be active, if it is
+			in the middle of its commit! Note that when a
+			transaction starts, we initialize trx->no to
+			ut_dulint_max. */
+
+			if (ut_dulint_cmp(view->low_limit_no, trx->no) > 0) {
+
+				view->low_limit_no = trx->no;
+			}	
+		}
+
+		trx = UT_LIST_GET_NEXT(trx_list, trx);
+	}
+
+	view->n_trx_ids = n;		
+
+	if (n > 0) {
+		/* The last active transaction has the smallest id: */
+		view->up_limit_id = read_view_get_nth_trx_id(view, n - 1);
+	} else {
+		view->up_limit_id = view->low_limit_id;
+	}
+
+	UT_LIST_ADD_FIRST(view_list, trx_sys->view_list, view);
+	
+	mutex_exit(&kernel_mutex);
+
+	return(curview);
+}
+
+/*************************************************************************
+Close a consistent cursor view for mysql */
+
+void
+read_cursor_view_close_for_mysql(
+/*=============================*/
+	trx_t*		trx,	/* in: trx */
+	cursor_view_t*	curview)/* in: cursor view to be closed */
+{
+	ut_a(curview);
+	ut_a(curview->read_view); 
+	ut_a(curview->heap);
+
+	mutex_enter(&kernel_mutex);
+
+	read_view_close(curview->read_view);
+	trx->read_view = trx->global_read_view;
+	trx->global_read_view = NULL;
+
+	mutex_exit(&kernel_mutex);
+
+	mem_heap_free(curview->heap);
+}
+	
+/*************************************************************************
+Set a consistent cursor view to a transaction for mysql */
+
+void 
+read_cursor_set_for_mysql(
+/*======================*/
+	trx_t*		trx,	/* in: transaction where cursor is set */
+	cursor_view_t*	curview)/* in: consistent cursor view to be set */
+{
+	ut_a(trx);
+
+	mutex_enter(&kernel_mutex);
+
+	if (UNIV_LIKELY(curview)) {
+		trx->global_read_view = trx->read_view;
+		trx->read_view = curview->read_view;
+	} else {
+		trx->read_view = trx->global_read_view;
+		trx->global_read_view = NULL;
+	}
+
+	mutex_exit(&kernel_mutex);
 }

--- 1.57/innobase/trx/trx0trx.c	2005-07-01 20:43:58 +03:00
+++ 1.58/innobase/trx/trx0trx.c	2005-07-21 13:44:14 +03:00
@@ -160,6 +160,7 @@
 	trx->auto_inc_lock = NULL;
 	
 	trx->read_view_heap = mem_heap_create(256);
+	trx->global_read_view = NULL;
 	trx->read_view = NULL;
 
 	/* Set X/Open XA transaction identification to NULL */
@@ -322,6 +323,8 @@
 		mem_heap_free(trx->read_view_heap);
 	}
 
+	trx->global_read_view = NULL;
+
 	ut_a(trx->read_view == NULL);
 	
 	mem_free(trx);
@@ -831,10 +834,23 @@
 	lock_release_off_kernel(trx);
 
 	if (trx->read_view) {
+		/* If transaction has a global read view this case
+		means that transaction has been using a consistent
+		read view associated to a cursor. Only the global
+		read view associated to a transaction is closed
+		and read view is then removed from the transaction.
+		If read view associated to a cursor is still used
+		it must be re-registered to another transaction. */
+
+		if (UNIV_LIKELY_NULL(trx->global_read_view)) {
+			trx->read_view = trx->global_read_view;
+		}
+
 		read_view_close(trx->read_view);
 
 		mem_heap_empty(trx->read_view_heap);
 		trx->read_view = NULL;
+		trx->global_read_view = NULL;
 	}
 
 	if (must_flush_log) {

--- 1.228/sql/ha_innodb.cc	2005-07-20 19:02:25 +03:00
+++ 1.229/sql/ha_innodb.cc	2005-07-21 13:44:14 +03:00
@@ -7130,4 +7130,41 @@
 	}
 }
 
+/***********************************************************************
+This function creates a consistent view for a cursor. This consistent
+view is then used inside of MySQL when accesing records using a cursor. */
+
+void*
+innobase_create_cursor_view(void)
+/*=============================*/
+			/* out: Pointer to cursor view or NULL */
+{
+	return(read_cursor_view_create_for_mysql(
+					check_trx_exists(current_thd)));
+}
+
+/***********************************************************************
+This function closes the consistent cursor view */
+
+void
+innobase_close_cursor_view(
+/*=======================*/
+	void*	curview)/* in: Consistent read view to be closed */
+{
+	read_cursor_view_close_for_mysql(check_trx_exists(current_thd),
+						(cursor_view_t*) curview);
+}
+
+/***********************************************************************
+This function sets the consistent cursor view to a transaction */
+
+void
+innobase_set_cursor_view(
+/*=====================*/
+	void*	curview)/* in: Consistent cursor view to be closed */
+{
+	read_cursor_set_for_mysql(check_trx_exists(current_thd), 
+						(cursor_view_t*) curview);
+}
+
 #endif /* HAVE_INNOBASE_DB */

--- 1.97/sql/ha_innodb.h	2005-07-19 21:21:01 +03:00
+++ 1.98/sql/ha_innodb.h	2005-07-21 13:44:15 +03:00
@@ -310,3 +310,27 @@
 
 int innobase_repl_report_sent_binlog(THD *thd, char *log_file_name,
                                my_off_t end_offset);
+
+/***********************************************************************
+This function creates a consistent cursor view. */
+
+void*
+innobase_create_cursor_view(void);
+/*=============================*/
+				/* out: Pointer to cursor view or NULL */
+
+/***********************************************************************
+This function closes the consistent cursor view */
+
+void
+innobase_close_cursor_view(
+/*=======================*/
+	void*	curview);	/* in: Consistent read view to be closed */
+
+/***********************************************************************
+This function sets the consistent cursor view to a transaction */
+
+void
+innobase_set_cursor_view(
+/*=====================*/
+	void*	curview);	/* in: Consistent read view to be closed */
Thread
bk commit into 5.0 tree (jan:1.1965)Jan Lindstrom21 Jul