Skip to content

HDDS-14916. Add a code generator for implementing invokeLocal(..).#9996

Merged
szetszwo merged 5 commits intoapache:masterfrom
szetszwo:HDDS-14916
Mar 29, 2026
Merged

HDDS-14916. Add a code generator for implementing invokeLocal(..).#9996
szetszwo merged 5 commits intoapache:masterfrom
szetszwo:HDDS-14916

Conversation

@szetszwo
Copy link
Copy Markdown
Contributor

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.

@szetszwo
Copy link
Copy Markdown
Contributor Author

Output for DeletedBlockLogStateManager:

  // 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);
  }

@Russole
Copy link
Copy Markdown
Contributor

Russole commented Mar 29, 2026

Thanks @szetszwo for working on this. LGTM!

Copy link
Copy Markdown
Contributor

@adoroszlai adoroszlai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

switch and case should be on the same level to satisfy this (unfortunate) checkstyle rule:

<property name="caseIndent" value="0"/>

(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()) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should sort methods alphabetically. This would stabilize order, reducing diff after regenerating code when the interface is changed.

@szetszwo
Copy link
Copy Markdown
Contributor Author

szetszwo commented Mar 29, 2026

@Russole , @adoroszlai , thanks for reviewing this!

  • Fixed the case indentation checkstyple problem.
  • Sorted the methods in switch.
  • It can generate the entire class now.
/** 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");
    }
  }
}

@szetszwo szetszwo merged commit a01ad89 into apache:master Mar 29, 2026
45 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants