Search in sources :

Example 1 with ReadOnlyTupleStore

use of org.bboxdb.storage.tuplestore.ReadOnlyTupleStore in project bboxdb by jnidzwetzki.

the class TestTableCompactor method testCompactorRunnable.

/**
 * Test the compactor runnable
 * @throws RejectedException
 * @throws StorageManagerException
 * @throws InterruptedException
 * @throws BBoxDBException
 */
@Test(timeout = 60000)
public void testCompactorRunnable() throws StorageManagerException, RejectedException, BBoxDBException, InterruptedException {
    storageRegistry.createTable(TEST_RELATION, new TupleStoreConfiguration());
    final TupleStoreManager storageManager = storageRegistry.getTupleStoreManager(TEST_RELATION);
    Assert.assertTrue(storageManager.getServiceState().isInRunningState());
    // Create file 1
    for (int i = 0; i < 1000; i++) {
        storageManager.put(new Tuple(Integer.toString(i), BoundingBox.FULL_SPACE, "abc".getBytes()));
    }
    storageManager.flush();
    // Create file 2
    for (int i = 0; i < 1000; i++) {
        storageManager.put(new Tuple(Integer.toString(i), BoundingBox.FULL_SPACE, "abc".getBytes()));
    }
    storageManager.flush();
    final List<DiskStorage> storages = storageRegistry.getAllStorages();
    Assert.assertEquals(1, storages.size());
    final SSTableServiceRunnable ssTableCompactorRunnable = new SSTableServiceRunnable(storages.get(0));
    ssTableCompactorRunnable.forceMajorCompact(storageManager);
    // Test exception handler
    final List<ReadOnlyTupleStore> writtenStorages = storageManager.aquireStorage();
    storageManager.releaseStorage(writtenStorages);
    storageManager.shutdown();
    final List<SSTableFacade> tupleStorages = writtenStorages.stream().filter(r -> r instanceof SSTableFacade).map(r -> (SSTableFacade) r).collect(Collectors.toList());
    Assert.assertFalse(tupleStorages.isEmpty());
    ssTableCompactorRunnable.handleCompactException(tupleStorages);
}
Also used : Arrays(java.util.Arrays) SSTableWriter(org.bboxdb.storage.sstable.SSTableWriter) SSTableReader(org.bboxdb.storage.sstable.reader.SSTableReader) BeforeClass(org.junit.BeforeClass) RejectedException(org.bboxdb.commons.RejectedException) Tuple(org.bboxdb.storage.entity.Tuple) SSTableServiceRunnable(org.bboxdb.storage.sstable.compact.SSTableServiceRunnable) SSTableHelper(org.bboxdb.storage.sstable.SSTableHelper) SSTableFacade(org.bboxdb.storage.sstable.reader.SSTableFacade) BoundingBox(org.bboxdb.commons.math.BoundingBox) ArrayList(java.util.ArrayList) ReadOnlyTupleStore(org.bboxdb.storage.tuplestore.ReadOnlyTupleStore) TupleStoreManager(org.bboxdb.storage.tuplestore.manager.TupleStoreManager) Lists(com.google.common.collect.Lists) SSTableCompactor(org.bboxdb.storage.sstable.compact.SSTableCompactor) SSTableKeyIndexReader(org.bboxdb.storage.sstable.reader.SSTableKeyIndexReader) DeletedTuple(org.bboxdb.storage.entity.DeletedTuple) BBoxDBConfigurationManager(org.bboxdb.misc.BBoxDBConfigurationManager) DiskStorage(org.bboxdb.storage.tuplestore.DiskStorage) Before(org.junit.Before) AfterClass(org.junit.AfterClass) Iterator(java.util.Iterator) Test(org.junit.Test) Collectors(java.util.stream.Collectors) File(java.io.File) TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) TupleStoreManagerRegistry(org.bboxdb.storage.tuplestore.manager.TupleStoreManagerRegistry) List(java.util.List) BBoxDBException(org.bboxdb.misc.BBoxDBException) TupleStoreConfiguration(org.bboxdb.storage.entity.TupleStoreConfiguration) Assert(org.junit.Assert) Collections(java.util.Collections) TupleStoreConfiguration(org.bboxdb.storage.entity.TupleStoreConfiguration) SSTableFacade(org.bboxdb.storage.sstable.reader.SSTableFacade) SSTableServiceRunnable(org.bboxdb.storage.sstable.compact.SSTableServiceRunnable) ReadOnlyTupleStore(org.bboxdb.storage.tuplestore.ReadOnlyTupleStore) DiskStorage(org.bboxdb.storage.tuplestore.DiskStorage) Tuple(org.bboxdb.storage.entity.Tuple) DeletedTuple(org.bboxdb.storage.entity.DeletedTuple) TupleStoreManager(org.bboxdb.storage.tuplestore.manager.TupleStoreManager) Test(org.junit.Test)

