use of org.bboxdb.distribution.region.DistributionRegionIdMapper in project bboxdb by jnidzwetzki.
the class StatisticsUpdateRunnable method updateRegionStatistics.
/**
* Update the statistics of the region
*/
private void updateRegionStatistics() {
try {
final List<String> allDistributionGroups = groupAdapter.getDistributionGroups();
for (final String distributionGroup : allDistributionGroups) {
final SpacePartitioner spacePartitioner = SpacePartitionerCache.getInstance().getSpacePartitionerForGroupName(distributionGroup);
final DistributionRegionIdMapper regionIdMapper = spacePartitioner.getDistributionRegionIdMapper();
final Collection<Long> allIds = regionIdMapper.getRegionIdsForRegion(BoundingBox.FULL_SPACE);
for (final long id : allIds) {
updateRegionStatistics(distributionGroup, id);
}
}
} catch (Exception e) {
logger.error("Got exception while updating statistics", e);
}
}
use of org.bboxdb.distribution.region.DistributionRegionIdMapper in project bboxdb by jnidzwetzki.
the class RegionMerger method redistributeDataMerge.
/**
* Redistribute the data in region merge
* @param source
* @param destination
* @throws Exception
*/
private void redistributeDataMerge(final List<DistributionRegion> source, final DistributionRegion destination) throws Exception {
logger.info("Redistributing all data for region (merge): " + destination.getIdentifier());
final String distributionGroupName = destination.getDistributionGroupName();
final List<TupleStoreName> localTables = TupleStoreUtil.getAllTablesForDistributionGroupAndRegionId(registry, distributionGroupName, destination.getRegionId());
// Add the local mapping, new data is written to the region
final SpacePartitioner spacePartitioner = SpacePartitionerCache.getInstance().getSpacePartitionerForGroupName(distributionGroupName);
final DistributionRegionIdMapper mapper = spacePartitioner.getDistributionRegionIdMapper();
// We have set the region to active, wait until we see this status change
// from Zookeeper and the space partitioner add this region as active
mapper.waitUntilMappingAppears(destination.getRegionId());
// Redistribute data
for (final TupleStoreName tupleStoreName : localTables) {
logger.info("Merging data of tuple store {}", tupleStoreName);
startFlushToDisk(tupleStoreName);
final TupleRedistributor tupleRedistributor = new TupleRedistributor(registry, tupleStoreName);
tupleRedistributor.registerRegion(destination);
for (final DistributionRegion childRegion : source) {
mergeDataFromChildRegion(destination, tupleStoreName, tupleRedistributor, childRegion);
}
logger.info("Final statistics for merge ({}): {}", tupleStoreName, tupleRedistributor.getStatistics());
}
}
use of org.bboxdb.distribution.region.DistributionRegionIdMapper in project bboxdb by jnidzwetzki.
the class RegionSplitter method redistributeDataSplit.
/**
* Redistribute data after region split
* @param region
*/
private void redistributeDataSplit(final DistributionRegion source, final List<DistributionRegion> destination) {
final long regionId = source.getRegionId();
try {
logger.info("Redistributing all data for region: {}", regionId);
final String distributionGroupName = source.getDistributionGroupName();
final List<TupleStoreName> localTables = TupleStoreUtil.getAllTablesForDistributionGroupAndRegionId(registry, distributionGroupName, regionId);
// Remove the local mapping, no new data is written to the region
final SpacePartitioner spacePartitioner = SpacePartitionerCache.getInstance().getSpacePartitionerForGroupName(distributionGroupName);
final DistributionRegionIdMapper mapper = spacePartitioner.getDistributionRegionIdMapper();
// We have set the region to splitting, wait until we see this status change
// from Zookeeper and the space partitioner removed this region as active
mapper.waitUntilMappingDisappears(regionId);
// Redistribute data
for (final TupleStoreName ssTableName : localTables) {
// Reject new writes and flush to disk
stopFlushToDisk(ssTableName);
distributeData(ssTableName, source, destination);
}
} catch (InterruptedException e) {
logger.warn("Thread was interrupted");
Thread.currentThread().interrupt();
return;
} catch (Exception e) {
logger.error("Got exception when redistribute local data", e);
return;
}
logger.info("Redistributing data for region: {} DONE", regionId);
}
use of org.bboxdb.distribution.region.DistributionRegionIdMapper in project bboxdb by jnidzwetzki.
the class KeepAliveHandler method checkLocalTuples.
/**
* @param tupleStoreManagerRegistry
* @param tupleStoreName
* @param tuple
* @throws BBoxDBException
* @throws StorageManagerException
*/
private boolean checkLocalTuples(final TupleStoreManagerRegistry tupleStoreManagerRegistry, final TupleStoreName tupleStoreName, final Tuple tuple) throws BBoxDBException {
final String fullname = tupleStoreName.getDistributionGroup();
final SpacePartitioner spacePartitioner = SpacePartitionerCache.getInstance().getSpacePartitionerForGroupName(fullname);
final DistributionRegionIdMapper regionIdMapper = spacePartitioner.getDistributionRegionIdMapper();
final Collection<TupleStoreName> localTables = regionIdMapper.getLocalTablesForRegion(tuple.getBoundingBox(), tupleStoreName);
for (final TupleStoreName localTupleStoreName : localTables) {
try {
final TupleStoreManager storageManager = tupleStoreManagerRegistry.getTupleStoreManager(localTupleStoreName);
final String key = tuple.getKey();
final List<Tuple> localTuples = storageManager.get(key);
if (localTables.isEmpty()) {
logger.error("Got empty tuple list during gossip");
return false;
}
final List<Long> localVersions = getSortedVersionList(localTuples);
final long gossipTupleVersion = tuple.getVersionTimestamp();
return checkLocalTupleVersions(localVersions, gossipTupleVersion, key);
} catch (StorageManagerException e) {
logger.error("Got exception while reading tuples", e);
}
}
return true;
}
use of org.bboxdb.distribution.region.DistributionRegionIdMapper in project bboxdb by jnidzwetzki.
the class TestRegionIdMapper method testMappingAppears1.
/**
* Wait until mapping appears
* @throws InterruptedException
* @throws TimeoutException
*/
@Test(timeout = 10000)
public void testMappingAppears1() throws TimeoutException, InterruptedException {
final DistributionRegionIdMapper regionIdMapper = new DistributionRegionIdMapper(DISTRIBUTION_REGION_NAME);
regionIdMapper.addMapping(3, new BoundingBox(15d, 18d, 15d, 18d));
regionIdMapper.waitUntilMappingAppears(3);
}
Aggregations