org.mapdb
Class StoreWAL

java.lang.Object
  extended by org.mapdb.Store
      extended by org.mapdb.StoreDirect
          extended by org.mapdb.StoreWAL
All Implemented Interfaces:
Engine

public class StoreWAL
extends StoreDirect

Write-Ahead-Log


Field Summary
protected  long[] indexVals
           
protected  boolean[] indexValsModified
           
protected  Volume log
           
protected static long LOG_MASK_OFFSET
           
protected static long LOG_SEAL
          added to offset 8 into log file, indicates that log was synced and closed
protected  AtomicInteger logChecksum
           
protected  long logSize
           
protected  LongMap<byte[]> longStackPages
           
protected  LongConcurrentHashMap<long[]> modified
           
protected static long[] PREALLOC
           
protected  boolean replayPending
           
protected static long[] TOMBSTONE
           
static String TRANS_LOG_FILE_EXT
           
protected  Volume.Factory volFac
           
protected static byte WAL_INDEX_LONG
           
protected static byte WAL_LONGSTACK_PAGE
           
protected static byte WAL_PHYS_ARRAY
           
protected static byte WAL_PHYS_ARRAY_ONE_LONG
           
protected static byte WAL_SEAL
          last instruction in log file
protected static byte WAL_SKIP_REST_OF_BLOCK
           
 
Fields inherited from class org.mapdb.StoreDirect
DATA_FILE_EXT, deleteFilesAfterClose, freeSize, HEADER, index, indexSize, IO_FREE_RECID, IO_FREE_SIZE, IO_INDEX_SIZE, IO_INDEX_SUM, IO_PHYS_SIZE, IO_USER_START, LONG_STACK_PREF_COUNT, LONG_STACK_PREF_COUNT_ALTER, LONG_STACK_PREF_SIZE, LONG_STACK_PREF_SIZE_ALTER, MASK_ARCHIVE, MASK_DISCARD, MASK_LINKED, MASK_OFFSET, MAX_REC_SIZE, maxUsedIoList, phys, PHYS_FREE_SLOTS_COUNT, physSize, readOnly, sizeLimit, spaceReclaimReuse, spaceReclaimSplit, spaceReclaimTrack, STORE_VERSION, syncOnCommitDisabled
 
Fields inherited from class org.mapdb.Store
checksum, CHECKSUM_FLAG_MASK, CHUNK_SIZE, CHUNK_SIZE_MOD_MASK, compress, COMPRESS_FLAG_MASK, encrypt, ENCRYPT_FLAG_MASK, encryptionXTEA, locks, LOG, LZF, newRecidLock, password, recycledDataOuts, serializerPojo, serializerPojoInitLock, structuralLock
 
Fields inherited from interface org.mapdb.Engine
CATALOG_RECID, CHECK_RECORD, CLASS_INFO_RECID, LAST_RESERVED_RECID
 
Constructor Summary
StoreWAL(Volume.Factory volFac)
           
StoreWAL(Volume.Factory volFac, boolean readOnly, boolean deleteFilesAfterClose, int spaceReclaimMode, boolean syncOnCommitDisabled, long sizeLimit, boolean checksum, boolean compress, byte[] password, boolean disableLocks, int sizeIncrement)
           
 
Method Summary
 boolean canRollback()
           
protected  void checkHeaders()
           
protected  void checkLogRounding()
           
 void close()
          Close store/cache.
 void commit()
          Makes all changes made since the previous commit/rollback permanent.
protected  void compactPostUnderLock()
          subclasses put additional cleanup after compaction finishes here
protected  void compactPreUnderLock()
          subclasses put additional checks before compaction starts here
<A> boolean
compareAndSwap(long recid, A expectedOldValue, A newValue, Serializer<A> serializer)
          Updates existing record in atomic (Compare And Swap) manner.
<A> void
delete(long recid, Serializer<A> serializer)
          Remove existing record from store/cache

Recid must be a number returned by 'put' method.

<A> A
get(long recid, Serializer<A> serializer)
          Get existing record.
protected
<A> A
get2(long ioRecid, Serializer<A> serializer)
           
protected  long[] getLinkedRecordsFromLog(long ioRecid)
           
protected  long indexHeaderChecksumUncommited()
           
protected  long[] logAllocate(long[] physPos)
           
protected  void logChecksumAdd(int cs)
           
protected  boolean logDirty()
           
protected  void logReset()
           
protected  byte[] longStackGetPage(long offset)
           
protected static long longStackGetSixLong(byte[] page, int pos)
           
protected  void longStackPut(long ioList, long offset, boolean recursive)
           
protected static void longStackPutSixLong(byte[] page, int pos, long value)
           
