bbotella commented on code in PR #241:
URL:
https://github.com/apache/cassandra-analytics/pull/241#discussion_r3986455897
##########
cassandra-four-zero-bridge/src/main/java/org/apache/cassandra/db/commitlog/BufferingCommitLogReader.java:
##########
@@ -604,6 +617,45 @@ private void readMutationInternal(byte[] inputBuffer,
this.handleMutation(mutation, size, mutationPosition, desc);
}
+ /**
+ * Best-effort check for whether a mutation that failed to deserialize is
guaranteed not to involve any
+ * CDC-enabled table, so the failure can be safely ignored.
+ * Only reads the first {@link TableId} to make the decision, as mutations
contain single partition update in most cases.
+ * If a mutation has more than one partition update, it conservatively
assumes a CDC-enabled table is involved.
+ *
+ * @param inputBuffer raw byte array w/Mutation data
+ * @param size serialized size of the mutation
+ * @return false if the first table touched by the mutation is confirmed
CDC-enabled, or the mutation has more
+ * than one {@link PartitionUpdate} (so the rest can't be safely
checked); true otherwise, including
+ * when the table's metadata can't be found, or even the first
{@link TableId} can't be read
+ */
+ @VisibleForTesting
+ static boolean failedMutationHasNoCdcTable(byte[] inputBuffer, int size)
+ {
+ try (DataInputBuffer in = new DataInputBuffer(inputBuffer, 0, size))
+ {
+ int updateCount = (int) in.readUnsignedVInt();
+ TableId tableId = TableId.deserialize(in);
+ TableMetadata metadata = Schema.instance.getTableMetadata(tableId);
+ if (metadata != null && metadata.params.cdc)
+ {
+ return false;
+ }
+
+ if (updateCount > 1)
Review Comment:
Can't we check this *before* we need to extract the tableId and the
metadata? (just at line 638)
##########
cassandra-four-zero-bridge/src/main/java/org/apache/cassandra/db/commitlog/BufferingCommitLogReader.java:
##########
@@ -567,6 +570,16 @@ private void readMutationInternal(byte[] inputBuffer,
catch (Throwable t)
{
JVMStabilityInspector.inspectThrowable(t);
+
+ if (failedMutationHasNoCdcTable(inputBuffer, size))
Review Comment:
It is scary that this new behavior doesn't break a pre-existing test :-(
##########
cassandra-four-zero-bridge/src/main/java/org/apache/cassandra/db/commitlog/BufferingCommitLogReader.java:
##########
@@ -604,6 +617,45 @@ private void readMutationInternal(byte[] inputBuffer,
this.handleMutation(mutation, size, mutationPosition, desc);
}
+ /**
+ * Best-effort check for whether a mutation that failed to deserialize is
guaranteed not to involve any
+ * CDC-enabled table, so the failure can be safely ignored.
+ * Only reads the first {@link TableId} to make the decision, as mutations
contain single partition update in most cases.
+ * If a mutation has more than one partition update, it conservatively
assumes a CDC-enabled table is involved.
+ *
+ * @param inputBuffer raw byte array w/Mutation data
+ * @param size serialized size of the mutation
+ * @return false if the first table touched by the mutation is confirmed
CDC-enabled, or the mutation has more
+ * than one {@link PartitionUpdate} (so the rest can't be safely
checked); true otherwise, including
+ * when the table's metadata can't be found, or even the first
{@link TableId} can't be read
+ */
+ @VisibleForTesting
+ static boolean failedMutationHasNoCdcTable(byte[] inputBuffer, int size)
Review Comment:
Maybe it is just me, but I tend to not like the negative on method names.
HasNo + false is what we are looking for here -> that double negative always
messes my head :-P
What do you think on having a failedMutationHasCdcTable method instead that
returns true if it needs to be handled, and false if it needs to be ignored?
Obviously not a blocker.
##########
cassandra-four-zero-bridge/src/test/java/org/apache/cassandra/db/commitlog/BufferingCommitLogReaderTableContextTests.java:
##########
@@ -0,0 +1,129 @@
+/*
+ * 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.db.commitlog;
+
+import java.util.UUID;
+
+import org.junit.jupiter.api.Test;
+
+import org.apache.cassandra.bridge.CassandraBridgeImplementation;
+import org.apache.cassandra.cql3.CQLFragmentParser;
+import org.apache.cassandra.cql3.CqlParser;
+import org.apache.cassandra.db.Keyspace;
+import org.apache.cassandra.io.util.DataOutputBuffer;
+import org.apache.cassandra.schema.KeyspaceMetadata;
+import org.apache.cassandra.schema.KeyspaceParams;
+import org.apache.cassandra.schema.Schema;
+import org.apache.cassandra.schema.TableId;
+import org.apache.cassandra.schema.TableMetadata;
+import org.apache.cassandra.schema.Types;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class BufferingCommitLogReaderTableContextTests
+{
+ @Test
+ public void
testFailedMutationHasNoCdcTableWhenNonCdcTableIdReadableButRestCorrupted()
throws Exception
+ {
+ TableId tableId = registerTable("ks_non_cdc", "tbl", false);
+ byte[] corruptedMutation = buildCorruptedMutation(1, tableId);
+
+ boolean failedMutationHasNoCdcTable =
BufferingCommitLogReader.failedMutationHasNoCdcTable(corruptedMutation,
+
corruptedMutation.length);
+
+ assertThat(failedMutationHasNoCdcTable).isTrue();
+ }
+
+ @Test
+ public void
testFailedMutationHasNoCdcTableWhenCdcTableIdReadableButRestCorrupted() throws
Exception
+ {
+ TableId tableId = registerTable("ks_cdc", "tbl", true);
+ byte[] corruptedMutation = buildCorruptedMutation(1, tableId);
+
+ boolean failedMutationHasNoCdcTable =
BufferingCommitLogReader.failedMutationHasNoCdcTable(corruptedMutation,
+
corruptedMutation.length);
+
+ assertThat(failedMutationHasNoCdcTable).isFalse();
+ }
+
+ @Test
+ public void testFailedMutationHasNoCdcTableWhenTableIdUnresolvable()
throws Exception
+ {
+ CassandraBridgeImplementation.setup();
+ TableId unknownTableId = TableId.fromUUID(UUID.randomUUID());
Review Comment:
nit: Maybe move these two to a helper getUnregisteredTable method?
--
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]