HDDS-14916. Add a code generator for implementing invokeLocal(..).#9996
Merged
szetszwo merged 5 commits intoapache:masterfrom Mar 29, 2026
Merged
HDDS-14916. Add a code generator for implementing invokeLocal(..).#9996szetszwo merged 5 commits intoapache:masterfrom
szetszwo merged 5 commits intoapache:masterfrom
Conversation
Contributor
Author
|
Output for // Code generated for DeletedBlockLogStateManager. Do not modify.
@SuppressWarnings("unchecked")
@Override
public Object invokeLocal(String methodName, Object[] params) throws Exception {
switch (methodName) {
case "onFlush": {
impl.onFlush();
return null;
}
case "addTransactionsToDB": {
final ArrayList arg0 = params.length > 0 ? (ArrayList) params[0] : null;
final DeletedBlocksTransactionSummary arg1 = params.length > 1 ? (DeletedBlocksTransactionSummary) params[1] : null;
impl.addTransactionsToDB(arg0, arg1);
return null;
}
case "removeTransactionsFromDB": {
final ArrayList arg0 = params.length > 0 ? (ArrayList) params[0] : null;
final DeletedBlocksTransactionSummary arg1 = params.length > 1 ? (DeletedBlocksTransactionSummary) params[1] : null;
impl.removeTransactionsFromDB(arg0, arg1);
return null;
}
case "getReadOnlyIterator": {
return impl.getReadOnlyIterator();
}
case "reinitialize": {
final Table arg0 = params.length > 0 ? (Table) params[0] : null;
final Table arg1 = params.length > 1 ? (Table) params[1] : null;
impl.reinitialize(arg0, arg1);
return null;
}
}
throw new IllegalArgumentException("Method not found: " + methodName);
} |
Contributor
|
Thanks @szetszwo for working on this. LGTM! |
Russole
approved these changes
Mar 29, 2026
adoroszlai
reviewed
Mar 29, 2026
Contributor
adoroszlai
left a comment
There was a problem hiding this comment.
Thanks @szetszwo for the patch.
For the record, the tool can be run from CLI as:
cd hadoop-ozone/dist/target/ozone-2.2.0-SNAPSHOT
java -cp $(echo share/ozone/lib/*.jar | sed 's/ /:/g') org.apache.hadoop.hdds.scm.block.DeletedBlockLogStateManager|
|
||
| final String switchName = method.getParameterName(0); | ||
| printf("switch (%s)", switchName); | ||
| try (UncheckedAutoCloseable ignored = printScope()) { |
Contributor
There was a problem hiding this comment.
switch and case should be on the same level to satisfy this (unfortunate) checkstyle rule:
(We can work on getting rid of the rule separately, since it needs lots of code changes.)
| final String switchName = method.getParameterName(0); | ||
| printf("switch (%s)", switchName); | ||
| try (UncheckedAutoCloseable ignored = printScope()) { | ||
| for (Method apiMethod : api.getMethods()) { |
Contributor
There was a problem hiding this comment.
I think we should sort methods alphabetically. This would stabilize order, reducing diff after regenerating code when the interface is changed.
Contributor
Author
|
@Russole , @adoroszlai , thanks for reviewing this!
/** Code generated for DeletedBlockLogStateManager. Do not modify. */
public class DeletedBlockLogStateManagerInvoker implements ScmInvoker<DeletedBlockLogStateManager> {
private final DeletedBlockLogStateManager impl;
public DeletedBlockLogStateManagerInvoker(DeletedBlockLogStateManager impl) {
this.impl = impl;
}
@Override
public RequestType getType() {
return RequestType.BLOCK;
}
@Override
public Class<DeletedBlockLogStateManager> getApi() {
return DeletedBlockLogStateManager.class;
}
@Override
public DeletedBlockLogStateManager getImpl() {
return impl;
}
@SuppressWarnings("unchecked")
@Override
public Object invokeLocal(String methodName, Object[] params) throws Exception {
switch (methodName) {
case "addTransactionsToDB":
final ArrayList arg0 = params.length > 0 ? (ArrayList) params[0] : null;
final DeletedBlocksTransactionSummary arg1 = params.length > 1 ? (DeletedBlocksTransactionSummary) params[1] : null;
impl.addTransactionsToDB(arg0, arg1);
return null;
case "getReadOnlyIterator":
return impl.getReadOnlyIterator();
case "onFlush":
impl.onFlush();
return null;
case "reinitialize":
final Table arg2 = params.length > 0 ? (Table) params[0] : null;
final Table arg3 = params.length > 1 ? (Table) params[1] : null;
impl.reinitialize(arg2, arg3);
return null;
case "removeTransactionsFromDB":
final ArrayList arg4 = params.length > 0 ? (ArrayList) params[0] : null;
final DeletedBlocksTransactionSummary arg5 = params.length > 1 ? (DeletedBlocksTransactionSummary) params[1] : null;
impl.removeTransactionsFromDB(arg4, arg5);
return null;
default:
throw new IllegalArgumentException("Method not found: " + methodName + " in DeletedBlockLogStateManager");
}
}
} |
adoroszlai
approved these changes
Mar 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this pull request?
Given an interface, generate the code for all the local calls.
What is the link to the Apache JIRA
HDDS-14916
How was this patch tested?
Tested manually.