Search in sources :

Example 1 with CoreDatabase

use of org.cojen.tupl.core.CoreDatabase in project Tupl by cojen.

the class RowStoreTest method randomRowInfos.

private void randomRowInfos(long seed) throws Exception {
    final var rnd = new Random(seed);
    final Database db = Database.open(new DatabaseConfig());
    final Index ix = db.openIndex("test");
    final RowStore rs = new RowStore((CoreDatabase) db, db.openIndex("Schemata"));
    final Map<String, ColumnInfo> keyColumns = randomKeyColumns(0, rnd);
    final boolean withAltKey = rnd.nextBoolean();
    final boolean withIndex = rnd.nextBoolean();
    final Map<Integer, RowInfo> rowInfos = new HashMap<>();
    for (int i = 0; i < 200; i++) {
        RowInfo rowInfo = randomRowInfo("Test", keyColumns, withAltKey, withIndex, rnd);
        Integer version = rs.schemaVersion(rowInfo, true, ix.id(), false);
        RowInfo existing = rowInfos.get(version);
        if (existing == null) {
            rowInfos.put(version, rowInfo);
        } else {
            assertMatches(rowInfo, existing);
        }
    }
    for (Map.Entry<Integer, RowInfo> e : rowInfos.entrySet()) {
        Integer version = rs.schemaVersion(e.getValue(), true, ix.id(), false);
        assertEquals(version, e.getKey());
    }
    db.close();
}
Also used : ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) CoreDatabase(org.cojen.tupl.core.CoreDatabase)

Example 2 with CoreDatabase

use of org.cojen.tupl.core.CoreDatabase in project Tupl by cojen.

the class IndexBackfill method unused.

private void unused(Trigger<R> trigger, boolean close) {
    Sorter sorter;
    Index deleted;
    synchronized (this) {
        if (mTriggers == null) {
            return;
        }
        mTriggers.remove(trigger);
        if (!close && !mTriggers.isEmpty()) {
            return;
        }
        mTriggers = null;
        sorter = mSorter;
        mSorter = null;
        deleted = mDeleted;
        mDeleted = null;
    }
    if (sorter == null && deleted == null) {
        return;
    }
    CoreDatabase db = mRowStore.mDatabase;
    db.removeRedoListener(this);
    Runner.start(() -> {
        Runnable deleteTask = null;
        if (deleted != null) {
            try {
                deleteTask = db.deleteIndex(deleted);
            } catch (Exception e) {
            // Ignore.
            }
        }
        if (sorter != null) {
            try {
                sorter.reset();
            } catch (Exception e) {
            // Ignore.
            }
        }
        if (deleteTask != null) {
            deleteTask.run();
        }
    });
}
Also used : CoreDatabase(org.cojen.tupl.core.CoreDatabase) Sorter(org.cojen.tupl.Sorter) Index(org.cojen.tupl.Index) IOException(java.io.IOException) ClosedIndexException(org.cojen.tupl.ClosedIndexException) InterruptedIOException(java.io.InterruptedIOException)

Aggregations

CoreDatabase (org.cojen.tupl.core.CoreDatabase)2 IOException (java.io.IOException)1 InterruptedIOException (java.io.InterruptedIOException)1 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)1 ClosedIndexException (org.cojen.tupl.ClosedIndexException)1 Index (org.cojen.tupl.Index)1 Sorter (org.cojen.tupl.Sorter)1