use of org.bboxdb.storage.entity.TupleStoreName in project bboxdb by jnidzwetzki.
the class TestNetworkClasses method encodeAndDecodeInsertTuple1.
/**
* The the encoding and decoding of an insert tuple package
* @throws IOException
* @throws PackageEncodeException
*/
@Test(timeout = 60000)
public void encodeAndDecodeInsertTuple1() throws IOException, PackageEncodeException {
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_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.storage.entity.TupleStoreName in project bboxdb by jnidzwetzki.
the class TupleStoreLocator method handleDistributionGroupEntry.
/**
* Handle the subdirs of the distribution group
* @param storageDirectory
* @param fileEntry
* @param distributionGroupName
* @return
*/
private static Map<TupleStoreName, String> handleDistributionGroupEntry(final String storageDirectory, final File fileEntry, final String distributionGroupName) {
final Map<TupleStoreName, String> sstableLocations = new HashMap<>();
// Tables
for (final File tableEntry : fileEntry.listFiles()) {
if (tableEntry.isDirectory()) {
final String tablename = tableEntry.getName();
final String fullname = distributionGroupName + "_" + tablename;
final TupleStoreName sstableName = new TupleStoreName(fullname);
sstableLocations.put(sstableName, storageDirectory);
}
}
return sstableLocations;
}
use of org.bboxdb.storage.entity.TupleStoreName in project bboxdb by jnidzwetzki.
the class TestCompressionRatio method runExperiment.
/**
* Run the experiment with the given batch size
* @param batchSize
* @return
* @throws IOException
* @throws ClassNotFoundException
* @throws PackageEncodeException
*/
protected long runExperiment(final Integer batchSize) throws ClassNotFoundException, IOException, PackageEncodeException {
final TupleStoreName tableName = new TupleStoreName("2_group1_table1");
final List<Long> experimentSize = new ArrayList<>();
final List<Tuple> buffer = new ArrayList<>();
final TupleFileReader tupleFile = new TupleFileReader(filename, format);
tupleFile.addTupleListener(t -> {
if (batchSize == 0) {
final long size = handleUncompressedData(tableName, t);
experimentSize.add(size);
} else if (buffer.size() == batchSize) {
final long size = handleCompressedData(tableName, buffer);
experimentSize.add(size);
} else {
buffer.add(t);
}
});
try {
tupleFile.processFile();
} catch (IOException e) {
logger.error("Got an IO-Exception while reading file", e);
System.exit(-1);
}
return experimentSize.stream().mapToLong(i -> i).sum();
}
use of org.bboxdb.storage.entity.TupleStoreName in project bboxdb by jnidzwetzki.
the class CreateTableHandler method handleRequest.
@Override
public /**
* Handle the create table call
*/
boolean handleRequest(final ByteBuffer encodedPackage, final short packageSequence, final ClientConnectionHandler clientConnectionHandler) throws IOException, PackageEncodeException {
try {
final CreateTableRequest createPackage = CreateTableRequest.decodeTuple(encodedPackage);
final TupleStoreName requestTable = createPackage.getTable();
logger.info("Got create call for table: {}", requestTable.getFullname());
final TupleStoreAdapter tupleStoreAdapter = ZookeeperClientFactory.getZookeeperClient().getTupleStoreAdapter();
if (tupleStoreAdapter.isTableKnown(requestTable)) {
logger.warn("Table name is already known {}", requestTable.getFullname());
final ErrorResponse responsePackage = new ErrorResponse(packageSequence, ErrorMessages.ERROR_TABLE_EXISTS);
clientConnectionHandler.writeResultPackage(responsePackage);
} else {
tupleStoreAdapter.writeTuplestoreConfiguration(requestTable, createPackage.getTupleStoreConfiguration());
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.storage.entity.TupleStoreName in project bboxdb by jnidzwetzki.
the class InsertTupleHandler method processPackageLocally.
/**
* @param packageSequence
* @param clientConnectionHandler
* @param insertTupleRequest
* @param routingHeader
* @throws BBoxDBException
* @throws RejectedException
* @throws PackageEncodeException
*/
private void processPackageLocally(final short packageSequence, final ClientConnectionHandler clientConnectionHandler, final InsertTupleRequest insertTupleRequest) throws BBoxDBException, RejectedException, PackageEncodeException {
final Tuple tuple = insertTupleRequest.getTuple();
final TupleStoreName requestTable = insertTupleRequest.getTable();
final TupleStoreManagerRegistry storageRegistry = clientConnectionHandler.getStorageRegistry();
final RoutingHeader routingHeader = insertTupleRequest.getRoutingHeader();
final RoutingHop localHop = routingHeader.getRoutingHop();
PackageRouter.checkLocalSystemNameMatchesAndThrowException(localHop);
final List<Long> distributionRegions = localHop.getDistributionRegions();
processInsertPackage(tuple, requestTable, storageRegistry, distributionRegions);
forwardRoutedPackage(packageSequence, clientConnectionHandler, insertTupleRequest);
}
Aggregations