apex-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From PramodSSImmaneni <...@git.apache.org>
Subject [GitHub] incubator-apex-malhar pull request: *Review only* N-DelayOperator
Date Wed, 06 Jan 2016 01:25:53 GMT
Github user PramodSSImmaneni commented on a diff in the pull request:

    https://github.com/apache/incubator-apex-malhar/pull/159#discussion_r48918818
  
    --- Diff: library/src/main/java/com/datatorrent/lib/iteration/nDelayOperator.java ---
    @@ -0,0 +1,186 @@
    +/**
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + *   http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing,
    + * software distributed under the License is distributed on an
    + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    + * KIND, either express or implied.  See the License for the
    + * specific language governing permissions and limitations
    + * under the License.
    + */
    +
    +package com.datatorrent.lib.iteration;
    +
    +import java.io.IOException;
    +import java.util.ArrayList;
    +import javax.validation.constraints.Min;
    +
    +import com.datatorrent.api.Context;
    +import com.datatorrent.api.DefaultInputPort;
    +import com.datatorrent.api.DefaultOutputPort;
    +import com.datatorrent.api.Operator;
    +import com.datatorrent.lib.util.WindowDataManager;
    +import com.datatorrent.netlet.util.DTThrowable;
    +
    +/**
    + * This operator is used in iteration and can do n window delay.
    + * Required delay needs to be set in the constructor, default delay is 1.
    +  *
    + * @displayName nDelayOperator
    + * @category iteration
    +
    + */
    +public class nDelayOperator<T> implements Operator.DelayOperator, Operator.CheckpointListener
    +{
    +  private WindowDataManager windowDataManager = new WindowDataManager.FSWindowDataManager();
    +  @Min(1)
    +  private int delay = 1;
    +  private long currentWindowId;
    +  private transient int operatorContextId;
    +  private transient ArrayList<T> windowData;
    +  private transient Context.OperatorContext context;
    +
    +  public transient DefaultInputPort<T> input = new DefaultInputPort<T>()
{
    +    @Override
    +    public void process(T t)
    +    {
    +      processTuple(t);
    +    }
    +  };
    +
    +  public transient DefaultOutputPort<T> output = new DefaultOutputPort();
    +
    +  public nDelayOperator()
    +  {
    +    init();
    +  }
    +
    +  /*
    +  * @param delay set the delay in number of windows for the tuples.
    +   */
    +  public nDelayOperator(int delay)
    +  {
    +    if ( delay < 1 ) {
    +      throw new IllegalArgumentException("Invalid Delay specified.");
    +    }
    +    this.delay = delay;
    +    init();
    +  }
    +
    +  /*
    +* Get Window Data Manager instance
    +*/
    +  public WindowDataManager getWindowDataManager()
    +  {
    +    return windowDataManager;
    +  }
    +
    +  /*
    +  * Set Window Data Manager instance
    +  */
    +  public void setWindowDataManager(WindowDataManager windowDataManager)
    +  {
    +    this.windowDataManager = windowDataManager;
    +  }
    +
    +  private void init()
    +  {
    +    windowData = new ArrayList<>();
    +  }
    +
    +  @Override
    +  public void setup(Context.OperatorContext context)
    +  {
    +    this.operatorContextId = context.getId();
    +    this.windowDataManager.setup(context);
    +    this.context = context;
    +  }
    +
    +  @Override
    +  public void teardown()
    +  {
    +    this.windowDataManager.teardown();
    +  }
    +
    +  @Override
    +  public void firstWindow()
    +  {
    +    replay(currentWindowId - delay);
    +  }
    +
    +  private void replay( long windowId )
    +  {
    +    if ( windowId < 0 ) {
    +      return;
    +    }
    +
    +    ArrayList<T> recoveredData;
    +    try {
    +      recoveredData = (ArrayList<T>)this.windowDataManager.load(operatorContextId,
windowId);
    +      if (recoveredData == null) {
    +        return;
    +      }
    +      for ( T tuple : recoveredData) {
    +        output.emit(tuple);
    +      }
    +    } catch (IOException e) {
    +      DTThrowable.rethrow(e);
    +    }
    +  }
    +
    +  @Override
    +  public void beginWindow(long windowId)
    +  {
    +    currentWindowId = windowId;
    +
    +    if ( delay > 1 ) {
    +      replay(windowId - delay + 1);
    --- End diff --
    
    I don't think operator should be doing this. We should enhance the platform to do the
n-delay by incrementing the window id by n for data transmitted in a window. This should have
to be managed within the operator where operator is doing (n-1) and platform is doing +1.
My suggestion is to implement n delay in platform and take this operator after. Also when
that happens the operator needs to only save data from (checkpoint-n, checkpoint] window range.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message