dbTalk Databases Forums  

JE Reading in Insertion Order

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


Discuss JE Reading in Insertion Order in the comp.databases.berkeley-db forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
theschooligan@gmail.com
 
Posts: n/a

Default JE Reading in Insertion Order - 08-22-2006 , 08:19 PM






Is there a way in JE to read records in insertion order? I'd like to
use a cursor, but they seem to always sort records by keys.

Patrick


Reply With Quote
  #2  
Old   
mark.hayes@oracle.com
 
Posts: n/a

Default Re: JE Reading in Insertion Order - 08-23-2006 , 12:23 PM






theschooligan (AT) gmail (DOT) com wrote:
Quote:
Is there a way in JE to read records in insertion order? I'd like to
use a cursor, but they seem to always sort records by keys.
JE stores and retrieves records in an ordered Btree, so records are
always retrieved in key order. The only way (currently) to return
records in insertion order is to use a key that is incremented to match
insertion order. That could be the primary key or a secondary key.
Timestamps or a sequence could be used to assign key values.

We are considering adding a way to retrieve records in arbitrary
storage (log file) order. This would be for better performance when
order of retrieval doesn't matter. It would *roughly* be insertion
order, but would not be insertion order when records had been migrated
by the cleaner or updated.

Hope this helps,
Mark



Reply With Quote
  #3  
Old   
theschooligan@gmail.com
 
Posts: n/a

Default Re: JE Reading in Insertion Order - 08-23-2006 , 02:07 PM




mark.hayes (AT) oracle (DOT) com wrote:
Quote:
theschooligan (AT) gmail (DOT) com wrote:
Is there a way in JE to read records in insertion order? I'd like to
use a cursor, but they seem to always sort records by keys.

JE stores and retrieves records in an ordered Btree, so records are
always retrieved in key order. The only way (currently) to return
records in insertion order is to use a key that is incremented to match
insertion order. That could be the primary key or a secondary key.
Timestamps or a sequence could be used to assign key values.
Thanks for your quick reply, Mark.

I tried implementing your suggestion using timestamps as a secondary
key, but I ran into some problems. Now when I try to remove records
from the database, I get the following exception:

Secondary TestSimple_sec_db is corrupt: the primary record contains a
key that is not present in the secondary

What I see happening is that when an item is removed, it calls my
SecondaryKeyCreator again. Maybe it expects that if the
SecondaryKeyCreator is called with the same primary key and data again,
it will generate the same secondary key. However in my application
this isn't the case, since secondary keys are based on the current time
and are not at all related to the primary key or data. Is there any
way around this, or am I doing something incorrectly?

Thanks for your help.

Patrick

Quote:
We are considering adding a way to retrieve records in arbitrary
storage (log file) order. This would be for better performance when
order of retrieval doesn't matter. It would *roughly* be insertion
order, but would not be insertion order when records had been migrated
by the cleaner or updated.

Hope this helps,
Mark


Reply With Quote
  #4  
Old   
mark.hayes@oracle.com
 
Posts: n/a

Default Re: JE Reading in Insertion Order - 08-24-2006 , 09:52 AM



theschooligan (AT) gmail (DOT) com wrote:

Quote:
Thanks for your quick reply, Mark.
You're welcome.

Quote:
What I see happening is that when an item is removed, it calls my
SecondaryKeyCreator again. Maybe it expects that if the
SecondaryKeyCreator is called with the same primary key and data again,
it will generate the same secondary key. However in my application
this isn't the case, since secondary keys are based on the current time
and are not at all related to the primary key or data. Is there any
way around this, or am I doing something incorrectly?
SecondaryKeyCreators must return the secondary key value as a
deterministic function of the stored record data. So you must store
the timestamp in the record data, and pull it out with your key
creator.

This is described in the javadoc:

http://www.sleepycat.com/jedocs/java....DatabaseEntry)

"To ensure the integrity of a secondary database the key creator method
must always return the same result for a given set of input
parameters."

Mark



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.