Added support for large field values (up to 4 GB), async and direct I/O on Linux and Solaris, and performed major code cleanup.
git-svn-id: https://svn.code.sf.net/p/flaim/code/trunk@213 0109f412-320b-0410-ab79-c3e0c5ffbbe6
This commit is contained in:
@@ -24,10 +24,323 @@
|
||||
|
||||
#include "flaimsys.h"
|
||||
|
||||
/****************************************************************************
|
||||
Desc: Obtains a a lock on the database.
|
||||
****************************************************************************/
|
||||
FLMEXP RCODE FLMAPI FlmDbLock(
|
||||
HFDB hDb,
|
||||
FLOCK_TYPE eLockType,
|
||||
FLMINT iPriority,
|
||||
FLMUINT uiTimeout)
|
||||
{
|
||||
RCODE rc = FERR_OK;
|
||||
FLMBOOL bIgnore;
|
||||
FDB * pDb = (FDB *)hDb;
|
||||
|
||||
if (IsInCSMode( hDb))
|
||||
{
|
||||
fdbInitCS( pDb);
|
||||
|
||||
CS_CONTEXT * pCSContext = pDb->pCSContext;
|
||||
FCL_WIRE Wire( pCSContext, pDb);
|
||||
|
||||
if( !pCSContext->bConnectionGood)
|
||||
{
|
||||
rc = RC_SET( FERR_BAD_SERVER_CONNECTION);
|
||||
goto Transmission_Error;
|
||||
}
|
||||
|
||||
if( RC_BAD( rc = Wire.sendOp(
|
||||
FCS_OPCLASS_DATABASE, FCS_OP_DATABASE_LOCK)))
|
||||
{
|
||||
goto Exit;
|
||||
}
|
||||
|
||||
if (RC_BAD( rc = Wire.sendNumber( WIRE_VALUE_NUMBER1,
|
||||
(FLMUINT)eLockType)))
|
||||
{
|
||||
goto Transmission_Error;
|
||||
}
|
||||
|
||||
if (RC_BAD( rc = Wire.sendNumber( WIRE_VALUE_SIGNED_NUMBER,
|
||||
0, iPriority)))
|
||||
{
|
||||
goto Transmission_Error;
|
||||
}
|
||||
|
||||
if (RC_BAD( rc = Wire.sendNumber( WIRE_VALUE_FLAGS, uiTimeout)))
|
||||
{
|
||||
goto Transmission_Error;
|
||||
}
|
||||
|
||||
if( RC_BAD( rc = Wire.sendTerminate()))
|
||||
{
|
||||
goto Transmission_Error;
|
||||
}
|
||||
|
||||
// Read the response
|
||||
|
||||
if (RC_BAD( rc = Wire.read()))
|
||||
{
|
||||
goto Transmission_Error;
|
||||
}
|
||||
|
||||
if( RC_BAD( rc = Wire.getRCode()))
|
||||
{
|
||||
goto Exit;
|
||||
}
|
||||
|
||||
goto Exit;
|
||||
|
||||
Transmission_Error:
|
||||
|
||||
pCSContext->bConnectionGood = FALSE;
|
||||
goto Exit;
|
||||
}
|
||||
|
||||
if (RC_BAD( rc = fdbInit( pDb, FLM_NO_TRANS,
|
||||
FDB_TRANS_GOING_OK, 0, &bIgnore)))
|
||||
{
|
||||
goto Exit;
|
||||
}
|
||||
|
||||
// eLockType better be exclusive or shared
|
||||
|
||||
if ((eLockType != FLM_LOCK_EXCLUSIVE) && (eLockType != FLM_LOCK_SHARED))
|
||||
{
|
||||
rc = RC_SET( FERR_ILLEGAL_OP);
|
||||
goto Exit;
|
||||
}
|
||||
|
||||
// Nesting of locks is not allowed - this test also keeps this call from
|
||||
// being executed inside an update transaction that implicitly acquired
|
||||
// the lock.
|
||||
|
||||
if (pDb->uiFlags &
|
||||
(FDB_HAS_FILE_LOCK | FDB_FILE_LOCK_SHARED | FDB_FILE_LOCK_IMPLICIT))
|
||||
{
|
||||
rc = RC_SET( FERR_ILLEGAL_OP);
|
||||
goto Exit;
|
||||
}
|
||||
|
||||
// Attempt to acquire the lock.
|
||||
|
||||
if (RC_BAD( rc = pDb->pFile->pFileLockObj->Lock( TRUE, pDb, FALSE,
|
||||
(FLMBOOL)((eLockType == FLM_LOCK_EXCLUSIVE)
|
||||
? (FLMBOOL)TRUE
|
||||
: (FLMBOOL)FALSE),
|
||||
uiTimeout, iPriority,
|
||||
pDb->pDbStats)))
|
||||
{
|
||||
goto Exit;
|
||||
}
|
||||
|
||||
pDb->uiFlags |= FDB_HAS_FILE_LOCK;
|
||||
|
||||
if (eLockType == FLM_LOCK_SHARED)
|
||||
{
|
||||
pDb->uiFlags |= FDB_FILE_LOCK_SHARED;
|
||||
}
|
||||
|
||||
Exit:
|
||||
|
||||
flmExit( FLM_DB_LOCK, pDb, rc);
|
||||
return( rc);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
Desc: Releases a lock on the database
|
||||
****************************************************************************/
|
||||
FLMEXP RCODE FLMAPI FlmDbUnlock(
|
||||
HFDB hDb)
|
||||
{
|
||||
RCODE rc = FERR_OK;
|
||||
FDB * pDb = (FDB *)hDb;
|
||||
FLMBOOL bIgnore;
|
||||
|
||||
if (IsInCSMode( hDb))
|
||||
{
|
||||
fdbInitCS( pDb);
|
||||
|
||||
CS_CONTEXT * pCSContext = pDb->pCSContext;
|
||||
FCL_WIRE Wire( pCSContext, pDb);
|
||||
|
||||
if( !pCSContext->bConnectionGood)
|
||||
{
|
||||
rc = RC_SET( FERR_BAD_SERVER_CONNECTION);
|
||||
goto Transmission_Error;
|
||||
}
|
||||
|
||||
if( RC_BAD( rc = Wire.sendOp(
|
||||
FCS_OPCLASS_DATABASE, FCS_OP_DATABASE_UNLOCK)))
|
||||
{
|
||||
goto Exit;
|
||||
}
|
||||
|
||||
if( RC_BAD( rc = Wire.sendTerminate()))
|
||||
{
|
||||
goto Transmission_Error;
|
||||
}
|
||||
|
||||
// Read the response
|
||||
|
||||
if (RC_BAD( rc = Wire.read()))
|
||||
{
|
||||
goto Transmission_Error;
|
||||
}
|
||||
|
||||
if( RC_BAD( rc = Wire.getRCode()))
|
||||
{
|
||||
goto Exit;
|
||||
}
|
||||
|
||||
goto Exit;
|
||||
|
||||
Transmission_Error:
|
||||
|
||||
pCSContext->bConnectionGood = FALSE;
|
||||
goto Exit;
|
||||
}
|
||||
|
||||
if (RC_BAD( rc = fdbInit( pDb, FLM_NO_TRANS,
|
||||
FDB_TRANS_GOING_OK | FDB_CLOSING_OK, 0, &bIgnore)))
|
||||
{
|
||||
goto Exit;
|
||||
}
|
||||
|
||||
// If we don't have an explicit lock, can't do the unlock. It is
|
||||
// also illegal to do the unlock during an update transaction.
|
||||
|
||||
if (!(pDb->uiFlags & FDB_HAS_FILE_LOCK) ||
|
||||
(pDb->uiFlags & FDB_FILE_LOCK_IMPLICIT) ||
|
||||
(pDb->uiTransType == FLM_UPDATE_TRANS))
|
||||
{
|
||||
rc = RC_SET( FERR_ILLEGAL_OP);
|
||||
goto Exit;
|
||||
}
|
||||
|
||||
// Unlock the file.
|
||||
|
||||
if (RC_BAD( rc = pDb->pFile->pFileLockObj->Unlock( TRUE, pDb)))
|
||||
{
|
||||
goto Exit;
|
||||
}
|
||||
|
||||
// Unset the flags that indicated the file was explicitly locked.
|
||||
|
||||
pDb->uiFlags &= (~(FDB_HAS_FILE_LOCK | FDB_FILE_LOCK_SHARED));
|
||||
|
||||
Exit:
|
||||
|
||||
if( RC_OK( rc))
|
||||
{
|
||||
rc = flmCheckDatabaseState( pDb);
|
||||
}
|
||||
|
||||
flmExit( FLM_DB_UNLOCK, pDb, rc);
|
||||
return( rc);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
Desc : Returns information about current and pending locks on the
|
||||
database.
|
||||
****************************************************************************/
|
||||
FLMEXP RCODE FLMAPI FlmDbGetLockInfo(
|
||||
HFDB hDb,
|
||||
FLMINT iPriority,
|
||||
FLOCK_INFO * pLockInfo)
|
||||
{
|
||||
RCODE rc = FERR_OK;
|
||||
FDB * pDb = NULL;
|
||||
FLMBOOL bIgnore;
|
||||
|
||||
if (IsInCSMode( hDb))
|
||||
{
|
||||
rc = RC_SET( FERR_NOT_IMPLEMENTED);
|
||||
goto Exit;
|
||||
}
|
||||
|
||||
pDb = (FDB *)hDb;
|
||||
if (RC_BAD( rc = fdbInit( pDb, FLM_NO_TRANS,
|
||||
FDB_TRANS_GOING_OK, 0, &bIgnore)))
|
||||
{
|
||||
goto Exit;
|
||||
}
|
||||
|
||||
pDb->pFile->pFileLockObj->GetLockInfo( iPriority, pLockInfo);
|
||||
|
||||
Exit:
|
||||
|
||||
flmExit( FLM_DB_GET_LOCK_INFO, pDb, rc);
|
||||
return( rc);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
Desc : Returns information about the lock held by the specified database
|
||||
handle.
|
||||
****************************************************************************/
|
||||
FLMEXP RCODE FLMAPI FlmDbGetLockType(
|
||||
HFDB hDb,
|
||||
FLOCK_TYPE * peLockType,
|
||||
FLMBOOL * pbImplicit)
|
||||
{
|
||||
RCODE rc = FERR_OK;
|
||||
FDB * pDb = NULL;
|
||||
FLMBOOL bIgnore;
|
||||
|
||||
if( peLockType)
|
||||
{
|
||||
*peLockType = FLM_LOCK_NONE;
|
||||
}
|
||||
|
||||
if( pbImplicit)
|
||||
{
|
||||
*pbImplicit = FALSE;
|
||||
}
|
||||
|
||||
if (IsInCSMode( hDb))
|
||||
{
|
||||
rc = RC_SET( FERR_NOT_IMPLEMENTED);
|
||||
goto Exit;
|
||||
}
|
||||
|
||||
pDb = (FDB *)hDb;
|
||||
if (RC_BAD( rc = fdbInit( pDb, FLM_NO_TRANS,
|
||||
FDB_TRANS_GOING_OK, 0, &bIgnore)))
|
||||
{
|
||||
goto Exit;
|
||||
}
|
||||
|
||||
if( pDb->uiFlags & FDB_HAS_FILE_LOCK)
|
||||
{
|
||||
if( peLockType)
|
||||
{
|
||||
if( pDb->uiFlags & FDB_FILE_LOCK_SHARED)
|
||||
{
|
||||
*peLockType = FLM_LOCK_SHARED;
|
||||
}
|
||||
else
|
||||
{
|
||||
*peLockType = FLM_LOCK_EXCLUSIVE;
|
||||
}
|
||||
}
|
||||
|
||||
if( pbImplicit)
|
||||
{
|
||||
*pbImplicit = (pDb->uiFlags & FDB_FILE_LOCK_IMPLICIT)
|
||||
? TRUE
|
||||
: FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
Exit:
|
||||
|
||||
flmExit( FLM_DB_GET_LOCK_TYPE, pDb, rc);
|
||||
return( rc);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
Desc: This routine locks a database for exclusive access.
|
||||
Ret: FERR_OK - Indicates that the database was successfully locked.
|
||||
FCERR_LOCK - Error locking database file.
|
||||
****************************************************************************/
|
||||
RCODE dbLock(
|
||||
FDB * pDb,
|
||||
@@ -99,9 +412,6 @@ Exit:
|
||||
/****************************************************************************
|
||||
Desc: This routine unlocks a database that was previously locked
|
||||
using the dbLock routine.
|
||||
Ret: FERR_OK - Indicates that the database was
|
||||
successfully unlocked.
|
||||
FERR_UNLOCK - Error unlocking file.
|
||||
****************************************************************************/
|
||||
RCODE dbUnlock(
|
||||
FDB * pDb)
|
||||
@@ -126,6 +436,5 @@ RCODE dbUnlock(
|
||||
}
|
||||
}
|
||||
|
||||
// Exit:
|
||||
return( rc);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user