Moved the super-file handle into FTK and fixed various memory leaks in the FLAIM/XFLAIM unit tests.

git-svn-id: https://svn.code.sf.net/p/flaim/code/trunk@575 0109f412-320b-0410-ab79-c3e0c5ffbbe6
This commit is contained in:
ahodgkinson
2006-06-15 17:05:55 +00:00
parent 9f7ca8edd3
commit 2fabd31c06
30 changed files with 1343 additions and 1866 deletions
+73 -17
View File
@@ -157,8 +157,10 @@ FSTATIC RCODE flmCopyDb(
{
RCODE rc = FERR_OK;
DB_COPY_INFO DbCopyInfo;
F_SuperFileHdl SrcSFileHdl;
F_SuperFileHdl DestSFileHdl;
F_SuperFileHdl * pSrcSFileHdl = NULL;
F_SuperFileHdl * pDestSFileHdl = NULL;
F_SuperFileClient * pSrcSFileClient = NULL;
F_SuperFileClient * pDestSFileClient = NULL;
FLMUINT uiFileNumber;
FLMUINT uiHighFileNumber;
FLMUINT uiHighLogFileNumber;
@@ -215,9 +217,26 @@ FSTATIC RCODE flmCopyDb(
// Set up the super file object for the source database.
// Must at least open the control file.
if( (pSrcSFileClient = f_new F_SuperFileClient) == NULL)
{
rc = RC_SET( FERR_MEM);
goto Exit;
}
if( RC_BAD( rc = pSrcSFileClient->setup(
pszSrcDbName, pszSrcDataDir, uiDbVersion)))
{
goto Exit;
}
if( (pSrcSFileHdl = f_new F_SuperFileHdl) == NULL)
{
rc = RC_SET( FERR_MEM);
goto Exit;
}
if (RC_BAD( rc = SrcSFileHdl.setup( pszSrcDbName, pszSrcDataDir,
uiDbVersion)))
if( RC_BAD( rc = pSrcSFileHdl->setup( pSrcSFileClient)))
{
goto Exit;
}
@@ -312,9 +331,26 @@ FSTATIC RCODE flmCopyDb(
}
// Set up the super file object for the destination database.
if( (pDestSFileClient = f_new F_SuperFileClient) == NULL)
{
rc = RC_SET( FERR_MEM);
goto Exit;
}
if( RC_BAD( rc = pDestSFileClient->setup(
pszDestDbName, pszDestDataDir, uiDbVersion)))
{
goto Exit;
}
if (RC_BAD( rc = DestSFileHdl.setup( pszDestDbName, pszDestDataDir,
uiDbVersion)))
if( (pDestSFileHdl = f_new F_SuperFileHdl) == NULL)
{
rc = RC_SET( FERR_MEM);
goto Exit;
}
if( RC_BAD( rc = pDestSFileHdl->setup( pDestSFileClient)))
{
goto Exit;
}
@@ -324,8 +360,8 @@ FSTATIC RCODE flmCopyDb(
uiHighFileNumber = 0;
for (;;)
{
if ((RC_BAD( rc = SrcSFileHdl.getFileSize(
uiHighFileNumber, &ui64FileSize))) || !ui64FileSize )
if( RC_BAD( rc = pSrcSFileHdl->getFileSize(
uiHighFileNumber, &ui64FileSize)) || !ui64FileSize)
{
if (rc == FERR_IO_PATH_NOT_FOUND ||
rc == FERR_IO_INVALID_PATH ||
@@ -359,7 +395,7 @@ FSTATIC RCODE flmCopyDb(
uiHighLogFileNumber = FIRST_LOG_BLOCK_FILE_NUMBER( uiDbVersion);
for (;;)
{
if ((RC_BAD( rc = SrcSFileHdl.getFileSize(
if ((RC_BAD( rc = pSrcSFileHdl->getFileSize(
uiHighLogFileNumber, &ui64FileSize))) || !ui64FileSize)
{
if (rc == FERR_IO_PATH_NOT_FOUND ||
@@ -473,8 +509,8 @@ FSTATIC RCODE flmCopyDb(
// Close all file handles in the source and destination
SrcSFileHdl.releaseFiles( TRUE);
DestSFileHdl.releaseFiles( TRUE);
pSrcSFileHdl->releaseFiles( TRUE);
pDestSFileHdl->releaseFiles( TRUE);
// Copy the database files.
@@ -483,12 +519,12 @@ FSTATIC RCODE flmCopyDb(
// Get the source file path and destination file path.
if( RC_BAD( rc = SrcSFileHdl.getFilePath(
if( RC_BAD( rc = pSrcSFileHdl->getFilePath(
uiFileNumber, DbCopyInfo.szSrcFileName)))
{
goto Exit;
}
if( RC_BAD( rc = DestSFileHdl.getFilePath(
if( RC_BAD( rc = pDestSFileHdl->getFilePath(
uiFileNumber, DbCopyInfo.szDestFileName)))
{
goto Exit;
@@ -531,13 +567,13 @@ FSTATIC RCODE flmCopyDb(
// Get the source file path and destination file path.
if (RC_BAD( rc = SrcSFileHdl.getFilePath( uiFileNumber,
if (RC_BAD( rc = pSrcSFileHdl->getFilePath( uiFileNumber,
DbCopyInfo.szSrcFileName)))
{
goto Exit;
}
if (RC_BAD( rc = DestSFileHdl.getFilePath( uiFileNumber,
if (RC_BAD( rc = pDestSFileHdl->getFilePath( uiFileNumber,
DbCopyInfo.szDestFileName)))
{
goto Exit;
@@ -685,12 +721,12 @@ FSTATIC RCODE flmCopyDb(
// Do one final copy on the control file to copy just the first 2K
if (RC_BAD( rc = SrcSFileHdl.getFilePath( 0, DbCopyInfo.szSrcFileName)))
if (RC_BAD( rc = pSrcSFileHdl->getFilePath( 0, DbCopyInfo.szSrcFileName)))
{
goto Exit;
}
if (RC_BAD( rc = DestSFileHdl.getFilePath( 0, DbCopyInfo.szDestFileName)))
if (RC_BAD( rc = pDestSFileHdl->getFilePath( 0, DbCopyInfo.szDestFileName)))
{
goto Exit;
}
@@ -810,6 +846,26 @@ Exit:
{
f_semDestroy( &hWaitSem);
}
if( pSrcSFileHdl)
{
pSrcSFileHdl->Release();
}
if( pSrcSFileClient)
{
pSrcSFileClient->Release();
}
if( pDestSFileHdl)
{
pDestSFileHdl->Release();
}
if( pDestSFileClient)
{
pDestSFileClient->Release();
}
return( rc);
}
+4 -2
View File
@@ -187,7 +187,8 @@ FLMEXP RCODE FLMAPI FlmDbRemove(
uiFileNumber = 1;
for (;;)
{
bldSuperFileExtension( uiVersionNum, uiFileNumber, pszDataExt);
F_SuperFileClient::bldSuperFileExtension(
uiVersionNum, uiFileNumber, pszDataExt);
if (RC_BAD( rc = gv_FlmSysData.pFileSystem->deleteFile( pszDataName)))
{
@@ -214,7 +215,8 @@ FLMEXP RCODE FLMAPI FlmDbRemove(
uiFileNumber = FIRST_LOG_BLOCK_FILE_NUMBER( uiVersionNum);
for (;;)
{
bldSuperFileExtension( uiVersionNum, uiFileNumber, pszExt);
F_SuperFileClient::bldSuperFileExtension(
uiVersionNum, uiFileNumber, pszExt);
if (RC_BAD( rc = gv_FlmSysData.pFileSystem->deleteFile( pszTmpName)))
{
+4 -4
View File
@@ -379,9 +379,9 @@ FLMEXP RCODE FLMAPI FlmDbRename(
uiFileNumber = 1;
for (;;)
{
bldSuperFileExtension( FileHdr.uiVersionNum,
F_SuperFileClient::bldSuperFileExtension( FileHdr.uiVersionNum,
uiFileNumber, pszDataExtOld);
bldSuperFileExtension( FileHdr.uiVersionNum,
F_SuperFileClient::bldSuperFileExtension( FileHdr.uiVersionNum,
uiFileNumber, pszDataExtNew);
if (RC_BAD( rc = flmRenameFile( pszOldDataName, pszNewDataName,
@@ -409,9 +409,9 @@ FLMEXP RCODE FLMAPI FlmDbRename(
FIRST_LOG_BLOCK_FILE_NUMBER (FileHdr.uiVersionNum);
for (;;)
{
bldSuperFileExtension( FileHdr.uiVersionNum,
F_SuperFileClient::bldSuperFileExtension( FileHdr.uiVersionNum,
uiFileNumber, pszExtOld);
bldSuperFileExtension( FileHdr.uiVersionNum,
F_SuperFileClient::bldSuperFileExtension( FileHdr.uiVersionNum,
uiFileNumber, pszExtNew);
if (RC_BAD( rc = flmRenameFile( pszOldName, pszNewName,
+41 -1
View File
@@ -72,7 +72,6 @@ class F_CCS;
#include "fcs.h"
#include "fsv.h"
#include "furl.h"
#include "fsuperfl.h"
#include "f_nici.h"
#include "fpackon.h"
@@ -2582,6 +2581,47 @@ private:
FLMBOOL m_bOpen;
};
/****************************************************************************
Desc:
*****************************************************************************/
class FLMEXP F_SuperFileClient : public IF_SuperFileClient
{
public:
F_SuperFileClient();
virtual ~F_SuperFileClient();
RCODE setup(
const char * pszCFileName,
const char * pszDataDir,
FLMUINT uiVersionNum);
FLMUINT FLMAPI getFileNumber(
FLMUINT uiBlockAddr);
FLMUINT FLMAPI getFileOffset(
FLMUINT uiBlockAddr);
RCODE FLMAPI getFilePath(
FLMUINT uiFileNumber,
char * pszPath);
static void bldSuperFileExtension(
FLMUINT uiVersionNum,
FLMUINT uiFileNum,
char * pszFileExtension);
private:
char * m_pszCFileName;
char * m_pszDataFileBaseName;
FLMUINT m_uiVersionNum;
FLMUINT m_uiExtOffset;
FLMUINT m_uiDataExtOffset;
FLMUINT m_uiDbVersion;
};
#include "fpackoff.h"
#endif
+46 -27
View File
@@ -1568,31 +1568,32 @@ FSTATIC RCODE flmRestoreFile(
FLMBYTE * pucKeyToUse,
FLMUINT * puiKeyLen)
{
RCODE rc = FERR_OK;
FLMUINT uiBytesWritten;
FLMUINT uiLogicalEOF;
FLMUINT uiBlkAddr;
FLMUINT uiBlockCount = 0;
FLMUINT uiActualBlkSize;
FLMUINT uiBlockSize;
FLMUINT uiDbVersion;
FLMUINT uiMaxFileSize;
FLMUINT uiBackupMaxFileSize;
FLMUINT uiPriorBlkFile = 0;
FLMUINT uiSectorSize;
FLMBYTE * pLogHdr;
FLMBYTE ucIncSerialNum[ F_SERIAL_NUM_SIZE];
FLMBYTE ucNextIncSerialNum[ F_SERIAL_NUM_SIZE];
FLMUINT uiIncSeqNum;
FLMBYTE * pucBlkBuf = NULL;
FLMBYTE ucLowChecksumByte;
FLMUINT uiBlkBufSize;
FLMUINT uiPriorBlkAddr = 0;
BYTE_PROGRESS byteProgress;
FBackupType eBackupType;
F_BackerStream * pBackerStream = NULL;
F_CCS * pTmpCCS = NULL;
F_SuperFileHdl * pSFile = NULL;
RCODE rc = FERR_OK;
FLMUINT uiBytesWritten;
FLMUINT uiLogicalEOF;
FLMUINT uiBlkAddr;
FLMUINT uiBlockCount = 0;
FLMUINT uiActualBlkSize;
FLMUINT uiBlockSize;
FLMUINT uiDbVersion;
FLMUINT uiMaxFileSize;
FLMUINT uiBackupMaxFileSize;
FLMUINT uiPriorBlkFile = 0;
FLMUINT uiSectorSize;
FLMBYTE * pLogHdr;
FLMBYTE ucIncSerialNum[ F_SERIAL_NUM_SIZE];
FLMBYTE ucNextIncSerialNum[ F_SERIAL_NUM_SIZE];
FLMUINT uiIncSeqNum;
FLMBYTE * pucBlkBuf = NULL;
FLMBYTE ucLowChecksumByte;
FLMUINT uiBlkBufSize;
FLMUINT uiPriorBlkAddr = 0;
BYTE_PROGRESS byteProgress;
FBackupType eBackupType;
F_BackerStream * pBackerStream = NULL;
F_CCS * pTmpCCS = NULL;
F_SuperFileHdl * pSFile = NULL;
F_SuperFileClient * pSFileClient = NULL;
#ifndef FLM_USE_NICI
F_UNREFERENCED_PARM( pszPassword);
@@ -1787,12 +1788,25 @@ FSTATIC RCODE flmRestoreFile(
rc = RC_SET( FERR_MEM);
goto Exit;
}
if( RC_BAD( rc = pSFile->setup( pszDbPath, pszDataDir, uiDbVersion)))
if( (pSFileClient = f_new F_SuperFileClient) == NULL)
{
rc = RC_SET( FERR_MEM);
goto Exit;
}
if( RC_BAD( rc = pSFileClient->setup( pszDbPath, pszDataDir, uiDbVersion)))
{
goto Exit;
}
if( RC_BAD( rc = pSFile->setup( pSFileClient)))
{
goto Exit;
}
pSFile->setBlockSize( uiBlockSize);
// Don't want to do extra file extensions or flush when file
// is extended. Setting the extend size to ~0 has the effect
// of not updating the directory entry (a time-consuming operation)
@@ -2175,6 +2189,11 @@ Exit:
{
pSFile->Release();
}
if( pSFileClient)
{
pSFileClient->Release();
}
return( rc);
}
+35 -17
View File
@@ -99,22 +99,23 @@ Exit:
Desc: This routine creates a FLAIM file.
****************************************************************************/
RCODE flmCreateNewFile(
const char * pszFilePath,
const char * pszDataDir,
const char * pszRflDir,
const char * pszDictFileName,
const char * pszDictBuf,
CREATE_OPTS * pCreateOpts,
FLMUINT uiTransID,
FDB * * ppDb,
REBUILD_STATE * pRebuildState)
const char * pszFilePath,
const char * pszDataDir,
const char * pszRflDir,
const char * pszDictFileName,
const char * pszDictBuf,
CREATE_OPTS * pCreateOpts,
FLMUINT uiTransID,
FDB * * ppDb,
REBUILD_STATE * pRebuildState)
{
RCODE rc = FERR_OK;
FDB * pDb = NULL;
FFILE * pFile;
FLMBOOL bFileCreated = FALSE;
FLMBOOL bNewFile = FALSE;
FLMBOOL bMutexLocked = FALSE;
RCODE rc = FERR_OK;
FDB * pDb = NULL;
FFILE * pFile;
FLMBOOL bFileCreated = FALSE;
FLMBOOL bNewFile = FALSE;
FLMBOOL bMutexLocked = FALSE;
F_SuperFileClient * pSFileClient = NULL;
if( ppDb)
{
@@ -257,6 +258,7 @@ RCODE flmCreateNewFile(
// Allocate the super file object
flmAssert( !pDb->pSFileHdl);
flmAssert( pFile->FileHdr.uiVersionNum);
if( (pDb->pSFileHdl = f_new F_SuperFileHdl) == NULL)
{
@@ -264,13 +266,24 @@ RCODE flmCreateNewFile(
goto Exit;
}
flmAssert( pFile->FileHdr.uiVersionNum);
if( (pSFileClient = f_new F_SuperFileClient) == NULL)
{
rc = RC_SET( FERR_MEM);
goto Exit;
}
if( RC_BAD( rc = pDb->pSFileHdl->setup(
if( RC_BAD( rc = pSFileClient->setup(
pFile->pszDbPath, pFile->pszDataDir, pFile->FileHdr.uiVersionNum)))
{
goto Exit;
}
if( RC_BAD( rc = pDb->pSFileHdl->setup( pSFileClient)))
{
goto Exit;
}
pDb->pSFileHdl->setBlockSize( pFile->FileHdr.uiBlockSize);
// Create the .db file.
@@ -336,6 +349,11 @@ Exit:
{
*ppDb = pDb;
}
if( pSFileClient)
{
pSFileClient->Release();
}
return( rc);
}
+103 -47
View File
@@ -433,23 +433,24 @@ Desc: This routine will open a file, returning a pointer to the FDB and
FFILE structures.
****************************************************************************/
RCODE flmOpenFile(
FFILE * pFile,
const char * pszDbPath,
const char * pszDataDir,
const char * pszRflDir,
FLMUINT uiOpenFlags,
FLMBOOL bInternalOpen,
F_Restore * pRestoreObj,
IF_FileHdl * pLockFileHdl,
const char * pszPassword,
FDB ** ppDb)
FFILE * pFile,
const char * pszDbPath,
const char * pszDataDir,
const char * pszRflDir,
FLMUINT uiOpenFlags,
FLMBOOL bInternalOpen,
F_Restore * pRestoreObj,
IF_FileHdl * pLockFileHdl,
const char * pszPassword,
FDB ** ppDb)
{
RCODE rc;
FLMBOOL bNewFile = FALSE;
FLMBOOL bMutexLocked = FALSE;
FLMBOOL bAllocatedFdb = FALSE;
FDB * pDb;
FLMBOOL bFirstOpen = FALSE;
RCODE rc = FERR_OK;
FLMBOOL bNewFile = FALSE;
FLMBOOL bMutexLocked = FALSE;
FLMBOOL bAllocatedFdb = FALSE;
FDB * pDb;
FLMBOOL bFirstOpen = FALSE;
F_SuperFileClient * pSFileClient = NULL;
// Allocate and initialize an FDB structure
@@ -610,6 +611,8 @@ RCODE flmOpenFile(
// Allocate the super file object
flmAssert( !pDb->pSFileHdl);
flmAssert( pFile->FileHdr.uiVersionNum);
flmAssert( pFile->FileHdr.uiBlockSize);
if( (pDb->pSFileHdl = f_new F_SuperFileHdl) == NULL)
{
@@ -617,14 +620,24 @@ RCODE flmOpenFile(
goto Exit;
}
flmAssert( pFile->FileHdr.uiVersionNum);
flmAssert( pFile->FileHdr.uiBlockSize);
if( (pSFileClient = f_new F_SuperFileClient) == NULL)
{
rc = RC_SET( FERR_MEM);
goto Exit;
}
if( RC_BAD( rc = pDb->pSFileHdl->setup(
if( RC_BAD( rc = pSFileClient->setup(
pFile->pszDbPath, pFile->pszDataDir, pFile->FileHdr.uiVersionNum)))
{
goto Exit;
}
if( RC_BAD( rc = pDb->pSFileHdl->setup( pSFileClient)))
{
goto Exit;
}
pDb->pSFileHdl->setBlockSize( pFile->FileHdr.uiBlockSize);
}
if (bNewFile && !(uiOpenFlags & FO_DONT_REDO_LOG))
@@ -672,6 +685,11 @@ Exit:
{
pLockFileHdl->Release();
}
if( pSFileClient)
{
pSFileClient->Release();
}
rc = flmCompleteOpenOrCreate( ppDb, rc, bNewFile, bAllocatedFdb);
return( rc);
@@ -910,16 +928,17 @@ Desc: This routine checks to see if it is OK for another FDB to use a file.
assumes that the global mutex is NOT locked.
****************************************************************************/
FSTATIC RCODE flmPhysFileOpen(
FDB * pDb,
const char * pszFilePath, // File name
const char * pszRflDir, // RFL directory
FLMUINT uiOpenFlags, // Flags for doing physical open
FLMBOOL bNewFile, // Is this a new file structure?
F_Restore * pRestoreObj) // Restore object
FDB * pDb,
const char * pszFilePath, // File name
const char * pszRflDir, // RFL directory
FLMUINT uiOpenFlags, // Flags for doing physical open
FLMBOOL bNewFile, // Is this a new file structure?
F_Restore * pRestoreObj) // Restore object
{
RCODE rc = FERR_OK;
FFILE * pFile = pDb->pFile;
FLMBOOL bAllowLimitedMode = FALSE;
RCODE rc = FERR_OK;
FFILE * pFile = pDb->pFile;
FLMBOOL bAllowLimitedMode = FALSE;
F_SuperFileClient * pSFileClient = NULL;
// If this is the first open of the database, read the header block
@@ -974,6 +993,8 @@ FSTATIC RCODE flmPhysFileOpen(
// Allocate the super file object
flmAssert( !pDb->pSFileHdl);
flmAssert( pFile->FileHdr.uiVersionNum);
flmAssert( pFile->FileHdr.uiBlockSize);
if( (pDb->pSFileHdl = f_new F_SuperFileHdl) == NULL)
{
@@ -981,14 +1002,24 @@ FSTATIC RCODE flmPhysFileOpen(
goto Exit;
}
flmAssert( pFile->FileHdr.uiVersionNum);
flmAssert( pFile->FileHdr.uiBlockSize);
if( (pSFileClient = f_new F_SuperFileClient) == NULL)
{
rc = RC_SET( FERR_MEM);
goto Exit;
}
if( RC_BAD( rc = pDb->pSFileHdl->setup(
if( RC_BAD( rc = pSFileClient->setup(
pFile->pszDbPath, pFile->pszDataDir, pFile->FileHdr.uiVersionNum)))
{
goto Exit;
}
if( RC_BAD( rc = pDb->pSFileHdl->setup( pSFileClient)))
{
goto Exit;
}
pDb->pSFileHdl->setBlockSize( pFile->FileHdr.uiBlockSize);
// We must have exclusive access. Create a lock file for that
// purpose, if there is not already a lock file.
@@ -1015,6 +1046,11 @@ FSTATIC RCODE flmPhysFileOpen(
Exit:
if( pSFileClient)
{
pSFileClient->Release();
}
return( rc);
}
@@ -1461,10 +1497,12 @@ FSTATIC void flmFreeCPInfo(
{
pCPInfo->pSFileHdl->Release();
}
if (pCPInfo->bStatsInitialized)
{
FlmFreeStats( &pCPInfo->Stats);
}
f_free( ppCPInfoRV);
}
}
@@ -1475,41 +1513,53 @@ Desc: This routine begins a thread that will do checkpoints for the
own handle to the database.
*****************************************************************************/
RCODE flmStartCPThread(
FFILE * pFile)
FFILE * pFile)
{
RCODE rc = FERR_OK;
CP_INFO * pCPInfo = NULL;
char szThreadName[ F_PATH_MAX_SIZE];
char szBaseName[ F_FILENAME_SIZE];
RCODE rc = FERR_OK;
CP_INFO * pCPInfo = NULL;
char szThreadName[ F_PATH_MAX_SIZE];
char szBaseName[ F_FILENAME_SIZE];
F_SuperFileClient * pSFileClient = NULL;
// Allocate a CP_INFO structure that will be passed into the
// thread when it is created.
if (RC_BAD( rc = f_calloc( (FLMUINT)(sizeof( CP_INFO)), &pCPInfo)))
if( RC_BAD( rc = f_calloc( (FLMUINT)(sizeof( CP_INFO)), &pCPInfo)))
{
goto Exit;
}
pCPInfo->pFile = pFile;
// Allocate a super file handle.
// Set up the super file
if ((pCPInfo->pSFileHdl = f_new F_SuperFileHdl) == NULL)
flmAssert( pFile->FileHdr.uiVersionNum);
if( (pCPInfo->pSFileHdl = f_new F_SuperFileHdl) == NULL)
{
rc = RC_SET( FERR_MEM);
goto Exit;
}
// Set up the super file
flmAssert( pFile->FileHdr.uiVersionNum);
if( (pSFileClient = f_new F_SuperFileClient) == NULL)
{
rc = RC_SET( FERR_MEM);
goto Exit;
}
if (RC_BAD( rc = pCPInfo->pSFileHdl->setup(
if( RC_BAD( rc = pSFileClient->setup(
pFile->pszDbPath, pFile->pszDataDir, pFile->FileHdr.uiVersionNum)))
{
goto Exit;
}
if (RC_BAD( rc = flmStatInit( &pCPInfo->Stats, FALSE)))
if( RC_BAD( rc = pCPInfo->pSFileHdl->setup( pSFileClient)))
{
goto Exit;
}
pCPInfo->pSFileHdl->setBlockSize( pFile->FileHdr.uiBlockSize);
if( RC_BAD( rc = flmStatInit( &pCPInfo->Stats, FALSE)))
{
goto Exit;
}
@@ -1517,7 +1567,7 @@ RCODE flmStartCPThread(
// Generate the thread name
if (RC_BAD( rc = gv_FlmSysData.pFileSystem->pathReduce( pFile->pszDbPath,
if( RC_BAD( rc = gv_FlmSysData.pFileSystem->pathReduce( pFile->pszDbPath,
szThreadName, szBaseName)))
{
goto Exit;
@@ -1528,7 +1578,7 @@ RCODE flmStartCPThread(
// Start the checkpoint thread.
if (RC_BAD( rc = f_threadCreate( &pFile->pCPThrd,
if( RC_BAD( rc = f_threadCreate( &pFile->pCPThrd,
flmCPThread, szThreadName,
gv_uiCPThrdGrp, 0, pCPInfo, NULL, 32000)))
{
@@ -1538,7 +1588,13 @@ RCODE flmStartCPThread(
pFile->pCPInfo = pCPInfo;
Exit:
if (RC_BAD( rc))
if( pSFileClient)
{
pSFileClient->Release();
}
if( RC_BAD( rc))
{
flmFreeCPInfo( &pCPInfo);
}
+75 -36
View File
@@ -2142,6 +2142,7 @@ FLMEXP RCODE FLMAPI FlmDbRebuild(
FDB * pDb = NULL;
FFILE * pFile;
F_SuperFileHdl * pSFileHdl = NULL;
F_SuperFileClient * pSFileClient = NULL;
FLMBOOL bFileLocked = FALSE;
FLMBOOL bWriteLocked = FALSE;
REBUILD_STATE * pRebuildState = NULL;
@@ -2448,25 +2449,37 @@ FLMEXP RCODE FLMAPI FlmDbRebuild(
// If no block size has been specified or determined yet, use what we
// read from the file header.
if (!pCreateOpts->uiBlockSize)
if( !pCreateOpts->uiBlockSize)
{
pCreateOpts->uiBlockSize = pHdrInfo->FileHdr.uiBlockSize;
}
// Open the corrupted database
if ((pSFileHdl = f_new F_SuperFileHdl) == NULL)
if( (pSFileHdl = f_new F_SuperFileHdl) == NULL)
{
rc = RC_SET( FERR_MEM);
goto Exit;
}
if( RC_BAD( rc = pSFileHdl->setup( pszSourceDbPath, pszSourceDataDir,
pHdrInfo->FileHdr.uiVersionNum)))
if( (pSFileClient = f_new F_SuperFileClient) == NULL)
{
rc = RC_SET( FERR_MEM);
goto Exit;
}
if( RC_BAD( rc = pSFileClient->setup(
pszSourceDbPath, pszSourceDataDir, pHdrInfo->FileHdr.uiVersionNum)))
{
goto Exit;
}
if( RC_BAD( rc = pSFileHdl->setup( pSFileClient)))
{
goto Exit;
}
pSFileHdl->setBlockSize( pCreateOpts->uiBlockSize);
pRebuildState->pSFileHdl = pSFileHdl;
// Calculate the file size.
@@ -2532,7 +2545,9 @@ Exit:
f_mutexLock( gv_FlmSysData.hShareMutex);
bMutexLocked = TRUE;
}
pTmpFile1 = gv_FlmSysData.pLrnuFile;
while (pTmpFile1)
{
if (pTmpFile1 == pTmpFile)
@@ -2551,24 +2566,26 @@ Exit:
f_mutexLock( gv_FlmSysData.hShareMutex);
bMutexLocked = TRUE;
}
if (!(--pFile->uiUseCount))
{
flmLinkFileToNUList( pFile);
}
}
if (bMutexLocked)
if( bMutexLocked)
{
f_mutexUnlock( gv_FlmSysData.hShareMutex);
bMutexLocked = FALSE;
}
if (bWriteLocked)
if( bWriteLocked)
{
pWriteLockObj->unlock();
bWriteLocked = FALSE;
}
if (bFileLocked)
if( bFileLocked)
{
pFileLockObj->unlock();
bFileLocked = FALSE;
@@ -2584,19 +2601,19 @@ Exit:
pCFileHdl->Release();
}
if (pWriteLockObj)
if( pWriteLockObj)
{
pWriteLockObj->Release();
pWriteLockObj = NULL;
}
if (pFileLockObj)
if( pFileLockObj)
{
pFileLockObj->Release();
pFileLockObj = NULL;
}
if (pLockFileHdl)
if( pLockFileHdl)
{
pLockFileHdl->Release();
pLockFileHdl = NULL;
@@ -2607,7 +2624,7 @@ Exit:
f_free( &pDefaultCreateOpts);
}
if (pRebuildState)
if( pRebuildState)
{
if( puiTotRecsRV)
{
@@ -2619,14 +2636,13 @@ Exit:
*puiRecsRecovRV = pRebuildState->CallbackData.uiRecsRecov;
}
if ((pRebuildState->pStateInfo) &&
(pRebuildState->pStateInfo->pRecord))
if( pRebuildState->pStateInfo && pRebuildState->pStateInfo->pRecord)
{
pRebuildState->pStateInfo->pRecord->Release();
}
if (pRebuildState->pRecord)
if( pRebuildState->pRecord)
{
pRebuildState->pRecord->Release();
pRebuildState->pRecord = NULL;
@@ -2671,6 +2687,11 @@ Exit:
{
f_semDestroy( &hWaitSem);
}
if( pSFileClient)
{
pSFileClient->Release();
}
return( rc);
}
@@ -2681,26 +2702,27 @@ Desc: This routine reads through a database and makes a best guess as to
the true block size of the database.
*****************************************************************************/
FSTATIC RCODE bldDetermineBlkSize(
const char * pszSourceDbPath,
const char * pszSourceDataDir,
FLMUINT uiDbVersion,
FLMUINT uiMaxFileSize,
FLMUINT * puiBlkSizeRV,
STATUS_HOOK fnStatusFunc,
REBUILD_INFO * pCallbackData,
void * AppArg)
const char * pszSourceDbPath,
const char * pszSourceDataDir,
FLMUINT uiDbVersion,
FLMUINT uiMaxFileSize,
FLMUINT * puiBlkSizeRV,
STATUS_HOOK fnStatusFunc,
REBUILD_INFO * pCallbackData,
void * AppArg)
{
RCODE rc = FERR_OK;
FLMBYTE ucBlkHeader [BH_OVHD];
FLMUINT uiBytesRead;
FLMUINT uiBlkAddress;
FLMUINT uiFileNumber = 0;
FLMUINT uiOffset = 0;
FLMUINT uiCount4K = 0;
FLMUINT uiCount8K = 0;
FLMUINT64 ui64BytesDone = 0;
IF_FileHdl * pFileHdl = NULL;
F_SuperFileHdl * pSFileHdl = NULL;
RCODE rc = FERR_OK;
FLMBYTE ucBlkHeader [BH_OVHD];
FLMUINT uiBytesRead;
FLMUINT uiBlkAddress;
FLMUINT uiFileNumber = 0;
FLMUINT uiOffset = 0;
FLMUINT uiCount4K = 0;
FLMUINT uiCount8K = 0;
FLMUINT64 ui64BytesDone = 0;
IF_FileHdl * pFileHdl = NULL;
F_SuperFileHdl * pSFileHdl = NULL;
F_SuperFileClient * pSFileClient = NULL;
// Open the corrupted database
@@ -2709,9 +2731,20 @@ FSTATIC RCODE bldDetermineBlkSize(
rc = RC_SET( FERR_MEM);
goto Exit;
}
if( (pSFileClient = f_new F_SuperFileClient) == NULL)
{
rc = RC_SET( FERR_MEM);
goto Exit;
}
if( RC_BAD( rc = pSFileClient->setup(
pszSourceDbPath, pszSourceDataDir, uiDbVersion)))
{
goto Exit;
}
if( RC_BAD( rc = pSFileHdl->setup( pszSourceDbPath, pszSourceDataDir,
uiDbVersion)))
if( RC_BAD( rc = pSFileHdl->setup( pSFileClient)))
{
goto Exit;
}
@@ -2720,6 +2753,7 @@ FSTATIC RCODE bldDetermineBlkSize(
pCallbackData->iDoingFlag = REBUILD_GET_BLK_SIZ;
pCallbackData->bStartFlag = TRUE;
for (;;)
{
if (uiOffset >= uiMaxFileSize || !uiFileNumber)
@@ -2830,6 +2864,11 @@ Exit:
{
pSFileHdl->Release();
}
if( pSFileClient)
{
pSFileClient->Release();
}
return( rc);
}
-964
View File
@@ -1,964 +0,0 @@
//-------------------------------------------------------------------------
// Desc: Super-file class implementation.
// Tabs: 3
//
// Copyright (c) 1998-2003,2005-2006 Novell, Inc. All Rights Reserved.
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of version 2 of the GNU General Public
// License as published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, contact Novell, Inc.
//
// To contact Novell about this file by physical or electronic mail,
// you may find current contact information at www.novell.com
//
// $Id: fsuperfl.cpp 12329 2006-01-20 17:49:30 -0700 (Fri, 20 Jan 2006) ahodgkinson $
//-------------------------------------------------------------------------
#include "flaimsys.h"
/****************************************************************************
Desc:
****************************************************************************/
F_SuperFileHdl::F_SuperFileHdl( void)
{
m_pszDbFileName = NULL;
m_pszDataFileNameBase = NULL;
f_memset( &m_CheckedOutFileHdls[ 0], 0, sizeof( m_CheckedOutFileHdls));
m_pCheckedOutFileHdls = &m_CheckedOutFileHdls [0];
m_uiCkoArraySize = MAX_CHECKED_OUT_FILE_HDLS + 1;
m_uiExtendSize = DEFAULT_FILE_EXTEND_SIZE;
m_uiMaxAutoExtendSize = gv_FlmSysData.uiMaxFileSize;
m_uiDbVersion = 0;
m_uiLowestDirtySlot = 1;
m_uiHighestDirtySlot = 0;
m_uiHighestUsedSlot = 0;
m_uiHighestFileNumber = 0;
m_bMinimizeFlushes = FALSE;
m_bSetupCalled = FALSE;
}
/****************************************************************************
Desc:
****************************************************************************/
F_SuperFileHdl::~F_SuperFileHdl()
{
if( m_bSetupCalled)
{
(void)releaseFiles( TRUE);
}
if (m_pszDbFileName)
{
f_free( &m_pszDbFileName);
}
}
/****************************************************************************
Desc: Configures the super file object
****************************************************************************/
RCODE F_SuperFileHdl::setup(
const char * pszDbFileName,
const char * pszDataDir,
FLMUINT uiDbVersion)
{
RCODE rc = NE_FLM_OK;
FLMUINT uiNameLen;
FLMUINT uiDataNameLen;
char szDir [F_PATH_MAX_SIZE];
char szBaseName [F_FILENAME_SIZE];
flmAssert( !m_bSetupCalled);
if( !pszDbFileName && *pszDbFileName == 0)
{
rc = RC_SET( NE_FLM_IO_INVALID_FILENAME);
goto Exit;
}
uiNameLen = f_strlen( pszDbFileName);
if (pszDataDir && *pszDataDir)
{
if (RC_BAD( rc = gv_FlmSysData.pFileSystem->pathReduce(
pszDbFileName, szDir, szBaseName)))
{
goto Exit;
}
f_strcpy( szDir, pszDataDir);
if (RC_BAD( rc = gv_FlmSysData.pFileSystem->pathAppend(
szDir, szBaseName)))
{
goto Exit;
}
uiDataNameLen = f_strlen( szDir);
if (RC_BAD( rc = f_alloc( (uiNameLen + 1) + (uiDataNameLen + 1),
&m_pszDbFileName)))
{
goto Exit;
}
f_memcpy( m_pszDbFileName, pszDbFileName, uiNameLen + 1);
m_pszDataFileNameBase = m_pszDbFileName + uiNameLen + 1;
flmGetDbBasePath( m_pszDataFileNameBase, szDir, &m_uiDataExtOffset);
m_uiExtOffset = uiNameLen - (uiDataNameLen - m_uiDataExtOffset);
}
else
{
if (RC_BAD( rc = f_alloc( (uiNameLen + 1) * 2, &m_pszDbFileName)))
{
goto Exit;
}
f_memcpy( m_pszDbFileName, pszDbFileName, uiNameLen + 1);
m_pszDataFileNameBase = m_pszDbFileName + uiNameLen + 1;
flmGetDbBasePath( m_pszDataFileNameBase,
m_pszDbFileName, &m_uiDataExtOffset);
m_uiExtOffset = m_uiDataExtOffset;
}
m_uiDbVersion = uiDbVersion;
m_bSetupCalled = TRUE;
Exit:
return( rc);
}
/****************************************************************************
Desc: Creates a file
****************************************************************************/
RCODE F_SuperFileHdl::createFile(
FLMUINT uiFileNumber)
{
RCODE rc = NE_FLM_OK;
char szFilePath[ F_PATH_MAX_SIZE];
IF_FileHdl * pFileHdl = NULL;
// Sanity checks
flmAssert( m_bSetupCalled && m_uiDbVersion);
flmAssert( uiFileNumber <= MAX_LOG_BLOCK_FILE_NUMBER( m_uiDbVersion));
// See if we already have an open file handle (or if we can open the file).
// If so, truncate the file and use it.
if( RC_OK( rc = getFileHdl( uiFileNumber, TRUE, &pFileHdl)))
{
rc = pFileHdl->truncate( 0);
pFileHdl = NULL;
goto Exit;
}
else if( rc != NE_FLM_IO_PATH_NOT_FOUND)
{
goto Exit;
}
// Build the file path
if( RC_BAD( rc = getFilePath( uiFileNumber, szFilePath)))
{
goto Exit;
}
if( RC_BAD( rc = gv_FlmSysData.pFileSystem->createFile(
szFilePath, FLM_IO_RDWR | FLM_IO_EXCL | FLM_IO_DIRECT | FLM_IO_SH_DENYNONE,
&pFileHdl)))
{
goto Exit;
}
Exit:
if( pFileHdl)
{
pFileHdl->Release();
}
return( rc);
}
/****************************************************************************
Desc: Reads a database block into a buffer
****************************************************************************/
RCODE F_SuperFileHdl::readBlock(
FLMUINT uiBlkAddress,
FLMUINT uiBytesToRead,
void * pvBuffer,
FLMUINT * puiBytesRead)
{
IF_FileHdl * pFileHdl = NULL;
RCODE rc = NE_FLM_OK;
flmAssert( m_bSetupCalled);
if( RC_BAD( rc = getFileHdl(
FSGetFileNumber( uiBlkAddress), FALSE, &pFileHdl)))
{
goto Exit;
}
if( RC_BAD( rc = pFileHdl->sectorRead(
FSGetFileOffset( uiBlkAddress), uiBytesToRead,
pvBuffer, puiBytesRead)))
{
if (rc != NE_FLM_IO_END_OF_FILE && rc != NE_FLM_MEM)
{
releaseFile( FSGetFileNumber( uiBlkAddress), TRUE);
}
goto Exit;
}
Exit:
return( rc);
}
/****************************************************************************
Desc: Writes a block to the database
****************************************************************************/
RCODE F_SuperFileHdl::writeBlock(
FLMUINT uiBlkAddress,
FLMUINT uiBytesToWrite,
const void * pvBuffer,
IF_IOBuffer * pIOBuffer,
FLMUINT * puiBytesWritten)
{
IF_FileHdl * pFileHdl = NULL;
RCODE rc = NE_FLM_OK;
flmAssert( m_bSetupCalled);
Get_Handle:
if( RC_BAD( rc = getFileHdl(
FSGetFileNumber( uiBlkAddress), TRUE, &pFileHdl)))
{
if (rc == NE_FLM_IO_PATH_NOT_FOUND)
{
if (RC_BAD( rc = createFile( FSGetFileNumber( uiBlkAddress))))
{
goto Exit;
}
else
{
goto Get_Handle;
}
}
goto Exit;
}
pFileHdl->setExtendSize( m_uiExtendSize);
pFileHdl->setMaxAutoExtendSize( m_uiMaxAutoExtendSize);
if( RC_BAD( rc = pFileHdl->sectorWrite(
FSGetFileOffset( uiBlkAddress), uiBytesToWrite,
pvBuffer, pIOBuffer, puiBytesWritten)))
{
if (rc != NE_FLM_IO_DISK_FULL && rc != NE_FLM_MEM)
{
releaseFile( FSGetFileNumber( uiBlkAddress), TRUE);
}
goto Exit;
}
Exit:
return( rc);
}
/****************************************************************************
Desc: Reads data from the database header
****************************************************************************/
RCODE F_SuperFileHdl::readHeader(
FLMUINT uiOffset,
FLMUINT uiBytesToRead,
void * pvBuffer,
FLMUINT * puiBytesRead)
{
RCODE rc = NE_FLM_OK;
IF_FileHdl * pFileHdl;
if( RC_BAD( rc = getFileHdl( 0, TRUE, &pFileHdl)))
{
goto Exit;
}
if( RC_BAD( rc = pFileHdl->read( uiOffset,
uiBytesToRead, pvBuffer, puiBytesRead)))
{
if (rc != NE_FLM_IO_END_OF_FILE && rc != NE_FLM_MEM)
{
releaseFile( (FLMUINT)0, TRUE);
}
goto Exit;
}
Exit:
return( rc);
}
/****************************************************************************
Desc: Writes data to the database header
****************************************************************************/
RCODE F_SuperFileHdl::writeHeader(
FLMUINT uiOffset,
FLMUINT uiBytesToWrite,
const void * pvBuffer,
FLMUINT * puiBytesWritten)
{
RCODE rc = NE_FLM_OK;
IF_FileHdl * pFileHdl;
if( RC_BAD( rc = getFileHdl( 0, TRUE, &pFileHdl)))
{
goto Exit;
}
if( RC_BAD( rc = pFileHdl->write( uiOffset,
uiBytesToWrite, pvBuffer, puiBytesWritten)))
{
if (rc != NE_FLM_IO_DISK_FULL && rc != NE_FLM_MEM)
{
releaseFile( (FLMUINT)0, TRUE);
}
goto Exit;
}
Exit:
return( rc);
}
/****************************************************************************
Desc: Releases all file handle objects and optionally closes the files
****************************************************************************/
RCODE F_SuperFileHdl::releaseFile(
FLMUINT uiFileNum,
FLMBOOL bCloseFile)
{
RCODE rc = NE_FLM_OK;
CHECKED_OUT_FILE_HDL * pCkoFileHdl;
FLMUINT uiSlot;
pCkoFileHdl = getCkoFileHdlPtr( uiFileNum, &uiSlot);
if( pCkoFileHdl->uiFileNumber == uiFileNum)
{
if( RC_BAD( rc = releaseFile( pCkoFileHdl, bCloseFile)))
{
goto Exit;
}
}
Exit:
return( rc);
}
/****************************************************************************
Desc: Releases all file handle objects and optionally closes the files
****************************************************************************/
RCODE F_SuperFileHdl::releaseFiles(
FLMBOOL bCloseFiles)
{
RCODE rc = NE_FLM_OK;
FLMUINT uiLoop;
flmAssert( m_bSetupCalled);
for( uiLoop = 0; uiLoop <= m_uiHighestUsedSlot; uiLoop++)
{
if( RC_BAD( rc = releaseFile(
&m_CheckedOutFileHdls[ uiLoop], bCloseFiles)))
{
goto Exit;
}
}
Exit:
return( rc);
}
/****************************************************************************
Desc: Releases a file handle object
****************************************************************************/
RCODE F_SuperFileHdl::releaseFile(
CHECKED_OUT_FILE_HDL * pCkoFileHdl,
FLMBOOL bCloseFile)
{
RCODE rc = NE_FLM_OK;
IF_FileHdl * pFileHdl = pCkoFileHdl->pFileHdl;
if( pFileHdl)
{
if( pCkoFileHdl->bDirty)
{
(void)pFileHdl->flush();
}
if( bCloseFile)
{
FLMUINT uiRefCnt;
uiRefCnt = pFileHdl->Release();
flmAssert( uiRefCnt == 0);
}
clearCkoFileHdl( pCkoFileHdl);
}
return( rc);
}
/****************************************************************************
Desc: Copy one CKO array into another.
****************************************************************************/
void F_SuperFileHdl::copyCkoFileHdls(
CHECKED_OUT_FILE_HDL * pSrcCkoArray,
FLMUINT uiSrcHighestUsedSlot)
{
FLMUINT uiNewSlot;
FLMUINT uiSrcSlot;
// Zeroeth element is always copied.
f_memcpy( m_pCheckedOutFileHdls, pSrcCkoArray,
sizeof( CHECKED_OUT_FILE_HDL));
// Memset the rest of the destination array to zero.
f_memset( &m_pCheckedOutFileHdls[1], 0, sizeof( CHECKED_OUT_FILE_HDL) *
(m_uiCkoArraySize - 1));
m_uiHighestUsedSlot = 0;
m_uiLowestDirtySlot = 1;
m_uiHighestDirtySlot = 0;
for (uiSrcSlot = 1, pSrcCkoArray++;
uiSrcSlot <= uiSrcHighestUsedSlot;
uiSrcSlot++, pSrcCkoArray++)
{
if (pSrcCkoArray->pFileHdl && pSrcCkoArray->uiFileNumber)
{
uiNewSlot = pSrcCkoArray->uiFileNumber % (m_uiCkoArraySize - 1) + 1;
// Only overwrite the destination one if the file number is
// lower than the one already there
if (pSrcCkoArray->uiFileNumber <
m_pCheckedOutFileHdls [uiNewSlot].uiFileNumber ||
!m_pCheckedOutFileHdls [uiNewSlot].uiFileNumber)
{
if (m_pCheckedOutFileHdls [uiNewSlot].uiFileNumber)
{
releaseFile( &m_pCheckedOutFileHdls [uiNewSlot], FALSE);
}
f_memcpy( &m_pCheckedOutFileHdls [uiNewSlot], pSrcCkoArray,
sizeof( CHECKED_OUT_FILE_HDL));
if (uiNewSlot > m_uiHighestUsedSlot)
{
m_uiHighestUsedSlot = uiNewSlot;
}
if (m_uiHighestFileNumber < pSrcCkoArray->uiFileNumber)
{
m_uiHighestFileNumber = pSrcCkoArray->uiFileNumber;
}
if (pSrcCkoArray->bDirty)
{
if (m_uiLowestDirtySlot > m_uiHighestDirtySlot)
{
m_uiLowestDirtySlot =
m_uiHighestDirtySlot = uiNewSlot;
}
else if( m_uiHighestDirtySlot < uiNewSlot)
{
m_uiHighestDirtySlot = uiNewSlot;
}
else if (m_uiLowestDirtySlot < uiNewSlot)
{
m_uiLowestDirtySlot = uiNewSlot;
}
}
}
else
{
releaseFile( pSrcCkoArray, FALSE);
}
}
}
}
/****************************************************************************
Desc: Disable flush minimizing.
****************************************************************************/
void F_SuperFileHdl::disableFlushMinimize( void)
{
// Copy the allocated array back into the fixed array.
// This doesn't necessarily copy all of the file handles.
if (m_pCheckedOutFileHdls != &m_CheckedOutFileHdls [0])
{
CHECKED_OUT_FILE_HDL * pOldCkoArray = m_pCheckedOutFileHdls;
FLMUINT uiOldHighestUsedSlot = m_uiHighestUsedSlot;
m_pCheckedOutFileHdls = &m_CheckedOutFileHdls [0];
m_uiCkoArraySize = MAX_CHECKED_OUT_FILE_HDLS + 1;
copyCkoFileHdls( pOldCkoArray, uiOldHighestUsedSlot);
f_free( &pOldCkoArray);
}
m_bMinimizeFlushes = FALSE;
}
/****************************************************************************
Desc: Flush dirty files to disk.
****************************************************************************/
RCODE F_SuperFileHdl::flush( void)
{
RCODE rc = NE_FLM_OK;
FLMUINT uiLoop;
// Flush all dirty files
for (uiLoop = m_uiLowestDirtySlot;
uiLoop <= m_uiHighestDirtySlot;
uiLoop++)
{
if( m_pCheckedOutFileHdls[ uiLoop].bDirty)
{
RCODE tmpRc;
if (RC_BAD( tmpRc =
m_pCheckedOutFileHdls[ uiLoop].pFileHdl->flush()))
{
rc = tmpRc;
releaseFile( &m_pCheckedOutFileHdls [uiLoop], TRUE);
}
m_pCheckedOutFileHdls[ uiLoop].bDirty = FALSE;
}
}
m_uiLowestDirtySlot = 1;
m_uiHighestDirtySlot = 0;
return( rc);
}
/****************************************************************************
Desc: Truncates back to an end of file block address.
This may only be called from reduce() because there cannot
be any other cases to reduce a 3x block file.
****************************************************************************/
RCODE F_SuperFileHdl::truncateFile(
FLMUINT uiEOFBlkAddress)
{
RCODE rc = NE_FLM_OK;
FLMUINT uiFileNumber = (FLMUINT)FSGetFileNumber( uiEOFBlkAddress);
FLMUINT uiBlockOffset = (FLMUINT)FSGetFileOffset( uiEOFBlkAddress);
IF_FileHdl * pFileHdl;
// Truncate the current block file.
if( RC_BAD( rc = getFileHdl( uiFileNumber, TRUE, &pFileHdl)))
{
goto Exit;
}
if( RC_BAD( rc = pFileHdl->truncate( uiBlockOffset)))
{
releaseFile( uiFileNumber, TRUE);
goto Exit;
}
// Visit the rest of the high block files until a NULL file hdl is hit.
for( ;;)
{
if( RC_BAD( getFileHdl( ++uiFileNumber, TRUE, &pFileHdl)))
{
break;
}
if( RC_BAD( rc = pFileHdl->truncate( (FLMUINT)0 )))
{
releaseFile( uiFileNumber, TRUE);
goto Exit;
}
if( RC_BAD( rc = releaseFile( uiFileNumber, TRUE)))
{
goto Exit;
}
}
Exit:
return( rc);
}
/****************************************************************************
Desc: Truncate to zero length any files between the specified start
and end files.
****************************************************************************/
void F_SuperFileHdl::truncateFiles(
FLMUINT uiStartFileNum,
FLMUINT uiEndFileNum)
{
FLMUINT uiFileNumber;
IF_FileHdl * pFileHdl;
for( uiFileNumber = uiStartFileNum;
uiFileNumber <= uiEndFileNum;
uiFileNumber++ )
{
if( RC_OK( getFileHdl( uiFileNumber, TRUE, &pFileHdl )))
{
(void)pFileHdl->truncate( (FLMUINT)0 );
(void)releaseFile( uiFileNumber, TRUE);
}
}
}
/****************************************************************************
Desc: Returns the physical size of a file
****************************************************************************/
RCODE F_SuperFileHdl::getFileSize(
FLMUINT uiFileNumber,
FLMUINT64 * pui64FileSize)
{
IF_FileHdl * pFileHdl = NULL;
RCODE rc = NE_FLM_OK;
flmAssert( m_bSetupCalled);
flmAssert( pui64FileSize);
*pui64FileSize = 0;
// Get the file handle.
if( RC_BAD( rc = getFileHdl( uiFileNumber, FALSE, &pFileHdl)))
{
goto Exit;
}
if( RC_BAD( rc = pFileHdl->size( pui64FileSize)))
{
releaseFile( uiFileNumber, TRUE);
goto Exit;
}
Exit:
return( rc);
}
/****************************************************************************
Desc: Returns the path of a file given its file number
****************************************************************************/
RCODE F_SuperFileHdl::getFilePath(
FLMUINT uiFileNumber,
char * pszIoPath)
{
RCODE rc = NE_FLM_OK;
FLMUINT uiExtOffset;
// Sanity checks
flmAssert( m_bSetupCalled);
if (!uiFileNumber)
{
f_strcpy( pszIoPath, m_pszDbFileName);
goto Exit;
}
if ((m_uiDbVersion >= FLM_FILE_FORMAT_VER_4_3 &&
uiFileNumber <= MAX_DATA_FILE_NUM_VER43) ||
uiFileNumber <= MAX_DATA_FILE_NUM_VER40)
{
f_memcpy( pszIoPath, m_pszDataFileNameBase, m_uiDataExtOffset);
uiExtOffset = m_uiDataExtOffset;
}
else
{
f_memcpy( pszIoPath, m_pszDbFileName, m_uiExtOffset);
uiExtOffset = m_uiExtOffset;
}
// Modify the file's extension.
bldSuperFileExtension( m_uiDbVersion,
uiFileNumber, &pszIoPath[ uiExtOffset]);
Exit:
return( rc);
}
/****************************************************************************
Desc: Reallocates the checked out file handle array.
****************************************************************************/
RCODE F_SuperFileHdl::reallocCkoArray(
FLMUINT uiFileNum
)
{
RCODE rc = NE_FLM_OK;
FLMUINT uiNewSize;
CHECKED_OUT_FILE_HDL * pNewCkoArray;
CHECKED_OUT_FILE_HDL * pOldCkoArray;
FLMUINT uiOldHighestUsedSlot;
if (uiFileNum < m_uiHighestFileNumber)
{
uiFileNum = m_uiHighestFileNumber;
}
uiNewSize = uiFileNum + 128;
// Reallocate so we can guarantee that all of the current file
// numbers will copy and there is room for this new one as well.
if (uiNewSize > MAX_LOG_BLOCK_FILE_NUMBER( m_uiDbVersion) + 1)
{
flmAssert( uiFileNum <= MAX_LOG_BLOCK_FILE_NUMBER( m_uiDbVersion));
uiNewSize = MAX_LOG_BLOCK_FILE_NUMBER( m_uiDbVersion) + 1;
}
// No need to call f_calloc, because copyCkoFileHdls will initialize
// it below.
if (RC_BAD( rc = f_alloc( sizeof( CHECKED_OUT_FILE_HDL) * uiNewSize,
&pNewCkoArray)))
{
goto Exit;
}
pOldCkoArray = m_pCheckedOutFileHdls;
uiOldHighestUsedSlot = m_uiHighestUsedSlot;
m_pCheckedOutFileHdls = pNewCkoArray;
m_uiCkoArraySize = uiNewSize;
copyCkoFileHdls( pOldCkoArray, uiOldHighestUsedSlot);
// Can't free the old one until after the copy!
if (pOldCkoArray != &m_CheckedOutFileHdls [0])
{
f_free( &pOldCkoArray);
}
Exit:
return( rc);
}
/****************************************************************************
Desc: Returns a file handle given the file's number
****************************************************************************/
RCODE F_SuperFileHdl::getFileHdl(
FLMUINT uiFileNum,
FLMBOOL bGetForUpdate,
IF_FileHdl ** ppFileHdl)
{
RCODE rc = NE_FLM_OK;
IF_FileHdl * pFileHdl = NULL;
CHECKED_OUT_FILE_HDL * pCkoFileHdl;
char szFilePath[ F_PATH_MAX_SIZE];
FLMUINT uiSlot;
pCkoFileHdl = getCkoFileHdlPtr( uiFileNum, &uiSlot);
if( pCkoFileHdl->uiFileNumber != uiFileNum &&
pCkoFileHdl->pFileHdl)
{
if (pCkoFileHdl->bDirty && m_bMinimizeFlushes)
{
flmAssert( pCkoFileHdl->uiFileNumber);
if (RC_BAD( reallocCkoArray( uiFileNum)))
{
goto Exit;
}
pCkoFileHdl = getCkoFileHdlPtr( uiFileNum, &uiSlot);
// Better have reallocated so that the new slot for
// the file number has nothing in it.
flmAssert( !pCkoFileHdl->uiFileNumber &&
!pCkoFileHdl->pFileHdl);
}
else
{
if( RC_BAD( rc = releaseFile( pCkoFileHdl, FALSE)))
{
goto Exit;
}
}
}
if( !pCkoFileHdl->pFileHdl)
{
if (!pFileHdl)
{
// Build the file path
if( RC_BAD( rc = getFilePath( uiFileNum, szFilePath)))
{
goto Exit;
}
// Open the file
if( RC_BAD( rc = gv_FlmSysData.pFileSystem->openFile(
szFilePath, FLM_IO_RDWR | FLM_IO_SH_DENYNONE | FLM_IO_DIRECT,
&pFileHdl)))
{
goto Exit;
}
}
pCkoFileHdl->pFileHdl = pFileHdl;
pFileHdl = NULL;
pCkoFileHdl->uiFileNumber = uiFileNum;
pCkoFileHdl->bDirty = FALSE;
if( m_uiHighestUsedSlot < uiSlot)
{
m_uiHighestUsedSlot = uiSlot;
}
if (m_uiHighestFileNumber < uiFileNum)
{
m_uiHighestFileNumber = uiFileNum;
}
}
*ppFileHdl = pCkoFileHdl->pFileHdl;
if( bGetForUpdate)
{
pCkoFileHdl->bDirty = TRUE;
if (m_uiLowestDirtySlot > m_uiHighestDirtySlot)
{
m_uiLowestDirtySlot =
m_uiHighestDirtySlot = uiSlot;
}
else if( m_uiHighestDirtySlot < uiSlot)
{
m_uiHighestDirtySlot = uiSlot;
}
else if (m_uiLowestDirtySlot < uiSlot)
{
m_uiLowestDirtySlot = uiSlot;
}
}
Exit:
if( pFileHdl)
{
pFileHdl->Release();
}
return( rc);
}
/****************************************************************************
Desc: Generates a file name given a super file number.
Adds ".xx" to pFileExtension. Use lower case characters.
Notes: This is a base 24 alphanumeric value where
{ a, b, c, d, e, f, i, l, o, r, u, v } values are removed.
****************************************************************************/
void bldSuperFileExtension(
FLMUINT uiDbVersion,
FLMUINT uiFileNum,
char * pszFileExtension)
{
FLMBYTE ucLetter;
flmAssert( uiDbVersion);
if (uiDbVersion >= FLM_FILE_FORMAT_VER_4_3)
{
if (uiFileNum <= MAX_DATA_FILE_NUM_VER43 - 1536)
{
// No additional letter - File numbers 1 to 511
// This is just like pre-4.3 numbering.
ucLetter = 0;
}
else if (uiFileNum <= MAX_DATA_FILE_NUM_VER43 - 1024)
{
// File numbers 512 to 1023
ucLetter = 'r';
}
else if (uiFileNum <= MAX_DATA_FILE_NUM_VER43 - 512)
{
// File numbers 1024 to 1535
ucLetter = 's';
}
else if (uiFileNum <= MAX_DATA_FILE_NUM_VER43)
{
// File numbers 1536 to 2047
ucLetter = 't';
}
else if (uiFileNum <= MAX_LOG_FILE_NUM_VER43 - 1536)
{
// File numbers 2048 to 2559
ucLetter = 'v';
}
else if (uiFileNum <= MAX_LOG_FILE_NUM_VER43 - 1024)
{
// File numbers 2560 to 3071
ucLetter = 'w';
}
else if (uiFileNum <= MAX_LOG_FILE_NUM_VER43 - 512)
{
// File numbers 3072 to 3583
ucLetter = 'x';
}
else
{
flmAssert( uiFileNum <= MAX_LOG_FILE_NUM_VER43);
// File numbers 3584 to 4095
ucLetter = 'z';
}
}
else
{
if (uiFileNum <= MAX_DATA_FILE_NUM_VER40)
{
// No additional letter - File numbers 1 to 511
// This is just like pre-4.3 numbering.
ucLetter = 0;
}
else
{
flmAssert( uiFileNum <= MAX_LOG_FILE_NUM_VER40);
// File numbers 512 to 1023
ucLetter = 'x';
}
}
*pszFileExtension++ = '.';
*pszFileExtension++ = f_getBase24DigitChar( (FLMBYTE)((uiFileNum & 511) / 24));
*pszFileExtension++ = f_getBase24DigitChar( (FLMBYTE)((uiFileNum & 511) % 24));
*pszFileExtension++ = ucLetter;
*pszFileExtension = 0;
}
-206
View File
@@ -1,206 +0,0 @@
//-------------------------------------------------------------------------
// Desc: Super-file class definitions.
// Tabs: 3
//
// Copyright (c) 1998-2006 Novell, Inc. All Rights Reserved.
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of version 2 of the GNU General Public
// License as published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, contact Novell, Inc.
//
// To contact Novell about this file by physical or electronic mail,
// you may find current contact information at www.novell.com
//
// $Id: fsuperfl.h 12329 2006-01-20 17:49:30 -0700 (Fri, 20 Jan 2006) ahodgkinson $
//-------------------------------------------------------------------------
#ifndef FSUPERFL_H
#define FSUPERFL_H
#define MAX_CHECKED_OUT_FILE_HDLS 8
void bldSuperFileExtension(
FLMUINT uiDbVersion,
FLMUINT uiFileNum,
char * pszFileExtension);
typedef struct
{
IF_FileHdl * pFileHdl;
FLMUINT uiFileNumber;
FLMBOOL bDirty;
} CHECKED_OUT_FILE_HDL;
/****************************************************************************
Desc: The F_SuperFileHdl object manages the control and block files
associated with a FLAIM Super File. This class also provides
backward compatibility with prior file formats.
Note:
****************************************************************************/
class F_SuperFileHdl : public F_Object
{
public:
F_SuperFileHdl();
~F_SuperFileHdl();
RCODE setup(
const char * pszDbFileName,
const char * pszDataDir,
FLMUINT uiDbVersion);
RCODE createFile(
FLMUINT uiFileNumber);
RCODE readBlock(
FLMUINT uiBlkAddress,
FLMUINT uiBytesToRead,
void * pvBuffer,
FLMUINT * puiBytesRead);
RCODE writeBlock(
FLMUINT uiBlkAddress,
FLMUINT uiBytesToWrite,
const void * pvBuffer,
IF_IOBuffer * pIOBuffer,
FLMUINT * puiBytesWritten);
RCODE readHeader(
FLMUINT uiOffset,
FLMUINT uiBytesToRead,
void * pvBuffer,
FLMUINT * puiBytesRead);
RCODE writeHeader(
FLMUINT uiOffset,
FLMUINT uiBytesToWrite,
const void * pvBuffer,
FLMUINT * puiBytesWritten);
RCODE getFilePath(
FLMUINT uiFileNumber,
char * pszPath);
RCODE getFileHdl(
FLMUINT uiFileNumber,
FLMBOOL bGetForUpdate,
IF_FileHdl ** ppFileHdlRV);
RCODE getFileSize(
FLMUINT uiFileNumber,
FLMUINT64 * pui64FileSize);
RCODE releaseFile(
FLMUINT uiFileNum,
FLMBOOL bCloseFile);
RCODE releaseFiles(
FLMBOOL bCloseFiles);
RCODE truncateFile(
FLMUINT uiEOFBlkAddress);
void truncateFiles(
FLMUINT uiStartFileNum,
FLMUINT uiEndFileNum);
RCODE releaseFile(
CHECKED_OUT_FILE_HDL * pChkFileHdl,
FLMBOOL bCloseFile);
FINLINE void enableFlushMinimize( void)
{
m_bMinimizeFlushes = TRUE;
}
void disableFlushMinimize( void);
RCODE flush( void);
FINLINE void setExtendSize(
FLMUINT uiExtendSize)
{
m_uiExtendSize = uiExtendSize;
}
FINLINE void setMaxAutoExtendSize(
FLMUINT uiMaxAutoExtendSize)
{
m_uiMaxAutoExtendSize = uiMaxAutoExtendSize;
}
FINLINE FLMBOOL canDoAsync( void)
{
if (m_pCheckedOutFileHdls[ 0].pFileHdl)
{
return( m_pCheckedOutFileHdls[ 0].pFileHdl->canDoAsync());
}
else
{
IF_FileHdl * pFileHdl;
if( RC_OK( getFileHdl( 0, FALSE, &pFileHdl)))
{
return( pFileHdl->canDoAsync());
}
}
return( FALSE);
}
private:
FINLINE CHECKED_OUT_FILE_HDL * getCkoFileHdlPtr(
FLMUINT uiFileNum,
FLMUINT * puiSlot)
{
*puiSlot = (uiFileNum
? (uiFileNum % (m_uiCkoArraySize - 1)) + 1
: 0);
return( &m_pCheckedOutFileHdls[ *puiSlot]);
}
FINLINE void clearCkoFileHdl(
CHECKED_OUT_FILE_HDL * pCkoFileHdl)
{
pCkoFileHdl->pFileHdl = NULL;
pCkoFileHdl->uiFileNumber = 0;
pCkoFileHdl->bDirty = FALSE;
}
void copyCkoFileHdls(
CHECKED_OUT_FILE_HDL * pSrcCkoArray,
FLMUINT uiSrcHighestUsedSlot);
RCODE reallocCkoArray(
FLMUINT uiFileNum);
char * m_pszDbFileName;
char * m_pszDataFileNameBase;
FLMUINT m_uiExtOffset;
FLMUINT m_uiDataExtOffset;
CHECKED_OUT_FILE_HDL m_CheckedOutFileHdls[
MAX_CHECKED_OUT_FILE_HDLS + 1];
CHECKED_OUT_FILE_HDL * m_pCheckedOutFileHdls;
FLMUINT m_uiCkoArraySize;
FLMUINT m_uiExtendSize;
FLMUINT m_uiMaxAutoExtendSize;
FLMUINT m_uiDbVersion;
FLMUINT m_uiLowestDirtySlot;
FLMUINT m_uiHighestDirtySlot;
FLMUINT m_uiHighestUsedSlot;
FLMUINT m_uiHighestFileNumber;
FLMBOOL m_bMinimizeFlushes;
FLMBOOL m_bSetupCalled;
};
#endif
+243
View File
@@ -4652,3 +4652,246 @@ void flmDeleteCCSRefs(
}
}
}
/****************************************************************************
Desc:
****************************************************************************/
F_SuperFileClient::F_SuperFileClient()
{
m_pszCFileName = NULL;
m_pszDataFileBaseName = NULL;
m_uiExtOffset = 0;
m_uiDataExtOffset = 0;
m_uiDbVersion = 0;
}
/****************************************************************************
Desc:
****************************************************************************/
F_SuperFileClient::~F_SuperFileClient()
{
if( m_pszCFileName)
{
f_free( &m_pszCFileName);
}
}
/****************************************************************************
Desc:
****************************************************************************/
RCODE F_SuperFileClient::setup(
const char * pszCFileName,
const char * pszDataDir,
FLMUINT uiDbVersion)
{
RCODE rc = NE_FLM_OK;
FLMUINT uiNameLen;
FLMUINT uiDataNameLen;
char szDir[ F_PATH_MAX_SIZE];
char szBaseName[ F_FILENAME_SIZE];
if( !pszCFileName && *pszCFileName == 0)
{
rc = RC_SET( NE_FLM_IO_INVALID_FILENAME);
goto Exit;
}
uiNameLen = f_strlen( pszCFileName);
if (pszDataDir && *pszDataDir)
{
if (RC_BAD( rc = gv_FlmSysData.pFileSystem->pathReduce(
pszCFileName, szDir, szBaseName)))
{
goto Exit;
}
f_strcpy( szDir, pszDataDir);
if (RC_BAD( rc = gv_FlmSysData.pFileSystem->pathAppend(
szDir, szBaseName)))
{
goto Exit;
}
uiDataNameLen = f_strlen( szDir);
if (RC_BAD( rc = f_alloc( (uiNameLen + 1) + (uiDataNameLen + 1),
&m_pszCFileName)))
{
goto Exit;
}
f_memcpy( m_pszCFileName, pszCFileName, uiNameLen + 1);
m_pszDataFileBaseName = m_pszCFileName + uiNameLen + 1;
flmGetDbBasePath( m_pszDataFileBaseName, szDir, &m_uiDataExtOffset);
m_uiExtOffset = uiNameLen - (uiDataNameLen - m_uiDataExtOffset);
}
else
{
if (RC_BAD( rc = f_alloc( (uiNameLen + 1) * 2, &m_pszCFileName)))
{
goto Exit;
}
f_memcpy( m_pszCFileName, pszCFileName, uiNameLen + 1);
m_pszDataFileBaseName = m_pszCFileName + uiNameLen + 1;
flmGetDbBasePath( m_pszDataFileBaseName,
m_pszCFileName, &m_uiDataExtOffset);
m_uiExtOffset = m_uiDataExtOffset;
}
m_uiDbVersion = uiDbVersion;
Exit:
return( rc);
}
/****************************************************************************
Desc:
****************************************************************************/
FLMUINT FLMAPI F_SuperFileClient::getFileNumber(
FLMUINT uiBlockAddr)
{
return( FSGetFileNumber( uiBlockAddr));
}
/****************************************************************************
Desc:
****************************************************************************/
FLMUINT FLMAPI F_SuperFileClient::getFileOffset(
FLMUINT uiBlockAddr)
{
return( FSGetFileOffset( uiBlockAddr));
}
/****************************************************************************
Desc:
****************************************************************************/
RCODE FLMAPI F_SuperFileClient::getFilePath(
FLMUINT uiFileNumber,
char * pszPath)
{
RCODE rc = NE_FLM_OK;
FLMUINT uiExtOffset;
if (!uiFileNumber)
{
f_strcpy( pszPath, m_pszCFileName);
goto Exit;
}
if ((m_uiDbVersion >= FLM_FILE_FORMAT_VER_4_3 &&
uiFileNumber <= MAX_DATA_FILE_NUM_VER43) ||
uiFileNumber <= MAX_DATA_FILE_NUM_VER40)
{
f_memcpy( pszPath, m_pszDataFileBaseName, m_uiDataExtOffset);
uiExtOffset = m_uiDataExtOffset;
}
else
{
f_memcpy( pszPath, m_pszCFileName, m_uiExtOffset);
uiExtOffset = m_uiExtOffset;
}
// Modify the file's extension.
bldSuperFileExtension( m_uiDbVersion,
uiFileNumber, &pszPath[ uiExtOffset]);
Exit:
return( rc);
}
/****************************************************************************
Desc: Generates a file name given a super file number.
Adds ".xx" to pFileExtension. Use lower case characters.
Notes: This is a base 24 alphanumeric value where
{ a, b, c, d, e, f, i, l, o, r, u, v } values are removed.
****************************************************************************/
void F_SuperFileClient::bldSuperFileExtension(
FLMUINT uiDbVersion,
FLMUINT uiFileNum,
char * pszFileExtension)
{
FLMBYTE ucLetter;
flmAssert( uiDbVersion);
if (uiDbVersion >= FLM_FILE_FORMAT_VER_4_3)
{
if (uiFileNum <= MAX_DATA_FILE_NUM_VER43 - 1536)
{
// No additional letter - File numbers 1 to 511
// This is just like pre-4.3 numbering.
ucLetter = 0;
}
else if (uiFileNum <= MAX_DATA_FILE_NUM_VER43 - 1024)
{
// File numbers 512 to 1023
ucLetter = 'r';
}
else if (uiFileNum <= MAX_DATA_FILE_NUM_VER43 - 512)
{
// File numbers 1024 to 1535
ucLetter = 's';
}
else if (uiFileNum <= MAX_DATA_FILE_NUM_VER43)
{
// File numbers 1536 to 2047
ucLetter = 't';
}
else if (uiFileNum <= MAX_LOG_FILE_NUM_VER43 - 1536)
{
// File numbers 2048 to 2559
ucLetter = 'v';
}
else if (uiFileNum <= MAX_LOG_FILE_NUM_VER43 - 1024)
{
// File numbers 2560 to 3071
ucLetter = 'w';
}
else if (uiFileNum <= MAX_LOG_FILE_NUM_VER43 - 512)
{
// File numbers 3072 to 3583
ucLetter = 'x';
}
else
{
flmAssert( uiFileNum <= MAX_LOG_FILE_NUM_VER43);
// File numbers 3584 to 4095
ucLetter = 'z';
}
}
else
{
if (uiFileNum <= MAX_DATA_FILE_NUM_VER40)
{
// No additional letter - File numbers 1 to 511
// This is just like pre-4.3 numbering.
ucLetter = 0;
}
else
{
flmAssert( uiFileNum <= MAX_LOG_FILE_NUM_VER40);
// File numbers 512 to 1023
ucLetter = 'x';
}
}
*pszFileExtension++ = '.';
*pszFileExtension++ = f_getBase24DigitChar( (FLMBYTE)((uiFileNum & 511) / 24));
*pszFileExtension++ = f_getBase24DigitChar( (FLMBYTE)((uiFileNum & 511) % 24));
*pszFileExtension++ = ucLetter;
*pszFileExtension = 0;
}
+12 -12
View File
@@ -43,20 +43,20 @@ FSTATIC const char * gv_pszSampleDictionary =
" 2 field 3\n"
" 3 required\n";
#define PERSON_TAG 1
#define LAST_NAME_TAG 2
#define FIRST_NAME_TAG 3
#define AGE_TAG 4
#define MISC_TAG 5
#define LAST_NAME_FIRST_NAME_IX 100
#define PERSON_TAG 1
#define LAST_NAME_TAG 2
#define FIRST_NAME_TAG 3
#define AGE_TAG 4
#define MISC_TAG 5
#define LAST_NAME_FIRST_NAME_IX 100
#ifdef FLM_NLM
#define DB_NAME_STR "SYS:\\TEST\\SAMPLE.DB"
#define DB_COPY_NAME_STR "SYS:\\TEST\\SAMPLECOPY.DB"
#define DB_RENAME_NAME_STR "SYS:\\TEST\\SAMPLERENAME.DB"
#define DB_RESTORE_NAME_STR "SYS:\\TEST\\SAMPLERESTORE.DB"
#define DB_REBUILD_NAME_STR "SYS:\\TEST\\SAMPLEREBUILD.DB"
#define BACKUP_PATH "SYS:\\TEST\\SAMPLEBACKUP"
#define DB_NAME_STR "SYS:\\SAMPLE.DB"
#define DB_COPY_NAME_STR "SYS:\\SAMPLECOPY.DB"
#define DB_RENAME_NAME_STR "SYS:\\SAMPLERENAME.DB"
#define DB_RESTORE_NAME_STR "SYS:\\SAMPLERESTORE.DB"
#define DB_REBUILD_NAME_STR "SYS:\\SAMPLEREBUILD.DB"
#define BACKUP_PATH "SYS:\\SAMPLEBACKUP"
#else
#define DB_NAME_STR "sample.db"
#define DB_COPY_NAME_STR "samplecopy.db"
+2 -2
View File
@@ -63,7 +63,7 @@ typedef enum
class FlmArgSet;
class FlmArg : public F_Base
class FlmArg : public F_Object
{
private:
FlmArg(
@@ -243,7 +243,7 @@ private:
friend class FlmArgSet;
};
class FlmArgSet : public F_Base
class FlmArgSet : public F_Object
{
public:
FlmArgSet(
+28 -18
View File
@@ -209,7 +209,7 @@ int main(
RCODE rc = FERR_OK;
IFlmTest * pTest = NULL;
unsigned int i = 1;
ArgList args;
ArgList * pArgs = NULL;
TEST_INFO testInfo;
if( RC_BAD( rc = FlmStartup()))
@@ -217,6 +217,12 @@ int main(
goto Exit;
}
if( (pArgs = f_new ArgList) == NULL)
{
rc = RC_SET( FERR_MEM);
goto Exit;
}
#ifdef FLM_NLM
f_conInit( 0, 0, "FLAIM Unit Test");
#endif
@@ -231,35 +237,35 @@ int main(
}
}
args.expandArgs( argv, argc);
pArgs->expandArgs( argv, argc);
while( i < args.getNumEntries())
while( i < pArgs->getNumEntries())
{
if ( args[i][0] != '-')
if( (*pArgs)[i][0] != '-')
{
goto Exit;
}
if( (args[i][1] == 'l') || (args[i][1] == 'L'))
if( ((*pArgs)[i][1] == 'l') || ((*pArgs)[i][1] == 'L'))
{
testInfo.bLog = true;
f_strcpy( testInfo.pszLogfile, &args[i][2]);
f_strcpy( testInfo.pszLogfile, &((*pArgs)[i][2]));
}
else if( (args[i][1] == 'd') || (args[i][1] == 'D'))
else if( ((*pArgs)[i][1] == 'd') || ((*pArgs)[i][1] == 'D'))
{
testInfo.bDisplay = true;
}
else if( (args[i][1] == 'c') || (args[i][1] == 'C'))
else if( ((*pArgs)[i][1] == 'c') || ((*pArgs)[i][1] == 'C'))
{
f_strcpy( testInfo.pszConfig, &args[i][2]);
f_strcpy( testInfo.pszConfig, &((*pArgs)[i][2]));
}
else if( (args[i][1] == 'b') || (args[i][1] == 'B'))
else if( ((*pArgs)[i][1] == 'b') || ((*pArgs)[i][1] == 'B'))
{
f_strcpy( testInfo.pszBuild, &args[i][2]);
f_strcpy( testInfo.pszBuild, &((*pArgs)[i][2]));
}
else if( (args[i][1] == 'u') || (args[i][1] == 'U'))
else if( ((*pArgs)[i][1] == 'u') || ((*pArgs)[i][1] == 'U'))
{
f_strcpy( testInfo.pszUser, &args[i][2]);
f_strcpy( testInfo.pszUser, &((*pArgs)[i][2]));
}
else
{
@@ -299,6 +305,11 @@ Exit:
pTest->Release();
}
if( pArgs)
{
pArgs->Release();
}
#ifdef FLM_NLM
f_conExit();
#endif
@@ -1131,7 +1142,6 @@ ArgList::ArgList()
{
m_uiCapacity = INIT_SIZE;
m_uiNumEntries = 0;
f_alloc( m_uiCapacity * sizeof( char *), &m_ppszArgs);
}
@@ -1146,7 +1156,7 @@ ArgList::~ArgList()
{
for( uiLoop = 0; uiLoop < m_uiNumEntries; uiLoop++)
{
f_free( &( m_ppszArgs[uiLoop]));
f_free( &m_ppszArgs[ uiLoop]);
}
f_free( &m_ppszArgs);
@@ -1172,8 +1182,8 @@ RCODE ArgList::resize( void)
for( uiLoop = 0; uiLoop < m_uiNumEntries; uiLoop++)
{
if( RC_BAD( rc = f_alloc( f_strlen( m_ppszArgs[uiLoop]) + 1,
&ppszTemp[uiLoop])))
if( RC_BAD( rc = f_alloc( f_strlen( m_ppszArgs[ uiLoop]) + 1,
&ppszTemp[ uiLoop])))
{
f_free( &ppszTemp);
goto Exit;
@@ -1215,7 +1225,7 @@ RCODE ArgList::addArg(
}
if( RC_BAD( rc = f_alloc( f_strlen( pszArg) + 1,
&m_ppszArgs[m_uiNumEntries])))
&m_ppszArgs[ m_uiNumEntries])))
{
goto Exit;
}
+1 -1
View File
@@ -429,7 +429,7 @@ protected:
/****************************************************************************
Desc:
****************************************************************************/
class ArgList
class ArgList : public F_Object
{
public:
+40 -11
View File
@@ -592,13 +592,12 @@ FSTATIC FLMBOOL ViewOpenFileDirect(
/***************************************************************************
Desc: This routine opens the database file which is to be viewed.
*****************************************************************************/
FSTATIC FLMBOOL ViewOpenFile(
void
)
FSTATIC FLMBOOL ViewOpenFile( void)
{
RCODE rc;
FLMBOOL bOk = FALSE;
FLMBOOL bIgnore;
RCODE rc;
FLMBOOL bOk = FALSE;
FLMBOOL bIgnore;
F_SuperFileClient * pSFileClient = NULL;
Get_File_Name:
@@ -625,7 +624,25 @@ Get_File_Name:
gv_pSFileHdl->Release();
gv_pSFileHdl = NULL;
}
if( pSFileClient)
{
pSFileClient->Release();
pSFileClient = NULL;
}
if( (pSFileClient = f_new F_SuperFileClient) == NULL)
{
rc = RC_SET( FERR_MEM);
goto Exit;
}
if( RC_BAD( pSFileClient->setup(
gv_szViewFileName, gv_szDataDir, gv_ViewHdrInfo.FileHdr.uiVersionNum)))
{
goto Exit;
}
if ((gv_pSFileHdl = f_new F_SuperFileHdl) == NULL)
{
rc = RC_SET( FERR_MEM);
@@ -633,12 +650,13 @@ Get_File_Name:
goto Exit;
}
if (RC_BAD( rc = gv_pSFileHdl->setup( gv_szViewFileName, gv_szDataDir,
gv_ViewHdrInfo.FileHdr.uiVersionNum)))
if (RC_BAD( rc = gv_pSFileHdl->setup( pSFileClient)))
{
ViewShowRCError( "setting up super file handle", rc);
goto Exit;
}
gv_pSFileHdl->setBlockSize( gv_ViewHdrInfo.FileHdr.uiBlockSize);
if( RC_BAD( rc = ViewReadAndVerifyHdrInfo()))
{
@@ -680,10 +698,14 @@ Other_Error:
'Y') == 'Y')
{
if (!ViewOpenFileDirect())
{
goto Exit;
}
}
else
{
goto Exit;
}
}
}
else
@@ -695,12 +717,13 @@ Other_Error:
ViewShowRCError( "calling fdbInit", rc);
goto Exit;
}
if (!ViewOpenFileDirect())
{
goto Exit;
}
}
/* Fix the header if requested to */
bOk = TRUE;
Exit:
@@ -715,6 +738,12 @@ Exit:
gv_bViewFileOpened = FALSE;
}
if( pSFileClient)
{
pSFileClient->Release();
}
return( bOk);
}
+190
View File
@@ -1656,6 +1656,196 @@
RCODE FLMAPI FlmAllocMultiFileHdl(
IF_MultiFileHdl ** ppFileHdl);
/****************************************************************************
Desc:
****************************************************************************/
typedef struct
{
IF_FileHdl * pFileHdl;
FLMUINT uiFileNumber;
FLMBOOL bDirty;
} CHECKED_OUT_FILE_HDL;
/****************************************************************************
Desc:
****************************************************************************/
flminterface FLMEXP IF_SuperFileClient : public F_Object
{
virtual FLMUINT FLMAPI getFileNumber(
FLMUINT uiBlockAddr) = 0;
virtual FLMUINT FLMAPI getFileOffset(
FLMUINT uiBlockAddr) = 0;
virtual RCODE FLMAPI getFilePath(
FLMUINT uiFileNumber,
char * pszPath) = 0;
};
/****************************************************************************
Desc:
****************************************************************************/
class F_SuperFileHdl : public F_Object
{
public:
F_SuperFileHdl();
virtual ~F_SuperFileHdl();
RCODE setup(
IF_SuperFileClient * pSuperFileClient);
RCODE createFile(
FLMUINT uiFileNumber);
RCODE readBlock(
FLMUINT uiBlkAddress,
FLMUINT uiBytesToRead,
void * pvBuffer,
FLMUINT * puiBytesRead);
RCODE writeBlock(
FLMUINT uiBlkAddress,
FLMUINT uiBytesToWrite,
const void * pvBuffer,
IF_IOBuffer * pIOBuffer,
FLMUINT * puiBytesWritten);
RCODE readHeader(
FLMUINT uiOffset,
FLMUINT uiBytesToRead,
void * pvBuffer,
FLMUINT * puiBytesRead);
RCODE writeHeader(
FLMUINT uiOffset,
FLMUINT uiBytesToWrite,
const void * pvBuffer,
FLMUINT * puiBytesWritten);
RCODE getFilePath(
FLMUINT uiFileNumber,
char * pszPath);
RCODE getFileHdl(
FLMUINT uiFileNumber,
FLMBOOL bGetForUpdate,
IF_FileHdl ** ppFileHdlRV);
RCODE getFileSize(
FLMUINT uiFileNumber,
FLMUINT64 * pui64FileSize);
RCODE releaseFile(
FLMUINT uiFileNum,
FLMBOOL bCloseFile);
RCODE releaseFiles(
FLMBOOL bCloseFiles);
RCODE truncateFile(
FLMUINT uiEOFBlkAddress);
void truncateFiles(
FLMUINT uiStartFileNum,
FLMUINT uiEndFileNum);
RCODE releaseFile(
CHECKED_OUT_FILE_HDL * pChkFileHdl,
FLMBOOL bCloseFile);
FINLINE void enableFlushMinimize( void)
{
m_bMinimizeFlushes = TRUE;
}
void disableFlushMinimize( void);
RCODE flush( void);
FINLINE void setBlockSize(
FLMUINT uiBlockSize)
{
m_uiBlockSize = uiBlockSize;
}
FINLINE void setExtendSize(
FLMUINT uiExtendSize)
{
m_uiExtendSize = uiExtendSize;
}
FINLINE void setMaxAutoExtendSize(
FLMUINT uiMaxAutoExtendSize)
{
m_uiMaxAutoExtendSize = uiMaxAutoExtendSize;
}
FINLINE FLMBOOL canDoAsync( void)
{
if( m_pCheckedOutFileHdls[ 0].pFileHdl)
{
return( m_pCheckedOutFileHdls[ 0].pFileHdl->canDoAsync());
}
else
{
IF_FileHdl * pFileHdl;
if( RC_OK( getFileHdl( 0, FALSE, &pFileHdl)))
{
return( pFileHdl->canDoAsync());
}
}
return( FALSE);
}
private:
FINLINE CHECKED_OUT_FILE_HDL * getCkoFileHdlPtr(
FLMUINT uiFileNum,
FLMUINT * puiSlot)
{
*puiSlot = (uiFileNum
? (uiFileNum % (m_uiCkoArraySize - 1)) + 1
: 0);
return( &m_pCheckedOutFileHdls[ *puiSlot]);
}
FINLINE void clearCkoFileHdl(
CHECKED_OUT_FILE_HDL * pCkoFileHdl)
{
pCkoFileHdl->pFileHdl = NULL;
pCkoFileHdl->uiFileNumber = 0;
pCkoFileHdl->bDirty = FALSE;
}
void copyCkoFileHdls(
CHECKED_OUT_FILE_HDL * pSrcCkoArray,
FLMUINT uiSrcHighestUsedSlot);
RCODE reallocCkoArray(
FLMUINT uiFileNum);
#define MAX_CHECKED_OUT_FILE_HDLS 8
IF_SuperFileClient * m_pSuperFileClient;
CHECKED_OUT_FILE_HDL m_CheckedOutFileHdls[ MAX_CHECKED_OUT_FILE_HDLS + 1];
CHECKED_OUT_FILE_HDL * m_pCheckedOutFileHdls;
FLMUINT m_uiCkoArraySize;
FLMUINT m_uiBlockSize;
FLMUINT m_uiExtendSize;
FLMUINT m_uiMaxAutoExtendSize;
FLMUINT m_uiLowestDirtySlot;
FLMUINT m_uiHighestDirtySlot;
FLMUINT m_uiHighestUsedSlot;
FLMUINT m_uiHighestFileNumber;
FLMBOOL m_bMinimizeFlushes;
FLMBOOL m_bSetupCalled;
};
/****************************************************************************
Desc:
****************************************************************************/
+74 -240
View File
@@ -1,6 +1,5 @@
//------------------------------------------------------------------------------
// Desc: This include file contains the methods for FLAIM's
// super file class.
// Desc: This include file contains the methods for the super file class.
//
// Tabs: 3
//
@@ -21,30 +20,28 @@
// To contact Novell about this file by physical or electronic mail,
// you may find current contact information at www.novell.com
//
// $Id: fsuperfl.cpp 3114 2006-01-19 13:22:45 -0700 (Thu, 19 Jan 2006) dsanders $
// $Id: $
//------------------------------------------------------------------------------
#include "flaimsys.h"
#include "ftksys.h"
/****************************************************************************
Desc:
****************************************************************************/
F_SuperFileHdl::F_SuperFileHdl( void)
{
m_pszDbFileName = NULL;
m_pszDataFileNameBase = NULL;
m_pSuperFileClient = NULL;
f_memset( &m_CheckedOutFileHdls[ 0], 0, sizeof( m_CheckedOutFileHdls));
m_pCheckedOutFileHdls = &m_CheckedOutFileHdls [0];
m_uiCkoArraySize = MAX_CHECKED_OUT_FILE_HDLS + 1;
m_uiBlockSize = 0;
m_uiExtendSize = XFLM_DEFAULT_FILE_EXTEND_SIZE;
m_uiMaxAutoExtendSize = gv_XFlmSysData.uiMaxFileSize;
m_uiExtendSize = (8 * 1024 * 1024);
m_uiMaxAutoExtendSize = f_getMaxFileSize();
m_uiLowestDirtySlot = 1;
m_uiHighestDirtySlot = 0;
m_uiHighestUsedSlot = 0;
m_uiHighestFileNumber = 0;
m_bMinimizeFlushes = FALSE;
m_bSetupCalled = FALSE;
}
/****************************************************************************
@@ -52,14 +49,11 @@ Desc:
****************************************************************************/
F_SuperFileHdl::~F_SuperFileHdl()
{
if( m_bSetupCalled)
releaseFiles( TRUE);
if( m_pSuperFileClient)
{
(void)releaseFiles( TRUE);
}
if (m_pszDbFileName)
{
f_free( &m_pszDbFileName);
m_pSuperFileClient->Release();
}
}
@@ -67,69 +61,14 @@ F_SuperFileHdl::~F_SuperFileHdl()
Desc: Configures the super file object
****************************************************************************/
RCODE F_SuperFileHdl::setup(
const char * pszDbFileName,
const char * pszDataDir)
IF_SuperFileClient * pSuperFileClient)
{
RCODE rc = NE_XFLM_OK;
FLMUINT uiNameLen;
FLMUINT uiDataNameLen;
char szDir [F_PATH_MAX_SIZE];
char szBaseName [F_FILENAME_SIZE];
flmAssert( !m_bSetupCalled);
if( !pszDbFileName && *pszDbFileName == 0)
{
rc = RC_SET( NE_FLM_IO_INVALID_FILENAME);
goto Exit;
}
uiNameLen = f_strlen( pszDbFileName);
if (pszDataDir && *pszDataDir)
{
if (RC_BAD( rc = gv_XFlmSysData.pFileSystem->pathReduce(
pszDbFileName, szDir, szBaseName)))
{
goto Exit;
}
f_strcpy( szDir, pszDataDir);
if (RC_BAD( rc = gv_XFlmSysData.pFileSystem->pathAppend(
szDir, szBaseName)))
{
goto Exit;
}
uiDataNameLen = f_strlen( szDir);
if (RC_BAD( rc = f_alloc( (uiNameLen + 1) + (uiDataNameLen + 1),
&m_pszDbFileName)))
{
goto Exit;
}
f_memcpy( m_pszDbFileName, pszDbFileName, uiNameLen + 1);
m_pszDataFileNameBase = m_pszDbFileName + uiNameLen + 1;
flmGetDbBasePath( m_pszDataFileNameBase, szDir, &m_uiDataExtOffset);
m_uiExtOffset = uiNameLen - (uiDataNameLen - m_uiDataExtOffset);
}
else
{
if (RC_BAD( rc = f_alloc( (uiNameLen + 1) * 2, &m_pszDbFileName)))
{
goto Exit;
}
f_memcpy( m_pszDbFileName, pszDbFileName, uiNameLen + 1);
m_pszDataFileNameBase = m_pszDbFileName + uiNameLen + 1;
flmGetDbBasePath( m_pszDataFileNameBase,
m_pszDbFileName, &m_uiDataExtOffset);
m_uiExtOffset = m_uiDataExtOffset;
}
m_bSetupCalled = TRUE;
Exit:
return( rc);
f_assert( !m_pSuperFileClient);
m_pSuperFileClient = pSuperFileClient;
m_pSuperFileClient->AddRef();
return( NE_FLM_OK);
}
/****************************************************************************
@@ -138,15 +77,13 @@ Desc: Creates a file
RCODE F_SuperFileHdl::createFile(
FLMUINT uiFileNumber)
{
RCODE rc = NE_XFLM_OK;
RCODE rc = NE_FLM_OK;
char szFilePath[ F_PATH_MAX_SIZE];
IF_FileHdl * pFileHdl = NULL;
// FLMUINT uiFileId;
// Sanity checks
flmAssert( m_bSetupCalled && m_uiBlockSize);
flmAssert( uiFileNumber <= MAX_LOG_BLOCK_FILE_NUMBER);
flmAssert( m_uiBlockSize);
// See if we already have an open file handle (or if we can open the file).
// If so, truncate the file and use it.
@@ -164,12 +101,12 @@ RCODE F_SuperFileHdl::createFile(
// Build the file path
if( RC_BAD( rc = getFilePath( uiFileNumber, szFilePath)))
if( RC_BAD( rc = m_pSuperFileClient->getFilePath( uiFileNumber, szFilePath)))
{
goto Exit;
}
if( RC_BAD( rc = gv_XFlmSysData.pFileSystem->createFile( szFilePath,
if( RC_BAD( rc = f_getFileSysPtr()->createFile( szFilePath,
FLM_IO_RDWR | FLM_IO_EXCL | FLM_IO_DIRECT | FLM_IO_SH_DENYNONE,
&pFileHdl)))
{
@@ -195,24 +132,24 @@ RCODE F_SuperFileHdl::readBlock(
void * pvBuffer,
FLMUINT * puiBytesRead)
{
RCODE rc = NE_FLM_OK;
IF_FileHdl * pFileHdl = NULL;
RCODE rc = NE_XFLM_OK;
flmAssert( m_bSetupCalled && m_uiBlockSize);
flmAssert( m_uiBlockSize);
if( RC_BAD( rc = getFileHdl(
FSGetFileNumber( uiBlkAddress), FALSE, &pFileHdl)))
m_pSuperFileClient->getFileNumber( uiBlkAddress), FALSE, &pFileHdl)))
{
goto Exit;
}
if( RC_BAD( rc = pFileHdl->sectorRead(
FSGetFileOffset( uiBlkAddress), uiBytesToRead,
m_pSuperFileClient->getFileOffset( uiBlkAddress), uiBytesToRead,
pvBuffer, puiBytesRead)))
{
if (rc != NE_FLM_IO_END_OF_FILE && rc != NE_XFLM_MEM)
if (rc != NE_FLM_IO_END_OF_FILE && rc != NE_FLM_MEM)
{
releaseFile( FSGetFileNumber( uiBlkAddress), TRUE);
releaseFile( m_pSuperFileClient->getFileNumber( uiBlkAddress), TRUE);
}
goto Exit;
}
@@ -232,18 +169,20 @@ RCODE F_SuperFileHdl::writeBlock(
IF_IOBuffer * pIOBuffer,
FLMUINT * puiBytesWritten)
{
RCODE rc = NE_FLM_OK;
IF_FileHdl * pFileHdl = NULL;
RCODE rc = NE_XFLM_OK;
flmAssert( m_bSetupCalled && m_uiBlockSize);
flmAssert( m_uiBlockSize);
Get_Handle:
if( RC_BAD( rc = getFileHdl(
FSGetFileNumber( uiBlkAddress), TRUE, &pFileHdl)))
m_pSuperFileClient->getFileNumber(uiBlkAddress), TRUE, &pFileHdl)))
{
if (rc == NE_FLM_IO_PATH_NOT_FOUND)
{
if (RC_BAD( rc = createFile( FSGetFileNumber( uiBlkAddress))))
if (RC_BAD( rc = createFile( m_pSuperFileClient->getFileNumber(
uiBlkAddress))))
{
goto Exit;
}
@@ -258,12 +197,12 @@ Get_Handle:
pFileHdl->setExtendSize( m_uiExtendSize);
pFileHdl->setMaxAutoExtendSize( m_uiMaxAutoExtendSize);
if( RC_BAD( rc = pFileHdl->sectorWrite(
FSGetFileOffset( uiBlkAddress), uiBytesToWrite,
m_pSuperFileClient->getFileOffset( uiBlkAddress), uiBytesToWrite,
pvBuffer, pIOBuffer, puiBytesWritten)))
{
if (rc != NE_FLM_IO_DISK_FULL && rc != NE_XFLM_MEM)
if (rc != NE_FLM_IO_DISK_FULL && rc != NE_FLM_MEM)
{
releaseFile( FSGetFileNumber( uiBlkAddress), TRUE);
releaseFile( m_pSuperFileClient->getFileNumber( uiBlkAddress), TRUE);
}
goto Exit;
}
@@ -282,7 +221,7 @@ RCODE F_SuperFileHdl::readHeader(
void * pvBuffer,
FLMUINT * puiBytesRead)
{
RCODE rc = NE_XFLM_OK;
RCODE rc = NE_FLM_OK;
IF_FileHdl * pFileHdl;
#ifdef FLM_DEBUG
@@ -304,7 +243,7 @@ RCODE F_SuperFileHdl::readHeader(
if( RC_BAD( rc = pFileHdl->read( uiOffset,
uiBytesToRead, pvBuffer, puiBytesRead)))
{
if (rc != NE_FLM_IO_END_OF_FILE && rc != NE_XFLM_MEM)
if (rc != NE_FLM_IO_END_OF_FILE && rc != NE_FLM_MEM)
{
releaseFile( (FLMUINT)0, TRUE);
}
@@ -325,7 +264,7 @@ RCODE F_SuperFileHdl::writeHeader(
const void * pvBuffer,
FLMUINT * puiBytesWritten)
{
RCODE rc = NE_XFLM_OK;
RCODE rc = NE_FLM_OK;
IF_FileHdl * pFileHdl;
#ifdef FLM_DEBUG
@@ -343,7 +282,7 @@ RCODE F_SuperFileHdl::writeHeader(
if( RC_BAD( rc = pFileHdl->write( uiOffset,
uiBytesToWrite, pvBuffer, puiBytesWritten)))
{
if (rc != NE_FLM_IO_DISK_FULL && rc != NE_XFLM_MEM)
if (rc != NE_FLM_IO_DISK_FULL && rc != NE_FLM_MEM)
{
releaseFile( (FLMUINT)0, TRUE);
}
@@ -362,7 +301,7 @@ RCODE F_SuperFileHdl::releaseFile(
FLMUINT uiFileNum,
FLMBOOL bCloseFile)
{
RCODE rc = NE_XFLM_OK;
RCODE rc = NE_FLM_OK;
CHECKED_OUT_FILE_HDL * pCkoFileHdl;
FLMUINT uiSlot;
@@ -386,11 +325,9 @@ Desc: Releases all file handle objects and optionally closes the files
RCODE F_SuperFileHdl::releaseFiles(
FLMBOOL bCloseFiles)
{
RCODE rc = NE_XFLM_OK;
RCODE rc = NE_FLM_OK;
FLMUINT uiLoop;
flmAssert( m_bSetupCalled);
for( uiLoop = 0; uiLoop <= m_uiHighestUsedSlot; uiLoop++)
{
if( RC_BAD( rc = releaseFile(
@@ -412,13 +349,11 @@ RCODE F_SuperFileHdl::releaseFile(
CHECKED_OUT_FILE_HDL * pCkoFileHdl,
FLMBOOL bCloseFile)
{
RCODE rc = NE_XFLM_OK;
RCODE rc = NE_FLM_OK;
IF_FileHdl * pFileHdl = pCkoFileHdl->pFileHdl;
if( pFileHdl)
{
// flmAssert( pFileHdl->getFileId());
if( pCkoFileHdl->bDirty)
{
(void)pFileHdl->flush();
@@ -443,8 +378,7 @@ Desc: Copy one CKO array into another.
****************************************************************************/
void F_SuperFileHdl::copyCkoFileHdls(
CHECKED_OUT_FILE_HDL * pSrcCkoArray,
FLMUINT uiSrcHighestUsedSlot
)
FLMUINT uiSrcHighestUsedSlot)
{
FLMUINT uiNewSlot;
FLMUINT uiSrcSlot;
@@ -462,6 +396,7 @@ void F_SuperFileHdl::copyCkoFileHdls(
m_uiHighestUsedSlot = 0;
m_uiLowestDirtySlot = 1;
m_uiHighestDirtySlot = 0;
for (uiSrcSlot = 1, pSrcCkoArray++;
uiSrcSlot <= uiSrcHighestUsedSlot;
uiSrcSlot++, pSrcCkoArray++)
@@ -481,20 +416,22 @@ void F_SuperFileHdl::copyCkoFileHdls(
{
releaseFile( &m_pCheckedOutFileHdls [uiNewSlot], FALSE);
}
f_memcpy( &m_pCheckedOutFileHdls [uiNewSlot], pSrcCkoArray,
sizeof( CHECKED_OUT_FILE_HDL));
if (uiNewSlot > m_uiHighestUsedSlot)
{
m_uiHighestUsedSlot = uiNewSlot;
}
if (m_uiHighestFileNumber < pSrcCkoArray->uiFileNumber)
{
m_uiHighestFileNumber = pSrcCkoArray->uiFileNumber;
}
if (pSrcCkoArray->bDirty)
{
if (m_uiLowestDirtySlot > m_uiHighestDirtySlot)
{
m_uiLowestDirtySlot =
m_uiHighestDirtySlot = uiNewSlot;
@@ -526,7 +463,7 @@ void F_SuperFileHdl::disableFlushMinimize( void)
// Copy the allocated array back into the fixed array.
// This doesn't necessarily copy all of the file handles.
if (m_pCheckedOutFileHdls != &m_CheckedOutFileHdls [0])
if( m_pCheckedOutFileHdls != &m_CheckedOutFileHdls [0])
{
CHECKED_OUT_FILE_HDL * pOldCkoArray = m_pCheckedOutFileHdls;
FLMUINT uiOldHighestUsedSlot = m_uiHighestUsedSlot;
@@ -537,6 +474,7 @@ void F_SuperFileHdl::disableFlushMinimize( void)
f_free( &pOldCkoArray);
}
m_bMinimizeFlushes = FALSE;
}
@@ -545,12 +483,12 @@ Desc: Flush dirty files to disk.
****************************************************************************/
RCODE F_SuperFileHdl::flush( void)
{
RCODE rc = NE_XFLM_OK;
RCODE rc = NE_FLM_OK;
FLMUINT uiLoop;
// Flush all dirty files
for (uiLoop = m_uiLowestDirtySlot;
for( uiLoop = m_uiLowestDirtySlot;
uiLoop <= m_uiHighestDirtySlot;
uiLoop++)
{
@@ -558,17 +496,20 @@ RCODE F_SuperFileHdl::flush( void)
{
RCODE tmpRc;
if (RC_BAD( tmpRc =
if( RC_BAD( tmpRc =
m_pCheckedOutFileHdls[ uiLoop].pFileHdl->flush()))
{
rc = tmpRc;
releaseFile( &m_pCheckedOutFileHdls [uiLoop], TRUE);
}
m_pCheckedOutFileHdls[ uiLoop].bDirty = FALSE;
}
}
m_uiLowestDirtySlot = 1;
m_uiHighestDirtySlot = 0;
return( rc);
}
@@ -580,9 +521,9 @@ Desc: Truncates back to an end of file block address.
RCODE F_SuperFileHdl::truncateFile(
FLMUINT uiEOFBlkAddress)
{
RCODE rc = NE_XFLM_OK;
FLMUINT uiFileNumber = (FLMUINT)FSGetFileNumber( uiEOFBlkAddress);
FLMUINT uiBlockOffset = (FLMUINT)FSGetFileOffset( uiEOFBlkAddress);
RCODE rc = NE_FLM_OK;
FLMUINT uiFileNumber = m_pSuperFileClient->getFileNumber( uiEOFBlkAddress);
FLMUINT uiBlockOffset = m_pSuperFileClient->getFileOffset( uiEOFBlkAddress);
IF_FileHdl * pFileHdl;
// Truncate the current block file.
@@ -654,11 +595,8 @@ RCODE F_SuperFileHdl::getFileSize(
FLMUINT uiFileNumber,
FLMUINT64 * pui64FileSize)
{
RCODE rc = NE_FLM_OK;
IF_FileHdl * pFileHdl = NULL;
RCODE rc = NE_XFLM_OK;
flmAssert( m_bSetupCalled);
flmAssert( pui64FileSize);
*pui64FileSize = 0;
@@ -687,47 +625,16 @@ RCODE F_SuperFileHdl::getFilePath(
FLMUINT uiFileNumber,
char * pszIoPath)
{
RCODE rc = NE_XFLM_OK;
FLMUINT uiExtOffset;
// Sanity checks
flmAssert( m_bSetupCalled);
if (!uiFileNumber)
{
f_strcpy( pszIoPath, m_pszDbFileName);
goto Exit;
}
if( uiFileNumber <= MAX_DATA_BLOCK_FILE_NUMBER)
{
f_memcpy( pszIoPath, m_pszDataFileNameBase, m_uiDataExtOffset);
uiExtOffset = m_uiDataExtOffset;
}
else
{
f_memcpy( pszIoPath, m_pszDbFileName, m_uiExtOffset);
uiExtOffset = m_uiExtOffset;
}
// Modify the file's extension.
bldSuperFileExtension( uiFileNumber, &pszIoPath[ uiExtOffset]);
Exit:
return( rc);
return( m_pSuperFileClient->getFilePath( uiFileNumber, pszIoPath));
}
/****************************************************************************
Desc: Reallocates the checked out file handle array.
****************************************************************************/
RCODE F_SuperFileHdl::reallocCkoArray(
FLMUINT uiFileNum
)
FLMUINT uiFileNum)
{
RCODE rc = NE_XFLM_OK;
RCODE rc = NE_FLM_OK;
FLMUINT uiNewSize;
CHECKED_OUT_FILE_HDL * pNewCkoArray;
CHECKED_OUT_FILE_HDL * pOldCkoArray;
@@ -737,21 +644,10 @@ RCODE F_SuperFileHdl::reallocCkoArray(
{
uiFileNum = m_uiHighestFileNumber;
}
uiNewSize = uiFileNum + 128;
// Reallocate so we can guarantee that all of the current file
// numbers will copy and there is room for this new one as well.
if (uiNewSize > MAX_LOG_BLOCK_FILE_NUMBER + 1)
{
flmAssert( uiFileNum <= MAX_LOG_BLOCK_FILE_NUMBER);
uiNewSize = MAX_LOG_BLOCK_FILE_NUMBER + 1;
}
// No need to call f_calloc, because copyCkoFileHdls will initialize
// it below.
if (RC_BAD( rc = f_alloc( sizeof( CHECKED_OUT_FILE_HDL) * uiNewSize,
if (RC_BAD( rc = f_calloc( sizeof( CHECKED_OUT_FILE_HDL) * uiNewSize,
&pNewCkoArray)))
{
goto Exit;
@@ -775,18 +671,17 @@ RCODE F_SuperFileHdl::reallocCkoArray(
Exit:
return( rc);
}
/****************************************************************************
Desc: Returns a file handle given the file's number
****************************************************************************/
RCODE F_SuperFileHdl::getFileHdl(
FLMUINT uiFileNum,
FLMBOOL bGetForUpdate,
IF_FileHdl ** ppFileHdl)
FLMUINT uiFileNum,
FLMBOOL bGetForUpdate,
IF_FileHdl ** ppFileHdl)
{
RCODE rc = NE_XFLM_OK;
RCODE rc = NE_FLM_OK;
IF_FileHdl * pFileHdl = NULL;
CHECKED_OUT_FILE_HDL * pCkoFileHdl;
char szFilePath[ F_PATH_MAX_SIZE];
@@ -796,7 +691,7 @@ RCODE F_SuperFileHdl::getFileHdl(
if( pCkoFileHdl->uiFileNumber != uiFileNum &&
pCkoFileHdl->pFileHdl)
{
if (pCkoFileHdl->bDirty && m_bMinimizeFlushes)
if( pCkoFileHdl->bDirty && m_bMinimizeFlushes)
{
flmAssert( pCkoFileHdl->uiFileNumber);
if (RC_BAD( reallocCkoArray( uiFileNum)))
@@ -826,14 +721,15 @@ RCODE F_SuperFileHdl::getFileHdl(
{
// Build the file path
if( RC_BAD( rc = getFilePath( uiFileNum, szFilePath)))
if( RC_BAD( rc = m_pSuperFileClient->getFilePath(
uiFileNum, szFilePath)))
{
goto Exit;
}
// Open the file
if( RC_BAD( rc = gv_XFlmSysData.pFileSystem->openFile( szFilePath,
if( RC_BAD( rc = f_getFileSysPtr()->openFile( szFilePath,
FLM_IO_RDWR | FLM_IO_SH_DENYNONE | FLM_IO_DIRECT,
&pFileHdl)))
{
@@ -850,6 +746,7 @@ RCODE F_SuperFileHdl::getFileHdl(
{
m_uiHighestUsedSlot = uiSlot;
}
if (m_uiHighestFileNumber < uiFileNum)
{
m_uiHighestFileNumber = uiFileNum;
@@ -885,66 +782,3 @@ Exit:
return( rc);
}
/****************************************************************************
Desc: Generates a file name given a super file number.
Adds ".xx" to pFileExtension. Use lower case characters.
Notes: This is a base 24 alphanumeric value where
{ a, b, c, d, e, f, i, l, o, r, u, v } values are removed.
****************************************************************************/
void bldSuperFileExtension(
FLMUINT uiFileNum,
char * pszFileExtension)
{
char ucLetter;
if (uiFileNum <= MAX_DATA_BLOCK_FILE_NUMBER - 1536)
{
// No additional letter - File numbers 1 to 511
// This is just like pre-4.3 numbering.
ucLetter = 0;
}
else if (uiFileNum <= MAX_DATA_BLOCK_FILE_NUMBER - 1024)
{
// File numbers 512 to 1023
ucLetter = 'r';
}
else if (uiFileNum <= MAX_DATA_BLOCK_FILE_NUMBER - 512)
{
// File numbers 1024 to 1535
ucLetter = 's';
}
else if (uiFileNum <= MAX_DATA_BLOCK_FILE_NUMBER)
{
// File numbers 1536 to 2047
ucLetter = 't';
}
else if (uiFileNum <= MAX_LOG_BLOCK_FILE_NUMBER - 1536)
{
// File numbers 2048 to 2559
ucLetter = 'v';
}
else if (uiFileNum <= MAX_LOG_BLOCK_FILE_NUMBER - 1024)
{
// File numbers 2560 to 3071
ucLetter = 'w';
}
else if (uiFileNum <= MAX_LOG_BLOCK_FILE_NUMBER - 512)
{
// File numbers 3072 to 3583
ucLetter = 'x';
}
else
{
flmAssert( uiFileNum <= MAX_LOG_BLOCK_FILE_NUMBER);
// File numbers 3584 to 4095
ucLetter = 'z';
}
*pszFileExtension++ = '.';
*pszFileExtension++ = (char)(f_getBase24DigitChar( (FLMBYTE)((uiFileNum & 511) / 24)));
*pszFileExtension++ = (char)(f_getBase24DigitChar( (FLMBYTE)((uiFileNum & 511) % 24)));
*pszFileExtension++ = ucLetter;
*pszFileExtension = 0;
}
+14 -2
View File
@@ -153,6 +153,8 @@ RCODE F_DbSystem::copyDb(
DB_COPY_INFO DbCopyInfo;
F_SuperFileHdl SrcSFileHdl;
F_SuperFileHdl DestSFileHdl;
F_SuperFileClient SrcSFileClient;
F_SuperFileClient DestSFileClient;
FLMUINT uiFileNumber;
FLMUINT uiHighFileNumber;
FLMUINT uiHighLogFileNumber;
@@ -208,8 +210,13 @@ RCODE F_DbSystem::copyDb(
// Set up the super file object for the source database.
// Must at least open the control file.
if( RC_BAD( rc = SrcSFileClient.setup( pszSrcDbName, pszSrcDataDir)))
{
goto Exit;
}
if (RC_BAD( rc = SrcSFileHdl.setup( pszSrcDbName, pszSrcDataDir)))
if (RC_BAD( rc = SrcSFileHdl.setup( &SrcSFileClient)))
{
goto Exit;
}
@@ -315,8 +322,13 @@ retry:
}
// Set up the super file object for the destination database.
if( RC_BAD( rc = DestSFileClient.setup( pszDestDbName, pszDestDataDir)))
{
goto Exit;
}
if (RC_BAD( rc = DestSFileHdl.setup( pszDestDbName, pszDestDataDir)))
if (RC_BAD( rc = DestSFileHdl.setup( &DestSFileClient)))
{
goto Exit;
}
+2 -2
View File
@@ -151,7 +151,7 @@ RCODE F_DbSystem::dbRemove(
uiFileNumber = 1;
for (;;)
{
bldSuperFileExtension( uiFileNumber, pszDataExt);
F_SuperFileClient::bldSuperFileExtension( uiFileNumber, pszDataExt);
if (RC_BAD( rc = gv_XFlmSysData.pFileSystem->deleteFile( pszDataName)))
{
@@ -177,7 +177,7 @@ RCODE F_DbSystem::dbRemove(
uiFileNumber = FIRST_LOG_BLOCK_FILE_NUMBER;
for (;;)
{
bldSuperFileExtension( uiFileNumber, pszExt);
F_SuperFileClient::bldSuperFileExtension( uiFileNumber, pszExt);
if (RC_BAD( rc = gv_XFlmSysData.pFileSystem->deleteFile( pszTmpName)))
{
+4 -4
View File
@@ -230,8 +230,8 @@ RCODE F_DbSystem::dbRename(
uiFileNumber = 1;
for (;;)
{
bldSuperFileExtension( uiFileNumber, pszDataExtOld);
bldSuperFileExtension( uiFileNumber, pszDataExtNew);
F_SuperFileClient::bldSuperFileExtension( uiFileNumber, pszDataExtOld);
F_SuperFileClient::bldSuperFileExtension( uiFileNumber, pszDataExtNew);
if (RC_BAD( rc = flmRenameFile( pszOldDataName, pszNewDataName,
bOverwriteDestOk, TRUE,
@@ -256,8 +256,8 @@ RCODE F_DbSystem::dbRename(
uiFileNumber = FIRST_LOG_BLOCK_FILE_NUMBER;
for (;;)
{
bldSuperFileExtension( uiFileNumber, pszExtOld);
bldSuperFileExtension( uiFileNumber, pszExtNew);
F_SuperFileClient::bldSuperFileExtension( uiFileNumber, pszExtOld);
F_SuperFileClient::bldSuperFileExtension( uiFileNumber, pszExtNew);
if (RC_BAD( rc = flmRenameFile( pszOldName, pszNewName,
bOverwriteDestOk, TRUE,
+37 -1
View File
@@ -100,7 +100,6 @@ class F_RebuildNodeIStream;
#include "f_btree.h"
#include "f_btpool.h"
#include "rfl.h"
#include "fsuperfl.h"
#include "filesys.h"
#include "flog.h"
#include "f_nici.h"
@@ -8450,4 +8449,41 @@ FINLINE RCODE F_NodeCacheMgr::makeWriteCopy(
return( NE_XFLM_OK);
}
/****************************************************************************
Desc:
*****************************************************************************/
class FLMEXP F_SuperFileClient : public IF_SuperFileClient
{
public:
F_SuperFileClient();
virtual ~F_SuperFileClient();
RCODE setup(
const char * pszCFileName,
const char * pszDataDir);
FLMUINT FLMAPI getFileNumber(
FLMUINT uiBlockAddr);
FLMUINT FLMAPI getFileOffset(
FLMUINT uiBlockAddr);
RCODE FLMAPI getFilePath(
FLMUINT uiFileNumber,
char * pszPath);
static void bldSuperFileExtension(
FLMUINT uiFileNum,
char * pszFileExtension);
private:
char * m_pszCFileName;
char * m_pszDataFileBaseName;
FLMUINT m_uiExtOffset;
FLMUINT m_uiDataExtOffset;
};
#endif // FLAIMSYS_H
+22 -16
View File
@@ -974,21 +974,22 @@ RCODE F_DbSystem::dbRestore(
// [IN] Object for reporting the status of the restore
// operation
{
IF_FileHdl * pFileHdl = NULL;
IF_FileHdl * pLockFileHdl = NULL;
F_SuperFileHdl * pSFile = NULL;
FLMBYTE szBasePath[ F_PATH_MAX_SIZE];
char szTmpPath[ F_PATH_MAX_SIZE];
FLMUINT uiDbVersion;
FLMUINT uiNextIncNum;
eRestoreAction eAction = XFLM_RESTORE_ACTION_CONTINUE; // default action...
FLMBOOL bRflPreserved;
FLMBOOL bMutexLocked = FALSE;
IF_Db * pDb = NULL;
F_Database * pDatabase = NULL;
F_FSRestore * pFSRestoreObj = NULL;
FLMBOOL bOKToRetry;
RCODE rc = NE_XFLM_OK;
RCODE rc = NE_XFLM_OK;
IF_FileHdl * pFileHdl = NULL;
IF_FileHdl * pLockFileHdl = NULL;
F_SuperFileHdl * pSFile = NULL;
F_SuperFileClient SFileClient;
FLMBYTE szBasePath[ F_PATH_MAX_SIZE];
char szTmpPath[ F_PATH_MAX_SIZE];
FLMUINT uiDbVersion;
FLMUINT uiNextIncNum;
eRestoreAction eAction = XFLM_RESTORE_ACTION_CONTINUE; // default action...
FLMBOOL bRflPreserved;
FLMBOOL bMutexLocked = FALSE;
IF_Db * pDb = NULL;
F_Database * pDatabase = NULL;
F_FSRestore * pFSRestoreObj = NULL;
FLMBOOL bOKToRetry;
// Set up the callback
@@ -1088,8 +1089,13 @@ RCODE F_DbSystem::dbRestore(
rc = RC_SET( NE_XFLM_MEM);
goto Exit;
}
if( RC_BAD( rc = SFileClient.setup( pszDbPath, pszDataDir)))
{
goto Exit;
}
if( RC_BAD( rc = pSFile->setup( pszDbPath, pszDataDir)))
if( RC_BAD( rc = pSFile->setup( &SFileClient)))
{
goto Exit;
}
+7 -1
View File
@@ -347,6 +347,7 @@ RCODE F_DbRebuild::dbRebuild(
F_SEM hWaitSem = F_SEM_NULL;
FLMUINT uiRflToken = 0;
F_CCS * pWrappingKey = NULL;
F_SuperFileClient SFileClient;
if( RC_BAD( rc = f_semCreate( &hWaitSem)))
{
@@ -480,7 +481,12 @@ Retry:
goto Exit;
}
if( RC_BAD( rc = m_pSFileHdl->setup( pszSourceDbPath, pszSourceDataDir)))
if( RC_BAD( rc = SFileClient.setup( pszSourceDbPath, pszSourceDataDir)))
{
goto Exit;
}
if( RC_BAD( rc = m_pSFileHdl->setup( &SFileClient)))
{
goto Exit;
}
+23 -6
View File
@@ -1619,10 +1619,11 @@ Desc: This routine begins a thread that will do checkpoints for the
*****************************************************************************/
RCODE F_Database::startCPThread( void)
{
RCODE rc = NE_XFLM_OK;
CP_INFO * pCPInfo = NULL;
char szThreadName[ F_PATH_MAX_SIZE];
char szBaseName[ 32];
RCODE rc = NE_XFLM_OK;
CP_INFO * pCPInfo = NULL;
char szThreadName[ F_PATH_MAX_SIZE];
char szBaseName[ 32];
F_SuperFileClient * pSFileClient = NULL;
// Allocate a CP_INFO structure that will be passed into the
// thread when it is created.
@@ -1642,15 +1643,26 @@ RCODE F_Database::startCPThread( void)
// Allocate a super file handle.
if ((pCPInfo->pSFileHdl = f_new F_SuperFileHdl) == NULL)
if( (pCPInfo->pSFileHdl = f_new F_SuperFileHdl) == NULL)
{
rc = RC_SET( NE_XFLM_MEM);
goto Exit;
}
if( (pSFileClient = f_new F_SuperFileClient) == NULL)
{
rc = RC_SET( NE_XFLM_MEM);
goto Exit;
}
if( RC_BAD( rc = pSFileClient->setup( m_pszDbPath, m_pszDataDir)))
{
goto Exit;
}
// Set up the super file
if (RC_BAD( rc = pCPInfo->pSFileHdl->setup( m_pszDbPath, m_pszDataDir)))
if (RC_BAD( rc = pCPInfo->pSFileHdl->setup( pSFileClient)))
{
goto Exit;
}
@@ -1692,6 +1704,11 @@ Exit:
flmFreeCPInfo( &pCPInfo);
}
if( pSFileClient)
{
pSFileClient->Release();
}
return( rc);
}
-212
View File
@@ -1,212 +0,0 @@
//------------------------------------------------------------------------------
// Desc: This include file contains the class definitions for FLAIM's
// super file class.
//
// Tabs: 3
//
// Copyright (c) 1998-2006 Novell, Inc. All Rights Reserved.
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of version 2 of the GNU General Public
// License as published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, contact Novell, Inc.
//
// To contact Novell about this file by physical or electronic mail,
// you may find current contact information at www.novell.com
//
// $Id: fsuperfl.h 3109 2006-01-19 13:07:07 -0700 (Thu, 19 Jan 2006) dsanders $
//------------------------------------------------------------------------------
#ifndef FSUPERFL_H
#define FSUPERFL_H
#define MAX_CHECKED_OUT_FILE_HDLS 8
void bldSuperFileExtension(
FLMUINT uiFileNum,
char * pszFileExtension);
typedef struct
{
IF_FileHdl * pFileHdl;
FLMUINT uiFileNumber;
FLMBOOL bDirty;
} CHECKED_OUT_FILE_HDL;
/****************************************************************************
Desc: The F_SuperFileHdl object manages the control and block files
associated with a FLAIM Super File. This class also provides
backward compatibility with prior file formats.
Note:
****************************************************************************/
class F_SuperFileHdl : public F_Object
{
public:
F_SuperFileHdl();
~F_SuperFileHdl();
RCODE setup(
const char * pszDbFileName,
const char * pszDataDir);
RCODE createFile(
FLMUINT uiFileNumber);
RCODE readBlock(
FLMUINT uiBlkAddress,
FLMUINT uiBytesToRead,
void * pvBuffer,
FLMUINT * puiBytesRead);
RCODE writeBlock(
FLMUINT uiBlkAddress,
FLMUINT uiBytesToWrite,
const void * pvBuffer,
IF_IOBuffer * pIOBuffer,
FLMUINT * puiBytesWritten);
RCODE readHeader(
FLMUINT uiOffset,
FLMUINT uiBytesToRead,
void * pvBuffer,
FLMUINT * puiBytesRead);
RCODE writeHeader(
FLMUINT uiOffset,
FLMUINT uiBytesToWrite,
const void * pvBuffer,
FLMUINT * puiBytesWritten);
RCODE getFilePath(
FLMUINT uiFileNumber,
char * pszPath);
RCODE getFileHdl(
FLMUINT uiFileNumber,
FLMBOOL bGetForUpdate,
IF_FileHdl ** ppFileHdlRV);
RCODE getFileSize(
FLMUINT uiFileNumber,
FLMUINT64 * pui64FileSize);
RCODE releaseFile(
FLMUINT uiFileNum,
FLMBOOL bCloseFile);
RCODE releaseFiles(
FLMBOOL bCloseFiles);
RCODE truncateFile(
FLMUINT uiEOFBlkAddress);
void truncateFiles(
FLMUINT uiStartFileNum,
FLMUINT uiEndFileNum);
RCODE releaseFile(
CHECKED_OUT_FILE_HDL * pChkFileHdl,
FLMBOOL bCloseFile);
FINLINE void enableFlushMinimize( void)
{
m_bMinimizeFlushes = TRUE;
}
void disableFlushMinimize( void);
RCODE flush( void);
FINLINE void setBlockSize(
FLMUINT uiBlockSize)
{
m_uiBlockSize = uiBlockSize;
}
FINLINE void setExtendSize(
FLMUINT uiExtendSize)
{
m_uiExtendSize = uiExtendSize;
}
FINLINE void setMaxAutoExtendSize(
FLMUINT uiMaxAutoExtendSize)
{
m_uiMaxAutoExtendSize = uiMaxAutoExtendSize;
}
FINLINE FLMBOOL canDoAsync( void)
{
if (m_pCheckedOutFileHdls[ 0].pFileHdl)
{
return( m_pCheckedOutFileHdls[ 0].pFileHdl->canDoAsync());
}
else
{
IF_FileHdl * pFileHdl;
if( RC_OK( getFileHdl( 0, FALSE, &pFileHdl)))
{
return( pFileHdl->canDoAsync());
}
}
return( FALSE);
}
private:
FINLINE CHECKED_OUT_FILE_HDL * getCkoFileHdlPtr(
FLMUINT uiFileNum,
FLMUINT * puiSlot)
{
*puiSlot = (uiFileNum
? (uiFileNum % (m_uiCkoArraySize - 1)) + 1
: 0);
return( &m_pCheckedOutFileHdls[ *puiSlot]);
}
FINLINE void clearCkoFileHdl(
CHECKED_OUT_FILE_HDL * pCkoFileHdl)
{
pCkoFileHdl->pFileHdl = NULL;
pCkoFileHdl->uiFileNumber = 0;
pCkoFileHdl->bDirty = FALSE;
}
void copyCkoFileHdls(
CHECKED_OUT_FILE_HDL * pSrcCkoArray,
FLMUINT uiSrcHighestUsedSlot);
RCODE reallocCkoArray(
FLMUINT uiFileNum);
char * m_pszDbFileName;
char * m_pszDataFileNameBase;
FLMUINT m_uiExtOffset;
FLMUINT m_uiDataExtOffset;
CHECKED_OUT_FILE_HDL m_CheckedOutFileHdls[
MAX_CHECKED_OUT_FILE_HDLS + 1];
CHECKED_OUT_FILE_HDL * m_pCheckedOutFileHdls;
FLMUINT m_uiCkoArraySize;
FLMUINT m_uiBlockSize;
FLMUINT m_uiExtendSize;
FLMUINT m_uiMaxAutoExtendSize;
FLMUINT m_uiLowestDirtySlot;
FLMUINT m_uiHighestDirtySlot;
FLMUINT m_uiHighestUsedSlot;
FLMUINT m_uiHighestFileNumber;
FLMBOOL m_bMinimizeFlushes;
FLMBOOL m_bSetupCalled;
};
#endif // FSUPERFL_H
+227 -9
View File
@@ -748,10 +748,10 @@ Desc: This routine links an FDB structure to an F_Database structure.
locked.
****************************************************************************/
RCODE F_Db::linkToDatabase(
F_Database * pDatabase
)
F_Database * pDatabase)
{
RCODE rc = NE_XFLM_OK;
RCODE rc = NE_XFLM_OK;
F_SuperFileClient * pSFileClient = NULL;
// If the use count on the file used to be zero, unlink it from the
// unused list.
@@ -773,22 +773,31 @@ RCODE F_Db::linkToDatabase(
// Allocate the super file object
if (!m_pSFileHdl)
if( !m_pSFileHdl)
{
if ((m_pSFileHdl = f_new F_SuperFileHdl) == NULL)
if( (m_pSFileHdl = f_new F_SuperFileHdl) == NULL)
{
rc = RC_SET( NE_XFLM_MEM);
goto Exit;
}
// Set up the super file
if( RC_BAD( rc = m_pSFileHdl->setup(
if( (pSFileClient = f_new F_SuperFileClient) == NULL)
{
rc = RC_SET( NE_XFLM_MEM);
goto Exit;
}
if( RC_BAD( rc = pSFileClient->setup(
pDatabase->m_pszDbPath, pDatabase->m_pszDataDir)))
{
goto Exit;
}
if( RC_BAD( rc = m_pSFileHdl->setup( pSFileClient)))
{
goto Exit;
}
if( pDatabase->m_lastCommittedDbHdr.ui32DbVersion)
{
m_pSFileHdl->setBlockSize( pDatabase->m_uiBlockSize);
@@ -797,6 +806,11 @@ RCODE F_Db::linkToDatabase(
Exit:
if( pSFileClient)
{
pSFileClient->Release();
}
return( rc);
}
@@ -3957,3 +3971,207 @@ RCODE FLMAPI F_DbSystem::numUCS2Chars(
{
return( f_numUCS2Chars( pszUTF8, puiNumChars));
}
/****************************************************************************
Desc:
****************************************************************************/
F_SuperFileClient::F_SuperFileClient()
{
m_pszCFileName = NULL;
m_pszDataFileBaseName = NULL;
m_uiExtOffset = 0;
m_uiDataExtOffset = 0;
}
/****************************************************************************
Desc:
****************************************************************************/
F_SuperFileClient::~F_SuperFileClient()
{
if( m_pszCFileName)
{
f_free( &m_pszCFileName);
}
}
/****************************************************************************
Desc:
****************************************************************************/
RCODE F_SuperFileClient::setup(
const char * pszCFileName,
const char * pszDataDir)
{
RCODE rc = NE_XFLM_OK;
FLMUINT uiNameLen;
FLMUINT uiDataNameLen;
char szDir[ F_PATH_MAX_SIZE];
char szBaseName[ F_FILENAME_SIZE];
if( !pszCFileName && *pszCFileName == 0)
{
rc = RC_SET( NE_FLM_IO_INVALID_FILENAME);
goto Exit;
}
uiNameLen = f_strlen( pszCFileName);
if (pszDataDir && *pszDataDir)
{
if (RC_BAD( rc = gv_XFlmSysData.pFileSystem->pathReduce(
pszCFileName, szDir, szBaseName)))
{
goto Exit;
}
f_strcpy( szDir, pszDataDir);
if (RC_BAD( rc = gv_XFlmSysData.pFileSystem->pathAppend(
szDir, szBaseName)))
{
goto Exit;
}
uiDataNameLen = f_strlen( szDir);
if (RC_BAD( rc = f_alloc( (uiNameLen + 1) + (uiDataNameLen + 1),
&m_pszCFileName)))
{
goto Exit;
}
f_memcpy( m_pszCFileName, pszCFileName, uiNameLen + 1);
m_pszDataFileBaseName = m_pszCFileName + uiNameLen + 1;
flmGetDbBasePath( m_pszDataFileBaseName, szDir, &m_uiDataExtOffset);
m_uiExtOffset = uiNameLen - (uiDataNameLen - m_uiDataExtOffset);
}
else
{
if (RC_BAD( rc = f_alloc( (uiNameLen + 1) * 2, &m_pszCFileName)))
{
goto Exit;
}
f_memcpy( m_pszCFileName, pszCFileName, uiNameLen + 1);
m_pszDataFileBaseName = m_pszCFileName + uiNameLen + 1;
flmGetDbBasePath( m_pszDataFileBaseName,
m_pszCFileName, &m_uiDataExtOffset);
m_uiExtOffset = m_uiDataExtOffset;
}
Exit:
return( rc);
}
/****************************************************************************
Desc:
****************************************************************************/
FLMUINT FLMAPI F_SuperFileClient::getFileNumber(
FLMUINT uiBlockAddr)
{
return( FSGetFileNumber( uiBlockAddr));
}
/****************************************************************************
Desc:
****************************************************************************/
FLMUINT FLMAPI F_SuperFileClient::getFileOffset(
FLMUINT uiBlockAddr)
{
return( FSGetFileOffset( uiBlockAddr));
}
/****************************************************************************
Desc:
****************************************************************************/
RCODE FLMAPI F_SuperFileClient::getFilePath(
FLMUINT uiFileNumber,
char * pszPath)
{
RCODE rc = NE_XFLM_OK;
FLMUINT uiExtOffset;
if( !uiFileNumber)
{
f_strcpy( pszPath, m_pszCFileName);
goto Exit;
}
if( uiFileNumber <= MAX_DATA_BLOCK_FILE_NUMBER)
{
f_memcpy( pszPath, m_pszDataFileBaseName, m_uiDataExtOffset);
uiExtOffset = m_uiDataExtOffset;
}
else
{
f_memcpy( pszPath, m_pszCFileName, m_uiExtOffset);
uiExtOffset = m_uiExtOffset;
}
// Modify the file's extension.
bldSuperFileExtension( uiFileNumber, &pszPath[ uiExtOffset]);
Exit:
return( rc);
}
/****************************************************************************
Desc: Generates a file name given a super file number.
Adds ".xx" to pFileExtension. Use lower case characters.
Notes: This is a base 24 alphanumeric value where
{ a, b, c, d, e, f, i, l, o, r, u, v } values are removed.
****************************************************************************/
void F_SuperFileClient::bldSuperFileExtension(
FLMUINT uiFileNum,
char * pszFileExtension)
{
char ucLetter;
if (uiFileNum <= MAX_DATA_BLOCK_FILE_NUMBER - 1536)
{
// No additional letter - File numbers 1 to 511
// This is just like pre-4.3 numbering.
ucLetter = 0;
}
else if (uiFileNum <= MAX_DATA_BLOCK_FILE_NUMBER - 1024)
{
// File numbers 512 to 1023
ucLetter = 'r';
}
else if (uiFileNum <= MAX_DATA_BLOCK_FILE_NUMBER - 512)
{
// File numbers 1024 to 1535
ucLetter = 's';
}
else if (uiFileNum <= MAX_DATA_BLOCK_FILE_NUMBER)
{
// File numbers 1536 to 2047
ucLetter = 't';
}
else if (uiFileNum <= MAX_LOG_BLOCK_FILE_NUMBER - 1536)
{
// File numbers 2048 to 2559
ucLetter = 'v';
}
else if (uiFileNum <= MAX_LOG_BLOCK_FILE_NUMBER - 1024)
{
// File numbers 2560 to 3071
ucLetter = 'w';
}
else if (uiFileNum <= MAX_LOG_BLOCK_FILE_NUMBER - 512)
{
// File numbers 3072 to 3583
ucLetter = 'x';
}
else
{
flmAssert( uiFileNum <= MAX_LOG_BLOCK_FILE_NUMBER);
// File numbers 3584 to 4095
ucLetter = 'z';
}
*pszFileExtension++ = '.';
*pszFileExtension++ = (char)(f_getBase24DigitChar( (FLMBYTE)((uiFileNum & 511) / 24)));
*pszFileExtension++ = (char)(f_getBase24DigitChar( (FLMBYTE)((uiFileNum & 511) % 24)));
*pszFileExtension++ = ucLetter;
*pszFileExtension = 0;
}
+1 -1
View File
@@ -1950,7 +1950,7 @@ Exit:
if( pBufferIStream)
{
pBufferIStream->close();
pBufferIStream->Release();
}
return( rc);
+23
View File
@@ -818,6 +818,11 @@ Exit:
{
pCSVFileHdl->Release();
}
if( pFileSystem)
{
pFileSystem->Release();
}
return( rc);
}
@@ -1508,6 +1513,12 @@ RCODE TestBase::importBuffer(
Exit:
if( m_pInputStream)
{
m_pInputStream->Release();
m_pInputStream = NULL;
}
return( rc);
}
@@ -1534,6 +1545,12 @@ RCODE TestBase::importDocument(
Exit:
if( m_pInputStream)
{
m_pInputStream->Release();
m_pInputStream = NULL;
}
return( rc);
}
@@ -1561,6 +1578,12 @@ RCODE TestBase::importFile(
Exit:
if( m_pInputStream)
{
m_pInputStream->Release();
m_pInputStream = NULL;
}
return( rc);
}
+12 -7
View File
@@ -283,6 +283,9 @@ RCODE IMetaphoneTestImpl::suite1( void)
MAKE_FLM_ERROR_STRING( "getNextMetaphone failed.", m_szDetails, rc);
goto Exit;
}
pMetaphoneIStream->Release();
pMetaphoneIStream = NULL;
if ( RC_BAD( rc = m_pDbSystem->openBufferIStream(
commonMisspellings[uiLoop].pszWord2,
@@ -300,6 +303,9 @@ RCODE IMetaphoneTestImpl::suite1( void)
MAKE_FLM_ERROR_STRING( "getNextMetaphone failed.", m_szDetails, rc);
goto Exit;
}
pMetaphoneIStream->Release();
pMetaphoneIStream = NULL;
// No sense in testing the index if the metaphone algorithm itself yields
// different codes for these two words.
@@ -357,22 +363,22 @@ RCODE IMetaphoneTestImpl::suite1( void)
Exit:
if ( RC_BAD( rc))
if( RC_BAD( rc))
{
endTest("FAIL");
}
if ( pMetaphoneIStream)
if( pMetaphoneIStream)
{
pMetaphoneIStream->Release();
}
if ( pSearchKey)
if( pSearchKey)
{
pSearchKey->Release();
}
if ( pFoundKey)
if( pFoundKey)
{
pFoundKey->Release();
}
@@ -387,14 +393,13 @@ Exit:
pChild->Release();
}
if ( bTransStarted)
if( bTransStarted)
{
m_pDb->transCommit();
}
shutdownTestState( DB_NAME_STR, bDibCreated);
return rc;
return( rc);
}
/****************************************************************************