smengcl commented on code in PR #12171:
URL: https://github.com/apache/ozone/pull/12171#discussion_r4704792345


##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OmSnapshotLocalDataYaml.java:
##########
@@ -81,9 +92,85 @@ public final class OmSnapshotLocalDataYaml {
   // For the ASCII snapshot local data YAML this is effectively the maximum 
file size in bytes.
   public static final int SNAPSHOT_LOCAL_DATA_YAML_CODE_POINT_LIMIT = 128 * 
1024 * 1024;
 
+  // zstd frame magic number 0xFD2FB528 in the little-endian byte order it is 
written in. YAML never starts with it.
+  private static final byte[] ZSTD_MAGIC = {0x28, (byte) 0xB5, 0x2F, (byte) 
0xFD};
+  // On snapshot local data YAML files, level 1 compresses smaller and faster 
than the default level 3.
+  private static final int ZSTD_LEVEL = 1;
+
   private OmSnapshotLocalDataYaml() {
   }
 
+  /**
+   * Opens a snapshot local data YAML file for reading, decompressing it if it 
is zstd compressed.
+   */
+  public static InputStream newInputStream(File yamlFile) throws IOException {
+    InputStream in = new 
BufferedInputStream(Files.newInputStream(yamlFile.toPath()));
+    try {
+      return isZstd(in) ? new ZstdInputStream(in) : in;
+    } catch (Throwable t) {
+      in.close();
+      throw t;

Review Comment:
   Thanks for the check. This one does compile: since Java 7, rethrowing an 
effectively final catch parameter only rethrows the checked exceptions its try 
block can throw (JLS 11.2.2). Both try blocks can only throw `IOException` plus 
unchecked exceptions, so `throw t` fits the `throws IOException` clause, and 
the CI build of this commit passed: 
https://github.com/smengcl/hadoop-ozone/actions/runs/45764108300. Catching 
`Throwable` is on purpose, so that a `LinkageError` from zstd-jni still 
discards the temporary file and closes the stream.



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