Top Description Inners Fields Constructors Methods
org.hsqldb.persist

public Class DataFileCache

extends Object
Class Inheritance
Known Direct Subclasses
org.hsqldb.persist.DataFileCacheSession, org.hsqldb.persist.TextCache
Imports
java.io.IOException, java.util.concurrent.atomic.AtomicInteger, java.util.concurrent.locks.Lock, .ReadWriteLock, .ReentrantReadWriteLock, org.hsqldb.Database, .HsqlException, .Session, org.hsqldb.error.Error, .ErrorCode, org.hsqldb.lib.FileAccess, .FileArchiver, .IntIndex, org.hsqldb.map.BitMap, org.hsqldb.rowio.RowInputBinaryDecode, .RowInputInterface, .RowOutputBinaryEncode, .RowOutputInterface

Acts as a manager for CACHED table persistence.

This contains the top level functionality. Provides file management services and access.

Author
Fred Toussi (fredt@users dot sourceforge.net)
Since
1.7.2
Version
2.5.1

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static interface
pack-priv static interface
DataFileCache.Positions

file format fields

Field Summary

Modifier and TypeField and Description
protected String
protected Cache
protected int
protected boolean
protected boolean
protected Database
protected RandomAccessInterface
protected String
protected int
protected int
protected FileAccess
protected volatile long
protected boolean
fileModified

this flag is used externally to determine if a backup is required

protected long
pack-priv static final int
pack-priv boolean
pack-priv ReadWriteLock
protected boolean
protected long
protected long
protected int
public long
pack-priv Lock
protected RowInputInterface
public RowOutputInterface
private RAShadowFile
public DataSpaceManager
protected long
protected int
pack-priv Lock

Constructor Summary

AccessConstructor and Description
public
DataFileCache(Database db, String baseFileName)

public
DataFileCache(Database db, String baseFileName, boolean defrag)

used for defrag

Method Summary

Modifier and TypeMethod and Description
public void
add(CachedObject object, boolean keep)

public void
adjustStoreCount(int adjust)

public long
public int
protected void
public void
close()

Writes out all cached rows that have been modified and the free position pointer for the *.data file and then closes the file.

protected int
copyShadow(CachedObject[] rows, int offset, int count)

protected int
pack-priv DataFileDefrag
defrag(Session session)

private void
pack-priv void
public long
enlargeFileSpace(long newLength)

Delta must always result in block multiples

public CachedObject
get(CachedObject object, PersistentStore store, boolean keep)

public CachedObject
get(long pos, int size, PersistentStore store, boolean keep)

public CachedObject
get(long pos, PersistentStore store, boolean keep)

public AtomicInteger
public int
public int
public int
public long
public String
pack-priv int
private CachedObject
getFromFile(long pos, PersistentStore store, boolean keep)

private CachedObject
getFromFile(long pos, int size, PersistentStore store, boolean keep)

public long
pack-priv RowInputInterface
getRaw(long pos)

public RAShadowFile
public long
protected void
pack-priv void
protected void
initParams(Database database, String baseFileName, boolean defrag)

initial external parameters are set here.

public boolean
public boolean
public boolean
public boolean
pack-priv void
pack-priv void
private void
logSevereEvent(String message, Throwable t, long position)

public void
public void
open(boolean readonly)

Opens the *.data file for this cache, setting the variables that allow access to the particular database version of the *.data file.

private void
private void
readObject(long pos)

protected void
readObject(long pos, int size)

public void
release()

Abandons changed rows and closes the .data file.

public CachedObject
release(long pos)

public void
releaseRange(long startPos, long limitPos)

public void
releaseRange(IntIndex list, int fileBlockItemCount)

public void
remove(CachedObject object)

Used when a row is deleted as a result of some DML or DDL statement.

public void
public void
public void
reset()

Commits all the changes to the file

private boolean
restoreBackup()

Restores a compressed backup or the .data file.

private boolean
restoreBackupIncremental()

Restores in from an incremental backup

public void
saveRow(CachedObject row)

Writes out the specified Row.

protected void
public void
saveRowOutput(long pos)

protected void
saveRows(CachedObject[] rows, int offset, int count)

