Search in sources :

Example 26 with TupleStoreConfiguration

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);
}
Also used : TupleStoreConfiguration(org.bboxdb.storage.entity.TupleStoreConfiguration) ArrayList(java.util.ArrayList) MembershipConnectionService(org.bboxdb.distribution.membership.MembershipConnectionService) TupleStoreAdapter(org.bboxdb.distribution.zookeeper.TupleStoreAdapter) TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) BBoxDBInstance(org.bboxdb.distribution.membership.BBoxDBInstance) BBoxDBConnection(org.bboxdb.network.client.BBoxDBConnection) TupleStoreManager(org.bboxdb.storage.tuplestore.manager.TupleStoreManager)

Example 27 with TupleStoreConfiguration

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();
}
Also used : BBoxDB(org.bboxdb.network.client.BBoxDB) TupleStoreConfiguration(org.bboxdb.storage.entity.TupleStoreConfiguration) BoundingBox(org.bboxdb.commons.math.BoundingBox) TupleListFuture(org.bboxdb.network.client.future.TupleListFuture) BBoxDBCluster(org.bboxdb.network.client.BBoxDBCluster) DistributionGroupConfiguration(org.bboxdb.storage.entity.DistributionGroupConfiguration) Tuple(org.bboxdb.storage.entity.Tuple) EmptyResultFuture(org.bboxdb.network.client.future.EmptyResultFuture)

Example 28 with TupleStoreConfiguration

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);
}
Also used : TupleStoreConfiguration(org.bboxdb.storage.entity.TupleStoreConfiguration) TupleStoreAdapter(org.bboxdb.distribution.zookeeper.TupleStoreAdapter) StorageManagerException(org.bboxdb.storage.StorageManagerException)

Example 29 with TupleStoreConfiguration

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);
}
Also used : TupleStoreConfiguration(org.bboxdb.storage.entity.TupleStoreConfiguration) PackageEncodeException(org.bboxdb.network.packages.PackageEncodeException)

Example 30 with 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);
}
Also used : BBoxDBClient(org.bboxdb.network.client.BBoxDBClient) TupleStoreConfiguration(org.bboxdb.storage.entity.TupleStoreConfiguration) BBoxDBConnection(org.bboxdb.network.client.BBoxDBConnection) EmptyResultFuture(org.bboxdb.network.client.future.EmptyResultFuture) Test(org.junit.Test)

Aggregations

TupleStoreConfiguration (org.bboxdb.storage.entity.TupleStoreConfiguration)44 Test (org.junit.Test)23 Tuple (org.bboxdb.storage.entity.Tuple)21 EmptyResultFuture (org.bboxdb.network.client.future.EmptyResultFuture)15 TupleStoreName (org.bboxdb.storage.entity.TupleStoreName)13 BoundingBox (org.bboxdb.commons.math.BoundingBox)12 TupleListFuture (org.bboxdb.network.client.future.TupleListFuture)10 TupleStoreAdapter (org.bboxdb.distribution.zookeeper.TupleStoreAdapter)7 JoinedTupleListFuture (org.bboxdb.network.client.future.JoinedTupleListFuture)7 DeletedTuple (org.bboxdb.storage.entity.DeletedTuple)7 JoinedTuple (org.bboxdb.storage.entity.JoinedTuple)7 TupleStoreManager (org.bboxdb.storage.tuplestore.manager.TupleStoreManager)7 BBoxDBConnection (org.bboxdb.network.client.BBoxDBConnection)5 ArrayList (java.util.ArrayList)4 BBoxDBException (org.bboxdb.misc.BBoxDBException)4 BBoxDBClient (org.bboxdb.network.client.BBoxDBClient)4 DistributionRegion (org.bboxdb.distribution.region.DistributionRegion)3 DistributionGroupConfiguration (org.bboxdb.storage.entity.DistributionGroupConfiguration)3 SSTableWriter (org.bboxdb.storage.sstable.SSTableWriter)3 SSTableCompactor (org.bboxdb.storage.sstable.compact.SSTableCompactor)3