Skip to content

Conversation

adnanhemani
Copy link
Contributor

@adnanhemani adnanhemani commented Jun 16, 2025

Adding instrumentation for events for all events defined in PolarisServiceImpl.java. Not all events will be useful and/or necessary - but allow users to plug in with custom event listeners for any of these APIs. The default event listener is a no-op.

The main file to review here is PolarisServiceImpl. All new events are simply just a constructor and getter methods.

@adnanhemani adnanhemani reopened this Jun 16, 2025
@github-project-automation github-project-automation bot moved this from Done to PRs In Progress in Basic Kanban Board Jun 16, 2025
eric-maynard
eric-maynard previously approved these changes Jul 17, 2025
Copy link
Contributor

@eric-maynard eric-maynard left a comment

Choose a reason for hiding this comment

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

LGTM! This isn't all the new events we'll need to add but it's a good start.

@github-project-automation github-project-automation bot moved this from PRs In Progress to Ready to merge in Basic Kanban Board Jul 17, 2025
@adnanhemani
Copy link
Contributor Author

@eric-maynard - any way to retrigger the tests? Seems like it failed on a processing step unrelated to the changes.

@snazy
Copy link
Member

snazy commented Jul 17, 2025

This PR received a lot of comments, should wait for @adutra's review as well.

Copy link
Member

@snazy snazy left a comment

Choose a reason for hiding this comment

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

This change exposes secrets to event listeners, which is quite concerning.

I've posted a bunch of comments for discussion about the approach on the dev-ML.

@github-project-automation github-project-automation bot moved this from Ready to merge to PRs In Progress in Basic Kanban Board Jul 17, 2025
@adnanhemani adnanhemani requested a review from snazy July 21, 2025 07:58
eric-maynard
eric-maynard previously approved these changes Jul 22, 2025
Copy link
Contributor

@eric-maynard eric-maynard left a comment

Choose a reason for hiding this comment

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

Still LGTM, and the secrets are gone from the events now which is good

@eric-maynard
Copy link
Contributor

@snazy are there still changes you'd like to see here?

@snazy
Copy link
Member

snazy commented Aug 5, 2025

Yea, I think we should simplify and enhance the API, as proposed on dev@

@adnanhemani
Copy link
Contributor Author

@snazy - I've replied on the referenced email thread >2 weeks ago but there is not any response to any of the comments on the thread since then. If you have a hard opinion on this, can you please reply to the email thread to keep this work moving forward?

If there is not a hard opinion, I will continue pushing to get this PR merged as-is.

@snazy
Copy link
Member

snazy commented Aug 6, 2025

My impression was that you're working on the proposed ideas.

My (hard) opinion on this is that we have to allow event listeners to
a) associate after with before events
b) opt in to get success/failure results
and to reduce the amount of code that is necessary in call sites and listener implementations and events themselves.

Copy link
Contributor

@singhpk234 singhpk234 left a comment

Choose a reason for hiding this comment

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

can we have all the records in one class ?

@eric-maynard
Copy link
Contributor

eric-maynard commented Aug 8, 2025

The current events aren't all in one file, so while I think grouping them that way is fine we should be consistent.

IIUC association* of different events is possible (and intended) on the EventListener side.

@adnanhemani
Copy link
Contributor Author

The current events aren't all in one file, so while I think grouping them that way is fine we should be consistent.

Agreed, I can do this in the next round of revisions. But am waiting for the followup meeting regarding events to put further work in on this PR.

IIUC associated of different events is possible (and intended) on the EventListener side.

This is correct as well. @snazy - does that resolve your concerns?

@snazy
Copy link
Member

snazy commented Aug 14, 2025

Thanks for removing the secrets.

But I still believe that it can be simplified, and have the currently missing the failure notifications. I've proposed a way to achieve this using Java pseudo code on the dev-ML. Adding it here as well below.

public interface EventListener {
  /**
   * "Dummy event foo" about to happen, with parameters x + y, no additional information collected
   * for "after the fact".
   */
  InFlightVoid beforeEventFoo(String x, int y);

  /** About to commit to an Iceberg table. */
  InFlight<IcebergTableCommitted> beforeIcebergTableCommit(UpdateTableRequest updateTableRequest);
}

public interface InFlight<SUCCESS_PAYLOAD> {
  /** Called "after the fact". */
  void success(SUCCESS_PAYLOAD payload);

  /** Potentially called "after the fact" in case of a failure. */
  void failure(Throwable throwable);

  /** Potentially called "after the fact" in case of a failure. */
  void failure(String reason);
}

/** Convenience for events that do not have a success-payload. */
public interface InFlightVoid extends InFlight<Void> {
  default void success() {
    success(null);
  }
}

/** Success-payload for table-committed. */
public record IcebergTableCommitted(TableMetadata originalState, TableMetadata newState) {}

Example for a simple event "foo", w/o a success-payload:

public interface Foo {
  void doFoo();
}

class FooImpl implements Foo {
  EventListener eventListener;

  @Override
  public void doFoo() {
    InFlightVoid event = eventListener.beforeEventFoo("foo", 42);
    try {
      // do foo stuff
      event.success();
    } catch (Exception x) {
      event.failure(x);
    }
  }
}

Example for table committed, with update-request, before and after states. Up to the event listener implementation which parts are consumed.

public interface Commit {
  void doCommit(UpdateTableRequest updateTableRequest);
}

class CommitImpl implements Commit {
  EventListener eventListener;

  @Override
  public void doCommit(UpdateTableRequest updateTableRequest) {
    InFlight<IcebergTableCommitted> event =
        eventListener.beforeIcebergTableCommit(updateTableRequest);
    try {
      // do table commit
      TableMetadata previousTableMetadata = ...;
      if (somePreconditionFailed) {
        event.failure("Precondition xyz failed");
        return;
      }
      TableMetadata updatedTableMetadata = ...;
      event.success(new IcebergTableCommitted(previousTableMetadata, updatedTableMetadata));
    } catch (Exception x) {
      event.failure(x);
    }
  }
}

@adnanhemani
Copy link
Contributor Author

Further discussion on stateful event handling is on the Dev ML.

@adnanhemani
Copy link
Contributor Author

Closed in favor of #2482.

@github-project-automation github-project-automation bot moved this from PRs In Progress to Done in Basic Kanban Board Aug 31, 2025
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.

5 participants