[ 
https://issues.apache.org/jira/browse/TEZ-1447?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14122439#comment-14122439
 ] 

Bikas Saha commented on TEZ-1447:
---------------------------------

There should probably be an unregister API to mirror the register API so that 
users can unregister from notifications.

Rename since this is not always a vertex state. Maybe just call is 
VertexNotification
{code}+public enum VertexState {{code}

I still dont understand the usefulness of VertexStateUpdateParallelismUpdated 
when getting a notification with ENUM.parallelism_updated can be followed up 
with context.getVertexNumTasks(Vertex) to get the same information.

Visibility of these methods not public?
{code}-  public int getVertexNumTasks(String vertexName);
+  int getVertexNumTasks(String vertexName);
+
+  /**
+   * Register to get notifications on updates to the specified vertex. 
Notifications will be sent
+   * via {@link 
org.apache.tez.runtime.api.InputInitializer#onVertexStatusUpdated(org.apache.tez.dag.api.event.VertexStatusUpdateEvent)}
+   *
+   * @param vertexName the vertex name for which notifications are required.
+   */
+  void registerForVertexStatusUpdates(String vertexName);{code}

Shouldnt this be in tez-dag project?
tez-common/src/main/java/org/apache/tez/state/OnStateChangedCallback.java

The StateChangeNotifier should not be in business of understanding the 
notifications logical meaning. That should be in the publisher of the 
notification. Specifically, it should not have separate methods for stateChange 
and updateParallelism. It should just have a receiveNotification() method. 
Similarly this is unnecessarily leaking Vertex knowledge into the notifier. 
This could easily be in the vertex where the vertex converts its interesting 
event into a notification event.
{code}
+  private org.apache.tez.dag.api.event.VertexState 
convertInternalState(VertexState vertexState,
+                                                                 TezVertexID 
vertexId) {
+    switch (vertexState) {
+      case RUNNING:
+        return org.apache.tez.dag.api.event.VertexState.RUNNING;
+      case SUCCEEDED:
+        return org.apache.tez.dag.api.event.VertexState.SUCCEEDED;{code}
This way the notifier does not have to be kept in sync with Vertex and can more 
easily to be used for a generic set of notifications without needing to change 
it.
If this logic moves back into vertex, where its self contained, then 
VertexImpl.handle() just needs to check for the relevant state and  make the 
conversion to the correct ENUM and call the generic notify method on the 
Notifier. We may not have to extend the StateMachine.

Also a change of name to PubSubNotifier or something like that would be good.

It may be better to store per vertex per enum a boolean that shows whether that 
notification has been received or not. Then, when a listener subscribed to an 
ENUM that has already occurred then we can immediately notify it about that 
ENUM. It does not seem correct to notify the listener about the last known 
state. It implies an implicit order of states, gives users notifications that 
they dont need etc.
Also, it might be better to rename the notification enums to something that 
denotes an event having occurred e.g. has_started_running, has_succeeded. Not 
only is this clearer about the notification being post-facto, it also clears 
receiving a notification immediately about vertex.has_started_running when the 
vertex may have already succeeded because the notification is about something 
that has already occurred.


> Provide a mechanism for InputInitializers to know about interesting Vertex 
> state changes
> ----------------------------------------------------------------------------------------
>
>                 Key: TEZ-1447
>                 URL: https://issues.apache.org/jira/browse/TEZ-1447
>             Project: Apache Tez
>          Issue Type: Bug
>    Affects Versions: 0.5.0
>            Reporter: Gunther Hagleitner
>            Assignee: Siddharth Seth
>            Priority: Blocker
>         Attachments: TEZ-1447.1.wip.txt, TEZ-1447.2.txt, TEZ-1447.3.txt
>
>
> I'm trying to do dynamic partition pruning through input initializer events 
> in Hive. That means that the initializer of a table scan vertex has to 
> receive events from all tasks in another vertex (which contain the pruning 
> info) before generating tasks to run.
> The problem with the current API I ran into:
> getNumTasks: I'm currently using a busy loop to wait for the num tasks for a 
> vertex to be decided (-1 -> x). There's no way around it, because it's the 
> only way to find out what number of events to expect (0 is a valid number of 
> tasks - so I can't wait for the first to complete).
> With auto-reducer parallelism I have to employ another busy loop. Because I 
> might be initially expecting 10 events, which later get's knocked down to 5. 
> Since there's no event associated with this, I have to periodically check 
> whether I have enough events.
> Versioning: Events have a version number, but I don't know which task they 
> are coming from. Thus I can't de-dup events.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to