use of io.pravega.client.tables.impl.TableSegmentKeyVersion in project pravega by pravega.
the class PravegaTablesStoreHelper method updateEntry.
/**
* Method to update a single entry.
* @param tableName tablename
* @param key key
* @param toBytes to bytes function
* @param val value
* @param ver previous key version
* @param <T> Type of value to be added
* @param requestId request id
* @return CompletableFuture which when completed will indicate that the value is updated in the table.
*/
public <T> CompletableFuture<Version> updateEntry(String tableName, String key, T val, Function<T, byte[]> toBytes, Version ver, long requestId) {
long version = ver.asLongVersion().getLongValue();
log.trace(requestId, "updateEntry entry called for : {} key : {} version {}", tableName, key, version);
byte[] value = toBytes.apply(val);
long time = System.currentTimeMillis();
List<TableSegmentEntry> entries = Collections.singletonList(TableSegmentEntry.versioned(key.getBytes(Charsets.UTF_8), value, version));
return withRetries(() -> segmentHelper.updateTableEntries(tableName, entries, authToken.get(), requestId), () -> String.format("updateEntry: key: %s table: %s", key, tableName), true, requestId).thenApplyAsync(x -> {
TableSegmentKeyVersion first = x.get(0);
log.debug(requestId, "entry for key {} updated to table {} with new version {}", key, tableName, first.getSegmentVersion());
Version newVersion = new Version.LongVersion(first.getSegmentVersion());
putInCache(tableName, key, new VersionedMetadata<>(val, newVersion), time);
return newVersion;
}, executor).exceptionally(e -> {
invalidateCache(tableName, key);
throw new CompletionException(e);
}).whenComplete((r, ex) -> releaseEntries(entries));
}
Aggregations