ozone core API

org.ozoneDB.core.storage.wizardStore
Class ClusterStore

java.lang.Object
  extended byorg.ozoneDB.core.storage.AbstractClusterStore
      extended byorg.ozoneDB.core.storage.wizardStore.ClusterStore

public final class ClusterStore
extends AbstractClusterStore

The ClusterStore is the back-end store of the wizardStore. It maintains the cluster cache, activation/passivation and the actual persistent commits.

Version:
$Revision: 1.3 $Date: 2004/01/10 21:40:24 $
Author:
SMB, Medium.net

Field Summary
protected  DxMap cachedClusters
           
private  boolean compressClusters
           
protected static int compressionFactor
           
protected  DxMap growingClusterIDs
          Table that maps Permissions to ClusterIDs.
protected  int maxClusterSize
           
static java.lang.String POSTFIX_SHADOW
           
 
Fields inherited from class org.ozoneDB.core.storage.AbstractClusterStore
env, POSTFIX_CLUSTER, POSTFIX_LOCK, POSTFIX_SEPARATOR, POSTFIX_TEMP, touchCount
 
Constructor Summary
(package private) ClusterStore(Env _env)
           
 
Method Summary
 void abortCluster(Transaction ta, ClusterID cid)
          Actually abort the specified cluster.
protected  void activateCluster(Cluster cluster, int size)
          This method is called right after the specified WizardCluster was loaded from disk.
 void commitCluster(Transaction ta, ClusterID cid)
          Actually commit the specified cluster.
protected  Cluster createANewEmptyAndUsableCluster(Permissions perms)
          Creates a cluster which is new empty usable and not locked
 int currentBytesPerContainer()
           
 long currentCacheSize()
           
protected  void deactivateCluster(Cluster cluster)
          Deactivate the specified cluster before it is written to disk.
protected  Cluster giveMeAnUnlockedCluster(Permissions perms)
          Returns or creates a cluster which is not locked so that locking it will succeed.
protected  Cluster growingCluster(Permissions perms)
           
 void invalidateContainer(StorageObjectContainer container)
           
 boolean isCleanShutdown()
          Check if the ClusterStore was cleanly shutted down.
 Cluster loadCluster(ClusterID cid, boolean pin)
          Make sure the corresponding cluster is in the cache.
protected  java.lang.Object loadData(java.lang.String key)
          Load the data that previously has been stored for the given key.
 void prepareCommitCluster(Transaction ta, ClusterID cid)
          Store the specified cluster on disk.
 DxSet recoverClusterIDs()
          Search the DATA dir and recover all ClusterIDs.
 void registerContainerAndLock(StorageObjectContainer container, Permissions perms, Transaction locker, int lockLevel)
          Associates the specified container with a cluster.
protected  Cluster restoreCluster(ClusterID cid)
           
 void shutdown()
           
 void splitCluster(Cluster cluster)
           
 void startup()
           
protected  void storeData(java.lang.Object obj, java.lang.String key)
          Serialize and store the specified object for the specified key.
protected  void trimCache()
          Ensure that there is at least the specified size of free space in the cluster cache.
 void unloadCluster(ClusterID cid, boolean deactivate)
          Remove cluster from the cluster cache.
protected  void updateLockOnDisk(Cluster cluster, Transaction ta)
           
 
Methods inherited from class org.ozoneDB.core.storage.AbstractClusterStore
basename
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

POSTFIX_SHADOW

public static final java.lang.String POSTFIX_SHADOW
See Also:
Constant Field Values

compressionFactor

protected static final int compressionFactor
See Also:
Constant Field Values

cachedClusters

protected DxMap cachedClusters

maxClusterSize

protected int maxClusterSize

growingClusterIDs

protected DxMap growingClusterIDs
Table that maps Permissions to ClusterIDs.


compressClusters

private boolean compressClusters
Constructor Detail

ClusterStore

ClusterStore(Env _env)
Method Detail

startup

public void startup()
             throws java.lang.Exception
Throws:
java.lang.Exception

shutdown

public void shutdown()

isCleanShutdown

public boolean isCleanShutdown()
Check if the ClusterStore was cleanly shutted down.


recoverClusterIDs

public DxSet recoverClusterIDs()
Search the DATA dir and recover all ClusterIDs.


currentCacheSize

public long currentCacheSize()

currentBytesPerContainer

public int currentBytesPerContainer()
Specified by:
currentBytesPerContainer in class AbstractClusterStore

growingCluster

protected Cluster growingCluster(Permissions perms)
                          throws java.lang.Exception
Parameters:
perms - Permissions of the cluster to search.
Returns:
WizardCluster with the specified permissions that is good to store a new container in it.
Throws:
java.lang.Exception

createANewEmptyAndUsableCluster

protected Cluster createANewEmptyAndUsableCluster(Permissions perms)
                                           throws java.io.IOException,
                                                  java.lang.ClassNotFoundException
Creates a cluster which is

Throws:
java.io.IOException
java.lang.ClassNotFoundException

giveMeAnUnlockedCluster

protected Cluster giveMeAnUnlockedCluster(Permissions perms)
                                   throws java.io.IOException,
                                          java.lang.ClassNotFoundException
