diff options
Diffstat (limited to 'storage/xtradb/ut')
-rw-r--r-- | storage/xtradb/ut/ut0bh.c | 164 | ||||
-rw-r--r-- | storage/xtradb/ut/ut0byte.c | 25 | ||||
-rw-r--r-- | storage/xtradb/ut/ut0dbg.c | 38 | ||||
-rw-r--r-- | storage/xtradb/ut/ut0mem.c | 8 | ||||
-rw-r--r-- | storage/xtradb/ut/ut0rbt.c | 259 | ||||
-rw-r--r-- | storage/xtradb/ut/ut0ut.c | 121 | ||||
-rw-r--r-- | storage/xtradb/ut/ut0wqueue.c | 4 |
7 files changed, 423 insertions, 196 deletions
diff --git a/storage/xtradb/ut/ut0bh.c b/storage/xtradb/ut/ut0bh.c new file mode 100644 index 00000000000..ae0b1aff207 --- /dev/null +++ b/storage/xtradb/ut/ut0bh.c @@ -0,0 +1,164 @@ +/***************************************************************************//** +Copyright (c) 2010, 2011, Oracle Corpn. All Rights Reserved. + +Portions of this file contain modifications contributed and copyrighted by +Sun Microsystems, Inc. Those modifications are gratefully acknowledged and +are described briefly in the InnoDB documentation. The contributions by +Sun Microsystems are incorporated with their permission, and subject to the +conditions contained in the file COPYING.Sun_Microsystems. + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; version 2 of the License. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program; if not, write to the Free Software Foundation, Inc., 59 Temple +Place, Suite 330, Boston, MA 02111-1307 USA + +*****************************************************************************/ + +/******************************************************************//** +@file ut/ut0bh.c +Binary min-heap implementation. + +Created 2010-05-28 by Sunny Bains +*******************************************************/ + +#include "ut0bh.h" +#include "ut0mem.h" + +#ifdef UNIV_NONINL +#include "ut0bh.ic" +#endif + +#include <string.h> + +/**********************************************************************//** +Create a binary heap. +@return a new binary heap */ +UNIV_INTERN +ib_bh_t* +ib_bh_create( +/*=========*/ + ib_bh_cmp_t compare, /*!< in: comparator */ + ulint sizeof_elem, /*!< in: size of one element */ + ulint max_elems) /*!< in: max elements allowed */ +{ + ulint sz; + ib_bh_t* ib_bh; + + sz = sizeof(*ib_bh) + (sizeof_elem * max_elems); + + ib_bh = (ib_bh_t*) ut_malloc(sz); + memset(ib_bh, 0x0, sz); + + ib_bh->compare = compare; + ib_bh->max_elems = max_elems; + ib_bh->sizeof_elem = sizeof_elem; + + return(ib_bh); +} + +/**********************************************************************//** +Free a binary heap. +@return a new binary heap */ +UNIV_INTERN +void +ib_bh_free( +/*=======*/ + ib_bh_t* ib_bh) /*!< in/own: instance */ +{ + ut_free(ib_bh); +} + +/**********************************************************************//** +Add an element to the binary heap. Note: The element is copied. +@return pointer to added element or NULL if full. */ +UNIV_INTERN +void* +ib_bh_push( +/*=======*/ + ib_bh_t* ib_bh, /*!< in/out: instance */ + const void* elem) /*!< in: element to add */ +{ + void* ptr; + + if (ib_bh_is_full(ib_bh)) { + return(NULL); + } else if (ib_bh_is_empty(ib_bh)) { + ++ib_bh->n_elems; + return(ib_bh_set(ib_bh, 0, elem)); + } else { + ulint i; + + i = ib_bh->n_elems; + + ++ib_bh->n_elems; + + for (ptr = ib_bh_get(ib_bh, i >> 1); + i > 0 && ib_bh->compare(ptr, elem) > 0; + i >>= 1, ptr = ib_bh_get(ib_bh, i >> 1)) { + + ib_bh_set(ib_bh, i, ptr); + } + + ptr = ib_bh_set(ib_bh, i, elem); + } + + return(ptr); +} + +/**********************************************************************//** +Remove the first element from the binary heap. */ +UNIV_INTERN +void +ib_bh_pop( +/*======*/ + ib_bh_t* ib_bh) /*!< in/out: instance */ +{ + byte* ptr; + byte* last; + ulint parent = 0; + + if (ib_bh_is_empty(ib_bh)) { + return; + } else if (ib_bh_size(ib_bh) == 1) { + --ib_bh->n_elems; + return; + } + + last = (byte*) ib_bh_last(ib_bh); + + /* Start from the child node */ + ptr = (byte*) ib_bh_get(ib_bh, 1); + + while (ptr < last) { + /* If the "right" child node is < "left" child node */ + if (ib_bh->compare(ptr + ib_bh->sizeof_elem, ptr) < 0) { + ptr += ib_bh->sizeof_elem; + } + + if (ib_bh->compare(last, ptr) <= 0) { + break; + } + + ib_bh_set(ib_bh, parent, ptr); + + parent = (ptr - (byte*) ib_bh_first(ib_bh)) + / ib_bh->sizeof_elem; + + if ((parent << 1) >= ib_bh_size(ib_bh)) { + break; + } + + ptr = (byte*) ib_bh_get(ib_bh, parent << 1); + } + + --ib_bh->n_elems; + + ib_bh_set(ib_bh, parent, last); +} diff --git a/storage/xtradb/ut/ut0byte.c b/storage/xtradb/ut/ut0byte.c index 4e093f72ce2..535f74b8907 100644 --- a/storage/xtradb/ut/ut0byte.c +++ b/storage/xtradb/ut/ut0byte.c @@ -28,28 +28,3 @@ Created 5/11/1994 Heikki Tuuri #ifdef UNIV_NONINL #include "ut0byte.ic" #endif - -/** Zero value for a dulint */ -UNIV_INTERN const dulint ut_dulint_zero = {0, 0}; - -/** Maximum value for a dulint */ -UNIV_INTERN const dulint ut_dulint_max = {0xFFFFFFFFUL, 0xFFFFFFFFUL}; - -#ifdef notdefined /* unused code */ -#include "ut0sort.h" - -/************************************************************//** -Sort function for dulint arrays. */ -UNIV_INTERN -void -ut_dulint_sort( -/*===========*/ - dulint* arr, /*!< in/out: array to be sorted */ - dulint* aux_arr,/*!< in/out: auxiliary array (same size as arr) */ - ulint low, /*!< in: low bound of sort interval, inclusive */ - ulint high) /*!< in: high bound of sort interval, noninclusive */ -{ - UT_SORT_FUNCTION_BODY(ut_dulint_sort, arr, aux_arr, low, high, - ut_dulint_cmp); -} -#endif /* notdefined */ diff --git a/storage/xtradb/ut/ut0dbg.c b/storage/xtradb/ut/ut0dbg.c index 4484e6c36de..64fadd76d1c 100644 --- a/storage/xtradb/ut/ut0dbg.c +++ b/storage/xtradb/ut/ut0dbg.c @@ -25,6 +25,7 @@ Created 1/30/1994 Heikki Tuuri #include "univ.i" #include "ut0dbg.h" +#include "ha_prototypes.h" #if defined(__GNUC__) && (__GNUC__ > 2) #else @@ -37,12 +38,7 @@ UNIV_INTERN ulint ut_dbg_zero = 0; will stop at the next ut_a() or ut_ad(). */ UNIV_INTERN ibool ut_dbg_stop_threads = FALSE; #endif -#ifdef __NETWARE__ -/** Flag for ignoring further assertion failures. This is set to TRUE -when on NetWare there happens an InnoDB assertion failure or other -fatal error condition that requires an immediate shutdown. */ -UNIV_INTERN ibool panic_shutdown = FALSE; -#elif !defined(UT_DBG_USE_ABORT) +#ifndef UT_DBG_USE_ABORT /** A null pointer that will be dereferenced to trigger a memory trap */ UNIV_INTERN ulint* ut_dbg_null_ptr = NULL; #endif @@ -60,12 +56,13 @@ ut_dbg_assertion_failed( ut_print_timestamp(stderr); #ifdef UNIV_HOTBACKUP fprintf(stderr, " InnoDB: Assertion failure in file %s line %lu\n", - file, line); + innobase_basename(file), line); #else /* UNIV_HOTBACKUP */ fprintf(stderr, " InnoDB: Assertion failure in thread %lu" " in file %s line %lu\n", - os_thread_pf(os_thread_get_curr_id()), file, line); + os_thread_pf(os_thread_get_curr_id()), + innobase_basename(file), line); #endif /* UNIV_HOTBACKUP */ if (expr) { fprintf(stderr, @@ -79,29 +76,14 @@ ut_dbg_assertion_failed( " or crashes, even\n" "InnoDB: immediately after the mysqld startup, there may be\n" "InnoDB: corruption in the InnoDB tablespace. Please refer to\n" - "InnoDB: " REFMAN "forcing-recovery.html\n" + "InnoDB: " REFMAN "forcing-innodb-recovery.html\n" "InnoDB: about forcing recovery.\n", stderr); #if defined(UNIV_SYNC_DEBUG) || !defined(UT_DBG_USE_ABORT) ut_dbg_stop_threads = TRUE; #endif } -#ifdef __NETWARE__ -/*************************************************************//** -Shut down MySQL/InnoDB after assertion failure. */ -UNIV_INTERN -void -ut_dbg_panic(void) -/*==============*/ -{ - if (!panic_shutdown) { - panic_shutdown = TRUE; - innobase_shutdown_for_mysql(); - } - exit(1); -} -#else /* __NETWARE__ */ -# if defined(UNIV_SYNC_DEBUG) || !defined(UT_DBG_USE_ABORT) +#if defined(UNIV_SYNC_DEBUG) || !defined(UT_DBG_USE_ABORT) /*************************************************************//** Stop a thread after assertion failure. */ UNIV_INTERN @@ -113,12 +95,12 @@ ut_dbg_stop_thread( { #ifndef UNIV_HOTBACKUP fprintf(stderr, "InnoDB: Thread %lu stopped in file %s line %lu\n", - os_thread_pf(os_thread_get_curr_id()), file, line); + os_thread_pf(os_thread_get_curr_id()), + innobase_basename(file), line); os_thread_sleep(1000000000); #endif /* !UNIV_HOTBACKUP */ } -# endif -#endif /* __NETWARE__ */ +#endif #ifdef UNIV_COMPILE_TEST_FUNCS diff --git a/storage/xtradb/ut/ut0mem.c b/storage/xtradb/ut/ut0mem.c index bf55e4273b6..53f15029e1b 100644 --- a/storage/xtradb/ut/ut0mem.c +++ b/storage/xtradb/ut/ut0mem.c @@ -179,9 +179,6 @@ retry: /* Make an intentional seg fault so that we get a stack trace */ - /* Intentional segfault on NetWare causes an abend. Avoid this - by graceful exit handling in ut_a(). */ -#if (!defined __NETWARE__) if (assert_on_error) { ut_print_timestamp(stderr); @@ -194,9 +191,6 @@ retry: } else { return(NULL); } -#else - ut_a(0); -#endif } if (set_to_zero) { @@ -296,7 +290,7 @@ UNIV_INTERN void ut_free( /*====*/ - void* ptr) /*!< in, own: memory block */ + void* ptr) /*!< in, own: memory block, can be NULL */ { #ifndef UNIV_HOTBACKUP ut_mem_block_t* block; diff --git a/storage/xtradb/ut/ut0rbt.c b/storage/xtradb/ut/ut0rbt.c index 3d7bc91e714..3d7cfa7636f 100644 --- a/storage/xtradb/ut/ut0rbt.c +++ b/storage/xtradb/ut/ut0rbt.c @@ -1,6 +1,12 @@ -/***************************************************************************** +/***************************************************************************//** -Copyright (c) 2006, 2009, Innobase Oy. All Rights Reserved. +Copyright (c) 2007, 2010, Innobase Oy. All Rights Reserved. + +Portions of this file contain modifications contributed and copyrighted by +Sun Microsystems, Inc. Those modifications are gratefully acknowledged and +are described briefly in the InnoDB documentation. The contributions by +Sun Microsystems are incorporated with their permission, and subject to the +conditions contained in the file COPYING.Sun_Microsystems. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -15,17 +21,17 @@ this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *****************************************************************************/ - -/*******************************************************************//** -@file ut/ut0rbt.c +/********************************************************************//** Red-Black tree implementation +(c) 2007 Oracle/Innobase Oy + Created 2007-03-20 Sunny Bains ***********************************************************************/ #include "ut0rbt.h" -/************************************************************************ +/**********************************************************************//** Definition of a red-black tree ============================== @@ -41,7 +47,8 @@ red-black properties: from (3) above, the implication is that on any path from the root to a leaf, red nodes must not be adjacent. - However, any number of black nodes may appear in a sequence. */ + However, any number of black nodes may appear in a sequence. + */ #if defined(IB_RBT_TESTING) #warning "Testing enabled!" @@ -50,15 +57,15 @@ red-black properties: #define ROOT(t) (t->root->left) #define SIZEOF_NODE(t) ((sizeof(ib_rbt_node_t) + t->sizeof_value) - 1) -/****************************************************************//** +/**********************************************************************//** Print out the sub-tree recursively. */ static void rbt_print_subtree( /*==============*/ - const ib_rbt_t* tree, /*!< in: tree to traverse */ - const ib_rbt_node_t* node, /*!< in: node to print */ - ib_rbt_print_node print) /*!< in: print key function */ + const ib_rbt_t* tree, /*!< in: tree to traverse */ + const ib_rbt_node_t* node, /*!< in: node to print */ + ib_rbt_print_node print) /*!< in: print key function */ { /* FIXME: Doesn't do anything yet */ if (node != tree->nil) { @@ -68,14 +75,14 @@ rbt_print_subtree( } } -/****************************************************************//** +/**********************************************************************//** Verify that the keys are in order. @return TRUE of OK. FALSE if not ordered */ static ibool rbt_check_ordering( /*===============*/ - const ib_rbt_t* tree) /*!< in: tree to verfify */ + const ib_rbt_t* tree) /*!< in: tree to verfify */ { const ib_rbt_node_t* node; const ib_rbt_node_t* prev = NULL; @@ -93,7 +100,7 @@ rbt_check_ordering( return(TRUE); } -/****************************************************************//** +/**********************************************************************//** Check that every path from the root to the leaves has the same count. Count is expressed in the number of black nodes. @return 0 on failure else black height of the subtree */ @@ -101,8 +108,8 @@ static ibool rbt_count_black_nodes( /*==================*/ - const ib_rbt_t* tree, /*!< in: tree to verify */ - const ib_rbt_node_t* node) /*!< in: start of sub-tree */ + const ib_rbt_t* tree, /*!< in: tree to verify */ + const ib_rbt_node_t* node) /*!< in: start of sub-tree */ { ulint result; @@ -141,15 +148,15 @@ rbt_count_black_nodes( return(result); } -/****************************************************************//** +/**********************************************************************//** Turn the node's right child's left sub-tree into node's right sub-tree. This will also make node's right child it's parent. */ static void rbt_rotate_left( /*============*/ - const ib_rbt_node_t* nil, /*!< in: nil node of the tree */ - ib_rbt_node_t* node) /*!< in: node to rotate */ + const ib_rbt_node_t* nil, /*!< in: nil node of the tree */ + ib_rbt_node_t* node) /*!< in: node to rotate */ { ib_rbt_node_t* right = node->right; @@ -177,15 +184,15 @@ rbt_rotate_left( node->parent = right; } -/****************************************************************//** +/**********************************************************************//** Turn the node's left child's right sub-tree into node's left sub-tree. This also make node's left child it's parent. */ static void rbt_rotate_right( /*=============*/ - const ib_rbt_node_t* nil, /*!< in: nil node of tree */ - ib_rbt_node_t* node) /*!< in: node to rotate */ + const ib_rbt_node_t* nil, /*!< in: nil node of tree */ + ib_rbt_node_t* node) /*!< in: node to rotate */ { ib_rbt_node_t* left = node->left; @@ -213,16 +220,15 @@ rbt_rotate_right( node->parent = left; } -/****************************************************************//** -Append a node to the tree. -@return inserted node */ +/**********************************************************************//** +Append a node to the tree. */ static ib_rbt_node_t* rbt_tree_add_child( /*===============*/ - const ib_rbt_t* tree, /*!< in: rbt tree */ - ib_rbt_bound_t* parent, /*!< in: node's parent */ - ib_rbt_node_t* node) /*!< in: node to add */ + const ib_rbt_t* tree, + ib_rbt_bound_t* parent, + ib_rbt_node_t* node) { /* Cast away the const. */ ib_rbt_node_t* last = (ib_rbt_node_t*) parent->last; @@ -241,16 +247,15 @@ rbt_tree_add_child( return(node); } -/****************************************************************//** -Generic binary tree insert -@return inserted node */ +/**********************************************************************//** +Generic binary tree insert */ static ib_rbt_node_t* rbt_tree_insert( /*============*/ - ib_rbt_t* tree, /*!< in: rb tree */ - const void* key, /*!< in: key for ordering */ - ib_rbt_node_t* node) /*!< in: node hold the insert value */ + ib_rbt_t* tree, + const void* key, + ib_rbt_node_t* node) { ib_rbt_bound_t parent; ib_rbt_node_t* current = ROOT(tree); @@ -278,14 +283,14 @@ rbt_tree_insert( return(node); } -/****************************************************************//** +/**********************************************************************//** Balance a tree after inserting a node. */ static void rbt_balance_tree( /*=============*/ - const ib_rbt_t* tree, /*!< in: tree to balance */ - ib_rbt_node_t* node) /*!< in: node that was inserted */ + const ib_rbt_t* tree, /*!< in: tree to balance */ + ib_rbt_node_t* node) /*!< in: node that was inserted */ { const ib_rbt_node_t* nil = tree->nil; ib_rbt_node_t* parent = node->parent; @@ -368,17 +373,17 @@ rbt_balance_tree( ROOT(tree)->color = IB_RBT_BLACK; } -/****************************************************************//** +/**********************************************************************//** Find the given node's successor. @return successor node or NULL if no successor */ static ib_rbt_node_t* rbt_find_successor( /*===============*/ - const ib_rbt_t* tree, /*!< in: rb tree */ - const ib_rbt_node_t* current)/*!< in: this is declared const - because it can be called via - rbt_next() */ + const ib_rbt_t* tree, /*!< in: rb tree */ + const ib_rbt_node_t* current) /*!< in: this is declared const + because it can be called via + rbt_next() */ { const ib_rbt_node_t* nil = tree->nil; ib_rbt_node_t* next = current->right; @@ -408,7 +413,7 @@ rbt_find_successor( return(next); } -/****************************************************************//** +/**********************************************************************//** Find the given node's precedecessor. @return predecessor node or NULL if no predecesor */ static @@ -448,15 +453,15 @@ rbt_find_predecessor( return(prev); } -/****************************************************************//** +/**********************************************************************//** Replace node with child. After applying transformations eject becomes an orphan. */ static void rbt_eject_node( /*===========*/ - ib_rbt_node_t* eject, /*!< in: node to eject */ - ib_rbt_node_t* node) /*!< in: node to replace with */ + ib_rbt_node_t* eject, /*!< in: node to eject */ + ib_rbt_node_t* node) /*!< in: node to replace with */ { /* Update the to be ejected node's parent's child pointers. */ if (eject->parent->left == eject) { @@ -472,14 +477,14 @@ rbt_eject_node( node->parent = eject->parent; } -/****************************************************************//** +/**********************************************************************//** Replace a node with another node. */ static void rbt_replace_node( /*=============*/ - ib_rbt_node_t* replace, /*!< in: node to replace */ - ib_rbt_node_t* node) /*!< in: node to replace with */ + ib_rbt_node_t* replace, /*!< in: node to replace */ + ib_rbt_node_t* node) /*!< in: node to replace with */ { ib_rbt_color_t color = node->color; @@ -499,15 +504,15 @@ rbt_replace_node( replace->color = color; } -/****************************************************************//** +/**********************************************************************//** Detach node from the tree replacing it with one of it's children. @return the child node that now occupies the position of the detached node */ static ib_rbt_node_t* rbt_detach_node( /*============*/ - const ib_rbt_t* tree, /*!< in: rb tree */ - ib_rbt_node_t* node) /*!< in: node to detach */ + const ib_rbt_t* tree, /*!< in: rb tree */ + ib_rbt_node_t* node) /*!< in: node to detach */ { ib_rbt_node_t* child; const ib_rbt_node_t* nil = tree->nil; @@ -542,16 +547,16 @@ rbt_detach_node( return(child); } -/****************************************************************//** +/**********************************************************************//** Rebalance the right sub-tree after deletion. @return node to rebalance if more rebalancing required else NULL */ static ib_rbt_node_t* rbt_balance_right( /*==============*/ - const ib_rbt_node_t* nil, /*!< in: rb tree nil node */ - ib_rbt_node_t* parent, /*!< in: parent node */ - ib_rbt_node_t* sibling)/*!< in: sibling node */ + const ib_rbt_node_t* nil, /*!< in: rb tree nil node */ + ib_rbt_node_t* parent, /*!< in: parent node */ + ib_rbt_node_t* sibling) /*!< in: sibling node */ { ib_rbt_node_t* node = NULL; @@ -602,16 +607,16 @@ rbt_balance_right( return(node); } -/****************************************************************//** +/**********************************************************************//** Rebalance the left sub-tree after deletion. @return node to rebalance if more rebalancing required else NULL */ static ib_rbt_node_t* rbt_balance_left( /*=============*/ - const ib_rbt_node_t* nil, /*!< in: rb tree nil node */ - ib_rbt_node_t* parent, /*!< in: parent node */ - ib_rbt_node_t* sibling)/*!< in: sibling node */ + const ib_rbt_node_t* nil, /*!< in: rb tree nil node */ + ib_rbt_node_t* parent, /*!< in: parent node */ + ib_rbt_node_t* sibling) /*!< in: sibling node */ { ib_rbt_node_t* node = NULL; @@ -662,14 +667,14 @@ rbt_balance_left( return(node); } -/****************************************************************//** +/**********************************************************************//** Delete the node and rebalance the tree if necessary */ static void rbt_remove_node_and_rebalance( /*==========================*/ - ib_rbt_t* tree, /*!< in: rb tree */ - ib_rbt_node_t* node) /*!< in: node to remove */ + ib_rbt_t* tree, /*!< in: rb tree */ + ib_rbt_node_t* node) /*!< in: node to remove */ { /* Detach node and get the node that will be used as rebalance start. */ @@ -714,14 +719,14 @@ rbt_remove_node_and_rebalance( --tree->n_nodes; } -/****************************************************************//** +/**********************************************************************//** Recursively free the nodes. */ static void rbt_free_node( /*==========*/ - ib_rbt_node_t* node, /*!< in: node to free */ - ib_rbt_node_t* nil) /*!< in: rb tree nil node */ + ib_rbt_node_t* node, /*!< in: node to free */ + ib_rbt_node_t* nil) /*!< in: rb tree nil node */ { if (node != nil) { rbt_free_node(node->left, nil); @@ -731,28 +736,28 @@ rbt_free_node( } } -/****************************************************************//** +/**********************************************************************//** Free all the nodes and free the tree. */ UNIV_INTERN void rbt_free( /*=====*/ - ib_rbt_t* tree) /*!< in: rb tree to free */ + ib_rbt_t* tree) /*!< in: rb tree to free */ { rbt_free_node(tree->root, tree->nil); ut_free(tree->nil); ut_free(tree); } -/****************************************************************//** +/**********************************************************************//** Create an instance of a red black tree. @return an empty rb tree */ UNIV_INTERN ib_rbt_t* rbt_create( /*=======*/ - size_t sizeof_value, /*!< in: sizeof data item */ - ib_rbt_compare compare) /*!< in: fn to compare items */ + size_t sizeof_value, /*!< in: sizeof data item */ + ib_rbt_compare compare) /*!< in: fn to compare items */ { ib_rbt_t* tree; ib_rbt_node_t* node; @@ -782,17 +787,17 @@ rbt_create( return(tree); } -/****************************************************************//** +/**********************************************************************//** Generic insert of a value in the rb tree. @return inserted node */ UNIV_INTERN const ib_rbt_node_t* rbt_insert( /*=======*/ - ib_rbt_t* tree, /*!< in: rb tree */ - const void* key, /*!< in: key for ordering */ - const void* value) /*!< in: value of key, this value - is copied to the node */ + ib_rbt_t* tree, /*!< in: rb tree */ + const void* key, /*!< in: key for ordering */ + const void* value) /*!< in: value of key, this value + is copied to the node */ { ib_rbt_node_t* node; @@ -811,17 +816,17 @@ rbt_insert( return(node); } -/****************************************************************//** +/**********************************************************************//** Add a new node to the tree, useful for data that is pre-sorted. @return appended node */ UNIV_INTERN const ib_rbt_node_t* rbt_add_node( /*=========*/ - ib_rbt_t* tree, /*!< in: rb tree */ - ib_rbt_bound_t* parent, /*!< in: bounds */ - const void* value) /*!< in: this value is copied - to the node */ + ib_rbt_t* tree, /*!< in: rb tree */ + ib_rbt_bound_t* parent, /*!< in: bounds */ + const void* value) /*!< in: this value is copied + to the node */ { ib_rbt_node_t* node; @@ -849,15 +854,15 @@ rbt_add_node( return(node); } -/****************************************************************//** +/**********************************************************************//** Find a matching node in the rb tree. @return NULL if not found else the node where key was found */ UNIV_INTERN const ib_rbt_node_t* rbt_lookup( /*=======*/ - const ib_rbt_t* tree, /*!< in: rb tree */ - const void* key) /*!< in: key to use for search */ + const ib_rbt_t* tree, /*!< in: rb tree */ + const void* key) /*!< in: key to use for search */ { const ib_rbt_node_t* current = ROOT(tree); @@ -877,15 +882,15 @@ rbt_lookup( return(current != tree->nil ? current : NULL); } -/****************************************************************//** -Delete a node from the red black tree, identified by key. +/**********************************************************************//** +Delete a node indentified by key. @return TRUE if success FALSE if not found */ UNIV_INTERN ibool rbt_delete( /*=======*/ - ib_rbt_t* tree, /*!< in: rb tree */ - const void* key) /*!< in: key to delete */ + ib_rbt_t* tree, /*!< in: rb tree */ + const void* key) /*!< in: key to delete */ { ibool deleted = FALSE; ib_rbt_node_t* node = (ib_rbt_node_t*) rbt_lookup(tree, key); @@ -900,7 +905,7 @@ rbt_delete( return(deleted); } -/****************************************************************//** +/**********************************************************************//** Remove a node from the rb tree, the node is not free'd, that is the callers responsibility. @return deleted node but without the const */ @@ -924,15 +929,15 @@ rbt_remove_node( return((ib_rbt_node_t*) const_node); } -/****************************************************************//** +/**********************************************************************//** Find the node that has the lowest key that is >= key. @return node satisfying the lower bound constraint or NULL */ UNIV_INTERN const ib_rbt_node_t* rbt_lower_bound( /*============*/ - const ib_rbt_t* tree, /*!< in: rb tree */ - const void* key) /*!< in: key to search */ + const ib_rbt_t* tree, /*!< in: rb tree */ + const void* key) /*!< in: key to search */ { ib_rbt_node_t* lb_node = NULL; ib_rbt_node_t* current = ROOT(tree); @@ -958,15 +963,15 @@ rbt_lower_bound( return(lb_node); } -/****************************************************************//** +/**********************************************************************//** Find the node that has the greatest key that is <= key. @return node satisfying the upper bound constraint or NULL */ UNIV_INTERN const ib_rbt_node_t* rbt_upper_bound( /*============*/ - const ib_rbt_t* tree, /*!< in: rb tree */ - const void* key) /*!< in: key to search */ + const ib_rbt_t* tree, /*!< in: rb tree */ + const void* key) /*!< in: key to search */ { ib_rbt_node_t* ub_node = NULL; ib_rbt_node_t* current = ROOT(tree); @@ -992,16 +997,16 @@ rbt_upper_bound( return(ub_node); } -/****************************************************************//** +/**********************************************************************//** Find the node that has the greatest key that is <= key. @return value of result */ UNIV_INTERN int rbt_search( /*=======*/ - const ib_rbt_t* tree, /*!< in: rb tree */ - ib_rbt_bound_t* parent, /*!< in: search bounds */ - const void* key) /*!< in: key to search */ + const ib_rbt_t* tree, /*!< in: rb tree */ + ib_rbt_bound_t* parent, /*!< in: search bounds */ + const void* key) /*!< in: key to search */ { ib_rbt_node_t* current = ROOT(tree); @@ -1026,7 +1031,7 @@ rbt_search( return(parent->result); } -/****************************************************************//** +/**********************************************************************//** Find the node that has the greatest key that is <= key. But use the supplied comparison function. @return value of result */ @@ -1034,10 +1039,10 @@ UNIV_INTERN int rbt_search_cmp( /*===========*/ - const ib_rbt_t* tree, /*!< in: rb tree */ - ib_rbt_bound_t* parent, /*!< in: search bounds */ - const void* key, /*!< in: key to search */ - ib_rbt_compare compare) /*!< in: fn to compare items */ + const ib_rbt_t* tree, /*!< in: rb tree */ + ib_rbt_bound_t* parent, /*!< in: search bounds */ + const void* key, /*!< in: key to search */ + ib_rbt_compare compare) /*!< in: fn to compare items */ { ib_rbt_node_t* current = ROOT(tree); @@ -1062,14 +1067,14 @@ rbt_search_cmp( return(parent->result); } -/****************************************************************//** -Get the leftmost node. +/**********************************************************************//** Return the left most node in the tree. */ UNIV_INTERN const ib_rbt_node_t* rbt_first( /*======*/ - const ib_rbt_t* tree) /* in: rb tree */ + /* out leftmost node or NULL */ + const ib_rbt_t* tree) /* in: rb tree */ { ib_rbt_node_t* first = NULL; ib_rbt_node_t* current = ROOT(tree); @@ -1082,14 +1087,14 @@ rbt_first( return(first); } -/****************************************************************//** +/**********************************************************************//** Return the right most node in the tree. @return the rightmost node or NULL */ UNIV_INTERN const ib_rbt_node_t* rbt_last( /*=====*/ - const ib_rbt_t* tree) /*!< in: rb tree */ + const ib_rbt_t* tree) /*!< in: rb tree */ { ib_rbt_node_t* last = NULL; ib_rbt_node_t* current = ROOT(tree); @@ -1102,39 +1107,39 @@ rbt_last( return(last); } -/****************************************************************//** +/**********************************************************************//** Return the next node. @return node next from current */ UNIV_INTERN const ib_rbt_node_t* rbt_next( /*=====*/ - const ib_rbt_t* tree, /*!< in: rb tree */ - const ib_rbt_node_t* current)/*!< in: current node */ + const ib_rbt_t* tree, /*!< in: rb tree */ + const ib_rbt_node_t* current) /*!< in: current node */ { return(current ? rbt_find_successor(tree, current) : NULL); } -/****************************************************************//** +/**********************************************************************//** Return the previous node. @return node prev from current */ UNIV_INTERN const ib_rbt_node_t* rbt_prev( /*=====*/ - const ib_rbt_t* tree, /*!< in: rb tree */ - const ib_rbt_node_t* current)/*!< in: current node */ + const ib_rbt_t* tree, /*!< in: rb tree */ + const ib_rbt_node_t* current) /*!< in: current node */ { return(current ? rbt_find_predecessor(tree, current) : NULL); } -/****************************************************************//** +/**********************************************************************//** Reset the tree. Delete all the nodes. */ UNIV_INTERN void rbt_clear( /*======*/ - ib_rbt_t* tree) /*!< in: rb tree */ + ib_rbt_t* tree) /*!< in: rb tree */ { rbt_free_node(ROOT(tree), tree->nil); @@ -1142,15 +1147,15 @@ rbt_clear( tree->root->left = tree->root->right = tree->nil; } -/****************************************************************//** +/**********************************************************************//** Merge the node from dst into src. Return the number of nodes merged. @return no. of recs merged */ UNIV_INTERN ulint rbt_merge_uniq( /*===========*/ - ib_rbt_t* dst, /*!< in: dst rb tree */ - const ib_rbt_t* src) /*!< in: src rb tree */ + ib_rbt_t* dst, /*!< in: dst rb tree */ + const ib_rbt_t* src) /*!< in: src rb tree */ { ib_rbt_bound_t parent; ulint n_merged = 0; @@ -1171,7 +1176,7 @@ rbt_merge_uniq( return(n_merged); } -/****************************************************************//** +/**********************************************************************//** Merge the node from dst into src. Return the number of nodes merged. Delete the nodes from src after copying node to dst. As a side effect the duplicates will be left untouched in the src. @@ -1180,8 +1185,8 @@ UNIV_INTERN ulint rbt_merge_uniq_destructive( /*=======================*/ - ib_rbt_t* dst, /*!< in: dst rb tree */ - ib_rbt_t* src) /*!< in: src rb tree */ + ib_rbt_t* dst, /*!< in: dst rb tree */ + ib_rbt_t* src) /*!< in: src rb tree */ { ib_rbt_bound_t parent; ib_rbt_node_t* src_node; @@ -1219,7 +1224,7 @@ rbt_merge_uniq_destructive( return(rbt_size(dst) - old_size); } -/****************************************************************//** +/**********************************************************************//** Check that every path from the root to the leaves has the same count and the tree nodes are in order. @return TRUE if OK FALSE otherwise */ @@ -1236,14 +1241,14 @@ rbt_validate( return(FALSE); } -/****************************************************************//** +/**********************************************************************//** Iterate over the tree in depth first order. */ UNIV_INTERN void rbt_print( /*======*/ - const ib_rbt_t* tree, /*!< in: tree to traverse */ - ib_rbt_print_node print) /*!< in: print function */ + const ib_rbt_t* tree, /*!< in: tree to traverse */ + ib_rbt_print_node print) /*!< in: print function */ { rbt_print_subtree(tree, ROOT(tree), print); } diff --git a/storage/xtradb/ut/ut0ut.c b/storage/xtradb/ut/ut0ut.c index 498873e290a..a9c0d381e16 100644 --- a/storage/xtradb/ut/ut0ut.c +++ b/storage/xtradb/ut/ut0ut.c @@ -1,13 +1,6 @@ /***************************************************************************** -Copyright (c) 1994, 2009, Innobase Oy. All Rights Reserved. -Copyright (c) 2009, Sun Microsystems, Inc. - -Portions of this file contain modifications contributed and copyrighted by -Sun Microsystems, Inc. Those modifications are gratefully acknowledged and -are described briefly in the InnoDB documentation. The contributions by -Sun Microsystems are incorporated with their permission, and subject to the -conditions contained in the file COPYING.Sun_Microsystems. +Copyright (c) 2011, Oracle Corpn. All Rights Reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -623,3 +616,115 @@ ut_snprintf( return(res); } #endif /* __WIN__ */ + +/*************************************************************//** +Convert an error number to a human readable text message. The +returned string is static and should not be freed or modified. +@return string, describing the error */ +UNIV_INTERN +const char* +ut_strerr( +/*======*/ + enum db_err num) /*!< in: error number */ +{ + switch (num) { + case DB_SUCCESS: + return("Success"); + case DB_SUCCESS_LOCKED_REC: + return("Success, record lock created"); + case DB_ERROR: + return("Generic error"); + case DB_INTERRUPTED: + return("Operation interrupted"); + case DB_OUT_OF_MEMORY: + return("Cannot allocate memory"); + case DB_OUT_OF_FILE_SPACE: + return("Out of disk space"); + case DB_LOCK_WAIT: + return("Lock wait"); + case DB_DEADLOCK: + return("Deadlock"); + case DB_ROLLBACK: + return("Rollback"); + case DB_DUPLICATE_KEY: + return("Duplicate key"); + case DB_QUE_THR_SUSPENDED: + return("The queue thread has been suspended"); + case DB_MISSING_HISTORY: + return("Required history data has been deleted"); + case DB_CLUSTER_NOT_FOUND: + return("Cluster not found"); + case DB_TABLE_NOT_FOUND: + return("Table not found"); + case DB_MUST_GET_MORE_FILE_SPACE: + return("More file space needed"); + case DB_TABLE_IS_BEING_USED: + return("Table is being used"); + case DB_TOO_BIG_RECORD: + return("Record too big"); + case DB_TOO_BIG_INDEX_COL: + return("Index columns size too big"); + case DB_LOCK_WAIT_TIMEOUT: + return("Lock wait timeout"); + case DB_NO_REFERENCED_ROW: + return("Referenced key value not found"); + case DB_ROW_IS_REFERENCED: + return("Row is referenced"); + case DB_CANNOT_ADD_CONSTRAINT: + return("Cannot add constraint"); + case DB_CORRUPTION: + return("Data structure corruption"); + case DB_COL_APPEARS_TWICE_IN_INDEX: + return("Column appears twice in index"); + case DB_CANNOT_DROP_CONSTRAINT: + return("Cannot drop constraint"); + case DB_NO_SAVEPOINT: + return("No such savepoint"); + case DB_TABLESPACE_ALREADY_EXISTS: + return("Tablespace already exists"); + case DB_TABLESPACE_DELETED: + return("No such tablespace"); + case DB_LOCK_TABLE_FULL: + return("Lock structs have exhausted the buffer pool"); + case DB_FOREIGN_DUPLICATE_KEY: + return("Foreign key activated with duplicate keys"); + case DB_FOREIGN_EXCEED_MAX_CASCADE: + return("Foreign key cascade delete/update exceeds max depth"); + case DB_TOO_MANY_CONCURRENT_TRXS: + return("Too many concurrent transactions"); + case DB_UNSUPPORTED: + return("Unsupported"); + case DB_PRIMARY_KEY_IS_NULL: + return("Primary key is NULL"); + case DB_STATS_DO_NOT_EXIST: + return("Persistent statistics do not exist"); + case DB_FAIL: + return("Failed, retry may succeed"); + case DB_OVERFLOW: + return("Overflow"); + case DB_UNDERFLOW: + return("Underflow"); + case DB_STRONG_FAIL: + return("Failed, retry will not succeed"); + case DB_ZIP_OVERFLOW: + return("Zip overflow"); + case DB_RECORD_NOT_FOUND: + return("Record not found"); + case DB_CHILD_NO_INDEX: + return("No index on referencing keys in referencing table"); + case DB_PARENT_NO_INDEX: + return("No index on referenced keys in referenced table"); + case DB_END_OF_INDEX: + return("End of index"); + /* do not add default: in order to produce a warning if new code + is added to the enum but not added here */ + } + + /* we abort here because if unknown error code is given, this could + mean that memory corruption has happened and someone's error-code + variable has been overwritten with bogus data */ + ut_error; + + /* NOT REACHED */ + return("Unknown error"); +} diff --git a/storage/xtradb/ut/ut0wqueue.c b/storage/xtradb/ut/ut0wqueue.c index 5220d1e17f4..d32086bdfc4 100644 --- a/storage/xtradb/ut/ut0wqueue.c +++ b/storage/xtradb/ut/ut0wqueue.c @@ -35,7 +35,9 @@ ib_wqueue_create(void) { ib_wqueue_t* wq = mem_alloc(sizeof(ib_wqueue_t)); - mutex_create(&wq->mutex, SYNC_WORK_QUEUE); + /* Function ib_wqueue_create() has not been used anywhere, + not necessary to instrument this mutex */ + mutex_create(PFS_NOT_INSTRUMENTED, &wq->mutex, SYNC_WORK_QUEUE); wq->items = ib_list_create(); wq->event = os_event_create(NULL); |