You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by re...@apache.org on 2016/01/18 12:41:39 UTC

[1/3] git commit: updated refs/heads/4.7 to 1f1da0f

Repository: cloudstack
Updated Branches:
  refs/heads/4.7 24277e1d8 -> 1f1da0fa5


Fix execution counter to support separate counts per thread


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/c35c4164
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/c35c4164
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/c35c4164

Branch: refs/heads/4.7
Commit: c35c4164d94cd6c1878b841080e96ac073342ddd
Parents: 21d2423
Author: Miguel Ferreira <mi...@me.com>
Authored: Thu Dec 17 19:47:08 2015 +0100
Committer: Miguel Ferreira <mi...@me.com>
Committed: Mon Jan 18 09:24:32 2016 +0100

----------------------------------------------------------------------
 .../java/com/cloud/network/nicira/ExecutionCounter.java | 12 ++++++++----
 .../com/cloud/network/nicira/ExecutionCounterTest.java  |  2 ++
 2 files changed, 10 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c35c4164/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/ExecutionCounter.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/ExecutionCounter.java b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/ExecutionCounter.java
index 1314498..7eedebb 100644
--- a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/ExecutionCounter.java
+++ b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/ExecutionCounter.java
@@ -19,15 +19,19 @@
 
 package com.cloud.network.nicira;
 
