/** * Create a new shard mapping. * * @param type method by which data is distributed to shards * @param globalGroupName name of global group of the shard mapping * @returns id of the new shard mapping. */ public int createShardMapping(ShardingType type, String globalGroupName) throws FabricCommunicationException { Response r = errorSafeCallMethod( METHOD_SHARDING_CREATE_DEFINITION, new Object[] {type.toString(), globalGroupName}); return (Integer) r.getResultSet().get(0).get(FIELD_RESULT); }
/** * Retrieve a set of complete shard mappings. The returned mappings include all information * available about the mapping. * * @param shardMappingIdPattern the shard mapping id to retrieve */ public FabricStateResponse<Set<ShardMapping>> getShardMappings(String shardMappingIdPattern) throws FabricCommunicationException { int version = 0; Object args[] = new Object[] {version, shardMappingIdPattern}; // common to all calls Response mapsResponse = errorSafeCallMethod(METHOD_DUMP_SHARD_MAPS, args); // use the lowest ttl of all the calls long minExpireTimeMillis = System.currentTimeMillis() + (1000 * mapsResponse.getTtl()); // construct the maps Set<ShardMapping> mappings = new HashSet<ShardMapping>(); for (Map rawMapping : mapsResponse.getResultSet()) { int mappingId = (Integer) rawMapping.get(FIELD_MAPPING_ID); ShardingType shardingType = ShardingType.valueOf((String) rawMapping.get(FIELD_TYPE_NAME)); String globalGroupName = (String) rawMapping.get(FIELD_GLOBAL_GROUP_ID); FabricStateResponse<Set<ShardTable>> tables = getShardTables(mappingId); FabricStateResponse<Set<ShardIndex>> indices = getShardIndices(mappingId); if (tables.getExpireTimeMillis() < minExpireTimeMillis) { minExpireTimeMillis = tables.getExpireTimeMillis(); } if (indices.getExpireTimeMillis() < minExpireTimeMillis) { minExpireTimeMillis = indices.getExpireTimeMillis(); } ShardMapping m = new ShardMappingFactory() .createShardMapping( mappingId, shardingType, globalGroupName, tables.getData(), indices.getData()); mappings.add(m); } return new FabricStateResponse<Set<ShardMapping>>(mappings, minExpireTimeMillis); }