You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pr@cassandra.apache.org by "bdeggleston (via GitHub)" <gi...@apache.org> on 2023/03/02 23:33:51 UTC

[GitHub] [cassandra] bdeggleston commented on a diff in pull request #2144: CEP-15 Accord: Immutable state integration

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


##########
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:
   we should actually be checking this, pushed a change to fix



-- 
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: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org