This is an automated email from the ASF dual-hosted git repository.
adoroszlai pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ozone.git
The following commit(s) were added to refs/heads/master by this push:
new b1ccf4881e9 HDDS-13735. DBConfigFromFile warns about trying to read
from "" (#9093)
b1ccf4881e9 is described below
commit b1ccf4881e9aa38b3852549957582cfd3824e24d
Author: Priyesh Karatha <[email protected]>
AuthorDate: Fri Oct 3 19:09:13 2025 +0530
HDDS-13735. DBConfigFromFile warns about trying to read from "" (#9093)
---
.../org/apache/hadoop/hdds/utils/db/DBConfigFromFile.java | 13 +++++++++++--
.../apache/hadoop/hdds/utils/db/TestDBConfigFromFile.java | 7 +++++++
2 files changed, 18 insertions(+), 2 deletions(-)
diff --git
a/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/DBConfigFromFile.java
b/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/DBConfigFromFile.java
index 4e7950ec559..b2ebf627ee5 100644
---
a/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/DBConfigFromFile.java
+++
b/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/DBConfigFromFile.java
@@ -82,7 +82,7 @@ public static File getConfigLocation() {
*/
public static String getOptionsFileNameFromDB(String dbFileName) {
Preconditions.checkNotNull(dbFileName);
- return dbFileName + ".ini";
+ return dbFileName.isEmpty() ? "" : dbFileName + ".ini";
}
/**
@@ -113,6 +113,9 @@ public static String getOptionsFileNameFromDB(String
dbFileName) {
*/
public static ManagedDBOptions readDBOptionsFromFile(Path dbPath) throws
RocksDBException {
Path generatedDBPath = generateDBPath(dbPath);
+ if (generatedDBPath.toString().isEmpty()) {
+ return null;
+ }
if (!generatedDBPath.toFile().exists()) {
LOG.warn("Error trying to read generated rocksDB file: {}, file does not
exists.", generatedDBPath);
return null;
@@ -137,6 +140,9 @@ public static ManagedDBOptions readDBOptionsFromFile(Path
dbPath) throws RocksDB
public static ManagedColumnFamilyOptions readCFOptionsFromFile(Path
optionsPath, String cfName)
throws RocksDBException {
Path generatedDBPath = generateDBPath(optionsPath);
+ if (generatedDBPath.toString().isEmpty()) {
+ return null;
+ }
if (!generatedDBPath.toFile().exists()) {
LOG.warn("Error trying to read column family options from file: {}, file
does not exists.", generatedDBPath);
return null;
@@ -173,6 +179,10 @@ private static void
closeDescriptors(List<ColumnFamilyDescriptor> descriptors) {
* @throws RocksDBException
*/
private static Path generateDBPath(Path path) {
+ String dbPath = path == null ? "" : path.toString();
+ if (dbPath.isEmpty()) {
+ return Paths.get("");
+ }
if (path.toFile().exists()) {
LOG.debug("RocksDB path found: {}, opening db from it.", path);
return path;
@@ -190,5 +200,4 @@ private static Path generateDBPath(Path path) {
LOG.info("No RocksDB path found");
return Paths.get("");
}
-
}
diff --git
a/hadoop-hdds/framework/src/test/java/org/apache/hadoop/hdds/utils/db/TestDBConfigFromFile.java
b/hadoop-hdds/framework/src/test/java/org/apache/hadoop/hdds/utils/db/TestDBConfigFromFile.java
index 9e092c6b441..72ac0c4ecae 100644
---
a/hadoop-hdds/framework/src/test/java/org/apache/hadoop/hdds/utils/db/TestDBConfigFromFile.java
+++
b/hadoop-hdds/framework/src/test/java/org/apache/hadoop/hdds/utils/db/TestDBConfigFromFile.java
@@ -79,6 +79,13 @@ public void readFromNonExistentFile() throws
RocksDBException {
assertNull(options);
}
+ @Test
+ public void readFromEmptyFilePath() throws RocksDBException {
+ final DBOptions options =
DBConfigFromFile.readDBOptionsFromFile(Paths.get(""));
+ // This has to return a Null, since the path is empty.
+ assertNull(options);
+ }
+
@Test
public void readFromEmptyFile() throws IOException {
File emptyFile = new
File(Paths.get(System.getProperty(DBConfigFromFile.CONFIG_DIR)).toString(),
"empty.ini");
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]