Search in sources :

Example 1 with KCVEntryMutation

use of com.thinkaurelius.titan.diskstorage.keycolumnvalue.cache.KCVEntryMutation in project titan by thinkaurelius.

the class MultiWriteKeyColumnValueStoreTest method deletionsAppliedBeforeAdditions.

@Test
public void deletionsAppliedBeforeAdditions() throws BackendException {
    StaticBuffer b1 = KeyColumnValueStoreUtil.longToByteBuffer(1);
    Assert.assertNull(KCVSUtil.get(store1, b1, b1, tx));
    List<Entry> additions = Lists.newArrayList(StaticArrayEntry.of(b1, b1));
    List<Entry> deletions = Lists.newArrayList(additions);
    Map<StaticBuffer, KCVEntryMutation> combination = new HashMap<StaticBuffer, KCVEntryMutation>(1);
    Map<StaticBuffer, KCVEntryMutation> deleteOnly = new HashMap<StaticBuffer, KCVEntryMutation>(1);
    Map<StaticBuffer, KCVEntryMutation> addOnly = new HashMap<StaticBuffer, KCVEntryMutation>(1);
    combination.put(b1, new KCVEntryMutation(additions, deletions));
    deleteOnly.put(b1, new KCVEntryMutation(KeyColumnValueStore.NO_ADDITIONS, deletions));
    addOnly.put(b1, new KCVEntryMutation(additions, KCVSCache.NO_DELETIONS));
    store1.mutateEntries(b1, additions, deletions, tx);
    newTx();
    StaticBuffer result = KCVSUtil.get(store1, b1, b1, tx);
    Assert.assertEquals(b1, result);
    store1.mutateEntries(b1, NO_ADDITIONS, deletions, tx);
    newTx();
    for (int i = 0; i < 100; i++) {
        StaticBuffer n = KCVSUtil.get(store1, b1, b1, tx);
        Assert.assertNull(n);
        store1.mutateEntries(b1, additions, KCVSCache.NO_DELETIONS, tx);
        newTx();
        store1.mutateEntries(b1, NO_ADDITIONS, deletions, tx);
        newTx();
        n = KCVSUtil.get(store1, b1, b1, tx);
        Assert.assertNull(n);
    }
    for (int i = 0; i < 100; i++) {
        store1.mutateEntries(b1, NO_ADDITIONS, deletions, tx);
        newTx();
        store1.mutateEntries(b1, additions, KCVSCache.NO_DELETIONS, tx);
        newTx();
        Assert.assertEquals(b1, KCVSUtil.get(store1, b1, b1, tx));
    }
    for (int i = 0; i < 100; i++) {
        store1.mutateEntries(b1, additions, deletions, tx);
        newTx();
        Assert.assertEquals(b1, KCVSUtil.get(store1, b1, b1, tx));
    }
}
Also used : StaticArrayEntry(com.thinkaurelius.titan.diskstorage.util.StaticArrayEntry) KCVEntryMutation(com.thinkaurelius.titan.diskstorage.keycolumnvalue.cache.KCVEntryMutation) Test(org.junit.Test)

Example 2 with KCVEntryMutation

use of com.thinkaurelius.titan.diskstorage.keycolumnvalue.cache.KCVEntryMutation in project titan by thinkaurelius.

the class MultiWriteKeyColumnValueStoreTest method checkThatDeletionsApplied.

public int checkThatDeletionsApplied(Map<StaticBuffer, KCVEntryMutation> changes, KeyColumnValueStore store, int round) throws BackendException {
    int checked = 0;
    int skipped = 0;
    for (StaticBuffer key : changes.keySet()) {
        KCVEntryMutation m = changes.get(key);
        if (!m.hasDeletions())
            continue;
        List<Entry> deletions = m.getDeletions();
        List<Entry> additions = m.getAdditions();
        for (Entry entry : deletions) {
            StaticBuffer col = entry.getColumn();
            if (null != additions && additions.contains(StaticArrayEntry.of(col, col))) {
                skipped++;
                continue;
            }
            Assert.assertNull(KCVSUtil.get(store, key, col, tx));
            checked++;
        }
    }
    log.debug("Checked absence of {} key-column-value deletions on round {} (skipped {})", new Object[] { checked, round, skipped });
    return checked;
}
Also used : StaticArrayEntry(com.thinkaurelius.titan.diskstorage.util.StaticArrayEntry) KCVEntryMutation(com.thinkaurelius.titan.diskstorage.keycolumnvalue.cache.KCVEntryMutation)

