Search in sources :

Example 41 with EmptyResultFuture

use of org.bboxdb.network.client.future.EmptyResultFuture in project bboxdb by jnidzwetzki.

the class DataRedistributionLoader method deleteFile.

/**
 * Remove the given file
 * @param fileid
 * @throws InterruptedException
 */
private void deleteFile(final int fileid) throws InterruptedException {
    final String filename = files[fileid];
    if (!loadedFiles.contains(filename)) {
        System.err.println("File " + filename + " is not loaded");
        return;
    }
    System.out.println("Removing content from: " + filename);
    final AtomicInteger lineNumber = new AtomicInteger(0);
    final String prefix = Integer.toString(fileid) + "_";
    try (final Stream<String> lines = Files.lines(Paths.get(filename))) {
        lines.forEach(l -> {
            final String key = prefix + lineNumber.getAndIncrement();
            try {
                final EmptyResultFuture resultFuture = bboxDBCluster.deleteTuple(TABLE, key);
                pendingFutures.put(resultFuture);
                if (lineNumber.get() % 1000 == 0) {
                    System.out.format("Deleted %d elements\n", lineNumber.get());
                }
            } catch (BBoxDBException e) {
                logger.error("Got error while deleting tuple", e);
            }
        });
    } catch (IOException e) {
        System.err.println("Got an exeption while reading file: " + e);
        System.exit(-1);
    }
    pendingFutures.waitForCompletion();
    loadedFiles.remove(filename);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IOException(java.io.IOException) BBoxDBException(org.bboxdb.misc.BBoxDBException) EmptyResultFuture(org.bboxdb.network.client.future.EmptyResultFuture)

Example 42 with EmptyResultFuture

use of org.bboxdb.network.client.future.EmptyResultFuture in project bboxdb by jnidzwetzki.

the class DataRedistributionLoader method initBBoxDB.

/**
 * Re-Create the distribution group and the table
 */
private void initBBoxDB() {
    try {
        // Delete old distribution group
        System.out.println("Delete old distribution group");
        final EmptyResultFuture dgroupDeleteResult = bboxDBCluster.deleteDistributionGroup(DGROUP);
        dgroupDeleteResult.waitForAll();
        if (dgroupDeleteResult.isFailed()) {
            System.err.println(dgroupDeleteResult.getAllMessages());
            System.exit(-1);
        }
        // Create new distribution group
        System.out.println("Create new distribution group");
        final DistributionGroupConfiguration dgroupConfig = DistributionGroupConfigurationBuilder.create(2).withReplicationFactor((short) 1).withMaximumRegionSize(16).withMinimumRegionSize(4).build();
        final EmptyResultFuture dgroupCreateResult = bboxDBCluster.createDistributionGroup(DGROUP, dgroupConfig);
        dgroupCreateResult.waitForAll();
        if (dgroupCreateResult.isFailed()) {
            System.err.println(dgroupCreateResult.getAllMessages());
            System.exit(-1);
        }
        // Create new table
        System.out.println("Create new table");
        final TupleStoreConfiguration storeConfiguration = TupleStoreConfigurationBuilder.create().allowDuplicates(false).build();
        final EmptyResultFuture tableCreateResult = bboxDBCluster.createTable(TABLE, storeConfiguration);
        tableCreateResult.waitForAll();
        if (tableCreateResult.isFailed()) {
            System.err.println(tableCreateResult.getAllMessages());
            System.exit(-1);
        }
    } catch (Exception e) {
        System.err.println("Got an exception while prepating BBoxDB");
        e.printStackTrace();
        System.exit(-1);
    }
}
Also used : TupleStoreConfiguration(org.bboxdb.storage.entity.TupleStoreConfiguration) DistributionGroupConfiguration(org.bboxdb.storage.entity.DistributionGroupConfiguration) IOException(java.io.IOException) BBoxDBException(org.bboxdb.misc.BBoxDBException) EmptyResultFuture(org.bboxdb.network.client.future.EmptyResultFuture)

Example 43 with EmptyResultFuture

use of org.bboxdb.network.client.future.EmptyResultFuture in project bboxdb by jnidzwetzki.

the class BenchmarkFileInsertPerformance method handleLine.

/**
 * Handle a line from the input file
 * @param line
 * @throws BBoxDBException
 */
protected void handleLine(String line) {
    try {
        final Polygon polygon = Polygon.fromGeoJson(line);
        final byte[] tupleBytes = polygon.toGeoJson().getBytes();
        final Tuple tuple = new Tuple(Long.toString(polygon.getId()), polygon.getBoundingBox(), tupleBytes);
        final EmptyResultFuture insertFuture = bboxdbClient.insertTuple(table, tuple);
        // register pending future
        pendingFutures.put(insertFuture);
        insertedTuples.incrementAndGet();
    } catch (BBoxDBException e) {
        System.err.println("Got an exeption while reading file: " + e);
        System.exit(-1);
    }
}
Also used : Polygon(org.bboxdb.tools.converter.osm.util.Polygon) BBoxDBException(org.bboxdb.misc.BBoxDBException) Tuple(org.bboxdb.storage.entity.Tuple) EmptyResultFuture(org.bboxdb.network.client.future.EmptyResultFuture)

Aggregations

EmptyResultFuture (org.bboxdb.network.client.future.EmptyResultFuture)43 Tuple (org.bboxdb.storage.entity.Tuple)17 TupleStoreConfiguration (org.bboxdb.storage.entity.TupleStoreConfiguration)15 BoundingBox (org.bboxdb.commons.math.BoundingBox)11 BBoxDBException (org.bboxdb.misc.BBoxDBException)11 Test (org.junit.Test)11 TupleListFuture (org.bboxdb.network.client.future.TupleListFuture)10 DistributionGroupConfiguration (org.bboxdb.storage.entity.DistributionGroupConfiguration)9 BBoxDBClient (org.bboxdb.network.client.BBoxDBClient)8 BBoxDBConnection (org.bboxdb.network.client.BBoxDBConnection)8 JoinedTuple (org.bboxdb.storage.entity.JoinedTuple)8 JoinedTupleListFuture (org.bboxdb.network.client.future.JoinedTupleListFuture)7 NetworkOperationFuture (org.bboxdb.network.client.future.NetworkOperationFuture)5 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 BBoxDBInstance (org.bboxdb.distribution.membership.BBoxDBInstance)3 FixedSizeFutureStore (org.bboxdb.network.client.tools.FixedSizeFutureStore)3 RoutingHeader (org.bboxdb.network.routing.RoutingHeader)3 List (java.util.List)2