dcapwell commented on code in PR #2144: URL: https://github.com/apache/cassandra/pull/2144#discussion_r1105099656
########## src/java/org/apache/cassandra/service/accord/serializers/CommandsForKeySerializer.java: ########## @@ -0,0 +1,159 @@ +/* + * 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.serializers; + +import java.io.IOException; +import java.nio.ByteBuffer; + +import accord.impl.CommandsForKey.CommandLoader; +import accord.local.Command; +import accord.local.SaveStatus; +import accord.primitives.PartialDeps; +import accord.primitives.Timestamp; +import accord.primitives.TxnId; +import accord.utils.Invariants; +import org.apache.cassandra.db.TypeSizes; +import org.apache.cassandra.db.marshal.ByteBufferAccessor; +import org.apache.cassandra.db.marshal.ValueAccessor; +import org.apache.cassandra.io.LocalVersionedSerializer; +import org.apache.cassandra.io.util.DataInputBuffer; +import org.apache.cassandra.io.util.DataOutputBuffer; +import org.apache.cassandra.io.util.DataOutputPlus; +import org.apache.cassandra.service.accord.AccordSerializerVersion; + +public class CommandsForKeySerializer +{ + private static final LocalVersionedSerializer<PartialDeps> depsSerializer = new LocalVersionedSerializer<>(AccordSerializerVersion.CURRENT, AccordSerializerVersion.serializer, DepsSerializer.partialDeps); + public static final CommandLoader<ByteBuffer> loader = new AccordCFKLoader(); + private static class AccordCFKLoader implements CommandLoader<ByteBuffer> + { + private static final int HAS_DEPS = 0x01; + + private static final long FIXED_SIZE; + private static final int FLAG_OFFSET; + private static final int STATUS_OFFSET; + private static final int TXNID_OFFSET; + private static final int EXECUTEAT_OFFSET; + private static final int DEPS_OFFSET; + + static + { + long size = 0; + + FLAG_OFFSET = (int) size; + size += TypeSizes.BYTE_SIZE; + + STATUS_OFFSET = (int) size; + size += TypeSizes.BYTE_SIZE; + + TXNID_OFFSET = (int) size; + size += CommandSerializers.txnId.serializedSize(); + + EXECUTEAT_OFFSET = (int) size; + size += CommandSerializers.timestamp.serializedSize(); + + DEPS_OFFSET = (int) size; + FIXED_SIZE = size; + } + + private int serializedSize(Command command) + { + return (int) (FIXED_SIZE + (command.partialDeps() != null ? depsSerializer.serializedSize(command.partialDeps()) : 0)); + } + + private static final ValueAccessor<ByteBuffer> accessor = ByteBufferAccessor.instance; + + private static byte toByte(int v) + { + Invariants.checkArgument(v < Byte.MAX_VALUE); Review Comment: can we update `Invariants` to allow string + args like Precnditions has? Then update this to have a useful error message, something like `, "Value %d is larger than %d", v, Byte.MAX_VALUE);` ########## src/java/org/apache/cassandra/service/accord/async/AsyncWriter.java: ########## @@ -76,35 +71,26 @@ public AsyncWriter(AccordCommandStore commandStore) this.cfkCache = commandStore.commandsForKeyCache(); } - private interface StateMutationFunction<K, V extends AccordState<K>> + private interface StateMutationFunction<V> { - Mutation apply(AccordCommandStore commandStore, V state, long timestamp); + Mutation apply(AccordCommandStore commandStore, V previous, V updated, long timestamp); } - private static <K, V extends AccordState<K>> List<Future<?>> dispatchWrites(AsyncContext.Group<K, V> ctxGroup, - AccordStateCache.Instance<K, V> cache, - StateMutationFunction<K, V> mutationFunction, - long timestamp, - AccordCommandStore commandStore, - List<Future<?>> futures, - Object callback) + private static <K, V extends ImmutableState> List<AsyncChain<Void>> dispatchWrites(ImmutableMap<K, ContextValue<V>> values, + AccordStateCache.Instance<K, V> cache, + StateMutationFunction<V> mutationFunction, + long timestamp, + AccordCommandStore commandStore, + List<AsyncChain<Void>> results, + Object callback) Review Comment: can we remove callback? the logging doesn't add value as its always a single class: `AsyncOperation` -- 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]