protected  long longStackTake(long ioList, boolean recursive)
           
 long preallocate()
          Preallocates recid for not yet created record.
 void preallocate(long[] recids)
          Preallocates recids for not yet created record.
<A> long
put(A value, Serializer<A> serializer)
          Insert new record.
protected  void reloadIndexFile()
           
protected  void replayLogFile()
           
 void rollback()
          Undoes all changes made in the current transaction.
<A> void
update(long recid, A value, Serializer<A> serializer)
          Update existing record with new value.
protected  boolean verifyLogFile()
           
protected  void walIndexVal(long logPos, long ioRecid, long indexVal)
           
protected  void walPhysArray(DataOutput2 out, long[] physPos, long[] logPos)
           
 
Methods inherited from class org.mapdb.StoreDirect
calculateStatistics, clearCache, compact, countLongStackItems, createStructure, freeIoRecidPut, freeIoRecidTake, freePhysPut, freePhysTake, getCurrSize, getFreeRecids, getFreeSize, getLinkedRecordsIndexVals, getMaxRecid, getRaw, getSizeLimit, indexHeaderChecksum, isClosed, isReadOnly, physAllocate, put2, roundTo16, size2ListIoRecid, update2, updateRaw
 
Methods inherited from class org.mapdb.Store
canSnapshot, closeListenerRegister, closeListenerUnregister, deserialize, expectedMasks, forDB, forEngine, getSerializerPojo, lockAllWrite, lockPos, newDataOut2, printStatistics, serialize, snapshot, unlockAllWrite
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOG_MASK_OFFSET

protected static final long LOG_MASK_OFFSET
See Also:
Constant Field Values

WAL_INDEX_LONG

protected static final byte WAL_INDEX_LONG
See Also:
Constant Field Values

WAL_LONGSTACK_PAGE

protected static final byte WAL_LONGSTACK_PAGE
See Also:
Constant Field Values

WAL_PHYS_ARRAY_ONE_LONG

protected static final byte WAL_PHYS_ARRAY_ONE_LONG
See Also:
Constant Field Values

WAL_PHYS_ARRAY

protected static final byte WAL_PHYS_ARRAY
See Also:
Constant Field Values

WAL_SKIP_REST_OF_BLOCK

protected static final byte WAL_SKIP_REST_OF_BLOCK
See Also:
Constant Field Values

WAL_SEAL

protected static final byte WAL_SEAL
last instruction in log file

See Also:
Constant Field Values

LOG_SEAL

protected static final long LOG_SEAL
added to offset 8 into log file, indicates that log was synced and closed

See Also:
Constant Field Values

TRANS_LOG_FILE_EXT

public static final String TRANS_LOG_FILE_EXT
See Also:
Constant Field Values

TOMBSTONE

protected static final long[] TOMBSTONE

PREALLOC

protected static final long[] PREALLOC

volFac

protected final Volume.Factory volFac

log

protected Volume log

logSize

protected volatile long logSize

modified

protected final LongConcurrentHashMap<long[]> modified

longStackPages

protected final LongMap<byte[]> longStackPages

indexVals

protected final long[] indexVals

indexValsModified

protected final boolean[] indexValsModified

replayPending

protected boolean replayPending

logChecksum

protected final AtomicInteger logChecksum
Constructor Detail

StoreWAL

public StoreWAL(Volume.Factory volFac)

StoreWAL

public StoreWAL(Volume.Factory volFac,
                boolean readOnly,
                boolean deleteFilesAfterClose,
                int spaceReclaimMode,
                boolean syncOnCommitDisabled,
                long sizeLimit,
                boolean checksum,
                boolean compress,
                byte[] password,
                boolean disableLocks,
                int sizeIncrement)
Method Detail

checkHeaders

protected void checkHeaders()
Overrides:
checkHeaders in class StoreDirect

reloadIndexFile

protected void reloadIndexFile()

logReset

protected void logReset()

preallocate

public long preallocate()
Description copied from interface: Engine
Preallocates recid for not yet created record. It does not insert any data into it.

Specified by:
preallocate in interface Engine
Overrides:
preallocate in class StoreDirect
Returns:
new recid

preallocate

public void preallocate(long[] recids)
Description copied from interface: Engine
Preallocates recids for not yet created record. It does not insert any data into it. This is done in batch of given size (determied by size of array in argument)

Specified by:
preallocate in interface Engine
Overrides:
preallocate in class StoreDirect
Parameters:
recids - array to put result into

put

public <A> long put(A value,
                    Serializer<A> serializer)
Description copied from interface: Engine
Insert new record.

Specified by:
put in interface Engine
Overrides:
put in class StoreDirect
Parameters:
value - records to be added
serializer - used to convert record into/from binary form
Returns:
recid (record identifier) under which record is stored.

