@Override public void putUnlessExists(TableReference tableRef, Map<Cell, byte[]> values) throws KeyAlreadyExistsException { delegate1.putUnlessExists(tableRef, values); }
@Override public void putUnlessExists(TableReference tableRef, Map<Cell, byte[]> values) throws KeyAlreadyExistsException { if (values.isEmpty()) { return; } delegate.putUnlessExists(tableRef, values); }
@Test public void testPrimaryKeyViolation() { Cell cell = Cell.create("r1".getBytes(), TransactionConstants.COMMIT_TS_COLUMN); keyValueService.putUnlessExists(TransactionConstants.TRANSACTION_TABLE, ImmutableMap.of(cell, "v1".getBytes())); assertThatThrownBy(() -> keyValueService.putUnlessExists(TransactionConstants.TRANSACTION_TABLE, ImmutableMap.of(cell, "v2".getBytes()))) .isInstanceOf(KeyAlreadyExistsException.class); }
@Override public void putUnlessExists(TableReference tableRef, Map<Cell, byte[]> values) throws KeyAlreadyExistsException { getDelegate(tableRef).putUnlessExists(tableRef, values); }
@Override public void putUnlessExists(TableReference tableRef, Map<Cell, byte[]> values) throws KeyAlreadyExistsException { delegate().putUnlessExists(tableRef, values); }
@Override public void putUnlessExists(TableReference tableRef, Map<Cell, byte[]> values) throws KeyAlreadyExistsException { try { delegate().putUnlessExists(tableMapper.getMappedTableName(tableRef), values); } catch (TableMappingNotFoundException e) { throw new IllegalArgumentException(e); } }
@Override protected void performOneCall() { byte[] data = RandomBytes.ofLength(16); keyValueService.putUnlessExists( BenchmarksSchema.BLOBS_TABLE_REF, ImmutableMap.of(Cell.create(data, data), data)); } }
public void putUnlessExists(long startTimestamp, long commitTimestamp) throws KeyAlreadyExistsException { Cell key = getTransactionCell(startTimestamp); byte[] value = TransactionConstants.getValueForTimestamp(commitTimestamp); keyValueService.putUnlessExists(TransactionConstants.TRANSACTION_TABLE, ImmutableMap.of(key, value)); }
@Override public void putUnlessExists(long startTimestamp, long commitTimestamp) { Cell key = getTransactionCell(startTimestamp); byte[] value = TransactionConstants .getValueForTimestamp(commitTimestamp); keyValueService.putUnlessExists(TransactionConstants.TRANSACTION_TABLE, ImmutableMap.of(key, value)); }
@Override public void putUnlessExists(TableReference tableRef, Map<Cell, byte[]> values) throws KeyAlreadyExistsException { maybeLog(() -> delegate.putUnlessExists(tableRef, values), logCellsAndSize("putUnlessExists", tableRef, values.keySet().size(), byteSize(values))); }
@Override public void putUnlessExists(TableReference tableRef, Map<Cell, byte[]> values) throws KeyAlreadyExistsException { //noinspection unused - try-with-resources closes trace try (CloseableTrace trace = startLocalTrace("putUnlessExists({}, {} values)", LoggingArgs.safeTableOrPlaceholder(tableRef), values.size())) { delegate().putUnlessExists(tableRef, values); } }
private void commit(long timestamp) { Cell cell = Cell.create( TransactionConstants.getValueForTimestamp(timestamp), TransactionConstants.COMMIT_TS_COLUMN); byte[] value = TransactionConstants.getValueForTimestamp(timestamp); delegate().putUnlessExists(TransactionConstants.TRANSACTION_TABLE, ImmutableMap.of(cell, value)); } }
@VisibleForTesting void putUnlessValueExists(long sequenceNumber, T value) { Preconditions.checkState( sequenceNumber > 0, "Only positive sequence numbers are supported, but found %s", sequenceNumber); try { kvs.putUnlessExists(AtlasDbConstants.COORDINATION_TABLE, ImmutableMap.of(getCellForSequence(sequenceNumber), serializeValue(value))); } catch (KeyAlreadyExistsException e) { throw new SafeIllegalStateException("The coordination store failed a putUnlessExists. This is unexpected" + " as it implies timestamps may have been reused, or a writer to the store behaved badly." + " The offending sequence number was {}. " + " Please contact support - DO NOT ATTEMPT TO FIX THIS YOURSELF.", e, SafeArg.of("sequenceNumber", sequenceNumber)); } }
@Test public void putUnlessExistsLargeValue() { Assume.assumeTrue(checkAndSetSupported()); byte[] megabyteValue = new byte[1048576]; keyValueService.putUnlessExists(TEST_TABLE, ImmutableMap.of(TEST_CELL, megabyteValue)); Value storedValue = keyValueService.get(TEST_TABLE, ImmutableMap.of(TEST_CELL, Long.MAX_VALUE)).get(TEST_CELL); assertArrayEquals(megabyteValue, storedValue.getContents()); }
@Test public void putUnlessExists() throws Exception { Map<Cell, byte[]> values = ImmutableMap.of(CELL, VALUE_BYTES); kvs.putUnlessExists(TABLE_REF, values); checkSpan("atlasdb-kvs.putUnlessExists({table}, 1 values)"); verify(delegate).putUnlessExists(TABLE_REF, values); verifyNoMoreInteractions(delegate); }
@Override public TableReference addTable(TableReference tableRef) { if (tableRef.getNamespace().isEmptyNamespace()) { return tableRef; } if (tableMap.get().containsKey(tableRef)) { return tableMap.get().get(tableRef); } Cell key = Cell.create(getBytesForTableRef(tableRef), AtlasDbConstants.NAMESPACE_SHORT_COLUMN_BYTES); String shortName = AtlasDbConstants.NAMESPACE_PREFIX + Preconditions.checkNotNull(uniqueLongSupplier.get(), "uniqueLongSupplier returned null"); byte[] value = PtBytes.toBytes(shortName); try { kv.putUnlessExists(AtlasDbConstants.NAMESPACE_TABLE, ImmutableMap.of(key, value)); } catch (KeyAlreadyExistsException e) { return getAlreadyExistingMappedTableName(tableRef); } return TableReference.createWithEmptyNamespace(shortName); }
@Test public void putUnlessExistsDoesNotConflictForMultipleCellsSameColumn() { Assume.assumeTrue(checkAndSetSupported()); Cell firstTestCell = Cell.create(row(0), column(0)); Cell nextTestCell = Cell.create(row(1), column(0)); keyValueService.putUnlessExists(TEST_TABLE, ImmutableMap.of(firstTestCell, val(0, 0))); keyValueService.putUnlessExists(TEST_TABLE, ImmutableMap.of(nextTestCell, val(0, 1))); // Legal as the cells are different }
@Test public void putUnlessExistsDoesNotConflictForMultipleCellsSameRow() { Assume.assumeTrue(checkAndSetSupported()); Cell firstTestCell = Cell.create(row(0), column(0)); Cell nextTestCell = Cell.create(row(0), column(1)); keyValueService.putUnlessExists(TEST_TABLE, ImmutableMap.of(firstTestCell, val(0, 0))); keyValueService.putUnlessExists(TEST_TABLE, ImmutableMap.of(nextTestCell, val(0, 1))); // Legal as the cells are different }
@Benchmark @Threads(1) @Warmup(time = 2, timeUnit = TimeUnit.SECONDS) @Measurement(time = 20, timeUnit = TimeUnit.SECONDS) public Map<Cell, byte[]> putUnlessExistsAndExists(EmptyTables tables) { Map<Cell, byte[]> batch = tables.generateBatchToInsert(1); tables.getKvs().putUnlessExists(tables.getFirstTableRef(), batch); try { tables.getKvs().putUnlessExists(tables.getFirstTableRef(), batch); Preconditions.checkArgument(false, "putUnlessExists should have failed"); } catch (KeyAlreadyExistsException e) { // success } return batch; }
@Benchmark @Threads(1) @Warmup(time = 1, timeUnit = TimeUnit.SECONDS) @Measurement(time = 10, timeUnit = TimeUnit.SECONDS) public Map<Cell, byte[]> putUnlessExistsDoesNotExist(EmptyTables tables) { Map<Cell, byte[]> batch = tables.generateBatchToInsert(1); tables.getKvs().putUnlessExists(tables.getFirstTableRef(), batch); return batch; }