Skip to content

Commit

Permalink
HDDS-4768. Refactor the repeated exception conversion method into a c…
Browse files Browse the repository at this point in the history
…ommon util class (apache#1864)
  • Loading branch information
lamberken committed Feb 4, 2021
1 parent d4e51a8 commit 836072e
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@
import static org.apache.hadoop.hdds.scm.ScmConfigKeys.OZONE_SCM_STALENODE_INTERVAL;
import static org.apache.hadoop.hdds.scm.ScmConfigKeys.OZONE_SCM_STALENODE_INTERVAL_DEFAULT;
import static org.apache.hadoop.hdds.server.ServerUtils.sanitizeUserArgs;

import org.rocksdb.RocksDBException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -487,4 +489,21 @@ public static MetricsSystem initializeMetrics(
}
return metricsSystem;
}

/**
* Converts RocksDB exception to IOE.
* @param msg - Message to add to exception.
* @param e - Original Exception.
* @return IOE.
*/
public static IOException toIOException(String msg, RocksDBException e) {
String statusCode = e.getStatus() == null ? "N/A" :
e.getStatus().getCodeString();
String errMessage = e.getMessage() == null ? "Unknown error" :
e.getMessage();
String output = msg + "; status : " + statusCode
+ "; message : " + errMessage;
return new IOException(output, e);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
import java.util.List;
import java.util.Map;

import static org.apache.hadoop.hdds.utils.HddsServerUtil.toIOException;

/**
* RocksDB implementation of ozone metadata store.
*/
Expand Down Expand Up @@ -97,16 +99,6 @@ public RocksDBStore(File dbFile, Options options) throws IOException {
}
}

public static IOException toIOException(String msg, RocksDBException e) {
String statusCode = e.getStatus() == null ? "N/A" :
e.getStatus().getCodeString();
String errMessage = e.getMessage() == null ? "Unknown error" :
e.getMessage();
String output = msg + "; status : " + statusCode
+ "; message : " + errMessage;
return new IOException(output, e);
}

@Override
public void put(byte[] key, byte[] value) throws IOException {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
import java.nio.file.Paths;
import java.util.List;

import static org.apache.hadoop.hdds.utils.HddsServerUtil.toIOException;

/**
* A Class that controls the standard config options of RocksDB.
* <p>
Expand Down Expand Up @@ -134,7 +136,7 @@ public static DBOptions readFromFile(String dbFileName,
env, options, cfDescs, true);

} catch (RocksDBException rdEx) {
RDBTable.toIOException("Unable to find/open Options file.", rdEx);
toIOException("Unable to find/open Options file.", rdEx);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static org.apache.hadoop.hdds.utils.HddsServerUtil.toIOException;

/**
* RocksDB Store that supports creating Tables in DB.
*/
Expand Down Expand Up @@ -189,16 +191,6 @@ private List<TableConfig> getColumnFamiliesInExistingDb()
return columnFamiliesInDb;
}

public static IOException toIOException(String msg, RocksDBException e) {
String statusCode = e.getStatus() == null ? "N/A" :
e.getStatus().getCodeString();
String errMessage = e.getMessage() == null ? "Unknown error" :
e.getMessage();
String output = msg + "; status : " + statusCode
+ "; message : " + errMessage;
return new IOException(output, e);
}

@Override
public void compactDB() throws IOException {
if (db != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static org.apache.hadoop.hdds.utils.HddsServerUtil.toIOException;

/**
* RocksDB implementation of ozone metadata store. This class should be only
* used as part of TypedTable as it's underlying implementation to access the
Expand Down Expand Up @@ -71,22 +73,6 @@ class RDBTable implements Table<byte[], byte[]> {
this.rdbMetrics = rdbMetrics;
}

/**
* Converts RocksDB exception to IOE.
* @param msg - Message to add to exception.
* @param e - Original Exception.
* @return IOE.
*/
public static IOException toIOException(String msg, RocksDBException e) {
String statusCode = e.getStatus() == null ? "N/A" :
e.getStatus().getCodeString();
String errMessage = e.getMessage() == null ? "Unknown error" :
e.getMessage();
String output = msg + "; status : " + statusCode
+ "; message : " + errMessage;
return new IOException(output, e);
}

/**
* Returns the Column family Handle.
*
Expand Down

0 comments on commit 836072e

Please sign in to comment.