Package org.apache.activemq.store.kahadb
Class AbstractKahaDBStore
java.lang.Object
org.apache.activemq.util.ServiceSupport
org.apache.activemq.broker.LockableServiceSupport
org.apache.activemq.store.kahadb.AbstractKahaDBStore
- All Implemented Interfaces:
BrokerServiceAware,Lockable,org.apache.activemq.Service
- Direct Known Subclasses:
JobSchedulerStoreImpl
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanprotected booleanprotected booleanprotected longprotected ReentrantReadWriteLockprotected Threadprotected final Objectprotected booleanprotected longprotected booleanprotected Fileprotected Fileprotected booleanprotected booleanprotected booleanprotected booleanprotected booleanprotected booleanprotected booleanprotected booleanprotected intprotected floatprotected ReentrantReadWriteLockprotected intprotected Journalprotected intprotected intprotected AtomicLongstatic final intprotected AtomicBooleanprotected PageFilestatic final Stringprotected booleanprotected booleanFields inherited from class org.apache.activemq.broker.LockableServiceSupport
brokerService, clockDaemon -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidcheckpointCleanup(boolean cleanup) Called from the worker thread to start a checkpoint.protected voidcheckpointUpdate(boolean cleanup) Perform a checkpoint operation with optional cleanup.protected abstract voidcheckpointUpdate(Transaction tx, boolean cleanup) Perform the checkpoint update operation.protected JournalCreate a new Journal instance and configure it using the currently set configuration options.protected PageFileCreate the PageFile instance and configure it using the configuration options currently set.protected voiddoStart()protected voiddoStop(ServiceStopper stopper) longlongbooleanprotected abstract Fileintfloatintintintprotected abstract Stringvoidinit()booleanbooleanbooleanbooleanbooleanbooleanbooleanbooleanbooleanbooleanbooleanbooleanbooleanbooleanbooleanabstract voidload()Loads the store from disk.protected JournalCommand<?>Loads a previously stored JournalMessageprotected abstract voidprocess(JournalCommand<?> command, Location location) Process a stored or recovered JournalCommand instance and update the DB Index with the state changes that this command produces.voidsetArchiveCorruptedIndex(boolean archiveCorruptedIndex) voidsetArchiveDataLogs(boolean archiveDataLogs) voidsetCheckForCorruptJournalFiles(boolean checkForCorruptJournalFiles) voidsetCheckpointInterval(long checkpointInterval) voidsetChecksumJournalFiles(boolean checksumJournalFiles) voidsetCleanupInterval(long cleanupInterval) voidsetCleanupOnStop(boolean cleanupOnStop) voidsetDeleteAllJobs(boolean deleteAllJobs) voidsetDirectory(File directory) voidsetDirectoryArchive(File directoryArchive) voidsetEnableIndexDiskSyncs(boolean enableIndexDiskSyncs) voidsetEnableIndexPageCaching(boolean enableIndexPageCaching) voidsetEnableIndexRecoveryFile(boolean enableIndexRecoveryFile) voidsetEnableIndexWriteAsync(boolean enableIndexWriteAsync) voidsetEnableJournalDiskSyncs(boolean syncWrites) voidsetFailIfDatabaseIsLocked(boolean failIfDatabaseIsLocked) voidsetForceRecoverIndex(boolean forceRecoverIndex) voidsetIgnoreMissingJournalfiles(boolean ignoreMissingJournalfiles) voidsetIndexCacheSize(int indexCacheSize) voidsetIndexLFUEvictionFactor(float indexLFUEvictionFactor) voidsetIndexWriteBatchSize(int indexWriteBatchSize) voidsetJournalMaxFileLength(int journalMaxFileLength) voidsetJournalMaxWriteBatchSize(int journalMaxWriteBatchSize) voidsetPurgeStoreOnStartup(boolean purge) voidsetUseIndexLFRUEviction(boolean useIndexLFRUEviction) longsize()protected voidStarts the checkpoint Thread instance if not already running and not disabled by configuration.store(JournalCommand<?> command) Store a command in the Journal and process to update the Store index.store(JournalCommand<?> command, boolean sync) Store a command in the Journal and process to update the Store index.store(JournalCommand<?> command, boolean sync, Runnable before, Runnable after) Store a command in the Journal and process to update the Store index.store(JournalCommand<?> command, boolean sync, Runnable before, Runnable after, Runnable onJournalStoreComplete) All updated are are funneled through this method.store(JournalCommand<?> command, Runnable onJournalStoreComplete) Store a command in the Journal and process to update the Store index.protected ByteSequencetoByteSequence(JournalCommand<?> data) Creates a new ByteSequence that represents the marshaled form of the given Journal Command.abstract voidunload()Unload the state of the Store to disk and shuts down all resources assigned to this KahaDB store implementation.Methods inherited from class org.apache.activemq.broker.LockableServiceSupport
getBrokerService, getLocker, getLockKeepAlivePeriod, getScheduledThreadPoolExecutor, isStopOnError, isUseLock, keepLockAlive, postStop, preStart, setBrokerService, setLocker, setLockKeepAlivePeriod, setScheduledThreadPoolExecutor, setStopOnError, setUseLock, stopBrokerMethods inherited from class org.apache.activemq.util.ServiceSupport
addServiceListener, dispose, isStarted, isStopped, isStopping, removeServiceListener, start, stop
-
Field Details
-
PROPERTY_LOG_SLOW_ACCESS_TIME
- See Also:
-
LOG_SLOW_ACCESS_TIME
public static final int LOG_SLOW_ACCESS_TIME -
directory
-
pageFile
-
journal
-
journalSize
-
failIfDatabaseIsLocked
protected boolean failIfDatabaseIsLocked -
checkpointInterval
protected long checkpointInterval -
cleanupInterval
protected long cleanupInterval -
checkForCorruptJournalFiles
protected boolean checkForCorruptJournalFiles -
checksumJournalFiles
protected boolean checksumJournalFiles -
forceRecoverIndex
protected boolean forceRecoverIndex -
journalMaxFileLength
protected int journalMaxFileLength -
journalMaxWriteBatchSize
protected int journalMaxWriteBatchSize -
archiveCorruptedIndex
protected boolean archiveCorruptedIndex -
enableIndexWriteAsync
protected boolean enableIndexWriteAsync -
enableJournalDiskSyncs
protected boolean enableJournalDiskSyncs -
deleteAllJobs
protected boolean deleteAllJobs -
indexWriteBatchSize
protected int indexWriteBatchSize -
useIndexLFRUEviction
protected boolean useIndexLFRUEviction -
indexLFUEvictionFactor
protected float indexLFUEvictionFactor -
ignoreMissingJournalfiles
protected boolean ignoreMissingJournalfiles -
indexCacheSize
protected int indexCacheSize -
enableIndexDiskSyncs
protected boolean enableIndexDiskSyncs -
enableIndexRecoveryFile
protected boolean enableIndexRecoveryFile -
enableIndexPageCaching
protected boolean enableIndexPageCaching -
archiveDataLogs
protected boolean archiveDataLogs -
purgeStoreOnStartup
protected boolean purgeStoreOnStartup -
directoryArchive
-
opened
-
checkpointThread
-
checkpointThreadLock
-
checkpointLock
-
indexLock
-
-
Constructor Details
-
AbstractKahaDBStore
public AbstractKahaDBStore()
-
-
Method Details
-
getPageFileName
- Returns:
- the name to give this store's PageFile instance.
-
getDefaultDataDirectory
- Returns:
- the location of the data directory if no set by configuration.
-
load
Loads the store from disk. Based on configuration this method can either load an existing store or it can purge an existing store and start in a clean state.- Throws:
IOException- if an error occurs during the load.
-
unload
Unload the state of the Store to disk and shuts down all resources assigned to this KahaDB store implementation.- Throws:
IOException- if an error occurs during the store unload.
-
doStart
- Specified by:
doStartin classServiceSupport- Throws:
Exception
-
doStop
- Specified by:
doStopin classServiceSupport- Throws:
Exception
-
getPageFile
-
getJournal
- Throws:
IOException
-
getDirectory
-
setDirectory
-
isArchiveCorruptedIndex
public boolean isArchiveCorruptedIndex() -
setArchiveCorruptedIndex
public void setArchiveCorruptedIndex(boolean archiveCorruptedIndex) -
isFailIfDatabaseIsLocked
public boolean isFailIfDatabaseIsLocked() -
setFailIfDatabaseIsLocked
public void setFailIfDatabaseIsLocked(boolean failIfDatabaseIsLocked) -
isCheckForCorruptJournalFiles
public boolean isCheckForCorruptJournalFiles() -
setCheckForCorruptJournalFiles
public void setCheckForCorruptJournalFiles(boolean checkForCorruptJournalFiles) -
getCheckpointInterval
public long getCheckpointInterval() -
setCheckpointInterval
public void setCheckpointInterval(long checkpointInterval) -
getCleanupInterval
public long getCleanupInterval() -
setCleanupInterval
public void setCleanupInterval(long cleanupInterval) -
setCleanupOnStop
public void setCleanupOnStop(boolean cleanupOnStop) -
getCleanupOnStop
public boolean getCleanupOnStop() -
isChecksumJournalFiles
public boolean isChecksumJournalFiles() -
setChecksumJournalFiles
public void setChecksumJournalFiles(boolean checksumJournalFiles) -
isForceRecoverIndex
public boolean isForceRecoverIndex() -
setForceRecoverIndex
public void setForceRecoverIndex(boolean forceRecoverIndex) -
getJournalMaxFileLength
public int getJournalMaxFileLength() -
setJournalMaxFileLength
public void setJournalMaxFileLength(int journalMaxFileLength) -
getJournalMaxWriteBatchSize
public int getJournalMaxWriteBatchSize() -
setJournalMaxWriteBatchSize
public void setJournalMaxWriteBatchSize(int journalMaxWriteBatchSize) -
isEnableIndexWriteAsync
public boolean isEnableIndexWriteAsync() -
setEnableIndexWriteAsync
public void setEnableIndexWriteAsync(boolean enableIndexWriteAsync) -
isEnableJournalDiskSyncs
public boolean isEnableJournalDiskSyncs() -
setEnableJournalDiskSyncs
public void setEnableJournalDiskSyncs(boolean syncWrites) -
isDeleteAllJobs
public boolean isDeleteAllJobs() -
setDeleteAllJobs
public void setDeleteAllJobs(boolean deleteAllJobs) -
isArchiveDataLogs
public boolean isArchiveDataLogs()- Returns:
- the archiveDataLogs
-
setArchiveDataLogs
public void setArchiveDataLogs(boolean archiveDataLogs) - Parameters:
archiveDataLogs- the archiveDataLogs to set
-
getDirectoryArchive
- Returns:
- the directoryArchive
-
setDirectoryArchive
- Parameters:
directoryArchive- the directoryArchive to set
-
getIndexCacheSize
public int getIndexCacheSize() -
setIndexCacheSize
public void setIndexCacheSize(int indexCacheSize) -
getIndexWriteBatchSize
public int getIndexWriteBatchSize() -
setIndexWriteBatchSize
public void setIndexWriteBatchSize(int indexWriteBatchSize) -
isUseIndexLFRUEviction
public boolean isUseIndexLFRUEviction() -
setUseIndexLFRUEviction
public void setUseIndexLFRUEviction(boolean useIndexLFRUEviction) -
getIndexLFUEvictionFactor
public float getIndexLFUEvictionFactor() -
setIndexLFUEvictionFactor
public void setIndexLFUEvictionFactor(float indexLFUEvictionFactor) -
isEnableIndexDiskSyncs
public boolean isEnableIndexDiskSyncs() -
setEnableIndexDiskSyncs
public void setEnableIndexDiskSyncs(boolean enableIndexDiskSyncs) -
isEnableIndexRecoveryFile
public boolean isEnableIndexRecoveryFile() -
setEnableIndexRecoveryFile
public void setEnableIndexRecoveryFile(boolean enableIndexRecoveryFile) -
isEnableIndexPageCaching
public boolean isEnableIndexPageCaching() -
setEnableIndexPageCaching
public void setEnableIndexPageCaching(boolean enableIndexPageCaching) -
isPurgeStoreOnStartup
public boolean isPurgeStoreOnStartup() -
setPurgeStoreOnStartup
public void setPurgeStoreOnStartup(boolean purge) -
isIgnoreMissingJournalfiles
public boolean isIgnoreMissingJournalfiles() -
setIgnoreMissingJournalfiles
public void setIgnoreMissingJournalfiles(boolean ignoreMissingJournalfiles) -
size
public long size() -
createDefaultLocker
- Throws:
IOException
-
init
- Specified by:
initin classLockableServiceSupport- Throws:
Exception
-
store
Store a command in the Journal and process to update the Store index.- Parameters:
command- The specific JournalCommand to store and process.- Throws:
IOException- if an error occurs storing or processing the command.
-
store
Store a command in the Journal and process to update the Store index.- Parameters:
command- The specific JournalCommand to store and process.sync- Should the store operation be done synchronously. (ignored if completion passed).- Throws:
IOException- if an error occurs storing or processing the command.
-
store
public Location store(JournalCommand<?> command, Runnable onJournalStoreComplete) throws IOException Store a command in the Journal and process to update the Store index.- Parameters:
command- The specific JournalCommand to store and process.onJournalStoreComplete- The Runnable to call when the Journal write operation completes.- Throws:
IOException- if an error occurs storing or processing the command.
-
store
public Location store(JournalCommand<?> command, boolean sync, Runnable before, Runnable after) throws IOException Store a command in the Journal and process to update the Store index.- Parameters:
command- The specific JournalCommand to store and process.sync- Should the store operation be done synchronously. (ignored if completion passed).before- The Runnable instance to execute before performing the store and process operation.after- The Runnable instance to execute after performing the store and process operation.- Throws:
IOException- if an error occurs storing or processing the command.
-
store
public Location store(JournalCommand<?> command, boolean sync, Runnable before, Runnable after, Runnable onJournalStoreComplete) throws IOException All updated are are funneled through this method. The updates are converted to a JournalMessage which is logged to the journal and then the data from the JournalMessage is used to update the index just like it would be done during a recovery process.- Parameters:
command- The specific JournalCommand to store and process.sync- Should the store operation be done synchronously. (ignored if completion passed).before- The Runnable instance to execute before performing the store and process operation.after- The Runnable instance to execute after performing the store and process operation.onJournalStoreComplete- Callback to be run when the journal write operation is complete.- Throws:
IOException- if an error occurs storing or processing the command.
-
load
Loads a previously stored JournalMessage- Parameters:
location- The location of the journal command to read.- Returns:
- a new un-marshaled JournalCommand instance.
- Throws:
IOException- if an error occurs reading the stored command.
-
process
Process a stored or recovered JournalCommand instance and update the DB Index with the state changes that this command produces. This can be called either as a new DB operation or as a replay during recovery operations.- Parameters:
command- The JournalCommand to process.location- The location in the Journal where the command was written or read from.- Throws:
IOException
-
checkpointUpdate
Perform a checkpoint operation with optional cleanup. Called by the checkpoint background thread periodically to initiate a checkpoint operation and if the cleanup flag is set a cleanup sweep should be done to allow for release of no longer needed journal log files etc.- Parameters:
cleanup- Should the method do a simple checkpoint or also perform a journal cleanup.- Throws:
IOException- if an error occurs during the checkpoint operation.
-
checkpointUpdate
Perform the checkpoint update operation. If the cleanup flag is true then the operation should also purge any unused Journal log files. This method must always be called with the checkpoint and index write locks held.- Parameters:
tx- The TX under which to perform the checkpoint update.cleanup- Should the checkpoint also do unused Journal file cleanup.- Throws:
IOException- if an error occurs while performing the checkpoint.
-
toByteSequence
Creates a new ByteSequence that represents the marshaled form of the given Journal Command.- Parameters:
data- The Journal Command that should be marshaled to bytes for writing.- Returns:
- the byte representation of the given journal command.
- Throws:
IOException- if an error occurs while serializing the command.
-
createPageFile
Create the PageFile instance and configure it using the configuration options currently set.- Returns:
- the newly created and configured PageFile instance.
-
createJournal
Create a new Journal instance and configure it using the currently set configuration options. If an archive directory is configured than this method will attempt to create that directory if it does not already exist.- Returns:
- the newly created an configured Journal instance.
- Throws:
IOException- if an error occurs while creating the Journal object.
-
startCheckpoint
protected void startCheckpoint()Starts the checkpoint Thread instance if not already running and not disabled by configuration. -
checkpointCleanup
Called from the worker thread to start a checkpoint. This method ensure that the store is in an opened state and optionaly logs information related to slow store access times.- Parameters:
cleanup- Should a cleanup of the journal occur during the checkpoint operation.- Throws:
IOException- if an error occurs during the checkpoint operation.
-