C
- container of the data structurepublic abstract class AbstractContainerCollector<C> extends Object
SplitBrainHandlerService
capable data structures.
The ClusterMergeTask
collects all mergeable data from all Hazelcast services. The problem is that it
runs on an arbitrary thread, but the data is only modified by specific
partition threads
.
This can cause visibility issues due to a missing happens-before relation.
The collector fetches the data via PartitionSpecificRunnable
(which
run on the partition threads) and stores them in a ConcurrentHashMap
.
This guarantees the visibility for the ClusterMergeTask
.
The collector can be implemented for data structures which reference their containers by
AbstractContainerCollector
AbstractNamedContainerCollector
ManagedService.reset()
is not allowed to clear or destroy those containers.
To ensure this the collector removes the link between the data structure and a container
via Iterator.remove()
in CollectContainerRunnable#run()
.
The cleanup of the containers itself is done in destroy()
via destroy(Object)
after the merge is done, or directly if the container is not collected. Containers from backup
partitions are directly cleaned via destroyBackup(Object)
.
Modifier and Type | Class and Description |
---|---|
protected class |
AbstractContainerCollector.EmptyIterator
Empty iterator for
containerIterator(int) calls, if the requested partition is empty. |
Modifier | Constructor and Description |
---|---|
protected |
AbstractContainerCollector(NodeEngine nodeEngine) |
Modifier and Type | Method and Description |
---|---|
protected abstract Iterator<C> |
containerIterator(int partitionId)
Returns all containers of the data structure for the given partition ID.
|
void |
destroy()
Destroys all collected containers.
|
protected abstract void |
destroy(C container)
Destroys the owned data in the container.
|
protected abstract void |
destroyBackup(C container)
Destroys the backup data in the container.
|
ConcurrentMap<Integer,Collection<C>> |
getCollectedContainers()
Returns the collected containers by partition ID.
|
protected abstract MergePolicyConfig |
getMergePolicyConfig(C container)
Returns the
MergePolicyConfig of the container. |
protected abstract int |
getMergingValueCount()
Returns the number of collected merging values in this collector.
|
protected boolean |
isMergeable(C container)
Determines if the container should be merged.
|
protected void |
onDestroy()
Will be called by
destroy() . |
void |
run()
Collects the containers from the data structure in a thread-safe way.
|
protected AbstractContainerCollector(NodeEngine nodeEngine)
public final void run()
public final ConcurrentMap<Integer,Collection<C>> getCollectedContainers()
public final void destroy()
protected void onDestroy()
destroy()
.
Can be overridden by implementations to cleanup local resources.
protected abstract Iterator<C> containerIterator(int partitionId)
Iterator
over the containers of the given partitionprotected abstract MergePolicyConfig getMergePolicyConfig(C container)
MergePolicyConfig
of the container.MergePolicyConfig
of the containerprotected abstract void destroy(C container)
Is called if a container is not collected or after the merge has been done.
protected abstract void destroyBackup(C container)
Is called if the container is not collected, since it's in a backup partition.
protected abstract int getMergingValueCount()
The count is used to calculate the timeout value to wait for merge operations to complete.
Note: Depending on the data structure, this can be the number of collected containers or the number of merging values within the collected containers.
protected boolean isMergeable(C container)
Can be overridden if there are additional restrictions beside the merge policy, if a container is mergeable or not.
true
if the container is mergeable, false
otherwiseCopyright © 2022 Hazelcast, Inc.. All Rights Reserved.