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