I am new to BDB and have just started to work with Berkley DB (ver. 5.3.15) using the Linux C API.
I set up a simple Recno DB which is populated with sequential keys 1,2,3….100. DB Records are in variable length size, although, I am limiting them to a max size.
Below are the environment and DB open flags I am using:
dbenv->open(dbenv, DB_HOME_DIR, DB_SYSTEM_MEM | DB_INIT_LOCK | DB_CREATE | DB_INIT_MPOOL, 0)
dbp->open(dbp, NULL, NULL,DATABASE_NAME, DB_RECNO, DB_CREATE, 0664))
Single record get/put or using cursor to iterate over the all DB works well.
However, I would like to retrieve multiple records in a single get call.
These records can be non-sequential.
For example, retrieving 3 records with the keys 4,89,90. I prefer the bulk buffer to be as minimal as possible (avoiding stack or heap unnecessary memory allocation).
I was reading and saw few examples about using bulk retrieval. Though, I couldn’t find any example for racno bulk get on multiple specified keys.
From what I figured out till now, it seems that I should use:
Get flags: DB_SET_RECNO, DB_MULTIPLE_KEY. And the macros: DB_MULTIPLE_INIT and DB_MULTIPLE_RECNO_NEXT to iterate over a bulk buffer received.
But, I couldn’t figure it out where and how I should specify the list of Keys.
Beside, the BDB man says: "For DB_SET_RECNO to be specified, the underlying database must be of type Btree, and it must have been created with the DB_RECNUM flag."
Does the BDB open with DB_RECNO flag imply that the underlying database is Btree? If creating Btree instead of recno, wouldn’t I loss access performances?
I would appreciate if anyone could supply some guidelines or an example which will assist me to figure it out how to retrieve multiple key/data pairs from a recno DB.
Thanks in advance
We'll be happy to help you with your question.
I'm curious to know what application you intend to use Berkeley DB for. Can you post some information about what you're trying to do with BDB?
Thanks and warm regards.
I am checking the BDB to see if it can suit my needs (mostly performance wise).
It should work on a simple home router device and should hold router runtime information (static/dynamic).
This information should be accessible for process in the system which can write or read the device info.
The DB is not require to be persistent and is recreated every reboot (memory only).
I believe the DB will hold not more then 200 parameters at max.
DB access rate is around 30 records per sec (write/read)...
Currently, I think of either BDB or maybe just use a normal Linux shared memory (random access + semaphore).
Cons and pros to each...
If I choose BDB, I will use the in memory DB and recno due to access performance considerations.
Getting back to my question, I would like to be able to read a list of parameters in a single get call.
In order to use recno, I will give every parameter a unique id (1 - ip, 2 - subnet , 3 - default gateway).
e.g: ip , subnet , default gateway. (get keys 1,2,3)
Hope you have the relevant info.