org.neo4j.kernel.impl.nioneo.store
Class AbstractDynamicStore

java.lang.Object
  extended by org.neo4j.kernel.impl.nioneo.store.CommonAbstractStore
      extended by org.neo4j.kernel.impl.nioneo.store.AbstractDynamicStore
All Implemented Interfaces:
RecordStore<DynamicRecord>, Store
Direct Known Subclasses:
DynamicArrayStore, DynamicStringStore

public abstract class AbstractDynamicStore
extends CommonAbstractStore
implements Store, RecordStore<DynamicRecord>

An abstract representation of a dynamic store. The difference between a normal AbstractStore and a AbstractDynamicStore is that the size of a record/entry can be dynamic.

Instead of a fixed record this class uses blocks to store a record. If a record size is greater than the block size the record will use one or more blocks to store its data.

A dynamic store don't have a IdGenerator because the position of a record can't be calculated just by knowing the id. Instead one should use a AbstractStore and store the start block of the record located in the dynamic store. Note: This class makes use of an id generator internally for managing free and non free blocks.

Note, the first block of a dynamic store is reserved and contains information about the store.


Nested Class Summary
 
Nested classes/interfaces inherited from interface org.neo4j.kernel.impl.nioneo.store.RecordStore
RecordStore.Processor
 
Field Summary
protected static int BLOCK_HEADER_SIZE
           
 
Fields inherited from class org.neo4j.kernel.impl.nioneo.store.CommonAbstractStore
ALL_STORES_VERSION, logger, storageFileName, UNKNOWN_VERSION
 
Fields inherited from interface org.neo4j.kernel.impl.nioneo.store.RecordStore
IN_USE
 
Constructor Summary
AbstractDynamicStore(String fileName, Map<?,?> config, IdType idType)
           
 
Method Summary
protected  Collection<DynamicRecord> allocateRecords(long startBlock, byte[] src)
           
protected static void createEmptyStore(String fileName, int baseBlockSize, String typeAndVersionDescriptor, IdGeneratorFactory idGeneratorFactory, IdType idType)
          Creates a new empty store.
protected  long figureOutHighestIdInUse()
           
 DynamicRecord forceGetRaw(long id)
           
 DynamicRecord forceGetRecord(long id)
           
 void forceUpdateRecord(DynamicRecord record)
           
 void freeBlockId(long blockId)
          Makes a previously used block available again.
 int getBlockSize()
          Returns the byte size of each block for this dynamic store
protected  int getEffectiveRecordSize()
           
 Collection<DynamicRecord> getLightRecords(long startBlockId)
           
 DynamicRecord getRecord(long id)
           
 int getRecordHeaderSize()
           
 Collection<DynamicRecord> getRecords(long startBlockId)
           
 int getRecordSize()
           
static int getRecordSize(int dataSize)
          Calculate the size of a dynamic record given the size of the data block.
protected  boolean isRecordInUse(ByteBuffer buffer)
           
 void logIdUsage(StringLogger logger)
           
 void makeHeavy(DynamicRecord record)
           
 long nextBlockId()
          Returns next free block.
protected  void readAndVerifyBlockSize()
           
protected  void rebuildIdGenerator()
          Rebuilds the internal id generator keeping track of what blocks are free or taken.
 String toString()
           
 void updateRecord(DynamicRecord record)
           
protected  void verifyFileSizeAndTruncate()
           
 
Methods inherited from class org.neo4j.kernel.impl.nioneo.store.CommonAbstractStore
acquireWindow, buildTypeDescriptorAndVersion, calculateMappedMemory, checkStorage, checkVersion, close, closeIdGenerator, closeStorage, createIdGenerator, flushAll, freeId, getConfig, getFileChannel, getFileSystem, getHighestPossibleIdInUse, getHighId, getIdType, getIfMemoryMapped, getNumberOfIdsInUse, getStorageFileName, getStoreDir, getStoreOk, getTypeAndVersionDescriptor, getTypeDescriptor, getWindowPoolStats, initStorage, isInRecoveryMode, loadStorage, logVersions, longFromIntAndMod, makeStoreOk, nextId, openIdGenerator, openIdGenerator, openReadOnlyIdGenerator, rebuildIdGenerators, registerIdFromUpdateRecord, releaseFileLockAndCloseFileChannel, releaseWindow, setHighId, setRecovered, setStoreNotOk, setWindowPool, unsetRecovered, updateHighId, verifyCorrectTypeDescriptorAndVersion
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.neo4j.kernel.impl.nioneo.store.Store
getHighestPossibleIdInUse, getNumberOfIdsInUse, getTypeDescriptor, getWindowPoolStats, nextId
 
