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;
}
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;
}
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();
}
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);
}
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);
}
Aggregations