Database :: openMirror - Open mirror database
The function may be called in order to write data to a mirror database. Mirrors have to be opened explicitly for each data area a database consists of. Data areas are addressed by main base and data area number (iMainBase and iDataArea). The database file referred to by sFilePath is a copy of the data area.
Mirror databases also offer a possibility for detecting hardware problems. When passing true in bCheck, the function causes a check for all entries in the data area, i.e. content written to the mirror database is compares with content written to the original database.
Usually, the database is copied to the mirror database location before opening the mirror database. In order to make sure, that all changes are written properly to the mirror database, it should be opened in the doBeforeOpen() database context handler.
When running a database in client/server mode (ODABA server), the function should be called on server side, only.
int32 MyDB_Context :: doBeforeOpen ( ) { // osi implementation
VARIABLES
STRING mPath = "/usr/local/var/project/mirror.dat";
File mFile(mPath);
int iError = false;
PROCESS
if ( !database().isServer() ) LEAVE; // run for local applications or server, only
if ( processState() == Opened ) LEAVE; // already executed
if ( mFile.isDirectory() ) ERROR;
if ( !mFile.exist() )
File(database().path()).copy(mPath);
database().openMirror(mPath,0,0,true);
RECOVER
iError = true;
FINAL
return iError;
}
Implementation details
- sFilePath - Complete file path
- iMainBase
- Main base number
When running distributed databases, main bases for a database are numbered when being defined. The default main base for the database is main base 0. Negative values are invalid.
- iDataArea
- Data area number
When running distributed databases, data areas for each main base are numbered when being defined. The default data area for each main base is data area 0. Negative values are invalid.
- bCheck - Check option