public class FileManager
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
FileManager.FileMode |
(package private) class |
FileManager.LogEndFileDescriptor
The LogEndFileDescriptor is used to write and fsync the end of the log.
|
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
BAD_SUFFIX |
static java.lang.String |
BUP_SUFFIX |
static java.lang.String |
DEL_SUFFIX |
(package private) static java.lang.String[] |
DEL_SUFFIXES |
(package private) static boolean |
IO_EXCEPTION_TESTING_ON_READ |
(package private) static boolean |
IO_EXCEPTION_TESTING_ON_WRITE |
static java.lang.String |
JE_SUFFIX |
(package private) static java.lang.String[] |
JE_SUFFIXES |
(package private) long |
lastFileNumberTouched |
(package private) long |
lastFileTouchedOffset |
static boolean |
LOGWRITE_EXCEPTION_TESTING |
static long |
N_BAD_WRITES |
(package private) LongStat |
nBytesReadFromWriteQueue |
(package private) LongStat |
nBytesWrittenFromWriteQueue |
(package private) IntStat |
nFileOpens |
(package private) LongStat |
nFSyncTime |
(package private) LongStat |
nLogFSyncs |
(package private) IntStat |
nOpenFiles |
(package private) LongStat |
nRandomReadBytes |
(package private) LongStat |
nRandomReads |
(package private) LongStat |
nRandomWriteBytes |
(package private) LongStat |
nRandomWrites |
(package private) LongStat |
nReadsFromWriteQueue |
(package private) LongStat |
nSequentialReadBytes |
(package private) LongStat |
nSequentialReads |
(package private) LongStat |
nSequentialWriteBytes |
(package private) LongStat |
nSequentialWrites |
(package private) LongStat |
nWriteQueueOverflow |
(package private) LongStat |
nWriteQueueOverflowFailures |
(package private) LongStat |
nWritesFromWriteQueue |
(package private) StatGroup |
stats |
static long |
STOP_ON_WRITE_COUNT |
static boolean |
THROW_ON_WRITE |
(package private) static boolean |
THROW_RRE_FOR_UNIT_TESTS |
static java.lang.String |
TMP_SUFFIX |
boolean |
VERIFY_CHECKSUMS |
static long |
WRITE_COUNT |
Constructor and Description |
---|
FileManager(EnvironmentImpl envImpl,
java.io.File dbEnvHome,
boolean readOnly)
Set up the file cache and initialize the file manager to point to the
beginning of the log.
|
Modifier and Type | Method and Description |
---|---|
(package private) boolean |
bumpLsn(long size)
Increase the current log position by "size" bytes.
|
boolean |
checkEnvHomePermissions(boolean rdOnly)
Ensure that if the environment home dir is on readonly media or in a
readonly directory that the environment has been opened for readonly
access.
|
void |
clear()
Close all file handles and empty the cache.
|
void |
close()
Clear the file lock.
|
static boolean |
continueAfterWriteException()
Returns whether we are in a test mode where we attempt to continue
after a write IOException.
|
boolean |
deleteFile(long fileNum)
Delete log file NNNNNNNN.
|
boolean |
filesExist() |
static int |
firstLogEntryOffset() |
void |
force(java.util.Set<java.lang.Long> fileNums)
Fsync this set of log files.
|
(package private) void |
forceNewLogFile()
Set the flag that causes a new file to be written before the next write.
|
java.io.File[] |
gatherDataDirs() |
java.lang.Long[] |
getAllFileNumbers()
Get all JE file numbers.
|
(package private) java.util.Set<java.lang.Long> |
getCacheKeys() |
long |
getCurrentFileNum()
Returns the highest (current) file number.
|
FileHandle |
getFileHandle(long fileNum)
Return a read only file handle that corresponds to this file number.
|
(package private) long |
getFileHeaderPrevOffset(long fileNum) |
int |
getFileLogVersion(long fileNum)
Returns the log version for the given file.
|
static java.lang.String |
getFileName(long fileNum,
java.lang.String suffix) |
java.lang.Long |
getFirstFileNum()
public for cleaner.
|
java.lang.Long |
getFollowingFileNum(long currentFileNum1,
boolean forward)
Get the next file number before/after currentFileNum.
|
java.lang.String |
getFullFileName(long fileNum,
java.lang.String suffix) |
java.lang.String |
getFullFileName(java.lang.String fileName) |
(package private) java.lang.String[] |
getFullFileNames(long fileNum) |
java.lang.Long |
getLastFileNum() |
long |
getLastUsedLsn()
Return the last allocated LSN in the log.
|
long |
getNextLsn()
Return the next available LSN in the log.
|
long |
getNFSyncRequests() |
long |
getNFSyncs() |
long |
getNFSyncTimeouts() |
java.lang.Long |
getNumFromName(java.lang.String fileName)
Get the file number from a file name.
|
(package private) long |
getPrevEntryOffset() |
boolean |
getReadOnly() |
(package private) boolean |
getUseWriteQueue()
For unit tests.
|
(package private) void |
groupSync()
Flush a file using the group sync mechanism, trying to amortize off
other syncs.
|
boolean |
hasQueuedWrites()
Returns whether anything is in the write queue.
|
boolean |
isFileValid(long fileNum)
For assertions that check whether a file is valid or has been deleted
via log cleaning.
|
java.lang.String[] |
listFileNames(long minFileNumber,
long maxFileNumber)
Find .jdb files which are >= the minimimum file number and
<= the maximum file number.
|
(package private) java.lang.String[] |
listFileNames(java.lang.String[] suffixes)
Find JE files.
|
static java.lang.String[] |
listFiles(java.io.File envDirFile,
java.lang.String[] suffixes,
boolean envMultiSubDir)
Find JE files, flavor for unit test support.
|
java.io.File[] |
listJDBFiles() |
java.io.File[] |
listJDBFilesInternalMultiDir(JEFileFilter fileFilter) |
java.io.File[] |
listJDBFilesInternalSingleDir(JEFileFilter fileFilter) |
(package private) StatGroup |
loadStats(StatsConfig config) |
boolean |
lockEnvironment(boolean rdOnly,
boolean exclusive)
Lock the environment.
|
void |
makeInvisible(long fileNum,
java.util.List<java.lang.Long> lsns)
Mark the specified log entries as invisible and obsolete.
|
(package private) void |
readFromFile(java.io.RandomAccessFile file,
java.nio.ByteBuffer readBuffer,
long offset,
long fileNo)
Read a buffer from a file at a given offset.
|
(package private) boolean |
readFromFile(java.io.RandomAccessFile file,
java.nio.ByteBuffer readBuffer,
long offset,
long fileNo,
boolean dataKnownToBeInFile)
Read a buffer from a file at a given offset.
|
void |
releaseExclusiveLock() |
boolean |
renameFile(long fileNum,
java.lang.String newSuffix)
Rename this file to NNNNNNNN.suffix.
|
(package private) void |
restoreLastPosition() |
(package private) void |
saveLastPosition() |
void |
setIncludeDeletedFiles(boolean includeDeletedFiles) |
void |
setLastPosition(long nextAvailableLsn,
long lastUsedLsn,
long prevOffset)
Set the file manager's "end of log".
|
void |
setSyncAtFileEnd(boolean sync)
May be used to disable sync at file end to speed unit tests.
|
(package private) void |
syncLogEnd()
FSync the end of the log.
|
(package private) void |
syncLogEndAndFinishFile()
Sync the end of the log, close off this log file.
|
void |
testWriteQueueLock()
For unit testing only.
|
void |
testWriteQueueUnlock()
For unit testing only.
|
void |
truncateLog(long fileNum,
long offset) |
void |
truncateSingleFile(long fileNum,
long offset)
Truncate a log at this position.
|
(package private) void |
writeLogBuffer(LogBuffer fullBuffer,
boolean flushRequired)
Write out a log buffer to the file.
|
static boolean IO_EXCEPTION_TESTING_ON_WRITE
static boolean IO_EXCEPTION_TESTING_ON_READ
static boolean THROW_RRE_FOR_UNIT_TESTS
public static long WRITE_COUNT
public static long STOP_ON_WRITE_COUNT
public static long N_BAD_WRITES
public static boolean THROW_ON_WRITE
public static final java.lang.String JE_SUFFIX
public static final java.lang.String DEL_SUFFIX
public static final java.lang.String BAD_SUFFIX
static final java.lang.String[] DEL_SUFFIXES
static final java.lang.String[] JE_SUFFIXES
public static final java.lang.String TMP_SUFFIX
public static final java.lang.String BUP_SUFFIX
public boolean VERIFY_CHECKSUMS
long lastFileNumberTouched
long lastFileTouchedOffset
final StatGroup stats
final LongStat nRandomReads
final LongStat nRandomWrites
final LongStat nSequentialReads
final LongStat nSequentialWrites
final LongStat nRandomReadBytes
final LongStat nRandomWriteBytes
final LongStat nSequentialReadBytes
final LongStat nSequentialWriteBytes
final IntStat nFileOpens
final IntStat nOpenFiles
final LongStat nBytesReadFromWriteQueue
final LongStat nBytesWrittenFromWriteQueue
final LongStat nReadsFromWriteQueue
final LongStat nWritesFromWriteQueue
final LongStat nWriteQueueOverflow
final LongStat nWriteQueueOverflowFailures
final LongStat nLogFSyncs
final LongStat nFSyncTime
public static final boolean LOGWRITE_EXCEPTION_TESTING
public FileManager(EnvironmentImpl envImpl, java.io.File dbEnvHome, boolean readOnly) throws EnvironmentLockedException
configManager
- dbEnvHome
- environment home directoryjava.lang.IllegalArgumentException
- via Environment ctorEnvironmentLockedException
- via Environment ctorpublic static boolean continueAfterWriteException()
public void setLastPosition(long nextAvailableLsn, long lastUsedLsn, long prevOffset)
nextAvailableLsn
- LSN to be used for the next log entrylastUsedLsn
- last LSN to have a valid entry, may be nullprevOffset
- value to use for the prevOffset of the next entry.
If the beginning of the file, this is 0.void saveLastPosition()
void restoreLastPosition()
public void setSyncAtFileEnd(boolean sync)
public java.lang.Long getFirstFileNum()
public boolean getReadOnly()
public java.lang.Long getLastFileNum()
public long getCurrentFileNum()
boolean getUseWriteQueue()
public boolean isFileValid(long fileNum)
public void setIncludeDeletedFiles(boolean includeDeletedFiles)
public java.lang.Long[] getAllFileNumbers()
public java.lang.Long getFollowingFileNum(long currentFileNum1, boolean forward)
currentFileNum1
- the file we're at right now. Note that
it may not exist, if it's been cleaned and renamed.forward
- if true, we want the next larger file, if false
we want the previous filepublic boolean filesExist()
public java.lang.Long getNumFromName(java.lang.String fileName)
the
- file namejava.lang.String[] listFileNames(java.lang.String[] suffixes)
suffix
- which type of file we're looking forpublic java.lang.String[] listFileNames(long minFileNumber, long maxFileNumber)
public static java.lang.String[] listFiles(java.io.File envDirFile, java.lang.String[] suffixes, boolean envMultiSubDir)
suffix
- which type of file we're looking forpublic java.io.File[] listJDBFiles()
public java.io.File[] listJDBFilesInternalSingleDir(JEFileFilter fileFilter)
public java.io.File[] listJDBFilesInternalMultiDir(JEFileFilter fileFilter)
public java.io.File[] gatherDataDirs()
java.lang.String[] getFullFileNames(long fileNum)
public java.lang.String getFullFileName(long fileNum, java.lang.String suffix)
public java.lang.String getFullFileName(java.lang.String fileName)
public static java.lang.String getFileName(long fileNum, java.lang.String suffix)
public boolean renameFile(long fileNum, java.lang.String newSuffix) throws java.io.IOException, DatabaseException
fileNum
- the file we want to movenewSuffix
- the new file suffixjava.io.IOException
DatabaseException
public boolean deleteFile(long fileNum) throws java.io.IOException, DatabaseException
fileNum
- the file we want to movejava.io.IOException
DatabaseException
public int getFileLogVersion(long fileNum) throws DatabaseException
DatabaseException
public FileHandle getFileHandle(long fileNum) throws java.io.FileNotFoundException, ChecksumException, DatabaseException
fileNum
- which filejava.io.FileNotFoundException
ChecksumException
DatabaseException
long getFileHeaderPrevOffset(long fileNum) throws ChecksumException, DatabaseException
ChecksumException
DatabaseException
long getPrevEntryOffset()
boolean bumpLsn(long size)
size
- is an unsigned intvoid writeLogBuffer(LogBuffer fullBuffer, boolean flushRequired) throws DatabaseException
fullBuffer
- buffer to writeflushRequired
- true if this write can not be queued on the
Write Queue.DatabaseException
void readFromFile(java.io.RandomAccessFile file, java.nio.ByteBuffer readBuffer, long offset, long fileNo) throws DatabaseException
DatabaseException
boolean readFromFile(java.io.RandomAccessFile file, java.nio.ByteBuffer readBuffer, long offset, long fileNo, boolean dataKnownToBeInFile) throws DatabaseException
DatabaseException
void syncLogEnd() throws DatabaseException
DatabaseException
void syncLogEndAndFinishFile() throws DatabaseException, java.io.IOException
DatabaseException
java.io.IOException
public boolean hasQueuedWrites()
public void testWriteQueueLock()
public void testWriteQueueUnlock()
void groupSync() throws DatabaseException
DatabaseException
public void clear() throws java.io.IOException, DatabaseException
java.io.IOException
DatabaseException
public void close() throws java.io.IOException
java.io.IOException
public boolean lockEnvironment(boolean rdOnly, boolean exclusive)
public void releaseExclusiveLock() throws DatabaseException
DatabaseException
public boolean checkEnvHomePermissions(boolean rdOnly) throws DatabaseException
java.lang.IllegalArgumentException
- via Environment ctorDatabaseException
public void truncateSingleFile(long fileNum, long offset) throws java.io.IOException, DatabaseException
This method forces a new log file to be written next, if the last file (the file truncated to) has an old version in its header. This ensures that when the log is opened by an old version of JE, a version incompatibility will be detected. [#11243]
java.io.IOException
DatabaseException
public void truncateLog(long fileNum, long offset) throws java.io.IOException, DatabaseException
java.io.IOException
DatabaseException
public void makeInvisible(long fileNum, java.util.List<java.lang.Long> lsns)
fileNum
- target file.lsns
- The list of LSNs to make invisible, must be sorted in
ascending order.public void force(java.util.Set<java.lang.Long> fileNums)
void forceNewLogFile()
public static int firstLogEntryOffset()
public long getNextLsn()
public long getLastUsedLsn()
public long getNFSyncs()
public long getNFSyncRequests()
public long getNFSyncTimeouts()
StatGroup loadStats(StatsConfig config)
java.util.Set<java.lang.Long> getCacheKeys()
Copyright (c) 2004-2012 Oracle. All rights reserved.