dbTalk Databases Forums  

pdb->put fail after crash

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


Discuss pdb->put fail after crash in the comp.databases.berkeley-db forum.



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

Default pdb->put fail after crash - 10-19-2006 , 02:13 AM






The application can't put records into database after crash, can
someone help me to solve the problem? The details are described as
follows:

I create db environment and db like this, just a simplified edition:

DB_ENV* dbenv;
rc = db_env_create(&dbenv, 0);
dbenv->set_errfile(dbenv, stderr);
unsigned int flags = DB_INIT_CDB | DB_INIT_MPOOL | DB_THREAD;
int mode = 0;
rc = dbenv->open(dbenv, szhome, flags, mode);

DB* pdb;
rc = db_create(&pdb, dbenv, 0);
flags = DB_THREAD;
mode = 0;
rc = pdb->open(pdb, NULL, table_file_name, table_name, DB_BTREE,
flags, mode);

Then a segment fault or reference to a null pointer occurs, it can't
open some of the dbs when restart. I remove the db env files and create
them again at the startup, the it can open all the dbs, reading data
can be done well as before.

But writing data goes to wrong. Debug into the code, I find the error
occurs at
db_meta.c, int __db_new(dbc, type, pagepp)
DB_ASSERT(last == pgno); ---- assert
fails here


Reply With Quote
  #2  
Old   
Philip Guenther
 
Posts: n/a

Default Re: pdb->put fail after crash - 10-19-2006 , 04:12 PM






On Oct 19, 1:13 am, likun.navi... (AT) gmail (DOT) com wrote:
Quote:
The application can't put records into database after crash, can
someone help me to solve the problem?
Because a single 'put' operation may require multiple pages to be
changed, the only way in Sleepycat DB to guarantee that the table
structure has consistently updated when applications or the system have
crashed is to use transactions and logging. This means you'll at least
need to pass DB_INIT_TXN and DB_INIT_LOG (and probably DB_INIT_LOCK) to
the DBENV->open() call and possibly pass DB_AUTO_COMMIT to other calls
or add explicit transaction creation and committing. You should read
the "Berkeley DB Transactional Data Store Applications" section of th
programming manual for more information.


Alternatively, if loss of some recent changes is okay, you could
occasionlly do this:
1) stop making updates
2) call DB->sync()
3) copy filename.db filename.db.tmp
4) use fsync() to force filename.db.tmp to disk
5) rename filename.db.tmp filename.db.backup
(at least on UNIX systems, this will atomicly replace the previous
backup)
6) start making updates again

On clean shutdown, you would do this:
1) close the database
2) close the database environment
3) remove filename.db.backup

On start up, if filename.db.backup exist, then:
1) remove the database environment
2) copy filename.db.backup over filename.db

....then open the database environment and the database.

Note that this gets less and less efficient as the database gets larger
or if you have to make the backup more often. At some point, using
transactions becomes faster and simpler.


Philip Guenther



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.