dcapwell commented on code in PR #46:
URL: https://github.com/apache/cassandra-accord/pull/46#discussion_r1199177636


##########
accord-core/src/main/java/accord/impl/CommandTimeseries.java:
##########
@@ -0,0 +1,233 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package accord.impl;
+
+import java.util.List;
+import java.util.NavigableMap;
+import java.util.Objects;
+import java.util.TreeMap;
+import java.util.function.Predicate;
+import java.util.stream.Stream;
+import javax.annotation.Nullable;
+
+import com.google.common.collect.ImmutableSortedMap;
+
+import accord.api.Key;
+import accord.local.Command;
+import accord.local.SafeCommandStore;
+import accord.local.SaveStatus;
+import accord.local.Status;
+import accord.primitives.Seekable;
+import accord.primitives.Timestamp;
+import accord.primitives.TxnId;
+
+import static accord.local.SafeCommandStore.TestDep.ANY_DEPS;
+import static accord.local.SafeCommandStore.TestDep.WITH;
+import static accord.utils.Utils.ensureSortedImmutable;
+import static accord.utils.Utils.ensureSortedMutable;
+
+public class CommandTimeseries<D>
+{
+    public enum TestTimestamp
+    {BEFORE, AFTER}
+
+    private final Seekable keyOrRange;
+    protected final CommandLoader<D> loader;
+    public final ImmutableSortedMap<Timestamp, D> commands;
+    private final boolean ignoreTestKind;
+
+    public CommandTimeseries(Update<D> builder)
+    {
+        this.keyOrRange = builder.keyOrRange;
+        this.loader = builder.loader;
+        this.commands = ensureSortedImmutable(builder.commands);
+        this.ignoreTestKind = builder.ignoreTestKind;
+    }
+
+    CommandTimeseries(Seekable keyOrRange, CommandLoader<D> loader, 
ImmutableSortedMap<Timestamp, D> commands)
+    {
+        this.keyOrRange = keyOrRange;
+        this.loader = loader;
+        this.commands = commands;
+        this.ignoreTestKind = false;
+    }
+
+    public CommandTimeseries(Key keyOrRange, CommandLoader<D> loader)
+    {
+        this(keyOrRange, loader, ImmutableSortedMap.of());
+    }
+
+    @Override
+    public boolean equals(Object o)
+    {
+        if (this == o) return true;
+        if (o == null || getClass() != o.getClass()) return false;
+        CommandTimeseries<?> that = (CommandTimeseries<?>) o;
+        return keyOrRange.equals(that.keyOrRange) && 
loader.equals(that.loader) && commands.equals(that.commands);
+    }
+
+    @Override
+    public int hashCode()
+    {
+        int hash = 1;
+        hash = 31 * hash + Objects.hashCode(keyOrRange);
+        hash = 31 * hash + Objects.hashCode(loader);
+        hash = 31 * hash + Objects.hashCode(commands);
+        return hash;
+    }
+
+    public D get(Timestamp key)
+    {
+        return commands.get(key);
+    }
+
+    public boolean isEmpty()
+    {
+        return commands.isEmpty();
+    }
+
+    /**
+     * All commands before/after (exclusive of) the given timestamp
+     * <p>
+     * Note that {@code testDep} applies only to commands that know at least 
proposed deps; if specified any
+     * commands that do not know any deps will be ignored.
+     * <p>
+     * TODO (expected, efficiency): TestDep should be asynchronous; data 
should not be kept memory-resident as only used for recovery
+     */
+    public <T> T mapReduce(SafeCommandStore.TestKind testKind, TestTimestamp 
testTimestamp, Timestamp timestamp,
+                           SafeCommandStore.TestDep testDep, @Nullable TxnId 
depId,
+                           @Nullable Status minStatus, @Nullable Status 
maxStatus,
+                           SafeCommandStore.CommandFunction<T, T> map, T 
initialValue, T terminalValue)
+    {
+
+        for (D data : (testTimestamp == TestTimestamp.BEFORE ? 
commands.headMap(timestamp, false) : commands.tailMap(timestamp, 
false)).values())
+        {
+            TxnId txnId = loader.txnId(data);

Review Comment:
   I changed the ordering of this method due to cost to deserialize for 
`CommandsForKeys`, idea was to only deserialize what is needed and avoid 
touching deps until needed



-- 
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]

Reply via email to