dbTalk Databases Forums  

Cursor read fail at exactly 40,000 record point

comp.databases.berkeley-db comp.databases.berkeley-db


Discuss Cursor read fail at exactly 40,000 record point in the comp.databases.berkeley-db forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Gerard J. Nicol
 
Posts: n/a

Default Cursor read fail at exactly 40,000 record point - 05-22-2007 , 04:32 PM






I have an application that is using Berkeley DB 4.5.20 under Windows
2003.

One particular database has around 200,000 records and regularly
creates a cursor, positions at starting points and reads records until
the records go out of scope.

In one particular instance the application reads a set of records that
amount to over 50,000 records. Usually all is OK, but every few days
the read starts returning only exactly 40,000 records for the same
set. This continues to occur until the application is restarted and
the environment renewed. When the application is restarted the correct
number of records is returned.

Can anybody suggest what could be causing this error?

Gerard


Reply With Quote
  #2  
Old   
michael.cahill@gmail.com
 
Posts: n/a

Default Re: Cursor read fail at exactly 40,000 record point - 05-22-2007 , 11:56 PM






Hi Gerard,

Quote:
One particular database has around 200,000 records and regularly
creates a cursor, positions at starting points and reads records until
the records go out of scope.

In one particular instance the application reads a set of records that
amount to over 50,000 records. Usually all is OK, but every few days
the read starts returning only exactly 40,000 records for the same
set. This continues to occur until the application is restarted and
the environment renewed. When the application is restarted the correct
number of records is returned.
I don't understand why this would be happening. Can you give a few
more details:

* what type of database are you using (btree, hash, etc.)?
* is the database configured to support duplicates?
* how do you read the records (just cursor gets with DB_SET followed
by some number of DB_NEXT calls, or something more exotic)?
* how is the end of set determined (key goes out of scope, DB_NOTFOUND
at the end of the database, or some other condition)?

Regards,
Michael Cahill, Oracle.



Reply With Quote
  #3  
Old   
Philip Guenther
 
Posts: n/a

Default Re: Cursor read fail at exactly 40,000 record point - 05-23-2007 , 12:38 AM



On May 22, 3:32 pm, "Gerard J. Nicol" <gerard.ni... (AT) tapetrack (DOT) com>
wrote:
Quote:
One particular database has around 200,000 records and regularly
creates a cursor, positions at starting points and reads records until
the records go out of scope.

In one particular instance the application reads a set of records that
amount to over 50,000 records. Usually all is OK, but every few days
the read starts returning only exactly 40,000 records for the same
set. This continues to occur until the application is restarted and
the environment renewed. When the application is restarted the correct
number of records is returned.
What is the error returned by DBC->c_get() when it fails to return
another record?

Is the cursor inside a transaction? What flags are used when the
database environment
and involved database table are opened?


Philip Guenther



Reply With Quote
  #4  
Old   
Gerard J. Nicol
 
Posts: n/a

Default Re: Cursor read fail at exactly 40,000 record point - 05-23-2007 , 04:24 AM



Michael,

I was getting no errors from the database (even with verbose message).
I have just tracked down the problem to:

(1) The database cache was set to 1 GB on a machine with 8 GB of RAM.
(2) It would appear that Windows limits the per address space storage
to 1 GB.
(3) Each record is 300 bytes.
(4) I use a custom array function that automatically grows (via
realloc). In this case it was set to grow by 10,000 records each time.

It would appear that the database was monopolizing most of the
available address space memory. When the array grew and the record set
got large the realloc was requiring a lot of memory for both the
source and destination.

The array function was returning a failure after the array failed to
grow but I was not catching this.

So in the end it was not the database environment as such. It was the
database environment sucking up the RAM and leaving insufficient
contiguous memory for the rest of the application.

A work around for the problem was to reduce the cache size. I will
also fix the code to read through the record set twice, once to count
the records and a second time to populate the array with a single
malloc. It would be nice if you could count the keys between a key
range without having to read every record!

Thanks for taking an interest.

Gerard




Reply With Quote
  #5  
Old   
michael.cahill@gmail.com
 
Posts: n/a

Default Re: Cursor read fail at exactly 40,000 record point - 05-24-2007 , 07:01 AM



Hi Gerard,

Quote:
So in the end it was not the database environment as such. It was the
database environment sucking up the RAM and leaving insufficient
contiguous memory for the rest of the application.
You might want to investigate the "/3GB" switch when starting Windows:

http://technet.microsoft.com/en-us/l...ae443ecbf.aspx

Alternatively, Windows X64 obviously doesn't have this restriction.

Quote:
A work around for the problem was to reduce the cache size. I will
also fix the code to read through the record set twice, once to count
the records and a second time to populate the array with a single
malloc. It would be nice if you could count the keys between a key
range without having to read every record!
The DB_RECNUM flag to Berkeley DB can give you this count, but
maintaining the record numbers effectively prevents concurrent
updates.

Regards,
Michael.



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.