public class BdbjeCacheStore extends AbstractCacheStore
CacheStore. This implementation uses
two databases namestored entries are stored here, keyed on
CacheEntry.getKey() name_class_catalog/{location}/je.properties is optional and will
override any parameters to the internal SleepyCat JE EnvironmentConfig.
BdbjeCacheStoreConfig.getLockAcquistionTimeout().
Calls to CacheStore.prepare(java.util.List, org.infinispan.transaction.xa.GlobalTransaction,
boolean) will attempt to resolve deadlocks, retrying up to BdbjeCacheStoreConfig.getMaxTxRetries()
attempts.
Unlike the C version of SleepyCat, JE does not support MVCC or READ_COMMITTED isolation. In other words, readers
will block on any data held by a pending transaction. As such, it is best practice to keep the duration between
prepare and commit as short as possible.
multiThreadedPurge, purgerServicecache, marshaller| Constructor and Description |
|---|
BdbjeCacheStore() |
| Modifier and Type | Method and Description |
|---|---|
protected void |
applyModifications(List<? extends Modification> mods)
Perform the
mods atomically by creating a worker and invoking
them in TransactionRunner.run(com.sleepycat.collections.TransactionWorker). |
void |
clear()
Clears all entries in the store
|
void |
commit(GlobalTransaction tx)
Commits a transaction that has been previously prepared.
|
protected void |
completeTransaction(GlobalTransaction tx,
boolean commit)
Looks up the SleepyCat transaction associated with the parameter
tx. |
void |
fromStream(ObjectInput ois)
Writes contents of the stream to the store.
|
Class<? extends CacheLoaderConfig> |
getConfigurationClass()
This method is used by the configuration parser to get a hold of the CacheLoader implementation's corresponding
CacheLoaderConfig type. |
void |
init(CacheLoaderConfig config,
Cache<?,?> cache,
StreamingMarshaller m)
Used to initialize a cache loader.
|
Set<InternalCacheEntry> |
load(int numEntries)
Loads up to a specific number of entries.
|
InternalCacheEntry |
load(Object key)
Loads an entry mapped to by a given key.
|
Set<InternalCacheEntry> |
loadAll()
Loads all entries in the loader.
|
Set<Object> |
loadAllKeys(Set<Object> keysToExclude)
Loads a set of all keys, excluding a filter set.
|
protected void |
prepare(List<? extends Modification> mods,
GlobalTransaction tx)
Looks up the
SleepyCat transaction associated with tx. |
void |
prepare(List<? extends Modification> mods,
GlobalTransaction tx,
boolean isOnePhase)
Issues a prepare call with a set of modifications to be applied to the cache store
|
void |
printLicense()
prints terms of use for Berkeley DB JE
|
protected void |
purgeInternal()
Iterate through
StoredMap.entrySet() and remove, if expired. |
boolean |
remove(Object key)
Removes an entry in the store.
|
void |
rollback(GlobalTransaction tx)
Rolls back a transaction that has been previously prepared
This method may be invoked on a transaction for which there is no prior
CacheStore.prepare(java.util.List, org.infinispan.transaction.xa.GlobalTransaction, boolean). |
void |
start()
Validates configuration, configures and opens the
Environment, then opens the databases. |
void |
stop()
Stops transaction and purge processing and closes the SleepyCat environment.
|
void |
store(InternalCacheEntry ed)
Stores an entry
|
void |
toStream(ObjectOutput oos)
|
getCacheStoreConfig, getConcurrencyLevel, getMarshaller, purgeExpired, removeAll, safeClose, safeClose, supportsMultiThreadedPurgecontainsKeyclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitcontainsKeypublic void init(CacheLoaderConfig config, Cache<?,?> cache, StreamingMarshaller m) throws CacheLoaderException
CacheLoaderManager
when setting up cache loaders. This implementation expects config to be an instance of BdbjeCacheStoreConfig note
that the m is not currently used as SleepyCat has its own efficient solution.init in interface CacheLoaderinit in class AbstractCacheStoreconfig - the cache loader configuration beancache - cache associated with this cache loader. Implementations may use this to determine cache name when
selecting where refer to state in storage, for example, a different database table name.m - marshaller to use when loading state from a stream, if supported by the implementation.CacheLoaderExceptionBdbjeCacheStoreConfigpublic Class<? extends CacheLoaderConfig> getConfigurationClass()
CacheLoaderConfig type. This is usually done by instantiating the CacheLoader
and then calling this method. This may result in 2 instances being created, however, since the instance
created to get a hold of the configuration type is then discarded and another instance is created for actual
use as a CacheLoader when the cache starts.
Since Infinispan 4.1, you can also annotate your CacheLoader implementation with CacheLoaderMetadata
and provide this information via the annotation, which will prevent unnecessary instances being created.
BdbjeCacheStoreConfigpublic void start()
throws CacheLoaderException
Environment, then opens the databases. When this is
finished, transactional and purging services are instantiated.start in interface CacheLoaderstart in class AbstractCacheStoreCacheLoaderExceptionpublic void stop()
throws CacheLoaderException
stop in interface CacheLoaderstop in class AbstractCacheStoreCacheLoaderExceptionpublic void prepare(List<? extends Modification> mods, GlobalTransaction tx, boolean isOnePhase) throws CacheLoaderException
applyModifications(java.util.List), if
isOnePhase. Otherwise, delegates to prepare(java.util.List,
org.infinispan.transaction.xa.GlobalTransaction)prepare in interface CacheStoreprepare in class AbstractCacheStoremods - modifications to be appliedtx - transaction identifierisOnePhase - if true, there will not be a commit or rollback phase and changes should be flushed
immediatelyCacheLoaderException - in the event of problems writing to the storeprotected void applyModifications(List<? extends Modification> mods) throws CacheLoaderException
mods atomically by creating a worker and invoking
them in TransactionRunner.run(com.sleepycat.collections.TransactionWorker).applyModifications in class AbstractCacheStoremods - actions to perform atomicallyCacheLoaderException - on problems during the transactionprotected void prepare(List<? extends Modification> mods, GlobalTransaction tx) throws CacheLoaderException
SleepyCat transaction associated with tx. Creates a ModificationsTransactionWorker instance from mods. Then prepares the
transaction via PreparableTransactionRunner.prepare(com.sleepycat.collections.TransactionWorker).
Finally, it invalidates CurrentTransaction.getTransaction() so that no other
thread can accidentally commit this.mods - modifications to be appliedtx - transaction identifierCacheLoaderException - in the event of problems writing to the storepublic void rollback(GlobalTransaction tx)
CacheStore.prepare(java.util.List, org.infinispan.transaction.xa.GlobalTransaction, boolean). The implementation would
need to deal with this case accordingly. Typically, this would be a no-op, after ensuring any resources attached
to the transaction are cleared up.
Also note that this method may be invoked on a thread which is different from the CacheStore.prepare(java.util.List, org.infinispan.transaction.xa.GlobalTransaction, boolean) invocation. As such, ThreadLocals should not be relied upon to maintain transaction context.
This implementation calls completeTransaction(org.infinispan.transaction.xa.GlobalTransaction,
boolean) completeTransaction} with an argument of false.rollback in interface CacheStorerollback in class AbstractCacheStoretx - tx to roll backpublic void commit(GlobalTransaction tx) throws CacheLoaderException
CacheStore.prepare(java.util.List, org.infinispan.transaction.xa.GlobalTransaction, boolean). The implementation would
need to deal with this case accordingly. Typically, this would be a no-op, after ensuring any resources attached
to the transaction are cleared up.
Also note that this method may be invoked on a thread which is different from the CacheStore.prepare(java.util.List, org.infinispan.transaction.xa.GlobalTransaction, boolean) invocation. As such, ThreadLocals should not be relied upon to maintain transaction context.
This implementation calls completeTransaction(org.infinispan.transaction.xa.GlobalTransaction,
boolean) completeTransaction} with an argument of true.commit in interface CacheStorecommit in class AbstractCacheStoretx - tx to commitCacheLoaderException - in the event of problems writing to the storeprotected void completeTransaction(GlobalTransaction tx, boolean commit) throws CacheLoaderException
tx. If there is no associated
sleepycat transaction, an error is logged.tx - java transaction used to lookup a SleepyCat transactioncommit - true to commit false to abortCacheLoaderException - if there are problems committing or aborting the transactionpublic boolean remove(Object key) throws CacheLoaderException
StoredMap.remove(Object)key - key to removeCacheLoaderException - in the event of problems writing to the storepublic InternalCacheEntry load(Object key) throws CacheLoaderException
StoredMap.get(Object). If the object is expired, it will
not be returned.key - keyCacheLoaderException - in the event of problems reading from sourcepublic void store(InternalCacheEntry ed) throws CacheLoaderException
StoredMap.put(Object, Object)ed - entry to storeCacheLoaderException - in the event of problems writing to the storepublic void clear()
throws CacheLoaderException
StoredContainer.clear()CacheLoaderException - in the event of problems writing to the storepublic Set<InternalCacheEntry> loadAll() throws CacheLoaderException
StoredMap.values()CacheLoaderException - in the event of problems reading from sourcepublic Set<InternalCacheEntry> load(int numEntries) throws CacheLoaderException
CacheLoadernumEntries - maximum number of entries to loadCacheLoaderExceptionpublic Set<Object> loadAllKeys(Set<Object> keysToExclude) throws CacheLoaderException
CacheLoaderkeysToExclude - a set of keys to exclude. An empty set or null will indicate that all keys should be returned.CacheLoaderExceptionpublic void fromStream(ObjectInput ois) throws CacheLoaderException
CacheStore.toStream(java.io.ObjectOutput). While not a
requirement, it is recommended that implementations make use of the StreamingMarshaller
when dealing with the stream to make use of efficient marshalling.
It is imperative that implementations do not close the stream after finishing with it.
It is also recommended that implementations use their own start and end markers on the stream since
other processes may write additional data to the stream after the cache store has written to it. As such, either
markers or some other mechanism to prevent the store from reading too much information should be employed when
writing to the stream in CacheStore.fromStream(java.io.ObjectInput) to prevent data corruption.
It can be assumed that the stream passed in already performs buffering such that the cache store implementation
doesn't have to.
This implementation reads the number of entries to load from the stream, then begins a transaction.
During that transaction, the cachestore is cleared and replaced with entries from the stream. If there are any
errors during the process, the entire transaction is rolled back. Deadlock handling is not addressed, as there
is no means to rollback reads from the input stream.ois - stream to read fromCacheLoaderException - in the event of problems writing to the storetoStream(java.io.ObjectOutput)public void toStream(ObjectOutput oos) throws CacheLoaderException
key value.
This implementation holds a transaction open to ensure that we see no new records added while iterating.oos - stream to write toCacheLoaderException - in the event of problems reading from the storeprotected void purgeInternal()
throws CacheLoaderException
StoredMap.entrySet() and remove, if expired.purgeInternal in class AbstractCacheStoreCacheLoaderExceptionpublic void printLicense()
Copyright © 2017 JBoss, a division of Red Hat. All Rights Reserved.