swamirishi commented on code in PR #8555: URL: https://github.com/apache/ozone/pull/8555#discussion_r2136351173
########## hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OmSnapshotLocalPropertyYamlImpl.java: ########## @@ -0,0 +1,178 @@ +/* + * 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.om; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Files; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; +import java.util.concurrent.atomic.AtomicBoolean; +import org.apache.hadoop.hdds.server.YamlUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.yaml.snakeyaml.DumperOptions; +import org.yaml.snakeyaml.Yaml; +import org.yaml.snakeyaml.scanner.ScannerException; + +/** + * Implementation of {@link OmSnapshotLocalProperty} that uses a YAML file + * to store and retrieve snapshot local properties. + * Changes are only persisted when the object is closed. + */ +public class OmSnapshotLocalPropertyYamlImpl implements OmSnapshotLocalProperty, AutoCloseable { + + private static final Logger LOG = LoggerFactory.getLogger(OmSnapshotLocalPropertyYamlImpl.class); + + /** + * The path to the YAML file used to store properties. + * If this file does not exist, it will be created upon close(). + */ + private final File yamlFile; + + /** + * A map storing key-value pairs of snapshot properties. + * Read from the YAML file upon initialization. + */ + private Map<String, String> properties; + + /** + * Flag indicating whether the properties have been modified + * since the last save to the YAML file. + * Used to determine if file write is needed on close. + */ + private final AtomicBoolean isDirty = new AtomicBoolean(false); + + /** + * Flag indicating whether this instance has been closed. + * Operations attempted after closing will throw an OMException. + */ + private final AtomicBoolean isClosed = new AtomicBoolean(false); + + /** + * Constructs a new OmSnapshotLocalPropertyYamlImpl. + * + * @param yamlFilePath Path to the YAML file + */ + public OmSnapshotLocalPropertyYamlImpl(String yamlFilePath) throws IOException { + this.yamlFile = new File(yamlFilePath); + loadPropertiesFromFile(); + } + + @Override + public void setProperty(String key, String value) throws IOException { Review Comment: For SstFilteredFlag the key could be a constant String "SstFilteredFlag" -- 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]
