From: Date: September 25 2007 12:01pm Subject: bk commit into 5.0 tree (stewart:1.2482) BUG#30379 List-Archive: http://lists.mysql.com/commits/34543 X-Bug: 30379 Message-Id: <20070925100130.0CC6DA18AFF@localhost.localdomain> Below is the list of changes that have just been committed into a local 5.0 repository of stewart. When stewart 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-09-25 12:01:23+02:00, stewart@stripped +4 -0 [PATCH] BUG#30379 Better randomise time before retry in timeout check (DBTC) timoOutLoopStartLab() checks if any transactions have been delayed for so long that we are forced to perform some action (e.g. abort, resend etc). It is *MEANT* to (according to the comment): > To avoid aborting both transactions in a deadlock detected by time-out > we insert a random extra time-out of upto 630 ms by using the lowest > six bits of the api connect reference. > We spread it out from 0 to 630 ms if base time-out is larger than 3 sec, > we spread it out from 0 to 70 ms if base time-out is smaller than 300 msec, > and otherwise we spread it out 310 ms. The comment (as all do) lies. the API connect reference is not very random, producing incredibly predictable "random" numbers. This could lead to both txns being aborted instead of just one. Before: timeout value: 123 3 timeout value: 122 2 timeout value: 122 2 timeout value: 122 2 timeout value: 123 3 After: timeout value: 127 7 timeout value: 126 6 timeout value: 129 9 timeout value: 139 19 timeout value: 137 17 timeout value: 151 31 timeout value: 130 10 timeout value: 132 12 Index: ndb-work/ndb/src/kernel/blocks/dbtc/DbtcMain.cpp =================================================================== ndb/include/util/ndb_rand.h@stripped, 2007-09-25 11:02:59+02:00, stewart@stripped +33 -0 BUG#30379 Better randomise time before retry in timeout check (DBTC) ndb/include/util/ndb_rand.h@stripped, 2007-09-25 11:02:59+02:00, stewart@stripped +0 -0 ndb/src/common/util/Makefile.am@stripped, 2007-09-25 11:02:59+02:00, stewart@stripped +2 -1 BUG#30379 Better randomise time before retry in timeout check (DBTC) ndb/src/common/util/ndb_rand.c@stripped, 2007-09-25 11:02:59+02:00, stewart@stripped +40 -0 BUG#30379 Better randomise time before retry in timeout check (DBTC) ndb/src/common/util/ndb_rand.c@stripped, 2007-09-25 11:02:59+02:00, stewart@stripped +0 -0 ndb/src/kernel/blocks/dbtc/DbtcMain.cpp@stripped, 2007-09-25 11:02:59+02:00, stewart@stripped +3 -1 BUG#30379 Better randomise time before retry in timeout check (DBTC) # 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: stewart # Host: willster.(none) # Root: /home/stewart/Documents/MySQL/5.0/ndb --- 1.112/ndb/src/kernel/blocks/dbtc/DbtcMain.cpp 2007-08-13 09:22:40 +02:00 +++ 1.113/ndb/src/kernel/blocks/dbtc/DbtcMain.cpp 2007-09-25 11:02:59 +02:00 @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -6278,7 +6279,8 @@ jam(); if (api_timer != 0) { Uint32 error= ZTIME_OUT_ERROR; - time_out_value= time_out_param + (api_con_ptr & mask_value); + time_out_value= time_out_param + (ndb_rand() & mask_value); + ndbout_c("timeout value: %u %u",time_out_value, time_out_value-time_out_param); if (unlikely(old_mask_value)) // abort during single user mode { apiConnectptr.i = api_con_ptr; --- New file --- +++ ndb/include/util/ndb_rand.h 07/09/25 11:02:59 /* Copyright (C) 2003 MySQL AB 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 */ #ifndef NDB_RAND_H #define NDB_RAND_H #define NDB_RAND_MAX 32767 #ifdef __cplusplus extern "C" { #endif int ndb_rand(void); void ndb_srand(unsigned seed); #ifdef __cplusplus } #endif #endif --- New file --- +++ ndb/src/common/util/ndb_rand.c 07/09/25 11:02:59 /* Copyright (C) 2003 MySQL AB 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 */ #include static unsigned long next= 1; /** * ndb_rand * * constant time, cheap, pseudo-random number generator. * * NDB_RAND_MAX assumed to be 32767 * * This is the POSIX example for "generating the same sequence on * different machines". Although that is not one of our requirements. */ int ndb_rand(void) { next= next * 1103515245 + 12345; return((unsigned)(next/65536) % 32768); } void ndb_srand(unsigned seed) { next= seed; } --- 1.12/ndb/src/common/util/Makefile.am 2006-12-30 22:07:31 +01:00 +++ 1.13/ndb/src/common/util/Makefile.am 2007-09-25 11:02:59 +02:00 @@ -24,7 +24,8 @@ uucode.c random.c version.c \ strdup.c \ ConfigValues.cpp ndb_init.c basestring_vsnprintf.c \ - Bitmask.cpp + Bitmask.cpp \ + ndb_rand.c EXTRA_PROGRAMS = testBitmask testBitmask_SOURCES = testBitmask.cpp