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);
}
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();
}
}
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;
}
}
}
Aggregations