xichen01 commented on code in PR #8707:
URL: https://github.com/apache/ozone/pull/8707#discussion_r2202836758


##########
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;
+    private String checksum;
+    private long timestamp;
+    private int version;
+
+    public CacheMetadata() {
+      this.containerYamlData = new HashMap<>();
+      this.timestamp = System.currentTimeMillis();
+      this.version = CacheVersion.CURRENT_VERSION;
+    }
+
+    public Map<Long, String> getContainerYamlData() {
+      return containerYamlData;
+    }
+
+    public void setContainerYamlData(Map<Long, String> containerYamlData) {
+      this.containerYamlData = containerYamlData;
+    }
+
+    public long getRocksDbSequenceNumber() {
+      return rocksDbSequenceNumber;
+    }
+
+    public void setRocksDbSequenceNumber(long rocksDbSequenceNumber) {
+      this.rocksDbSequenceNumber = rocksDbSequenceNumber;
+    }
+
+    public String getChecksum() {
+      return checksum;
+    }
+
+    public void setChecksum(String checksum) {
+      this.checksum = checksum;
+    }
+
+    public long getTimestamp() {
+      return timestamp;
+    }
+
+    public void setTimestamp(long timestamp) {
+      this.timestamp = timestamp;
+    }
+
+    public int getVersion() {
+      return version;
+    }
+
+    public void setVersion(int version) {
+      this.version = version;
+    }
+  }
+
+  /**
+   * Dump container metadata cache for specific volume.
+   */
+  public File dumpContainerCache(Iterable<? extends Container<?>> containers,

Review Comment:
   Only the contents of the container's yaml file are cached here, and no 
content of the DB itself is included. This is because reading the container 
yaml file is the main bottleneck of startup performance.
   
   It seems that the name of the method here is not very accurate.



-- 
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: issues-unsubscr...@ozone.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@ozone.apache.org
For additional commands, e-mail: issues-h...@ozone.apache.org

Reply via email to