From d1bec47a3d9c62a849d12782f8dcdaf6fc63bf74 Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 15 Jan 2004 13:29:31 +0000 Subject: [PATCH] More aggressive retry schedule in sqlite_busy_timeout(). (CVS 1181) FossilOrigin-Name: 5e85025be7aa4a03b0cfb4d0f28a2e44653b9d3f --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/main.c | 29 +++++++++++++++-------------- test/lock.test | 16 ++++++++++++++-- 4 files changed, 37 insertions(+), 24 deletions(-) diff --git a/manifest b/manifest index f08f144701..8093b607a4 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Allow\s"\sIN\s"\sas\sa\sshorthand\sfor\n"\sIN\s(SELECT\s*\sFROM\s
)"\s(CVS\s1180) -D 2004-01-15T03:30:25 +C More\saggressive\sretry\sschedule\sin\ssqlite_busy_timeout().\s(CVS\s1181) +D 2004-01-15T13:29:32 F Makefile.in 0515ff9218ad8d5a8f6220f0494b8ef94c67013b F Makefile.linux-gcc b86a99c493a5bfb402d1d9178dcdc4bd4b32f906 F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd @@ -36,7 +36,7 @@ F src/func.c 62cf8fae8147c0301d1c6a4a94fe0a78f7aa5b33 F src/hash.c 9b56ef3b291e25168f630d5643a4264ec011c70e F src/hash.h 3247573ab95b9dd90bcca0307a75d9a16da1ccc7 F src/insert.c 01f66866f35c986eab4a57373ca689a3255ef2df -F src/main.c 67af644fa7c1b8bb06032b6a9459d084cf79bb81 +F src/main.c 808ea1bda0798f4a714479aee8289d65f04cf29b F src/md5.c fe4f9c9c6f71dfc26af8da63e4d04489b1430565 F src/os.c 681ec36217bc7c795d55d9a63ff79a8614ddee8c F src/os.h 257c9aef1567bb20c8b767fc27fe3ee7d89104e0 @@ -97,7 +97,7 @@ F test/intpkey.test 9320af48415c594afd4e15f8ef0daa272e05502e F test/ioerr.test 5dbaf09f96b56ee01cf3edd762b96eb4ad2c9ca4 F test/join.test 9ef6aabaac9de51d5fc41e68d1f4355da05a84cd F test/limit.test fa2a8b3fe377ebe60e0bc9a6a35af9ac4eb3d2b3 -F test/lock.test 388a3a10962d2d571c0c1821cc35bf069ee73473 +F test/lock.test 3d1855ba930732566f569d680e828656bd5b7f5c F test/main.test 6a851b5992c4881a725a3d9647e629199df8de9d F test/malloc.test 7ba32a9ebd3aeed52ae4aaa6d42ca37e444536fd F test/memdb.test 6ece25c7c0e6500199d3662607a3edca081abb2a @@ -180,7 +180,7 @@ F www/speed.tcl 2f6b1155b99d39adb185f900456d1d592c4832b3 F www/sqlite.tcl 3c83b08cf9f18aa2d69453ff441a36c40e431604 F www/tclsqlite.tcl b9271d44dcf147a93c98f8ecf28c927307abd6da F www/vdbe.tcl 9b9095d4495f37697fd1935d10e14c6015e80aa1 -P 72bc84f2f18f6eeb279a4ad670310e85d154f663 -R 2bc9ea54c7ac36ba81835b3e442ee3bc +P 01874d252ac44861e927dea3f5534f67e19b1fa8 +R 889c699198a4172a6f24b672e8a9f759 U drh -Z 123afbc81ac483920b37bfd6b69d6479 +Z 4f8f302ff0837a7468fa75430d63c5d0 diff --git a/manifest.uuid b/manifest.uuid index 22eb6ee030..3d91402ba1 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -01874d252ac44861e927dea3f5534f67e19b1fa8 \ No newline at end of file +5e85025be7aa4a03b0cfb4d0f28a2e44653b9d3f \ No newline at end of file diff --git a/src/main.c b/src/main.c index 2b4a396ca7..17d2e04eb2 100644 --- a/src/main.c +++ b/src/main.c @@ -14,7 +14,7 @@ ** other files are for internal use by SQLite and should not be ** accessed by users of the library. ** -** $Id: main.c,v 1.145 2004/01/15 02:44:03 drh Exp $ +** $Id: main.c,v 1.146 2004/01/15 13:29:32 drh Exp $ */ #include "sqliteInt.h" #include "os.h" @@ -784,22 +784,23 @@ static int sqliteDefaultBusyCallback( int count /* Number of times table has been busy */ ){ #if SQLITE_MIN_SLEEP_MS==1 - int delay = 10; - int prior_delay = 0; + static const char delays[] = + { 1, 2, 5, 10, 15, 20, 25, 25, 25, 50, 50, 50, 100}; + static const short int totals[] = + { 0, 1, 3, 8, 18, 33, 53, 78, 103, 128, 178, 228, 287}; +# define NDELAY (sizeof(delays)/sizeof(delays[0])) int timeout = (int)Timeout; - int i; + int delay, prior; - for(i=1; i=1000 ){ - delay = 1000; - prior_delay += 1000*(count - i - 1); - break; - } + if( count <= NDELAY ){ + delay = delays[count-1]; + prior = totals[count-1]; + }else{ + delay = delays[NDELAY-1]; + prior = totals[NDELAY-1] + delay*(count-NDELAY-1); } - if( prior_delay + delay > timeout ){ - delay = timeout - prior_delay; + if( prior + delay > timeout ){ + delay = timeout - prior; if( delay<=0 ) return 0; } sqliteOsSleep(delay); diff --git a/test/lock.test b/test/lock.test index ca715fffff..e7f1eddd05 100644 --- a/test/lock.test +++ b/test/lock.test @@ -11,7 +11,7 @@ # This file implements regression tests for SQLite library. The # focus of this script is database locks. # -# $Id: lock.test,v 1.18 2002/09/14 13:47:33 drh Exp $ +# $Id: lock.test,v 1.19 2004/01/15 13:29:40 drh Exp $ set testdir [file dirname $argv0] @@ -232,7 +232,19 @@ do_test lock-2.7 { lappend r $msg lappend r $::callback_value } {0 {} {1 2 3}} -integrity_check lock-2.8 + +# Test the built-in busy timeout handler +# +do_test lock-2.8 { + db2 timeout 400 + execsql BEGIN + catchsql BEGIN db2 +} {1 {database is locked}} +do_test lock-2.9 { + db2 timeout 0 + execsql COMMIT +} {} +integrity_check lock-2.10 # Try to start two transactions in a row #