,I%Berkeley DB: Db::close[P

Db::close





#include <db_cxx.h>

intDb::close(u_int32_t flags);





Description



EThe Db::close method flushes any cached database information to disk,Fcloses any open cursors, frees any allocated resources, and closes anyunderlying files.HSince key/data pairs are cached in memory, failing to sync the file withgthe Db::close or Db::sync method may result in inconsistent orlost information.

CThe flags parameter must be set to 0 or the following value:

<

DB_NOSYNC
Do not flush cached information to disk.

)The DB_NOSYNC flag is a dangerous option.?It should only be set if the application is doing logging (with@transactions) so that the database is recoverable after a systemAor application crash, or if the database is always generated from.scratch after any system or application crash.

IIt is important to understand that flushing cached information to disk@only minimizes the window of opportunity for corrupted data.EWhile unlikely, it is possible for database corruption to happen if aFsystem or application crash occurs while writing data to the database.JTo ensure that database corruption never occurs, applications must either:Euse transactions and logging with automatic recovery, use logging and>application-specific recovery, or edit a copy of the database,Fand, once all applications using the database have successfully called<Db::close, atomically replace the original database with the updated copy.



RWhen multiple threads are using the Berkeley DB handle concurrently, only a single%thread may call the Db::close method.

=Once Db::close has been called, regardless of its return, the)Berkeley DB handle may not be used again.

The Db::close>method either returns errno or throws an exception that:encapsulates an errno on failure, and 0 on success.



Errors

PIf a fatal error occurs in Berkeley DB, the Db::close method may fail and eitherIreturn DB_RUNRECOVERY or throw an exception encapsulating DB_RUNRECOVERY,Gat which point all subsequent database calls will also fail in the sameFway. Methods marked as returning errno will, by default, throwHan exception that encapsulates the error information. The default error\behavior can be changed, see
DbException.

The Db::close&method may fail and throw an exceptionKfor any of the errors specified for the following Berkeley DB and C library functions:2Db::sync,DBcursor->c_close(3),dbc->c_am_destroy(3),6dbm_close,dbp->am_close(3), fflush(3), fprintf(3),free(3),JDbLog::db_unregister,>DbMpool::close,FDbMpoolFile::close,DDbMpoolFile::sync, memset(3), vfprintf(3),and vsnprintf(3).



Class

,Db



See Also

Db::close,6Db::cursor,0Db::del,.Db::fd,0Db::get,HDb::get_byteswapped,:Db::get_type,2Db::join,2Db::open,0Db::put,1Db::statand2Db::sync.
ÿÿ