belliottsmith commented on code in PR #50:
URL: https://github.com/apache/cassandra-accord/pull/50#discussion_r1284873662
##########
accord-core/src/main/java/accord/local/CommandStores.java:
##########
@@ -474,40 +474,42 @@ public <O> void mapReduceConsume(PreLoadContext context,
IntStream commandStore
public <O> AsyncChain<O> mapReduce(PreLoadContext context, Routables<?>
keys, long minEpoch, long maxEpoch, MapReduce<? super SafeCommandStore, O>
mapReduce)
{
- AsyncChain<O> chain = null;
BiFunction<O, O, O> reducer = mapReduce::reduce;
Snapshot snapshot = current;
ShardHolder[] shards = snapshot.shards;
+ List<AsyncChain<? extends O>> chains = null;
Review Comment:
why?
##########
accord-core/src/main/java/accord/local/CommandStores.java:
##########
@@ -474,40 +474,42 @@ public <O> void mapReduceConsume(PreLoadContext context,
IntStream commandStore
public <O> AsyncChain<O> mapReduce(PreLoadContext context, Routables<?>
keys, long minEpoch, long maxEpoch, MapReduce<? super SafeCommandStore, O>
mapReduce)
{
- AsyncChain<O> chain = null;
BiFunction<O, O, O> reducer = mapReduce::reduce;
Snapshot snapshot = current;
ShardHolder[] shards = snapshot.shards;
+ List<AsyncChain<? extends O>> chains = null;
for (ShardHolder shard : shards)
{
// TODO (urgent, efficiency): range map for intersecting ranges
(e.g. that to be introduced for range dependencies)
Ranges shardRanges = shard.ranges().allBetween(minEpoch, maxEpoch);
if (!shardRanges.intersects(keys))
continue;
- AsyncChain<O> next = shard.store.submit(context, mapReduce);
- chain = chain != null ? AsyncChains.reduce(chain, next, reducer) :
next;
+ if (chains == null)
+ chains = new ArrayList<>();
+ chains.add(shard.store.submit(context, mapReduce));
}
- if (chain == null)
- return AsyncChains.success(null);
- return chain;
+ return chains == null ?
+ AsyncChains.success(null) :
+ AsyncChains.reduce(chains, reducer);
}
protected <O> AsyncChain<O> mapReduce(PreLoadContext context, IntStream
commandStoreIds, MapReduce<? super SafeCommandStore, O> mapReduce)
{
// TODO (low priority, efficiency): avoid using an array, or use a
scratch buffer
int[] ids = commandStoreIds.toArray();
- AsyncChain<O> chain = null;
+ List<AsyncChain<? extends O>> chains = null;
Review Comment:
?
##########
accord-core/src/main/java/accord/local/CommandStores.java:
##########
@@ -519,17 +521,18 @@ public <O> void mapReduceConsume(PreLoadContext context,
MapReduceConsume<? supe
protected <O> AsyncChain<O> mapReduce(PreLoadContext context, MapReduce<?
super SafeCommandStore, O> mapReduce)
{
// TODO (low priority, efficiency): avoid using an array, or use a
scratch buffer
- AsyncChain<O> chain = null;
+ List<AsyncChain<? extends O>> chains = null;
Review Comment:
?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]