------------------------------------------------------------ revno: 685 revision-id:[EMAIL PROTECTED] parent: [EMAIL PROTECTED] committer: Andrew Tridgell <[EMAIL PROTECTED]> branch nick: s3-ctdb-tridge timestamp: Thu 2008-01-10 09:45:02 +1100 message: merge tdb from ctdbd modified: source/lib/tdb/common/freelist.c freelist.c-20070416112700-wu1jh7in2kvfbr2w-16 === modified file 'source/lib/tdb/common/freelist.c' --- a/source/lib/tdb/common/freelist.c 2008-01-08 21:52:16 +0000 +++ b/source/lib/tdb/common/freelist.c 2008-01-09 22:45:02 +0000 @@ -280,6 +280,7 @@ tdb_off_t rec_ptr, last_ptr; tdb_len_t rec_len; } bestfit; + float multiplier = 1.0; if (tdb_lock(tdb, -1, F_WRLCK) == -1) return 0; @@ -314,13 +315,27 @@ bestfit.rec_len = rec->rec_len; bestfit.rec_ptr = rec_ptr; bestfit.last_ptr = last_ptr; - break; } } /* move to the next record */ last_ptr = rec_ptr; rec_ptr = rec->next; + + /* if we've found a record that is big enough, then + stop searching if its also not too big. The + definition of 'too big' changes as we scan + through */ + if (bestfit.rec_len > 0 && + bestfit.rec_len < length * multiplier) { + break; + } + + /* this multiplier means we only extremely rarely + search more than 50 or so records. At 50 records we + accept records up to 11 times larger than what we + want */ + multiplier *= 1.05; } if (bestfit.rec_ptr != 0) { @@ -357,9 +372,8 @@ } ptr = FREELIST_TOP; - while (ptr != 0 && tdb_ofs_read(tdb, ptr, &ptr) == 0) { + while (tdb_ofs_read(tdb, ptr, &ptr) == 0 && ptr != 0) { count++; - } tdb_unlock(tdb, -1, F_RDLCK);