-
Notifications
You must be signed in to change notification settings - Fork 4k
Add topology stream-awareness to storm-redis #1760
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
38 changes: 38 additions & 0 deletions
38
...nal/storm-redis/src/main/java/org/apache/storm/redis/common/mapper/BasicStreamMapper.java
This file contains hidden or 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,38 @@ | ||
| /* | ||
| * Copyright 2016 The Apache Software Foundation. | ||
| * | ||
| * 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. | ||
| */ | ||
| package org.apache.storm.redis.common.mapper; | ||
|
|
||
| import org.apache.storm.tuple.Tuple; | ||
| import org.apache.storm.tuple.Values; | ||
|
|
||
| /** | ||
| * A StreamMapper implementation which always returns the streamId with | ||
| * which it was constructed. | ||
| */ | ||
| public class BasicStreamMapper implements StreamMapper { | ||
|
|
||
| private final String streamId; | ||
|
|
||
| public BasicStreamMapper(String streamId) { | ||
| this.streamId = streamId; | ||
| } | ||
|
|
||
| @Override | ||
| public String getStreamId(Tuple input, Values values) { | ||
| return streamId; | ||
| } | ||
|
|
||
| } |
29 changes: 29 additions & 0 deletions
29
...l/storm-redis/src/main/java/org/apache/storm/redis/common/mapper/DefaultStreamMapper.java
This file contains hidden or 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,29 @@ | ||
| /* | ||
| * Copyright 2016 The Apache Software Foundation. | ||
| * | ||
| * 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. | ||
| */ | ||
| package org.apache.storm.redis.common.mapper; | ||
|
|
||
| import org.apache.storm.utils.Utils; | ||
|
|
||
| /** | ||
| * A RedisStreamMapper implementation which always returns Storm's default streamId. | ||
| */ | ||
| public final class DefaultStreamMapper extends BasicStreamMapper { | ||
|
|
||
| public DefaultStreamMapper() { | ||
| super(Utils.DEFAULT_STREAM_ID); | ||
| } | ||
|
|
||
| } |
32 changes: 32 additions & 0 deletions
32
...orm-redis/src/main/java/org/apache/storm/redis/common/mapper/InputSourceStreamMapper.java
This file contains hidden or 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,32 @@ | ||
| /* | ||
| * Copyright 2016 The Apache Software Foundation. | ||
| * | ||
| * 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. | ||
| */ | ||
| package org.apache.storm.redis.common.mapper; | ||
|
|
||
| import org.apache.storm.tuple.Tuple; | ||
| import org.apache.storm.tuple.Values; | ||
|
|
||
| /** | ||
| * Returns the streamId of the input tuple's source stream. In other words, | ||
| * tuples will be emitted to the same streamId from which they came. | ||
| */ | ||
| public class InputSourceStreamMapper implements StreamMapper { | ||
|
|
||
| @Override | ||
| public String getStreamId(Tuple input, Values values) { | ||
| return input.getSourceStreamId(); | ||
| } | ||
|
|
||
| } |
38 changes: 38 additions & 0 deletions
38
external/storm-redis/src/main/java/org/apache/storm/redis/common/mapper/StreamMapper.java
This file contains hidden or 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,38 @@ | ||
| /* | ||
| * Copyright 2016 The Apache Software Foundation. | ||
| * | ||
| * 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. | ||
| */ | ||
| package org.apache.storm.redis.common.mapper; | ||
|
|
||
| import java.io.Serializable; | ||
| import org.apache.storm.tuple.Tuple; | ||
| import org.apache.storm.tuple.Values; | ||
|
|
||
| /** | ||
| * StreamMapper is for specifying the stream to which Values should be | ||
| * emitted, based on the input tuple and/or the already mapped output values | ||
| * (about to be emitted). | ||
| */ | ||
| public interface StreamMapper extends Serializable { | ||
|
|
||
| /** | ||
| * Gets the streamId based on the input Tuple and/or the values to be | ||
| * emitted. | ||
| * @param input the original source input tuple | ||
| * @param values the Values which were generated by a bolt, based on the input tuple. | ||
| * @return the stream id to use for emitting tuples | ||
| */ | ||
| String getStreamId(Tuple input, Values values); | ||
|
|
||
| } |
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.
This now creates a lot of coupling between the filter mapper and the stream mapper. Simply because the Filter Mapper is the one that declares the output fields.
So either we need to embrace the coupling and have StreamMapper also be a FilterMapper. (which would require some documentation) or we find a way to fake out FilterMapper and have it declare multiple outputs for what the StreamMapper wants.
I prefer the first one, because it seems like it would be more flexible.
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.
Thanks for taking a look at this. I see your point, and I agree it makes the most sense for both to be done in the same interface. TL;DR is at the bottom ;-)
The same problem also applies to RedisLookupMapper, which also defines
declareOutputFieldsseparately. I just came across STORM-1953.About your first option, would it make more sense for a FilterMapper to be a StreamMapper, rather than a StreamMapper be a FilterMapper? I'm afraid that making StreamMapper a FilterMapper would introduce too much ambiguity in the lookup and filter bolts (if the constructors accepted both), since we'd have to rely on only the docs to define which object's
declareOutputFieldswould be called. It also would make STORM-1953 worse. Or did you mean the bolts only accept FilterMapper, and have something like this inexecute:Either way, if you combine them, one downside is that the provided convenience StreamMapper implementations would have to be sacrificed. Making them abstract probably wouldn't be worth it for something like just specifying the stream.
In case you want to see what having FilterMapper and LookupMapper also extend StreamMapper looks like, I implemented that in a branch here. The flexibility to dynamically choose a stream is there, but the problem is that the trident-related classes also use LookupMapper, and have no need to declare a streamId, yet users will have to implement this method in their LookupMappers. Just returning null is one [not so good] option here, and is also an option when using LookupMapper for bolts (in which case, the existing behavior of emitting to the default stream is maintained).
TL;DR: I can't think of a great solution for what you mentioned, while maintaining user-friendliness of the API, without totally redoing the Mapper interfaces, i.e. STORM-1953. On the other hand, the above commit does maintain full backward compatibility and is probably most convenient for users!
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.
Do you want to target this for master? Or do you also want this in 1.x? If it is just master we can play some games with a default method implementation in the FilterMapper interface.
If you want it in 1.x I would suggest that we leave FilterMapper untouched and create a LookupMapper that also has the same, or similar methods to FilterMapper, but is not a FilterMapper. Then you can have a wrapper class that is a LookupMapper, but takes a FilterMapper. The code could then wrap any FilterMapper passed in, and just use the LookupMapper interface.
I prefer the first one with the default methods because it reduce the number of classes and interfaces but is also binary compatible. If we are not on java 8 like 1.x then we cannot use default methods.