@Override public void commit() throws BackendException { flushInternal(); tx.commit(); }
public void newTx() throws BackendException { if (tx!=null) tx.commit(); tx = startTx(); }
public void close() throws BackendException { if (tx != null) tx.commit(); store.close(); manager.close(); }
public void close() throws BackendException { if (tx != null) tx.commit(); if (null != store) store.close(); if (null != manager) manager.close(); }
public void close() throws BackendException { for (int i = 0; i < CONCURRENCY; i++) { store[i].close(); for (int j = 0; j < NUM_TX; j++) { log.debug("Committing tx[{}][{}] = {}", i, j, tx[i][j]); if (tx[i][j] != null) tx[i][j].commit(); } manager[i].close(); } LocalLockMediators.INSTANCE.clear(); }
public void loadStore(int numKeys, int numCols) { StoreTransaction tx = getStoreTx(); try { for (int i=1;i<=numKeys;i++) { final List<Entry> adds = new ArrayList<>(numCols); for (int j=1;j<=numCols;j++) adds.add(getEntry(j,j)); store.mutate(BufferUtil.getIntBuffer(i),adds,KeyColumnValueStore.NO_DELETIONS,tx); } tx.commit(); } catch (BackendException e) { throw new RuntimeException(e); } }
public void newTx() throws BackendException { if (tx!=null) tx.commit(); tx = new CacheTransaction(manager.beginTransaction(getTxConfig()), manager, bufferSize, Duration.ofMillis(100), true); }
public void close() throws BackendException { if (tx != null) tx.commit(); if (null != store1) store1.close(); if (null != store2) store2.close(); if (null != manager) manager.close(); }
@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])); }
@Test public void testGetSlices() throws Exception { if (!manager.getFeatures().hasMultiQuery()) return; populateDBWith100Keys(); tx.commit(); tx = startTx(); final List<StaticBuffer> keys = new ArrayList<>(100); for (int i = 1; i <= 100; i++) { keys.add(KeyColumnValueStoreUtil.longToByteBuffer(i)); } StaticBuffer start = KeyColumnValueStoreUtil.stringToByteBuffer("a"); StaticBuffer end = KeyColumnValueStoreUtil.stringToByteBuffer("d"); Map<StaticBuffer,EntryList> results = store.getSlice(keys, new SliceQuery(start, end), tx); Assert.assertEquals(100, results.size()); for (List<Entry> entries : results.values()) { Assert.assertEquals(3, entries.size()); } }
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 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])); }
@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)); }
@Test @Category({UnorderedKeyStoreTests.class}) public void testGetKeysWithSliceQuery() throws Exception { if (!manager.getFeatures().hasUnorderedScan()) { log.warn("Can't test key-unordered features on incompatible store. " + "This warning could indicate reduced test coverage and " + "a broken JUnit configuration. Skipping test {}.", name.getMethodName()); return; } populateDBWith100Keys(); tx.commit(); tx = startTx(); KeyIterator keyIterator = store.getKeys( new SliceQuery(new ReadArrayBuffer("b".getBytes()), new ReadArrayBuffer("c".getBytes())), tx); examineGetKeysResults(keyIterator, 0, 100); }
@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)); }
@Test public void insertingGettingAndDeletingSimpleDataWorks() throws Exception { KeyColumnValueStoreUtil.insert(store, tx, 0, "col0", "val0"); KeyColumnValueStoreUtil.insert(store, tx, 0, "col1", "val1"); tx.commit(); tx = startTx(); Assert.assertEquals("val0", KeyColumnValueStoreUtil.get(store, tx, 0, "col0")); Assert.assertEquals("val1", KeyColumnValueStoreUtil.get(store, tx, 0, "col1")); KeyColumnValueStoreUtil.delete(store, tx, 0, "col0"); KeyColumnValueStoreUtil.delete(store, tx, 0, "col1"); tx.commit(); tx = startTx(); Assert.assertEquals(null, KeyColumnValueStoreUtil.get(store, tx, 0, "col0")); Assert.assertEquals(null, KeyColumnValueStoreUtil.get(store, tx, 0, "col1")); }
@Test @Category({OrderedKeyStoreTests.class}) public void testGetKeysWithKeyRange() throws Exception { if (!manager.getFeatures().hasOrderedScan()) { log.warn("Can't test ordered scans on incompatible store. " + "This warning could indicate reduced test coverage and " + "shouldn't happen in an ideal JUnit configuration. " + "Skipping test {}.", name.getMethodName()); return; } populateDBWith100Keys(); tx.commit(); tx = startTx(); KeyIterator keyIterator = store.getKeys(new KeyRangeQuery( KeyColumnValueStoreUtil.longToByteBuffer(10), // key start KeyColumnValueStoreUtil.longToByteBuffer(40), // key end new ReadArrayBuffer("b".getBytes()), // column start new ReadArrayBuffer("c".getBytes())), tx); examineGetKeysResults(keyIterator, 10, 40); }
public static<R> R execute(Transactional<R> exe, TransactionalProvider provider, TimestampProvider times) throws BackendException { StoreTransaction txh = null; try { txh = provider.openTx(); if (!txh.getConfiguration().hasCommitTime()) txh.getConfiguration().setCommitTime(times.getTime()); return exe.call(txh); } catch (BackendException e) { if (txh!=null) txh.rollback(); txh=null; throw e; } finally { if (txh!=null) txh.commit(); } }
@Test public void getSliceRespectsAllBoundsInclusionArguments() throws Exception { // Test case where endColumn=startColumn+1 StaticBuffer key = KeyColumnValueStoreUtil.longToByteBuffer(0); StaticBuffer columnBeforeStart = KeyColumnValueStoreUtil.longToByteBuffer(776); StaticBuffer columnStart = KeyColumnValueStoreUtil.longToByteBuffer(777); StaticBuffer columnEnd = KeyColumnValueStoreUtil.longToByteBuffer(778); StaticBuffer columnAfterEnd = KeyColumnValueStoreUtil.longToByteBuffer(779); // First insert four test Entries List<Entry> entries = Arrays.asList( StaticArrayEntry.of(columnBeforeStart, columnBeforeStart), StaticArrayEntry.of(columnStart, columnStart), StaticArrayEntry.of(columnEnd, columnEnd), StaticArrayEntry.of(columnAfterEnd, columnAfterEnd)); store.mutate(key, entries, KeyColumnValueStore.NO_DELETIONS, tx); tx.commit(); // getSlice() with only start inclusive tx = startTx(); List<Entry> result = store.getSlice(new KeySliceQuery(key, columnStart, columnEnd), tx); Assert.assertEquals(1, result.size()); Assert.assertEquals(777, KeyColumnValueStoreUtil.bufferToLong(result.get(0).getColumn())); }