Search in sources :

Example 1 with Memtable

use of org.bboxdb.storage.memtable.Memtable in project bboxdb by jnidzwetzki.

the class TestMemtable method before.

@Before
public void before() {
    memtable = new Memtable(MEMTABLE_TABLE_NAME, MEMTABLE_MAX_ENTRIES, MEMTABLE_MAX_SIZE);
    memtable.init();
    memtable.acquire();
}
Also used : Memtable(org.bboxdb.storage.memtable.Memtable) Before(org.junit.Before)

Example 2 with Memtable

use of org.bboxdb.storage.memtable.Memtable in project bboxdb by jnidzwetzki.

the class TestMemtable method testAquire2.

/**
 * Test the aquire
 * @throws StorageManagerException
 */
@Test(timeout = 60000)
public void testAquire2() throws StorageManagerException {
    final Memtable memtable = new Memtable(MEMTABLE_TABLE_NAME, MEMTABLE_MAX_ENTRIES, MEMTABLE_MAX_SIZE);
    memtable.init();
    Assert.assertTrue(memtable.acquire());
    final Tuple createdTuple1 = new Tuple("1", null, "abc".getBytes(), 60);
    memtable.put(createdTuple1);
    memtable.release();
    Assert.assertEquals(3, memtable.getSize());
    memtable.deleteOnClose();
    Assert.assertEquals(0, memtable.getSize());
}
Also used : Memtable(org.bboxdb.storage.memtable.Memtable) Tuple(org.bboxdb.storage.entity.Tuple) DeletedTuple(org.bboxdb.storage.entity.DeletedTuple) Test(org.junit.Test)

Example 3 with Memtable

use of org.bboxdb.storage.memtable.Memtable in project bboxdb by jnidzwetzki.

the class TestMemtable method testAquire1.

/**
 * Test the aquire
 * @throws StorageManagerException
 */
@Test(timeout = 60000)
public void testAquire1() throws StorageManagerException {
    final Memtable memtable = new Memtable(MEMTABLE_TABLE_NAME, MEMTABLE_MAX_ENTRIES, MEMTABLE_MAX_SIZE);
    memtable.init();
    Assert.assertTrue(memtable.acquire());
    final Tuple createdTuple1 = new Tuple("1", null, "abc".getBytes(), 60);
    memtable.put(createdTuple1);
    memtable.deleteOnClose();
    Assert.assertFalse(memtable.acquire());
    Assert.assertEquals(1, memtable.get("1").size());
    memtable.release();
    Assert.assertEquals(0, memtable.getSize());
}
Also used : Memtable(org.bboxdb.storage.memtable.Memtable) Tuple(org.bboxdb.storage.entity.Tuple) DeletedTuple(org.bboxdb.storage.entity.DeletedTuple) Test(org.junit.Test)

Example 4 with Memtable

use of org.bboxdb.storage.memtable.Memtable in project bboxdb by jnidzwetzki.

the class TupleStoreManager method flush.

/**
 * Flush all in memory data, if the memtable flush thread is running
 * @return
 */
public boolean flush() {
    final Memtable activeMemtable = tupleStoreInstances.getMemtable();
    if (activeMemtable == null) {
        return true;
    }
    // Flush in memory data
    initNewMemtable();
    try {
        tupleStoreInstances.waitForMemtableFlush(activeMemtable);
    } catch (InterruptedException e) {
        logger.info("Got interrupted exception while waiting for memtable flush");
        Thread.currentThread().interrupt();
        return false;
    } catch (StorageManagerException e) {
        logger.info("Got exception while waiting for memtable flush", e);
        return false;
    }
    return true;
}
Also used : Memtable(org.bboxdb.storage.memtable.Memtable) StorageManagerException(org.bboxdb.storage.StorageManagerException)

Example 5 with Memtable

use of org.bboxdb.storage.memtable.Memtable in project bboxdb by jnidzwetzki.

the class TupleStoreManager method initNewMemtable.

/**
 * Open a new memtable and schedule the old memtable for flushing
 * @throws StorageManagerException
 */
public synchronized void initNewMemtable() {
    final Memtable memtable = new Memtable(tupleStoreName, configuration.getMemtableEntriesMax(), configuration.getMemtableSizeMax());
    memtable.acquire();
    memtable.init();
    final Memtable oldMemtable = tupleStoreInstances.activateNewMemtable(memtable);
    if (oldMemtable != null) {
        final MemtableAndTupleStoreManagerPair memtableTask = new MemtableAndTupleStoreManagerPair(oldMemtable, this);
        storage.scheduleMemtableFlush(memtableTask);
    }
    logger.debug("Activated a new memtable: {}", memtable.getInternalName());
}
Also used : MemtableAndTupleStoreManagerPair(org.bboxdb.storage.entity.MemtableAndTupleStoreManagerPair) Memtable(org.bboxdb.storage.memtable.Memtable)

Aggregations

Memtable (org.bboxdb.storage.memtable.Memtable)6 DeletedTuple (org.bboxdb.storage.entity.DeletedTuple)2 Tuple (org.bboxdb.storage.entity.Tuple)2 Test (org.junit.Test)2 StorageManagerException (org.bboxdb.storage.StorageManagerException)1 MemtableAndTupleStoreManagerPair (org.bboxdb.storage.entity.MemtableAndTupleStoreManagerPair)1 Before (org.junit.Before)1