-import java.util.concurrent.atomic.AtomicInteger;
-
 public class ExecutionCounter {
 
     private final int executionLimit;
-    private final AtomicInteger executionCount = new AtomicInteger(0);
+    private final ThreadLocal<Integer> executionCount;
 
     public ExecutionCounter(final int executionLimit) {
         this.executionLimit = executionLimit;
+        executionCount = new ThreadLocal<Integer>() {
+            @Override
+            protected Integer initialValue() {
+                return new Integer(0);
+            }
+        };
     }
 
     public ExecutionCounter resetExecutionCounter() {
@@ -40,7 +44,7 @@ public class ExecutionCounter {
     }
 
     public ExecutionCounter incrementExecutionCounter() {
-        executionCount.incrementAndGet();
+        executionCount.set(executionCount.get() + 1);
         return this;
     }
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c35c4164/plugins/network-elements/nicira-nvp/src/test/java/com/cloud/network/nicira/ExecutionCounterTest.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nicira-nvp/src/test/java/com/cloud/network/nicira/ExecutionCounterTest.java b/plugins/network-elements/nicira-nvp/src/test/java/com/cloud/network/nicira/ExecutionCounterTest.java
index f063b75..b14694d 100644
--- a/plugins/network-elements/nicira-nvp/src/test/java/com/cloud/network/nicira/ExecutionCounterTest.java
+++ b/plugins/network-elements/nicira-nvp/src/test/java/com/cloud/network/nicira/ExecutionCounterTest.java
@@ -24,6 +24,7 @@ import static org.hamcrest.Matchers.equalTo;
 
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicInteger;
 
 import org.junit.Test;
@@ -92,6 +93,7 @@ public class ExecutionCounterTest {
         executorService.execute(task3);
 
         executorService.shutdown();
+        executorService.awaitTermination(5L, TimeUnit.SECONDS);
 
         assertThat(counterTask1.get(), equalTo(4));
         assertThat(counterTask2.get(), equalTo(2));


[3/3] git commit: updated refs/heads/4.7 to 1f1da0f

Posted by re...@apache.org.
Merge pull request #1294 from miguelaferreira/nsx-execution-counter-per-thread

Implement a NSX API request execution counter per threadThe NSX plugin has a execution counter to prevent infinite recursion (and as a result a stack overflow exception). However, the thread safeness of this counter are not as desired. The counter was implemented with an AtomicInteger which make it safe for multiple threads to update and read it. The desired property would be to have a counter per thread.

This PR addresses that issue.

* pr/1294:
  Fix execution counter to support separate counts per thread
  Add test to check that each thread has it's own execution counter

Signed-off-by: Remi Bergsma <gi...@remi.nl>


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/1f1da0fa
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/1f1da0fa
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/1f1da0fa

Branch: refs/heads/4.7
Commit: 1f1da0fa594ef5fad2974cea371c7a5f635488b6
Parents: 24277e1 c35c416
Author: Remi Bergsma <gi...@remi.nl>
Authored: Mon Jan 18 12:41:20 2016 +0100
Committer: Remi Bergsma <gi...@remi.nl>
Committed: Mon Jan 18 12:41:21 2016 +0100

----------------------------------------------------------------------
 .../cloud/network/nicira/ExecutionCounter.java  | 12 +++--
 .../network/nicira/ExecutionCounterTest.java    | 47 ++++++++++++++++++++
 2 files changed, 55 insertions(+), 4 deletions(-)
----------------------------------------------------------------------



[2/3] git commit: updated refs/heads/4.7 to 1f1da0f

Posted by re...@apache.org.
Add test to check that each thread has it's own execution counter


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/21d24237
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/21d24237
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/21d24237

Branch: refs/heads/4.7
Commit: 21d2423709946d77981d6bc151c4729bb361b2ec
Parents: 24277e1
Author: Miguel Ferreira <mi...@me.com>
Authored: Thu Dec 17 16:29:59 2015 +0100
Committer: Miguel Ferreira <mi...@me.com>
Committed: Mon Jan 18 09:24:32 2016 +0100

----------------------------------------------------------------------
 .../network/nicira/ExecutionCounterTest.java    | 45 ++++++++++++++++++++
 1 file changed, 45 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/21d24237/plugins/network-elements/nicira-nvp/src/test/java/com/cloud/network/nicira/ExecutionCounterTest.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nicira-nvp/src/test/java/com/cloud/network/nicira/ExecutionCounterTest.java b/plugins/network-elements/nicira-nvp/src/test/java/com/cloud/network/nicira/ExecutionCounterTest.java
index 18797df..f063b75 100644
--- a/plugins/network-elements/nicira-nvp/src/test/java/com/cloud/network/nicira/ExecutionCounterTest.java
+++ b/plugins/network-elements/nicira-nvp/src/test/java/com/cloud/network/nicira/ExecutionCounterTest.java
@@ -22,6 +22,10 @@ package com.cloud.network.nicira;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.equalTo;
 
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.atomic.AtomicInteger;
+
 import org.junit.Test;
 
 public class ExecutionCounterTest {
@@ -52,4 +56,45 @@ public class ExecutionCounterTest {
 
         assertThat(executionCounter.hasReachedExecutionLimit(), equalTo(true));
     }
+
+    @Test
+    public void testConcurrentUpdatesToCounter() throws Exception {
+        final ExecutionCounter executionCounter = new ExecutionCounter(0);
+        final ExecutorService executorService = Executors.newFixedThreadPool(3);
+        final AtomicInteger counterTask1 = new AtomicInteger(-1);
+        final AtomicInteger counterTask2 = new AtomicInteger(-1);
+        final AtomicInteger counterTask3 = new AtomicInteger(-1);
+
+        final Runnable task1 = new Runnable() {
+            @Override
+            public void run() {
+                executionCounter.incrementExecutionCounter().incrementExecutionCounter();
+                executionCounter.incrementExecutionCounter().incrementExecutionCounter();
+                counterTask1.set(executionCounter.getValue());
+            }
+        };
+        final Runnable task2 = new Runnable() {
+            @Override
+            public void run() {
+                executionCounter.incrementExecutionCounter().incrementExecutionCounter();
+                counterTask2.set(executionCounter.getValue());
+            }
+        };
+        final Runnable task3 = new Runnable() {
+            @Override
+            public void run() {
+                counterTask3.set(executionCounter.getValue());
+            }
+        };
+
+        executorService.execute(task1);
+        executorService.execute(task2);
+        executorService.execute(task3);
+
+        executorService.shutdown();
+
+        assertThat(counterTask1.get(), equalTo(4));
+        assertThat(counterTask2.get(), equalTo(2));
+        assertThat(counterTask3.get(), equalTo(0));
+    }
 }