Search in sources :

Example 1 with DiskStorage

use of org.bboxdb.storage.tuplestore.DiskStorage 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 DiskStorage

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

the class TupleStoreManagerRegistry method init.

/**
 * Init the service
 * @throws BBoxDBException
 */
@Override
public synchronized void init() throws InterruptedException, BBoxDBException {
    if (!serviceState.isInNewState()) {
        throw new BBoxDBException("Unable to init service is in state: " + serviceState.getState());
    }
    serviceState.dipatchToStarting();
    final List<String> storageDirs = configuration.getStorageDirectories();
    if (storageDirs.isEmpty()) {
        throw new IllegalArgumentException("Unable to init storage registry without any data directory");
    }
    // Populate the sstable location map
    for (final String directory : storageDirs) {
        try {
            tupleStoreLocations.putAll(TupleStoreLocator.scanDirectoryForExistingTables(directory));
            final int flushThreadsPerStorage = configuration.getMemtableFlushThreadsPerStorage();
            final DiskStorage storage = new DiskStorage(this, new File(directory), flushThreadsPerStorage);
            storage.init();
            storages.put(directory, storage);
        } catch (StorageManagerException e) {
            final String dataDirString = SSTableHelper.getDataDir(directory);
            logger.error("Directory {} does not exists, exiting...", dataDirString);
            System.exit(-1);
        }
    }
    serviceState.dispatchToRunning();
}
Also used : StorageManagerException(org.bboxdb.storage.StorageManagerException) BBoxDBException(org.bboxdb.misc.BBoxDBException) DiskStorage(org.bboxdb.storage.tuplestore.DiskStorage) File(java.io.File)

Example 3 with DiskStorage

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

the class TupleStoreManagerRegistry method deleteTable.

/**
 * Delete the given table
 * @param table
 * @throws StorageManagerException
 */
public void deleteTable(final TupleStoreName table, final boolean synchronous) throws StorageManagerException {
    if (!table.isValid()) {
        throw new StorageManagerException("Invalid tablename: " + table);
    }
    String storageDirectory = null;
    synchronized (this) {
        if (managerInstances.containsKey(table)) {
            shutdownSStable(table);
        }
        if (!tupleStoreLocations.containsKey(table)) {
            logger.error("Table {} not known during deletion", table.getFullname());
            return;
        }
        storageDirectory = tupleStoreLocations.get(table);
        tupleStoreLocations.remove(table);
    }
    final DiskStorage storage = storages.get(storageDirectory);
    logger.info("Deleting table {} synchronous {}", table.getFullname(), synchronous);
    if (synchronous) {
        TupleStoreManager.deletePersistentTableData(storageDirectory, table);
    } else {
        storage.getPendingTableDeletions().add(table);
    }
}
Also used : StorageManagerException(org.bboxdb.storage.StorageManagerException) DiskStorage(org.bboxdb.storage.tuplestore.DiskStorage)

Example 4 with DiskStorage

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

the class TupleStoreManagerRegistry method createTable.

/**
 * Create a new table
 * @param tupleStoreName
 * @param configuration
 * @return
 * @throws StorageManagerException
 */
public synchronized TupleStoreManager createTable(final TupleStoreName tupleStoreName, final TupleStoreConfiguration tupleStoreConfiguration) throws StorageManagerException {
    // Find a new storage directory for the sstable manager
    if (tupleStoreLocations.containsKey(tupleStoreName)) {
        throw new StorageManagerException("Table already exist");
    }
    final String location = getLocationLowestUtilizedDataLocation();
    tupleStoreLocations.put(tupleStoreName, location);
    final DiskStorage storage = storages.get(location);
    final TupleStoreManager tupleStoreManager = new TupleStoreManager(storage, tupleStoreName, configuration);
    tupleStoreManager.create(tupleStoreConfiguration);
    tupleStoreManager.init();
    managerInstances.put(tupleStoreName, tupleStoreManager);
    return tupleStoreManager;
}
Also used : StorageManagerException(org.bboxdb.storage.StorageManagerException) DiskStorage(org.bboxdb.storage.tuplestore.DiskStorage)

Example 5 with DiskStorage

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

the class TupleStoreManagerRegistry method getTupleStoreManager.

/**
 * Get the storage manager for a given table. If the storage manager does not
 * exist, it will be created
 *
 * @return
 */
public synchronized TupleStoreManager getTupleStoreManager(final TupleStoreName tupleStoreName) throws StorageManagerException {
    if (!tupleStoreName.isValid()) {
        throw new StorageManagerException("Invalid tablename: " + tupleStoreName);
    }
    zookeeperObserver.registerTable(tupleStoreName);
    // Instance is known
    if (managerInstances.containsKey(tupleStoreName)) {
        return managerInstances.get(tupleStoreName);
    }
    // Find a new storage directory for the sstable manager
    if (!tupleStoreLocations.containsKey(tupleStoreName)) {
        throw new StorageManagerException("Unknown location for table " + tupleStoreName.getFullname() + " does the table exist?");
    }
    final String location = tupleStoreLocations.get(tupleStoreName);
    final DiskStorage storage = storages.get(location);
    final TupleStoreManager sstableManager = new TupleStoreManager(storage, tupleStoreName, configuration);
    sstableManager.init();
    managerInstances.put(tupleStoreName, sstableManager);
    return sstableManager;
}
Also used : StorageManagerException(org.bboxdb.storage.StorageManagerException) DiskStorage(org.bboxdb.storage.tuplestore.DiskStorage)

Aggregations

DiskStorage (org.bboxdb.storage.tuplestore.DiskStorage)6 StorageManagerException (org.bboxdb.storage.StorageManagerException)4 File (java.io.File)2 BBoxDBException (org.bboxdb.misc.BBoxDBException)2 Lists (com.google.common.collect.Lists)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 RejectedException (org.bboxdb.commons.RejectedException)1 BoundingBox (org.bboxdb.commons.math.BoundingBox)1 BBoxDBInstance (org.bboxdb.distribution.membership.BBoxDBInstance)1 SpacePartitioner (org.bboxdb.distribution.partitioner.SpacePartitioner)1 DistributionRegion (org.bboxdb.distribution.region.DistributionRegion)1 ZookeeperClient (org.bboxdb.distribution.zookeeper.ZookeeperClient)1 BBoxDBConfigurationManager (org.bboxdb.misc.BBoxDBConfigurationManager)1 DeletedTuple (org.bboxdb.storage.entity.DeletedTuple)1 Tuple (org.bboxdb.storage.entity.Tuple)1