You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@storm.apache.org by OuYangLiang <gi...@git.apache.org> on 2017/12/20 15:01:08 UTC

[GitHub] storm pull request #2476: Minor optimisation about trident kafka state

GitHub user OuYangLiang opened a pull request:

    https://github.com/apache/storm/pull/2476

    Minor optimisation about trident kafka state

    Make TridentKafkaState a template class to eliminate warning messages in eclipse, and a minor optimisation that use StringBuilder.append instead of string concat operation.

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/OuYangLiang/storm master

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/storm/pull/2476.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #2476
    
----
commit 97df3fb1632b6a6411c9f0598ac70e98d52cc654
Author: OuYang Liang <ou...@...>
Date:   2017-12-20T14:51:29Z

    Make TridentKafkaState a template class to eliminate warning messages in
    eclipse, and a minor optimization that use StringBuilder.append instead
    of string concat operation.

----


---

[GitHub] storm pull request #2476: Minor optimisation about trident kafka state

Posted by srdo <gi...@git.apache.org>.
Github user srdo commented on a diff in the pull request:

    https://github.com/apache/storm/pull/2476#discussion_r158124954
  
    --- Diff: external/storm-kafka-client/src/main/java/org/apache/storm/kafka/trident/TridentKafkaState.java ---
    @@ -89,19 +87,19 @@ public void updateState(List<TridentTuple> tuples, TridentCollector collector) {
                 List<Future<RecordMetadata>> futures = new ArrayList<>(numberOfRecords);
                 for (TridentTuple tuple : tuples) {
                     topic = topicSelector.getTopic(tuple);
    -                Object messageFromTuple = mapper.getMessageFromTuple(tuple);
    -                Object keyFromTuple = mapper.getKeyFromTuple(tuple);
    +                V messageFromTuple = mapper.getMessageFromTuple(tuple);
    +                K keyFromTuple = mapper.getKeyFromTuple(tuple);
     
                     if (topic != null) {
                         if (messageFromTuple != null) {
    -                        Future<RecordMetadata> result = producer.send(new ProducerRecord(topic, keyFromTuple, messageFromTuple));
    +                        Future<RecordMetadata> result = producer.send(new ProducerRecord<K, V>(topic, keyFromTuple, messageFromTuple));
    --- End diff --
    
    Pretty sure the `<>` will also work here


---

[GitHub] storm pull request #2476: Minor optimisation about trident kafka state

Posted by srdo <gi...@git.apache.org>.
Github user srdo commented on a diff in the pull request:

    https://github.com/apache/storm/pull/2476#discussion_r158125370
  
    --- Diff: external/storm-kafka-client/src/main/java/org/apache/storm/kafka/trident/TridentKafkaStateFactory.java ---
    @@ -28,33 +28,34 @@
     import org.slf4j.Logger;
     import org.slf4j.LoggerFactory;
     
    -public class TridentKafkaStateFactory implements StateFactory {
    +public class TridentKafkaStateFactory<K, V> implements StateFactory {
     
    +    private static final long serialVersionUID = -3613240970062343385L;
         private static final Logger LOG = LoggerFactory.getLogger(TridentKafkaStateFactory.class);
     
    -    private TridentTupleToKafkaMapper mapper;
    +    private TridentTupleToKafkaMapper<K, V> mapper;
         private KafkaTopicSelector topicSelector;
         private Properties producerProperties = new Properties();
     
    -    public TridentKafkaStateFactory withTridentTupleToKafkaMapper(TridentTupleToKafkaMapper mapper) {
    +    public TridentKafkaStateFactory<K, V> withTridentTupleToKafkaMapper(TridentTupleToKafkaMapper<K, V> mapper) {
             this.mapper = mapper;
             return this;
         }
     
    -    public TridentKafkaStateFactory withKafkaTopicSelector(KafkaTopicSelector selector) {
    +    public TridentKafkaStateFactory<K, V> withKafkaTopicSelector(KafkaTopicSelector selector) {
             this.topicSelector = selector;
             return this;
         }
     
    -    public TridentKafkaStateFactory withProducerProperties(Properties props) {
    +    public TridentKafkaStateFactory<K, V> withProducerProperties(Properties props) {
             this.producerProperties = props;
             return this;
         }
     
         @Override
         public State makeState(Map<String, Object> conf, IMetricsContext metrics, int partitionIndex, int numPartitions) {
             LOG.info("makeState(partitonIndex={}, numpartitions={}", partitionIndex, numPartitions);
    -        TridentKafkaState state = new TridentKafkaState()
    +        TridentKafkaState<K, V> state = new TridentKafkaState<K, V>()
    --- End diff --
    
    Can use `<>` on the right hand side


---

[GitHub] storm pull request #2476: STORM-2864: Minor optimisation about trident kafka...

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/storm/pull/2476


---

[GitHub] storm issue #2476: STORM-2864: Minor optimisation about trident kafka state

Posted by srdo <gi...@git.apache.org>.
Github user srdo commented on the issue:

    https://github.com/apache/storm/pull/2476
  
    @OuYangLiang Thanks for contributing. Merged to master and 1.x-branch. Keep up the good work.


---

[GitHub] storm pull request #2476: Minor optimisation about trident kafka state

Posted by OuYangLiang <gi...@git.apache.org>.
Github user OuYangLiang commented on a diff in the pull request:

    https://github.com/apache/storm/pull/2476#discussion_r158179810
  
    --- Diff: external/storm-kafka-client/src/main/java/org/apache/storm/kafka/trident/TridentKafkaState.java ---
    @@ -116,8 +114,9 @@ public void updateState(List<TridentTuple> tuples, TridentCollector collector) {
                 }
     
                 if (exceptions.size() > 0) {
    -                StringBuilder errorMsg = new StringBuilder("Could not retrieve result for messages " + tuples + " from topic = " + topic
    -                    + " because of the following exceptions:" + System.lineSeparator());
    +                StringBuilder errorMsg = new StringBuilder("Could not retrieve result for messages ");
    --- End diff --
    
    There's a foreach statement right below it to iterate the exceptions, and append each exception to the errorMsg, it is still necessary I think.
    
    for (ExecutionException exception : exceptions) {
        errorMsg = errorMsg.append(exception.getMessage()).append(System.lineSeparator());
    }


---

[GitHub] storm pull request #2476: Minor optimisation about trident kafka state

Posted by srdo <gi...@git.apache.org>.
Github user srdo commented on a diff in the pull request:

    https://github.com/apache/storm/pull/2476#discussion_r158203266
  
    --- Diff: external/storm-kafka-client/src/main/java/org/apache/storm/kafka/trident/TridentKafkaState.java ---
    @@ -116,8 +114,9 @@ public void updateState(List<TridentTuple> tuples, TridentCollector collector) {
                 }
     
                 if (exceptions.size() > 0) {
    -                StringBuilder errorMsg = new StringBuilder("Could not retrieve result for messages " + tuples + " from topic = " + topic
    -                    + " because of the following exceptions:" + System.lineSeparator());
    +                StringBuilder errorMsg = new StringBuilder("Could not retrieve result for messages ");
    --- End diff --
    
    Makes sense, thanks.


---

[GitHub] storm pull request #2476: Minor optimisation about trident kafka state

Posted by srdo <gi...@git.apache.org>.
Github user srdo commented on a diff in the pull request:

    https://github.com/apache/storm/pull/2476#discussion_r158124853
  
    --- Diff: external/storm-kafka-client/src/main/java/org/apache/storm/kafka/trident/TridentKafkaState.java ---
    @@ -73,7 +71,7 @@ public void commit(Long txid) {
         public void prepare(Properties options) {
             Objects.requireNonNull(mapper, "mapper can not be null");
             Objects.requireNonNull(topicSelector, "topicSelector can not be null");
    -        producer = new KafkaProducer(options);
    +        producer = new KafkaProducer<K, V>(options);
    --- End diff --
    
    Nit: I think `new KafkaProducer<>(options)` will work here


---

[GitHub] storm pull request #2476: Minor optimisation about trident kafka state

Posted by srdo <gi...@git.apache.org>.
Github user srdo commented on a diff in the pull request:

    https://github.com/apache/storm/pull/2476#discussion_r158125258
  
    --- Diff: external/storm-kafka-client/src/main/java/org/apache/storm/kafka/trident/TridentKafkaState.java ---
    @@ -116,8 +114,9 @@ public void updateState(List<TridentTuple> tuples, TridentCollector collector) {
                 }
     
                 if (exceptions.size() > 0) {
    -                StringBuilder errorMsg = new StringBuilder("Could not retrieve result for messages " + tuples + " from topic = " + topic
    -                    + " because of the following exceptions:" + System.lineSeparator());
    +                StringBuilder errorMsg = new StringBuilder("Could not retrieve result for messages ");
    --- End diff --
    
    Since the message is only ~5 strings long, I don't think there's much reason to use a StringBuilder at all.


---

[GitHub] storm issue #2476: STORM-2864: Minor optimisation about trident kafka state

Posted by OuYangLiang <gi...@git.apache.org>.
Github user OuYangLiang commented on the issue:

    https://github.com/apache/storm/pull/2476
  
    Done already.


---

[GitHub] storm issue #2476: Minor optimisation about trident kafka state

Posted by srdo <gi...@git.apache.org>.
Github user srdo commented on the issue:

    https://github.com/apache/storm/pull/2476
  
    Ah, sorry I missed this in the first go round; You need to raise an issue at https://issues.apache.org/jira describing this change/issue, then rename this PR to reference the issue number (see for example the naming of https://github.com/apache/storm/pull/2477). Please also squash to one commit, with the commit message referencing the JIRA issue number.


---

[GitHub] storm issue #2476: Minor optimisation about trident kafka state

Posted by srdo <gi...@git.apache.org>.
Github user srdo commented on the issue:

    https://github.com/apache/storm/pull/2476
  
    +1


---