iamaleksey commented on code in PR #2256: URL: https://github.com/apache/cassandra/pull/2256#discussion_r1160565156
########## src/java/org/apache/cassandra/service/accord/AccordJournal.java: ########## @@ -0,0 +1,407 @@ +/* + * 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.io.IOException; +import java.nio.ByteBuffer; +import java.util.*; +import java.util.concurrent.Executor; +import java.util.zip.Checksum; + +import com.google.common.primitives.Ints; + +import accord.local.Node.Id; +import accord.local.PreLoadContext; +import accord.messages.Accept; +import accord.messages.Apply; +import accord.messages.Commit; +import accord.messages.MessageType; +import accord.messages.PreAccept; +import accord.messages.TxnRequest; +import accord.primitives.*; +import org.apache.cassandra.config.DatabaseDescriptor; +import org.apache.cassandra.io.IVersionedSerializer; +import org.apache.cassandra.io.util.DataInputPlus; +import org.apache.cassandra.io.util.DataOutputPlus; +import org.apache.cassandra.io.util.File; +import org.apache.cassandra.journal.Journal; +import org.apache.cassandra.journal.KeySupport; +import org.apache.cassandra.journal.Params; +import org.apache.cassandra.journal.ValueSerializer; +import org.apache.cassandra.service.accord.serializers.AcceptSerializers; +import org.apache.cassandra.service.accord.serializers.ApplySerializers; +import org.apache.cassandra.service.accord.serializers.CommitSerializers; +import org.apache.cassandra.service.accord.serializers.EnumSerializer; +import org.apache.cassandra.service.accord.serializers.PreacceptSerializers; + +import static org.apache.cassandra.db.TypeSizes.BYTE_SIZE; +import static org.apache.cassandra.db.TypeSizes.INT_SIZE; +import static org.apache.cassandra.db.TypeSizes.LONG_SIZE; +import static org.apache.cassandra.utils.FBUtilities.updateChecksumInt; +import static org.apache.cassandra.utils.FBUtilities.updateChecksumLong; + +/* + * TODO: expose more journal params via Config + */ +class AccordJournal +{ + private static final Set<Integer> SENTINEL_HOSTS = Collections.singleton(0); + + final File directory; + final Journal<Key, TxnRequest<?>> journal; + + AccordJournal() + { + directory = new File(DatabaseDescriptor.getAccordJournalDirectory()); + journal = new Journal<>("AccordJournal", directory, Params.DEFAULT, Key.SUPPORT, MESSAGE_SERIALIZER); + } + + AccordJournal start() + { + journal.start(); + return this; + } + + void shutdown() + { + journal.shutdown(); + } + + boolean mustAppend(PreLoadContext context) + { + return context instanceof TxnRequest && Type.mustAppend((TxnRequest<?>) context); + } + + void append(int storeId, PreLoadContext context, Executor executor, Runnable onDurable) + { + append(storeId, (TxnRequest<?>) context, executor, onDurable); + } + + void append(int storeId, TxnRequest<?> message, Executor executor, Runnable onDurable) + { + Key key = new Key(message.txnId, Type.fromMsgType(message.type()), storeId); + journal.asyncWrite(key, message, SENTINEL_HOSTS, executor, onDurable); Review Comment: Segment target prioritisation for `Compactor` (stripped from the patch for now but will be reintroduced shortly). -- 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]

