There maybe a few of you out there (when I mean few, hopefully a few million :)) that maybe interested in how Terracotta collects its Distributed Objects that is no longer in use. Ok here goes...
Objects that should be collected by DSO Garbage Collection are objects which are no longer referenced by any client (meaning the object has already been GCed locally on every client that held it). So now that the clients have no more use for this object, its up to the server array to dispose of it (i.e. remove it from the server array cache or terraocotta's persistent storage).
When DGC kicks in..
1. It starts monitoring for new objects being created and keep a set of those. This is used later to rescue GC candidates.
2. It does its initial mark, which is to get all the ObjectIDs in the system. And also our roots in the system. We remove the roots and well as object reachable by roots form GC Candidates set. The objects that are left are objects that are no longer referenced by anyone
3. Remember when monitoring new object references was turned on? Now new referenced objects that appeared in our GC Candidate set can be removed from that set. This means there were new references to those objects while our first marking was going on, so they need to be rescued and not collected anymore. If after this rescue there are no GC candidates, then GC is complete.
4. If there are still GC Candidates left, then the system is paused. For us this means pausing our ObjectManager so that new lookup or create requests
goes pending (i.e no new references are created). We now do another rescue and produce our final GC Candidate set for this GC Cycle. Then new reference monitoring is turned off.
5. finally we have a have a set to delete and pass that list onto a different thread that will delete the GC Candidates from the ObjectManager in batches.
Since the delete is staged on a different thread (SEDA arch). It is possible for another GC Cycle to kick in before all the delete request complete, which can in turn create more objects to delete and life goes on...
Up next: Young GC Candidates....