use of org.bboxdb.storage.entity.DistributionGroupConfiguration in project bboxdb by jnidzwetzki.
the class BenchmarkFileInsertPerformance method prepare.
@Override
protected void prepare() throws Exception {
super.prepare();
// Remove old data
final EmptyResultFuture deleteResult = bboxdbClient.deleteDistributionGroup(DISTRIBUTION_GROUP);
deleteResult.waitForAll();
// Create a new distribution group
final DistributionGroupConfiguration config = DistributionGroupConfigurationBuilder.create(2).withReplicationFactor(replicationFactor).build();
final EmptyResultFuture createResult = bboxdbClient.createDistributionGroup(DISTRIBUTION_GROUP, config);
createResult.waitForAll();
}
use of org.bboxdb.storage.entity.DistributionGroupConfiguration in project bboxdb by jnidzwetzki.
the class BBoxDBClientExample method main.
/**
* Connect to the BBoxDB Server at localhost and insert some tuples
*
* @param args
* @throws ExecutionException
* @throws InterruptedException
* @throws BBoxDBException
*/
public static void main(String[] args) throws InterruptedException, ExecutionException, BBoxDBException {
// A 2 dimensional table (member of distribution group 'mygroup3') with the name 'testdata'
final int dimensions = 2;
final String distributionGroup = "mygroup3";
final String mytable = distributionGroup + "_testdata";
// The name of the cluster
final String clustername = "mycluster";
// The zookeeper connect points
final List<String> connectPoints = Arrays.asList("localhost:2181");
// Connect to the server
final BBoxDB bboxdbClient = new BBoxDBCluster(connectPoints, clustername);
bboxdbClient.connect();
// Check the connection state
if (!bboxdbClient.isConnected()) {
System.out.println("Error while connecting to the BBoxDB cluster");
System.exit(-1);
}
// Clean the old content of the distribution group
final EmptyResultFuture deleteGroupResult = bboxdbClient.deleteDistributionGroup(distributionGroup);
deleteGroupResult.waitForAll();
if (deleteGroupResult.isFailed()) {
System.err.println("Unable to delete distribution group: " + distributionGroup);
System.err.println(deleteGroupResult.getAllMessages());
System.exit(-1);
}
// Create a new distribution group
final DistributionGroupConfiguration configuration = DistributionGroupConfigurationBuilder.create(dimensions).withReplicationFactor((short) 3).build();
final EmptyResultFuture createGroupResult = bboxdbClient.createDistributionGroup(distributionGroup, configuration);
createGroupResult.waitForAll();
if (createGroupResult.isFailed()) {
System.err.println("Unable to create distribution group: " + distributionGroup);
System.err.println(createGroupResult.getAllMessages());
System.exit(-1);
}
// Create the table
final TupleStoreConfiguration tableConfig = TupleStoreConfigurationBuilder.create().allowDuplicates(false).build();
final EmptyResultFuture createTableResult = bboxdbClient.createTable(mytable, tableConfig);
createTableResult.waitForAll();
if (createTableResult.isFailed()) {
System.err.println("Unable to create table group: " + mytable);
System.err.println(createTableResult.getAllMessages());
System.exit(-1);
}
// Insert two new tuples
final Tuple tuple1 = new Tuple("key1", new BoundingBox(0d, 5d, 0d, 1d), "mydata1".getBytes());
final EmptyResultFuture insertResult1 = bboxdbClient.insertTuple(mytable, tuple1);
final Tuple tuple2 = new Tuple("key2", new BoundingBox(-1d, 2d, -1d, 2d), "mydata2".getBytes());
final EmptyResultFuture insertResult2 = bboxdbClient.insertTuple(mytable, tuple2);
// Wait for the insert operations to complete
insertResult1.waitForAll();
insertResult2.waitForAll();
if (insertResult1.isFailed()) {
System.err.println("Unable to insert tuple: " + insertResult1.getAllMessages());
System.exit(-1);
}
if (insertResult2.isFailed()) {
System.err.println("Unable to insert tuple: " + insertResult2.getAllMessages());
System.exit(-1);
}
// Query by key
final TupleListFuture resultFuture1 = bboxdbClient.queryKey(mytable, "key");
// We got a future object, the search is performed asynchronous
// Wait for the result
resultFuture1.waitForAll();
if (resultFuture1.isFailed()) {
System.err.println("NetworkOperationFuture is failed: " + resultFuture1.getAllMessages());
System.exit(-1);
}
// Output all tuples
for (final Tuple tuple : resultFuture1) {
System.out.println(tuple);
}
// Query by bounding box
final TupleListFuture resultFuture2 = bboxdbClient.queryBoundingBox(mytable, new BoundingBox(-0.5d, 1d, -0.5d, 1d));
// Again, we got a future object, the search is performed asynchronous
resultFuture2.waitForAll();
if (resultFuture2.isFailed()) {
System.err.println("NetworkOperationFuture is failed: " + resultFuture2.getAllMessages());
System.exit(-1);
}
// Output all tuples
for (final Tuple tuple : resultFuture2) {
System.out.println("Tuple: " + tuple);
}
bboxdbClient.disconnect();
}
use of org.bboxdb.storage.entity.DistributionGroupConfiguration in project bboxdb by jnidzwetzki.
the class CreateDistributionGroupRequest method decodeTuple.
/**
* Decode the encoded package into a object
*
* @param encodedPackage
* @return
* @throws PackageEncodeException
*/
public static CreateDistributionGroupRequest decodeTuple(final ByteBuffer encodedPackage) throws PackageEncodeException {
final short sequenceNumber = NetworkPackageDecoder.getRequestIDFromRequestPackage(encodedPackage);
final boolean decodeResult = NetworkPackageDecoder.validateRequestPackageHeader(encodedPackage, NetworkConst.REQUEST_TYPE_CREATE_DISTRIBUTION_GROUP);
if (decodeResult == false) {
throw new PackageEncodeException("Unable to decode package");
}
final int dimensions = encodedPackage.getInt();
final short replicationFactor = encodedPackage.getShort();
final short groupLength = encodedPackage.getShort();
final short placementLength = encodedPackage.getShort();
final short spacePartitionerLength = encodedPackage.getShort();
final int placementConfigLength = encodedPackage.getInt();
final int spacePartitionerConfigLength = encodedPackage.getInt();
final int maximumRegionSize = encodedPackage.getInt();
final int minimumRegionSize = encodedPackage.getInt();
// Distribution group
final byte[] groupBytes = new byte[groupLength];
encodedPackage.get(groupBytes, 0, groupBytes.length);
final String distributionGroup = new String(groupBytes);
// Placement strategy
final byte[] placementBytes = new byte[placementLength];
encodedPackage.get(placementBytes, 0, placementBytes.length);
final String placemeneStrategy = new String(placementBytes);
// Placement config length
final byte[] placementConfigBytes = new byte[placementConfigLength];
encodedPackage.get(placementConfigBytes, 0, placementConfigBytes.length);
final String placementConfig = new String(placementConfigBytes);
// Space partitioner
final byte[] spacePartitionerBytes = new byte[spacePartitionerLength];
encodedPackage.get(spacePartitionerBytes, 0, spacePartitionerBytes.length);
final String spacePartitioner = new String(spacePartitionerBytes);
// Space partitioner configuration
final byte[] spacePartitionerConfigBytes = new byte[spacePartitionerConfigLength];
encodedPackage.get(spacePartitionerConfigBytes, 0, spacePartitionerConfigBytes.length);
final String spacePartitionerConfig = new String(spacePartitionerConfigBytes);
if (encodedPackage.remaining() != 0) {
throw new PackageEncodeException("Some bytes are left after decoding: " + encodedPackage.remaining());
}
final DistributionGroupConfiguration configuration = DistributionGroupConfigurationBuilder.create(dimensions).withPlacementStrategy(placemeneStrategy, placementConfig).withSpacePartitioner(spacePartitioner, spacePartitionerConfig).withMaximumRegionSize(maximumRegionSize).withMinimumRegionSize(minimumRegionSize).withReplicationFactor(replicationFactor).build();
return new CreateDistributionGroupRequest(sequenceNumber, distributionGroup, configuration);
}
use of org.bboxdb.storage.entity.DistributionGroupConfiguration in project bboxdb by jnidzwetzki.
the class TestNetworkCommunication method testCreateDistributionGroupTwoTimes.
/**
* Test create a distribution group two times
* @throws BBoxDBException
* @throws InterruptedException
*/
@Test(timeout = 60000)
public void testCreateDistributionGroupTwoTimes() throws BBoxDBException, InterruptedException {
final BBoxDBConnection bboxdbConnection = connectToServer();
final BBoxDBClient bboxDBClient = bboxdbConnection.getBboxDBClient();
// Create distribution group
final DistributionGroupConfiguration configuration = DistributionGroupConfigurationBuilder.create(2).withReplicationFactor((short) 1).build();
final EmptyResultFuture resultCreate = bboxDBClient.createDistributionGroup(DISTRIBUTION_GROUP, configuration);
// Prevent retries
resultCreate.setRetryPolicy(FutureRetryPolicy.RETRY_POLICY_NONE);
resultCreate.waitForAll();
Assert.assertTrue(resultCreate.isFailed());
Assert.assertEquals(ErrorMessages.ERROR_DGROUP_EXISTS, resultCreate.getMessage(0));
Assert.assertTrue(bboxdbConnection.getConnectionState().isInRunningState());
disconnect(bboxDBClient);
}
use of org.bboxdb.storage.entity.DistributionGroupConfiguration in project bboxdb by jnidzwetzki.
the class TestSampling method before.
@Before
public void before() throws ZookeeperException, BBoxDBException, StorageManagerException {
final DistributionGroupConfiguration configuration = DistributionGroupConfigurationBuilder.create(2).withPlacementStrategy("org.bboxdb.distribution.placement.DummyResourcePlacementStrategy", "").build();
storageRegistry.deleteAllTablesInDistributionGroup(TEST_GROUP);
distributionGroupZookeeperAdapter.deleteDistributionGroup(TEST_GROUP);
distributionGroupZookeeperAdapter.createDistributionGroup(TEST_GROUP, configuration);
}
Aggregations