ozone core API

org.ozoneDB.core.storage.gammaStore
Class IndexManager

java.lang.Object
  extended byorg.ozoneDB.core.storage.gammaStore.IndexManager
All Implemented Interfaces:
PropertyConfigurable

public final class IndexManager
extends java.lang.Object
implements PropertyConfigurable

Takes care of storing and caching all object locations. Because of the nature of generated object ids (a newly generated id is always one bigger than the id generated before) this class is very fast when adding new ids, but a bit slow when inserting ids in random order. Random order insertion will only take place during a crash recovery.

Version:
$Id: IndexManager.java,v 1.8 2004/04/06 18:39:39 leomekenkamp Exp $
Author:
Leo Mekenkamp (mind the anti sp@m)

Field Summary
private  WeakReferenceCache backupNodeCache
          makes sure we have access to nodes that have been thrown out of the other caches but are still strongly referenced somwhere
private  int branchNodeMergeReach
           
static PropertyInfo BRANCHNODEMERGEREACH
           
private  int branchNodeMergeSize
           
static PropertyInfo BRANCHNODEMERGESIZE
           
private static java.lang.String CONFIGNAME
          (file)name to store / read configuration at shutdown / startup
private  java.lang.String dbDirectory
           
private  Deleter deleter
          takes care of deleting index nodes that have become empty and have been removed from the indexmanager
static PropertyInfo DIRTYINDEXNODECACHE
           
private  TrimmingCache dirtyNodeCache
          holds all dirty nodes ("You dirty little nodes, you...")
static PropertyInfo GENERALINDEXNODECACHE
           
private  TrimmingCache generalNodeCache
          holds most index nodes
static PropertyInfo INDEXNODESTORAGEFACTORY
           
static PropertyInfo INDEXNODESTREAMFACTORY
           
static PropertyInfo INDEXSTREAMFACTORY
           
private  int leafNodeMergeReach
           
static PropertyInfo LEAFNODEMERGEREACH
           
private  int leafNodeMergeSize
           
static PropertyInfo LEAFNODEMERGESIZE
           
private static java.util.logging.Logger log
           
private  int maxBranchNodeSize
           
static PropertyInfo MAXBRANCHNODESIZE
           
private  int maxLeafNodeSize
           
static PropertyInfo MAXLEAFNODESIZE
           
static int MINMAXBRANCHNODESIZE
           
static int MINMAXLEAFNODESIZE
           
private  IndexLeafNode newestLeafNode
          provides fast access for when new objects are created
private  long nodeIdCounter
          for generating unique ids; -1 so the first returned id will be 0
private  long nodeLoaded
           
private  long nodeLoadedCache
           
private  long nodeLoadedDirect
           
private  long nodeLoadedDisk
           
private  long nodeLoadedSerializer
           
private  Serializer nodeSerializer
           
private  java.lang.String prefix
           
private  IndexBranchNode rootNode
          entry point for the tree containing all index nodes
private  long size
           
private  StorageFactory storageFactory
          factory needed for swapping index nodes in and out
private  StreamFactory streamFactory
          factory needed for extra streams during (de)serialization
 
Constructor Summary
IndexManager(java.util.Properties properties, java.lang.String prefix, boolean initialize)
          initialize if true preform a full (re)initialization, if false, tries to read config.
 
Method Summary
(package private)  void checkSerializerSize()
          Checks the size of the serializer and suspends the current thread (sleep) if the serializer has too many nodes in it.
private  WeakReferenceCache getBackupNodeCache()
           
(package private)  int getBranchNodeMergeReach()
           
(package private)  int getBranchNodeMergeSize()
           
 ContainerLocation getContainerLocation(long objectId)
           
(package private)  Deleter getDeleter()
           
private  TrimmingCache getDirtyNodeCache()
           
private  TrimmingCache getGeneralNodeCache()
          Keep in mind that dirty nodes may also be in this cache.
private  IndexLeafNode getLeafNode(long objectId)
           
private  int getLeafNodeMergeDistance()
           
(package private)  int getLeafNodeMergeReach()
           
private  float getLeafNodeMergeThreshhold()
           
(package private)  int getMaxBranchNodeSize()
           
(package private)  int getMaxLeafNodeSize()
           
private  IndexLeafNode getNewestLeafNode()
           
(package private)  IndexNode getNode(long nodeId)
          Returns the specified index node from the cache, or from disk.
private  int getNodeCacheSize()
           
private  IndexNode getNodeFromCaches(java.lang.Long id)
           
private  long getNodeIdCounter()
           
(package private)  Serializer getNodeSerializer()
           
 java.lang.String getPrefix()
           
 java.util.Collection getPropertyInfos()
          Returns a Collection with all the properties this instance supports.
private  IndexBranchNode getRootNode()
           
 long getSize()
          Returns the number of container locations in this instance.
(package private)  StorageFactory getStorageFactory()
           
(package private)  StreamFactory getStreamFactory()
           
private  IndexNode loadNode(long nodeId)
          Loads an indexnode from disk.
(package private)  long nextNodeId()
           
