@Override public void checkAndSet(CheckAndSetRequest request) { tablesWrittenTo.add(request.table()); super.checkAndSet(request); }
@Override public void checkAndSet(CheckAndSetRequest checkAndSetRequest) { getDelegate(checkAndSetRequest.table()).checkAndSet(checkAndSetRequest); }
private void executePutUnlessExists(CheckAndSetRequest checkAndSetRequest) { try { Map<Cell, byte[]> value = ImmutableMap.of(checkAndSetRequest.cell(), checkAndSetRequest.newValue()); putUnlessExists(checkAndSetRequest.table(), value); } catch (KeyAlreadyExistsException e) { throw new CheckAndSetException("Value unexpectedly present when running check and set", e); } }
private void executeCheckAndSet(CheckAndSetRequest request) { Preconditions.checkArgument(request.oldValue().isPresent()); runWrite(request.table(), table -> { //noinspection OptionalGetWithoutIsPresent table.update(request.cell(), AtlasDbConstants.TRANSACTION_TS, request.oldValue().get(), request.newValue()); return null; }); }
@Override public void checkAndSet(CheckAndSetRequest checkAndSetRequest) throws CheckAndSetException { //noinspection unused - try-with-resources closes trace try (CloseableTrace trace = startLocalTrace("checkAndSet({})", LoggingArgs.safeTableOrPlaceholder(checkAndSetRequest.table()))) { delegate().checkAndSet(checkAndSetRequest); } }
@Override public void checkAndSet(CheckAndSetRequest request) { maybeLog(() -> delegate.checkAndSet(request), logCellsAndSize("checkAndSet", request.table(), 1, request.newValue().length)); }
@Override public void checkAndSet(CheckAndSetRequest request) { TableStats s = timeOperation(request.table(), () -> super.checkAndSet(request)); // Only update stats after put was successful. s.totalPutCells.incrementAndGet(); // can only CAS one value incrementPutBytes(s, request.cell(), request.newValue()); }
@Override public void checkAndSet(CheckAndSetRequest checkAndSetRequest) { try { CheckAndSetRequest request = new CheckAndSetRequest.Builder() .from(checkAndSetRequest) .table(tableMapper.getMappedTableName(checkAndSetRequest.table())) .build(); delegate().checkAndSet(request); } catch (TableMappingNotFoundException e) { throw new IllegalArgumentException(e); } }
request.table(), request.oldValue().orElse(null), currentValues);
public CheckAndSetResult<ByteString> executeCheckAndSet(CassandraClient client, CheckAndSetRequest request) throws TException { try { TableReference table = request.table(); CqlResult result = queryRunner.run( client, table, () -> client.execute_cql3_query( CheckAndSetQueries.getQueryForRequest(request), Compression.NONE, writeConsistency)); return CheckAndSetResponseDecoder.decodeCqlResult(result); } catch (UnavailableException e) { throw new InsufficientConsistencyException( "Check-and-set requires " + writeConsistency + " Cassandra nodes to be up and available.", e); } } }
@Override public void checkAndSet(CheckAndSetRequest request) throws CheckAndSetException { TableReference tableRef = request.table(); Table table = getTableMap(tableRef); Cell cell = request.cell(); Optional<byte[]> oldValue = request.oldValue(); byte[] contents = request.newValue(); Key key = getKey(table, cell, AtlasDbConstants.TRANSACTION_TS); if (oldValue.isPresent()) { byte[] storedValue = table.entries.get(key); boolean succeeded = Arrays.equals(storedValue, oldValue.get()) && table.entries.replace(key, storedValue, copyOf(contents)); if (!succeeded) { byte[] actual = table.entries.get(key); // Re-fetch, something may have happened between get and replace throwCheckAndSetException(cell, tableRef, oldValue.get(), actual); } } else { byte[] oldContents = putIfAbsent(table, key, contents); if (oldContents != null) { throwCheckAndSetException(cell, tableRef, null, oldContents); } } }
private static CqlQuery updateIfMatching(CheckAndSetRequest request) { Preconditions.checkState(request.oldValue().isPresent(), "updateIfMatching queries should only be made if we do have an old value"); return ImmutableCqlQuery.builder() .safeQueryFormat("UPDATE \"%s\" SET value=%s WHERE key=%s AND column1=%s AND column2=%s IF value=%s;") .addArgs( LoggingArgs.internalTableName(request.table()), UnsafeArg.of("newValue", encodeCassandraHexString(request.newValue())), UnsafeArg.of("row", encodeCassandraHexString(request.cell().getRowName())), UnsafeArg.of("column", encodeCassandraHexString(request.cell().getColumnName())), SafeArg.of("cassandraTimestamp", CASSANDRA_TIMESTAMP), UnsafeArg.of("oldValue", encodeCassandraHexString(request.oldValue().get()))) .build(); }
private static CqlQuery insertIfNotExists(CheckAndSetRequest request) { Preconditions.checkState(!request.oldValue().isPresent(), "insertIfNotExists queries should only be made if we don't have an old value"); return ImmutableCqlQuery.builder() .safeQueryFormat("INSERT INTO \"%s\" (key, column1, column2, value)" + " VALUES (%s, %s, %s, %s) IF NOT EXISTS;") .addArgs( LoggingArgs.internalTableName(request.table()), UnsafeArg.of("row", encodeCassandraHexString(request.cell().getRowName())), UnsafeArg.of("column", encodeCassandraHexString(request.cell().getColumnName())), SafeArg.of("cassandraTimestamp", CASSANDRA_TIMESTAMP), UnsafeArg.of("newValue", encodeCassandraHexString(request.newValue()))) .build(); }
@Override public void checkAndSet(CheckAndSetRequest request) { tablesWrittenTo.add(request.table()); super.checkAndSet(request); }
@Override public void checkAndSet(CheckAndSetRequest checkAndSetRequest) { getDelegate(checkAndSetRequest.table()).checkAndSet(checkAndSetRequest); }
private void executePutUnlessExists(CheckAndSetRequest checkAndSetRequest) { try { Map<Cell, byte[]> value = ImmutableMap.of(checkAndSetRequest.cell(), checkAndSetRequest.newValue()); putUnlessExists(checkAndSetRequest.table(), value); } catch (KeyAlreadyExistsException e) { throw new CheckAndSetException("Value unexpectedly present when running check and set", e); } }
@Override public void checkAndSet(CheckAndSetRequest request) { TableStats s = timeOperation(request.table(), () -> super.checkAndSet(request)); // Only update stats after put was successful. s.totalPutCells.incrementAndGet(); // can only CAS one value incrementPutBytes(s, request.cell(), request.newValue()); }
@Override public void checkAndSet(CheckAndSetRequest request) { maybeLog(() -> delegate.checkAndSet(request), logCellsAndSize("checkAndSet", request.table(), 1, request.newValue().length)); }
@Override public void checkAndSet(CheckAndSetRequest checkAndSetRequest) throws CheckAndSetException { //noinspection unused - try-with-resources closes trace try (CloseableTrace trace = startLocalTrace("checkAndSet({})", LoggingArgs.safeTableOrPlaceholder(checkAndSetRequest.table()))) { delegate().checkAndSet(checkAndSetRequest); } }
@Override public void checkAndSet(CheckAndSetRequest checkAndSetRequest) { try { CheckAndSetRequest request = new CheckAndSetRequest.Builder() .from(checkAndSetRequest) .table(tableMapper.getMappedTableName(checkAndSetRequest.table())) .build(); delegate().checkAndSet(request); } catch (TableMappingNotFoundException e) { throw new IllegalArgumentException(e); } }