protected void
pack-priv void
setFlag(int singleFlag, boolean val)

pack-priv void
setFlags(int flags)

pack-priv void
setSpaceProps(int spaceProps)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

backupFileNameback to summary
protected String backupFileName
cacheback to summary
protected Cache cache
cachedRowPaddingback to summary
protected int cachedRowPadding
cacheModifiedback to summary
protected boolean cacheModified
cacheReadonlyback to summary
protected boolean cacheReadonly
databaseback to summary
protected Database database
dataFileback to summary
protected RandomAccessInterface dataFile
dataFileNameback to summary
protected String dataFileName
dataFileScaleback to summary
protected int dataFileScale
dataFileSpaceback to summary
protected int dataFileSpace
faback to summary
protected FileAccess fa
fileFreePositionback to summary
protected volatile long fileFreePosition
fileModifiedback to summary
protected boolean fileModified

this flag is used externally to determine if a backup is required

fileStartFreePositionback to summary
protected long fileStartFreePosition
initIOBufferSizeback to summary
pack-priv static final int initIOBufferSize
is251back to summary
pack-priv boolean is251
lockback to summary
pack-priv ReadWriteLock lock
logEventsback to summary
protected boolean logEvents
lostSpaceSizeback to summary
protected long lostSpaceSize
maxCacheBytesback to summary
protected long maxCacheBytes
maxCacheRowsback to summary
protected int maxCacheRows
maxDataFileSizeback to summary
public long maxDataFileSize
readLockback to summary
pack-priv Lock readLock
rowInback to summary
protected RowInputInterface rowIn
rowOutback to summary
public RowOutputInterface rowOut
shadowFileback to summary
private RAShadowFile shadowFile
spaceManagerback to summary
public DataSpaceManager spaceManager
spaceManagerPositionback to summary
protected long spaceManagerPosition
storeCountback to summary
protected int storeCount
writeLockback to summary
pack-priv Lock writeLock

Constructor Detail

DataFileCacheback to summary
public DataFileCache(Database db, String baseFileName)
DataFileCacheback to summary
public DataFileCache(Database db, String baseFileName, boolean defrag)

used for defrag

Method Detail

addback to summary
public void add(CachedObject object, boolean keep)
adjustStoreCountback to summary
public void adjustStoreCount(int adjust)
bytesCapacityback to summary
public long bytesCapacity()
capacityback to summary
public int capacity()
clearback to summary
protected void clear()
closeback to summary
public void close()

Writes out all cached rows that have been modified and the free position pointer for the *.data file and then closes the file.

copyShadowback to summary
protected int copyShadow(CachedObject[] rows, int offset, int count)
copyShadowback to summary
protected int copyShadow(CachedObject row)
defragback to summary
pack-priv DataFileDefrag defrag(Session session)
deleteBackupFileback to summary
private void deleteBackupFile()
deleteDataFileback to summary
pack-priv void deleteDataFile()
enlargeFileSpaceback to summary
public long enlargeFileSpace(long newLength)

Delta must always result in block multiples

getback to summary
public CachedObject get(CachedObject object, PersistentStore store, boolean keep)
getback to summary
public CachedObject get(long pos, int size, PersistentStore store, boolean keep)
getback to summary
public CachedObject get(long pos, PersistentStore store, boolean keep)
getAccessCountback to summary
public AtomicInteger getAccessCount()
getCachedObjectCountback to summary
public int getCachedObjectCount()
getDataFileScaleback to summary
public int getDataFileScale()
getDataFileSpaceback to summary
public int getDataFileSpace()
getFileFreePosback to summary
public long getFileFreePos()
getFileNameback to summary
public String getFileName()
getFlagsback to summary
pack-priv int getFlags() throws IOException
getFromFileback to summary
private CachedObject getFromFile(long pos, PersistentStore store, boolean keep)
getFromFileback to summary
private CachedObject getFromFile(long pos, int size, PersistentStore store, boolean keep)
getLostBlockSizeback to summary
public long getLostBlockSize()
getRawback to summary
pack-priv RowInputInterface getRaw(long pos)
getShadowFileback to summary
public RAShadowFile getShadowFile()
getTotalCachedBlockSizeback to summary
public long getTotalCachedBlockSize()
initBuffersback to summary
protected void initBuffers()
initNewFileback to summary
pack-priv void initNewFile()
initParamsback to summary
protected void initParams(Database database, String baseFileName, boolean defrag)

