use of org.bboxdb.distribution.membership.BBoxDBInstance in project bboxdb by jnidzwetzki.
the class TestStorageUtilizationRessourcePlacement method testUtilPlacement.
/**
* Test round robin placement 1
* @throws ResourceAllocationException
*/
@Test(timeout = 60000)
public void testUtilPlacement() throws ResourceAllocationException {
final ResourcePlacementStrategy resourcePlacementStrategy = getPlacementStrategy();
final List<BBoxDBInstance> systems = new ArrayList<>();
final BBoxDBInstance instance1 = new BBoxDBInstance("node1:123", "0.1", BBoxDBInstanceState.READY);
systems.add(instance1);
instance1.addFreeSpace("/tmp", 10);
instance1.addTotalSpace("/tmp", 10);
final BBoxDBInstance instance2 = new BBoxDBInstance("node2:123", "0.1", BBoxDBInstanceState.READY);
systems.add(instance2);
instance2.addFreeSpace("/tmp", 10);
instance2.addTotalSpace("/tmp", 10);
instance2.addFreeSpace("/tmp2", 10);
instance2.addTotalSpace("/tmp2", 10);
final BBoxDBInstance instance3 = new BBoxDBInstance("node3:123", "0.1", BBoxDBInstanceState.READY);
systems.add(instance3);
instance3.addFreeSpace("/tmp", 10);
instance3.addTotalSpace("/tmp", 10);
instance3.addFreeSpace("/tmp2", 10);
instance3.addTotalSpace("/tmp2", 10);
instance3.addFreeSpace("/tmp3", 10);
instance3.addTotalSpace("/tmp3", 10);
final BBoxDBInstance instance4 = new BBoxDBInstance("node4:123", "0.1", BBoxDBInstanceState.READY);
systems.add(instance4);
instance4.addFreeSpace("/tmp", 10);
instance4.addTotalSpace("/tmp", 10);
instance4.addFreeSpace("/tmp2", 10);
instance4.addTotalSpace("/tmp2", 10);
instance4.addFreeSpace("/tmp3", 10);
instance4.addTotalSpace("/tmp3", 10);
instance4.addFreeSpace("/tmp4", 10);
instance4.addTotalSpace("/tmp4", 10);
utilization.clear();
utilization.setCount(systems.get(0), 1);
utilization.setCount(systems.get(1), 1);
utilization.setCount(systems.get(2), 1);
Assert.assertEquals(systems.get(3), resourcePlacementStrategy.getInstancesForNewRessource(systems));
utilization.clear();
utilization.setCount(systems.get(0), 1);
utilization.setCount(systems.get(1), 1);
utilization.setCount(systems.get(2), 1);
utilization.setCount(systems.get(3), 1);
Assert.assertEquals(systems.get(3), resourcePlacementStrategy.getInstancesForNewRessource(systems));
utilization.setCount(systems.get(3), 100);
Assert.assertEquals(systems.get(2), resourcePlacementStrategy.getInstancesForNewRessource(systems));
}
use of org.bboxdb.distribution.membership.BBoxDBInstance in project bboxdb by jnidzwetzki.
the class BBoxDBMain method createMembershipService.
/**
* Returns a new instance of the membership service
* @param storageRegistry
* @return
*/
public MembershipConnectionService createMembershipService(final TupleStoreManagerRegistry storageRegistry) {
final MembershipConnectionService membershipService = MembershipConnectionService.getInstance();
// Prevent network connections to ourself
final BBoxDBInstance localhost = ZookeeperClientFactory.getLocalInstanceName();
membershipService.addSystemToBlacklist(localhost);
// The storage registry for gossip
membershipService.setTupleStoreManagerRegistry(storageRegistry);
return membershipService;
}
use of org.bboxdb.distribution.membership.BBoxDBInstance in project bboxdb by jnidzwetzki.
the class DistributedRecoveryService method runRecoveryForDistributionGroup.
/**
* Run recovery for distribution group
* @param distributionGroupName
* @throws ZookeeperException
*/
protected void runRecoveryForDistributionGroup(final String distributionGroupName) {
try {
final ZookeeperClient zookeeperClient = ZookeeperClientFactory.getZookeeperClient();
final BBoxDBInstance localInstance = ZookeeperClientFactory.getLocalInstanceName();
for (final DiskStorage storage : storageRegistry.getAllStorages()) {
checkGroupVersion(storage, distributionGroupName, zookeeperClient);
}
final SpacePartitioner spacePartitioner = SpacePartitionerCache.getInstance().getSpacePartitionerForGroupName(distributionGroupName);
final DistributionRegion distributionGroup = spacePartitioner.getRootNode();
final List<OutdatedDistributionRegion> outdatedRegions = DistributionRegionHelper.getOutdatedRegions(distributionGroup, localInstance);
handleOutdatedRegions(distributionGroupName, outdatedRegions);
} catch (Throwable e) {
logger.error("Got exception while running recovery for distribution group: " + distributionGroupName, e);
}
}
use of org.bboxdb.distribution.membership.BBoxDBInstance in project bboxdb by jnidzwetzki.
the class StaticgridSpacePartitioner method createGridInDimension.
/**
* Create the grid in the given dimension
* @param splitConfig
* @param rootPath
* @param rootBox
* @param dimension
* @throws ZookeeperException
* @throws InputParseException
* @throws ResourceAllocationException
* @throws ZookeeperNotFoundException
*/
private void createGridInDimension(final String[] splitConfig, final String parentPath, final BoundingBox box, final int dimension) throws ZookeeperException, InputParseException, ZookeeperNotFoundException, ResourceAllocationException {
logger.info("Processing dimension {}", dimension);
final String fullname = distributionGroupName;
final String stepIntervalString = splitConfig[dimension + 1];
final double stepInterval = MathUtil.tryParseDouble(stepIntervalString, () -> "Unable to parse" + stepIntervalString);
BoundingBox boundingBoxToSplit = box;
int childNumber = 0;
while (boundingBoxToSplit != null) {
final double splitPos = boundingBoxToSplit.getCoordinateLow(dimension) + stepInterval;
BoundingBox nodeBox;
if (splitPos >= boundingBoxToSplit.getCoordinateHigh(dimension)) {
nodeBox = boundingBoxToSplit;
boundingBoxToSplit = null;
} else {
nodeBox = boundingBoxToSplit.splitAndGetRight(splitPos, dimension, false);
boundingBoxToSplit = boundingBoxToSplit.splitAndGetRight(splitPos, dimension, true);
}
final String childPath = distributionRegionZookeeperAdapter.createNewChild(parentPath, childNumber, nodeBox, fullname);
if (dimension == 0) {
SpacePartitionerHelper.allocateSystemsToRegion(childPath, distributionGroupName, new ArrayList<BBoxDBInstance>(), zookeeperClient);
distributionRegionZookeeperAdapter.setStateForDistributionGroup(childPath, DistributionRegionState.ACTIVE);
} else {
distributionRegionZookeeperAdapter.setStateForDistributionGroup(childPath, DistributionRegionState.SPLIT);
createGridInDimension(splitConfig, childPath, nodeBox, dimension - 1);
}
childNumber++;
}
}
use of org.bboxdb.distribution.membership.BBoxDBInstance in project bboxdb by jnidzwetzki.
the class RegionMergeHelper method isRegionUnderflow.
/**
* Needs the region a merge?
* @param region
* @return
* @throws BBoxDBException
*/
public static boolean isRegionUnderflow(final List<DistributionRegion> sources) throws BBoxDBException {
assert (!sources.isEmpty()) : "Sources can not be empty";
final List<String> sourceIds = getRegionIdsFromRegionList(sources);
logger.info("Testing for underflow: {}", sourceIds);
final boolean inactiveChilds = sources.stream().anyMatch(c -> c.getState() != DistributionRegionState.ACTIVE);
if (inactiveChilds) {
logger.info("Not all children ready, skip merge test for {}", sourceIds);
return false;
}
// We are not responsible to this region
final BBoxDBInstance localInstanceName = ZookeeperClientFactory.getLocalInstanceName();
final boolean localSystemContained = sources.stream().anyMatch(r -> r.getSystems().contains(localInstanceName));
if (!localSystemContained) {
logger.info("Not testing for underflow for {} on {}", sourceIds, localInstanceName);
return false;
}
final OptionalDouble childRegionSize = getTotalRegionSize(sources);
if (!childRegionSize.isPresent()) {
logger.info("Got invalid statistics for {}", sourceIds);
return false;
}
try {
final String fullname = sources.get(0).getDistributionGroupName();
final long minSize = getConfiguredRegionMinSizeInMB(fullname);
final double childDoubleSize = childRegionSize.getAsDouble();
logger.info("Testing for region {} underflow curent size is {} / min is {}", sourceIds, childDoubleSize, minSize);
return (childDoubleSize < minSize);
} catch (ZookeeperException | ZookeeperNotFoundException e) {
throw new BBoxDBException(e);
}
}
Aggregations