belliottsmith commented on code in PR #1845:
URL: https://github.com/apache/cassandra/pull/1845#discussion_r996312462


##########
src/java/org/apache/cassandra/service/accord/AccordCommand.java:
##########
@@ -0,0 +1,788 @@
+/*
+ * 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 org.apache.cassandra.service.accord;
+
+import java.nio.ByteBuffer;
+import java.util.Objects;
+import java.util.TreeMap;
+import java.util.TreeSet;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import com.google.common.base.Preconditions;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import accord.api.Data;
+import accord.api.Key;
+import accord.api.Result;
+import accord.local.Command;
+import accord.local.Listener;
+import accord.local.Listeners;
+import accord.local.PartialCommand;
+import accord.local.PreLoadContext;
+import accord.local.Status;
+import accord.primitives.Ballot;
+import accord.primitives.Deps;
+import accord.primitives.KeyRanges;
+import accord.primitives.Keys;
+import accord.primitives.Timestamp;
+import accord.primitives.TxnId;
+import accord.txn.Txn;
+import accord.txn.Writes;
+import accord.utils.DeterministicIdentitySet;
+import org.apache.cassandra.service.accord.api.AccordKey;
+import org.apache.cassandra.service.accord.async.AsyncContext;
+import org.apache.cassandra.service.accord.db.AccordData;
+import org.apache.cassandra.service.accord.store.StoredBoolean;
+import org.apache.cassandra.service.accord.store.StoredNavigableMap;
+import org.apache.cassandra.service.accord.store.StoredSet;
+import org.apache.cassandra.service.accord.store.StoredValue;
+import org.apache.cassandra.utils.ByteBufferUtil;
+import org.apache.cassandra.utils.ObjectSizes;
+import org.apache.cassandra.utils.concurrent.AsyncPromise;
+import org.apache.cassandra.utils.concurrent.Future;
+
+import static 
org.apache.cassandra.service.accord.AccordState.WriteOnly.applyMapChanges;
+import static 
org.apache.cassandra.service.accord.AccordState.WriteOnly.applySetChanges;
+
+public class AccordCommand extends Command implements AccordState<TxnId>
+{
+    private static final Logger logger = 
LoggerFactory.getLogger(AccordCommand.class);
+
+    private static final AtomicInteger INSTANCE_COUNTER = new AtomicInteger(0);
+
+    private static final long EMPTY_SIZE = ObjectSizes.measure(new 
AccordCommand(null, null));
+
+    public static class WriteOnly extends AccordCommand implements 
AccordState.WriteOnly<TxnId, AccordCommand>
+    {
+        private Future<?> future = null;
+
+        public WriteOnly(AccordCommandStore commandStore, TxnId txnId)
+        {
+            super(commandStore, txnId);
+        }
+
+        @Override
+        public void future(Future<?> future)
+        {
+            Preconditions.checkArgument(this.future == null);
+            this.future = future;
+        }
+
+        @Override
+        public Future<?> future()
+        {
+            return future;
+        }
+
+        @Override
+        public void applyChanges(AccordCommand instance)
+        {
+            applyMapChanges(this, instance, cmd -> cmd.waitingOnCommit);
+            applyMapChanges(this, instance, cmd -> cmd.waitingOnApply);
+            applySetChanges(this, instance, cmd -> cmd.blockingCommitOn);
+            applySetChanges(this, instance, cmd -> cmd.blockingApplyOn);
+        }
+    }
+
+    public static class ReadOnly extends AccordCommand implements 
AccordState.ReadOnly<TxnId, AccordCommand>
+    {
+        public ReadOnly(AccordCommandStore commandStore, TxnId txnId)
+        {
+            super(commandStore, txnId);
+        }
+
+        @Override
+        boolean isReadOnly()
+        {
+            return true;
+        }
+    }
+
+    private final AccordCommandStore commandStore;
+    private final TxnId txnId;
+    private final int instanceCount = INSTANCE_COUNTER.getAndIncrement();
+    public final StoredValue<Key> homeKey;
+    public final StoredValue<Key> progressKey;
+    public final StoredValue<Txn> txn;
+    public final StoredValue<Ballot> promised;
+    public final StoredValue<Ballot> accepted;
+    public final StoredValue<Timestamp> executeAt;
+    public final StoredValue<Deps> deps;
+    public final StoredValue<Writes> writes;
+    public final StoredValue<Result> result;
+
+    public final StoredValue.HistoryPreserving<Status> status;
+    public final StoredBoolean isGloballyPersistent;
+
+    public final StoredNavigableMap<TxnId, ByteBuffer> waitingOnCommit;
+    public final StoredNavigableMap<TxnId, ByteBuffer> waitingOnApply;

Review Comment:
   FYI, this should be sorted by `Timestamp` (executeAt). But I will address it 
in my follow-up patch.



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