Example 2 with ReadOnlyTupleStore

use of org.bboxdb.storage.tuplestore.ReadOnlyTupleStore in project bboxdb by jnidzwetzki.

the class TupleStoreManager method getAllTupleVersionsForKey.

/**
 * Get all tuples for a given key
 * @param tuple
 * @param activeStorage
 * @return
 * @throws StorageManagerException
 */
public List<Tuple> getAllTupleVersionsForKey(final String key) throws StorageManagerException {
    List<ReadOnlyTupleStore> aquiredStorages = null;
    try {
        aquiredStorages = aquireStorage();
        final List<Tuple> resultTuples = new ArrayList<>();
        for (final ReadOnlyTupleStore readOnlyTupleStorage : aquiredStorages) {
            final List<Tuple> possibleTuples = readOnlyTupleStorage.get(key);
            resultTuples.addAll(possibleTuples);
        }
        return resultTuples;
    } catch (Exception e) {
        throw e;
    } finally {
        releaseStorage(aquiredStorages);
    }
}
Also used : ArrayList(java.util.ArrayList) ReadOnlyTupleStore(org.bboxdb.storage.tuplestore.ReadOnlyTupleStore) Tuple(org.bboxdb.storage.entity.Tuple) RejectedException(org.bboxdb.commons.RejectedException) ZookeeperNotFoundException(org.bboxdb.distribution.zookeeper.ZookeeperNotFoundException) ZookeeperException(org.bboxdb.distribution.zookeeper.ZookeeperException) StorageManagerException(org.bboxdb.storage.StorageManagerException) IOException(java.io.IOException) BBoxDBException(org.bboxdb.misc.BBoxDBException)

Example 3 with ReadOnlyTupleStore

use of org.bboxdb.storage.tuplestore.ReadOnlyTupleStore in project bboxdb by jnidzwetzki.

the class RegionSplitter method spreadTupleStores.

/**
 * Spread a given tuple store onto new systems
 * @param region
 * @param sstableManager
 * @param ssTableManager
 * @param tupleRedistributor
 * @param onlyInMemoryData
 * @throws StorageManagerException
 */
private void spreadTupleStores(final TupleStoreManager ssTableManager, final TupleRedistributor tupleRedistributor) throws BBoxDBException {
    final List<ReadOnlyTupleStore> storages = new ArrayList<>();
    try {
        final List<ReadOnlyTupleStore> aquiredStorages = ssTableManager.aquireStorage();
        storages.addAll(aquiredStorages);
        final int totalSotrages = aquiredStorages.size();
        for (int i = 0; i < totalSotrages; i++) {
            final ReadOnlyTupleStore storage = aquiredStorages.get(i);
            logger.info("Spread tuple storage {} number {} of {}", storage.getInternalName(), i, totalSotrages - 1);
            spreadStorage(tupleRedistributor, storage);
        }
        logger.info("Final statistics for spread ({}): {}", ssTableManager.getTupleStoreName().getFullname(), tupleRedistributor.getStatistics());
    } catch (Exception e) {
        throw new BBoxDBException(e);
    } finally {
        ssTableManager.releaseStorage(storages);
    }
}
Also used : ArrayList(java.util.ArrayList) ReadOnlyTupleStore(org.bboxdb.storage.tuplestore.ReadOnlyTupleStore) BBoxDBException(org.bboxdb.misc.BBoxDBException) BBoxDBException(org.bboxdb.misc.BBoxDBException) StorageManagerException(org.bboxdb.storage.StorageManagerException)

Example 4 with ReadOnlyTupleStore

use of org.bboxdb.storage.tuplestore.ReadOnlyTupleStore in project bboxdb by jnidzwetzki.

the class SamplingHelper method processTupleStores.

/**
 * Process the facades for the table and create samples
 * @param storages
 * @param splitDimension
 * @param boundingBox
 * @param floatIntervals
 * @return
 * @throws StorageManagerException
 */