(package private)  void nodeBecameDirty(IndexNode indexNode)
           
 void putContainerLocation(long objectId, ContainerLocation containerLocation)
           
(package private)  void putInCaches(IndexNode indexNode)
           
 void removeContainerLocation(long objectId)
           
(package private)  void removeFromCaches(IndexNode indexNode)
           
(package private)  void serialize(IndexNode indexNode)
           
private  void setBranchNodeMergeReach(int branchNodeMergeReach)
           
private  void setBranchNodeMergeSize(int branchNodeMergeSize)
           
private  void setDirtyNodeCache(TrimmingCache dirtyNodeCache)
           
private  void setGeneralNodeCache(TrimmingCache generalNodeCache)
           
private  void setLeafNodeMergeReach(int leafNodeMergeReach)
           
private  void setMaxBranchNodeSize(int maxBranchNodeSize)
           
private  void setMaxLeafNodeSize(int maxLeafNodeSize)
           
(package private)  void setNewestLeafNode(IndexLeafNode newestLeafNode)
           
private  void setNodeIdCounter(long nodeIdCounter)
           
private  void setNodeSerializer(Serializer nodeSerializer)
           
(package private)  void setRootNode(IndexBranchNode rootNode)
           
private  void setSize(long size)
           
private  void setStorageFactory(StorageFactory storageFactory)
           
private  void setStreamFactory(StreamFactory streamFactory)
           
 void shutdown()
          Shuts the indexmanager down; writes all data needed for the constructor when the initialize parameter is false
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private static java.util.logging.Logger log

MINMAXBRANCHNODESIZE

public static final int MINMAXBRANCHNODESIZE
See Also:
Constant Field Values

MINMAXLEAFNODESIZE

public static final int MINMAXLEAFNODESIZE
See Also:
Constant Field Values

INDEXSTREAMFACTORY

public static final PropertyInfo INDEXSTREAMFACTORY

DIRTYINDEXNODECACHE

public static final PropertyInfo DIRTYINDEXNODECACHE

GENERALINDEXNODECACHE

public static final PropertyInfo GENERALINDEXNODECACHE

MAXBRANCHNODESIZE

public static final PropertyInfo MAXBRANCHNODESIZE

BRANCHNODEMERGEREACH

public static final PropertyInfo BRANCHNODEMERGEREACH

BRANCHNODEMERGESIZE

public static final PropertyInfo BRANCHNODEMERGESIZE

MAXLEAFNODESIZE

public static final PropertyInfo MAXLEAFNODESIZE

LEAFNODEMERGEREACH

public static final PropertyInfo LEAFNODEMERGEREACH

LEAFNODEMERGESIZE

public static final PropertyInfo LEAFNODEMERGESIZE

INDEXNODESTORAGEFACTORY

public static final PropertyInfo INDEXNODESTORAGEFACTORY

INDEXNODESTREAMFACTORY

public static final PropertyInfo INDEXNODESTREAMFACTORY

CONFIGNAME

private static final java.lang.String CONFIGNAME
(file)name to store / read configuration at shutdown / startup

See Also:
Constant Field Values

newestLeafNode

private IndexLeafNode newestLeafNode
provides fast access for when new objects are created


rootNode

private IndexBranchNode rootNode
entry point for the tree containing all index nodes


nodeIdCounter

private long nodeIdCounter
for generating unique ids; -1 so the first returned id will be 0


storageFactory

private StorageFactory storageFactory
factory needed for swapping index nodes in and out


streamFactory

private StreamFactory streamFactory
factory needed for extra streams during (de)serialization


dirtyNodeCache

private TrimmingCache dirtyNodeCache
holds all dirty nodes ("You dirty little nodes, you...")


generalNodeCache

private TrimmingCache generalNodeCache
holds most index nodes


backupNodeCache

private WeakReferenceCache backupNodeCache
makes sure we have access to nodes that have been thrown out of the other caches but are still strongly referenced somwhere


maxLeafNodeSize

private int maxLeafNodeSize

leafNodeMergeSize

private int leafNodeMergeSize

leafNodeMergeReach

private int leafNodeMergeReach

maxBranchNodeSize

private int maxBranchNodeSize

branchNodeMergeSize

private int branchNodeMergeSize

branchNodeMergeReach

private int branchNodeMergeReach

nodeSerializer

private Serializer nodeSerializer

deleter

private Deleter deleter
takes care of deleting index nodes that have become empty and have been removed from the indexmanager


nodeLoaded

private transient long nodeLoaded

nodeLoadedDirect

private transient long nodeLoadedDirect

nodeLoadedSerializer

private transient long nodeLoadedSerializer

nodeLoadedCache

private transient long nodeLoadedCache

nodeLoadedDisk

private transient long nodeLoadedDisk

dbDirectory

private java.lang.String dbDirectory

size

private long size

prefix

private java.lang.String prefix
Constructor Detail

IndexManager

public IndexManager(java.util.Properties properties,
                    java.lang.String prefix,
                    boolean initialize)
             throws java.io.IOException
