Creating dynamic global indexes
If you need to efficiently access an object or set of objects in eXtreme Scale 8.6 or XC10 2.5, a global index is one of the best ways to accomplish the task. Creating and using a global index is relatively straightforward:
HashIndex globalIndex = new HashIndex();
globalIndex.setName("productCodeGI");
globalIndex.setAttributeName("productCode");
globalIndex.setRangeIndex(false);
globalIndex.setGlobalIndexEnabled(true);
getObjectGrid().getMap("test").createDynamicIndex(
globalIndex,null);
The above code creates a global index named productCodeGI which is index the field name productCode on inserted objects in the map named test. To use the index to find all keys with productCode==2
MapGlobalIndex codeGlobalIndex =
(MapGlobalIndex) map.getIndex("productCodeGI");
Set s = codeGlobalIndex.findKeys(new Integer(2));
More information on the operations available on the global index are in the javadoc here
The use of the global index can significantly speed up access for secondary attributes since the global index can be consulted to find out which partitions contain key-value pairs that match the search condition. This could reduce your RPCs from 100s to 2 (in the case only 1 partition has an object matching the condition).