smiklosovic commented on code in PR #1351: URL: https://github.com/apache/cassandra/pull/1351#discussion_r857912701
########## src/java/org/apache/cassandra/service/DataResurrectionCheck.java: ########## @@ -0,0 +1,324 @@ +/* + * 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; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.time.Instant; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; + +import com.google.common.annotations.VisibleForTesting; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; +import org.apache.cassandra.concurrent.ScheduledExecutors; +import org.apache.cassandra.config.CassandraRelevantProperties; +import org.apache.cassandra.config.DatabaseDescriptor; +import org.apache.cassandra.config.StartupChecksOptions; +import org.apache.cassandra.exceptions.StartupException; +import org.apache.cassandra.io.util.File; +import org.apache.cassandra.io.util.FileInputStreamPlus; +import org.apache.cassandra.io.util.FileOutputStreamPlus; +import org.apache.cassandra.schema.KeyspaceMetadata; +import org.apache.cassandra.schema.SchemaKeyspace; +import org.apache.cassandra.utils.Clock; +import org.apache.cassandra.utils.Pair; + +import static java.lang.String.format; +import static java.util.concurrent.TimeUnit.MILLISECONDS; +import static java.util.stream.Collectors.joining; +import static java.util.stream.Collectors.toList; +import static java.util.stream.Collectors.toSet; +import static org.apache.cassandra.exceptions.StartupException.ERR_WRONG_DISK_STATE; +import static org.apache.cassandra.exceptions.StartupException.ERR_WRONG_MACHINE_STATE; +import static org.apache.cassandra.io.util.File.WriteMode.OVERWRITE; +import static org.apache.cassandra.utils.Clock.Global.currentTimeMillis; + +public class DataResurrectionCheck implements StartupCheck +{ + private static final Logger LOGGER = LoggerFactory.getLogger(DataResurrectionCheck.class); + + public static final String HEARTBEAT_FILE_CONFIG_PROPERTY = "heartbeat_file"; + public static final String EXCLUDED_KEYSPACES_CONFIG_PROPERTY = "excluded_keyspaces"; + public static final String EXCLUDED_TABLES_CONFIG_PROPERTY = "excluded_tables"; + + public static final String DEFAULT_HEARTBEAT_FILE = "cassandra-heartbeat"; + + public static class Heartbeat + { + private static final ObjectMapper mapper = new ObjectMapper(); + static + { + mapper.registerModule(new JavaTimeModule()); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + } + + @JsonProperty("last_heartbeat") + public final Instant lastHeartbeat; + + /** needed for jackson serialization */ + @SuppressWarnings("unused") + private Heartbeat() { + this.lastHeartbeat = null; + } + + public Heartbeat(Instant lastHeartbeat) + { + this.lastHeartbeat = lastHeartbeat; + } + + public void serializeToJsonFile(File outputFile) throws IOException + { + try (FileOutputStreamPlus out = outputFile.newOutputStream(OVERWRITE)) + { + mapper.writeValue((OutputStream) out, Heartbeat.this); + } + } + + public static Heartbeat deserializeFromJsonFile(File file) throws IOException + { + try (FileInputStreamPlus in = file.newInputStream()) + { + return mapper.readValue((InputStream) in, Heartbeat.class); + } + } + + @Override + public boolean equals(Object o) + { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Heartbeat manifest = (Heartbeat) o; + return Objects.equals(lastHeartbeat, manifest.lastHeartbeat); + } + + @Override + public int hashCode() + { + return Objects.hash(lastHeartbeat); Review Comment: putting here null is fine, it will return 0. -- 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: pr-unsubscr...@cassandra.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: pr-unsubscr...@cassandra.apache.org For additional commands, e-mail: pr-h...@cassandra.apache.org