| |
|
| java.lang.Object org.ozoneDB.core.ServerComponent org.ozoneDB.core.GarbageCollector
GarbageCollector | public class GarbageCollector extends ServerComponent implements Runnable(Code) | | Marks reachable objects and sweeps unreachable objects.
This implementation has at least following deficiencies:
-
Method invocation observation is limited to the direct method parameters and the return value.
A correct implementation should observe not only method parameters and return values but
all objects which are reachable from these objects.
-
Currently, the implementation is not scaleable, because the list
GarbageCollector.surelyReachableObjectsWhichHaveToBeMarkedAsSuch may grow to the count of objects.
Possible solutions are:
-
Export some contents of this stack to disk. This seems to be highly efficient, because
the "hot spot" of the corresponding file always would be the end of the file.
-
Simply forget entries if they are too much. Work through the whole list until it is empty.
Once the list is empty, walk through all objects to refill this list and continue.
This approach has some appeals, but seems to be element of O(n^2) for large databases because
there would be n*c1 walks trough 1/2*n objects each walk.
author: Xuân Baldauf (Medium.net |
Inner Class :public class GarbageCollectorProxyObjectIdentificationObjectOutputStream extends ObjectOutputStream | |
Method Summary | |
protected void | addAllNamedObjectsToSurelyReachableSet() This method walks through all named objects and adds each of them to the surelyReachable set. | protected void | addObjectIDToSurelyReachableObjectsWhichHaveToBeMarkedAsSuch(ObjectID id) This method may be called both from transaction threads and from GarbageCollector-Threads. | protected void | addRootSetElementsToSurelyReachableSet() | public void | addTransactionRequiredToComplete(Object ta) | protected void | checkForEndOfWaitForCurrentTransactionsToCompletePhase() | protected void | checkForProxyBorderCross(Object o) This method checks wether the given object or the object graph reachable from this given object
contains OzoneProxys. | protected void | checkForProxyBorderCross(OzoneProxy o) This method checks wether the given object or the object graph reachable from this given object
contains OzoneProxys. | protected void | checkForProxyBorderCross(OzoneCompatible o) This method checks wether the given object or the object graph reachable from this given object
contains OzoneProxys. | protected void | completeTransaction() Completes the current transaction and releases it. | protected void | deferProcessingOfObjectContainerDueToLockContention(ObjectContainer objectContainer) Defers the processing of the given objectContainer because locking was not possible at current time. | protected void | ensureDoneReachable(ObjectContainer objectContainer) Ensures that the given object is doneReachable. | protected void | ensureSurelyReachable(ObjectID id) Calling this method makes sure that the object which is referenced by the given ID is
at least surely reachable. | protected void | ensureSurelyReachable(ObjectContainer objectContainer) Calling this method makes sure that the object which is referenced by the given ID is
at least surely reachable. | protected void | incCurrentGarbageCollectorLevel() | public void | interceptInvocationPost(Transaction transaction, ObjectContainer callee, Object result) This method is called by Transactions to indicate that a method of the object callee
was called by the transaction. | public void | interceptInvocationPre(Transaction transaction, ObjectContainer callee, Object[] args) This method is called by Transactions to indicate that a method of the object callee
will be called by the transaction. | protected void | internalAbortTransaction(Transaction transaction) | protected void | internalCompleteTransaction(Transaction transaction) | protected void | internalEnsureDoneReachable(ObjectContainer objectContainer) Internally ensures that the given object is doneReachable. | protected int | internalEnsureSurelyReachable(ObjectContainer objectContainer) Internally ensures that the given object is at least surelyReachable.
<0 if this object has been updated. | protected void | internalFinishTransaction(Transaction transaction) | protected boolean | isRunning() Returns wether this GarbageCollector is running. | protected void | notifyAboutTransactionActionAndRenewTransactionIfRequired() | public void | notifyDatabaseObjectIsAboutToBeExported(ObjectID id) This method is called by DbInvokeClient to notify this garbageCollector
that there is a reference which is to be exported to a client. | public void | notifyDatabaseObjectIsExported(ObjectID id) | protected void | notifyEndOfWaitForCurrentTransactionsToCompletePhase() Informs this GarbageCollector, the the pre-phase is done, there are no transactions that
are older than this garbage collector run. | public void | notifyNamedObject(ObjectID id) This method is called by StoreManager to indicate that the object
with the given id is a named object. | public void | notifyNewObjectContainer(ObjectContainer objectContainer) This method is called by StoreManager in the event an object is freshly created. | public void | notifyNewObjectName(ObjectContainer objectContainer) This method is called by StoreManager in the event an unnamed object receives a name. | protected void | processObjectContainerWhichWantsToBeSurelyReachableAndUnpin(Transaction transaction, ObjectContainer objectContainer) Processes an ObjectContainer which possibly has not already been registered as surely reachable. | protected void | processReferencesByThisObject(Transaction transaction, ObjectContainer objectContainer) Determines all references which are "contained" within the given object,
adds them to the list of
GarbageCollector.surelyReachableObjectsWhichHaveToBeMarkedAsSuch and then marks the given object as doneReachable. | protected void | processSurelyReachableObjectsWhichHaveToBeMarkedAsSuch() This is the "main()" method of the mark phase. | public void | removeTransactionRequiredToComplete(Transaction ta) | protected void | renewTransactionIfRequired() Checks wether the current transaction has to be committed (because it accumulated too much changes)
and if so, commits it and closes it. | public void | run() The main method for garbage collection. | public void | save() | protected void | setCurrentGarbageCollectionLevel(int to) | protected synchronized void | setPhase(int to) | public void | shutdown() | public void | start() Starts the garbage collection process. | protected void | startFilterDatabaseObjectReferencesAtExternalDatabaseGates() | public void | startup() | protected void | sweepUnreachableObjects() Sweeps all objects which are considered unreachable. | protected synchronized void | waitForPhase(int newPhase) |
PHASE_IDLE | final protected static int PHASE_IDLE(Code) | | Doing nothing
|
PHASE_MARKING | final protected static int PHASE_MARKING(Code) | | We are started, we are marking all reachable objects
|
PHASE_MARKING2 | final protected static int PHASE_MARKING2(Code) | | We are started, we are marking all reachable objects
|
PHASE_READY_TO_START | final protected static int PHASE_READY_TO_START(Code) | | We may start, all old transactions are complete
|
PHASE_RUN_INITIATED | final protected static int PHASE_RUN_INITIATED(Code) | | A run has been initiated
|
PHASE_SWEEPING | final protected static int PHASE_SWEEPING(Code) | | We are started, we are sweeping all unreachable objects
|
PHASE_WAITING_FOR_NEW_TRANSACTIONS_TO_COMPLETE | final protected static int PHASE_WAITING_FOR_NEW_TRANSACTIONS_TO_COMPLETE(Code) | | Waiting for the old transactions to complete
|
PHASE_WAITING_FOR_OLD_TRANSACTIONS_TO_COMPLETE | final protected static int PHASE_WAITING_FOR_OLD_TRANSACTIONS_TO_COMPLETE(Code) | | Waiting for the old transactions to complete
|
actionsWithinTransactionCount | protected int actionsWithinTransactionCount(Code) | | The count of actions which were done within this garbageCollector.
|
currentGarbageCollectionLevel | protected int currentGarbageCollectionLevel(Code) | | The number which represents the current garbage collection run.
This number is the number mentioned in
org.ozoneDB.core.wizardStore.WizardObjectContainer.garbageCollectionLevel .
There are tree sets of database objects
- probablyReachable: These objects may or may not be reachable. Their garbageCollectionLevel is below the currentGarbageCollectionLevel
- surelyReachable: These objects have been reached during the walk. Their garbageCollectionLevel is currentGarbageCollectionLevel
- doneReachable: These object have been processed for members. All their members are surelyReachable or better. Their garbageCollectionLevel is currentGarbageCollectionLevel+1
|
garbageCollectionLevelsLock | protected Object garbageCollectionLevelsLock(Code) | | This is the lock that everybody has to be synchronized to in order to
be able to access any garbageCollectionLevel in any object within this database.
|
garbageCollectionThread | protected Thread garbageCollectionThread(Code) | | The thread which actually does the work.
|
kill | protected boolean kill(Code) | | Wether we should stop running as soon as possible. Synchronization is not required,
because it does not matter wether we receive this signal soon or later.
|
phase | protected int phase(Code) | | The current phase this GarbageCollector is in. Access only within synchronization to this object.
|
surelyReachableObjectsWhichHaveToBeMarkedAsSuch | protected SimpleArrayList surelyReachableObjectsWhichHaveToBeMarkedAsSuch(Code) | | A stack of ObjectIDs of objects, which are surely reachable, but still
were not marked as such.
Access only during synchronization on it.
|
surelyReachableObjectsWhichShouldHaveBeenProcessedButWereLockContented | protected LinkedList surelyReachableObjectsWhichShouldHaveBeenProcessedButWereLockContented(Code) | | The list of ObjectIDs of objects which are surelyReachable and already were tried to
be processed but where locking the objects failed. The processing the contents of this
list should be retried some times later.
To minimize overhead, access is only allowed during synchronization to
GarbageCollector.surelyReachableObjectsWhichHaveToBeMarkedAsSuch |
transaction | protected Transaction transaction(Code) | | The current transaction of this garbageCollector.
|
transactionsRequiredToComplete | protected HashSet transactionsRequiredToComplete(Code) | | The list of
Transaction s, which have to be completed before the GarbageCollector
may start. It may not start earlier because the rollback of those transaction may make
objects live which were believed to be dead.
|
GarbageCollector | protected GarbageCollector(Env env)(Code) | | Creates a new garbage collector.
|
addAllNamedObjectsToSurelyReachableSet | protected void addAllNamedObjectsToSurelyReachableSet()(Code) | | This method walks through all named objects and adds each of them to the surelyReachable set.
|
addObjectIDToSurelyReachableObjectsWhichHaveToBeMarkedAsSuch | protected void addObjectIDToSurelyReachableObjectsWhichHaveToBeMarkedAsSuch(ObjectID id)(Code) | | This method may be called both from transaction threads and from GarbageCollector-Threads.
|
addRootSetElementsToSurelyReachableSet | protected void addRootSetElementsToSurelyReachableSet()(Code) | | |
addTransactionRequiredToComplete | public void addTransactionRequiredToComplete(Object ta)(Code) | | |
checkForEndOfWaitForCurrentTransactionsToCompletePhase | protected void checkForEndOfWaitForCurrentTransactionsToCompletePhase()(Code) | | |
checkForProxyBorderCross | protected void checkForProxyBorderCross(Object o)(Code) | | This method checks wether the given object or the object graph reachable from this given object
contains OzoneProxys. If so, the database objects referenced by these proxies are considered
surelyReachable.
|
checkForProxyBorderCross | protected void checkForProxyBorderCross(OzoneProxy o)(Code) | | This method checks wether the given object or the object graph reachable from this given object
contains OzoneProxys. If so, the database objects referenced by these proxies are considered
surelyReachable.
|
checkForProxyBorderCross | protected void checkForProxyBorderCross(OzoneCompatible o)(Code) | | This method checks wether the given object or the object graph reachable from this given object
contains OzoneProxys. If so, the database objects referenced by these proxies are considered
surelyReachable.
|
deferProcessingOfObjectContainerDueToLockContention | protected void deferProcessingOfObjectContainerDueToLockContention(ObjectContainer objectContainer)(Code) | | Defers the processing of the given objectContainer because locking was not possible at current time.
Because objectContainers may be modified in the meantime
(in the case they are unloaded and loaded again, we would hold an old copy of objectContainer which
does not reflect the changes made to the new objectContainer), it's not wise to queue the ObjectContainer.
Instead, we have to queue the ObjectID of that ObjectContainer.
|
ensureDoneReachable | protected void ensureDoneReachable(ObjectContainer objectContainer)(Code) | | Ensures that the given object is doneReachable.
|
ensureSurelyReachable | protected void ensureSurelyReachable(ObjectID id)(Code) | | Calling this method makes sure that the object which is referenced by the given ID is
at least surely reachable.
|
ensureSurelyReachable | protected void ensureSurelyReachable(ObjectContainer objectContainer)(Code) | | Calling this method makes sure that the object which is referenced by the given ID is
at least surely reachable. This method is called by non-GarbageCollector-Threads.
|
incCurrentGarbageCollectorLevel | protected void incCurrentGarbageCollectorLevel()(Code) | | |
interceptInvocationPost | public void interceptInvocationPost(Transaction transaction, ObjectContainer callee, Object result)(Code) | | This method is called by Transactions to indicate that a method of the object callee
was called by the transaction.
This method will always be called, even if the GarbageCollector is not startet.
|
interceptInvocationPre | public void interceptInvocationPre(Transaction transaction, ObjectContainer callee, Object[] args)(Code) | | This method is called by Transactions to indicate that a method of the object callee
will be called by the transaction.
This method will always be called, even if the GarbageCollector is not startet.
|
internalEnsureDoneReachable | protected void internalEnsureDoneReachable(ObjectContainer objectContainer)(Code) | | Internally ensures that the given object is doneReachable.
|
internalEnsureSurelyReachable | protected int internalEnsureSurelyReachable(ObjectContainer objectContainer)(Code) | | Internally ensures that the given object is at least surelyReachable.
<0 if this object has been updated. If this is the case, this object has to join a transaction which will complete successfully.=0 if this object has not been updated, it is surelyReachable>0 if this object has not been updated, it is processedReachable |
isRunning | protected boolean isRunning()(Code) | | Returns wether this GarbageCollector is running. This method
must be called during synchronization on this GarbageCollector.
|
notifyDatabaseObjectIsAboutToBeExported | public void notifyDatabaseObjectIsAboutToBeExported(ObjectID id)(Code) | | This method is called by DbInvokeClient to notify this garbageCollector
that there is a reference which is to be exported to a client.
|
notifyDatabaseObjectIsExported | public void notifyDatabaseObjectIsExported(ObjectID id)(Code) | | |
notifyEndOfWaitForCurrentTransactionsToCompletePhase | protected void notifyEndOfWaitForCurrentTransactionsToCompletePhase()(Code) | | Informs this GarbageCollector, the the pre-phase is done, there are no transactions that
are older than this garbage collector run.
|
notifyNamedObject | public void notifyNamedObject(ObjectID id)(Code) | | This method is called by StoreManager to indicate that the object
with the given id is a named object.
|
notifyNewObjectContainer | public void notifyNewObjectContainer(ObjectContainer objectContainer)(Code) | | This method is called by StoreManager in the event an object is freshly created.
|
notifyNewObjectName | public void notifyNewObjectName(ObjectContainer objectContainer)(Code) | | This method is called by StoreManager in the event an unnamed object receives a name.
This is the case if an object which was formerly unnamed gets a name.
|
processObjectContainerWhichWantsToBeSurelyReachableAndUnpin | protected void processObjectContainerWhichWantsToBeSurelyReachableAndUnpin(Transaction transaction, ObjectContainer objectContainer)(Code) | | Processes an ObjectContainer which possibly has not already been registered as surely reachable.
// This method may be called by any CommandThread.
This method may be called only by the garbage collector thread.
|
processSurelyReachableObjectsWhichHaveToBeMarkedAsSuch | protected void processSurelyReachableObjectsWhichHaveToBeMarkedAsSuch()(Code) | | This is the "main()" method of the mark phase.
|
removeTransactionRequiredToComplete | public void removeTransactionRequiredToComplete(Transaction ta)(Code) | | |
renewTransactionIfRequired | protected void renewTransactionIfRequired() throws IOException, ClassNotFoundException, TransactionExc(Code) | | Checks wether the current transaction has to be committed (because it accumulated too much changes)
and if so, commits it and closes it. Afterwards (or if there has not been a current transaction already),
it creates a new current transaction.
|
run | public void run()(Code) | | The main method for garbage collection.
|
setCurrentGarbageCollectionLevel | protected void setCurrentGarbageCollectionLevel(int to)(Code) | | |
setPhase | protected synchronized void setPhase(int to)(Code) | | |
shutdown | public void shutdown()(Code) | | |
start | public void start()(Code) | | Starts the garbage collection process.
|
startFilterDatabaseObjectReferencesAtExternalDatabaseGates | protected void startFilterDatabaseObjectReferencesAtExternalDatabaseGates()(Code) | | |
startup | public void startup()(Code) | | |
sweepUnreachableObjects | protected void sweepUnreachableObjects()(Code) | | Sweeps all objects which are considered unreachable.
|
Fields inherited from org.ozoneDB.core.ServerComponent | protected transient Env env(Code)(Java Doc)
|
|
|
|