Search in sources :

Example 1 with SSTableKeyIndexReader

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

the class TestSSTable method testIndexIterator.

/**
 * Test the tuple iterator
 * @throws Exception
 */
@Test(timeout = 60000)
public void testIndexIterator() throws Exception {
    final String relationDirectory = SSTableHelper.getSSTableDir(STORAGE_DIRECTORY, TEST_RELATION);
    final File relationDirectoryFile = new File(relationDirectory);
    FileUtil.deleteRecursive(relationDirectoryFile.toPath());
    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 sstableIndexFile = ssTableWriter.getSstableIndexFile();
    ssTableWriter.close();
    final SSTableReader sstableReader = new SSTableReader(STORAGE_DIRECTORY, TEST_RELATION, 1);
    sstableReader.init();
    final SSTableKeyIndexReader ssTableIndexReader = new SSTableKeyIndexReader(sstableReader);
    ssTableIndexReader.init();
    Assert.assertEquals(1, sstableReader.getTablebumber());
    Assert.assertEquals(1, ssTableIndexReader.getTablebumber());
    Assert.assertEquals(sstableIndexFile, ssTableIndexReader.getFile());
    Assert.assertTrue(sstableReader.getLastModifiedTimestamp() > 0);
    Assert.assertTrue(ssTableIndexReader.getLastModifiedTimestamp() > 0);
    Assert.assertTrue(ssTableIndexReader.getSize() > 0);
    Assert.assertTrue(sstableReader.getSize() > 0);
    int tupleCounter = 0;
    for (Tuple tuple : ssTableIndexReader) {
        Assert.assertEquals(tupleList.get(tupleCounter), tuple);
        tupleCounter++;
    }
    Assert.assertEquals(tupleList.size(), tupleCounter);
}
Also used : SSTableReader(org.bboxdb.storage.sstable.reader.SSTableReader) SSTableKeyIndexReader(org.bboxdb.storage.sstable.reader.SSTableKeyIndexReader) SSTableWriter(org.bboxdb.storage.sstable.SSTableWriter) File(java.io.File) Tuple(org.bboxdb.storage.entity.Tuple) DeletedTuple(org.bboxdb.storage.entity.DeletedTuple) Test(org.junit.Test)

Example 2 with SSTableKeyIndexReader

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

the class TestTableCompactor method testCompactTestFileOneEmptyfile1.

@Test(timeout = 60000)
public void testCompactTestFileOneEmptyfile1() throws StorageManagerException {
    final List<Tuple> tupleList1 = new ArrayList<Tuple>();
    tupleList1.add(new Tuple("1", BoundingBox.FULL_SPACE, "abc".getBytes()));
    final SSTableKeyIndexReader reader1 = addTuplesToFileAndGetReader(tupleList1, 1);
    final List<Tuple> tupleList2 = new ArrayList<Tuple>();
    final SSTableKeyIndexReader reader2 = addTuplesToFileAndGetReader(tupleList2, 2);
    final SSTableKeyIndexReader ssTableIndexReader = exectuteCompactAndGetReader(reader1, reader2, false);
    int counter = 0;
    for (@SuppressWarnings("unused") final Tuple tuple : ssTableIndexReader) {
        counter++;
    }
    Assert.assertEquals(tupleList1.size() + tupleList2.size(), counter);
}
Also used : SSTableKeyIndexReader(org.bboxdb.storage.sstable.reader.SSTableKeyIndexReader) ArrayList(java.util.ArrayList) Tuple(org.bboxdb.storage.entity.Tuple) DeletedTuple(org.bboxdb.storage.entity.DeletedTuple) Test(org.junit.Test)

Example 3 with SSTableKeyIndexReader

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

the class TestTableCompactor method addTuplesToFileAndGetReader.

/**
 * Write the tuplelist into a SSTable and return a reader for this table
 *
 * @param tupleList
 * @param number
 * @return
 * @throws StorageManagerException
 */
protected SSTableKeyIndexReader addTuplesToFileAndGetReader(final List<Tuple> tupleList, int number) throws StorageManagerException {
    Collections.sort(tupleList);
    final SSTableWriter ssTableWriter = new SSTableWriter(STORAGE_DIRECTORY, TEST_RELATION, number, EXPECTED_TUPLES);
    ssTableWriter.open();
    ssTableWriter.addData(tupleList);
    ssTableWriter.close();
    final SSTableReader sstableReader = new SSTableReader(STORAGE_DIRECTORY, TEST_RELATION, number);
    sstableReader.init();
    final SSTableKeyIndexReader ssTableIndexReader = new SSTableKeyIndexReader(sstableReader);
    ssTableIndexReader.init();
    return ssTableIndexReader;
}
Also used : SSTableReader(org.bboxdb.storage.sstable.reader.SSTableReader) SSTableKeyIndexReader(org.bboxdb.storage.sstable.reader.SSTableKeyIndexReader) SSTableWriter(org.bboxdb.storage.sstable.SSTableWriter)

