ozone core API

org.ozoneDB.core.storage.magicStore
Class ClusterStore

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

public final class ClusterStore
extends AbstractClusterStore

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

Version:
$Revision: 1.11 $Date: 2004/03/10 14:59:48 $
Author:
SMB, Medium.net, Leo Mekenkamp, Per Nyfelt

Nested Class Summary
private  class ClusterStore.StoreThread
           
 
Field Summary
private  Cache clusterCache
           
private  boolean compressClusters
           
protected static int compressionFactor
           
protected  DxMap growingClusterIDs
          Table that maps Permissions to ClusterIDs.
private  MagicStore magicStore
           
protected  int maxClusterSize
           
(package private) static java.lang.String POSTFIX_NEW
           
private static java.lang.String POSTFIX_OLD
           
private  ClusterStore.StoreThread storeThread
           
 
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.
(package private)  void abortTransaction(MagicTransaction ta)
           
protected  void activateCluster(Cluster cluster, int size)
          This method is called right after the specified MagicCluster was loaded from disk.
 void commitCluster(Transaction ta, ClusterID cid)
           
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.
(package private)  MagicStore getMagicStore()
           
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, MagicTransaction ta)
           
 void invalidateContainer(StorageObjectContainer container)
           
 boolean isCleanShutdown()
          Check if the ClusterStore was cleanly shutted down.
 Cluster loadCluster(ClusterID cid, MagicTransaction ta)
          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.
 java.util.Set 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, java.util.Set uncommittedTaIDs)
           
(package private)  void setMagicStore(MagicStore _magicStore)
           
 void shutdown()
           
 void splitCluster(Cluster cluster)
           
private static java.lang.String[] splitClusterName(java.lang.String clusterName)
           
 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 storeDataImmediately(java.lang.Object obj, java.lang.String key)
           
(package private)  java.util.Set uncommittedTaIDs()
          Returns a set containing the IDs of all tx-es that for one reason or another have not committed.
 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_NEW

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

POSTFIX_OLD

private static final java.lang.String POSTFIX_OLD
See Also:
Constant Field Values

compressionFactor

protected static final int compressionFactor
See Also:
Constant Field Values

clusterCache

private transient Cache clusterCache

maxClusterSize

protected int maxClusterSize

growingClusterIDs

protected DxMap growingClusterIDs
Table that maps Permissions to ClusterIDs.


compressClusters

private boolean compressClusters

magicStore

private MagicStore magicStore

storeThread

private ClusterStore.StoreThread storeThread
Constructor Detail

ClusterStore

ClusterStore(Env _env)
Method Detail

getMagicStore

MagicStore getMagicStore()

setMagicStore

void setMagicStore(MagicStore _magicStore)

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 java.util.Set recoverClusterIDs()
Search the DATA dir and recover all ClusterIDs.


uncommittedTaIDs

java.util.Set uncommittedTaIDs()
Returns a set containing the IDs of all tx-es that for one reason or another have not committed.


splitClusterName

private static java.lang.String[] splitClusterName(java.lang.String clusterName)

currentCacheSize

public long currentCacheSize()

currentBytesPerContainer

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

growingCluster

protected Cluster growingCluster(Permissions perms,
                                 MagicTransaction ta)
                          throws java.lang.Exception
Parameters:
perms - Permissions of the cluster to search.
Returns:
MagicCluster 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 (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,
                                 java.util.Set uncommittedTaIDs)
                          throws java.lang.Exception
Throws:
java.lang.Exception

loadCluster

public Cluster loadCluster(ClusterID cid,
                           MagicTransaction ta)
                    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.
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

activateCluster

protected void activateCluster(Cluster cluster,
                               int size)
This method is called right after the specified MagicCluster 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 new 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 - MagicCluster 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
Specified by:
commitCluster in class AbstractClusterStore
Parameters:
cid - MagicCluster 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 - MagicCluster 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

storeDataImmediately

protected void storeDataImmediately(java.lang.Object obj,
                                    java.lang.String key)
                             throws java.io.IOException
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

abortTransaction

void abortTransaction(MagicTransaction ta)
                throws java.io.IOException,
                       java.lang.ClassNotFoundException
Throws:
java.io.IOException
java.lang.ClassNotFoundException

ozone core API

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