walPhysArray

protected void walPhysArray(DataOutput2 out,
                            long[] physPos,
                            long[] logPos)

walIndexVal

protected void walIndexVal(long logPos,
                           long ioRecid,
                           long indexVal)

logAllocate

protected long[] logAllocate(long[] physPos)

checkLogRounding

protected void checkLogRounding()

get

public <A> A get(long recid,
                 Serializer<A> serializer)
Description copied from interface: Engine
Get 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'

Specified by:
get in interface Engine
Overrides:
get in class StoreDirect
Parameters:
recid - (record identifier) under which record was persisted
serializer - used to deserialize record from binary form
Returns:
record matching given recid, or null if record is not found under given recid.

get2

protected <A> A get2(long ioRecid,
                     Serializer<A> serializer)
          throws IOException
Overrides:
get2 in class StoreDirect
Throws:
IOException

update

public <A> void update(long recid,
                       A value,
                       Serializer<A> serializer)
Description copied from interface: Engine
Update 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.

Specified by:
update in interface Engine
Overrides:
update in class StoreDirect
Parameters:
recid - (record identifier) under which record was persisted.
value - new record value to be stored
serializer - used to serialize record into binary form

compareAndSwap

public <A> boolean compareAndSwap(long recid,
                                  A expectedOldValue,
                                  A newValue,
                                  Serializer<A> serializer)
Description copied from interface: Engine
Updates 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:
  1. Equality check oldValue==expectedOldValue when old value is found in instance cache
  2. Deserializing oldValue using serializer and checking oldValue.equals(expectedOldValue)
  3. Serializing 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.

Specified by:
compareAndSwap in interface Engine
Overrides:
compareAndSwap in class StoreDirect
Parameters:
recid - (record identifier) under which record was persisted.
expectedOldValue - old value to be compared with existing record
newValue - to be written if values are matching
serializer - used to serialize record into binary form
Returns:
true if values matched and newValue was written

delete

public <A> void delete(long recid,
                       Serializer<A> serializer)
Description copied from interface: Engine
Remove 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.

Specified by:
delete in interface Engine
Overrides:
delete in class StoreDirect
Parameters:
recid - (record identifier) under which was record persisted
serializer - which may be used in some circumstances to deserialize and store old object

commit

public void commit()
Description copied from interface: Engine
Makes all changes made since the previous commit/rollback permanent. In transactional mode (on by default) it means creating journal file and replaying it to storage. In other modes it may flush disk caches or do nothing at all (check your config options)

Specified by:
commit in interface Engine
Overrides:
commit in class StoreDirect

logDirty

protected boolean logDirty()

indexHeaderChecksumUncommited

protected long indexHeaderChecksumUncommited()

verifyLogFile

protected boolean verifyLogFile()

replayLogFile

protected void replayLogFile()

rollback

public void rollback()
              throws UnsupportedOperationException
Description copied from interface: Engine
Undoes all changes made in the current transaction. If transactions are disabled it throws UnsupportedOperationException.

Specified by:
rollback in interface Engine
Overrides:
rollback in class StoreDirect
Throws:
UnsupportedOperationException - if transactions are disabled

getLinkedRecordsFromLog

protected long[] getLinkedRecordsFromLog(long ioRecid)

longStackTake

protected long longStackTake(long ioList,
                             boolean recursive)
Overrides:
longStackTake in class StoreDirect

longStackPut

protected void longStackPut(long ioList,
                            long offset,
                            boolean recursive)
Overrides:
longStackPut in class StoreDirect

longStackGetSixLong

protected static long longStackGetSixLong(byte[] page,
                                          int pos)

longStackPutSixLong

protected static void longStackPutSixLong(byte[] page,
                                          int pos,
                                          long value)

longStackGetPage

protected byte[] longStackGetPage(long offset)

close

public void close()
Description copied from interface: Engine
Close 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.closeOnJvmShutdown() which uses shutdown hook to automatically close Engine when JVM shutdowns.

Specified by:
close in interface Engine
Overrides:
close in class StoreDirect

compactPreUnderLock

protected void compactPreUnderLock()
Description copied from class: StoreDirect
subclasses put additional checks before compaction starts here

Overrides:
compactPreUnderLock in class StoreDirect

compactPostUnderLock

protected void compactPostUnderLock()
Description copied from class: StoreDirect
subclasses put additional cleanup after compaction finishes here

Overrides:
compactPostUnderLock in class StoreDirect

canRollback

public boolean canRollback()
Specified by:
canRollback in interface Engine
Overrides:
canRollback in class StoreDirect
Returns:
true if engine supports rollback

logChecksumAdd

protected void logChecksumAdd(int cs)


Copyright © 2014. All Rights Reserved.