Search in sources :

Example 61 with TupleStoreName

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);
}
Also used : RoutingHeader(org.bboxdb.network.routing.RoutingHeader) TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) ByteBuffer(java.nio.ByteBuffer) JoinedTuple(org.bboxdb.storage.entity.JoinedTuple) Tuple(org.bboxdb.storage.entity.Tuple) DeletedTuple(org.bboxdb.storage.entity.DeletedTuple) InsertTupleRequest(org.bboxdb.network.packages.request.InsertTupleRequest) Test(org.junit.Test)

Example 62 with TupleStoreName

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;
}
Also used : HashMap(java.util.HashMap) TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) File(java.io.File)

Example 63 with TupleStoreName

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();
}
Also used : Arrays(java.util.Arrays) PackageEncodeException(org.bboxdb.network.packages.PackageEncodeException) Logger(org.slf4j.Logger) ByteArrayOutputStream(java.io.ByteArrayOutputStream) NetworkConst(org.bboxdb.network.NetworkConst) InsertTupleRequest(org.bboxdb.network.packages.request.InsertTupleRequest) RoutingHeader(org.bboxdb.network.routing.RoutingHeader) Tuple(org.bboxdb.storage.entity.Tuple) LoggerFactory(org.slf4j.LoggerFactory) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) Objects(java.util.Objects) TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) List(java.util.List) TupleFileReader(org.bboxdb.tools.TupleFileReader) CompressionEnvelopeRequest(org.bboxdb.network.packages.request.CompressionEnvelopeRequest) NetworkRequestPackage(org.bboxdb.network.packages.NetworkRequestPackage) TupleFileReader(org.bboxdb.tools.TupleFileReader) ArrayList(java.util.ArrayList) TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) IOException(java.io.IOException) Tuple(org.bboxdb.storage.entity.Tuple)

Example 64 with TupleStoreName

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;
}
Also used : SuccessResponse(org.bboxdb.network.packages.response.SuccessResponse) TupleStoreAdapter(org.bboxdb.distribution.zookeeper.TupleStoreAdapter) TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) CreateTableRequest(org.bboxdb.network.packages.request.CreateTableRequest) PackageEncodeException(org.bboxdb.network.packages.PackageEncodeException) IOException(java.io.IOException) ErrorResponse(org.bboxdb.network.packages.response.ErrorResponse)

Example 65 with TupleStoreName

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);
}
Also used : TupleStoreManagerRegistry(org.bboxdb.storage.tuplestore.manager.TupleStoreManagerRegistry) RoutingHeader(org.bboxdb.network.routing.RoutingHeader) TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) RoutingHop(org.bboxdb.network.routing.RoutingHop) Tuple(org.bboxdb.storage.entity.Tuple)

Aggregations

TupleStoreName (org.bboxdb.storage.entity.TupleStoreName)77 Test (org.junit.Test)25 Tuple (org.bboxdb.storage.entity.Tuple)18 StorageManagerException (org.bboxdb.storage.StorageManagerException)15 ArrayList (java.util.ArrayList)14 PackageEncodeException (org.bboxdb.network.packages.PackageEncodeException)14 SpacePartitioner (org.bboxdb.distribution.partitioner.SpacePartitioner)13 ByteBuffer (java.nio.ByteBuffer)12 BoundingBox (org.bboxdb.commons.math.BoundingBox)12 DistributionRegionIdMapper (org.bboxdb.distribution.region.DistributionRegionIdMapper)12 BBoxDBException (org.bboxdb.misc.BBoxDBException)12 InsertTupleRequest (org.bboxdb.network.packages.request.InsertTupleRequest)12 RoutingHeader (org.bboxdb.network.routing.RoutingHeader)12 TupleStoreConfiguration (org.bboxdb.storage.entity.TupleStoreConfiguration)12 TupleStoreManager (org.bboxdb.storage.tuplestore.manager.TupleStoreManager)11 List (java.util.List)10 JoinedTuple (org.bboxdb.storage.entity.JoinedTuple)10 TupleStoreManagerRegistry (org.bboxdb.storage.tuplestore.manager.TupleStoreManagerRegistry)10 ErrorResponse (org.bboxdb.network.packages.response.ErrorResponse)9 DeletedTuple (org.bboxdb.storage.entity.DeletedTuple)9