Search in sources :

Example 1 with SSTableFacade

use of org.bboxdb.storage.sstable.reader.SSTableFacade in project bboxdb by jnidzwetzki.

the class SSTableServiceRunnable method processTupleStores.

/**
 * Process the tuple stores
 *
 * @param storageRegistry
 * @param tupleStores
 * @throws InterruptedException
 */
private void processTupleStores(final TupleStoreManagerRegistry storageRegistry, final List<TupleStoreName> tupleStores) throws InterruptedException {
    for (final TupleStoreName tupleStoreName : tupleStores) {
        try {
            logger.debug("Running compact for: {}", tupleStoreName);
            final TupleStoreManager tupleStoreManager = storageRegistry.getTupleStoreManager(tupleStoreName);
            if (tupleStoreManager.getSstableManagerState() == TupleStoreManagerState.READ_ONLY) {
                logger.debug("Skipping compact for read only sstable manager: {}", tupleStoreName);
                continue;
            }
            if (!CompactorHelper.isRegionActive(tupleStoreName)) {
                logger.info("Skipping compact run, because region is not active {}", tupleStoreName);
                continue;
            }
            final List<SSTableFacade> facades = getAllTupleStores(tupleStoreManager);
            final MergeTask mergeTask = mergeStrategy.getMergeTask(facades);
            executeCompactTask(mergeTask, tupleStoreManager);
            testForRegionOverflow(tupleStoreManager);
        } catch (StorageManagerException | BBoxDBException e) {
            logger.error("Error while merging tables", e);
        }
    }
}
Also used : SSTableFacade(org.bboxdb.storage.sstable.reader.SSTableFacade) TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) StorageManagerException(org.bboxdb.storage.StorageManagerException) BBoxDBException(org.bboxdb.misc.BBoxDBException) TupleStoreManager(org.bboxdb.storage.tuplestore.manager.TupleStoreManager)

Example 2 with SSTableFacade

use of org.bboxdb.storage.sstable.reader.SSTableFacade in project bboxdb by jnidzwetzki.

the class SSTableServiceRunnable method registerNewFacadeAndDeleteOldInstances.

/**
 * Register a new sstable facade and delete the old ones
 * @param oldFacades
 * @param directory
 * @param name
 * @param tablenumber
 * @throws StorageManagerException
 */
private void registerNewFacadeAndDeleteOldInstances(final TupleStoreManager sstableManager, final List<SSTableFacade> oldFacades, final List<SSTableWriter> newTableWriter) throws StorageManagerException {
    final List<SSTableFacade> newFacades = new ArrayList<>();
    // Open new facades
    openFacades(newTableWriter, newFacades);
    // Manager has switched to read only
    if (sstableManager.getSstableManagerState() == TupleStoreManagerState.READ_ONLY) {
        logger.info("Manager is in read only mode, cancel compact run");
        handleCompactException(newFacades);
        return;
    }
    try {
        for (final SSTableFacade facade : newFacades) {
            facade.init();
        }
        // Switch facades in registry
        sstableManager.replaceCompactedSStables(newFacades, oldFacades);
        // Schedule facades for deletion
        oldFacades.forEach(f -> f.deleteOnClose());
    } catch (BBoxDBException | RejectedException e) {
        handleCompactException(newFacades);
        throw new StorageManagerException(e);
    } catch (InterruptedException e) {
        handleCompactException(newFacades);
        Thread.currentThread().interrupt();
        throw new StorageManagerException(e);
    }
}
Also used : RejectedException(org.bboxdb.commons.RejectedException) ArrayList(java.util.ArrayList) SSTableFacade(org.bboxdb.storage.sstable.reader.SSTableFacade) StorageManagerException(org.bboxdb.storage.StorageManagerException) BBoxDBException(org.bboxdb.misc.BBoxDBException)

Example 3 with SSTableFacade

use of org.bboxdb.storage.sstable.reader.SSTableFacade in project bboxdb by jnidzwetzki.

the class SSTableServiceRunnable method openFacades.

/**
 * Open the facades
 *
 * @param newTableWriter
 * @param newFacades
 * @throws StorageManagerException
 */
