xichen01 commented on code in PR #8707: URL: https://github.com/apache/ozone/pull/8707#discussion_r2212769141
########## hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/impl/ContainerStartupCache.java: ########## @@ -0,0 +1,366 @@ +/* + * 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.hadoop.ozone.container.common.impl; + +import static org.apache.hadoop.ozone.OzoneConsts.CONTAINER_DB_NAME; +import static org.apache.hadoop.ozone.OzoneConsts.SCHEMA_V3; +import static org.apache.hadoop.ozone.container.common.impl.ContainerData.CHARSET_ENCODING; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.common.base.Preconditions; +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.StandardCopyOption; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.util.HashMap; +import java.util.Map; +import org.apache.commons.codec.digest.DigestUtils; +import org.apache.hadoop.hdds.conf.ConfigurationSource; +import org.apache.hadoop.hdds.utils.db.RDBStore; +import org.apache.hadoop.ozone.OzoneConsts; +import org.apache.hadoop.ozone.container.common.interfaces.Container; +import org.apache.hadoop.ozone.container.common.utils.DatanodeStoreCache; +import org.apache.hadoop.ozone.container.common.volume.HddsVolume; +import org.apache.hadoop.ozone.container.keyvalue.KeyValueContainer; +import org.apache.hadoop.ozone.container.keyvalue.KeyValueContainerData; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Container YAML cache for reducing random IO when reading Container YAML files. + */ +public class ContainerStartupCache { + + private static final Logger LOG = LoggerFactory.getLogger(ContainerStartupCache.class); + private static final String CACHE_FILE_NAME = "container_cache.json"; + private static final String CACHE_FILE_TEMP_SUFFIX = ".tmp"; + private static final String CHECKSUM_PLACEHOLDER = "CHECKSUM_PLACEHOLDER"; + + private final ObjectMapper objectMapper; + + /** + * Versioning for Container Cache format. + */ + public enum CacheVersion { + INITIAL_VERSION(1, "Initial container cache format"), + + FUTURE_VERSION(-1, "Used internally when an unknown cache version is encountered"); + + public static final CacheVersion CURRENT = latest(); + public static final int CURRENT_VERSION = CURRENT.version; + + private final int version; + private final String description; + + CacheVersion(int version, String description) { + this.version = version; + this.description = description; + } + + public String description() { + return description; + } + + public static CacheVersion fromValue(int value) { + for (CacheVersion v : values()) { + if (v.version == value) { + return v; + } + } + return FUTURE_VERSION; + } + + private static CacheVersion latest() { + CacheVersion[] versions = CacheVersion.values(); + // Return the latest version (excluding FUTURE_VERSION which is always last) + return versions[versions.length - 2]; + } + } + + public ContainerStartupCache() { + this.objectMapper = new ObjectMapper(); + this.objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); + } + + /** + * Cache metadata for containers in the volume. + */ + public static class CacheMetadata { + private Map<Long, String> containerYamlData; + private long rocksDbSequenceNumber; Review Comment: > thanks for proposing this improvement. I understand we need an anchor as the indicator that whether the cached file is update-to-date and can be used ... Using the rocksDbSequenceNumber is a stricter indicator, which may cause a usable, latest cache be dropped, but cannot cause a stale cache be loaded. I have not find a more accurate indicator yet. > is this adopted in real cluster? Have we got any info about the cache hit ratio, and miss ratio given this implementation? This have is not online yet, this feature's main scenario is to release new version for the Datanode, in this scenario, the Datanode will be stop and start in a short time, so this cache should be valid -- 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]
