iamaleksey commented on code in PR #3506:
URL: https://github.com/apache/cassandra/pull/3506#discussion_r1758648221
##########
src/java/org/apache/cassandra/journal/Journal.java:
##########
@@ -654,6 +616,11 @@ private void runNormal() throws InterruptedException
Thread.yield();
}
}
+ catch (JournalWriteError e)
Review Comment:
Have you witnessed a `ClosedByInterruptException` in a tests, coming from
here?
##########
src/java/org/apache/cassandra/service/accord/AccordJournalTable.java:
##########
@@ -0,0 +1,183 @@
+/*
+ * 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.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import accord.utils.Invariants;
+import com.carrotsearch.hppc.LongHashSet;
+import org.agrona.collections.IntHashSet;
+import org.apache.cassandra.cql3.ColumnIdentifier;
+import org.apache.cassandra.db.ColumnFamilyStore;
+import org.apache.cassandra.db.DecoratedKey;
+import org.apache.cassandra.db.Keyspace;
+import org.apache.cassandra.db.Slices;
+import org.apache.cassandra.db.StorageHook;
+import org.apache.cassandra.db.filter.ColumnFilter;
+import org.apache.cassandra.db.lifecycle.SSTableSet;
+import org.apache.cassandra.db.lifecycle.View;
+import org.apache.cassandra.db.marshal.Int32Type;
+import org.apache.cassandra.db.marshal.LongType;
+import org.apache.cassandra.db.rows.Row;
+import org.apache.cassandra.db.rows.Unfiltered;
+import org.apache.cassandra.db.rows.UnfilteredRowIterator;
+import org.apache.cassandra.db.rows.UnfilteredRowIterators;
+import org.apache.cassandra.io.sstable.SSTableReadsListener;
+import org.apache.cassandra.io.sstable.format.SSTableReader;
+import org.apache.cassandra.journal.EntrySerializer;
+import org.apache.cassandra.journal.Journal;
+import org.apache.cassandra.journal.KeySupport;
+import org.apache.cassandra.journal.RecordConsumer;
+import org.apache.cassandra.schema.ColumnMetadata;
+import org.apache.cassandra.utils.concurrent.Ref;
+
+public class AccordJournalTable<K, V>
+{
+ private static final Logger logger =
LoggerFactory.getLogger(AccordJournalTable.class);
+ private final ColumnFamilyStore cfs;
+
+ private final ColumnMetadata recordColumn;
+ private final ColumnMetadata versionColumn;
+
+ private final Journal<K, V> journal;
+ private final KeySupport<K> keySupport;
+ private final int keySerializationVersion;
+
+
+ public AccordJournalTable(Journal<K, V> journal, KeySupport<K> keySupport,
int keySerializationVersion)
+ {
+ this.journal = journal;
+ this.cfs =
Keyspace.open(AccordKeyspace.metadata().name).getColumnFamilyStore(AccordKeyspace.JOURNAL);
+ this.recordColumn =
cfs.metadata().getColumn(ColumnIdentifier.getInterned("record", false));
+ this.versionColumn =
cfs.metadata().getColumn(ColumnIdentifier.getInterned("user_version", false));
+ this.keySupport = keySupport;
+ this.keySerializationVersion = keySerializationVersion;
+ }
+
+ /**
+ * Perform a read from Journal table, followed by the reas from all
journal segments.
+ * <p>
+ * When reading from journal segments, skip descriptors that were read
from the table.
+ */
+ public void readAll(K id, RecordConsumer<K> consumer)
+ {
+ journal.readAll(id,
+ new RecordConsumer<>()
+ {
+ LongHashSet visitedDescriptors = new LongHashSet();
+ boolean collectDescriptors = true;
+
+ @Override
+ public void init()
+ {
+ readAllFromTable(id, this);
+ collectDescriptors = false;
+ }
+
+ @Override
+ public void accept(long segment, int position, K
key, ByteBuffer buffer, IntHashSet hosts, int userVersion)
+ {
+ // To avoid duplicates, we need to filter out
segment descriptors that were visited while reading from the table
+ if (collectDescriptors)
+ visitedDescriptors.add(segment);
+ else if (visitedDescriptors.contains(segment))
+ return;
+
+ consumer.accept(segment, position, key,
buffer, hosts, userVersion);
+ }
+ });
+ }
+
+ protected void readAllFromTable(K key, RecordConsumer<K> onEntry)
+ {
+ List<Ref<SSTableReader>> refs = null;
+ try
+ {
+ EntrySerializer.EntryHolder<K> into = new
EntrySerializer.EntryHolder<>();
+ DecoratedKey pk =
cfs.decorateKey(JournalKey.Support.serialize(keySupport, key,
keySerializationVersion));
+ Collection<SSTableReader> sstables =
cfs.select(View.select(SSTableSet.LIVE, pk)).sstables;
Review Comment:
I think we should be using `CFS.selectAndReference` here? Is there a reason
why we cannot? Otherwise I think this code is possibly incorrect? Think
skipping sstables that have just been compacted away.
--
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]