List:Commits« Previous MessageNext Message »
From:marko.makela Date:April 26 2011 11:14am
Subject:bzr push into mysql-trunk-innodb branch (marko.makela:3605 to 3606) WL#5526
View as plain text  
 3606 Marko Mäkelä	2011-04-26
      Non-functional changes in preparation of WL#5526.
      
      row_purge_record_func(): Replace if with switch.
      
      row_undo_ins_remove_sec_rec(): New function, refactored from row_undo_ins().
      Remove the secondary index records.
      
      row_undo_mod_upd_del_sec(), row_undo_mod_del_mark_sec(),
      row_undo_mod_upd_exist_sec(): Use for instead of while.
      Invoke mem_heap_empty() on every loop iteration.
      
      row_undo_mod(): Replace if with switch.
      
      row_upd(): Replace if with switch. Eliminate a goto label.

    modified:
      storage/innobase/row/row0purge.c
      storage/innobase/row/row0uins.c
      storage/innobase/row/row0umod.c
      storage/innobase/row/row0upd.c
 3605 Inaam Rana	2011-04-22
      Fix warning due to trailing comma in enum declaration.
      
      Pointed by: Davi

    modified:
      storage/innobase/include/hash0hash.h
=== modified file 'storage/innobase/row/row0purge.c'
--- a/storage/innobase/row/row0purge.c	revid:inaam.rana@strippedhfmkt6
+++ b/storage/innobase/row/row0purge.c	revid:marko.makela@stripped
@@ -735,14 +735,20 @@ row_purge_record_func(
 
 	node->index = dict_table_get_next_index(clust_index);
 
-	if (node->rec_type == TRX_UNDO_DEL_MARK_REC) {
+	switch (node->rec_type) {
+	case TRX_UNDO_DEL_MARK_REC:
 		row_purge_del_mark(node);
 		MONITOR_INC(MONITOR_N_DEL_ROW_PURGE);
-	} else if (updated_extern
-		   || node->rec_type == TRX_UNDO_UPD_EXIST_REC) {
-
+		break;
+	default:
+		if (!updated_extern) {
+			break;
+		}
+		/* fall through */
+	case TRX_UNDO_UPD_EXIST_REC:
 		row_purge_upd_exist_or_extern(thr, node, undo_rec);
 		MONITOR_INC(MONITOR_N_UPD_EXIST_EXTERN);
+		break;
 	}
 
 	if (node->found_clust) {

=== modified file 'storage/innobase/row/row0uins.c'
--- a/storage/innobase/row/row0uins.c	revid:inaam.rana@stripped422203150-pxdf539zqhhfmkt6
+++ b/storage/innobase/row/row0uins.c	revid:marko.makela@strippedsm4zhkok9d19
@@ -307,6 +307,53 @@ row_undo_ins_parse_undo_rec(
 	}
 }
 
+/***************************************************************//**
+Removes secondary index records.
+@return	DB_SUCCESS or DB_OUT_OF_FILE_SPACE */
+static
+ulint
+row_undo_ins_remove_sec_rec(
+/*========================*/
+	undo_node_t*	node)	/*!< in/out: row undo node */
+{
+	ulint		err	= DB_SUCCESS;
+	mem_heap_t*	heap;
+
+	for (heap = mem_heap_create(1024);
+	     node->index != NULL;
+	     mem_heap_empty(heap),
+		     node->index = dict_table_get_next_index(node->index)) {
+		dtuple_t*	entry;
+
+		entry = row_build_index_entry(node->row, node->ext,
+					      node->index, heap);
+		if (UNIV_UNLIKELY(!entry)) {
+			/* The database must have crashed after
+			inserting a clustered index record but before
+			writing all the externally stored columns of
+			that record.  Because secondary index entries
+			are inserted after the clustered index record,
+			we may assume that the secondary index record
+			does not exist.  However, this situation may
+			only occur during the rollback of incomplete
+			transactions. */
+			ut_a(trx_is_recv(node->trx));
+		} else {
+			log_free_check();
+
+			err = row_undo_ins_remove_sec(node->index, entry);
+
+			if (UNIV_UNLIKELY(err != DB_SUCCESS)) {
+				goto func_exit;
+			}
+		}
+	}
+
+func_exit:
+	mem_heap_free(heap);
+	return(err);
+}
+
 /***********************************************************//**
 Undoes a fresh insert of a row to a table. A fresh insert means that
 the same clustered index unique key did not have any record, even delete
@@ -342,44 +389,17 @@ row_undo_ins(
 	node->index = dict_table_get_next_index(
 		dict_table_get_first_index(node->table));
 
-	while (node->index != NULL) {
-		dtuple_t*	entry;
-
-		entry = row_build_index_entry(node->row, node->ext,
-					      node->index, node->heap);
-		if (UNIV_UNLIKELY(!entry)) {
-			/* The database must have crashed after
-			inserting a clustered index record but before
-			writing all the externally stored columns of
-			that record.  Because secondary index entries
-			are inserted after the clustered index record,
-			we may assume that the secondary index record
-			does not exist.  However, this situation may
-			only occur during the rollback of incomplete
-			transactions. */
-			ut_a(trx_is_recv(node->trx));
-		} else {
-			log_free_check();
-
-			err = row_undo_ins_remove_sec(node->index, entry);
-
-			if (err != DB_SUCCESS) {
-
-				dict_table_close(node->table, dict_locked);
-
-				node->table = NULL;
-
-				return(err);
-			}
-		}
+	err = row_undo_ins_remove_sec_rec(node);
 
-		node->index = dict_table_get_next_index(node->index);
+	if (UNIV_UNLIKELY(err != DB_SUCCESS)) {
+		goto func_exit;
 	}
 
 	log_free_check();
 
 	err = row_undo_ins_remove_clust_rec(node);
 
+func_exit:
 	dict_table_close(node->table, dict_locked);
 
 	node->table = NULL;

=== modified file 'storage/innobase/row/row0umod.c'
--- a/storage/innobase/row/row0umod.c	revid:inaam.rana@stripped50-pxdf539zqhhfmkt6
+++ b/storage/innobase/row/row0umod.c	revid:marko.makela@strippedk9d19
@@ -565,18 +565,17 @@ row_undo_mod_upd_del_sec(
 	que_thr_t*	thr)	/*!< in: query thread */
 {
 	mem_heap_t*	heap;
-	dtuple_t*	entry;
-	dict_index_t*	index;
 	ulint		err	= DB_SUCCESS;
 
 	ut_ad(node->rec_type == TRX_UNDO_UPD_DEL_REC);
-	heap = mem_heap_create(1024);
 
-	while (node->index != NULL) {
-		index = node->index;
-
-		entry = row_build_index_entry(node->row, node->ext,
-					      index, heap);
+	for (heap = mem_heap_create(1024);
+	     node->index != NULL;
+	     mem_heap_empty(heap),
+		     node->index = dict_table_get_next_index(node->index)) {
+		dict_index_t*	index	= node->index;
+		dtuple_t*	entry	= row_build_index_entry(
+			node->row, node->ext, index, heap);
 		if (UNIV_UNLIKELY(!entry)) {
 			/* The database must have crashed after
 			inserting a clustered index record but before
@@ -592,15 +591,11 @@ row_undo_mod_upd_del_sec(
 			err = row_undo_mod_del_mark_or_remove_sec(
 				node, thr, index, entry);
 
-			if (err != DB_SUCCESS) {
+			if (UNIV_UNLIKELY(err != DB_SUCCESS)) {
 
 				break;
 			}
 		}
-
-		mem_heap_empty(heap);
-
-		node->index = dict_table_get_next_index(node->index);
 	}
 
 	mem_heap_free(heap);
@@ -619,18 +614,17 @@ row_undo_mod_del_mark_sec(
 	que_thr_t*	thr)	/*!< in: query thread */
 {
 	mem_heap_t*	heap;
-	dtuple_t*	entry;
-	dict_index_t*	index;
-	ulint		err;
-
-	heap = mem_heap_create(1024);
-
-	while (node->index != NULL) {
-		index = node->index;
+	ulint		err	= DB_SUCCESS;
 
-		entry = row_build_index_entry(node->row, node->ext,
-					      index, heap);
+	for (heap = mem_heap_create(1024);
+	     node->index != NULL;
+	     mem_heap_empty(heap),
+		     node->index = dict_table_get_next_index(node->index)) {
+		dict_index_t*	index	= node->index;
+		dtuple_t*	entry	= row_build_index_entry(
+			node->row, node->ext, index, heap);
 		ut_a(entry);
+
 		err = row_undo_mod_del_unmark_sec_and_undo_update(
 			BTR_MODIFY_LEAF, thr, index, entry);
 		if (err == DB_FAIL) {
@@ -638,19 +632,15 @@ row_undo_mod_del_mark_sec(
 				BTR_MODIFY_TREE, thr, index, entry);
 		}
 
-		if (err != DB_SUCCESS) {
-
-			mem_heap_free(heap);
+		if (UNIV_UNLIKELY(err != DB_SUCCESS)) {
 
-			return(err);
+			break;
 		}
-
-		node->index = dict_table_get_next_index(node->index);
 	}
 
 	mem_heap_free(heap);
 
-	return(DB_SUCCESS);
+	return(err);
 }
 
 /***********************************************************//**
@@ -664,109 +654,101 @@ row_undo_mod_upd_exist_sec(
 	que_thr_t*	thr)	/*!< in: query thread */
 {
 	mem_heap_t*	heap;
-	dtuple_t*	entry;
-	dict_index_t*	index;
-	ulint		err;
+	ulint		err	= DB_SUCCESS;
 
-	if (node->cmpl_info & UPD_NODE_NO_ORD_CHANGE) {
+	if (node->index == NULL
+	    || (node->cmpl_info & UPD_NODE_NO_ORD_CHANGE)) {
 		/* No change in secondary indexes */
 
-		return(DB_SUCCESS);
+		return(err);
 	}
 
-	heap = mem_heap_create(1024);
-
-	while (node->index != NULL) {
-		index = node->index;
-
-		if (row_upd_changes_ord_field_binary(node->index, node->update,
-						     thr,
-						     node->row, node->ext)) {
-
-			/* Build the newest version of the index entry */
-			entry = row_build_index_entry(node->row, node->ext,
-						      index, heap);
-			if (UNIV_UNLIKELY(!entry)) {
-				/* The server must have crashed in
-				row_upd_clust_rec_by_insert() before
-				the updated externally stored columns (BLOBs)
-				of the new clustered index entry were
-				written. */
-
-				/* The table must be in DYNAMIC or COMPRESSED
-				format.  REDUNDANT and COMPACT formats
-				store a local 768-byte prefix of each
-				externally stored column. */
-				ut_a(dict_table_get_format(index->table)
-				     >= UNIV_FORMAT_B);
-
-				/* This is only legitimate when
-				rolling back an incomplete transaction
-				after crash recovery. */
-				ut_a(thr_get_trx(thr)->is_recovered);
-
-				/* The server must have crashed before
-				completing the insert of the new
-				clustered index entry and before
-				inserting to the secondary indexes.
-				Because node->row was not yet written
-				to this index, we can ignore it.  But
-				we must restore node->undo_row. */
-			} else {
-				/* NOTE that if we updated the fields of a
-				delete-marked secondary index record so that
-				alphabetically they stayed the same, e.g.,
-				'abc' -> 'aBc', we cannot return to the
-				original values because we do not know them.
-				But this should not cause problems because
-				in row0sel.c, in queries we always retrieve
-				the clustered index record or an earlier
-				version of it, if the secondary index record
-				through which we do the search is
-				delete-marked. */
-
-				err = row_undo_mod_del_mark_or_remove_sec(
-					node, thr, index, entry);
-				if (err != DB_SUCCESS) {
-					mem_heap_free(heap);
+	for (heap = mem_heap_create(1024); node->index != NULL;
+	     mem_heap_empty(heap),
+		     node->index = dict_table_get_next_index(node->index)) {
+		dict_index_t*	index	= node->index;
+		dtuple_t*	entry;
+
+		if (!row_upd_changes_ord_field_binary(index, node->update, thr,
+						      node->row, node->ext)) {
+			continue;
+		}
 
-					return(err);
-				}
+		/* Build the newest version of the index entry */
+		entry = row_build_index_entry(node->row, node->ext,
+					      index, heap);
+		if (UNIV_UNLIKELY(!entry)) {
+			/* The server must have crashed in
+			row_upd_clust_rec_by_insert() before
+			the updated externally stored columns (BLOBs)
+			of the new clustered index entry were written. */
+
+			/* The table must be in DYNAMIC or COMPRESSED
+			format.  REDUNDANT and COMPACT formats
+			store a local 768-byte prefix of each
+			externally stored column. */
+			ut_a(dict_table_get_format(index->table)
+			     >= UNIV_FORMAT_B);
+
+			/* This is only legitimate when
+			rolling back an incomplete transaction
+			after crash recovery. */
+			ut_a(thr_get_trx(thr)->is_recovered);
+
+			/* The server must have crashed before
+			completing the insert of the new
+			clustered index entry and before
+			inserting to the secondary indexes.
+			Because node->row was not yet written
+			to this index, we can ignore it.  But
+			we must restore node->undo_row. */
+		} else {
+			/* NOTE that if we updated the fields of a
+			delete-marked secondary index record so that
+			alphabetically they stayed the same, e.g.,
+			'abc' -> 'aBc', we cannot return to the
+			original values because we do not know them.
+			But this should not cause problems because
+			in row0sel.c, in queries we always retrieve
+			the clustered index record or an earlier
+			version of it, if the secondary index record
+			through which we do the search is
+			delete-marked. */
 
-				mem_heap_empty(heap);
+			err = row_undo_mod_del_mark_or_remove_sec(
+				node, thr, index, entry);
+			if (err != DB_SUCCESS) {
+				break;
 			}
+		}
 
-			/* We may have to update the delete mark in the
-			secondary index record of the previous version of
-			the row. We also need to update the fields of
-			the secondary index record if we updated its fields
-			but alphabetically they stayed the same, e.g.,
-			'abc' -> 'aBc'. */
-			entry = row_build_index_entry(node->undo_row,
-						      node->undo_ext,
-						      index, heap);
-			ut_a(entry);
+		mem_heap_empty(heap);
+		/* We may have to update the delete mark in the
+		secondary index record of the previous version of
+		the row. We also need to update the fields of
+		the secondary index record if we updated its fields
+		but alphabetically they stayed the same, e.g.,
+		'abc' -> 'aBc'. */
+		entry = row_build_index_entry(node->undo_row,
+					      node->undo_ext,
+					      index, heap);
+		ut_a(entry);
 
+		err = row_undo_mod_del_unmark_sec_and_undo_update(
+			BTR_MODIFY_LEAF, thr, index, entry);
+		if (err == DB_FAIL) {
 			err = row_undo_mod_del_unmark_sec_and_undo_update(
-				BTR_MODIFY_LEAF, thr, index, entry);
-			if (err == DB_FAIL) {
-				err = row_undo_mod_del_unmark_sec_and_undo_update(
-					BTR_MODIFY_TREE, thr, index, entry);
-			}
-
-			if (err != DB_SUCCESS) {
-				mem_heap_free(heap);
-
-				return(err);
-			}
+				BTR_MODIFY_TREE, thr, index, entry);
 		}
 
-		node->index = dict_table_get_next_index(node->index);
+		if (UNIV_UNLIKELY(err != DB_SUCCESS)) {
+			break;
+		}
 	}
 
 	mem_heap_free(heap);
 
-	return(DB_SUCCESS);
+	return(err);
 }
 
 /***********************************************************//**
@@ -872,16 +854,19 @@ row_undo_mod(
 	node->index = dict_table_get_next_index(
 		dict_table_get_first_index(node->table));
 
-	if (node->rec_type == TRX_UNDO_UPD_EXIST_REC) {
-
+	switch (node->rec_type) {
+	case TRX_UNDO_UPD_EXIST_REC:
 		err = row_undo_mod_upd_exist_sec(node, thr);
-
-	} else if (node->rec_type == TRX_UNDO_DEL_MARK_REC) {
-
+		break;
+	case TRX_UNDO_DEL_MARK_REC:
 		err = row_undo_mod_del_mark_sec(node, thr);
-	} else {
-		ut_ad(node->rec_type == TRX_UNDO_UPD_DEL_REC);
+		break;
+	case TRX_UNDO_UPD_DEL_REC:
 		err = row_undo_mod_upd_del_sec(node, thr);
+		break;
+	default:
+		ut_error;
+		err = DB_ERROR;
 	}
 
 	if (err == DB_SUCCESS) {

=== modified file 'storage/innobase/row/row0upd.c'
--- a/storage/innobase/row/row0upd.c	revid:inaam.rana@stripped20110422203150-pxdf539zqhhfmkt6
+++ b/storage/innobase/row/row0upd.c	revid:marko.makela@stripped1sr7sm4zhkok9d19
@@ -2280,52 +2280,52 @@ row_upd(
 		}
 	}
 
-	if (node->state == UPD_NODE_UPDATE_CLUSTERED
-	    || node->state == UPD_NODE_INSERT_CLUSTERED
-	    || node->state == UPD_NODE_INSERT_BLOB) {
-
+	switch (node->state) {
+	case UPD_NODE_UPDATE_CLUSTERED:
+	case UPD_NODE_INSERT_CLUSTERED:
+	case UPD_NODE_INSERT_BLOB:
 		log_free_check();
 		err = row_upd_clust_step(node, thr);
 
 		if (err != DB_SUCCESS) {
 
-			goto function_exit;
+			return(err);
 		}
 	}
 
-	if (!node->is_delete && (node->cmpl_info & UPD_NODE_NO_ORD_CHANGE)) {
+	if (node->index == NULL
+	    || (!node->is_delete
+		&& (node->cmpl_info & UPD_NODE_NO_ORD_CHANGE))) {
 
-		goto function_exit;
+		return(DB_SUCCESS);
 	}
 
-	while (node->index != NULL) {
-
+	do {
 		log_free_check();
 		err = row_upd_sec_step(node, thr);
 
 		if (err != DB_SUCCESS) {
 
-			goto function_exit;
+			return(err);
 		}
 
 		node->index = dict_table_get_next_index(node->index);
-	}
+	} while (node->index != NULL);
 
-function_exit:
-	if (err == DB_SUCCESS) {
-		/* Do some cleanup */
-
-		if (node->row != NULL) {
-			node->row = NULL;
-			node->ext = NULL;
-			node->upd_row = NULL;
-			node->upd_ext = NULL;
-			mem_heap_empty(node->heap);
-		}
+	ut_ad(err == DB_SUCCESS);
+
+	/* Do some cleanup */
 
-		node->state = UPD_NODE_UPDATE_CLUSTERED;
+	if (node->row != NULL) {
+		node->row = NULL;
+		node->ext = NULL;
+		node->upd_row = NULL;
+		node->upd_ext = NULL;
+		mem_heap_empty(node->heap);
 	}
 
+	node->state = UPD_NODE_UPDATE_CLUSTERED;
+
 	return(err);
 }
 

Attachment: [text/bzr-bundle] bzr/marko.makela@oracle.com-20110426111422-1sr7sm4zhkok9d19.bundle
Thread
bzr push into mysql-trunk-innodb branch (marko.makela:3605 to 3606) WL#5526marko.makela26 Apr