Repository: cassandra Updated Branches: refs/heads/cassandra-3.0 3153c630c -> 68079e4b2 refs/heads/cassandra-3.11 5cbe08b6a -> 18278e422 refs/heads/trunk 674addd03 -> fc2e420fd
Handle incompletely written hint descriptors during startup patch by Alex Lourie; reviewed by Aleksey Yeschenko for CASSANDRA-14080 Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/68079e4b Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/68079e4b Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/68079e4b Branch: refs/heads/cassandra-3.0 Commit: 68079e4b2ed4e58dbede70af45414b3d4214e195 Parents: 3153c63 Author: Alex Lourie <a...@instaclustr.com> Authored: Thu Mar 29 13:21:43 2018 +0100 Committer: Aleksey Yeshchenko <alek...@apple.com> Committed: Thu Mar 29 13:56:18 2018 +0100 ---------------------------------------------------------------------- CHANGES.txt | 1 + .../hints/ChecksumMismatchException.java | 28 ++++++++++++++++++++ .../apache/cassandra/hints/HintsCatalog.java | 4 ++- .../apache/cassandra/hints/HintsDescriptor.java | 24 ++++++++++++++++- 4 files changed, 55 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/68079e4b/CHANGES.txt ---------------------------------------------------------------------- diff --git a/CHANGES.txt b/CHANGES.txt index d701a22..7917712 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,4 +1,5 @@ 3.0.17 + * Handle incompletely written hint descriptors during startup (CASSANDRA-14080) * Handle repeat open bound from SRP in read repair (CASSANDRA-14330) * Use zero as default score in DynamicEndpointSnitch (CASSANDRA-14252) * Respect max hint window when hinting for LWT (CASSANDRA-14215) http://git-wip-us.apache.org/repos/asf/cassandra/blob/68079e4b/src/java/org/apache/cassandra/hints/ChecksumMismatchException.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/hints/ChecksumMismatchException.java b/src/java/org/apache/cassandra/hints/ChecksumMismatchException.java new file mode 100644 index 0000000..84dbbb2 --- /dev/null +++ b/src/java/org/apache/cassandra/hints/ChecksumMismatchException.java @@ -0,0 +1,28 @@ +/* + * 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.hints; + +import java.io.IOException; + +final class ChecksumMismatchException extends IOException +{ + ChecksumMismatchException(String message) + { + super(message); + } +} http://git-wip-us.apache.org/repos/asf/cassandra/blob/68079e4b/src/java/org/apache/cassandra/hints/HintsCatalog.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/hints/HintsCatalog.java b/src/java/org/apache/cassandra/hints/HintsCatalog.java index 5ebe65b..6d01629 100644 --- a/src/java/org/apache/cassandra/hints/HintsCatalog.java +++ b/src/java/org/apache/cassandra/hints/HintsCatalog.java @@ -61,7 +61,9 @@ final class HintsCatalog Map<UUID, List<HintsDescriptor>> stores = Files.list(hintsDirectory.toPath()) .filter(HintsDescriptor::isHintFileName) - .map(HintsDescriptor::readFromFile) + .map(HintsDescriptor::readFromFileQuietly) + .filter(Optional::isPresent) + .map(Optional::get) .collect(groupingBy(h -> h.hostId)); return new HintsCatalog(hintsDirectory, writerParams, stores); } http://git-wip-us.apache.org/repos/asf/cassandra/blob/68079e4b/src/java/org/apache/cassandra/hints/HintsDescriptor.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/hints/HintsDescriptor.java b/src/java/org/apache/cassandra/hints/HintsDescriptor.java index 916da4e..e9e1c30 100644 --- a/src/java/org/apache/cassandra/hints/HintsDescriptor.java +++ b/src/java/org/apache/cassandra/hints/HintsDescriptor.java @@ -23,6 +23,7 @@ import java.io.RandomAccessFile; import java.nio.charset.StandardCharsets; import java.nio.file.Path; import java.util.Map; +import java.util.Optional; import java.util.UUID; import java.util.regex.Pattern; import java.util.zip.CRC32; @@ -30,6 +31,8 @@ import java.util.zip.CRC32; import com.google.common.base.MoreObjects; import com.google.common.base.Objects; import com.google.common.collect.ImmutableMap; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.apache.cassandra.config.ParameterizedClass; import org.apache.cassandra.db.TypeSizes; @@ -50,6 +53,8 @@ import static org.apache.cassandra.utils.FBUtilities.updateChecksumInt; */ final class HintsDescriptor { + private static final Logger logger = LoggerFactory.getLogger(HintsDescriptor.class); + static final int VERSION_30 = 1; static final int CURRENT_VERSION = VERSION_30; @@ -131,6 +136,23 @@ final class HintsDescriptor return pattern.matcher(path.getFileName().toString()).matches(); } + static Optional<HintsDescriptor> readFromFileQuietly(Path path) + { + try (RandomAccessFile raf = new RandomAccessFile(path.toFile(), "r")) + { + return Optional.of(deserialize(raf)); + } + catch (ChecksumMismatchException e) + { + throw new FSReadError(e, path.toFile()); + } + catch (IOException e) + { + logger.error("Failed to deserialize hints descriptor {}", path.toString(), e); + return Optional.empty(); + } + } + static HintsDescriptor readFromFile(Path path) { try (RandomAccessFile raf = new RandomAccessFile(path.toFile(), "r")) @@ -274,6 +296,6 @@ final class HintsDescriptor private static void validateCRC(int expected, int actual) throws IOException { if (expected != actual) - throw new IOException("Hints Descriptor CRC Mismatch"); + throw new ChecksumMismatchException("Hints Descriptor CRC Mismatch"); } } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@cassandra.apache.org For additional commands, e-mail: commits-h...@cassandra.apache.org