maedhroz commented on code in PR #2267: URL: https://github.com/apache/cassandra/pull/2267#discussion_r1167171132
########## src/java/org/apache/cassandra/io/sstable/format/bti/BtiTableVerifier.java: ########## @@ -0,0 +1,207 @@ +/* + * 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.io.sstable.format.bti; + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.util.Collections; +import java.util.List; +import java.util.Objects; + +import com.google.common.base.Throwables; + +import org.apache.cassandra.db.ColumnFamilyStore; +import org.apache.cassandra.db.DecoratedKey; +import org.apache.cassandra.db.compaction.CompactionInterruptedException; +import org.apache.cassandra.db.rows.UnfilteredRowIterator; +import org.apache.cassandra.dht.LocalPartitioner; +import org.apache.cassandra.dht.Range; +import org.apache.cassandra.dht.Token; +import org.apache.cassandra.io.sstable.CorruptSSTableException; +import org.apache.cassandra.io.sstable.IVerifier; +import org.apache.cassandra.io.sstable.KeyReader; +import org.apache.cassandra.io.sstable.SSTableIdentityIterator; +import org.apache.cassandra.io.sstable.format.SSTableReader; +import org.apache.cassandra.io.sstable.format.SortedTableVerifier; +import org.apache.cassandra.utils.ByteBufferUtil; +import org.apache.cassandra.utils.FBUtilities; +import org.apache.cassandra.utils.OutputHandler; + +public class BtiTableVerifier extends SortedTableVerifier<BtiTableReader> implements IVerifier +{ + public BtiTableVerifier(ColumnFamilyStore cfs, BtiTableReader sstable, OutputHandler outputHandler, boolean isOffline, Options options) + { + super(cfs, sstable, outputHandler, isOffline, options); + } + + public void verify() + { + verifySSTableVersion(); + + verifySSTableMetadata(); + + verifyIndex(); + + verifyBloomFilter(); + + if (options.checkOwnsTokens && !isOffline && !(cfs.getPartitioner() instanceof LocalPartitioner)) + { + if (verifyOwnedRanges() == 0) + return; + } + + if (options.quick) + return; + + if (verifyDigest() && !options.extendedVerification) + return; + + verifySSTable(); + + outputHandler.output("Verify of %s succeeded. All %d rows read successfully", sstable, goodRows); + } + + private void verifySSTable() + { + long rowStart; + outputHandler.output("Extended Verify requested, proceeding to inspect values"); + + try (VerifyController verifyController = new VerifyController(cfs); + KeyReader indexIterator = sstable.keyReader()) + { + if (indexIterator.dataPosition() != 0) + markAndThrow(new RuntimeException("First row position from index != 0: " + indexIterator.dataPosition())); + + List<Range<Token>> ownedRanges = isOffline ? Collections.emptyList() : Range.normalize(tokenLookup.apply(cfs.metadata().keyspace)); + RangeOwnHelper rangeOwnHelper = new RangeOwnHelper(ownedRanges); + DecoratedKey prevKey = null; + + while (!dataFile.isEOF()) + { + + if (verifyInfo.isStopRequested()) + throw new CompactionInterruptedException(verifyInfo.getCompactionInfo()); + + rowStart = dataFile.getFilePointer(); + outputHandler.debug("Reading row at %d", rowStart); + + DecoratedKey key = null; + try + { + key = sstable.decorateKey(ByteBufferUtil.readWithShortLength(dataFile)); + } + catch (Throwable th) + { + throwIfFatal(th); Review Comment: Won't we ignore things like NPEs here? Would it make sense to catch and re-throw any `RuntimeException` before we hit this fallback? -- 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]

