[EMAIL PROTECTED] wrote:
> "Igor Tandetnik" <[EMAIL PROTECTED]> wrote:
>   
>> "B V, Phanisekhar" <[EMAIL PROTECTED]> wrote in
>> message news:[EMAIL PROTECTED]
>>     
>>> So is it possible
>>> that SQLITE will give an error when attempting to insert a record even
>>> if there are free ROWID's?
>>>       
>> Yes, in theory. If you have close to 2^63-1 rows, probing at random for 
>> a ROWID to reuse may just happen to keep hitting occupied ROWIDs. If I 
>> remember correctly, after a certain number of unsuccessful attemps 
>> SQLite gives up and returns an error.
>>     
>
> You remember correctly.  Up to 100 random rowids are attempted.
> If no unused rowid is found, SQLITE_FULL is returned.  
>
> As an aside, I note that this logic presents some interesting
> problems for testing.  How does one verify that random rowid
> algorithm works and that it really does stop after 100 tries
> and return SQLITE_FULL?  How does one construct a test that 
> collides for 100 randomly chosen rowids?  We can force the 
> random-rowid logic to run simply by inserting a row with a 
> rowid of 9223372036854775807. But how can we get collisions 
> to happen 100 times in a row without inserting 
> 18446744073709551616 distinct rows?
>
> Our solution to this problem is that we allow the test script
> to monkey with the state of the Pseudo-Random Number Generator
> (PRNG) that SQLite uses to generate random rowids.  On a test
> build, we have special APIs that will save the current state
> of the PRNG and that will restore the state of the PRNG to its
> most recently saved state.
>   

There is a fairly common pattern where the random number generator is 
passed into the system under test as an abstraction.  That permits one 
to substitute any type of mock generator one would like, including one 
accessing an array of specifically picked numbers.  Easier to do in 
languages which either support interfaces or dynamic typing, although I 
guess you could do it in C as a callback function.


John
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to