|
|||||||||
| Home >> All >> org >> apache >> derby >> impl >> store >> raw >> [ log overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
org.apache.derby.impl.store.raw.log
Class LogToFile

java.lang.Objectorg.apache.derby.impl.store.raw.log.LogToFile
- All Implemented Interfaces:
- org.apache.derby.iapi.store.raw.Corruptable, org.apache.derby.iapi.store.raw.log.LogFactory, org.apache.derby.iapi.services.monitor.ModuleControl, org.apache.derby.iapi.services.monitor.ModuleSupportable, java.security.PrivilegedExceptionAction, org.apache.derby.iapi.services.daemon.Serviceable
- public class LogToFile
- extends java.lang.Object
- implements org.apache.derby.iapi.store.raw.log.LogFactory, org.apache.derby.iapi.services.monitor.ModuleControl, org.apache.derby.iapi.services.monitor.ModuleSupportable, org.apache.derby.iapi.services.daemon.Serviceable, java.security.PrivilegedExceptionAction
- extends java.lang.Object
This is an implementation of the log using a non-circular file system file. No support for incremental log backup or media recovery. Only crash recovery is supported.
The 'log' is a stream of log records. The 'log' is implemented as a series of numbered log files. These numbered log files are logically continuous so a transaction can have log records that span multiple log files. A single log record cannot span more then one log file. The log file number is monotonically increasing.
The log belongs to a log factory of a RawStore. In the current implementation, each RawStore only has one log factory, so each RawStore only has one log (which composed of multiple log files). At any given time, a log factory only writes new log records to one log file, this log file is called the 'current log file'.
A log file is named loglogNumber.dat
Everytime a checkpoint is taken, a new log file is created and all subsequent log records will go to the new log file. After a checkpoint is taken, old and useless log files will be deleted.
RawStore exposes a checkpoint method which clients can call, or a checkpoint is taken automatically by the RawStore when
- the log file grows beyond a certain size (configurable, default 100K bytes)
- RawStore is shutdown and a checkpoint hasn't been done "for a while"
- RawStore is recovered and a checkpoint hasn't been done "for a while"
This LogFactory is responsible for the formats of 2 kinds of file: the log file and the log control file. And it is responsible for the format of the log record wrapper.
Format of log control file
| Field Summary | |
private int |
action
|
private org.apache.derby.io.StorageFile |
activeFile
|
private java.lang.String |
activePerms
|
private static int |
CHECKPOINT_INTERVAL_MAX
|
private static int |
CHECKPOINT_INTERVAL_MIN
|
private org.apache.derby.iapi.services.daemon.DaemonService |
checkpointDaemon
|
private boolean |
checkpointDaemonCalled
|
(package private) long |
checkpointInstant
|
private int |
checkpointInterval
|
private java.util.zip.CRC32 |
checksum
|
protected org.apache.derby.iapi.error.StandardException |
corrupt
If not null then something is corrupt in the raw store and this represents the original error. |
private CheckpointOperation |
currentCheckpoint
|
private boolean |
databaseEncrypted
|
(package private) java.lang.String |
dataDirectory
|
protected org.apache.derby.iapi.store.raw.data.DataFactory |
dataFactory
|
static java.lang.String |
DBG_FLAG
|
private static int |
DEFAULT_CHECKPOINT_INTERVAL
|
private static java.lang.String |
DEFAULT_LOG_ARCHIVE_DIRECTORY
|
private static int |
DEFAULT_LOG_BUFFER_SIZE
|
private static int |
DEFAULT_LOG_SWITCH_INTERVAL
|
static java.lang.String |
DUMP_LOG_FROM_LOG_FILE
|
static java.lang.String |
DUMP_LOG_ONLY
|
protected long |
endPosition
|
private static int |
fid
|
private org.apache.derby.io.StorageRandomAccessFile |
firstLog
|
(package private) long |
firstLogFileNumber
|
private boolean |
inCheckpoint
|
private boolean |
inLogSwitch
|
private boolean |
inRedo
|
private static byte |
IS_BETA_FLAG
|
private static byte |
IS_DURABILITY_TESTMODE_NO_SYNC_FLAG
When the derby.system.durability property is set to 'test', the store system will not force sync calls in the following cases - for the log file at each commit - for the log file before data page is forced to disk - for page allocation when file is grown - for data writes during checkpoint This means it is possible that the recovery system may not work properly, committed transactions may be lost, and/or database may not be in a consistent state. |
private boolean |
isFrozen
If frozen, don't allow anything on disk to change. |
private boolean |
isWriteSynced
Note: Why logging system support file sync and write sync ? Note : The reason to support file and write sync of logs is there was no support to do write sync until jdk1.4 and then there was write sync jvm bug in jdk1.4.1, only in jdk1.4.2 write sync(rws mode) mechanism can be used corretly. |
(package private) org.apache.derby.iapi.services.info.ProductVersionHolder |
jbmsVersion
Product Version information. |
private boolean |
keepAllLogs
|
(package private) long |
lastFlush
|
private static int |
LOG_BUFFER_SIZE_MAX
|
private static int |
LOG_BUFFER_SIZE_MIN
|
protected static int |
LOG_FILE_HEADER_PREVIOUS_LOG_INSTANT_OFFSET
|
static int |
LOG_FILE_HEADER_SIZE
|
static int |
LOG_RECORD_OVERHEAD
|
private static int |
LOG_SWITCH_INTERVAL_MAX
|
private static int |
LOG_SWITCH_INTERVAL_MIN
|
protected static java.lang.String |
LOG_SYNC_STATISTICS
|
private boolean |
logArchived
|
private boolean |
logBeingFlushed
|
private int |
logBufferSize
|
(package private) java.lang.String |
logDevice
|
(package private) long |
logFileNumber
|
private boolean |
logNotSynced
|
protected LogAccessFile |
logOut
|
private org.apache.derby.io.WritableStorageFactory |
logStorageFactory
|
private int |
logSwitchInterval
|
private boolean |
logSwitchRequired
|
private long |
logWrittenFromLastCheckPoint
|
private long |
maxLogFileNumber
|
private int |
mon_flushCalls
|
private boolean |
mon_LogSyncStatistics
|
private int |
mon_numBytesToLog
|
private int |
mon_numLogFlushWaits
|
private int |
mon_syncCalls
|
private int |
myClientNumber
|
private static int |
OBSOLETE_LOG_VERSION_NUMBER
|
private boolean |
onDiskBeta
|
private int |
onDiskMajorVersion
On disk database version information. |
private int |
onDiskMinorVersion
|
private org.apache.derby.iapi.store.raw.RawStoreFactory |
rawStoreFactory
|
protected boolean |
ReadOnlyDB
|
private boolean |
recoveryNeeded
|
private boolean |
stopped
|
static java.lang.String |
TEST_LOG_FULL
Set to true if we want to simulate a log full condition |
static java.lang.String |
TEST_LOG_INCOMPLETE_LOG_WRITE
Set to true if we want the up comming log record to be only partially written. |
static java.lang.String |
TEST_LOG_PARTIAL_LOG_WRITE_NUM_BYTES
Set to the number of bytes we want the next log record to actually write out, only used when TEST_LOG_INCOMPLETE_LOG_WRITE is on. |
static java.lang.String |
TEST_LOG_SWITCH_LOG
Set to true if we want the checkpoint to only switch the log but not actually do the checkpoint |
(package private) int |
test_logWritten
DEBUG test only |
static java.lang.String |
TEST_MAX_LOGFILE_NUMBER
Set to true if we want to simulate max possible log file number is being used. |
(package private) int |
test_numRecordToFillLog
|
static java.lang.String |
TEST_RECORD_TO_FILL_LOG
Set to the number of log record we want to write before the log is simulated to be full. |
static java.lang.String |
TEST_SWITCH_LOG_FAIL1
Set to true if we want to simulate a log full condition while switching log |
static java.lang.String |
TEST_SWITCH_LOG_FAIL2
|
private java.io.File |
toFile
|
private static boolean |
wasDBInDurabilityTestModeNoSync
keeps track of if the database was booted previously at any time with derby.system.durability=test |
| Fields inherited from interface org.apache.derby.iapi.store.raw.log.LogFactory |
LOG_DIRECTORY_NAME, MODULE, RT_READONLY, RUNTIME_ATTRIBUTES |
| Fields inherited from interface org.apache.derby.iapi.services.daemon.Serviceable |
DONE, REQUEUE |
| Constructor Summary | |
LogToFile()
MT- not needed for constructor |
|
| Method Summary | |
protected long |
appendLogRecord(byte[] data,
int offset,
int length,
byte[] optionalData,
int optionalDataOffset,
int optionalDataLength)
Append length bytes of data to the log prepended by a long log instant and followed by 4 bytes of length information. |
void |
boot(boolean create,
java.util.Properties startParams)
Boot up the log factory. |
boolean |
canSupport(java.util.Properties startParams)
See if this implementation can support any attributes that are listed in properties. |
private void |
checkCorrupt()
|
boolean |
checkpoint(org.apache.derby.iapi.store.raw.RawStoreFactory rsf,
org.apache.derby.iapi.store.raw.data.DataFactory df,
org.apache.derby.iapi.store.raw.xact.TransactionFactory tf,
boolean wait)
Checkpoint the rawStore. |
void |
checkpointInRFR(org.apache.derby.iapi.store.raw.log.LogInstant cinstant,
long redoLWM,
org.apache.derby.iapi.store.raw.data.DataFactory df)
redo a checkpoint during rollforward recovery |
protected boolean |
checkpointWithTran(org.apache.derby.iapi.store.raw.xact.RawTransaction cptran,
org.apache.derby.iapi.store.raw.RawStoreFactory rsf,
org.apache.derby.iapi.store.raw.data.DataFactory df,
org.apache.derby.iapi.store.raw.xact.TransactionFactory tf)
checkpoint with pre-start transaction |
(package private) boolean |
checkVersion(int requiredMajorVersion,
int requiredMinorVersion)
Check to see if a database has been upgraded to the required level in order to use a store feature. |
boolean |
copyActiveLogFiles(java.io.File toDir)
|
protected long |
currentInstant()
Get the current log instant - this is the log instant of the Next log record to be written out |
boolean |
databaseEncrypted()
|
int |
decrypt(byte[] ciphertext,
int offset,
int length,
byte[] cleartext,
int outputOffset)
|
private void |
deleteObsoleteLogfiles()
|
void |
deleteOnlineArchivedLogFiles()
|
void |
disableLogArchiveMode()
|
void |
enableLogArchiveMode()
|
int |
encrypt(byte[] cleartext,
int offset,
int length,
byte[] ciphertext,
int outputOffset)
|
protected long |
endPosition()
|
private CheckpointOperation |
findCheckpoint(long checkpointInstant,
FileLogger logger)
|
private long |
firstLogInstant()
Get the first valid log instant - this is the beginning of the first log file |
void |
flush(org.apache.derby.iapi.store.raw.log.LogInstant where)
Flush all unwritten log record up to the log instance indicated to disk and sync. |
protected void |
flush(long fileNumber,
long wherePosition)
Flush the log such that the log record written with the instant wherePosition is guaranteed to be on disk. |
void |
flushAll()
Flush all unwritten log record to disk and sync. |
private void |
flushBuffer(long fileNumber,
long wherePosition)
Flush all unwritten log record up to the log instance indicated to disk without syncing. |
void |
freezePersistentStore()
Backup restore - stop sending log record to the log stream |
java.lang.String |
getCanonicalLogPath()
Return the canonical directory of the PARENT of the log directory. |
private org.apache.derby.io.StorageFile |
getControlFileName()
Return the control file name |
int |
getEncryptedDataLength(int length)
returns the length that will make the data to be multiple of encryption block size based on the given length. |
int |
getEncryptionBlockSize()
return the encryption block size used during encrypted db creation |
private long |
getFirstLogNeeded(CheckpointOperation checkpoint)
|
org.apache.derby.iapi.store.raw.log.LogInstant |
getFirstUnflushedInstant()
Get the instant of the first record which was not flushed. |
org.apache.derby.io.StorageFile |
getLogDirectory()
Return the location of the log directory. |
private java.lang.String |
getLogDirPath(org.apache.derby.io.StorageFile logDir)
|
void |
getLogFactoryProperties(org.apache.derby.iapi.services.property.PersistentSet set)
Get JBMS properties relavent to the log factory |
protected org.apache.derby.io.StorageRandomAccessFile |
getLogFileAtBeginning(long filenumber)
Open a log file and position the file at the beginning. |
protected org.apache.derby.io.StorageRandomAccessFile |
getLogFileAtPosition(long logInstant)
Get a read-only handle to the log file positioned at the stated position |
private org.apache.derby.io.StorageFile |
getLogFileName(long filenumber)
Given a log file number, return its file name |
private long |
getLogFileNumber()
Return the current log file number. |
org.apache.derby.io.StorageRandomAccessFile |
getLogFileToSimulateCorruption(long filenum)
Get the log file to Simulate a log corruption FOR UNIT TESTING USAGE ONLY |
org.apache.derby.iapi.store.raw.log.Logger |
getLogger()
MT- not needed |
private void |
getLogStorageFactory()
|
private org.apache.derby.io.StorageFile |
getMirrorControlFileName()
Return the mirror control file name |
int |
getTypeFormatId()
Return my format identifier. |
private boolean |
initLogFile(org.apache.derby.io.StorageRandomAccessFile newlog,
long number,
long prevLogRecordEndInstant)
Initialize the log to the correct format with the given version and log file number. |
boolean |
inRFR()
|
boolean |
logArchived()
Backup restore - is the log being archived to some directory? if log archive mode is enabled return true else false |
protected void |
logErrMsg(java.lang.String msg)
Print error message to user about the log MT - not needed, informational only |
protected void |
logErrMsg(java.lang.Throwable t)
Print error message to user about the log MT - not needed, informational only |
private void |
logErrMsgForDurabilityTestModeNoSync()
In case of boot errors, and if database is either booted with derby.system.durability=test or was previously at any time booted in this mode, mention in the error message that the error is probably because the derby.system.durability was set. |
private long |
logtest_appendPartialLogRecord(byte[] data,
int offset,
int length,
byte[] optionalData,
int optionalDataOffset,
int optionalDataLength)
Writes out a partial log record - takes the appendLogRecord. |
org.apache.derby.iapi.error.StandardException |
markCorrupt(org.apache.derby.iapi.error.StandardException originalError)
Once the log factory is makred as corrupt then the raw sto |
protected org.apache.derby.iapi.store.raw.log.LogScan |
openBackwardsScan(org.apache.derby.iapi.store.raw.log.LogInstant stopAt)
Scan backward from end of log. |
protected org.apache.derby.iapi.store.raw.log.LogScan |
openBackwardsScan(long startAt,
org.apache.derby.iapi.store.raw.log.LogInstant stopAt)
Scan backward from start position. |
org.apache.derby.iapi.store.raw.ScanHandle |
openFlushedScan(org.apache.derby.iapi.store.access.DatabaseInstant start,
int groupsIWant)
Get a ScanHandle to scan flushed records from the log. |
org.apache.derby.iapi.store.raw.log.LogScan |
openForwardsFlushedScan(org.apache.derby.iapi.store.raw.log.LogInstant startAt)
Open a forward scan of the transaction log. |
org.apache.derby.iapi.store.raw.log.LogScan |
openForwardsScan(org.apache.derby.iapi.store.raw.log.LogInstant startAt,
org.apache.derby.iapi.store.raw.log.LogInstant stopAt)
Get a forwards scan |
protected org.apache.derby.iapi.store.raw.log.LogScan |
openForwardsScan(long startAt,
org.apache.derby.iapi.store.raw.log.LogInstant stopAt)
Scan Forward from start position. |
org.apache.derby.io.StorageRandomAccessFile |
openLogFileInWriteMode(org.apache.derby.io.StorageFile logFile)
|
int |
performWork(org.apache.derby.iapi.services.context.ContextManager context)
Do whatever it is that you want the daemon to do for you. |
private void |
preAllocateNewLogFile(org.apache.derby.io.StorageRandomAccessFile log)
|
private void |
printErrorStack(java.lang.Throwable t)
print stack trace from the Throwable including its nested exceptions |
protected boolean |
privCanWrite(org.apache.derby.io.StorageFile file)
|
protected boolean |
privCopyFile(java.io.File from,
org.apache.derby.io.StorageFile to)
|
protected boolean |
privCopyFile(org.apache.derby.io.StorageFile from,
java.io.File to)
|
protected boolean |
privDelete(org.apache.derby.io.StorageFile file)
|
protected boolean |
privExists(org.apache.derby.io.StorageFile file)
|
protected java.lang.String[] |
privList(java.io.File file)
|
protected java.lang.String[] |
privList(org.apache.derby.io.StorageFile file)
|
protected boolean |
privMkdirs(org.apache.derby.io.StorageFile file)
|
protected org.apache.derby.io.StorageRandomAccessFile |
privRandomAccessFile(org.apache.derby.io.StorageFile file,
java.lang.String perms)
|
protected boolean |
privRemoveDirectory(org.apache.derby.io.StorageFile file)
|
private long |
readControlFile(org.apache.derby.io.StorageFile logControlFileName,
java.util.Properties startParams)
|
void |
recover(org.apache.derby.iapi.store.raw.RawStoreFactory rsf,
org.apache.derby.iapi.store.raw.data.DataFactory df,
org.apache.derby.iapi.store.raw.xact.TransactionFactory tf)
Recover the rawStore to a consistent state using the log. |
private void |
restoreLogs(java.util.Properties properties)
This function restores logs based on the following attributes are specified on connection URL: Attribute.CREATE_FROM (Create database from backup if it does not exist) Attribute.RESTORE_FROM (Delete the whole database if it exists and then restore it from backup) Attribute.ROLL_FORWARD_RECOVERY_FROM:(Perform Rollforward Recovery; except for the log directory everthing else is replced by the copy from backup. |
java.lang.Object |
run()
This method performs an operation that requires higher privileges to successfully complete. |
private boolean |
runBooleanAction(int action,
org.apache.derby.io.StorageFile file)
|
boolean |
serviceASAP()
If this work should be done as soon as possible, then return true. |
boolean |
serviceImmediately()
If this work should be done immediately on the user thread then return true. |
void |
stop()
Stop the log factory |
private void |
switchLogFile()
Switch to the next log file if possible. |
private void |
syncFile(org.apache.derby.io.StorageRandomAccessFile raf)
Utility routine to call sync() on the input file descriptor. |
protected void |
testLogFull()
Simulate a log full condition if TEST_LOG_FULL is set to true, then the property TEST_RECORD_TO_FILL_LOG indicates the number of times this function is call before an IOException simulating a log full condition is raised. |
private void |
truncateLog(CheckpointOperation checkpoint)
Get rid of old and unnecessary log files |
void |
unfreezePersistentStore()
Backup restore - start sending log record to the log stream |
private boolean |
verifyLogFormat(org.apache.derby.io.StorageFile logFileName,
long number)
Verify that we the log file is of the right format and of the right version and log file number. |
private boolean |
verifyLogFormat(org.apache.derby.io.StorageRandomAccessFile log,
long number)
Verify that we the log file is of the right format and of the right version and log file number. |
(package private) boolean |
writeControlFile(org.apache.derby.io.StorageFile logControlFileName,
long value)
Carefully write out this value to the control file. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
fid
private static int fid
LOG_FILE_HEADER_SIZE
public static final int LOG_FILE_HEADER_SIZE
- See Also:
- Constant Field Values
LOG_FILE_HEADER_PREVIOUS_LOG_INSTANT_OFFSET
protected static final int LOG_FILE_HEADER_PREVIOUS_LOG_INSTANT_OFFSET
- See Also:
- Constant Field Values
LOG_RECORD_OVERHEAD
public static final int LOG_RECORD_OVERHEAD
- See Also:
- Constant Field Values
DBG_FLAG
public static final java.lang.String DBG_FLAG
DUMP_LOG_ONLY
public static final java.lang.String DUMP_LOG_ONLY
DUMP_LOG_FROM_LOG_FILE
public static final java.lang.String DUMP_LOG_FROM_LOG_FILE
LOG_SYNC_STATISTICS
protected static final java.lang.String LOG_SYNC_STATISTICS
- See Also:
- Constant Field Values
OBSOLETE_LOG_VERSION_NUMBER
private static final int OBSOLETE_LOG_VERSION_NUMBER
- See Also:
- Constant Field Values
DEFAULT_LOG_SWITCH_INTERVAL
private static final int DEFAULT_LOG_SWITCH_INTERVAL
- See Also:
- Constant Field Values
LOG_SWITCH_INTERVAL_MIN
private static final int LOG_SWITCH_INTERVAL_MIN
- See Also:
- Constant Field Values
LOG_SWITCH_INTERVAL_MAX
private static final int LOG_SWITCH_INTERVAL_MAX
- See Also:
- Constant Field Values
CHECKPOINT_INTERVAL_MIN
private static final int CHECKPOINT_INTERVAL_MIN
- See Also:
- Constant Field Values
CHECKPOINT_INTERVAL_MAX
private static final int CHECKPOINT_INTERVAL_MAX
- See Also:
- Constant Field Values
DEFAULT_CHECKPOINT_INTERVAL
private static final int DEFAULT_CHECKPOINT_INTERVAL
- See Also:
- Constant Field Values
DEFAULT_LOG_BUFFER_SIZE
private static final int DEFAULT_LOG_BUFFER_SIZE
- See Also:
- Constant Field Values
LOG_BUFFER_SIZE_MIN
private static final int LOG_BUFFER_SIZE_MIN
- See Also:
- Constant Field Values
LOG_BUFFER_SIZE_MAX
private static final int LOG_BUFFER_SIZE_MAX
- See Also:
- Constant Field Values
logBufferSize
private int logBufferSize
IS_BETA_FLAG
private static final byte IS_BETA_FLAG
- See Also:
- Constant Field Values
IS_DURABILITY_TESTMODE_NO_SYNC_FLAG
private static final byte IS_DURABILITY_TESTMODE_NO_SYNC_FLAG
- When the derby.system.durability property is set to 'test', the store
system will not force sync calls in the following cases
- for the log file at each commit
- for the log file before data page is forced to disk
- for page allocation when file is grown
- for data writes during checkpoint
This means it is possible that the recovery system may not work properly,
committed transactions may be lost, and/or database may not
be in a consistent state.
In order that we recognize this case that the database was previously
at any time booted in this mode, this value is written out
into the log control file. This will help prevent us from
wasting time to resolve issues in such cases.
wasDBInDurabilityTestModeNoSync
private static boolean wasDBInDurabilityTestModeNoSync
- keeps track of if the database was booted previously at any time with
derby.system.durability=test
DEFAULT_LOG_ARCHIVE_DIRECTORY
private static final java.lang.String DEFAULT_LOG_ARCHIVE_DIRECTORY
- See Also:
- Constant Field Values
logSwitchInterval
private int logSwitchInterval
checkpointInterval
private int checkpointInterval
dataDirectory
java.lang.String dataDirectory
logStorageFactory
private org.apache.derby.io.WritableStorageFactory logStorageFactory
logBeingFlushed
private boolean logBeingFlushed
logOut
protected LogAccessFile logOut
firstLog
private org.apache.derby.io.StorageRandomAccessFile firstLog
endPosition
protected long endPosition
lastFlush
long lastFlush
logFileNumber
long logFileNumber
firstLogFileNumber
long firstLogFileNumber
maxLogFileNumber
private long maxLogFileNumber
currentCheckpoint
private CheckpointOperation currentCheckpoint
checkpointInstant
long checkpointInstant
checkpointDaemon
private org.apache.derby.iapi.services.daemon.DaemonService checkpointDaemon
myClientNumber
private int myClientNumber
checkpointDaemonCalled
private volatile boolean checkpointDaemonCalled
logWrittenFromLastCheckPoint
private long logWrittenFromLastCheckPoint
rawStoreFactory
private org.apache.derby.iapi.store.raw.RawStoreFactory rawStoreFactory
dataFactory
protected org.apache.derby.iapi.store.raw.data.DataFactory dataFactory
ReadOnlyDB
protected boolean ReadOnlyDB
keepAllLogs
private boolean keepAllLogs
databaseEncrypted
private boolean databaseEncrypted
recoveryNeeded
private boolean recoveryNeeded
inCheckpoint
private boolean inCheckpoint
inRedo
private boolean inRedo
inLogSwitch
private boolean inLogSwitch
stopped
private boolean stopped
logDevice
java.lang.String logDevice
logNotSynced
private boolean logNotSynced
logArchived
private boolean logArchived
logSwitchRequired
private boolean logSwitchRequired
test_logWritten
int test_logWritten
- DEBUG test only
test_numRecordToFillLog
int test_numRecordToFillLog
mon_flushCalls
private int mon_flushCalls
mon_syncCalls
private int mon_syncCalls
mon_numLogFlushWaits
private int mon_numLogFlushWaits
mon_LogSyncStatistics
private boolean mon_LogSyncStatistics
mon_numBytesToLog
private int mon_numBytesToLog
corrupt
protected volatile org.apache.derby.iapi.error.StandardException corrupt
- If not null then something is corrupt in the raw store and this represents the original error.
isFrozen
private boolean isFrozen
- If frozen, don't allow anything on disk to change.
jbmsVersion
org.apache.derby.iapi.services.info.ProductVersionHolder jbmsVersion
- Product Version information. Invarient after boot.
onDiskMajorVersion
private int onDiskMajorVersion
- On disk database version information. When running in soft upgrade this version
may be different to jbmsVersion.
onDiskMinorVersion
private int onDiskMinorVersion
onDiskBeta
private boolean onDiskBeta
checksum
private java.util.zip.CRC32 checksum
isWriteSynced
private boolean isWriteSynced
- Note: Why logging system support file sync and write sync ?
Note : The reason to support file and write sync of logs is
there was no support to do write sync until jdk1.4 and then
there was write sync jvm bug in jdk1.4.1, only in jdk1.4.2 write
sync(rws mode) mechanism can be used corretly.
Default in JVMS >= jdk1.4.2 is write sync(see the boot method for jvm checks).
Write sync mechanism support is added for performance reasons.
On commits, logging system has to make sure the log for committed
transaction is on disk. With out write sync , log is written to the
disk and then fsync() is used on commits to make log is written to the
disk for sure. On most of the OS , fsync() calls are expensive.
On heavey commit oriented systems , file sync make the system run slow.
This problem is solved by using write sync on preallocated log file.
write sync is much faster than doing write and file sync to a file.
File should be preallocated for write syncs to perform better than
the file sync method. Whenever a new log file is created,
logSwitchInterval size is preallocated by writing zeros after file after the header.
TEST_LOG_SWITCH_LOG
public static final java.lang.String TEST_LOG_SWITCH_LOG
- Set to true if we want the checkpoint to only switch the log but not
actually do the checkpoint
TEST_LOG_INCOMPLETE_LOG_WRITE
public static final java.lang.String TEST_LOG_INCOMPLETE_LOG_WRITE
- Set to true if we want the up comming log record to be only partially
written. The database is corrupted if not immediately shutdown.
Set TEST_LOG_PARTIAL_LOG_WRITE_NUM_BYTES to the number of bytes to write
out, default is 1 byte.
TEST_LOG_PARTIAL_LOG_WRITE_NUM_BYTES
public static final java.lang.String TEST_LOG_PARTIAL_LOG_WRITE_NUM_BYTES
- Set to the number of bytes we want the next log record to actually write
out, only used when TEST_LOG_INCOMPLETE_LOG_WRITE is on. Default is 1
byte.
TEST_LOG_FULL
public static final java.lang.String TEST_LOG_FULL
- Set to true if we want to simulate a log full condition
TEST_SWITCH_LOG_FAIL1
public static final java.lang.String TEST_SWITCH_LOG_FAIL1
- Set to true if we want to simulate a log full condition while switching log
TEST_SWITCH_LOG_FAIL2
public static final java.lang.String TEST_SWITCH_LOG_FAIL2
TEST_RECORD_TO_FILL_LOG
public static final java.lang.String TEST_RECORD_TO_FILL_LOG
- Set to the number of log record we want to write before the log is
simulated to be full.
TEST_MAX_LOGFILE_NUMBER
public static final java.lang.String TEST_MAX_LOGFILE_NUMBER
- Set to true if we want to simulate max possible log file number is
being used.
action
private int action
activeFile
private org.apache.derby.io.StorageFile activeFile
toFile
private java.io.File toFile
activePerms
private java.lang.String activePerms
| Constructor Detail |
LogToFile
public LogToFile()
- MT- not needed for constructor
| Method Detail |
getTypeFormatId
public int getTypeFormatId()
- Return my format identifier.
markCorrupt
public org.apache.derby.iapi.error.StandardException markCorrupt(org.apache.derby.iapi.error.StandardException originalError)
- Once the log factory is makred as corrupt then the raw sto
- Specified by:
markCorruptin interfaceorg.apache.derby.iapi.store.raw.Corruptable
checkCorrupt
private void checkCorrupt()
throws org.apache.derby.iapi.error.StandardException
getLogger
public org.apache.derby.iapi.store.raw.log.Logger getLogger()
- MT- not needed
- Specified by:
getLoggerin interfaceorg.apache.derby.iapi.store.raw.log.LogFactory
recover
public void recover(org.apache.derby.iapi.store.raw.RawStoreFactory rsf, org.apache.derby.iapi.store.raw.data.DataFactory df, org.apache.derby.iapi.store.raw.xact.TransactionFactory tf) throws org.apache.derby.iapi.error.StandardException
- Recover the rawStore to a consistent state using the log.
In this implementation, the log is a stream of log records stored in one or more flat files. Recovery is done in 2 passes: redo and undo.
Redo pass
In the redo pass, reconstruct the state of the rawstore by repeating exactly what happened before as recorded in the log.
Undo pass
In the undo pass, all incomplete transactions are rolled back in the order from the most recently started to the oldest.MT - synchronization provided by caller - RawStore boot. This method is guaranteed to be the only method being called and can assume single thread access on all fields.
- Specified by:
recoverin interfaceorg.apache.derby.iapi.store.raw.log.LogFactory
checkpoint
public boolean checkpoint(org.apache.derby.iapi.store.raw.RawStoreFactory rsf, org.apache.derby.iapi.store.raw.data.DataFactory df, org.apache.derby.iapi.store.raw.xact.TransactionFactory tf, boolean wait) throws org.apache.derby.iapi.error.StandardException
- Checkpoint the rawStore.
MT- Only one checkpoint is to be taking place at any given time.
The steps of a checkpoint are
- switch to a new log file if possible
freeze the log (for the transition to a new log file) flush current log file create and flush the new log file (with file number 1 higher than the previous log file). The new log file becomes the current log file. unfreeze the log - start checkpoint transaction
- gather interesting information about the rawStore: the current log instant (redoLWM) the earliest active transaction begin tran log record instant (undoLWM), all the truncation LWM set by clients of raw store (replication)
- clean the buffer cache
- log the next checkpoint log record, which contains (repPoint, undoLWM, redoLWM) and commit checkpoint transaction.
- synchronously write the control file containing the next checkpoint log record log instant
- the new checkpoint becomes the current checkpoint. Somewhere near the beginning of each log file should be a checkpoint log record (not guarenteed to be there)
- see if the log can be truncated
The earliest useful log record is determined by the repPoint and the undoLWM, whichever is earlier.
Every log file whose log file number is smaller than the earliest useful log record's log file number can be deleted.
Transactions can be at the following states w/r to a checkpoint - consider the log as a continous stream and not as series of log files for the sake of clarity. |(BT)-------(ET)| marks the begin and end of a transaction. . checkpoint started . |__undoLWM | . V |___redoLWM . |___TruncationLWM . | . V 1 |-----------------| 2 |--------------------------------| 3 |-------| 4 |--------------------------------------(end of log) 5 |-^-| . Checkpoint Log Record ---A--->|<-------B--------->|<-------------C-----------There are only 3 periods of interest :
A) before undoLWM, B) between undo and redo LWM, C) after redoLWM.Transaction 1 started in A and terminates in B.
During redo, we should only see log records and endXact from this transaction in the first phase (between undoLWM and redoLWM). No beginXact log record for this transaction will be seen.Transaction 2 started in B (right on the undoLWM) and terminated in C.
Any transaction that terminates in C must have a beginXact at or after undoLWM. In other words, no transaction can span A, B and C. During redo, we will see beginXact, other log records and endXact for this transaction.Transaction 3 started in B and ended in B.
During redo, we will see beginXact, other log records and endXact for this transaction.Transaction 4 begins in B and never ends.
During redo, we will see beginXact, other log records. In undo, this loser transaction will be rolled back.Transaction 5 is the transaction taking the checkpoint.
The checkpoint action started way back in time but the checkpoint log record is only written after the buffer cache has been flushed.Note that if any time elapse between taking the undoLWM and the redoLWM, then it will create a 4th period of interest.
- Specified by:
checkpointin interfaceorg.apache.derby.iapi.store.raw.log.LogFactory
- switch to a new log file if possible
checkpointWithTran
protected boolean checkpointWithTran(org.apache.derby.iapi.store.raw.xact.RawTransaction cptran, org.apache.derby.iapi.store.raw.RawStoreFactory rsf, org.apache.derby.iapi.store.raw.data.DataFactory df, org.apache.derby.iapi.store.raw.xact.TransactionFactory tf) throws org.apache.derby.iapi.error.StandardException
- checkpoint with pre-start transaction
flush
public void flush(org.apache.derby.iapi.store.raw.log.LogInstant where) throws org.apache.derby.iapi.error.StandardException
- Flush all unwritten log record up to the log instance indicated to disk
and sync.
Also check to see if database is frozen or corrupt.
MT - not needed, wrapper method
- Specified by:
flushin interfaceorg.apache.derby.iapi.store.raw.log.LogFactory
flushAll
public void flushAll()
throws org.apache.derby.iapi.error.StandardException
- Flush all unwritten log record to disk and sync.
Also check to see if database is frozen or corrupt.
MT - not needed, wrapper method
verifyLogFormat
private boolean verifyLogFormat(org.apache.derby.io.StorageFile logFileName, long number) throws org.apache.derby.iapi.error.StandardException
- Verify that we the log file is of the right format and of the right
version and log file number.
MT - not needed, no global variables used
JAVADOC
org.apache.derby.impl.store.raw.log.LogToFile