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


##########
hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/DBConfigFromFile.java:
##########
@@ -103,37 +108,87 @@ 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.
    */
-  public static ManagedDBOptions readFromFile(String dbFileName,
-      List<ColumnFamilyDescriptor> cfDescs) throws RocksDatabaseException {
-    Preconditions.checkNotNull(dbFileName);
-    Preconditions.checkNotNull(cfDescs);
-    Preconditions.checkArgument(!cfDescs.isEmpty());
+  public static ManagedDBOptions readDBOptionsFromFile(Path dbPath) throws 
RocksDBException {
+    List<ColumnFamilyDescriptor> descriptors = new ArrayList<>();
+    try {
+      return readFromFile(dbPath, descriptors);
+    } finally {
+      //readDBOptions will be freed once the store using it is closed, but the 
descriptors need to be closed.
+      closeDescriptors(descriptors);
+    }
+  }
 
-    //TODO: Add Documentation on how to support RocksDB Mem Env.
-    Env env = Env.getDefault();
-    ManagedDBOptions options = null;
-    File configLocation = getConfigLocation();
-    if (configLocation != null &&
-        StringUtils.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 new RocksDatabaseException("Failed to loadOptionsFromFile " + 
optionsFile, rdEx);
-        }
+  public static ManagedColumnFamilyOptions readCFOptionsFromFile(Path dbPath, 
String cfName) throws RocksDBException {
+    List<ColumnFamilyDescriptor> descriptors = new ArrayList<>();
+    String defaultColumnFamilyString = 
StringUtils.toEncodedString(DEFAULT_COLUMN_FAMILY, StandardCharsets.UTF_8);
+    String validatedCfName = StringUtils.isEmpty(cfName) ? 
defaultColumnFamilyString : cfName;
+    ManagedColumnFamilyOptions resultCfOptions = null;
+    try (ManagedDBOptions ignored = readFromFile(dbPath, descriptors)) {
+      ColumnFamilyDescriptor descriptor = descriptors.stream()
+          .filter(desc -> StringUtils.toEncodedString(desc.getName(), 
StandardCharsets.UTF_8).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)

Review Comment:
   This function can return a AutoCloseable wrapper which would close the 
descriptors when close is called. Moreover we are always creating a new 
ArrayList<>() for descriptors so it would be better if just initialize 
descriptor inside this function



##########
hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/DBProfile.java:
##########
@@ -44,51 +48,92 @@ public String toString() {
     }
 
     @Override
-    public ManagedColumnFamilyOptions getColumnFamilyOptions() {
-      // Write Buffer Size -- set to 128 MB
-      final long writeBufferSize = toLong(StorageUnit.MB.toBytes(128));
+    public ManagedDBOptions getDBOptions(Path optionsPath) {

Review Comment:
   This is a bad idea to add the optionsPath in DB profile. Reading from ini 
file should be done on the DBStoreBuilder and not on the DBProfile. I believe 
we can load the ini file and not load from DB profile if the ini file exists on 
the DBStoreBuilder side. We would have to implement the same optionsPath read 
logic for each and every enum which is a bad idea



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