use of org.bboxdb.network.routing.RoutingHeader in project bboxdb by jnidzwetzki.
the class QueryVersionTimeRequest method decodeTuple.
/**
* Decode the encoded package into a object
*
* @param encodedPackage
* @return
* @throws PackageEncodeException
* @throws IOException
*/
public static QueryVersionTimeRequest 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_VERSION_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 QueryVersionTimeRequest(sequenceNumber, routingHeader, table, timestamp, pagingEnabled, tuplesPerPage);
}
use of org.bboxdb.network.routing.RoutingHeader in project bboxdb by jnidzwetzki.
the class TupleListFuture method performReadRepairForResult.
/**
* Perform read repair for the given result
*
* @param allTuples
* @param resultId
* @throws InterruptedException
* @throws BBoxDBException
* @throws ZookeeperException
*/
private void performReadRepairForResult(final List<Tuple> allTuples, int resultId) throws InterruptedException, BBoxDBException, ZookeeperException {
final List<Tuple> tupleResult = get(resultId);
final BBoxDBConnection bboxDBConnection = getConnection(resultId);
if (bboxDBConnection == null) {
// Unable to perform read repair when the connection is not known
return;
}
for (final Tuple tuple : allTuples) {
final RoutingHeader routingHeader = RoutingHeaderHelper.getRoutingHeaderForLocalSystem(tablename, tuple.getBoundingBox(), true, bboxDBConnection.getServerAddress(), true);
// System is not responsible for the tuple
if (routingHeader.getHopCount() == 0) {
return;
}
if (!tupleResult.contains(tuple)) {
logger.info("Tuple {} is not contained in result {} from server {}, " + "performing read repair", tuple, tupleResult, bboxDBConnection.getConnectionName());
final BBoxDBClient bboxDBClient = bboxDBConnection.getBboxDBClient();
bboxDBClient.insertTuple(tablename, tuple, routingHeader);
}
}
}
use of org.bboxdb.network.routing.RoutingHeader in project bboxdb by jnidzwetzki.
the class TestNetworkClasses method encodeAndDecodeInsertTuple2.
/**
* The the encoding and decoding of an insert tuple package
* @throws IOException
* @throws PackageEncodeException
*/
@Test(timeout = 60000)
public void encodeAndDecodeInsertTuple2() throws IOException, PackageEncodeException {
final Tuple tuple = new Tuple("key", new BoundingBox(1.3244343224, 232.232333343, 34324.343, 343243.0), "abc".getBytes(), 12);
final short sequenceNumber = sequenceNumberGenerator.getNextSequenceNummber();
final InsertTupleRequest insertPackage = new InsertTupleRequest(sequenceNumber, ROUTING_HEADER_UNROUTED, new TupleStoreName("test"), tuple);
byte[] encodedVersion = networkPackageToByte(insertPackage);
Assert.assertNotNull(encodedVersion);
final ByteBuffer bb = NetworkPackageDecoder.encapsulateBytes(encodedVersion);
final InsertTupleRequest decodedPackage = InsertTupleRequest.decodeTuple(bb);
Assert.assertEquals(insertPackage.getTuple(), decodedPackage.getTuple());
Assert.assertEquals(insertPackage.getTable(), decodedPackage.getTable());
Assert.assertEquals(insertPackage.getRoutingHeader(), new RoutingHeader(false));
Assert.assertEquals(insertPackage, decodedPackage);
Assert.assertEquals(insertPackage.hashCode(), decodedPackage.hashCode());
Assert.assertTrue(insertPackage.toString().length() > 10);
}
use of org.bboxdb.network.routing.RoutingHeader in project bboxdb by jnidzwetzki.
the class TestNetworkClasses method testCompression2Request.
/**
* Test the decoding and the encoding of an compressed request package
* @throws IOException
* @throws PackageEncodeException
*/
@Test(timeout = 60000)
public void testCompression2Request() throws IOException, PackageEncodeException {
final RoutingHeader routingHeader = ROUTING_HEADER_ROUTED;
final Tuple tuple = new Tuple("abcdefghijklmopqrstuvxyz", BoundingBox.FULL_SPACE, "abcdefghijklmopqrstuvxyzabcdefghijklmopqrstuvxyzabcdefghijklmopqrstuvxyzabcdefghijklmopqrstuvxyzabcdefghijklmopqrstuvxyzabcdefghijklmopqrstuvxyzabcdefghijklmopqrstuvxyzabcdefghijklmopqrstuvxyzabcdefghijklmopqrstuvxyzabcdefghijklmopqrstuvxyz".getBytes(), 12);
final short sequenceNumber = sequenceNumberGenerator.getNextSequenceNummber();
final InsertTupleRequest insertPackage = new InsertTupleRequest(sequenceNumber, ROUTING_HEADER_ROUTED, new TupleStoreName("test"), tuple);
Assert.assertEquals(routingHeader, insertPackage.getRoutingHeader());
final CompressionEnvelopeRequest compressionPackage = new CompressionEnvelopeRequest(NetworkConst.COMPRESSION_TYPE_GZIP, Arrays.asList(insertPackage));
final ByteArrayOutputStream bos = new ByteArrayOutputStream();
compressionPackage.writeToOutputStream(bos);
bos.close();
final byte[] encodedVersion = bos.toByteArray();
Assert.assertNotNull(encodedVersion);
final ByteBuffer bb = NetworkPackageDecoder.encapsulateBytes(encodedVersion);
Assert.assertNotNull(bb);
final InputStream uncompressedByteStream = CompressionEnvelopeRequest.decodePackage(bb);
final byte[] uncompressedBytes = ByteStreams.toByteArray(uncompressedByteStream);
final ByteBuffer uncompressedByteBuffer = NetworkPackageDecoder.encapsulateBytes(uncompressedBytes);
final InsertTupleRequest decodedPackage = InsertTupleRequest.decodeTuple(uncompressedByteBuffer);
Assert.assertEquals(insertPackage.getTuple(), decodedPackage.getTuple());
Assert.assertEquals(insertPackage.getTable(), decodedPackage.getTable());
Assert.assertEquals(routingHeader, decodedPackage.getRoutingHeader());
Assert.assertFalse(insertPackage.getRoutingHeader().equals(new RoutingHeader(false)));
Assert.assertEquals(insertPackage, decodedPackage);
Assert.assertEquals(insertPackage.hashCode(), decodedPackage.hashCode());
Assert.assertTrue(insertPackage.toString().length() > 10);
}
use of org.bboxdb.network.routing.RoutingHeader in project bboxdb by jnidzwetzki.
the class TestNetworkClasses method testCompression1Request.
/**
* Test the decoding and the encoding of an compressed request package
* @throws IOException
* @throws PackageEncodeException
*/
@Test(timeout = 60000)
public void testCompression1Request() throws IOException, PackageEncodeException {
final RoutingHeader routingHeader = ROUTING_HEADER_ROUTED;
final Tuple tuple = new Tuple("key", BoundingBox.FULL_SPACE, "abc".getBytes(), 12);
final short sequenceNumber = sequenceNumberGenerator.getNextSequenceNummber();
final InsertTupleRequest insertPackage = new InsertTupleRequest(sequenceNumber, ROUTING_HEADER_ROUTED, new TupleStoreName("test"), tuple);
Assert.assertEquals(routingHeader, insertPackage.getRoutingHeader());
final CompressionEnvelopeRequest compressionPackage = new CompressionEnvelopeRequest(NetworkConst.COMPRESSION_TYPE_GZIP, Arrays.asList(insertPackage));
final ByteArrayOutputStream bos = new ByteArrayOutputStream();
compressionPackage.writeToOutputStream(bos);
bos.close();
final byte[] encodedVersion = bos.toByteArray();
Assert.assertNotNull(encodedVersion);
final ByteBuffer bb = NetworkPackageDecoder.encapsulateBytes(encodedVersion);
Assert.assertNotNull(bb);
final InputStream uncompressedByteStream = CompressionEnvelopeRequest.decodePackage(bb);
final byte[] uncompressedBytes = ByteStreams.toByteArray(uncompressedByteStream);
final ByteBuffer uncompressedByteBuffer = NetworkPackageDecoder.encapsulateBytes(uncompressedBytes);
final InsertTupleRequest decodedPackage = InsertTupleRequest.decodeTuple(uncompressedByteBuffer);
Assert.assertEquals(insertPackage.getTuple(), decodedPackage.getTuple());
Assert.assertEquals(insertPackage.getTable(), decodedPackage.getTable());
Assert.assertEquals(routingHeader, decodedPackage.getRoutingHeader());
Assert.assertFalse(insertPackage.getRoutingHeader().equals(new RoutingHeader(false)));
Assert.assertEquals(insertPackage, decodedPackage);
Assert.assertEquals(insertPackage.hashCode(), decodedPackage.hashCode());
Assert.assertTrue(insertPackage.toString().length() > 10);
}
Aggregations