use of org.apache.ignite.internal.schema.BinaryRow in project ignite-3 by apache.
the class InternalTableImpl method enlistInTx.
/**
* Enlists multiple rows into a transaction.
*
* @param keyRows Rows.
* @param tx The transaction.
* @param op Command factory.
* @param reducer The reducer.
* @param <R> Reducer's input.
* @param <T> Reducer's output.
* @return The future.
*/
private <R, T> CompletableFuture<T> enlistInTx(Collection<BinaryRow> keyRows, InternalTransaction tx, BiFunction<Collection<BinaryRow>, InternalTransaction, Command> op, Function<CompletableFuture<R>[], CompletableFuture<T>> reducer) {
final boolean implicit = tx == null;
final InternalTransaction tx0 = implicit ? txManager.begin() : tx;
Int2ObjectOpenHashMap<List<BinaryRow>> keyRowsByPartition = mapRowsToPartitions(keyRows);
CompletableFuture<R>[] futures = new CompletableFuture[keyRowsByPartition.size()];
int batchNum = 0;
for (Int2ObjectOpenHashMap.Entry<List<BinaryRow>> partToRows : keyRowsByPartition.int2ObjectEntrySet()) {
CompletableFuture<RaftGroupService> fut = enlist(partToRows.getIntKey(), tx0);
futures[batchNum++] = fut.thenCompose(svc -> svc.run(op.apply(partToRows.getValue(), tx0)));
}
CompletableFuture<T> fut = reducer.apply(futures);
return postEnlist(fut, implicit, tx0);
}
use of org.apache.ignite.internal.schema.BinaryRow in project ignite-3 by apache.
the class InternalTableImpl method collectMultiRowsResponses.
/**
* TODO asch keep the same order as for keys Collects multirow responses from multiple futures into a single collection IGNITE-16004.
*
* @param futs Futures.
* @return Row collection.
*/
private CompletableFuture<Collection<BinaryRow>> collectMultiRowsResponses(CompletableFuture<?>[] futs) {
return CompletableFuture.allOf(futs).thenApply(response -> {
List<BinaryRow> list = new ArrayList<>(futs.length);
for (CompletableFuture<?> future : futs) {
MultiRowsResponse ret = (MultiRowsResponse) future.join();
List<BinaryRow> values = ret.getValues();
if (values != null) {
list.addAll(values);
}
}
return list;
});
}
use of org.apache.ignite.internal.schema.BinaryRow in project ignite-3 by apache.
the class VersionedRowStore method resolve.
/**
* Resolves a multi-versioned value depending on a viewer's timestamp.
*
* @param val The value.
* @param timestamp The timestamp
* @return New and old rows pair.
* @see #versionedRow
*/
private Pair<BinaryRow, BinaryRow> resolve(Value val, Timestamp timestamp) {
if (val.timestamp == null) {
// New or after reset.
assert val.oldRow == null : val;
return new Pair<>(val.newRow, null);
}
// Checks "inTx" condition. Will be false if this is a first transactional op.
if (val.timestamp.equals(timestamp)) {
return new Pair<>(val.newRow, val.oldRow);
}
TxState state = txManager.state(val.timestamp);
BinaryRow cur;
if (state == TxState.ABORTED) {
// Was aborted and had written a temp value.
cur = val.oldRow;
} else {
cur = val.newRow;
}
return new Pair<>(cur, cur);
}
use of org.apache.ignite.internal.schema.BinaryRow in project ignite-3 by apache.
the class VersionedRowStore method getAndUpsert.
/**
* Upserts a row and returns previous value.
*
* @param row The row.
* @param ts The timestamp.
* @return Previous row.
*/
@Nullable
public BinaryRow getAndUpsert(@NotNull BinaryRow row, Timestamp ts) {
assert row != null;
BinaryRow oldRow = get(row, ts);
upsert(row, ts);
return oldRow != null ? oldRow : null;
}
use of org.apache.ignite.internal.schema.BinaryRow in project ignite-3 by apache.
the class KeyValueViewImpl method unmarshalKeys.
/**
* Marshal keys.
*
* @param rows Binary rows.
* @return Keys.
*/
@NotNull
public Collection<K> unmarshalKeys(Collection<BinaryRow> rows) {
if (rows.isEmpty()) {
return Collections.emptyList();
}
final KvMarshaller<K, V> marsh = marshaller(schemaReg.lastSchemaVersion());
List<K> keys = new ArrayList<>(rows.size());
try {
for (Row row : schemaReg.resolve(rows)) {
if (row != null) {
keys.add(marsh.unmarshalKey(row));
}
}
return keys;
} catch (MarshallerException e) {
throw new IgniteException(e);
}
}
Aggregations