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

java.lang.Object
  extended by org.neo4j.kernel.impl.nioneo.store.CommonAbstractStore
Direct Known Subclasses:
AbstractDynamicStore, AbstractStore

public abstract class CommonAbstractStore
extends Object

Contains common implementation for AbstractStore and AbstractDynamicStore.


Field Summary
static String ALL_STORES_VERSION
           
protected static Logger logger
           
protected  String storageFileName
           
static String UNKNOWN_VERSION
           
 
Constructor Summary
CommonAbstractStore(String fileName, Map<?,?> config, IdType idType)
          Opens and validates the store contained in fileName loading any configuration defined in config.
 
Method Summary
protected  PersistenceWindow acquireWindow(long position, OperationType type)
          Acquires a PersistenceWindow for position and operation type.
static String buildTypeDescriptorAndVersion(String typeDescriptor)
           
static long calculateMappedMemory(Map<?,?> config, String storageFileName)
          Returns memory assigned for memory mapped windows in bytes.
protected  void checkStorage()
           
protected  void checkVersion()
           
 void close()
          Closes this store.
protected  void closeIdGenerator()
          Closed the IdGenerator used by this store
protected  void closeStorage()
          This method should close/release all resources that the implementation of this store has allocated and is called just before the close() method returns.
protected  void createIdGenerator(String fileName)
           
protected abstract  long figureOutHighestIdInUse()
           
 void flushAll()
           
 void freeId(long id)
          Frees an id for this store's IdGenerator.
 Map<?,?> getConfig()
          Returns the configuration map if set in constructor.
protected abstract  int getEffectiveRecordSize()
           
protected  FileChannel getFileChannel()
          Returns a FileChannel to this storage's file.
protected  FileSystemAbstraction getFileSystem()
           
 long getHighestPossibleIdInUse()
           
 long getHighId()
          Return the highest id in use.
 IdType getIdType()
           
protected  boolean getIfMemoryMapped()
           
 long getNumberOfIdsInUse()
           
 String getStorageFileName()
          Returns the name of this store.
protected  String getStoreDir()
           
protected  boolean getStoreOk()
          If store is "not ok" false is returned.
 String getTypeAndVersionDescriptor()
           
abstract  String getTypeDescriptor()
          Returns the type and version that identifies this store.
 WindowPoolStats getWindowPoolStats()
           
protected  void initStorage()
          Called from the constructor after the end header has been checked.
 boolean isInRecoveryMode()
           
protected  void loadStorage()
          Should do first validation on store validating stuff like version and id generator.
 void logVersions(StringLogger msgLog)
           
protected static long longFromIntAndMod(long base, long modifier)
           
 void makeStoreOk()
          If store is not ok a call to this method will rebuild the IdGenerator used by this store and if successful mark it as ok.
 long nextId()
          Returns the next id for this store's IdGenerator.
protected  void openIdGenerator(boolean firstTime)
          Opens the IdGenerator used by this store.
protected  IdGenerator openIdGenerator(String fileName, int grabSize, boolean firstTime)
           
protected  void openReadOnlyIdGenerator(int recordSize)
           
protected abstract  void readAndVerifyBlockSize()
           
protected abstract  void rebuildIdGenerator()
          Should rebuild the id generator from scratch.
 void rebuildIdGenerators()
           
protected  void registerIdFromUpdateRecord(long id)
           
protected  void releaseFileLockAndCloseFileChannel()
           
protected  void releaseWindow(PersistenceWindow window)
          Releases the window and writes the data (async) if the window was a PersistenceRow.
 void setHighId(long highId)
          Sets the highest id in use (use this when rebuilding id generator).
protected  void setRecovered()
           
protected  void setStoreNotOk(Throwable cause)
          Marks this store as "not ok".
protected  void setWindowPool(PersistenceWindowPool pool)
          Sets the PersistenceWindowPool for this store to use.
 String toString()
           
protected  void unsetRecovered()
           
protected  void updateHighId()
           
protected  void verifyCorrectTypeDescriptorAndVersion()
           
protected abstract  void verifyFileSizeAndTruncate()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ALL_STORES_VERSION

public static final String ALL_STORES_VERSION
See Also:
Constant Field Values

UNKNOWN_VERSION

public static final String UNKNOWN_VERSION
See Also:
Constant Field Values

logger

protected static final Logger logger

storageFileName

protected final String storageFileName
Constructor Detail

CommonAbstractStore

public CommonAbstractStore(String fileName,
                           Map<?,?> config,
                           IdType idType)
Opens and validates the store contained in fileName loading any configuration defined in config. After validation the initStorage method is called.

If the store had a clean shutdown it will be marked as ok and the getStoreOk() method will return true. If a problem was found when opening the store the makeStoreOk() must be invoked. throws IOException if the unable to open the storage or if the initStorage method fails

Parameters:
fileName - The name of the store
config - The configuration for store (may be null)
idType - The Id used to index into this store
Method Detail

getTypeAndVersionDescriptor

public String getTypeAndVersionDescriptor()

buildTypeDescriptorAndVersion

public static String buildTypeDescriptorAndVersion(String typeDescriptor)

logVersions

public void logVersions(StringLogger msgLog)

longFromIntAndMod

protected static long longFromIntAndMod(long base,
                                        long modifier)

getTypeDescriptor

public abstract String getTypeDescriptor()
Returns the type and version that identifies this store.

Returns:
This store's implementation type and version identifier

checkStorage

protected void checkStorage()

checkVersion

protected void checkVersion()

loadStorage

