public class GUIDHelper extends Object
A persistence GUID must at minimum reflect the partition-id and a monotonically increasing partition-version that could be used to determine, given a set of GUIDs representing the same partition, a total ordering of the GUIDs over time.
Modifier and Type | Class and Description |
---|---|
static class |
GUIDHelper.GUIDResolver
Resolver used during a recovery to discover the newest available GUID for a given partition.
|
Constructor and Description |
---|
GUIDHelper() |
Modifier and Type | Method and Description |
---|---|
static Map<Integer,String[]> |
assignStores(Map<Integer,Object[]> mapConstraints, int cDistinctStores)
Return a Map containing assignments of member id to stores based on the given constraints.
|
protected static <K> Map.Entry<K,Object[]>[] |
createSortedEntries(Map<K,Object[]> map)
Return an array of
entries based on the provided map ensuring the value (Object[] ) is sorted. |
static String |
generateGUID(int nPartition, long lVersion, long ldt, Member member)
Generate and return a new GUID for the specified partition.
|
static int |
getMemberId(String sGUID)
Parse the specified GUID and return the originating member-id.
|
static int |
getPartition(String sGUID)
Parse the specified GUID and return the partition-id.
|
static PartitionSet |
getPartitions(Map<Integer,Object[]> mapStores, int cParts)
Return a
PartitionSet with all partitions present in the provided mapStores . |
static long |
getServiceJoinTime(String sGUID)
Parse the specified GUID and return the service join time.
|
static long |
getVersion(String sGUID)
Parse the specified GUID and return the partition-version.
|
protected static List<String> |
intersects(Object[] aoLHS, Object[] aoRHS)
Return a List of stores (GUIDs) that allows the caller to derive whether the provided sets are disjoint, intersect or equal.
|
static void |
main(String[] asArg)
Utility that outputs information about a given GUID.
|
protected static String |
parseAttribute(String sGUID, int id)
Return the specified (0-based) attribute from the GUID.
|
static String[] |
resolveNewest(Collection<String> colGUID, int cPartitions)
Return a list of the newest GUID for each partition, indexed by the partition-id.
|
static boolean |
validateGUID(String sGUID)
Validate the given GUID.
|
public static String generateGUID(int nPartition, long lVersion, long ldt, Member member)
nPartition
- the partition to return a GUID forlVersion
- the creation version of the partitionldt
- the creation timestamp; informational onlymember
- the member generating the GUID; informational onlypublic static boolean validateGUID(String sGUID)
sGUID
- the GUID to validatepublic static int getPartition(String sGUID)
sGUID
- the GUID to return the partition-id forpublic static long getVersion(String sGUID)
sGUID
- the GUID to return the partition-version forpublic static long getServiceJoinTime(String sGUID)
sGUID
- the GUID used to return the service join timepublic static int getMemberId(String sGUID)
sGUID
- the GUID to return the originating member-id forpublic static String[] resolveNewest(Collection<String> colGUID, int cPartitions)
colGUID
- the collection of GUIDs to resolvecPartitions
- the partition-countpublic static Map<Integer,String[]> assignStores(Map<Integer,Object[]> mapConstraints, int cDistinctStores)
The algorithm will attempt to fairly distribute assignment of stores across members while abiding to the given constraints. For example:
Member Id | Constraints | Assignments |
---|---|---|
1 | {a,b,c,d} | {a,c} |
2 | {a,b,c,d} | {b,d} |
3 | {e,f,g,h} | {e,g} |
4 | {e,f,g,h} | {f,h} |
mapConstraints
- the constraints to perform assignments withincDistinctStores
- the number of expected distinct storespublic static PartitionSet getPartitions(Map<Integer,Object[]> mapStores, int cParts)
PartitionSet
with all partitions present in the provided mapStores
.mapStores
- a Map of member id to storescParts
- the partition countprotected static String parseAttribute(String sGUID, int id)
sGUID
- the GUIDid
- the (0-based) attribute indexprotected static List<String> intersects(Object[] aoLHS, Object[] aoRHS)
Result | Reason |
---|---|
null | disjoint sets |
listReturn | shared elements across LHS and RHS |
listReturn.size() == aoLHS.length == aoRHS.length | LHS and RHS are equal |
aoLHS
- the first set in the comparisonaoRHS
- the second set in the comparisonprotected static <K> Map.Entry<K,Object[]>[] createSortedEntries(Map<K,Object[]> map)
entries
based on the provided map ensuring the value (Object[]
) is sorted.K
- - the key typemap
- a map to base the Entry[] onentries
ensuring the value (Object[]
) is sortedpublic static void main(String[] asArg)
asArg
- command line arguments