dcapwell commented on code in PR #2144:
URL: https://github.com/apache/cassandra/pull/2144#discussion_r1123808419


##########
src/java/org/apache/cassandra/service/accord/AccordSafeCommand.java:
##########
@@ -0,0 +1,107 @@
+/*
+ * 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.util.Objects;
+
+import com.google.common.annotations.VisibleForTesting;
+
+import accord.local.Command;
+import accord.local.SafeCommand;
+import accord.primitives.TxnId;
+
+public class AccordSafeCommand extends SafeCommand implements 
AccordSafeState<TxnId, Command>
+{
+    private boolean invalidated;
+    private final AccordLoadingState<TxnId, Command> global;
+    private Command original;
+    private Command current;
+
+    public AccordSafeCommand(AccordLoadingState<TxnId, Command> global)
+    {
+        super(global.key());
+        this.global = global;
+        this.original = null;
+        this.current = null;
+    }
+
+    @Override
+    public boolean equals(Object o)
+    {
+        if (this == o) return true;
+        if (o == null || getClass() != o.getClass()) return false;
+        AccordSafeCommand that = (AccordSafeCommand) o;
+        return Objects.equals(original, that.original) && 
Objects.equals(current, that.current);
+    }
+
+    @Override
+    public int hashCode()
+    {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public AccordLoadingState<TxnId, Command> global()
+    {
+        return global;
+    }
+
+    @Override
+    public Command current()
+    {
+        return current;
+    }
+
+    @Override
+    @VisibleForTesting
+    public void set(Command command)
+    {
+        this.current = command;
+    }
+
+    public Command original()
+    {
+        return original;
+    }
+
+    @Override
+    public void preExecute()
+    {
+        original = global.value();
+        current = original;
+    }
+
+    @Override
+    public void postExecute()
+    {
+        global.value(current);
+    }
+
+    @Override
+    public void invalidate()
+    {
+        invalidated = true;
+    }
+
+    @Override
+    public boolean invalidated()

Review Comment:
   this is logically dead code, its only used by 
`accord.local.SafeState#checkNotInvalidated` which is only used by 
`accord.impl.InMemorySafeCommand`; which this class does not extend



##########
src/java/org/apache/cassandra/utils/Throwables.java:
##########
@@ -267,4 +270,30 @@ public static RuntimeException cleaned(Throwable t)
     {
         return unchecked(unwrapped(t));
     }
+
+    public static List<Throwable> causes(Throwable actual, boolean 
includeSuppressed)
+    {
+        if (actual.getCause() == null) return 
Collections.singletonList(actual);
+        List<Throwable> causes = new ArrayList<>();
+        forEach(actual, includeSuppressed, causes::add);
+        return causes;
+    }
+
+    public enum ForEachResult { ALL, PARTIAL }
+
+    public static ForEachResult forEach(Throwable actual, boolean 
includeSuppressed, Predicate<? super Throwable> fn)

Review Comment:
   this is dead code I added... I was trying to do something else with 
`test/unit/org/apache/cassandra/utils/AssertionUtils.java` and went with a 
simpler solution; forgot to clean this up.
   
   We should just drop, else we should dead with circular references 



##########
src/java/org/apache/cassandra/service/accord/AccordSafeCommandsForKey.java:
##########
@@ -0,0 +1,108 @@
+/*
+ * 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.util.Objects;
+
+import com.google.common.annotations.VisibleForTesting;
+
+import accord.api.Key;
+import accord.impl.CommandsForKey;
+import accord.impl.SafeCommandsForKey;
+import accord.primitives.RoutableKey;
+
+public class AccordSafeCommandsForKey extends SafeCommandsForKey implements 
AccordSafeState<RoutableKey, CommandsForKey>
+{
+    private boolean invalidated;
+    private final AccordLoadingState<RoutableKey, CommandsForKey> global;
+    private CommandsForKey original;
+    private CommandsForKey current;
+
+    public AccordSafeCommandsForKey(AccordLoadingState<RoutableKey, 
CommandsForKey> global)
+    {
+        super((Key) global.key());
+        this.global = global;
+        this.original = null;
+        this.current = null;
+    }
+
+    @Override
+    public boolean equals(Object o)
+    {
+        if (this == o) return true;
+        if (o == null || getClass() != o.getClass()) return false;
+        AccordSafeCommandsForKey that = (AccordSafeCommandsForKey) o;
+        return Objects.equals(original, that.original) && 
Objects.equals(current, that.current);
+    }
+
+    @Override
+    public int hashCode()
+    {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public AccordLoadingState<RoutableKey, CommandsForKey> global()
+    {
+        return global;
+    }
+
+    @Override
+    public CommandsForKey current()
+    {
+        return current;
+    }
+
+    @Override
+    @VisibleForTesting
+    public void set(CommandsForKey cfk)
+    {
+        this.current = cfk;
+    }
+
+    public CommandsForKey original()
+    {
+        return original;
+    }
+
+    @Override
+    public void preExecute()
+    {
+        original = global.value();
+        current = original;
+    }
+
+    @Override
+    public void postExecute()
+    {
+        global.value(current);
+    }
+
+    @Override
+    public void invalidate()
+    {
+        invalidated = true;
+    }
+
+    @Override
+    public boolean invalidated()

Review Comment:
   dead code, same as the safe command version



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