Example 3 with KCVEntryMutation

use of com.thinkaurelius.titan.diskstorage.keycolumnvalue.cache.KCVEntryMutation in project titan by thinkaurelius.

the class MultiWriteKeyColumnValueStoreTest method mutateState.

/**
     * Pseudorandomly change the supplied {@code state}.
     * <p/>
     * This method removes {@code min(maxDeletionCount, S)} entries from the
     * maps in {@code state.values()}, where {@code S} is the sum of the sizes
     * of the maps in {@code state.values()}; this method then adds
     * {@code additionCount} pseudorandomly generated entries spread across
     * {@code state.values()}, potentially adding new keys to {@code state}
     * since they are randomly generated. This method then returns a map of keys
     * to Mutations representing the changes it has made to {@code state}.
     *
     * @param state            Maps keys -> columns -> values
     * @param maxDeletionCount Remove at most this many entries from state
     * @param additionCount    Add exactly this many entries to state
     * @return A KCVMutation map
     */
public Map<StaticBuffer, KCVEntryMutation> mutateState(Map<StaticBuffer, Map<StaticBuffer, StaticBuffer>> state, int maxDeletionCount, int additionCount) {
    final int keyLength = 8;
    final int colLength = 16;
    Map<StaticBuffer, KCVEntryMutation> result = new HashMap<StaticBuffer, KCVEntryMutation>();
    // deletion pass
    int dels = 0;
    StaticBuffer key = null, col = null;
    Entry entry = null;
    Iterator<StaticBuffer> keyIter = state.keySet().iterator();
    while (keyIter.hasNext() && dels < maxDeletionCount) {
        key = keyIter.next();
        Iterator<Map.Entry<StaticBuffer, StaticBuffer>> colIter = state.get(key).entrySet().iterator();
        while (colIter.hasNext() && dels < maxDeletionCount) {
            Map.Entry<StaticBuffer, StaticBuffer> colEntry = colIter.next();
            entry = StaticArrayEntry.of(colEntry.getKey(), colEntry.getValue());
            if (!result.containsKey(key)) {
                KCVEntryMutation m = new KCVEntryMutation(new LinkedList<Entry>(), new LinkedList<Entry>());
                result.put(key, m);
            }
            result.get(key).deletion(entry);
            dels++;
            colIter.remove();
            if (state.get(key).isEmpty()) {
                assert !colIter.hasNext();
                keyIter.remove();
            }
        }
    }
    // addition pass
    for (int i = 0; i < additionCount; i++) {
        while (true) {
            byte[] keyBuf = new byte[keyLength];
            rand.nextBytes(keyBuf);
            key = new StaticArrayBuffer(keyBuf);
            byte[] colBuf = new byte[colLength];
            rand.nextBytes(colBuf);
            col = new StaticArrayBuffer(colBuf);
            if (!state.containsKey(key) || !state.get(key).containsKey(col)) {
                break;
            }
        }
        if (!state.containsKey(key)) {
            Map<StaticBuffer, StaticBuffer> m = new HashMap<StaticBuffer, StaticBuffer>();
            state.put(key, m);
        }
        state.get(key).put(col, col);
        if (!result.containsKey(key)) {
            KCVEntryMutation m = new KCVEntryMutation(new LinkedList<Entry>(), new LinkedList<Entry>());
            result.put(key, m);
        }
        result.get(key).addition(StaticArrayEntry.of(col, col));
    }
    return result;
}
Also used : StaticArrayBuffer(com.thinkaurelius.titan.diskstorage.util.StaticArrayBuffer) KCVEntryMutation(com.thinkaurelius.titan.diskstorage.keycolumnvalue.cache.KCVEntryMutation) StaticArrayEntry(com.thinkaurelius.titan.diskstorage.util.StaticArrayEntry) ImmutableMap(com.google.common.collect.ImmutableMap)

Aggregations

KCVEntryMutation (com.thinkaurelius.titan.diskstorage.keycolumnvalue.cache.KCVEntryMutation)3 StaticArrayEntry (com.thinkaurelius.titan.diskstorage.util.StaticArrayEntry)3 ImmutableMap (com.google.common.collect.ImmutableMap)1 StaticArrayBuffer (com.thinkaurelius.titan.diskstorage.util.StaticArrayBuffer)1 Test (org.junit.Test)1