-
Notifications
You must be signed in to change notification settings - Fork 601
Add support for custom evictor and trigger policies #2653
Changes from 7 commits
254f4d6
44da17b
ef1357a
3184617
6a50ee7
1ef4279
5431c76
0098110
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,10 +30,10 @@ | |
* limitations under the License. | ||
*/ | ||
|
||
|
||
package com.twitter.heron.api.windowing; | ||
|
||
import java.io.Serializable; | ||
import java.util.Map; | ||
|
||
/** | ||
* Triggers the window calculations based on the policy. | ||
|
@@ -80,4 +80,32 @@ public interface TriggerPolicy<T extends Serializable, S> { | |
* @param state the state | ||
*/ | ||
void restoreState(S state); | ||
|
||
/** | ||
* Set the eviction policy to whatever eviction policy to use this with | ||
* | ||
* @param evictionPolicy the eviction policy | ||
*/ | ||
void setEvictionPolicy(EvictionPolicy<T, ?> evictionPolicy); | ||
|
||
/** | ||
* Set the trigger handler for this trigger policy to trigger | ||
* | ||
* @param triggerHandler the trigger handler | ||
*/ | ||
void setTriggerHandler(TriggerHandler triggerHandler); | ||
|
||
/** | ||
* Sets the window manager that uses this trigger policy | ||
* | ||
* @param windowManager the window manager | ||
*/ | ||
void setWindowManager(WindowManager<T> windowManager); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should remove this from the interface. Having this interface is confusing to users since WindowManager implements the TriggerHandler interface. WindowManager is also not a interface that users can implement thus it shouldn't be part of an interface that users will have to implement. I think having "setTriggerHandler" should suffice. For build in triggers (e.g. WatermarkCountTriggerPolicy, WatermarkTimeTriggerPolicy), we can just pass in the WindowManager via their constructor. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The reasoning behind this was that the WindowManager, TriggerHandler (which is the WindowManager) and TopologyConfig are three things the users may not have access to directly. I was aiming to provide access to the same structures used in the internal TriggerPolicies to custom TriggerPolicies, should users wish to use them. The idea was that, if someone wanted to, it should be possible to use the existing trigger policies in this manner. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looking more closely at the code I am confused how the a custom trigger policy will work. All the existing trigger policies require the WindowManager to actually trigger windows. How will a user implementing a custom TriggerPolicy do this. They have no reference to the WindowManager. Shouldn't the windowManager be passed into the custom trigger implicitly? As of right now, trigger polices can't trigger windows without the WindowManager. That is why I suggested removing the setWindowManager interface, since trigger policies need the window manager regardless of what kind of trigger policy it is. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Take a look at the changes i’ve made to windowedBoltExecutor. Essentially, in order to allow these to attach to arbitrary triggerPolicies, Ive replaced their inclusion in the constructor with the setters you see in the interface for all trigger policies. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see |
||
|
||
/** | ||
* Sets the Config used for this topology | ||
* | ||
* @param config the configuration policy | ||
*/ | ||
void setTopologyConfig(Map<String, Object> config); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
// Copyright 2017 Twitter. All rights reserved. | ||
// | ||
// Licensed 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. | ||
|
||
/** | ||
* 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.twitter.heron.api.windowing.triggers; | ||
|
||
import java.io.Serializable; | ||
import java.util.Map; | ||
|
||
import com.twitter.heron.api.windowing.EvictionPolicy; | ||
import com.twitter.heron.api.windowing.TriggerHandler; | ||
import com.twitter.heron.api.windowing.TriggerPolicy; | ||
import com.twitter.heron.api.windowing.WindowManager; | ||
|
||
|
||
public abstract class AbstractBaseTriggerPolicy<T extends Serializable, S> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if this interface is necessary, if we remove WindowManager from the TriggerPolicy interface There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Regardless, you would still need a way to get the TriggerHandler (WindowPolicy) attached to the custom TriggerPolicy that was passed to the config. AbstractBaseTriggerPolicy was just made as a way to standardize how these attachments were handled for the internal classes, and provide a way to use those same attachment variables in custom classes. |
||
implements TriggerPolicy<T, S> { | ||
protected TriggerHandler handler; | ||
protected EvictionPolicy<T, ?> evictionPolicy; | ||
protected WindowManager<T> windowManager; | ||
protected Boolean started; | ||
protected Map<String, Object> topoConf; | ||
|
||
private boolean requiresEvictionPolicy = false; | ||
private boolean requiresWindowManager = false; | ||
private boolean requiresTopologyConfig = false; | ||
|
||
/** | ||
* Set the requirements in the constructor | ||
*/ | ||
public AbstractBaseTriggerPolicy(boolean requiresEvictionPolicy, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if we need these checks. I think it should be up to the user to make sure to pass in the correct objects he or she needs for a custom trigger. Having to pass these booleans into the constructor also makes the interface confusing to some reading to code. If you really want these checks in place, I would suggest using setters to set these. Then it is clear to the reader of the code what is being set. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jerrypeng These checks were in place to keep the existing trigger policies as restrictive as they were before wrt which of the objects (evictionPolicy, windowManager) were attached. I could provide an alternate no-arg constructor that sets them all to false, then use setters instead? However, since this is the abstract class which already partially implements the TriggerPolicy interface, I would think it would be okay to perform some checks, but I have no issue with removing them either. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lets remove them to keep the interface as simple and clean as possible There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jerrypeng will do |
||
boolean requiresWindowManager, | ||
boolean requiresTopologyConfig) { | ||
this.requiresEvictionPolicy = requiresEvictionPolicy; | ||
this.requiresWindowManager = requiresWindowManager; | ||
this.requiresTopologyConfig = requiresTopologyConfig; | ||
} | ||
|
||
/** | ||
* Set the eviction policy to whatever eviction policy to use this with | ||
* | ||
* @param evictionPolicy the eviction policy | ||
*/ | ||
public void setEvictionPolicy(EvictionPolicy<T, ?> evictionPolicy) { | ||
this.evictionPolicy = evictionPolicy; | ||
} | ||
|
||
/** | ||
* Set the trigger handler for this trigger policy to trigger | ||
* | ||
* @param triggerHandler the trigger handler | ||
*/ | ||
public void setTriggerHandler(TriggerHandler triggerHandler) { | ||
this.handler = triggerHandler; | ||
} | ||
|
||
/** | ||
* Sets the window manager that uses this trigger policy | ||
* | ||
* @param windowManager the window manager | ||
*/ | ||
public void setWindowManager(WindowManager<T> windowManager) { | ||
this.windowManager = windowManager; | ||
} | ||
|
||
/** | ||
* Sets the Config used for this topology | ||
* | ||
* @param config the configuration object | ||
*/ | ||
public void setTopologyConfig(Map<String, Object> config) { | ||
this.topoConf = config; | ||
} | ||
|
||
/** | ||
* Starts the trigger policy. This can be used | ||
* during recovery to start the triggers after | ||
* recovery is complete. | ||
*/ | ||
@Override | ||
public void start() { | ||
if (this.evictionPolicy == null && this.requiresEvictionPolicy) { | ||
throw new RuntimeException("EvictionPolicy of TriggerPolicy was not set."); | ||
} | ||
|
||
if (this.handler == null) { | ||
throw new RuntimeException("TriggerHandler of TriggerPolicy was not set."); | ||
} | ||
|
||
if (this.windowManager == null && this.requiresWindowManager) { | ||
throw new RuntimeException("WindowManager of TriggerPolicy was not set."); | ||
} | ||
|
||
if (this.topoConf == null && this.requiresTopologyConfig) { | ||
throw new RuntimeException("WindowManager of TriggerPolicy was not set."); | ||
} | ||
|
||
started = true; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Place remove extra line