Package com.tangosol.persistence
Class GUIDHelper
java.lang.Object
com.tangosol.persistence.GUIDHelper
Static helper methods to encode and decode the attributes related to the
storage of a persistent form of a partition.
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.
- Author:
- rhl/jh 2012.07.06
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Resolver used during a recovery to discover the newest available GUID for a given partition. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionassignStores
(Map<Integer, Object[]> mapConstraints, int cDistinctStores) Return a Map containing assignments of member id to stores based on the given constraints.createSortedEntries
(Map<K, Object[]> map) Return an array ofentries
based on the provided map ensuring the value (Object
array) is sorted.protected static void
evaluateGUID
(String sGUID, String[] asGUIDNewest, Set<String> setPrevGUIDs, int cPartitions) Evaluate the provided GUID ensuringasGUIDNewest
references the latest andsetPrevGUIDs
references previous GUIDs.static String
generateGUID
(int nPartition, long lVersion, long ldt, Member member) Generate and return a new GUID for the specified partition.static String
Return GUID in the specified list of GUIDs 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 aPartitionSet
with all partitions present in the providedmapStores
.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.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
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) Deprecated.protected static String[]
Return an array of the newest GUID for each partition, indexed by the partition-id and collect previous GUIDs into the provided set.static boolean
validateGUID
(String sGUID) Validate the given GUID.
-
Constructor Details
-
GUIDHelper
public GUIDHelper()
-
-
Method Details
-
generateGUID
Generate and return a new GUID for the specified partition.- Parameters:
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 only- Returns:
- a new GUID for the specified partition
-
validateGUID
Validate the given GUID.- Parameters:
sGUID
- the GUID to validate- Returns:
- true if the specified GUID is valid; false otherwise
-
getPartition
Parse the specified GUID and return the partition-id.- Parameters:
sGUID
- the GUID to return the partition-id for- Returns:
- the partition-id
-
getVersion
Parse the specified GUID and return the partition-version.- Parameters:
sGUID
- the GUID to return the partition-version for- Returns:
- the partition-version
-
getServiceJoinTime
Parse the specified GUID and return the service join time.- Parameters:
sGUID
- the GUID used to return the service join time- Returns:
- the service join
-
getMemberId
Parse the specified GUID and return the originating member-id.- Parameters:
sGUID
- the GUID to return the originating member-id for- Returns:
- the originating member-id
-
getGUID
Return GUID in the specified list of GUIDs for the specified partition.- Parameters:
listGUID
- the list of GUIDsnPartition
- the partition- Returns:
- GUID for the specified partition
-
resolveNewest
Deprecated.Replaced byresolveNewest(Map, Set, int)
.Return a list of the newest GUID for each partition, indexed by the partition-id.- Parameters:
colGUID
- the collection of GUIDs to resolvecPartitions
- the partition-count- Returns:
- a list of the newest GUID for each partition
-
resolveNewest
protected static String[] resolveNewest(Map<Member, String[]> mapGUID, Set<String> setPrevGUIDs, int cPartitions) Return an array of the newest GUID for each partition, indexed by the partition-id and collect previous GUIDs into the provided set.- Parameters:
mapGUID
- the map of GUIDs to resolvesetPrevGUIDs
- the set that holds old GUIDscPartitions
- the partition-count- Returns:
- an array of the newest GUID for each partition
-
evaluateGUID
protected static void evaluateGUID(String sGUID, String[] asGUIDNewest, Set<String> setPrevGUIDs, int cPartitions) Evaluate the provided GUID ensuringasGUIDNewest
references the latest andsetPrevGUIDs
references previous GUIDs.- Parameters:
sGUID
- the GUID to be evaluatedasGUIDNewest
- the array that contains the newest GUIDssetPrevGUIDs
- the set that contains the old GUIDscPartitions
- the partition-count
-
assignStores
public 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.The algorithm will attempt to fairly distribute assignment of stores across members while abiding to the given constraints. For example:
Member constraints and assignments 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} - Parameters:
mapConstraints
- the constraints to perform assignments withincDistinctStores
- the number of expected distinct stores- Returns:
- a Map containing assignments of member id to stores based on the given constraints
-
getPartitions
Return aPartitionSet
with all partitions present in the providedmapStores
.- Parameters:
mapStores
- a Map of member id to storescParts
- the partition count- Returns:
- a PartitionSet with all partitions present in the provided mapStores
-
parseAttribute
Return the specified (0-based) attribute from the GUID.- Parameters:
sGUID
- the GUIDid
- the (0-based) attribute index- Returns:
- the GUID attribute
-
intersects
Return a List of stores (GUIDs) that allows the caller to derive whether the provided sets are disjoint, intersect or equal. These three states can be derived as follows:States Result Reason null disjoint sets listReturn shared elements across LHS and RHS listReturn.size() == aoLHS.length == aoRHS.length LHS and RHS are equal - Parameters:
aoLHS
- the first set in the comparisonaoRHS
- the second set in the comparison- Returns:
- a List of stores that allows the caller to derive whether the provided sets are disjoint, intersect or equal
-
createSortedEntries
Return an array ofentries
based on the provided map ensuring the value (Object
array) is sorted.- Type Parameters:
K
- - the key type- Parameters:
map
- a map to base the Entry[] on- Returns:
- an array of
entries
ensuring the value (Object
array) is sorted
-
main
Utility that outputs information about a given GUID.
Usage: com.tangosol.persistence.GUIDHelper <GUID>- Parameters:
asArg
- command line arguments
-
resolveNewest(Map, Set, int)
.