Search in sources :

Example 1 with TupleStoreAdapter

use of org.bboxdb.distribution.zookeeper.TupleStoreAdapter in project bboxdb by jnidzwetzki.

the class DeleteTableHandler method handleRequest.

@Override
public /**
 * Handle the delete table call
 */
boolean handleRequest(final ByteBuffer encodedPackage, final short packageSequence, final ClientConnectionHandler clientConnectionHandler) throws IOException, PackageEncodeException {
    try {
        final DeleteTableRequest deletePackage = DeleteTableRequest.decodeTuple(encodedPackage);
        final TupleStoreName requestTable = deletePackage.getTable();
        logger.info("Got delete call for table: {}", requestTable);
        // Delete zookeeper configuration
        final TupleStoreAdapter tupleStoreAdapter = ZookeeperClientFactory.getZookeeperClient().getTupleStoreAdapter();
        tupleStoreAdapter.deleteTable(requestTable);
        // Clear cached data
        TupleStoreConfigurationCache.getInstance().clear();
        clientConnectionHandler.writeResultPackage(new SuccessResponse(packageSequence));
    } catch (Exception e) {
        logger.warn("Error while delete tuple", e);
        final ErrorResponse responsePackage = new ErrorResponse(packageSequence, ErrorMessages.ERROR_EXCEPTION);
        clientConnectionHandler.writeResultPackage(responsePackage);
    }
    return true;
}
Also used : DeleteTableRequest(org.bboxdb.network.packages.request.DeleteTableRequest) SuccessResponse(org.bboxdb.network.packages.response.SuccessResponse) TupleStoreAdapter(org.bboxdb.distribution.zookeeper.TupleStoreAdapter) TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) PackageEncodeException(org.bboxdb.network.packages.PackageEncodeException) IOException(java.io.IOException) ErrorResponse(org.bboxdb.network.packages.response.ErrorResponse)

Example 2 with TupleStoreAdapter

use of org.bboxdb.distribution.zookeeper.TupleStoreAdapter in project bboxdb by jnidzwetzki.

the class QueryHelper method handleNonExstingTable.

/**
 * Handle a non existing table
 * @param requestTable
 * @param clientConnectionHandler
 * @return
 * @throws PackageEncodeException
 * @throws IOException
 */
public static boolean handleNonExstingTable(final TupleStoreName requestTable, final short packageSequence, final ClientConnectionHandler clientConnectionHandler) throws IOException, PackageEncodeException {
    // Table is locally known, prevent expensive zookeeper call
    final TupleStoreManagerRegistry storageRegistry = clientConnectionHandler.getStorageRegistry();
    if (storageRegistry.isStorageManagerKnown(requestTable)) {
        return true;
    }
    final TupleStoreAdapter tupleStoreAdapter = ZookeeperClientFactory.getZookeeperClient().getTupleStoreAdapter();
    try {
        final boolean tableKnown = tupleStoreAdapter.isTableKnown(requestTable);
        if (!tableKnown) {
            clientConnectionHandler.writeResultPackage(new ErrorResponse(packageSequence, ErrorMessages.ERROR_TABLE_NOT_EXIST));
            return false;
        }
    } catch (ZookeeperException e) {
        logger.error("Got an exception while query for table", e);
        return false;
    }
    return true;
}
Also used : ZookeeperException(org.bboxdb.distribution.zookeeper.ZookeeperException) TupleStoreManagerRegistry(org.bboxdb.storage.tuplestore.manager.TupleStoreManagerRegistry) TupleStoreAdapter(org.bboxdb.distribution.zookeeper.TupleStoreAdapter) ErrorResponse(org.bboxdb.network.packages.response.ErrorResponse)

Example 3 with TupleStoreAdapter

use of org.bboxdb.distribution.zookeeper.TupleStoreAdapter in project bboxdb by jnidzwetzki.

the class TestZookeeperIntegration method testTableCreateDelete.

/**
 * Test the table deletion and creation
 * @throws ZookeeperException
 * @throws BBoxDBException
 * @throws InterruptedException
 */