initial external parameters are set here.

isDataReadOnlyback to summary
public boolean isDataReadOnly()
isFileModifiedback to summary
public boolean isFileModified()
isFileOpenback to summary
public boolean isFileOpen()
isModifiedback to summary
public boolean isModified()
logDetailEventback to summary
pack-priv void logDetailEvent(String message)
logInfoEventback to summary
pack-priv void logInfoEvent(String message)
logSevereEventback to summary
private void logSevereEvent(String message, Throwable t, long position)
logSevereEventback to summary
public void logSevereEvent(String message, Throwable t)
openback to summary
public void open(boolean readonly)

Opens the *.data file for this cache, setting the variables that allow access to the particular database version of the *.data file.

openShadowFileback to summary
private void openShadowFile()
readObjectback to summary
private void readObject(long pos)
readObjectback to summary
protected void readObject(long pos, int size)
releaseback to summary
public void release()

Abandons changed rows and closes the .data file.

releaseback to summary
public CachedObject release(long pos)
releaseRangeback to summary
public void releaseRange(long startPos, long limitPos)
releaseRangeback to summary
public void releaseRange(IntIndex list, int fileBlockItemCount)
removeback to summary
public void remove(CachedObject object)

Used when a row is deleted as a result of some DML or DDL statement. Removes the row from the cache data structures.

removePersistenceback to summary
public void removePersistence(CachedObject object)
reopenback to summary
public void reopen()
resetback to summary
public void reset()

Commits all the changes to the file

restoreBackupback to summary
private boolean restoreBackup()

Restores a compressed backup or the .data file.

restoreBackupIncrementalback to summary
private boolean restoreBackupIncremental()

Restores in from an incremental backup

saveRowback to summary
public void saveRow(CachedObject row)

Writes out the specified Row. Will write only the Nodes or both Nodes and table row data depending on what is not already persisted to disk.

saveRowNoLockback to summary
protected void saveRowNoLock(CachedObject row)
saveRowOutputback to summary
public void saveRowOutput(long pos)
saveRowsback to summary
protected void saveRows(CachedObject[] rows, int offset, int count)
setFileModifiedback to summary
protected void setFileModified()
setFlagback to summary
pack-priv void setFlag(int singleFlag, boolean val) throws IOException
setFlagsback to summary
pack-priv void setFlags(int flags) throws IOException
setSpacePropsback to summary
pack-priv void setSpaceProps(int spaceProps)
org.hsqldb.persist back to summary

pack-priv Interface DataFileCache.Flags


Field Summary

Modifier and TypeField and Description
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int

Field Detail

FLAG_200back to summary
public static final int FLAG_200
FLAG_251back to summary
public static final int FLAG_251
FLAG_HXback to summary
public static final int FLAG_HX
FLAG_ISSAVEDback to summary
public static final int FLAG_ISSAVED
FLAG_ISSHADOWEDback to summary
public static final int FLAG_ISSHADOWED
FLAG_ROWINFOback to summary
public static final int FLAG_ROWINFO
org.hsqldb.persist back to summary

pack-priv Interface DataFileCache.Positions


file format fields

Field Summary

Modifier and TypeField and Description
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int
public static final int

Field Detail

INT_FLAGSback to summary
public static final int INT_FLAGS
INT_SPACE_LIST_POSback to summary
public static final int INT_SPACE_LIST_POS
INT_SPACE_PROPSback to summary
public static final int INT_SPACE_PROPS
LONG_EMPTY_SIZEback to summary
public static final int LONG_EMPTY_SIZE
LONG_FREE_POSback to summary
public static final int LONG_FREE_POS
LONG_TIMESTAMPback to summary
public static final int LONG_TIMESTAMP
MAX_INITIAL_FREE_POSback to summary
public static final int MAX_INITIAL_FREE_POS
MIN_INITIAL_FREE_POSback to summary
public static final int MIN_INITIAL_FREE_POS