Hello,
I am looking for some help getting BDB working in my program. It seems to work for a while but fails randomly and corrupts the database.
The DB pointer is saved to a structure that represents a thread.
struct processor {
pthread_t t_processor;
int state; // Marks this thread as active. 1=running, 0=stopping, -1=stopped.
struct workercounters metrics;
struct packet_head queue;
__u8 *lzbuffer; // Buffer used for QuickLZ.
DB *blocks; // DEDUP "block" database pointer. <-Saved here!
};
I initialize the database pointer by passing the DB pointer when the thread is initialized.
dbp_initialize(&thisprocessor->blocks);
The database is created or opened with DB_THREAD so I think it should be thread safe. Maybe there is something I am missing in this part.
int dbp_initialize(DB **dbp){
int ret = 0;
if ((ret = db_create(dbp, NULL, 0)) != 0) {
logger2(LOGGING_DEBUG,LOGGING_DEBUG,"[DEDUP] Error creating database pointer.\n");
exit (1);
}
if ((ret = (*dbp)->open(*dbp, NULL, DATABASE, BLOCKS, DB_BTREE, DB_CREATE | DB_THREAD, 0664)) != 0) {
(*dbp)->err(*dbp, ret, "%s", DATABASE);
logger2(LOGGING_DEBUG,LOGGING_DEBUG,"[DEDUP] Opening database failed.\n");
exit (1);
}
logger2(LOGGING_DEBUG,LOGGING_DEBUG,"[DEDUP] Opening database success.\n");
return 0;
}
Now the problem is when I try to input new records into the database. It seems to work for a while but eventually returns negative but no real indicator as to why.(apparently I cannot paste any more code)
[C] // Try inserting the key & data into the database. switch ((*dbp)->put(*dbp, NU - Pastebin.com
The full source code is online.
https://sourceforge.net/p/opennop/daemon/ci/feature/deduplication/~/tree/opennopd/
The data I am inserting is 128 bytes of binary data and the key is a 64 byte sha512 hash of that data.
Thanks so much.