1

I'm looking into using BerkeleyDB Java Edition for a project. I've only read some of the documentation so far (not written any code) but it looks like a good match.

One of the functions I would like is an append-only log for a particular key. e.g.

«my key» => «snapshot 1»
         => «snapshot 2»
         => «snapshot 3»

The Duplicate Data items documentation looks like if I set the DB_DUP flag I can write a number of items for a key (in configurable order) and then retrieve them with a cursor.

Is this a sensible / suitable use for BerkeleyDB?

(I do have other reasons for wanting to use BerkeleyDB in the project, this isn't my primary use case. I am aware of all of the capabilities in Redis but in-memory isn't suitable)

Joe
  • 46,419
  • 33
  • 155
  • 245

1 Answers1

0

You can certainly use Berkeley DB how you describe. It's a little more challenging than a straightforward key-value store, as there are number of additional flags to cursor operations that you'll need to pay attention to. It has the benefit that it only stores one copy of the key! But, in at least some version, you couldn't store the same data items if they were sorted. Just, you know, caveats.

If you're not concerned about the storage space of the keys, you might consider using a monotonically increasing number at the end of your key. Then, you could just use it like a simple key value store, inserting your records like this:

«my key.1» => «snapshot 1»
«my key.4» => «snapshot 2»
«my key.9» => «snapshot 3»

You'll still bring them in with a cursor, like you would have for duplicate data items. Just start your search at «my key.0» and terminate it when you see «my other key.x». My bet is that you'll be able to get something working with less head scratching.

Mike Andrews
  • 3,045
  • 18
  • 28