use of org.janusgraph.diskstorage.keycolumnvalue.cache.KCVEntryMutation in project janusgraph by JanusGraph.
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 {})", checked, round, skipped);
return checked;
}
use of org.janusgraph.diskstorage.keycolumnvalue.cache.KCVEntryMutation in project janusgraph by JanusGraph.
the class MultiWriteKeyColumnValueStoreTest method mutateState.
/**
* Change the supplied {@code state} with a pseudorandom number generator.
* <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} pseudorandom 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;
final Map<StaticBuffer, KCVEntryMutation> result = new HashMap<>();
// deletion pass
int deletions = 0;
StaticBuffer key = null, col = null;
Entry entry = null;
Iterator<StaticBuffer> iterator = state.keySet().iterator();
while (iterator.hasNext() && deletions < maxDeletionCount) {
key = iterator.next();
Iterator<Map.Entry<StaticBuffer, StaticBuffer>> columnIterator = state.get(key).entrySet().iterator();
while (columnIterator.hasNext() && deletions < maxDeletionCount) {
Map.Entry<StaticBuffer, StaticBuffer> colEntry = columnIterator.next();
entry = StaticArrayEntry.of(colEntry.getKey(), colEntry.getValue());
if (!result.containsKey(key)) {
KCVEntryMutation m = new KCVEntryMutation(new LinkedList<>(), new LinkedList<>());
result.put(key, m);
}
result.get(key).deletion(entry);
deletions++;
columnIterator.remove();
if (state.get(key).isEmpty()) {
assert !columnIterator.hasNext();
iterator.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<>();
state.put(key, m);
}
state.get(key).put(col, col);
if (!result.containsKey(key)) {
KCVEntryMutation m = new KCVEntryMutation(new LinkedList<>(), new LinkedList<>());
result.put(key, m);
}
result.get(key).addition(StaticArrayEntry.of(col, col));
}
return result;
}
use of org.janusgraph.diskstorage.keycolumnvalue.cache.KCVEntryMutation in project janusgraph by JanusGraph.
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<>(1);
Map<StaticBuffer, KCVEntryMutation> deleteOnly = new HashMap<>(1);
Map<StaticBuffer, KCVEntryMutation> addOnly = new HashMap<>(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));
}
}
Aggregations