This is an automated email from the ASF dual-hosted git repository. aleksey pushed a commit to branch trunk in repository https://gitbox.apache.org/repos/asf/cassandra-accord.git
The following commit(s) were added to refs/heads/trunk by this push: new da77b74 Swap long for int inside Node.Id da77b74 is described below commit da77b744e4fdb5f39656e4269f4f1806e485c9c0 Author: Aleksey Yeschenko <alek...@apache.org> AuthorDate: Tue Jan 31 16:02:37 2023 +0000 Swap long for int inside Node.Id patch by Aleksey Yeschenko; reviewed by Benedict Elliott Smith for CASSANDRA-18135 --- accord-core/build.gradle | 2 +- .../src/main/java/accord/local/CommandStores.java | 8 ++++---- accord-core/src/main/java/accord/local/Node.java | 14 ++++++-------- accord-core/src/main/java/accord/local/Status.java | 3 ++- accord-core/src/main/java/accord/messages/Defer.java | 4 ++-- .../src/main/java/accord/utils/ArrayBuffers.java | 2 +- .../verify/StrictSerializabilityVerifierTest.java | 19 +++---------------- .../src/main/java/accord/maelstrom/Json.java | 4 ++-- 8 files changed, 21 insertions(+), 35 deletions(-) diff --git a/accord-core/build.gradle b/accord-core/build.gradle index 146f9fa..32e1164 100644 --- a/accord-core/build.gradle +++ b/accord-core/build.gradle @@ -36,7 +36,7 @@ dependencies { // Dependencies we depend on that are not part of our API. // These act as runtimeOnly dependencies to users implementation 'org.slf4j:slf4j-api:1.7.36' - implementation 'com.carrotsearch:hppc:0.8.1' + implementation 'org.agrona:agrona:1.17.1' } task burn(type: JavaExec) { diff --git a/accord-core/src/main/java/accord/local/CommandStores.java b/accord-core/src/main/java/accord/local/CommandStores.java index 09ad0fc..467e23e 100644 --- a/accord-core/src/main/java/accord/local/CommandStores.java +++ b/accord-core/src/main/java/accord/local/CommandStores.java @@ -26,9 +26,9 @@ import accord.utils.MapReduce; import accord.utils.MapReduceConsume; import accord.utils.ReducingFuture; -import com.carrotsearch.hppc.IntObjectMap; -import com.carrotsearch.hppc.IntObjectScatterMap; import com.google.common.annotations.VisibleForTesting; +import org.agrona.collections.Hashing; +import org.agrona.collections.Int2ObjectHashMap; import org.apache.cassandra.utils.concurrent.Future; import java.util.ArrayList; @@ -200,14 +200,14 @@ public abstract class CommandStores<S extends CommandStore> static class Snapshot { final ShardHolder[] shards; - final IntObjectMap<CommandStore> byId; + final Int2ObjectHashMap<CommandStore> byId; final Topology local; final Topology global; Snapshot(ShardHolder[] shards, Topology local, Topology global) { this.shards = shards; - this.byId = new IntObjectScatterMap<>(shards.length); + this.byId = new Int2ObjectHashMap<>(shards.length, Hashing.DEFAULT_LOAD_FACTOR, true); for (ShardHolder shard : shards) byId.put(shard.store.id(), shard.store); this.local = local; diff --git a/accord-core/src/main/java/accord/local/Node.java b/accord-core/src/main/java/accord/local/Node.java index 4ccc05c..70be03a 100644 --- a/accord-core/src/main/java/accord/local/Node.java +++ b/accord-core/src/main/java/accord/local/Node.java @@ -57,18 +57,16 @@ import net.nicoulaj.compilecommand.annotations.Inline; import org.apache.cassandra.utils.concurrent.AsyncFuture; import org.apache.cassandra.utils.concurrent.Future; -import static accord.primitives.Routable.Domain.Key; - public class Node implements ConfigurationService.Listener, NodeTimeService { public static class Id implements Comparable<Id> { public static final Id NONE = new Id(0); - public static final Id MAX = new Id(Long.MAX_VALUE); + public static final Id MAX = new Id(Integer.MAX_VALUE); - public final long id; + public final int id; - public Id(long id) + public Id(int id) { this.id = id; } @@ -76,7 +74,7 @@ public class Node implements ConfigurationService.Listener, NodeTimeService @Override public int hashCode() { - return Long.hashCode(id); + return Integer.hashCode(id); } @Override @@ -93,12 +91,12 @@ public class Node implements ConfigurationService.Listener, NodeTimeService @Override public int compareTo(Id that) { - return Long.compare(this.id, that.id); + return Integer.compare(this.id, that.id); } public String toString() { - return Long.toString(id); + return Integer.toString(id); } } diff --git a/accord-core/src/main/java/accord/local/Status.java b/accord-core/src/main/java/accord/local/Status.java index 158bb89..98e9e23 100644 --- a/accord-core/src/main/java/accord/local/Status.java +++ b/accord-core/src/main/java/accord/local/Status.java @@ -51,7 +51,8 @@ public enum Status * So, for execution of other transactions we may treat a PreCommitted transaction as Committed, * using the timestamp to update our dependency set to rule it out as a dependency. * But we do not have enough information to execute the transaction, and when recovery calculates - * {@link BeginRecovery#acceptedStartedBeforeWithoutWitnessing}, {@link BeginRecovery#committedExecutesAfterWithoutWitnessing} + * {@link BeginRecovery#acceptedStartedBeforeWithoutWitnessing}, {@link BeginRecovery#hasCommittedExecutesAfterWithoutWitnessing} + * * and {@link BeginRecovery#committedStartedBeforeAndWitnessed} we may not have the dependencies * to calculate the result. For these operations we treat ourselves as whatever Accepted status * we may have previously taken, using any proposed dependencies to compute the result. diff --git a/accord-core/src/main/java/accord/messages/Defer.java b/accord-core/src/main/java/accord/messages/Defer.java index b7e018e..d28810a 100644 --- a/accord-core/src/main/java/accord/messages/Defer.java +++ b/accord-core/src/main/java/accord/messages/Defer.java @@ -24,7 +24,7 @@ import accord.local.*; import accord.local.Status.Known; import accord.primitives.TxnId; import accord.utils.Invariants; -import com.carrotsearch.hppc.IntHashSet; +import org.agrona.collections.IntHashSet; import static accord.messages.Defer.Ready.Expired; import static accord.messages.Defer.Ready.No; @@ -36,7 +36,7 @@ class Defer implements CommandListener final Function<Command, Ready> waitUntil; final TxnRequest<?> request; - final IntHashSet waitingOn = new IntHashSet(); // TODO (easy): use Agrona when available + final IntHashSet waitingOn = new IntHashSet(); int waitingOnCount; boolean isDone; diff --git a/accord-core/src/main/java/accord/utils/ArrayBuffers.java b/accord-core/src/main/java/accord/utils/ArrayBuffers.java index c021f25..d8261b1 100644 --- a/accord-core/src/main/java/accord/utils/ArrayBuffers.java +++ b/accord-core/src/main/java/accord/utils/ArrayBuffers.java @@ -33,7 +33,7 @@ import static accord.utils.Invariants.checkArgument; * A set of utility classes and interfaces for managing a collection of buffers for arrays of certain types. * * These buffers are designed to be used to combine simple one-shot methods that consume and produce one or more arrays - * with methods that may (or may not) call them repeatedly. Specifically, {@link accord.primitives.Deps#linearUnion}, + * with methods that may (or may not) call them repeatedly. Specifically, {@link accord.utils.RelationMultiMap#linearUnion}, * {@link SortedArrays#linearUnion} and {@link SortedArrays#linearIntersection} * * To support this efficiently and ergonomically for users of the one-shot methods, the cache management must diff --git a/accord-core/src/test/java/accord/verify/StrictSerializabilityVerifierTest.java b/accord-core/src/test/java/accord/verify/StrictSerializabilityVerifierTest.java index c78513f..39e9a4a 100644 --- a/accord-core/src/test/java/accord/verify/StrictSerializabilityVerifierTest.java +++ b/accord-core/src/test/java/accord/verify/StrictSerializabilityVerifierTest.java @@ -26,8 +26,6 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Stream; -import com.carrotsearch.hppc.IntHashSet; -import com.carrotsearch.hppc.IntSet; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -209,7 +207,6 @@ public class StrictSerializabilityVerifierTest private void fromLog(String log) { - IntSet pks = new IntHashSet(); class Read { final int pk, id, count; @@ -283,10 +280,7 @@ public class StrictSerializabilityVerifierTest if (line.startsWith("Witness")) { if (current != null) - { witnesses.add(current); - current = null; - } Matcher matcher = Pattern.compile("Witness\\(start=(.+), end=(.+)\\)").matcher(line); if (!matcher.find()) throw new AssertionError("Unable to match start/end of " + line); current = new Witness(Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2))); @@ -296,7 +290,6 @@ public class StrictSerializabilityVerifierTest Matcher matcher = Pattern.compile("\tread\\(pk=(.+), id=(.+), count=(.+), seq=\\[(.*)\\]\\)").matcher(line); if (!matcher.find()) throw new AssertionError("Unable to match read of " + line); int pk = Integer.parseInt(matcher.group(1)); - pks.add(pk); int id = Integer.parseInt(matcher.group(2)); int count = Integer.parseInt(matcher.group(3)); String seqStr = matcher.group(4); @@ -308,28 +301,22 @@ public class StrictSerializabilityVerifierTest Matcher matcher = Pattern.compile("\twrite\\(pk=(.+), id=(.+), success=(.+)\\)").matcher(line); if (!matcher.find()) throw new AssertionError("Unable to match write of " + line); int pk = Integer.parseInt(matcher.group(1)); - pks.add(pk); int id = Integer.parseInt(matcher.group(2)); boolean success = Boolean.parseBoolean(matcher.group(3)); current.write(pk, id, success); } else { - throw new IllegalArgumentException("Unknow line: " + line); + throw new IllegalArgumentException("Unknown line: " + line); } } + if (current != null) - { witnesses.add(current); - current = null; - } - int[] keys = pks.toArray(); - Arrays.sort(keys); + StrictSerializabilityVerifier validator = new StrictSerializabilityVerifier(3); for (Witness w : witnesses) - { w.process(validator); - } } @Test diff --git a/accord-maelstrom/src/main/java/accord/maelstrom/Json.java b/accord-maelstrom/src/main/java/accord/maelstrom/Json.java index 958f895..fcb56df 100644 --- a/accord-maelstrom/src/main/java/accord/maelstrom/Json.java +++ b/accord-maelstrom/src/main/java/accord/maelstrom/Json.java @@ -79,8 +79,8 @@ public class Json { switch (id.charAt(0)) { - case 'c': return new Id(-Long.parseLong(id.substring(1))); - case 'n':return new Id( Long.parseLong(id.substring(1))); + case 'c': return new Id(-Integer.parseInt(id.substring(1))); + case 'n':return new Id( Integer.parseInt(id.substring(1))); default: throw new IllegalStateException(); } } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@cassandra.apache.org For additional commands, e-mail: commits-h...@cassandra.apache.org