Github user HeartSaVioR commented on a diff in the pull request:

    https://github.com/apache/storm/pull/2261#discussion_r134644598
  
    --- Diff: 
storm-client/src/jvm/org/apache/storm/grouping/LoadAwareShuffleGrouping.java ---
    @@ -52,25 +78,92 @@ public void prepare(WorkerTopologyContext context, 
GlobalStreamId stream, List<I
         }
     
         @Override
    +    public void refreshLoad(LoadMapping loadMapping) {
    +        updateRing(loadMapping);
    +    }
    +
    +    @Override
         public List<Integer> chooseTasks(int taskId, List<Object> values, 
LoadMapping load) {
    -        if ((lastUpdate + 1000) < System.currentTimeMillis()) {
    -            int local_total = 0;
    -            for (int i = 0; i < targets.length; i++) {
    -                int val = (int)(101 - (load.get(targets[i]) * 100));
    -                loads[i] = val;
    -                local_total += val;
    +        int rightNow;
    +        while (true) {
    +            rightNow = current.incrementAndGet();
    +            if (rightNow < CAPACITY) {
    +                return rets[choices[rightNow]];
    +            } else if (rightNow == CAPACITY) {
    +                current.set(0);
    --- End diff --
    
    I borrowed this from ShuffleGrouping, and even I'm not clear whether it 
makes race condition, I think it is acceptable since race condition scenarios 
don't incur out of index, just letting some threads selecting same index and 
maybe skip some indices.
    Moreover this patch contains tests which addresses multi-thread safety.
    
    We can still replace `set` with `getAndSet` to make it fully thread-safe, 
but we need to do more experiments if we would want to. Same applies to 
ShuffleGrouping.


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to