/** * Returns true if the specified key-column pair exists in the store. * * @param store Store * @param key Key * @param column Column * @param txh Transaction * @return TRUE, if key has at least one column-value pair, else FALSE */ public static boolean containsKeyColumn(KeyColumnValueStore store, StaticBuffer key, StaticBuffer column, StoreTransaction txh) throws BackendException { return get(store, key, column, txh) != null; }
public int checkThatStateExistsInStore(Map<StaticBuffer, Map<StaticBuffer, StaticBuffer>> state, KeyColumnValueStore store, int round) throws BackendException { int checked = 0; for (StaticBuffer key : state.keySet()) { for (StaticBuffer col : state.get(key).keySet()) { StaticBuffer val = state.get(key).get(col); Assert.assertEquals(val, KCVSUtil.get(store, key, col, tx)); checked++; } } log.debug("Checked existence of {} key-column-value triples on round {}", checked, round); return checked; }
public static String get(KeyColumnValueStore store, StoreTransaction txn, long key, String col) throws BackendException { StaticBuffer k = longToByteBuffer(key); StaticBuffer c = stringToByteBuffer(col); StaticBuffer valBytes = KCVSUtil.get(store, k, c, txn); if (null == valBytes) return null; return byteBufferToString(valBytes); }
private void tryWrites(KeyColumnValueStore store1, KeyColumnValueStoreManager keyColumnValueStoreManager, StoreTransaction tx1, KeyColumnValueStore store2, StoreTransaction tx2) throws BackendException { Assert.assertNull(KCVSUtil.get(store1, k, c1, tx1)); Assert.assertNull(KCVSUtil.get(store2, k, c2, tx2)); store1.acquireLock(k, c1, null, tx1); store2.acquireLock(k, c2, null, tx2); store1.mutate(k, Collections.singletonList(StaticArrayEntry.of(c1, v1)), NO_DELETIONS, tx1); store2.mutate(k, Collections.singletonList(StaticArrayEntry.of(c2, v2)), NO_DELETIONS, tx2); tx1.commit(); if (tx2 != tx1) tx2.commit(); StoreTransaction transaction = newTransaction(keyColumnValueStoreManager); Assert.assertEquals(v1, KCVSUtil.get(store1, k, c1, transaction)); Assert.assertEquals(v2, KCVSUtil.get(store2, k, c2, transaction)); transaction.commit(); }
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; }
public void checkValues(String[][] values, Set<KeyColumn> removed) throws BackendException { for (int i = 0; i < numKeys; i++) { for (int j = 0; j < numColumns; j++) { StaticBuffer result = KCVSUtil.get(store, KeyValueStoreUtil.getBuffer(i), KeyValueStoreUtil.getBuffer(j), tx); if (removed.contains(new KeyColumn(i, j))) { Assert.assertNull(result); } else { Assert.assertEquals(values[i][j], KeyValueStoreUtil.getString(result)); } } } }
@Test public void singleLockAndUnlock() throws BackendException { store[0].acquireLock(k, c1, null, tx[0][0]); store[0].mutate(k, Collections.singletonList(StaticArrayEntry.of(c1, v1)), NO_DELETIONS, tx[0][0]); tx[0][0].commit(); tx[0][0] = newTransaction(manager[0]); Assert.assertEquals(v1, KCVSUtil.get(store[0], k, c1, tx[0][0])); }
Assert.assertNull(KCVSUtil.get(store1, b1, b1, tx)); newTx(); StaticBuffer result = KCVSUtil.get(store1, b1, b1, tx); StaticBuffer n = KCVSUtil.get(store1, b1, b1, tx); Assert.assertNull(n); store1.mutateEntries(b1, additions, KCVSCache.NO_DELETIONS, tx); store1.mutateEntries(b1, NO_ADDITIONS, deletions, tx); newTx(); n = KCVSUtil.get(store1, b1, b1, tx); Assert.assertNull(n); store1.mutateEntries(b1, additions, KCVSCache.NO_DELETIONS, tx); newTx(); Assert.assertEquals(b1, KCVSUtil.get(store1, b1, b1, tx)); store1.mutateEntries(b1, additions, deletions, tx); newTx(); Assert.assertEquals(b1, KCVSUtil.get(store1, b1, b1, tx));
@Test public void transactionMayReenterLock() throws BackendException { store[0].acquireLock(k, c1, null, tx[0][0]); store[0].acquireLock(k, c1, null, tx[0][0]); store[0].acquireLock(k, c1, null, tx[0][0]); store[0].mutate(k, Collections.singletonList(StaticArrayEntry.of(c1, v1)), NO_DELETIONS, tx[0][0]); tx[0][0].commit(); tx[0][0] = newTransaction(manager[0]); Assert.assertEquals(v1, KCVSUtil.get(store[0], k, c1, tx[0][0])); }
Assert.assertEquals(v1, KCVSUtil.get(store[0], k, c1, tx[0][0]));