Trouble with BDB

Hello

I'm looking for help getting BDB in my work programme.  It seems to work for awhile, but fails randomly and corrupts the database.

DB pointer is stored in 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 pointer to the database from 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.  There may be something that escapes me 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 enter new records into the database.  He seems to work for awhile but eventually returned negative but without true indicator as to why. (apparently, I can't paste any more code)

[C] / / try to insert the key and the data in the database. switch ((*dbp)-> put (* dbp, NU - Pastebin.com))

The complete source code is online.

https://sourceforge.NET/p/opennop/daemon/CI/feature/deduplication/~/tree/opennopd/

The data that I am inserting are 128 bytes of binary data and the key is 64 bytes of data sha512 hash.

Thank you very much.

Simply looking at snippets you have, it seems that you do not create an environment.  Without an environment you can get the version of the product that we call the data store.  The programmers reference guide has an interesting section on the explanation of what the data store does or does not.  high level summary is that you get a single editor or a single drive.   Chances are that your code violates which leads to corruption.  In addition, you have no active lock.   All this is very fast, be careful with your code.   I suspect that what you want is to store transaction data to which case you'll need an environment and you must activate the various subsystems such as locking, logging, txns etc..  This will allow multiple readers/writers at the same time.

Thank you

Mike

Tags: Database

Similar Questions

Maybe you are looking for