org.mapdb
Class StoreHeap

java.lang.Object
  extended by org.mapdb.Store
      extended by org.mapdb.StoreHeap
All Implemented Interfaces:
Serializable, Engine

public class StoreHeap
extends Store
implements Serializable

Store which keeps all instances on heap. It does not use serialization.

See Also:
Serialized Form

Field Summary
protected  Queue<Long> freeRecids
          Queue of deleted recids, those are reused for new records
protected  AtomicLong maxRecid
          Maximal returned recid, incremented if there are no free recids
protected static Object NULL
           
protected  ConcurrentNavigableMap<Long,Fun.Tuple2> records
          All commited records in store
protected  ConcurrentNavigableMap<Long,Fun.Tuple2> rollback
          All not-yet commited records in store
protected static Fun.Tuple2 TOMBSTONE
           
 
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
StoreHeap()
           
 
Method Summary
 String calculateStatistics()
          get some statistics about store.
 boolean canRollback()
           
 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.
<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.
 long getCurrSize()
          returns current size occupied by physical store (does not include index).
 Iterator<Long> getFreeRecids()
           
 long getFreeSize()
          returns free size in physical store (does not include index).
 long getMaxRecid()
           
 ByteBuffer getRaw(long recid)
           
 long getSizeLimit()
          returns maximal store size or `0` if there is no limit
 boolean isClosed()
          Checks whether Engine was closed.
 boolean isReadOnly()
          Check if you can write into this Engine.
 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.
 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.
 void updateRaw(long recid, ByteBuffer data)
           
 
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

TOMBSTONE

protected static final Fun.Tuple2 TOMBSTONE

NULL

protected static final Object NULL

records

protected final ConcurrentNavigableMap<Long,Fun.Tuple2> records
All commited records in store


rollback

protected final ConcurrentNavigableMap<Long,Fun.Tuple2> rollback
All not-yet commited records in store


freeRecids

protected final Queue<Long> freeRecids
Queue of deleted recids, those are reused for new records


maxRecid

protected final AtomicLong maxRecid
Maximal returned recid, incremented if there are no free recids

Constructor Detail

StoreHeap

public StoreHeap()
Method Detail

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
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
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
Parameters:
value - records to be added
serializer - used to convert record into/from binary form
Returns:
recid (record identifier) under which record is stored.

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
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.

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
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
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
Parameters:
recid - (record identifier) under which was record persisted
serializer - which may be used in some circumstances to deserialize and store old object

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

isClosed

public boolean isClosed()
Description copied from interface: Engine
Checks whether Engine was closed.

Specified by:
isClosed in interface Engine
Returns:
true if engine was closed

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

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
Throws:
UnsupportedOperationException - if transactions are disabled

isReadOnly

public boolean isReadOnly()
Description copied from interface: Engine
Check if you can write into this Engine. It may be readonly in some cases (snapshot, read-only files).

Specified by:
isReadOnly in interface Engine
Returns:
true if engine is read-only

clearCache

public void clearCache()
Description copied from interface: Engine
clears any underlying cache

Specified by:
clearCache in interface Engine

compact

public void compact()
Specified by:
compact in interface Engine

canRollback

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

getMaxRecid

public long getMaxRecid()
Specified by:
getMaxRecid in class Store

getRaw

public ByteBuffer getRaw(long recid)
Specified by:
getRaw in class Store

getFreeRecids

public Iterator<Long> getFreeRecids()
Specified by:
getFreeRecids in class Store

updateRaw

public void updateRaw(long recid,
                      ByteBuffer data)
Specified by:
updateRaw in class Store

getSizeLimit

public long getSizeLimit()
Description copied from class: Store
returns maximal store size or `0` if there is no limit

Specified by:
getSizeLimit in class Store

getCurrSize

public long getCurrSize()
Description copied from class: Store
returns current size occupied by physical store (does not include index). It means file allocated by physical file

Specified by:
getCurrSize in class Store

getFreeSize

public long getFreeSize()
Description copied from class: Store
returns free size in physical store (does not include index).

Specified by:
getFreeSize in class Store

calculateStatistics

public String calculateStatistics()
Description copied from class: Store
get some statistics about store. This may require traversing entire store, so it can take some time.

Specified by:
calculateStatistics in class Store


Copyright © 2014. All Rights Reserved.