Search in sources :

Example 31 with RoutingHeader

use of org.bboxdb.network.routing.RoutingHeader 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);
}
Also used : SpacePartitioner(org.bboxdb.distribution.partitioner.SpacePartitioner) Logger(org.slf4j.Logger) RoutingHeader(org.bboxdb.network.routing.RoutingHeader) LoggerFactory(org.slf4j.LoggerFactory) RoutingHop(org.bboxdb.network.routing.RoutingHop) InetSocketAddress(java.net.InetSocketAddress) Collectors(java.util.stream.Collectors) BoundingBox(org.bboxdb.commons.math.BoundingBox) ArrayList(java.util.ArrayList) Const(org.bboxdb.misc.Const) TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) ZookeeperException(org.bboxdb.distribution.zookeeper.ZookeeperException) List(java.util.List) DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) RoutingHopHelper(org.bboxdb.network.routing.RoutingHopHelper) BBoxDBException(org.bboxdb.misc.BBoxDBException) SpacePartitionerCache(org.bboxdb.distribution.partitioner.SpacePartitionerCache) DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) RoutingHeader(org.bboxdb.network.routing.RoutingHeader) TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) RoutingHop(org.bboxdb.network.routing.RoutingHop) BBoxDBException(org.bboxdb.misc.BBoxDBException) SpacePartitioner(org.bboxdb.distribution.partitioner.SpacePartitioner)

Example 32 with RoutingHeader

use of org.bboxdb.network.routing.RoutingHeader 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());
}
Also used : PackageEncodeException(org.bboxdb.network.packages.PackageEncodeException) RoutingHeader(org.bboxdb.network.routing.RoutingHeader) TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) TupleAndTable(org.bboxdb.storage.entity.TupleAndTable)

Example 33 with RoutingHeader

use of org.bboxdb.network.routing.RoutingHeader in project bboxdb by jnidzwetzki.

the class QueryBoundingBoxRequest method decodeTuple.

/**
 * Decode the encoded package into a object
 *
 * @param encodedPackage
 * @return
 * @throws PackageEncodeException
 * @throws IOException
 */
public static QueryBoundingBoxRequest 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_BBOX) {
        throw new PackageEncodeException("Wrong query type: " + queryType + " required type is: " + NetworkConst.REQUEST_QUERY_BBOX);
    }
    boolean pagingEnabled = false;
    if (encodedPackage.get() != 0) {
        pagingEnabled = true;
    }
    final short tuplesPerPage = encodedPackage.getShort();
    final short tableLength = encodedPackage.getShort();
    // 2 unused bytes
    encodedPackage.get();
    encodedPackage.get();
    final int bboxLength = encodedPackage.getInt();
    final byte[] tableBytes = new byte[tableLength];
    encodedPackage.get(tableBytes, 0, tableBytes.length);
    final String table = new String(tableBytes);
    final byte[] bboxBytes = new byte[bboxLength];
    encodedPackage.get(bboxBytes, 0, bboxBytes.length);
    final BoundingBox boundingBox = BoundingBox.fromByteArray(bboxBytes);
    if (encodedPackage.remaining() != 0) {
        throw new PackageEncodeException("Some bytes are left after decoding: " + encodedPackage.remaining());
    }
    final RoutingHeader routingHeader = NetworkPackageDecoder.getRoutingHeaderFromRequestPackage(encodedPackage);
    return new QueryBoundingBoxRequest(sequenceNumber, routingHeader, table, boundingBox, pagingEnabled, tuplesPerPage);
}
Also used : BoundingBox(org.bboxdb.commons.math.BoundingBox) PackageEncodeException(org.bboxdb.network.packages.PackageEncodeException) RoutingHeader(org.bboxdb.network.routing.RoutingHeader)

Example 34 with RoutingHeader

use of org.bboxdb.network.routing.RoutingHeader in project bboxdb by jnidzwetzki.

the class QueryInsertTimeRequest method decodeTuple.

/**
 * Decode the encoded package into a object
 *
 * @param encodedPackage
 * @return
 * @throws PackageEncodeException
 * @throws IOException
 */
public static QueryInsertTimeRequest 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_INSERT_TIME) {
        throw new PackageEncodeException("Wrong query type: " + queryType);
    }
    boolean pagingEnabled = false;
    if (encodedPackage.get() != 0) {
        pagingEnabled = true;
    }
    final short tuplesPerPage = encodedPackage.getShort();
    final long timestamp = encodedPackage.getLong();
    final short tableLength = encodedPackage.getShort();
    final byte[] tableBytes = new byte[tableLength];
    encodedPackage.get(tableBytes, 0, tableBytes.length);
    final String table = new String(tableBytes);
    if (encodedPackage.remaining() != 0) {
        throw new PackageEncodeException("Some bytes are left after decoding: " + encodedPackage.remaining());
    }
    final RoutingHeader routingHeader = NetworkPackageDecoder.getRoutingHeaderFromRequestPackage(encodedPackage);
    return new QueryInsertTimeRequest(sequenceNumber, routingHeader, table, timestamp, pagingEnabled, tuplesPerPage);
}
Also used : PackageEncodeException(org.bboxdb.network.packages.PackageEncodeException) RoutingHeader(org.bboxdb.network.routing.RoutingHeader)

Example 35 with RoutingHeader

use of org.bboxdb.network.routing.RoutingHeader 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);
}
Also used : ArrayList(java.util.ArrayList) RoutingHeader(org.bboxdb.network.routing.RoutingHeader) BoundingBox(org.bboxdb.commons.math.BoundingBox) PackageEncodeException(org.bboxdb.network.packages.PackageEncodeException) TupleStoreName(org.bboxdb.storage.entity.TupleStoreName)

Aggregations

RoutingHeader (org.bboxdb.network.routing.RoutingHeader)52 Test (org.junit.Test)18 NetworkOperationFuture (org.bboxdb.network.client.future.NetworkOperationFuture)16 RoutingHop (org.bboxdb.network.routing.RoutingHop)15 ArrayList (java.util.ArrayList)12 JoinedTupleListFuture (org.bboxdb.network.client.future.JoinedTupleListFuture)12 BBoxDBInstance (org.bboxdb.distribution.membership.BBoxDBInstance)11 PackageEncodeException (org.bboxdb.network.packages.PackageEncodeException)11 Tuple (org.bboxdb.storage.entity.Tuple)11 TupleStoreName (org.bboxdb.storage.entity.TupleStoreName)11 List (java.util.List)10 DistributionRegion (org.bboxdb.distribution.region.DistributionRegion)10 TupleListFuture (org.bboxdb.network.client.future.TupleListFuture)10 ByteBuffer (java.nio.ByteBuffer)9 InsertTupleRequest (org.bboxdb.network.packages.request.InsertTupleRequest)9 DeletedTuple (org.bboxdb.storage.entity.DeletedTuple)9 DoNothingDuplicateResolver (org.bboxdb.storage.sstable.duplicateresolver.DoNothingDuplicateResolver)8 BoundingBox (org.bboxdb.commons.math.BoundingBox)6 BBoxDBException (org.bboxdb.misc.BBoxDBException)6 JoinedTuple (org.bboxdb.storage.entity.JoinedTuple)6