Methods inherited from interface org.neo4j.kernel.impl.nioneo.store.RecordStore
accept, close, getHighId
 

Field Detail

BLOCK_HEADER_SIZE

protected static final int BLOCK_HEADER_SIZE
See Also:
Constant Field Values
Constructor Detail

AbstractDynamicStore

public AbstractDynamicStore(String fileName,
                            Map<?,?> config,
                            IdType idType)
Method Detail

createEmptyStore

protected static void createEmptyStore(String fileName,
                                       int baseBlockSize,
                                       String typeAndVersionDescriptor,
                                       IdGeneratorFactory idGeneratorFactory,
                                       IdType idType)
Creates a new empty store. A factory method returning an implementation should make use of this method to initialize an empty store. Block size must be greater than zero. Not that the first block will be marked as reserved (contains info about the block size). There will be an overhead for each block of AbstractDynamicStore.BLOCK_HEADER_SIZE bytes.

This method will create a empty store with descriptor returned by the CommonAbstractStore.getTypeDescriptor(). The internal id generator used by this store will also be created.

Parameters:
fileName - The file name of the store that will be created
blockSize - The number of bytes for each block
typeAndVersionDescriptor - The type and version descriptor that identifies this store
Throws:
IOException - If fileName is null or if file exists or illegal block size

getEffectiveRecordSize

protected int getEffectiveRecordSize()
Specified by:
getEffectiveRecordSize in class CommonAbstractStore

getRecordSize

public int getRecordSize()
Specified by:
getRecordSize in interface RecordStore<DynamicRecord>

getRecordHeaderSize

public int getRecordHeaderSize()
Specified by:
getRecordHeaderSize in interface RecordStore<DynamicRecord>

verifyFileSizeAndTruncate

protected void verifyFileSizeAndTruncate()
                                  throws IOException
Specified by:
verifyFileSizeAndTruncate in class CommonAbstractStore
Throws:
IOException

readAndVerifyBlockSize

protected void readAndVerifyBlockSize()
                               throws IOException
Specified by:
readAndVerifyBlockSize in class CommonAbstractStore
Throws:
IOException

getBlockSize

public int getBlockSize()
Returns the byte size of each block for this dynamic store

Returns:
The block size of this store

nextBlockId

public long nextBlockId()
Returns next free block.

Returns:
The next free block
Throws:
IOException - If capacity exceeded or closed id generator

freeBlockId

public void freeBlockId(long blockId)
Makes a previously used block available again.

Parameters:
blockId - The id of the block to free
Throws:
IOException - If id generator closed or illegal block id

getRecordSize

public static int getRecordSize(int dataSize)
Calculate the size of a dynamic record given the size of the data block.

Parameters:
dataSize - the size of the data block in bytes.
Returns:
the size of a dynamic record.

updateRecord

public void updateRecord(DynamicRecord record)
Specified by:
updateRecord in interface RecordStore<DynamicRecord>

forceUpdateRecord

public void forceUpdateRecord(DynamicRecord record)
Specified by:
forceUpdateRecord in interface RecordStore<DynamicRecord>

allocateRecords

protected Collection<DynamicRecord> allocateRecords(long startBlock,
                                                    byte[] src)

getLightRecords

public Collection<DynamicRecord> getLightRecords(long startBlockId)

makeHeavy

public void makeHeavy(DynamicRecord record)

isRecordInUse

protected boolean isRecordInUse(ByteBuffer buffer)

getRecord

public DynamicRecord getRecord(long id)
Specified by:
getRecord in interface RecordStore<DynamicRecord>

forceGetRecord

public DynamicRecord forceGetRecord(long id)
Specified by:
forceGetRecord in interface RecordStore<DynamicRecord>

forceGetRaw

public DynamicRecord forceGetRaw(long id)
Specified by:
forceGetRaw in interface RecordStore<DynamicRecord>

getRecords

public Collection<DynamicRecord> getRecords(long startBlockId)

rebuildIdGenerator

protected void rebuildIdGenerator()
Rebuilds the internal id generator keeping track of what blocks are free or taken.

Specified by:
rebuildIdGenerator in class CommonAbstractStore
Throws:
IOException - If unable to rebuild the id generator

figureOutHighestIdInUse

protected long figureOutHighestIdInUse()
Specified by:
figureOutHighestIdInUse in class CommonAbstractStore

logIdUsage

public void logIdUsage(StringLogger logger)
Specified by:
logIdUsage in interface Store

toString

public String toString()
Overrides:
toString in class CommonAbstractStore


Copyright © 2002-2012 The Neo4j Graph Database Project. All Rights Reserved.