initialize if true preform a full (re)initialization, if false, tries to read config.

Parameters:
properties -
prefix -
initialize - TODO: refactor with the new java.util.concurrent package in the 1.5 JDK to make fully reentrant
Method Detail

shutdown

public void shutdown()
              throws java.io.IOException
Shuts the indexmanager down; writes all data needed for the constructor when the initialize parameter is false

Throws:
java.io.IOException

getNode

IndexNode getNode(long nodeId)
Returns the specified index node from the cache, or from disk. The node places itself in the node cache. Returned node is invoked.

Parameters:
nodeId - the id of the node
Returns:
IndexNode node containing the specified node, or null when there is no such node

loadNode

private IndexNode loadNode(long nodeId)
Loads an indexnode from disk.

Throws:
org.ozoneDB.OzoneInternalException - if error during reading

checkSerializerSize

void checkSerializerSize()
Checks the size of the serializer and suspends the current thread (sleep) if the serializer has too many nodes in it. Needed to ensure there is never an out of memory because nodes that have to be removed from memory and stored on disk are still in memory; those nodes are to be swapped out because of low memory condition (probably).


getLeafNode

private IndexLeafNode getLeafNode(long objectId)

getContainerLocation

public ContainerLocation getContainerLocation(long objectId)
Parameters:
objectId - id of the object for which the location is returned
Returns:
ContainerLocation location for the specified object
Throws:
ObjectNotFoundException - if no container location can be found for specified objectId

putContainerLocation

public void putContainerLocation(long objectId,
                                 ContainerLocation containerLocation)

removeContainerLocation

public void removeContainerLocation(long objectId)

getSize

public long getSize()
Returns the number of container locations in this instance.


nextNodeId

long nextNodeId()

getNodeIdCounter

private long getNodeIdCounter()

setNodeIdCounter

private void setNodeIdCounter(long nodeIdCounter)

setSize

private void setSize(long size)

getMaxLeafNodeSize

int getMaxLeafNodeSize()

setMaxLeafNodeSize

private void setMaxLeafNodeSize(int maxLeafNodeSize)

getMaxBranchNodeSize

int getMaxBranchNodeSize()

setMaxBranchNodeSize

private void setMaxBranchNodeSize(int maxBranchNodeSize)

getLeafNodeMergeThreshhold

private float getLeafNodeMergeThreshhold()

getLeafNodeMergeDistance

private int getLeafNodeMergeDistance()

getNodeCacheSize

private int getNodeCacheSize()

getRootNode

private IndexBranchNode getRootNode()

putInCaches

void putInCaches(IndexNode indexNode)

removeFromCaches

void removeFromCaches(IndexNode indexNode)

getNodeFromCaches

private IndexNode getNodeFromCaches(java.lang.Long id)

setRootNode

void setRootNode(IndexBranchNode rootNode)

getNewestLeafNode

private IndexLeafNode getNewestLeafNode()

setNewestLeafNode

void setNewestLeafNode(IndexLeafNode newestLeafNode)

getStorageFactory

StorageFactory getStorageFactory()

getStreamFactory

StreamFactory getStreamFactory()

setStorageFactory

private void setStorageFactory(StorageFactory storageFactory)

setStreamFactory

private void setStreamFactory(StreamFactory streamFactory)

getDirtyNodeCache

private TrimmingCache getDirtyNodeCache()

setDirtyNodeCache

private void setDirtyNodeCache(TrimmingCache dirtyNodeCache)

getGeneralNodeCache

private TrimmingCache getGeneralNodeCache()
Keep in mind that dirty nodes may also be in this cache.


setGeneralNodeCache

private void setGeneralNodeCache(TrimmingCache generalNodeCache)

getBackupNodeCache

private WeakReferenceCache getBackupNodeCache()

serialize

void serialize(IndexNode indexNode)

getNodeSerializer

Serializer getNodeSerializer()

getDeleter

Deleter getDeleter()

setNodeSerializer

private void setNodeSerializer(Serializer nodeSerializer)

getPropertyInfos

public java.util.Collection getPropertyInfos()
Description copied from interface: PropertyConfigurable

Returns a Collection with all the properties this instance supports.

Specified by:
getPropertyInfos in interface PropertyConfigurable
Returns:
Collection with PropertyInfo elements

getLeafNodeMergeReach

int getLeafNodeMergeReach()

setLeafNodeMergeReach

private void setLeafNodeMergeReach(int leafNodeMergeReach)

getBranchNodeMergeSize

int getBranchNodeMergeSize()

setBranchNodeMergeSize

private void setBranchNodeMergeSize(int branchNodeMergeSize)

getBranchNodeMergeReach

int getBranchNodeMergeReach()

setBranchNodeMergeReach

private void setBranchNodeMergeReach(int branchNodeMergeReach)

nodeBecameDirty

void nodeBecameDirty(IndexNode indexNode)

getPrefix

public java.lang.String getPrefix()
Specified by:
getPrefix in interface PropertyConfigurable

ozone core API

Copyright (C) The Ozone Database Project - www.ozone-db.org. All rights reserved.