Example 4 with SSTableKeyIndexReader

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

the class TestTableCompactor method testCompactationMajor1.

/**
 * Test a major compactation
 * @throws StorageManagerException
 */
@Test(timeout = 60000)
public void testCompactationMajor1() throws StorageManagerException {
    final List<Tuple> tupleList1 = new ArrayList<Tuple>();
    tupleList1.add(new Tuple("1", BoundingBox.FULL_SPACE, "abc".getBytes()));
    final SSTableKeyIndexReader reader1 = addTuplesToFileAndGetReader(tupleList1, 1);
    final List<Tuple> tupleList2 = new ArrayList<Tuple>();
    tupleList2.add(new DeletedTuple("2"));
    final SSTableKeyIndexReader reader2 = addTuplesToFileAndGetReader(tupleList2, 2);
    final SSTableKeyIndexReader ssTableIndexReader = exectuteCompactAndGetReader(reader1, reader2, true);
    boolean containsDeletedTuple = false;
    int counter = 0;
    for (final Tuple tuple : ssTableIndexReader) {
        counter++;
        if (tuple instanceof DeletedTuple) {
            containsDeletedTuple = true;
        }
    }
    Assert.assertEquals(1, counter);
    Assert.assertFalse(containsDeletedTuple);
}
Also used : DeletedTuple(org.bboxdb.storage.entity.DeletedTuple) SSTableKeyIndexReader(org.bboxdb.storage.sstable.reader.SSTableKeyIndexReader) ArrayList(java.util.ArrayList) Tuple(org.bboxdb.storage.entity.Tuple) DeletedTuple(org.bboxdb.storage.entity.DeletedTuple) Test(org.junit.Test)

Example 5 with SSTableKeyIndexReader

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

the class TestTableCompactor method exectuteCompactAndGetReader.

/**
 * Execute a compactification and return the reader for the resulting table
 *
 * @param reader1
 * @param reader2
 * @param writer
 * @param major
 * @return
 * @throws StorageManagerException
 */
protected SSTableKeyIndexReader exectuteCompactAndGetReader(final SSTableKeyIndexReader reader1, final SSTableKeyIndexReader reader2, final boolean majorCompaction) throws StorageManagerException {
    storageRegistry.deleteTable(TEST_RELATION, true);
    storageRegistry.createTable(TEST_RELATION, new TupleStoreConfiguration());
    final TupleStoreManager storageManager = storageRegistry.getTupleStoreManager(TEST_RELATION);
    final SSTableCompactor compactor = new SSTableCompactor(storageManager, Arrays.asList(reader1, reader2));
    compactor.setMajorCompaction(majorCompaction);
    compactor.executeCompactation();
    final List<SSTableWriter> resultWriter = compactor.getResultList();
    Assert.assertEquals(1, resultWriter.size());
    final SSTableWriter writer = resultWriter.get(0);
    final SSTableReader reader = new SSTableReader(STORAGE_DIRECTORY, TEST_RELATION, writer.getTablenumber());
    reader.init();
    final SSTableKeyIndexReader ssTableIndexReader = new SSTableKeyIndexReader(reader);
    ssTableIndexReader.init();
    return ssTableIndexReader;
}
Also used : SSTableReader(org.bboxdb.storage.sstable.reader.SSTableReader) SSTableKeyIndexReader(org.bboxdb.storage.sstable.reader.SSTableKeyIndexReader) TupleStoreConfiguration(org.bboxdb.storage.entity.TupleStoreConfiguration) SSTableWriter(org.bboxdb.storage.sstable.SSTableWriter) TupleStoreManager(org.bboxdb.storage.tuplestore.manager.TupleStoreManager) SSTableCompactor(org.bboxdb.storage.sstable.compact.SSTableCompactor)

Aggregations

SSTableKeyIndexReader (org.bboxdb.storage.sstable.reader.SSTableKeyIndexReader)14 DeletedTuple (org.bboxdb.storage.entity.DeletedTuple)11 Tuple (org.bboxdb.storage.entity.Tuple)11 Test (org.junit.Test)11 ArrayList (java.util.ArrayList)10 SSTableWriter (org.bboxdb.storage.sstable.SSTableWriter)4 SSTableReader (org.bboxdb.storage.sstable.reader.SSTableReader)4 TupleStoreConfiguration (org.bboxdb.storage.entity.TupleStoreConfiguration)2 SSTableCompactor (org.bboxdb.storage.sstable.compact.SSTableCompactor)2 TupleStoreManager (org.bboxdb.storage.tuplestore.manager.TupleStoreManager)2 File (java.io.File)1 IOException (java.io.IOException)1 BufferUnderflowException (java.nio.BufferUnderflowException)1 StorageManagerException (org.bboxdb.storage.StorageManagerException)1 SSTableFacade (org.bboxdb.storage.sstable.reader.SSTableFacade)1