@Test(timeout = 60000)
public void testTableCreateDelete() throws Exception {
    final TupleStoreAdapter tupleStoreAdapter = zookeeperClient.getTupleStoreAdapter();
    final SpacePartitioner spacePartitioner = getSpacePartitioner();
    final DistributionRegion rootNode = spacePartitioner.getRootNode();
    final String rootPath = distributionRegionAdapter.getZookeeperPathForDistributionRegion(rootNode);
    distributionRegionAdapter.addSystemToDistributionRegion(rootPath, ZookeeperClientFactory.getLocalInstanceName());
    final TupleStoreName tupleStoreName = new TupleStoreName(TEST_GROUP + "_tabletest");
    final TupleStoreName tupleStoreName0 = new TupleStoreName(TEST_GROUP + "_tabletest_0");
    final TupleStoreConfiguration configuration = TupleStoreConfigurationBuilder.create().build();
    tupleStoreAdapter.writeTuplestoreConfiguration(tupleStoreName, configuration);
    final TupleStoreManagerRegistry storageRegistry = new TupleStoreManagerRegistry();
    storageRegistry.init();
    storageRegistry.deleteTable(tupleStoreName0, true);
    storageRegistry.createTable(tupleStoreName0, configuration);
    storageRegistry.getTupleStoreManager(tupleStoreName0);
    Assert.assertTrue(storageRegistry.isStorageManagerKnown(tupleStoreName0));
    System.out.println("=== Executing deletion");
    tupleStoreAdapter.deleteTable(tupleStoreName0);
    Thread.sleep(5000);
    Assert.assertFalse(storageRegistry.isStorageManagerKnown(tupleStoreName0));
    storageRegistry.shutdown();
}
Also used : DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) TupleStoreConfiguration(org.bboxdb.storage.entity.TupleStoreConfiguration) TupleStoreManagerRegistry(org.bboxdb.storage.tuplestore.manager.TupleStoreManagerRegistry) TupleStoreAdapter(org.bboxdb.distribution.zookeeper.TupleStoreAdapter) TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) SpacePartitioner(org.bboxdb.distribution.partitioner.SpacePartitioner) KDtreeSpacePartitioner(org.bboxdb.distribution.partitioner.KDtreeSpacePartitioner) Test(org.junit.Test)

Example 4 with TupleStoreAdapter

use of org.bboxdb.distribution.zookeeper.TupleStoreAdapter 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 5 with TupleStoreAdapter

use of org.bboxdb.distribution.zookeeper.TupleStoreAdapter 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)

Aggregations

TupleStoreAdapter (org.bboxdb.distribution.zookeeper.TupleStoreAdapter)9 TupleStoreName (org.bboxdb.storage.entity.TupleStoreName)7 TupleStoreConfiguration (org.bboxdb.storage.entity.TupleStoreConfiguration)6 ZookeeperException (org.bboxdb.distribution.zookeeper.ZookeeperException)3 ErrorResponse (org.bboxdb.network.packages.response.ErrorResponse)3 IOException (java.io.IOException)2 BBoxDBConnection (org.bboxdb.network.client.BBoxDBConnection)2 PackageEncodeException (org.bboxdb.network.packages.PackageEncodeException)2 SuccessResponse (org.bboxdb.network.packages.response.SuccessResponse)2 StorageManagerException (org.bboxdb.storage.StorageManagerException)2 TupleStoreManagerRegistry (org.bboxdb.storage.tuplestore.manager.TupleStoreManagerRegistry)2 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 BBoxDBInstance (org.bboxdb.distribution.membership.BBoxDBInstance)1 MembershipConnectionService (org.bboxdb.distribution.membership.MembershipConnectionService)1 KDtreeSpacePartitioner (org.bboxdb.distribution.partitioner.KDtreeSpacePartitioner)1 SpacePartitioner (org.bboxdb.distribution.partitioner.SpacePartitioner)1 DistributionRegion (org.bboxdb.distribution.region.DistributionRegion)1 ZookeeperClient (org.bboxdb.distribution.zookeeper.ZookeeperClient)1 BBoxDBClient (org.bboxdb.network.client.BBoxDBClient)1