Returns or creates a cluster which is not locked so that locking it will succeed. The returned cluster is only guaranteed to be not locked by any other thread as long as this method is called during synchronization to this ClusterStore.

Throws:
java.io.IOException
java.lang.ClassNotFoundException

registerContainerAndLock

public void registerContainerAndLock(StorageObjectContainer container,
                                     Permissions perms,
                                     Transaction locker,
                                     int lockLevel)
                              throws java.lang.Exception
Associates the specified container with a cluster. Iff this method returns normally (without exception), the container is pinned and thus has to be unpinned. Iff this method returns normally (without exception), the container (and thus the cluster of the container) is write locked

Specified by:
registerContainerAndLock in class AbstractClusterStore
Parameters:
container - Container to be registered with one cluster.
Throws:
java.lang.Exception

invalidateContainer

public void invalidateContainer(StorageObjectContainer container)

restoreCluster

protected Cluster restoreCluster(ClusterID cid)
                          throws java.lang.Exception
Throws:
java.lang.Exception

loadCluster

public Cluster loadCluster(ClusterID cid,
                           boolean pin)
                    throws java.io.IOException,
                           java.lang.ClassNotFoundException
Make sure the corresponding cluster is in the cache. While loading clusters, we may have to throw away (and maybe store) some currently cached clusters.

Parameters:
cid - ClusterID of the cluster to load.
pin - wether the loaded cluster should be pinned as soon as it is loaded so that there may be no chance to unload unless it is unpinned. If this parameter is set to true, the user has to unpin the cluster. If this parameter is set to false, the cluster may already be unloaded when this method returns. after using it.
Throws:
java.io.IOException
java.lang.ClassNotFoundException

splitCluster

public void splitCluster(Cluster cluster)

unloadCluster

public void unloadCluster(ClusterID cid,
                          boolean deactivate)
                   throws java.io.IOException
Remove cluster from the cluster cache.

Parameters:
cid -
Throws:
java.io.IOException

trimCache

protected void trimCache()
                  throws java.io.IOException
Ensure that there is at least the specified size of free space in the cluster cache. Under some circumstances clusters (currently invoked) cannot be deactivated. Therefore this method cannot guarantee that the needed space is free afterwards.

This is the central method of the deactivation of containers that are currently in use. This is different from the commit behaviour.

Throws:
java.io.IOException

activateCluster

protected void activateCluster(Cluster cluster,
                               int size)
This method is called right after the specified WizardCluster was loaded from disk.

Specified by:
activateCluster in class AbstractClusterStore

deactivateCluster

protected void deactivateCluster(Cluster cluster)
                          throws java.io.IOException
Deactivate the specified cluster before it is written to disk. The specified cluster will be removed from the cluster cache. If it currently has shadows, they are written to disk. If any of the containers are currently invoked (should normally never happen), the shadows must stay in memory.

Specified by:
deactivateCluster in class AbstractClusterStore
Throws:
java.io.IOException

prepareCommitCluster

public void prepareCommitCluster(Transaction ta,
                                 ClusterID cid)
                          throws java.io.IOException,
                                 java.lang.ClassNotFoundException
Store the specified cluster on disk. Write temp files first. If this write fails, the original are still valid. The cluster may has been written to the disk already, if is was deactivated while transaction. But in case the cluster (and its changes) are only in memory, we have to write now to check if this is possible without errors. Note: This only writes all currently commited transaction results to the disk. This is different from the deactivation behaviour.

Specified by:
prepareCommitCluster in class AbstractClusterStore
Parameters:
cid - WizardCluster to be prepare-commited.
Throws:
java.io.IOException - None of the clusters are written to disk.
java.lang.ClassNotFoundException

commitCluster

public void commitCluster(Transaction ta,
                          ClusterID cid)
                   throws java.io.IOException,
                          java.lang.ClassNotFoundException
Actually commit the specified cluster. This simply renames the temp file to be the new "original" ones. The rename operation MUST NOT fail.

Specified by:
commitCluster in class AbstractClusterStore
Parameters:
cid - WizardCluster to be commited.
Throws:
java.io.IOException
java.lang.ClassNotFoundException

abortCluster

public void abortCluster(Transaction ta,
                         ClusterID cid)
                  throws java.io.IOException,
                         java.lang.ClassNotFoundException
Actually abort the specified cluster. This deletes t

Specified by:
abortCluster in class AbstractClusterStore
Parameters:
cid - WizardCluster to be aborted.
Throws:
java.io.IOException
java.lang.ClassNotFoundException

updateLockOnDisk

protected void updateLockOnDisk(Cluster cluster,
                                Transaction ta)
                         throws java.io.IOException
Throws:
java.io.IOException

storeData

protected void storeData(java.lang.Object obj,
                         java.lang.String key)
                  throws java.io.IOException
Serialize and store the specified object for the specified key. This current implementation uses the file system as back end store.

Throws:
java.io.IOException

loadData

protected java.lang.Object loadData(java.lang.String key)
                             throws java.io.IOException,
                                    java.lang.ClassNotFoundException
Load the data that previously has been stored for the given key.

Throws:
java.io.IOException
java.lang.ClassNotFoundException

ozone core API

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