swamirishi commented on code in PR #8555:
URL: https://github.com/apache/ozone/pull/8555#discussion_r2136326590


##########
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 {
+    checkIfClosed();
+    String oldValue = properties.get(key);
+    if (!Objects.equals(value, oldValue)) {
+      properties.put(key, value);
+      isDirty.set(true);

Review Comment:
   Just setting the value in memory might not ensure it is going to be flushed 
in case of a jvm crash. Should we add a flag in the setProperty for forcefully 
flushing to disk in certain cases?



##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OmSnapshotLocalProperty.java:
##########
@@ -0,0 +1,71 @@
+/*
+ * 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.IOException;
+import java.util.Map;
+
+/**
+ * Interface to manage Ozone snapshot DB local checkpoint metadata properties.
+ * Those properties are per-OM, e.g. isSSTFiltered flag, which differs from 
the ones stored in SnapshotInfo proto.
+ */
+public interface OmSnapshotLocalProperty extends AutoCloseable {
+
+  /**
+   * Sets a property for a snapshot.
+   *
+   * @param key          Property key
+   * @param value        Property value
+   * @throws IOException if an I/O error occurs
+   */
+  void setProperty(String key, String value) throws IOException;
+
+  /**
+   * Gets a property value for a snapshot.
+   *
+   * @param key          Property key
+   * @return Property value or null if not found
+   * @throws IOException if an I/O error occurs
+   */
+  String getProperty(String key) throws IOException;

Review Comment:
   Boolean getSstFilteredFlag();



##########
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:
   ```suggestion
     private void setProperty(String key, Object value) throws IOException {
   ```



##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OmSnapshotLocalProperty.java:
##########
@@ -0,0 +1,71 @@
+/*
+ * 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.IOException;
+import java.util.Map;
+
+/**
+ * Interface to manage Ozone snapshot DB local checkpoint metadata properties.
+ * Those properties are per-OM, e.g. isSSTFiltered flag, which differs from 
the ones stored in SnapshotInfo proto.
+ */
+public interface OmSnapshotLocalProperty extends AutoCloseable {
+
+  /**
+   * Sets a property for a snapshot.
+   *
+   * @param key          Property key
+   * @param value        Property value
+   * @throws IOException if an I/O error occurs
+   */
+  void setProperty(String key, String value) throws IOException;

Review Comment:
   On a second thought I feel it would be better we can have a tightly couple 
schema.
   To begin with:
   ```suggestion
     void setSstFilteredProperty(Boolean sstFilteredFlag) throws IOException;
   ```



##########
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;

Review Comment:
   In certain cases we might have to support nested structure. This can be 
Map<String, Object> 



-- 
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]

Reply via email to