use of org.bboxdb.storage.entity.TupleStoreName in project bboxdb by jnidzwetzki.
the class BBoxDBCluster method getRootNode.
/**
* Get the root node from space partitioner
*
* @param fullname
* @return
* @throws BBoxDBException
*/
private DistributionRegion getRootNode(final String fullname) throws BBoxDBException {
final TupleStoreName tupleStoreName = new TupleStoreName(fullname);
final String distributionGroup = tupleStoreName.getDistributionGroup();
final SpacePartitioner distributionAdapter = SpacePartitionerCache.getInstance().getSpacePartitionerForGroupName(distributionGroup);
return distributionAdapter.getRootNode();
}
use of org.bboxdb.storage.entity.TupleStoreName in project bboxdb by jnidzwetzki.
the class ConnectionMainteinanceRunnable method sendKeepAlivePackage.
/**
* Build a keep alive package (with or without gossip)
* @return
* @return
*/
private EmptyResultFuture sendKeepAlivePackage() {
final TupleStoreManagerRegistry tupleStoreManagerRegistry = bboxDBClient.getTupleStoreManagerRegistry();
if (tupleStoreManagerRegistry == null) {
return bboxDBClient.sendKeepAlivePackage();
}
final List<TupleStoreName> tables = tupleStoreManagerRegistry.getAllTables();
if (tables.isEmpty()) {
return bboxDBClient.sendKeepAlivePackage();
}
lastGossipTableName = ListHelper.getElementRandom(tables);
List<ReadOnlyTupleStore> storages = new ArrayList<>();
try {
final TupleStoreManager tupleStoreManager = tupleStoreManagerRegistry.getTupleStoreManager(lastGossipTableName);
try {
storages = tupleStoreManager.aquireStorage();
if (storages.isEmpty()) {
return bboxDBClient.sendKeepAlivePackage();
}
final ReadOnlyTupleStore tupleStore = ListHelper.getElementRandom(storages);
if (tupleStore.getNumberOfTuples() > 0) {
return sendKeepAliveWithGossip(tupleStoreManager, tupleStore);
}
} catch (Exception e) {
throw e;
} finally {
tupleStoreManager.releaseStorage(storages);
}
} catch (StorageManagerException e) {
logger.error("Got exception while reading tuples", e);
}
return bboxDBClient.sendKeepAlivePackage();
}
use of org.bboxdb.storage.entity.TupleStoreName in project bboxdb by jnidzwetzki.
the class RoutingHeaderHelper method getRoutingHeaderForLocalSystem.
/**
* Get the routing header for the local system
* @param table
* @param serverAddress
* @param tuple
* @throws ZookeeperException
* @throws BBoxDBException
* @throws InterruptedException
*/
public static RoutingHeader getRoutingHeaderForLocalSystem(final String table, BoundingBox boundingBox, final boolean allowEmptyHop, final InetSocketAddress serverAddress, final boolean write) throws ZookeeperException, BBoxDBException, InterruptedException {
final TupleStoreName ssTableName = new TupleStoreName(table);
final String distributionGroup = ssTableName.getDistributionGroup();
final SpacePartitioner spacepartitioner = SpacePartitionerCache.getInstance().getSpacePartitionerForGroupName(distributionGroup);
final DistributionRegion distributionRegion = spacepartitioner.getRootNode();
if (boundingBox == null) {
boundingBox = BoundingBox.FULL_SPACE;
}
final List<RoutingHop> hops = getLocalHops(boundingBox, distributionRegion, write);
if (hops == null || hops.isEmpty()) {
if (!allowEmptyHop) {
throw new BBoxDBException("Got empty result list when query for write: " + boundingBox + " / in table " + table);
}
return new RoutingHeader((short) 0, new ArrayList<>());
}
// Filter the local hop
final List<RoutingHop> connectionHop = hops.stream().filter(r -> r.getDistributedInstance().getInetSocketAddress().equals(serverAddress)).collect(Collectors.toList());
if (!allowEmptyHop && connectionHop.isEmpty()) {
throw new BBoxDBException("Unable to find host " + serverAddress + " in global routing list: " + hops);
}
return new RoutingHeader((short) 0, connectionHop);
}
use of org.bboxdb.storage.entity.TupleStoreName in project bboxdb by jnidzwetzki.
the class InsertTupleRequest method decodeTuple.
/**
* Decode the encoded tuple into a object
*
* @param encodedPackage
* @return
* @throws IOException
* @throws PackageEncodeException
*/
public static InsertTupleRequest decodeTuple(final ByteBuffer encodedPackage) throws IOException, PackageEncodeException {
final short sequenceNumber = NetworkPackageDecoder.getRequestIDFromRequestPackage(encodedPackage);
final boolean decodeResult = NetworkPackageDecoder.validateRequestPackageHeader(encodedPackage, NetworkConst.REQUEST_TYPE_INSERT_TUPLE);
if (decodeResult == false) {
throw new PackageEncodeException("Unable to decode package");
}
final TupleAndTable tupleAndTable = NetworkTupleEncoderDecoder.decode(encodedPackage);
if (encodedPackage.remaining() != 0) {
throw new PackageEncodeException("Some bytes are left after decoding: " + encodedPackage.remaining());
}
final RoutingHeader routingHeader = NetworkPackageDecoder.getRoutingHeaderFromRequestPackage(encodedPackage);
final TupleStoreName ssTableName = new TupleStoreName(tupleAndTable.getTable());
return new InsertTupleRequest(sequenceNumber, routingHeader, ssTableName, tupleAndTable.getTuple());
}
use of org.bboxdb.storage.entity.TupleStoreName in project bboxdb by jnidzwetzki.
the class QueryJoinRequest method decodeTuple.
/**
* Decode the encoded package into a object
*
* @param encodedPackage
* @return
* @throws PackageEncodeException
* @throws IOException
*/
public static QueryJoinRequest decodeTuple(final ByteBuffer encodedPackage) throws PackageEncodeException, IOException {
final short sequenceNumber = NetworkPackageDecoder.getRequestIDFromRequestPackage(encodedPackage);
final boolean decodeResult = NetworkPackageDecoder.validateRequestPackageHeader(encodedPackage, NetworkConst.REQUEST_TYPE_QUERY);
if (decodeResult == false) {
throw new PackageEncodeException("Unable to decode package");
}
final byte queryType = encodedPackage.get();
if (queryType != NetworkConst.REQUEST_QUERY_JOIN) {
throw new PackageEncodeException("Wrong query type: " + queryType + " required type is: " + NetworkConst.REQUEST_QUERY_JOIN);
}
boolean pagingEnabled = false;
if (encodedPackage.get() != 0) {
pagingEnabled = true;
}
final short tuplesPerPage = encodedPackage.getShort();
final int numberOfTables = encodedPackage.getInt();
final int bboxLength = encodedPackage.getInt();
final byte[] bboxBytes = new byte[bboxLength];
encodedPackage.get(bboxBytes, 0, bboxBytes.length);
final BoundingBox boundingBox = BoundingBox.fromByteArray(bboxBytes);
final List<TupleStoreName> tableNames = new ArrayList<>();
for (int i = 0; i < numberOfTables; i++) {
final short tableNameLength = encodedPackage.getShort();
final byte[] tableBytes = new byte[tableNameLength];
encodedPackage.get(tableBytes, 0, tableBytes.length);
final String tablename = new java.lang.String(tableBytes);
tableNames.add(new TupleStoreName(tablename));
}
if (encodedPackage.remaining() != 0) {
throw new PackageEncodeException("Some bytes are left after decoding: " + encodedPackage.remaining());
}
final RoutingHeader routingHeader = NetworkPackageDecoder.getRoutingHeaderFromRequestPackage(encodedPackage);
return new QueryJoinRequest(sequenceNumber, routingHeader, tableNames, boundingBox, pagingEnabled, tuplesPerPage);
}
Aggregations