This repository has been archived by the owner on Mar 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 601
Add support for custom evictor and trigger policies #2653
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
254f4d6
Add support for custom evictor and trigger policies
dancollins34 44da17b
Fixed Checkstyle Issues
dancollins34 ef1357a
Fixed extra line errors, reorganized if statement in WIndowedBoltExec…
dancollins34 3184617
Reversed policy order to fix null pointer exception
dancollins34 6a50ee7
Trial push (local compilation not working for some reason, going to p…
dancollins34 1ef4279
Added Changes necessary to allow custom trigger policies to attach Wi…
dancollins34 5431c76
Fixed test errors due to lack of setting necessary paramters and defi…
dancollins34 0098110
Remove flags and checks on AbstractBaseTriggerPolicy
dancollins34 File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
heron/api/src/java/com/twitter/heron/api/windowing/triggers/AbstractBaseTriggerPolicy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
// 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() { | ||
} | ||
|
||
/** | ||
* 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() { | ||
started = true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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 comment
The 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 comment
The 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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
I see