public static boolean containsKey(KeyColumnValueStore store, StaticBuffer key, StoreTransaction txh) throws BackendException { return containsKey(store,key,32,txh); }
/** * 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; }
private DataPuller addDataPuller(SliceQuery sq, StoreTransaction stx) throws BackendException { final BlockingQueue<SliceResult> queue = new LinkedBlockingQueue<>(QUEUE_SIZE); dataQueues.add(queue); DataPuller dp = new DataPuller(sq, queue, KCVSUtil.getKeys(store,sq,storeFeatures,MAX_KEY_LENGTH,stx),job.getKeyFilter()); dp.start(); return dp; }
public void checkValueExistence(String[][] values, Set<KeyColumn> removed) throws BackendException { for (int i = 0; i < numKeys; i++) { for (int j = 0; j < numColumns; j++) { boolean result = KCVSUtil.containsKeyColumn(store, KeyValueStoreUtil.getBuffer(i), KeyValueStoreUtil.getBuffer(j), tx); if (removed.contains(new KeyColumn(i, j))) { Assert.assertFalse(result); } else { Assert.assertTrue(result); } } } }
public static boolean matches(KeyRangeQuery query, StaticBuffer key, StaticBuffer column) { return matches(query,column) && query.getKeyStart().compareTo(key)<=0 && query.getKeyEnd().compareTo(key)>0; }
return KCVSUtil.emptyResults(keys);
@Test public void containsKeyColumnReturnsFalseOnNonexistentInput() throws Exception { StaticBuffer key1 = KeyColumnValueStoreUtil.longToByteBuffer(1); StaticBuffer c = KeyColumnValueStoreUtil.stringToByteBuffer("c"); Assert.assertFalse(KCVSUtil.containsKeyColumn(store, key1, c, tx)); }
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 void checkKeys(Set<Integer> removed) throws BackendException { for (int i = 0; i < numKeys; i++) { if (removed.contains(i)) { Assert.assertFalse(KCVSUtil.containsKey(store, KeyValueStoreUtil.getBuffer(i), tx)); } else { Assert.assertTrue(KCVSUtil.containsKey(store, KeyValueStoreUtil.getBuffer(i), tx)); } } }
public static KeyIterator getKeys(KeyColumnValueStore store, StoreFeatures features, int keyLength, int sliceLength, StoreTransaction txh) throws BackendException { return getKeys(store,new SliceQuery(BufferUtil.zeroBuffer(1), BufferUtil.oneBuffer(sliceLength)).setLimit(1), features,keyLength,txh); }
@Test public void containsKeyColumnReturnsTrueOnExtantInput() throws Exception { KeyColumnValueStoreUtil.insert(store, tx, 1, "c", "v"); tx.commit(); tx = startTx(); StaticBuffer key1 = KeyColumnValueStoreUtil.longToByteBuffer(1); StaticBuffer c = KeyColumnValueStoreUtil.stringToByteBuffer("c"); Assert.assertTrue(KCVSUtil.containsKeyColumn(store, key1, c, tx)); }
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); }
@Test public void containsKeyReturnsFalseOnNonexistentKey() throws Exception { StaticBuffer key1 = KeyColumnValueStoreUtil.longToByteBuffer(1); Assert.assertFalse(KCVSUtil.containsKey(store, key1, tx)); }
String[][] values = generateValues(); loadValues(values); KeyIterator iterator0 = KCVSUtil.getKeys(store, storeFeatures(), 8, 4, tx); verifyIterator(iterator0,numKeys); clopen(); KeyIterator iterator1 = KCVSUtil.getKeys(store, storeFeatures(), 8, 4, tx); KeyIterator iterator2 = KCVSUtil.getKeys(store, storeFeatures(), 8, 4, tx); KeyIterator iterator3 = KCVSUtil.getKeys(store, storeFeatures(), 8, 4, tx); verifyIterator(iterator1,numKeys); verifyIterator(iterator2,numKeys);
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(); }
@Test public void containsKeyReturnsTrueOnExtantKey() throws Exception { StaticBuffer key1 = KeyColumnValueStoreUtil.longToByteBuffer(1); Assert.assertFalse(KCVSUtil.containsKey(store, key1, tx)); KeyColumnValueStoreUtil.insert(store, tx, 1, "c", "v"); tx.commit(); tx = startTx(); Assert.assertTrue(KCVSUtil.containsKey(store, key1, tx)); }
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])); }