use of org.bboxdb.storage.entity.TupleStoreName in project bboxdb by jnidzwetzki.
the class InsertTupleHandler method createMissingTables.
/**
* Create all missing tables
*/
protected void createMissingTables(final TupleStoreName requestTable, final TupleStoreManagerRegistry storageRegistry, final Collection<TupleStoreName> localTables) throws StorageManagerException {
try {
final TupleStoreAdapter tupleStoreAdapter = ZookeeperClientFactory.getZookeeperClient().getTupleStoreAdapter();
if (!tupleStoreAdapter.isTableKnown(requestTable)) {
throw new StorageManagerException("Table: " + requestTable.getFullname() + " is unkown");
}
final TupleStoreConfiguration config = tupleStoreAdapter.readTuplestoreConfiguration(requestTable);
for (final TupleStoreName tupleStoreName : localTables) {
final boolean alreadyKnown = storageRegistry.isStorageManagerKnown(tupleStoreName);
if (!alreadyKnown) {
storageRegistry.createTableIfNotExist(tupleStoreName, config);
}
}
} catch (ZookeeperException e) {
throw new StorageManagerException(e);
}
}
use of org.bboxdb.storage.entity.TupleStoreName in project bboxdb by jnidzwetzki.
the class InsertTupleHandler method processInsertPackage.
/**
* Insert the table into the local storage
* @param tuple
* @param requestTable
* @param storageRegistry
* @param routingHeader
* @throws StorageManagerException
* @throws RejectedException
* @throws BBoxDBException
*/
protected void processInsertPackage(final Tuple tuple, final TupleStoreName requestTable, final TupleStoreManagerRegistry storageRegistry, final List<Long> distributionRegions) throws RejectedException {
try {
final String fullname = requestTable.getDistributionGroup();
final SpacePartitioner spacePartitioner = SpacePartitionerCache.getInstance().getSpacePartitionerForGroupName(fullname);
final DistributionRegionIdMapper regionIdMapper = spacePartitioner.getDistributionRegionIdMapper();
final Collection<TupleStoreName> localTables = regionIdMapper.convertRegionIdToTableNames(requestTable, distributionRegions);
if (localTables.isEmpty()) {
throw new BBoxDBException("Got no local tables for routed package");
}
// Are some tables unknown and needs to be created?
final boolean unknownTables = localTables.stream().anyMatch((t) -> !storageRegistry.isStorageManagerKnown(t));
// Expensive call (involves Zookeeper interaction)
if (unknownTables) {
createMissingTables(requestTable, storageRegistry, localTables);
}
// Insert tuples
for (final TupleStoreName tupleStoreName : localTables) {
final TupleStoreManager storageManager = storageRegistry.getTupleStoreManager(tupleStoreName);
storageManager.put(tuple);
}
} catch (RejectedException e) {
throw e;
} catch (Throwable e) {
throw new RejectedException(e);
}
}
use of org.bboxdb.storage.entity.TupleStoreName in project bboxdb by jnidzwetzki.
the class KeepAliveHandler method handleGossip.
/**
* Handle keep alive gossip
* @param keepAliveRequst
* @param clientConnectionHandler
* @return
*/
private boolean handleGossip(final KeepAliveRequest keepAliveRequst, final ClientConnectionHandler clientConnectionHandler) {
final String table = keepAliveRequst.getTablename();
final TupleStoreName tupleStoreName = new TupleStoreName(table);
final List<Tuple> tuples = keepAliveRequst.getTuples();
final TupleStoreManagerRegistry storageRegistry = clientConnectionHandler.getStorageRegistry();
try {
for (final Tuple tuple : tuples) {
final boolean result = checkLocalTuples(storageRegistry, tupleStoreName, tuple);
if (!result) {
return false;
}
}
} catch (BBoxDBException e) {
logger.error("Got exception while handling gossip", e);
}
return true;
}
use of org.bboxdb.storage.entity.TupleStoreName in project bboxdb by jnidzwetzki.
the class HandleBoundingBoxTimeQuery method handleQuery.
@Override
public /**
* Handle the bounding box time query
*/
void handleQuery(final ByteBuffer encodedPackage, final short packageSequence, final ClientConnectionHandler clientConnectionHandler) throws IOException {
try {
if (clientConnectionHandler.getActiveQueries().containsKey(packageSequence)) {
logger.error("Query sequence {} is allready known, please close old query first", packageSequence);
}
final QueryBoundingBoxTimeRequest queryRequest = QueryBoundingBoxTimeRequest.decodeTuple(encodedPackage);
final TupleStoreName requestTable = queryRequest.getTable();
if (!QueryHelper.handleNonExstingTable(requestTable, packageSequence, clientConnectionHandler)) {
return;
}
final OperatorTreeBuilder operatorTreeBuilder = new OperatorTreeBuilder() {
@Override
public Operator buildOperatorTree(final List<TupleStoreManager> storageManager) {
if (storageManager.size() != 1) {
throw new IllegalArgumentException("This operator tree needs 1 storage manager");
}
final BoundingBox boundingBox = queryRequest.getBoundingBox();
final SpatialIndexReadOperator operator = new SpatialIndexReadOperator(storageManager.get(0), boundingBox);
final Operator operator1 = new NewerAsInsertTimeSeclectionOperator(queryRequest.getTimestamp(), operator);
return operator1;
}
};
final StreamClientQuery clientQuery = new StreamClientQuery(operatorTreeBuilder, queryRequest.isPagingEnabled(), queryRequest.getTuplesPerPage(), clientConnectionHandler, packageSequence, Arrays.asList(requestTable));
clientConnectionHandler.getActiveQueries().put(packageSequence, clientQuery);
clientConnectionHandler.sendNextResultsForQuery(packageSequence, packageSequence);
} catch (PackageEncodeException e) {
logger.warn("Got exception while decoding package", e);
clientConnectionHandler.writeResultPackageNE(new ErrorResponse(packageSequence, ErrorMessages.ERROR_EXCEPTION));
}
}
use of org.bboxdb.storage.entity.TupleStoreName in project bboxdb by jnidzwetzki.
the class HandleContinuousBoundingBoxQuery method handleQuery.
@Override
public /**
* Handle a bounding box query
*/
void handleQuery(final ByteBuffer encodedPackage, final short packageSequence, final ClientConnectionHandler clientConnectionHandler) throws IOException, PackageEncodeException {
try {
if (clientConnectionHandler.getActiveQueries().containsKey(packageSequence)) {
logger.error("Query sequence {} is already known, please close old query first", packageSequence);
return;
}
final QueryBoundingBoxContinuousRequest queryRequest = QueryBoundingBoxContinuousRequest.decodeTuple(encodedPackage);
final TupleStoreName requestTable = queryRequest.getTable();
if (!QueryHelper.handleNonExstingTable(requestTable, packageSequence, clientConnectionHandler)) {
return;
}
final BoundingBox boundingBox = queryRequest.getBoundingBox();
final ClientQuery clientQuery = new ContinuousBoundingBoxClientQuery(boundingBox, clientConnectionHandler, packageSequence, requestTable);
clientConnectionHandler.getActiveQueries().put(packageSequence, clientQuery);
clientConnectionHandler.sendNextResultsForQuery(packageSequence, packageSequence);
} catch (PackageEncodeException e) {
logger.warn("Got exception while decoding package", e);
clientConnectionHandler.writeResultPackage(new ErrorResponse(packageSequence, ErrorMessages.ERROR_EXCEPTION));
}
}
Aggregations