protected void loadStorage()
Should do first validation on store validating stuff like version and id generator. This method is called by constructors.


getEffectiveRecordSize

protected abstract int getEffectiveRecordSize()

verifyFileSizeAndTruncate

protected abstract void verifyFileSizeAndTruncate()
                                           throws IOException
Throws:
IOException

readAndVerifyBlockSize

protected abstract void readAndVerifyBlockSize()
                                        throws IOException
Throws:
IOException

verifyCorrectTypeDescriptorAndVersion

protected void verifyCorrectTypeDescriptorAndVersion()
                                              throws IOException
Throws:
IOException

rebuildIdGenerator

protected abstract void rebuildIdGenerator()
Should rebuild the id generator from scratch.


initStorage

protected void initStorage()
Called from the constructor after the end header has been checked. The store implementation can setup it's persistence windows and other resources that are needed by overriding this implementation.

This default implementation does nothing.


closeStorage

protected void closeStorage()
This method should close/release all resources that the implementation of this store has allocated and is called just before the close() method returns. Override this method to clean up stuff created in initStorage() method.

This default implementation does nothing.


getFileSystem

protected FileSystemAbstraction getFileSystem()

setStoreNotOk

protected void setStoreNotOk(Throwable cause)
Marks this store as "not ok".


getStoreOk

protected boolean getStoreOk()
If store is "not ok" false is returned.

Returns:
True if this store is ok

setWindowPool

protected void setWindowPool(PersistenceWindowPool pool)
Sets the PersistenceWindowPool for this store to use. Normally this is set in the loadStorage() method. This method must be invoked with a valid "pool" before any of the acquireWindow(long, OperationType) releaseWindow(PersistenceWindow) flushAll() close() methods are invoked.

Parameters:
pool - The window pool this store should use

nextId

public long nextId()
Returns the next id for this store's IdGenerator.

Returns:
The next free id

freeId

public void freeId(long id)
Frees an id for this store's IdGenerator.

Parameters:
id - The id to free

getHighId

public long getHighId()
Return the highest id in use.

Returns:
The highest id in use.

setHighId

public void setHighId(long highId)
Sets the highest id in use (use this when rebuilding id generator).

Parameters:
highId - The high id to set.

getIfMemoryMapped

protected boolean getIfMemoryMapped()

calculateMappedMemory

public static long calculateMappedMemory(Map<?,?> config,
                                         String storageFileName)
Returns memory assigned for memory mapped windows in bytes. The configuration map passed in one constructor is checked for an entry with this stores name.

Parameters:
config - Map of configuration parameters
storageFileName - Name of the file on disk
Returns:
The number of bytes memory mapped windows this store has

makeStoreOk

public void makeStoreOk()
If store is not ok a call to this method will rebuild the IdGenerator used by this store and if successful mark it as ok.


rebuildIdGenerators

public void rebuildIdGenerators()

getConfig

public Map<?,?> getConfig()
Returns the configuration map if set in constructor.

Returns:
A map containing configuration or null if no configuration map set.

getStoreDir

protected String getStoreDir()
Returns:
the store directory from config.

acquireWindow

protected PersistenceWindow acquireWindow(long position,
                                          OperationType type)
Acquires a PersistenceWindow for position and operation type. Window must be released after operation has been performed via releaseWindow(PersistenceWindow).

Parameters:
position - The record position
type - The operation type
Returns:
a persistence window encapsulating the record

releaseWindow

protected void releaseWindow(PersistenceWindow window)
Releases the window and writes the data (async) if the window was a PersistenceRow.

Parameters:
window - The window to be released

flushAll

public void flushAll()

isInRecoveryMode

public boolean isInRecoveryMode()

setRecovered

protected void setRecovered()

unsetRecovered

protected void unsetRecovered()

getStorageFileName

public String getStorageFileName()
Returns the name of this store.

Returns:
The name of this store

openIdGenerator

protected void openIdGenerator(boolean firstTime)
Opens the IdGenerator used by this store.


openIdGenerator

protected IdGenerator openIdGenerator(String fileName,
                                      int grabSize,
                                      boolean firstTime)

figureOutHighestIdInUse

protected abstract long figureOutHighestIdInUse()

createIdGenerator

protected void createIdGenerator(String fileName)

openReadOnlyIdGenerator

protected void openReadOnlyIdGenerator(int recordSize)

closeIdGenerator

protected void closeIdGenerator()
Closed the IdGenerator used by this store


close

public void close()
Closes this store. This will cause all buffers and channels to be closed. Requesting an operation from after this method has been invoked is illegal and an exception will be thrown.

This method will start by invoking the closeStorage() method giving the implementing store way to do anything that it needs to do before the fileChannel is closed.


releaseFileLockAndCloseFileChannel

protected void releaseFileLockAndCloseFileChannel()

getFileChannel

protected final FileChannel getFileChannel()
Returns a FileChannel to this storage's file. If close() method has been invoked null will be returned.

Returns:
A file channel to this storage

getHighestPossibleIdInUse

public long getHighestPossibleIdInUse()
Returns:
The highest possible id in use, -1 if no id in use.

getNumberOfIdsInUse

public long getNumberOfIdsInUse()
Returns:
The total number of ids in use.

getWindowPoolStats

public WindowPoolStats getWindowPoolStats()

getIdType

public IdType getIdType()

registerIdFromUpdateRecord

protected void registerIdFromUpdateRecord(long id)

updateHighId

protected void updateHighId()

toString

public String toString()
Overrides:
toString in class Object


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