Galsza commented on code in PR #8173:
URL: https://github.com/apache/ozone/pull/8173#discussion_r2023651115


##########
hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/DBConfigFromFile.java:
##########
@@ -106,38 +110,86 @@ public static String getOptionsFileNameFromDB(String 
dbFileName) {
    * control OzoneManager.db configs from a file, we need to create a file
    * called OzoneManager.db.ini and place that file in $OZONE_DIR/etc/hadoop.
    *
-   * @param dbFileName - The DB File Name, for example, OzoneManager.db.
-   * @param cfDescs - ColumnFamily Handles.
+   * @param dbPath - The DB File Name, for example, OzoneManager.db.
    * @return DBOptions, Options to be used for opening/creating the DB.
    * @throws IOException
    */
-  public static ManagedDBOptions readFromFile(String dbFileName,
-      List<ColumnFamilyDescriptor> cfDescs) throws IOException {
-    Preconditions.checkNotNull(dbFileName);
-    Preconditions.checkNotNull(cfDescs);
-    Preconditions.checkArgument(!cfDescs.isEmpty());
+  public static ManagedDBOptions readDBOptionsFromFile(Path dbPath) throws 
IOException {
+    List<ColumnFamilyDescriptor> descriptors = new ArrayList<>();
+    ManagedDBOptions readDBOptions = readFromFile(dbPath, descriptors);
+    //readDBOptions will be freed once the store using it is closed, but the 
descriptors need to be closed.
+    closeDescriptors(descriptors);
+    return readDBOptions;
+  }
 
-    //TODO: Add Documentation on how to support RocksDB Mem Env.
-    Env env = Env.getDefault();
-    ManagedDBOptions options = null;
-    File configLocation = getConfigLocation();
-    if (configLocation != null &&
-        StringUtil.isNotBlank(configLocation.toString())) {
-      Path optionsFile = Paths.get(configLocation.toString(),
-          getOptionsFileNameFromDB(dbFileName));
-
-      if (optionsFile.toFile().exists()) {
-        options = new ManagedDBOptions();
-        try {
-          OptionsUtil.loadOptionsFromFile(optionsFile.toString(),
-              env, options, cfDescs, true);
-
-        } catch (RocksDBException rdEx) {
-          throw toIOException("Unable to find/open Options file.", rdEx);
-        }
+  public static ManagedColumnFamilyOptions readCFOptionsFromFile(Path dbPath, 
String cfName) throws IOException {
+    List<ColumnFamilyDescriptor> descriptors = new ArrayList<>();
+    String validatedCfName = StringUtil.isEmpty(cfName) ? 
StringUtils.bytes2String(DEFAULT_COLUMN_FAMILY) : cfName;
+    ManagedColumnFamilyOptions resultCfOptions = null;
+    try (ManagedDBOptions ignored = readFromFile(dbPath, descriptors)) {
+      ColumnFamilyDescriptor descriptor = descriptors.stream()
+          .filter(desc -> 
StringUtils.bytes2String(desc.getName()).equals(validatedCfName))
+          .findAny().orElse(null);
+      if (descriptor != null) {
+        resultCfOptions = new 
ManagedColumnFamilyOptions(descriptor.getOptions());
       }
+    } finally {
+      closeDescriptors(descriptors);
+    }
+    return resultCfOptions;
+  }
+
+  private static ManagedDBOptions readFromFile(Path dbPath, 
List<ColumnFamilyDescriptor> descriptors)
+      throws IOException {
+    Preconditions.checkNotNull(dbPath);
+
+    //TODO: Add Documentation on how to support RocksDB Mem Env.
+    Path generatedDBPath = generateDBPath(dbPath);
+    if (!generatedDBPath.toFile().exists()) {
+      LOG.warn("Error trying to read generated rocksDB file: {}, file does not 
exists.", generatedDBPath);
+      return null;
+    }
+    ManagedDBOptions options = new ManagedDBOptions();
+    try (ManagedConfigOptions configOptions = new ManagedConfigOptions()) {
+      OptionsUtil.loadOptionsFromFile(configOptions, 
generatedDBPath.toString(), options, descriptors);
+    } catch (RocksDBException rdEx) {
+      options.close();
+      closeDescriptors(descriptors);

Review Comment:
   Thanks for the suggestion, I changed it



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