use of org.bboxdb.storage.entity.TupleStoreConfiguration in project bboxdb by jnidzwetzki.
the class TupleRedistributor method registerRegion.
/**
* Register a new region for distribution
* @param distributionRegion
* @throws StorageManagerException
* @throws ZookeeperException
*/
public void registerRegion(final DistributionRegion distributionRegion) throws StorageManagerException {
final ArrayList<AbstractTupleSink> sinks = new ArrayList<>();
final Collection<BBoxDBInstance> instances = distributionRegion.getSystems();
final MembershipConnectionService membershipConnectionService = MembershipConnectionService.getInstance();
final BBoxDBInstance localInstance = ZookeeperClientFactory.getLocalInstanceName();
for (final BBoxDBInstance instance : instances) {
if (instance.socketAddressEquals(localInstance)) {
final TupleStoreName localTableName = tupleStoreName.cloneWithDifferntRegionId(distributionRegion.getRegionId());
final TupleStoreAdapter tupleStoreAdapter = ZookeeperClientFactory.getZookeeperClient().getTupleStoreAdapter();
final TupleStoreConfiguration config = readTuplestoreConfig(localTableName, tupleStoreAdapter);
final TupleStoreManager storageManager = tupleStoreManagerRegistry.createTableIfNotExist(localTableName, config);
final LocalTupleSink tupleSink = new LocalTupleSink(tupleStoreName, storageManager);
sinks.add(tupleSink);
logger.info("Redistributing data to local table {}", localTableName.getFullname());
} else {
final BBoxDBConnection connection = membershipConnectionService.getConnectionForInstance(instance);
final NetworkTupleSink tupleSink = new NetworkTupleSink(tupleStoreName, connection);
sinks.add(tupleSink);
logger.info("Redistributing data to remote system {}", instance.getInetSocketAddress());
}
}
registerRegion(distributionRegion, sinks);
}
use of org.bboxdb.storage.entity.TupleStoreConfiguration 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.TupleStoreConfiguration in project bboxdb by jnidzwetzki.
the class QueryHelper method getTupleStoreManager.
/**
* Get or create the tuple store manager
* @param storageRegistry
* @param tupleStoreName
* @return
* @throws ZookeeperException
* @throws StorageManagerException
*/
public static TupleStoreManager getTupleStoreManager(TupleStoreManagerRegistry storageRegistry, final TupleStoreName tupleStoreName) throws ZookeeperException, StorageManagerException {
if (storageRegistry.isStorageManagerKnown(tupleStoreName)) {
return storageRegistry.getTupleStoreManager(tupleStoreName);
}
final TupleStoreAdapter tupleStoreAdapter = ZookeeperClientFactory.getZookeeperClient().getTupleStoreAdapter();
if (!tupleStoreAdapter.isTableKnown(tupleStoreName)) {
throw new StorageManagerException("Table: " + tupleStoreName.getFullname() + " is unkown");
}
final TupleStoreConfiguration config = tupleStoreAdapter.readTuplestoreConfiguration(tupleStoreName);
return storageRegistry.createTableIfNotExist(tupleStoreName, config);
}
use of org.bboxdb.storage.entity.TupleStoreConfiguration in project bboxdb by jnidzwetzki.
the class CreateTableRequest method decodeTuple.
/**
* Decode the encoded package into a object
*
* @param encodedPackage
* @return
* @throws PackageEncodeException
*/
public static CreateTableRequest decodeTuple(final ByteBuffer encodedPackage) throws PackageEncodeException {
final short sequenceNumber = NetworkPackageDecoder.getRequestIDFromRequestPackage(encodedPackage);
final boolean decodeResult = NetworkPackageDecoder.validateRequestPackageHeader(encodedPackage, NetworkConst.REQUEST_TYPE_CREATE_TABLE);
if (decodeResult == false) {
throw new PackageEncodeException("Unable to decode package");
}
// Table length
final short tableLength = encodedPackage.getShort();
// Allow duplicates
boolean allowDuplicates = false;
if (encodedPackage.get() != 0) {
allowDuplicates = true;
}
// Unused
encodedPackage.get();
// TTL
final long ttl = encodedPackage.getLong();
// Versions
final int versions = encodedPackage.getInt();
// Spatial reader length
final short spatialReaderLength = encodedPackage.getShort();
// Spatial writer length
final short spatialWriterLength = encodedPackage.getShort();
// Table name
final byte[] tableBytes = new byte[tableLength];
encodedPackage.get(tableBytes, 0, tableBytes.length);
final String table = new String(tableBytes);
// Spatial index reader
final byte[] spatialReaderBytes = new byte[spatialReaderLength];
encodedPackage.get(spatialReaderBytes, 0, spatialReaderBytes.length);
final String spatialIndexReader = new String(spatialReaderBytes);
// Spatial index writer
final byte[] spatialWriterBytes = new byte[spatialWriterLength];
encodedPackage.get(spatialWriterBytes, 0, spatialWriterBytes.length);
final String spatialIndexWriter = new String(spatialWriterBytes);
final TupleStoreConfiguration tupleStoreConfiguration = new TupleStoreConfiguration();
tupleStoreConfiguration.setAllowDuplicates(allowDuplicates);
tupleStoreConfiguration.setTtl(ttl);
tupleStoreConfiguration.setVersions(versions);
tupleStoreConfiguration.setSpatialIndexReader(spatialIndexReader);
tupleStoreConfiguration.setSpatialIndexWriter(spatialIndexWriter);
if (encodedPackage.remaining() != 0) {
throw new PackageEncodeException("Some bytes are left after decoding: " + encodedPackage.remaining());
}
return new CreateTableRequest(sequenceNumber, table, tupleStoreConfiguration);
}
use of org.bboxdb.storage.entity.TupleStoreConfiguration in project bboxdb by jnidzwetzki.
the class TestNetworkCommunication method testCreateTableTwoTimes.
/**
* Test create a table two times
* @throws BBoxDBException
* @throws InterruptedException
*/
@Test(timeout = 60000)
public void testCreateTableTwoTimes() throws BBoxDBException, InterruptedException {
final BBoxDBConnection bboxdbConnection = connectToServer();
final BBoxDBClient bboxDBClient = bboxdbConnection.getBboxDBClient();
final String table = DISTRIBUTION_GROUP + "_mytable";
final EmptyResultFuture resultCreateTable1 = bboxDBClient.createTable(table, new TupleStoreConfiguration());
resultCreateTable1.waitForAll();
Assert.assertFalse(resultCreateTable1.isFailed());
final EmptyResultFuture resultCreateTable2 = bboxDBClient.createTable(table, new TupleStoreConfiguration());
// Prevent retries
resultCreateTable2.setRetryPolicy(FutureRetryPolicy.RETRY_POLICY_NONE);
resultCreateTable2.waitForAll();
Assert.assertTrue(resultCreateTable2.isFailed());
Assert.assertEquals(ErrorMessages.ERROR_TABLE_EXISTS, resultCreateTable2.getMessage(0));
Assert.assertTrue(bboxdbConnection.getConnectionState().isInRunningState());
disconnect(bboxDBClient);
}
Aggregations