@Override public <A extends Writable> A getAggregatedValue(String name) { AggregationStorageMetadata metadata = Configuration.get().getAggregationMetadata(name); if (metadata == null) { return super.getAggregatedValue(name); } else { AggregationStorage aggregationStorage = inboundAggregationStorages.get(name); if (aggregationStorage == null) { int numSplits = metadata.getNumSplits(); AggregationStorageWrapper storageWrapper = new AggregationStorageWrapper(); for (int i = 0; i < numSplits; ++i) { AggregationStorageWrapper storageWrapperSplit = getAggregatedValue(Configuration.get().getAggregationSplitName(name, i)); storageWrapper.aggregate(storageWrapperSplit); } aggregationStorage = storageWrapper.getAggregationStorage(); if (aggregationStorage == null) { aggregationStorage = aggregationStorageFactory.createAggregationStorage(name, metadata); } inboundAggregationStorages.put(name, aggregationStorage); } return (A) aggregationStorage; } }
private void registerAggregationStore( String aggName, AggregationStorageMetadata aggStorageMetadata) throws IllegalAccessException, InstantiationException { boolean isPersistent = aggStorageMetadata.isPersistent(); int numSplits = aggStorageMetadata.getNumSplits(); for (int i = 0; i < numSplits; ++i) { String splitName = Configuration.get().getAggregationSplitName(aggName, i); if (isPersistent) { registerPersistentAggregator(splitName, AggregationStorageAggregator.class); } else { registerAggregator(splitName, AggregationStorageAggregator.class); } } }
private void splitAggregationStoragesAndSend( String name, AggregationStorageMetadata metadata, AggregationStorage aggregationStorage) { Configuration conf = Configuration.get(); int numSplits = metadata.getNumSplits(); if (numSplits == 1) { AggregationStorageWrapper aggWrapper = new AggregationStorageWrapper(aggregationStorage); super.setAggregatedValue(conf.getAggregationSplitName(name, 0), aggWrapper); } else { Collection<Writable> keysToTransfer = new ArrayList<>(aggregationStorage.getNumberMappings()); for (int i = 0; i < numSplits; ++i) { AggregationStorage aggStorageSplit = aggregationStorageFactory.createAggregationStorage(name); AggregationStorageWrapper aggStorageSplitWrapper = new AggregationStorageWrapper(aggStorageSplit); keysToTransfer.clear(); for (Object key : aggregationStorage.getKeys()) { int owner = key.hashCode() % numSplits; if (owner < 0) { owner += numSplits; } if (owner != i) { continue; } keysToTransfer.add((Writable) key); } for (Writable key : keysToTransfer) { aggStorageSplit.transferKeyFrom(key, aggregationStorage); } super.setAggregatedValue(conf.getAggregationSplitName(name, i), aggStorageSplitWrapper); } } }