use of io.pravega.segmentstore.contracts.tables.TableKey in project pravega by pravega.
the class TableServiceTests method executeOffsetConditonalRemovals.
private void executeOffsetConditonalRemovals(HashMap<String, ArrayList<TableKey>> removals, long tableSegmentOffset, TableStore tableStore) throws Exception {
val updateResult = removals.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> tableStore.remove(e.getKey(), e.getValue(), tableSegmentOffset, TIMEOUT)));
Futures.allOf(updateResult.values()).get(TIMEOUT.toMillis(), TimeUnit.MILLISECONDS);
}
use of io.pravega.segmentstore.contracts.tables.TableKey in project pravega by pravega.
the class TableServiceTests method executeRemovals.
private void executeRemovals(HashMap<String, ArrayList<TableKey>> removals, TableStore tableStore) throws Exception {
val updateResult = removals.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> tableStore.remove(e.getKey(), e.getValue(), TIMEOUT)));
Futures.allOf(updateResult.values()).get(TIMEOUT.toMillis(), TimeUnit.MILLISECONDS);
}
use of io.pravega.segmentstore.contracts.tables.TableKey in project pravega by pravega.
the class SegmentStoreAdapter method removeTableEntry.
@Override
public CompletableFuture<Void> removeTableEntry(String tableName, BufferView key, Long compareVersion, Duration timeout) {
ensureRunning();
TableKey e = compareVersion == null || compareVersion == TableKey.NO_VERSION ? TableKey.unversioned(key) : TableKey.versioned(key, compareVersion);
return this.tableStore.remove(tableName, Collections.singletonList(e), timeout);
}
use of io.pravega.segmentstore.contracts.tables.TableKey in project pravega by pravega.
the class TableBasedMetadataStore method writeAll.
/**
* Writes transaction data from a given list to the metadata store.
*
* @param dataList List of transaction data to write.
*/
@Override
protected CompletableFuture<Void> writeAll(Collection<TransactionData> dataList) {
val toUpdate = new ArrayList<TableEntry>();
val entryToTxnDataMap = new HashMap<TableEntry, TransactionData>();
val deletedKeyToTxnDataMap = new HashMap<TableKey, TransactionData>();
val keysToDelete = new ArrayList<TableKey>();
val t = new Timer();
return ensureInitialized().thenRunAsync(() -> {
for (TransactionData txnData : dataList) {
Preconditions.checkState(null != txnData.getDbObject(), "Missing tracking object");
val version = (Long) txnData.getDbObject();
if (null == txnData.getValue()) {
val toDelete = TableKey.unversioned(new ByteArraySegment(txnData.getKey().getBytes(Charsets.UTF_8)));
keysToDelete.add(toDelete);
deletedKeyToTxnDataMap.put(toDelete, txnData);
}
try {
val arraySegment = SERIALIZER.serialize(txnData);
TableEntry tableEntry = TableEntry.versioned(new ByteArraySegment(txnData.getKey().getBytes(Charsets.UTF_8)), arraySegment, version);
entryToTxnDataMap.put(tableEntry, txnData);
toUpdate.add(tableEntry);
} catch (Exception e) {
throw new CompletionException(handleException(e));
}
}
}, getExecutor()).thenComposeAsync(v -> {
// toUpdate includes both modified keys as well updates to deleted keys to mark them as deleted.
return this.tableStore.put(tableName, toUpdate, timeout).thenComposeAsync(ret -> {
// Update versions.
int i = 0;
for (TableEntry tableEntry : toUpdate) {
entryToTxnDataMap.get(tableEntry).setDbObject(ret.get(i));
i++;
}
// This next step will just remove them from table store.
return this.tableStore.remove(tableName, keysToDelete, timeout).handleAsync((v1, ex) -> {
// keys are already persisted successfully in earlier step.
if (ex == null) {
deletedKeyToTxnDataMap.values().stream().forEach(txnData -> txnData.setDbObject(TableKey.NOT_EXISTS));
} else {
log.warn("Error while deleting keys from table segment {}.", tableName, ex);
}
TABLE_WRITE_LATENCY.reportSuccessEvent(t.getElapsed());
return v1;
}, getExecutor());
}, getExecutor());
}, getExecutor()).exceptionally(e -> {
val ex = Exceptions.unwrap(e);
throw new CompletionException(handleException(ex));
});
}
use of io.pravega.segmentstore.contracts.tables.TableKey in project pravega by pravega.
the class PravegaRequestProcessor method removeTableKeys.
@Override
public void removeTableKeys(final WireCommands.RemoveTableKeys removeTableKeys) {
String segment = removeTableKeys.getSegment();
final String operation = "removeTableKeys";
if (!verifyToken(segment, removeTableKeys.getRequestId(), removeTableKeys.getDelegationToken(), operation)) {
removeTableKeys.release();
return;
}
log.debug(removeTableKeys.getRequestId(), "Remove Table Segment Keys: Segment={}, Offset={}, Count={}.", removeTableKeys.getSegment(), removeTableKeys.getTableSegmentOffset(), removeTableKeys.getKeys().size());
val keys = new ArrayList<TableKey>(removeTableKeys.getKeys().size());
val conditional = new AtomicBoolean(false);
val size = new AtomicInteger(0);
for (val k : removeTableKeys.getKeys()) {
val v = TableKey.versioned(new ByteBufWrapper(k.getData()), k.getKeyVersion());
keys.add(v);
size.addAndGet(v.getKey().getLength());
if (v.hasVersion()) {
conditional.set(true);
}
}
val timer = new Timer();
this.connection.adjustOutstandingBytes(size.get());
tableStore.remove(segment, keys, removeTableKeys.getTableSegmentOffset(), TIMEOUT).thenRun(() -> {
connection.send(new WireCommands.TableKeysRemoved(removeTableKeys.getRequestId(), segment));
this.tableStatsRecorder.removeKeys(removeTableKeys.getSegment(), keys.size(), conditional.get(), timer.getElapsed());
}).exceptionally(e -> handleException(removeTableKeys.getRequestId(), segment, removeTableKeys.getTableSegmentOffset(), operation, e)).whenComplete((r, ex) -> {
this.connection.adjustOutstandingBytes(-size.get());
removeTableKeys.release();
});
}
Aggregations