adoroszlai commented on code in PR #7652:
URL: https://github.com/apache/ozone/pull/7652#discussion_r1908458268
##########
hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/DBDefinitionFactory.java:
##########
@@ -98,6 +102,56 @@ public static DBDefinition getDefinition(Path dbPath,
return getDefinition(dbName);
}
+ public static List<CheckedSupplier<DBDefinition, Exception>> getFactories(
Review Comment:
This can be package-private.
```suggestion
static List<CheckedSupplier<DBDefinition, Exception>> getFactories(
```
##########
hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/debug/DBDefinitionFactory.java:
##########
@@ -98,6 +102,56 @@ public static DBDefinition getDefinition(Path dbPath,
return getDefinition(dbName);
}
+ public static List<CheckedSupplier<DBDefinition, Exception>> getFactories(
+ Class<?> clazz, String dbPathString, ConfigurationSource config) {
+ return Arrays.asList(
+ () -> {
+ Method factoryMethod = clazz.getDeclaredMethod("get");
+ factoryMethod.setAccessible(true);
+ return (DBDefinition) factoryMethod.invoke(clazz);
+ },
+ () -> {
+ Constructor<?> constructor = clazz.getDeclaredConstructor();
+ constructor.setAccessible(true);
+ return (DBDefinition) constructor.newInstance();
+ },
+ () -> {
+ Constructor<?> constructor =
clazz.getDeclaredConstructor(String.class);
+ constructor.setAccessible(true);
+ return (DBDefinition) constructor.newInstance(dbPathString);
+ },
+ () -> {
+ Constructor<?> constructor =
clazz.getDeclaredConstructor(String.class, ConfigurationSource.class);
+ constructor.setAccessible(true);
+ return (DBDefinition) constructor.newInstance(dbPathString, config);
+ }
Review Comment:
On second thought, we might want to reorder these, to ensure the constructor
with more params is picked first (so that the config and DB path are not
ignored).
##########
hadoop-ozone/tools/src/test/java/org/apache/hadoop/ozone/debug/TestDBDefinitionFactory.java:
##########
@@ -75,4 +84,48 @@ public void testGetDefinition() {
definition = DBDefinitionFactory.getDefinition(dbPath, conf);
assertInstanceOf(DatanodeSchemaThreeDBDefinition.class, definition);
}
+
+ @Test
+ public void testGetDefinitionWithOverride() {
+ final OzoneConfiguration conf = new OzoneConfiguration();
+ Path dbPath = Paths.get("another.db");
+ DBDefinition definition = DBDefinitionFactory.getDefinition(dbPath, conf,
OMDBDefinition.class.getName());
+ assertInstanceOf(OMDBDefinition.class, definition);
+ }
+
+ /*
+ * Test to ensure that any DBDefinition has a default constructor or a
constructor with 1 parameter.
+ * This is needed for ldb tools to run with arbitrary DB definitions.
+ */
+ @Test
+ public void testAllDBDefinitionsHaveCorrectConstructor() {
+ Set<Class<?>> subclasses = new HashSet<>();
+ try {
+ Reflections reflections = new Reflections("org.apache.hadoop");
+ subclasses.addAll(reflections.getSubTypesOf(DBDefinition.class));
+
subclasses.remove(Class.forName("org.apache.hadoop.hdds.utils.db.DBDefinition$WithMap"));
+
subclasses.remove(Class.forName("org.apache.hadoop.hdds.utils.db.DBDefinition$WithMapInterface"));
+ subclasses.remove(Class.forName(
+
"org.apache.hadoop.ozone.container.metadata.AbstractDatanodeDBDefinition"));
Review Comment:
No need to use reflection for removing these classes.
```suggestion
subclasses.remove(DBDefinition.WithMap.class);
subclasses.remove(DBDefinition.WithMapInterface.class);
subclasses.remove(AbstractDatanodeDBDefinition.class);
```
(needs imports)
##########
hadoop-ozone/tools/src/test/java/org/apache/hadoop/ozone/debug/TestDBDefinitionFactory.java:
##########
@@ -75,4 +84,48 @@ public void testGetDefinition() {
definition = DBDefinitionFactory.getDefinition(dbPath, conf);
assertInstanceOf(DatanodeSchemaThreeDBDefinition.class, definition);
}
+
+ @Test
+ public void testGetDefinitionWithOverride() {
+ final OzoneConfiguration conf = new OzoneConfiguration();
+ Path dbPath = Paths.get("another.db");
+ DBDefinition definition = DBDefinitionFactory.getDefinition(dbPath, conf,
OMDBDefinition.class.getName());
+ assertInstanceOf(OMDBDefinition.class, definition);
+ }
+
+ /*
+ * Test to ensure that any DBDefinition has a default constructor or a
constructor with 1 parameter.
+ * This is needed for ldb tools to run with arbitrary DB definitions.
+ */
+ @Test
+ public void testAllDBDefinitionsHaveCorrectConstructor() {
+ Set<Class<?>> subclasses = new HashSet<>();
+ try {
+ Reflections reflections = new Reflections("org.apache.hadoop");
Review Comment:
Packages under `org.apache.hadoop` are kept as legacy, we also use
`org.apache.ozone`.
```suggestion
Reflections reflections = new Reflections("org.apache");
```
--
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]