Performs an integrity check on the binary datum repository. The test expects to find in the index file, the time/date stamp and addresses of datum to be in ascending order. It further expects to find the sizes total exactly matches the data file size.
| Return Type | Function name | Arguments |
|---|---|---|
| hzEcode | hdbBinRepos::Integ | (hzLogger&,) |
Declared in file: hzDatabase.h
Defined in file : hdbBinRepos.cpp
Function Logic:
Function body:
hzEcode hdbBinRepos::Integ (hzLogger& log)
{
// Performs an integrity check on the binary datum repository. The test expects to find in the index file, the time/date stamp and addresses of datum to be in ascending order.
// It further expects to find the sizes total exactly matches the data file size.
//
// Argument: log The log-channel for the integrity report
//
// Returns: E_NOTOPEN If the reader stream is not open for reading
// E_READFAIL The reader stream is already in a fialed state
// E_CORRUPT Row metadata not as expected. Possible overwrites
// E_FORMAT Data format error
// E_OK The operation was successful
_hzfunc("hdbBinRepos::Integ") ;
ifstream is ; // Input stream for index file (separate from the in-built)
FSTAT fs ; // File status
_datum_hd* pHd ; // Datum header pointer
_datum_hd* arrHd ; // Datum header array (128 headers)
hzXDate lastDate ; // Date of last datum
uint64_t lastAddr ; // Address of last datum
uint64_t idxSize ; // Size of index file
uint64_t datSize ; // Size of data file
uint64_t totalSize ; // Total size of data file by adding size indicated in the headers
uint32_t datumId ; // Position of header in index
uint32_t nBytes ; // Bytes read in from index file
uint32_t nItems ; // Number of headers read in from index file
uint32_t nC ; // Header iterator
uint32_t totalItems = 0; // Bytes to get in the next read operation
hzEcode rc = E_OK ; // Return code
// Repos not initialized?
if (m_nInitState < 1)
return E_NOINIT ;
// Check index file
idxSize = datSize = 0;
if (!stat(*m_FileIndx, &fs))
idxSize = fs.st_size ;
if (!stat(*m_FileData, &fs))
datSize = fs.st_size ;
if (idxSize == 0&& datSize == 0)
{
log.Log("Both index and data file empty or non-existant\n") ;
return E_OK ;
}
log.Log("BinRepo %s, Size index %u data %u\n", *m_Name, idxSize, datSize) ;
// Open index file
is.open(*m_FileIndx) ;
if (is.fail())
return hzerr(E_OPENFAIL, "Could not open index file %s\n", *m_FileIndx) ;
// Process index blocks
arrHd = new _datum_hd[512];
totalSize = 0;
lastAddr = 0;
datumId = 0;
for (;;)
{
is.read((char*) arrHd, sizeof(_datum_hd) * 512);
nBytes = is.gcount() ;
if (nBytes % sizeof(_datum_hd))
{
rc = E_CORRUPT ;
log.Log("Unexpected read size %d\n", nBytes) ;
break ;
}
nItems = nBytes/sizeof(_datum_hd) ;
for (pHd = arrHd, nC = 0; nC < nItems ; nC++, pHd++)
{
totalItems++ ;
// log.Out("Datum addr %u id %u time/date %s size %u\n", pHd->m_Addr, totalItems, *pHd->m_DTStamp.Str(), pHd->m_Size) ;
totalSize += pHd->m_Size ;
// Expect this date to be greater than the last date, and this address to be 1 greater than the last address
if (pHd->m_XDate < lastDate)
log.Log("DatumId %u Address %u, date regression\n", datumId, pHd->m_Addr) ;
if (pHd->m_Addr <&eq; lastAddr)
log.Log("DatumId %u Address %u should be greater than last (%u)\n", datumId, pHd->m_Addr, lastAddr) ;
lastDate = pHd->m_XDate ;
lastAddr = pHd->m_Addr ;
datumId++ ;
}
if (nItems < 512)
break ;
}
is.close() ;
log.Log("Total size %u (expected %u)\n", totalSize, datSize) ;
log.Log("Total items %u\n", totalItems) ;
return rc ;
}