Search in sources :

Example 6 with SSTableFacade

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

the class TestSSTable method testDelayedDeletion.

/**
 * Test delayed deletion
 * @throws Exception
 */
@Test(timeout = 60000)
public void testDelayedDeletion() throws Exception {
    final String relationDirectory = SSTableHelper.getSSTableDir(STORAGE_DIRECTORY, TEST_RELATION);
    final File relationDirectoryFile = new File(relationDirectory);
    FileUtil.deleteRecursive(relationDirectoryFile.toPath());
    // Directory should be empty
    Assert.assertFalse(relationDirectoryFile.isDirectory());
    relationDirectoryFile.mkdirs();
    final List<Tuple> tupleList = createTupleList();
    final SSTableWriter ssTableWriter = new SSTableWriter(STORAGE_DIRECTORY, TEST_RELATION, 1, EXPECTED_TUPLES);
    ssTableWriter.open();
    ssTableWriter.addData(tupleList);
    final File sstableFile = ssTableWriter.getSstableFile();
    final File sstableIndexFile = ssTableWriter.getSstableIndexFile();
    ssTableWriter.close();
    Assert.assertTrue(sstableFile.exists());
    Assert.assertTrue(sstableIndexFile.exists());
    final ReadOnlyTupleStore ssTableFacade = new SSTableFacade(STORAGE_DIRECTORY, TEST_RELATION, 1, 0);
    ssTableFacade.acquire();
    ssTableFacade.deleteOnClose();
    // Directory should contain at least the sstable, the key index and the meta data file
    Assert.assertTrue(relationDirectoryFile.listFiles().length >= 3);
    Assert.assertTrue(sstableFile.exists());
    Assert.assertTrue(sstableIndexFile.exists());
    // After calling release, the files can be deleted
    ssTableFacade.release();
    Assert.assertFalse(sstableFile.exists());
    Assert.assertFalse(sstableIndexFile.exists());
    // Directory should be empty
    Assert.assertEquals(0, relationDirectoryFile.listFiles().length);
}
Also used : SSTableWriter(org.bboxdb.storage.sstable.SSTableWriter) SSTableFacade(org.bboxdb.storage.sstable.reader.SSTableFacade) ReadOnlyTupleStore(org.bboxdb.storage.tuplestore.ReadOnlyTupleStore) File(java.io.File) Tuple(org.bboxdb.storage.entity.Tuple) DeletedTuple(org.bboxdb.storage.entity.DeletedTuple) Test(org.junit.Test)

Example 7 with SSTableFacade

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

the class SSTableExaminer method run.

@Override
public void run() {
    try {
        final SSTableFacade sstableFacade = new SSTableFacade(baseDirectory, relationname, tableNumber, 0);
        sstableFacade.init();
        if (!sstableFacade.acquire()) {
            throw new StorageManagerException("Unable to acquire sstable reader");
        }
        final SSTableReader ssTableReader = sstableFacade.getSsTableReader();
        final SSTableKeyIndexReader ssTableIndexReader = sstableFacade.getSsTableKeyIndexReader();
        fullTableScan(ssTableReader);
        if (!WILDCARD_KEY.equals(examineKey)) {
            internalScan(ssTableReader);
            seachViaIndex(ssTableReader, ssTableIndexReader);
        }
        sstableFacade.release();
        sstableFacade.shutdown();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : SSTableReader(org.bboxdb.storage.sstable.reader.SSTableReader) SSTableKeyIndexReader(org.bboxdb.storage.sstable.reader.SSTableKeyIndexReader) SSTableFacade(org.bboxdb.storage.sstable.reader.SSTableFacade) StorageManagerException(org.bboxdb.storage.StorageManagerException) IOException(java.io.IOException) StorageManagerException(org.bboxdb.storage.StorageManagerException) BufferUnderflowException(java.nio.BufferUnderflowException)

Example 8 with SSTableFacade

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

the class MemtableWriterRunnable method flushMemtableToDisk.

/**
 * Flush a memtable to disk
 * @param memtable
 * @param sstableManager
 */
protected void flushMemtableToDisk(final Memtable memtable, final TupleStoreManager sstableManager) {
    SSTableFacade facade = null;
    try {
        // Don't write empty memtables to disk
        if (!memtable.isEmpty()) {
            final TupleStoreName sstableName = sstableManager.getTupleStoreName();
            final String dataDirectory = basedir.getAbsolutePath();
            final int tableNumber = writeMemtable(dataDirectory, memtable, sstableManager);
            final int sstableKeyCacheEntries = storage.getTupleStoreManagerRegistry().getConfiguration().getSstableKeyCacheEntries();
            facade = new SSTableFacade(dataDirectory, sstableName, tableNumber, sstableKeyCacheEntries);
            facade.init();
        }
        sstableManager.replaceMemtableWithSSTable(memtable, facade);
        sendCallbacks(memtable, sstableManager);
        memtable.deleteOnClose();
        memtable.release();
    } catch (Throwable e) {
        deleteWrittenFacade(facade);
        if (sstableManager.getSstableManagerState() == TupleStoreManagerState.READ_ONLY) {
            logger.debug("Rejected memtable write:", e);
            return;
        }
        logger.error("Exception while flushing memtable", e);
        if (Thread.currentThread().isInterrupted()) {
            logger.debug("Got Exception while flushing memtable, but thread was interrupted. " + "Ignoring exception.");
            Thread.currentThread().interrupt();
            return;
        }
    }
}
Also used : SSTableFacade(org.bboxdb.storage.sstable.reader.SSTableFacade) TupleStoreName(org.bboxdb.storage.entity.TupleStoreName)

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