List:Commits« Previous MessageNext Message »
From:kroki Date:January 9 2007 9:24am
Subject:bk commit into 4.0 tree (kroki:1.2198) BUG#23443
View as plain text  
Below is the list of changes that have just been committed into a local
4.0 repository of tomash. When tomash 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@stripped, 2007-01-09 12:24:25+03:00, kroki@stripped +3 -0
  BUG#23443: user-defined variables can consume too much memory in the
             server
  
  The problem was that when memory was exhausted HEAP engine could crash
  (GROUP BY uses HEAP TABLE).  Alternatively, if SET was used, it could
  report an error "You may only use constant expressions with SET" instead
  of "Out of memory (Needed NNNNNN bytes)".
  
  The solution is:
   - pass MY_WME to (some) calls to my_malloc() to get correct message.
   - fix heap_write() so that the first key is skipped during cleanup
     on ENOMEM because it wasn't inserted and doesn't have to be
     deleted.
  
  No test case is provided because we can't test out-of-memory behaviour
  in our current test framework.

  heap/hp_block.c@stripped, 2007-01-09 12:24:25+03:00, kroki@stripped +1 -1
    If allocation fails, write an error message.

  heap/hp_write.c@stripped, 2007-01-09 12:24:25+03:00, kroki@stripped +12 -3
    On ENOMEM, skip the first key in cleanup, as it wasn't inserted yet.

  sql/item_func.cc@stripped, 2007-01-09 12:24:25+03:00, kroki@stripped +3 -2
    Add MY_WME so that OOM error will be reported.

# 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:	kroki
# Host:	moonlight.home
# Root:	/home/tomash/src/mysql_ab/mysql-4.0-bug23443

--- 1.4/heap/hp_block.c	2007-01-09 12:24:28 +03:00
+++ 1.5/heap/hp_block.c	2007-01-09 12:24:28 +03:00
@@ -47,7 +47,7 @@ int _hp_get_new_block(HP_BLOCK *block, u
       break;
 
   *alloc_length=sizeof(HP_PTRS)*i+block->records_in_block* block->recbuffer;
-  if (!(root=(HP_PTRS*) my_malloc(*alloc_length,MYF(0))))
+  if (!(root=(HP_PTRS*) my_malloc(*alloc_length,MYF(MY_WME))))
     return 1;
 
   if (i == 0)

--- 1.10/heap/hp_write.c	2007-01-09 12:24:28 +03:00
+++ 1.11/heap/hp_write.c	2007-01-09 12:24:28 +03:00
@@ -66,13 +66,22 @@ int heap_write(HP_INFO *info, const byte
   DBUG_RETURN(0);
 
 err:
-  DBUG_PRINT("info",("Duplicate key: %d",key));
+  if (my_errno == HA_ERR_FOUND_DUPP_KEY)
+    DBUG_PRINT("info",("Duplicate key: %d",key));
   info->errkey= key;
-  do
+  /*
+    Because 'key' is unsigned, we increase it before the loop, unless
+    we have to skip the key that wasn't inserted yet due to OOM.  In
+    the loop we test 'key' before decreasing it as the protection
+    against value wraparound.
+  */
+  if (my_errno != ENOMEM)
+    key++;
+  while (key-- > 0)
   {
     if (_hp_delete_key(info,share->keydef+key,record,pos,0))
       break;
-  } while (key-- > 0);
+  }
 
   share->deleted++;
   *((byte**) pos)=share->del_link;

--- 1.113/sql/item_func.cc	2007-01-09 12:24:28 +03:00
+++ 1.114/sql/item_func.cc	2007-01-09 12:24:28 +03:00
@@ -1892,8 +1892,9 @@ bool Item_func_set_user_var::update_hash
 	char *pos= (char*) entry+ ALIGN_SIZE(sizeof(user_var_entry));
 	if (entry->value == pos)
 	  entry->value=0;
-	if (!(entry->value=(char*) my_realloc(entry->value, length,
-					      MYF(MY_ALLOW_ZERO_PTR))))
+        entry->value= (char*) my_realloc(entry->value, length,
+                                         MYF(MY_ALLOW_ZERO_PTR | MY_WME));
+        if (!entry->value)
 	  goto err;
       }
     }
Thread
bk commit into 4.0 tree (kroki:1.2198) BUG#23443kroki9 Jan