public final class PartitionRegionHelper extends Object
Functions
on a Partitioned Region.
Example of a Function using utility methods:
public Serializable execute(FunctionContext context) { if (context instanceof RegionFunctionContext) { RegionFunctionContext rc = (RegionFunctionContext) context; if (PartitionRegionHelper.isPartitionedRegion(rc.getDataSet())) { Region efficientReader = PartitionRegionHelper.getLocalDataForContext(rc); efficientReader.get("someKey"); // ... } } // ...
FunctionService.onRegion(Region)
Modifier and Type | Method and Description |
---|---|
static void |
assignBucketsToPartitions(Region<?,?> region)
Decide which partitions will host which buckets.
|
static <K,V> Set<DistributedMember> |
getAllMembersForKey(Region<K,V> r,
K key)
Get all potential owners for a key.
|
static Map<String,Region<?,?>> |
getColocatedRegions(Region<?,?> r)
Given a partitioned Region, return a map of
colocated Regions.
|
static Map<String,Region<?,?>> |
getLocalColocatedRegions(RegionFunctionContext c)
Given a RegionFunctionContext for a partitioned
Region, return a map of colocated Regions with read access limited to the context of the function.
|
static <K,V> Region<K,V> |
getLocalData(Region<K,V> r)
Given a partitioned Region return a Region providing read access limited to the local heap,
writes using this Region have no constraints and behave the same as a partitioned Region.
|
static <K,V> Region<K,V> |
getLocalDataForContext(RegionFunctionContext c)
Given a RegionFunctionContext for a partitioned
Region, return a Region providing read access limited to the function context.
Returned Region provides only one copy of the data although redundantCopies configured is more than 0. |
static <K,V> Region<K,V> |
getLocalPrimaryData(Region<K,V> r)
Given a partitioned Region return a Region providing read access to primary copy of the data
which is limited to the local heap, writes using this Region have no constraints and behave the
same as a partitioned Region.
|
static Set<PartitionRegionInfo> |
getPartitionRegionInfo(Cache cache)
Gathers a set of details about all partitioned regions in the local Cache.
|
static PartitionRegionInfo |
getPartitionRegionInfo(Region<?,?> region)
Gathers details about the specified partitioned region.
|
static <K,V> DistributedMember |
getPrimaryMemberForKey(Region<K,V> r,
K key)
Get the current primary owner for a key.
|
static <K,V> Set<DistributedMember> |
getRedundantMembersForKey(Region<K,V> r,
K key)
Get all potential redundant owners for a key.
|
static boolean |
isPartitionedRegion(Region<?,?> r)
Test a Region to see if it is a partitioned Region
|
static <K> void |
moveBucketByKey(Region<K,?> region,
DistributedMember source,
DistributedMember destination,
K key)
Moves the bucket which contains the given key from the source member to the destination member.
|
static RebalanceResults |
moveData(Region<?,?> region,
DistributedMember source,
DistributedMember destination,
float percentage)
Moves data from the source member to the destination member, up to the given percentage of data
(measured in bytes).
|
public static Map<String,Region<?,?>> getColocatedRegions(Region<?,?> r)
r
- a partitioned RegionRegion
IllegalStateException
- if the Region is not a partitioned Regionpublic static boolean isPartitionedRegion(Region<?,?> r)
r
- the regionpublic static Set<PartitionRegionInfo> getPartitionRegionInfo(Cache cache)
cache
- the cache which has the regionspublic static PartitionRegionInfo getPartitionRegionInfo(Region<?,?> region)
region
- the region to get info aboutpublic static void assignBucketsToPartitions(Region<?,?> region)
region
- The region which should have it's buckets assigned.IllegalStateException
- if the provided region is something other than a
partitioned Regionpublic static <K,V> DistributedMember getPrimaryMemberForKey(Region<K,V> r, K key)
This method is not a substitute for Region.containsKey(Object)
.
K
- The key type of the regionV
- The value type of the regionr
- a PartitionedRegionkey
- the key to evaluateIllegalStateException
- if the provided region is something other than a
partitioned Regionpublic static <K,V> Set<DistributedMember> getRedundantMembersForKey(Region<K,V> r, K key)
This method is not a substitute for Region.containsKey(Object)
.
This method is equivalent to:
DistributedMember primary = getPrimaryMemberForKey(r, key);
Set<? extends DistributedMember> allMembers = getAllMembersForKey(r, key);
allMembers.remove(primary);
K
- The key type of the regionV
- The value type of the regionr
- a PartitionedRegionkey
- the key to evaluateIllegalStateException
- if the provided region is something other than a
partitioned Regionpublic static <K,V> Set<DistributedMember> getAllMembersForKey(Region<K,V> r, K key)
This method is not a substitute for Region.containsKey(Object)
.
K
- The key type of the regionV
- The value type of the regionr
- PartitionedRegionkey
- the key to evaluateIllegalStateException
- if the provided region is something other than a
partitioned Regionpublic static Map<String,Region<?,?>> getLocalColocatedRegions(RegionFunctionContext c)
Writes using these Region have no constraints and behave the same as a partitioned Region.
If there are no colocated regions, return an empty map.
c
- the region function contextRegion
IllegalStateException
- if the Region is not a partitioned Regionpublic static <K,V> Region<K,V> getLocalDataForContext(RegionFunctionContext c)
redundantCopies
configured is more than 0. If
the invoking Function is configured to have optimizeForWrite
as true,the returned Region will only contain primary copy of the data.
Writes using this Region have no constraints and behave the same as a partitioned Region.
K
- The key type of the regionV
- The value type of the regionc
- a functions contextIllegalStateException
- if RegionFunctionContext.getDataSet()
returns something
other than a partitioned Regionpublic static <K,V> Region<K,V> getLocalData(Region<K,V> r)
K
- The key type of the regionV
- The value type of the regionr
- a partitioned regionIllegalStateException
- if the provided region is something other than a
partitioned Regionpublic static <K,V> Region<K,V> getLocalPrimaryData(Region<K,V> r)
K
- The key type of the regionV
- The value type of the regionr
- a partitioned regionIllegalStateException
- if the provided region is something other than a
partitioned Regionpublic static <K> void moveBucketByKey(Region<K,?> region, DistributedMember source, DistributedMember destination, K key)
All keys which exist in the same bucket will also be moved to the new node.
Any data in colocated regions that are colocated with this key will also be moved.
This method allows direct control of what data to move. To automatically balance buckets, see
ResourceManager.createRebalanceFactory()
K
- The key type of the regionregion
- The region in which to move the bucket. Data in regions colocated with this
region will also be moved.source
- A member that is currently hosting this bucket. The bucket is moved off of this
member.destination
- A member that is not currently hosting this bucket, but has the partitioned
region defined. The bucket is moved to this member.key
- A key which maps to the bucket to move. This key does not actually need to exist in
the region, but if using a PartitionResolver
the resolver should be able to get
the routing object from this key to determine the bucket to move.IllegalStateException
- if the bucket is not present on the source, if the source or
destination are not valid members of the system, if the destination already hosts a
copy of the bucket, or if the bucket does not exist.public static RebalanceResults moveData(Region<?,?> region, DistributedMember source, DistributedMember destination, float percentage)
If this region has colocated regions, the colocated data will also be moved. The total amount of data in all colocated regions will be taken into consideration when determining what percentage of data will be moved.
It may not be possible to move data to the destination member, if the destination member has no available space, no bucket smaller than the given percentage exists, or if moving data would violate redundancy constraints. If data cannot be moved, this method will return a RebalanceResult object with 0 total bucket transfers.
This method allows direct control of what data to move. To automatically balance buckets, see
ResourceManager.createRebalanceFactory()
region
- The region in which to move data. Data in regions colocated with this region will
also be moved.source
- A member that is currently hosting data. The bucket is moved off of this member.destination
- A member that that has the partitioned region defined. Data is moved to this
member.percentage
- the maximum amount of data to move, as a percentage from 0 to 100.IllegalStateException
- if the source or destination are not valid members of the system.IllegalArgumentException
- if the percentage is not between 0 to 100.