Next:Crash Tolerance API, Previous:Availability, Up:Crash Tolerance [Contents][Index]
InCrash recovery, we have shown that for database recovery,one should select the snapshot whose permission bits are read-only andwhose last-modification timestamp is greatest. However, there may becases when a crash occurs at such a time that both snapshot filesremain readable. It may also happen, that their permissions hadbeen reset to read-only and/or modification times inadvertentlychanged before recovery. To make it possible to select the rightsnapshot in such cases, a newextended database format wasintroduced inGDBM version 1.21. This format adds to thedatabase header thenumsync field, which holds the number ofsynchronizations the database underwent before being closed orabandoned due to a crash.
A readable snapshot is a consistent copy of the database at a given point oftime. Thus, if both snapshots of a database in extended format arereadable, it will suffice to examine theirnumsync countersand select the one whosenumsync is greater. That’s whatthegdbm_latest_snapshot function does in this case.
It is worth noticing, that the two counters should differ exactly byone. If the difference is greater than that,gdbm_latest_snapshotwill return a special status code,GDBM_SNAPSHOT_SUSPICIOUS.If, during a recovery attempt, you get this status code, we recommendto proceed with the manual recovery (seeManual crash recovery).
To create a database in extended format, callgdbm_open withbothGDBM_NEWDB andGDBM_NUMSYNC flags:
dbf = gdbm_open(dbfile, 0, GDBM_NEWDB|GDBM_NUMSYNC, 0600, NULL);
Notice, that this flag must always be used together withGDBM_NEWDB (seeOpening the database). It is silently ignored when usedtogether with another opening flag.
A standardGDBM database can be converted to the extendedformat and vice versa. To convert an existing database to theextended format, use thegdbm_convert function (seeChanging database format):
rc = gdbm_convert(dbf, GDBM_NUMSYNC);
You can do the same using thegdbmtool utility(seeupgrade):
gdbmtooldbname upgrade
To convert a database from extended format back to the standardGDBM format, do:
rc = gdbm_convert(dbf, 0);
To do the same from the command line, run:
gdbmtooldbname downgrade
Next:Crash Tolerance API, Previous:Availability, Up:Crash Tolerance [Contents][Index]