public class TxEngine extends Object implements Engine
Naive implementation of Snapshots on top of StorageEngine. On update it takes old value and stores it aside.
TODO merge snapshots down with Storage for best performance| Modifier and Type | Class and Description |
|---|---|
class |
TxEngine.Tx |
Engine.CloseOnJVMShutdown, Engine.ReadOnly, Engine.ReadOnlyWrapper| Modifier and Type | Field and Description |
|---|---|
protected ReentrantReadWriteLock |
commitLock |
protected Engine |
engine |
protected boolean |
fullTx |
protected int |
lockMask |
protected ReentrantReadWriteLock[] |
locks |
protected int |
lockScale |
protected int |
PREALLOC_RECID_SIZE |
protected Queue<Long> |
preallocRecids |
protected static Object |
TOMBSTONE |
protected ReferenceQueue<TxEngine.Tx> |
txQueue |
protected Set<Reference<TxEngine.Tx>> |
txs |
protected boolean |
uncommitedData |
CLOSED_ENGINE, RECID_CLASS_CATALOG, RECID_FIRST, RECID_LAST_RESERVED, RECID_NAME_CATALOG, RECID_RECORD_CHECK| Modifier | Constructor and Description |
|---|---|
protected |
TxEngine(Engine engine,
boolean fullTx,
int lockScale) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
canRollback() |
boolean |
canSnapshot() |
protected void |
cleanTxQueue() |
void |
clearCache()
clears any underlying cache
|
void |
close()
Close store/cache.
|
void |
commit()
Makes all changes made since the previous commit/rollback permanent.
|
void |
compact() |
<A> boolean |
compareAndSwap(long recid,
A expectedOldValue,
A newValue,
Serializer<A> serializer)
Updates existing record in atomic (Compare And Swap) manner.
|
static Engine |
createSnapshotFor(Engine engine) |
<A> void |
delete(long recid,
Serializer<A> serializer)
Remove existing record from store/cache
|
<A> A |
get(long recid,
Serializer<A> serializer)
Get existing record.
|
Engine |
getWrappedEngine()
if this is wrapper return underlying engine, or null
|
boolean |
isClosed()
Checks whether Engine was closed.
|
boolean |
isReadOnly()
Check if you can write into this Engine.
|
protected int |
lockPos(long recid) |
long |
preallocate()
Preallocates recid for not yet created record.
|
protected Long |
preallocRecidTake() |
<A> long |
put(A value,
Serializer<A> serializer)
Insert new record.
|
void |
rollback()
Undoes all changes made in the current transaction.
|
Engine |
snapshot()
Returns read-only snapshot of data in Engine.
|
protected void |
superCommit() |
protected <A> void |
superDelete(long recid,
Serializer<A> serializer) |
protected <A> A |
superGet(long recid,
Serializer<A> serializer) |
protected <A> void |
superUpdate(long recid,
A value,
Serializer<A> serializer) |
<A> void |
update(long recid,
A value,
Serializer<A> serializer)
Update existing record with new value.
|
protected static final Object TOMBSTONE
protected final ReentrantReadWriteLock commitLock
protected final ReentrantReadWriteLock[] locks
protected final int lockScale
protected final int lockMask
protected volatile boolean uncommitedData
protected Set<Reference<TxEngine.Tx>> txs
protected ReferenceQueue<TxEngine.Tx> txQueue
protected final boolean fullTx
protected final int PREALLOC_RECID_SIZE
protected final Engine engine
protected TxEngine(Engine engine, boolean fullTx, int lockScale)
protected Long preallocRecidTake()
public boolean canSnapshot()
canSnapshot in interface Enginepublic Engine snapshot()
Enginepublic Engine getWrappedEngine()
EnginegetWrappedEngine in interface Enginepublic void clearCache()
EngineclearCache in interface Engineprotected void cleanTxQueue()
public long preallocate()
Enginepreallocate in interface Enginepublic <A> long put(A value,
Serializer<A> serializer)
Enginepublic <A> A get(long recid,
Serializer<A> serializer)
EngineGet existing record.
Recid must be a number returned by 'put' method. Behaviour for invalid recid (random number or already deleted record) is not defined, typically it returns null or throws 'EndOfFileException'
public <A> void update(long recid,
A value,
Serializer<A> serializer)
EngineUpdate existing record with new value.
Recid must be a number returned by 'put' method. Behaviour for invalid recid (random number or already deleted record) is not defined, typically it throws 'EndOfFileException', but it may also corrupt store.
public <A> boolean compareAndSwap(long recid,
A expectedOldValue,
A newValue,
Serializer<A> serializer)
EngineUpdates existing record in atomic (Compare And Swap) manner. Value is modified only if old value matches expected value. There are three ways to match values, MapDB may use any of them:
oldValue==expectedOldValue when old value is found in instance cacheoldValue using serializer and checking oldValue.equals(expectedOldValue)expectedOldValue using serializer and comparing binary array with already serialized oldValue
Recid must be a number returned by 'put' method. Behaviour for invalid recid (random number or already deleted record) is not defined, typically it throws 'EndOfFileException', but it may also corrupt store.
compareAndSwap in interface Enginerecid - (record identifier) under which record was persisted.expectedOldValue - old value to be compared with existing recordnewValue - to be written if values are matchingserializer - used to serialize record into binary formpublic <A> void delete(long recid,
Serializer<A> serializer)
EngineRemove existing record from store/cache
Recid must be a number returned by 'put' method. Behaviour for invalid recid (random number or already deleted record) is not defined, typically it throws 'EndOfFileException', but it may also corrupt store.
public void close()
EngineClose store/cache. This method must be called before JVM exits to flush all caches and prevent store corruption. Also it releases resources used by MapDB (disk, memory..).
Engine can no longer be used after this method was called. If Engine is used after closing, it may
throw any exception including NullPointerException
There is an configuration option DBMaker.Maker.closeOnJvmShutdown() which uses shutdown hook to automatically
close Engine when JVM shutdowns.
public boolean isClosed()
Enginepublic void commit()
Enginepublic void rollback()
EngineUnsupportedOperationException.public boolean isReadOnly()
EngineisReadOnly in interface Enginepublic boolean canRollback()
canRollback in interface Engineprotected void superCommit()
protected <A> void superUpdate(long recid,
A value,
Serializer<A> serializer)
protected <A> void superDelete(long recid,
Serializer<A> serializer)
protected <A> A superGet(long recid,
Serializer<A> serializer)
protected final int lockPos(long recid)
Copyright © 2015. All Rights Reserved.