@Override public Transaction createNewTransaction() { return wrap(delegate.createNewTransaction()); }
private RowResult<byte[]> readRow(byte[] defaultRow) { Transaction readTransaction = txManager.createNewTransaction(); SortedMap<byte[], RowResult<byte[]>> allRows = readTransaction.getRows(TABLE, ImmutableSet.of(defaultRow), ColumnSelection.all()); return allRows.get(defaultRow); }
@Test (expected = IllegalArgumentException.class) public void disallowPutOnEmptyObject() { Transaction t1 = txManager.createNewTransaction(); t1.put(TABLE, ImmutableMap.of(TEST_CELL, PtBytes.EMPTY_BYTE_ARRAY)); }
private void writeCells(TableReference table, ImmutableMap<Cell, byte[]> cellsToWrite) { Transaction writeTransaction = txManager.createNewTransaction(); writeTransaction.put(table, cellsToWrite); writeTransaction.commit(); }
@Test public void writesNotAddedToSweepQueueOrKvsOnWriteWriteConflict() { Transaction t1 = txManager.createNewTransaction(); Transaction t2 = txManager.createNewTransaction(); put(t1, SINGLE_WRITE); put(t2, SINGLE_WRITE); t1.commit(); assertThatThrownBy(t2::commit).isInstanceOf(TransactionConflictException.class); verify(sweepQueue, times(1)).enqueue(anyList()); assertLatestEntryForCellInKvsAtTimestamp(TABLE_CONS, TEST_CELL, t1.getTimestamp()); }
@Test public void testIgnoresOrphanedSweepSentinel() { Cell cell = Cell.create(PtBytes.toBytes("row1"), PtBytes.toBytes("column1")); keyValueService.addGarbageCollectionSentinelValues(TABLE, ImmutableSet.of(cell)); Transaction txn = txManager.createNewTransaction(); assertThat(txn.get(TABLE, ImmutableSet.of(cell)), is(ImmutableMap.of())); }
@Test public void testWriteChangedConflictsNoThrow() { overrideConflictHandlerForTable(TABLE, ConflictHandler.RETRY_ON_VALUE_CHANGED); final Cell cell = Cell.create(PtBytes.toBytes("row1"), PtBytes.toBytes("column1")); Transaction t1 = txManager.createNewTransaction(); Transaction t2 = txManager.createNewTransaction(); t1.delete(TABLE, ImmutableSet.of(cell)); t2.delete(TABLE, ImmutableSet.of(cell)); t1.commit(); t2.commit(); }
private long concurrentlyIncrementValueThousandTimesAndGet() throws InterruptedException, ExecutionException { CompletionService<Void> executor = new ExecutorCompletionService<Void>( PTExecutors.newFixedThreadPool(8)); final Cell cell = Cell.create(PtBytes.toBytes("row1"), PtBytes.toBytes("column1")); Transaction t1 = txManager.createNewTransaction(); t1.put(TABLE, ImmutableMap.of(cell, EncodingUtils.encodeVarLong(0L))); t1.commit(); for (int i = 0; i < 1000; i++) { executor.submit(() -> { txManager.runTaskWithRetry((TxTask) t -> { long prev = EncodingUtils.decodeVarLong( t.get(TABLE, ImmutableSet.of(cell)).values().iterator().next()); t.put(TABLE, ImmutableMap.of(cell, EncodingUtils.encodeVarLong(prev + 1))); return null; }); return null; }); } for (int i = 0; i < 1000; i++) { Future<Void> future = executor.take(); future.get(); } t1 = txManager.createNewTransaction(); return EncodingUtils.decodeVarLong(t1.get(TABLE, ImmutableSet.of(cell)).values().iterator().next()); }
Transaction t1 = txManager.createNewTransaction(); Transaction t2 = txManager.createNewTransaction(); t1.put(TABLE1, ImmutableMap.of(row1Column1, BigInteger.valueOf(1).toByteArray())); t2.put(TABLE1, ImmutableMap.of(row1Column1, BigInteger.valueOf(1).toByteArray())); t1 = txManager.createNewTransaction(); t2 = txManager.createNewTransaction(); t1.put(TABLE1, ImmutableMap.of(row1Column1, BigInteger.valueOf(1).toByteArray())); t2.put(TABLE1, ImmutableMap.of(row1Column1, BigInteger.valueOf(1).toByteArray())); t1 = txManager.createNewTransaction(); t2 = txManager.createNewTransaction(); t1.put(TABLE1, ImmutableMap.of(row1Column1, BigInteger.valueOf(1).toByteArray())); t2.put(TABLE1, ImmutableMap.of(row2Column1, BigInteger.valueOf(1).toByteArray())); t1 = txManager.createNewTransaction(); t2 = txManager.createNewTransaction(); t1.put(TABLE1, ImmutableMap.of(row1Column1, BigInteger.valueOf(1).toByteArray())); t2.put(TABLE2, ImmutableMap.of(row1Column1, BigInteger.valueOf(1).toByteArray())); t1 = txManager.createNewTransaction(); t2 = txManager.createNewTransaction(); t1.put(TABLE1, ImmutableMap.of(row1Column1, BigInteger.valueOf(1).toByteArray())); t2.put(TABLE1, ImmutableMap.of(row1Column2, BigInteger.valueOf(1).toByteArray()));
int numTransactions = 500; Transaction initTransaction = txManager.createNewTransaction(); for (int i = 0; i < numColumns; i++) { Cell cell = Cell.create(PtBytes.toBytes("row"), PtBytes.toBytes("column" + i)); List<List<BigInteger>> writtenValues = Lists.newArrayList(); for (int i = 0; i < numTransactions; i++) { allTransactions.add(txManager.createNewTransaction()); List<BigInteger> initialValues = Lists.newArrayList(); for (int j = 0; j < numColumns; j++) {
@Test public void testWriteWriteConflictsDeletedThrow() { overrideConflictHandlerForTable(TABLE, ConflictHandler.RETRY_ON_WRITE_WRITE); final Cell cell = Cell.create(PtBytes.toBytes("row1"), PtBytes.toBytes("column1")); Transaction t1 = txManager.createNewTransaction(); Transaction t2 = txManager.createNewTransaction(); t1.delete(TABLE, ImmutableSet.of(cell)); t2.delete(TABLE, ImmutableSet.of(cell)); t1.commit(); try { t2.commit(); fail(); } catch (TransactionConflictException e) { // good } }
@Test public void testThrowsIfSweepSentinelSeen() { Cell cell = Cell.create(PtBytes.toBytes("row1"), PtBytes.toBytes("column1")); Transaction t1 = txManager.createNewTransaction(); Transaction t2 = txManager.createNewTransaction(); t1.getTimestamp(); t2.getTimestamp(); t1.put(TABLE, ImmutableMap.of(cell, new byte[1])); t1.commit(); keyValueService.addGarbageCollectionSentinelValues(TABLE, ImmutableSet.of(cell)); assertThatExceptionOfType(TransactionFailedRetriableException.class) .isThrownBy(() -> t2.get(TABLE, ImmutableSet.of(cell))) .withMessageContaining("Tried to read a value that has been deleted."); }
overrideConflictHandlerForTable(TABLE, ConflictHandler.RETRY_ON_VALUE_CHANGED); final Cell cell = Cell.create(PtBytes.toBytes("row1"), PtBytes.toBytes("column1")); Transaction t1 = txManager.createNewTransaction(); Transaction t2 = txManager.createNewTransaction(); t1.delete(TABLE, ImmutableSet.of(cell)); t2.put(TABLE, ImmutableMap.of(cell, new byte[1])); t1 = txManager.createNewTransaction(); t2 = txManager.createNewTransaction(); t1.delete(TABLE, ImmutableSet.of(cell)); t2.put(TABLE, ImmutableMap.of(cell, new byte[1])); t1 = txManager.createNewTransaction(); t2 = txManager.createNewTransaction(); t2.delete(TABLE, ImmutableSet.of(cell)); t1.put(TABLE, ImmutableMap.of(cell, new byte[1])); t1 = txManager.createNewTransaction(); t2 = txManager.createNewTransaction(); t2.delete(TABLE, ImmutableSet.of(cell)); t1.put(TABLE, ImmutableMap.of(cell, new byte[1]));
@Test public void writesAddedToSweepQueueOnNoConflict() { WriteReference firstWrite = WriteReference.write(TABLE_CONS, TEST_CELL); WriteReference secondWrite = WriteReference.write(TABLE_THOR, TEST_CELL); Transaction t1 = txManager.createNewTransaction(); Transaction t2 = txManager.createNewTransaction(); put(t1, firstWrite); put(t2, secondWrite); t1.commit(); assertThat(getEnqueuedWritesNumber(1)).containsExactly(WriteInfo.of(firstWrite, t1.getTimestamp())); assertLatestEntryForCellInKvsAtTimestamp(TABLE_CONS, TEST_CELL, t1.getTimestamp()); t2.commit(); assertThat(getEnqueuedWritesNumber(2)).containsExactly(WriteInfo.of(secondWrite, t2.getTimestamp())); assertLatestEntryForCellInKvsAtTimestamp(TABLE_THOR, TEST_CELL, t2.getTimestamp()); verify(sweepQueue, times(2)).enqueue(anyList()); }
Transaction transaction = unstableTransactionManager.createNewTransaction(); BatchingVisitable<RowResult<byte[]>> results = transaction.getRange(tableRef, RangeRequest.builder().build()); Transaction verifyTransaction = txManager.createNewTransaction(); BatchingVisitable<RowResult<byte[]>> results = verifyTransaction.getRange(tableRef, RangeRequest.builder().build());
@Override public Transaction createNewTransaction() { return wrap(delegate.createNewTransaction()); }