private void openFacades(final List<SSTableWriter> newTableWriter, final List<SSTableFacade> newFacades) throws StorageManagerException {
    for (final SSTableWriter writer : newTableWriter) {
        final TupleStoreManagerRegistry tupleStoreManagerRegistry = storage.getTupleStoreManagerRegistry();
        final BBoxDBConfiguration configuration = tupleStoreManagerRegistry.getConfiguration();
        final int sstableKeyCacheEntries = configuration.getSstableKeyCacheEntries();
        final SSTableFacade newFacade = new SSTableFacade(writer.getDirectory(), writer.getName(), writer.getTablenumber(), sstableKeyCacheEntries);
        newFacades.add(newFacade);
    }
}
Also used : TupleStoreManagerRegistry(org.bboxdb.storage.tuplestore.manager.TupleStoreManagerRegistry) BBoxDBConfiguration(org.bboxdb.misc.BBoxDBConfiguration) SSTableWriter(org.bboxdb.storage.sstable.SSTableWriter) SSTableFacade(org.bboxdb.storage.sstable.reader.SSTableFacade)

Example 4 with SSTableFacade

use of org.bboxdb.storage.sstable.reader.SSTableFacade 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 5 with SSTableFacade

use of org.bboxdb.storage.sstable.reader.SSTableFacade in project bboxdb by jnidzwetzki.

the class TupleStoreManager method scanForExistingTables.

/**
 * Scan the database directory for all existing SSTables and
 * create reader objects
 * @throws StorageManagerException
 * @throws InterruptedException
 */
protected void scanForExistingTables() throws StorageManagerException, InterruptedException {
    logger.info("Scan for existing SSTables: " + tupleStoreName.getFullname());
    final String storageDir = storage.getBasedir().getAbsolutePath();
    final String ssTableDir = SSTableHelper.getSSTableDir(storageDir, tupleStoreName);
    final File directoryHandle = new File(ssTableDir);
    checkSSTableDir(directoryHandle);
    final File[] entries = directoryHandle.listFiles();
    for (final File file : entries) {
        final String filename = file.getName();
        if (SSTableHelper.isFileNameSSTable(filename)) {
            logger.info("Found sstable: {}", filename);
            try {
                final int sequenceNumber = SSTableHelper.extractSequenceFromFilename(tupleStoreName, filename);
                final SSTableFacade facade = new SSTableFacade(storageDir, tupleStoreName, sequenceNumber, configuration.getSstableKeyCacheEntries());
                facade.init();
                tupleStoreInstances.addNewDetectedSSTable(facade);
            } catch (BBoxDBException e) {
                throw new StorageManagerException(e);
            }
        }
    }
}
Also used : SSTableFacade(org.bboxdb.storage.sstable.reader.SSTableFacade) StorageManagerException(org.bboxdb.storage.StorageManagerException) File(java.io.File) BBoxDBException(org.bboxdb.misc.BBoxDBException)

Aggregations

SSTableFacade (org.bboxdb.storage.sstable.reader.SSTableFacade)8 BBoxDBException (org.bboxdb.misc.BBoxDBException)4 StorageManagerException (org.bboxdb.storage.StorageManagerException)4 File (java.io.File)3 TupleStoreName (org.bboxdb.storage.entity.TupleStoreName)3 SSTableWriter (org.bboxdb.storage.sstable.SSTableWriter)3 ArrayList (java.util.ArrayList)2 RejectedException (org.bboxdb.commons.RejectedException)2 DeletedTuple (org.bboxdb.storage.entity.DeletedTuple)2 Tuple (org.bboxdb.storage.entity.Tuple)2 SSTableKeyIndexReader (org.bboxdb.storage.sstable.reader.SSTableKeyIndexReader)2 SSTableReader (org.bboxdb.storage.sstable.reader.SSTableReader)2 ReadOnlyTupleStore (org.bboxdb.storage.tuplestore.ReadOnlyTupleStore)2 TupleStoreManager (org.bboxdb.storage.tuplestore.manager.TupleStoreManager)2 TupleStoreManagerRegistry (org.bboxdb.storage.tuplestore.manager.TupleStoreManagerRegistry)2 Test (org.junit.Test)2 Lists (com.google.common.collect.Lists)1 IOException (java.io.IOException)1 BufferUnderflowException (java.nio.BufferUnderflowException)1 Arrays (java.util.Arrays)1