private static List<BoundingBox> processTupleStores(final List<ReadOnlyTupleStore> storages) throws StorageManagerException {
    final int samplesPerStorage = 100;
    final List<BoundingBox> samples = new ArrayList<>();
    logger.debug("Fetching {} samples per storage", samplesPerStorage);
    for (final ReadOnlyTupleStore storage : storages) {
        if (!storage.acquire()) {
            continue;
        }
        final long numberOfTuples = storage.getNumberOfTuples();
        final int sampleOffset = Math.max(10, (int) (numberOfTuples / samplesPerStorage));
        for (long position = 0; position < numberOfTuples; position = position + sampleOffset) {
            final Tuple tuple = storage.getTupleAtPosition(position);
            final BoundingBox tupleBoundingBox = tuple.getBoundingBox();
            // Ignore tuples with an empty box (e.g. deleted tuples)
            if (tupleBoundingBox == null || tupleBoundingBox.equals(BoundingBox.FULL_SPACE)) {
                continue;
            }
            samples.add(tupleBoundingBox);
        }
        storage.release();
    }
    return samples;
}
Also used : BoundingBox(org.bboxdb.commons.math.BoundingBox) ArrayList(java.util.ArrayList) ReadOnlyTupleStore(org.bboxdb.storage.tuplestore.ReadOnlyTupleStore) Tuple(org.bboxdb.storage.entity.Tuple)

Example 5 with ReadOnlyTupleStore

use of org.bboxdb.storage.tuplestore.ReadOnlyTupleStore in project bboxdb by jnidzwetzki.

the class ConnectionMainteinanceRunnable method sendKeepAlivePackage.

/**
 * Build a keep alive package (with or without gossip)
 * @return
 * @return
 */
private EmptyResultFuture sendKeepAlivePackage() {
    final TupleStoreManagerRegistry tupleStoreManagerRegistry = bboxDBClient.getTupleStoreManagerRegistry();
    if (tupleStoreManagerRegistry == null) {
        return bboxDBClient.sendKeepAlivePackage();
    }
    final List<TupleStoreName> tables = tupleStoreManagerRegistry.getAllTables();
    if (tables.isEmpty()) {
        return bboxDBClient.sendKeepAlivePackage();
    }
    lastGossipTableName = ListHelper.getElementRandom(tables);
    List<ReadOnlyTupleStore> storages = new ArrayList<>();
    try {
        final TupleStoreManager tupleStoreManager = tupleStoreManagerRegistry.getTupleStoreManager(lastGossipTableName);
        try {
            storages = tupleStoreManager.aquireStorage();
            if (storages.isEmpty()) {
                return bboxDBClient.sendKeepAlivePackage();
            }
            final ReadOnlyTupleStore tupleStore = ListHelper.getElementRandom(storages);
            if (tupleStore.getNumberOfTuples() > 0) {
                return sendKeepAliveWithGossip(tupleStoreManager, tupleStore);
            }
        } catch (Exception e) {
            throw e;
        } finally {
            tupleStoreManager.releaseStorage(storages);
        }
    } catch (StorageManagerException e) {
        logger.error("Got exception while reading tuples", e);
    }
    return bboxDBClient.sendKeepAlivePackage();
}
Also used : TupleStoreManagerRegistry(org.bboxdb.storage.tuplestore.manager.TupleStoreManagerRegistry) ArrayList(java.util.ArrayList) TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) StorageManagerException(org.bboxdb.storage.StorageManagerException) ReadOnlyTupleStore(org.bboxdb.storage.tuplestore.ReadOnlyTupleStore) BBoxDBException(org.bboxdb.misc.BBoxDBException) StorageManagerException(org.bboxdb.storage.StorageManagerException) TupleStoreManager(org.bboxdb.storage.tuplestore.manager.TupleStoreManager)

Aggregations

ReadOnlyTupleStore (org.bboxdb.storage.tuplestore.ReadOnlyTupleStore)11 ArrayList (java.util.ArrayList)9 StorageManagerException (org.bboxdb.storage.StorageManagerException)7 BBoxDBException (org.bboxdb.misc.BBoxDBException)6 Tuple (org.bboxdb.storage.entity.Tuple)6 TupleStoreName (org.bboxdb.storage.entity.TupleStoreName)5 TupleStoreManager (org.bboxdb.storage.tuplestore.manager.TupleStoreManager)5 RejectedException (org.bboxdb.commons.RejectedException)3 BoundingBox (org.bboxdb.commons.math.BoundingBox)3 TupleStoreManagerRegistry (org.bboxdb.storage.tuplestore.manager.TupleStoreManagerRegistry)3 File (java.io.File)2 IOException (java.io.IOException)2 List (java.util.List)2 ZookeeperException (org.bboxdb.distribution.zookeeper.ZookeeperException)2 ZookeeperNotFoundException (org.bboxdb.distribution.zookeeper.ZookeeperNotFoundException)2 DeletedTuple (org.bboxdb.storage.entity.DeletedTuple)2 SSTableWriter (org.bboxdb.storage.sstable.SSTableWriter)2 SSTableFacade (org.bboxdb.storage.sstable.reader.SSTableFacade)2 DiskStorage (org.bboxdb.storage.tuplestore.DiskStorage)2 Test (org.junit.Test)2