aurora-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject git commit: Fixing race in task secondary index.
Date Thu, 28 Aug 2014 23:08:28 GMT
Repository: incubator-aurora
Updated Branches:
  refs/heads/master 81d5c5c81 -> 6b7995e2c


Fixing race in task secondary index.

Bugs closed: AURORA-667

Reviewed at https://reviews.apache.org/r/25133/


Project: http://git-wip-us.apache.org/repos/asf/incubator-aurora/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-aurora/commit/6b7995e2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-aurora/tree/6b7995e2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-aurora/diff/6b7995e2

Branch: refs/heads/master
Commit: 6b7995e2cbede6be49d689a58a4d64623f60b255
Parents: 81d5c5c
Author: Maxim Khutornenko <maxim@apache.org>
Authored: Thu Aug 28 16:03:29 2014 -0700
Committer: Maxim Khutornenko <maxim@apache.org>
Committed: Thu Aug 28 16:03:29 2014 -0700

----------------------------------------------------------------------
 .../scheduler/storage/mem/MemTaskStore.java     |  6 ++-
 .../scheduler/storage/mem/MemTaskStoreTest.java | 49 ++++++++++++++++++++
 2 files changed, 53 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/6b7995e2/src/main/java/org/apache/aurora/scheduler/storage/mem/MemTaskStore.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/storage/mem/MemTaskStore.java b/src/main/java/org/apache/aurora/scheduler/storage/mem/MemTaskStore.java
index f2656de..3717623 100644
--- a/src/main/java/org/apache/aurora/scheduler/storage/mem/MemTaskStore.java
+++ b/src/main/java/org/apache/aurora/scheduler/storage/mem/MemTaskStore.java
@@ -417,8 +417,10 @@ class MemTaskStore implements TaskStore.Mutable {
           public Iterable<String> apply(Set<K> keys) {
             hitCount.incrementAndGet();
             ImmutableSet.Builder<String> builder = ImmutableSet.builder();
-            for (K key : keys) {
-              builder.addAll(index.get(key));
+            synchronized (index) {
+              for (K key : keys) {
+                builder.addAll(index.get(key));
+              }
             }
             return builder.build();
           }

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/6b7995e2/src/test/java/org/apache/aurora/scheduler/storage/mem/MemTaskStoreTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/storage/mem/MemTaskStoreTest.java b/src/test/java/org/apache/aurora/scheduler/storage/mem/MemTaskStoreTest.java
index 6882c25..3b61ff3 100644
--- a/src/test/java/org/apache/aurora/scheduler/storage/mem/MemTaskStoreTest.java
+++ b/src/test/java/org/apache/aurora/scheduler/storage/mem/MemTaskStoreTest.java
@@ -15,6 +15,9 @@ package org.apache.aurora.scheduler.storage.mem;
 
 import java.util.Map;
 import java.util.Set;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
 
 import com.google.common.base.Function;
 import com.google.common.base.Optional;
@@ -23,6 +26,10 @@ import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Iterables;
 import com.google.common.collect.Maps;
+import com.google.common.util.concurrent.ThreadFactoryBuilder;
+import com.twitter.common.quantity.Amount;
+import com.twitter.common.quantity.Time;
+import com.twitter.common.util.concurrent.ExecutorServiceShutdown;
 
 import org.apache.aurora.gen.AssignedTask;
 import org.apache.aurora.gen.ExecutorConfig;
@@ -43,6 +50,7 @@ import org.junit.Test;
 import static org.apache.aurora.gen.ScheduleStatus.RUNNING;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
 public class MemTaskStoreTest {
@@ -387,6 +395,47 @@ public class MemTaskStoreTest {
     assertQueryResults(Query.slaveScoped(host), updated);
   }
 
+  @Test
+  public void testReadSecondaryIndexMultipleThreads() throws Exception {
+    ExecutorService executor = Executors.newFixedThreadPool(4,
+        new ThreadFactoryBuilder().setNameFormat("SlowRead-%d").setDaemon(true).build());
+
+    try {
+      ImmutableSet.Builder<IScheduledTask> builder = ImmutableSet.builder();
+      final int numTasks = 100;
+      final int numJobs = 100;
+      for (int j = 0; j < numJobs; j++) {
+        for (int t = 0; t < numTasks; t++) {
+          builder.add(makeTask("" + j + "-" + t, "role", "env", "name" + j));
+        }
+      }
+      store.saveTasks(builder.build());
+
+      final CountDownLatch read = new CountDownLatch(numJobs);
+      for (int j = 0; j < numJobs; j++) {
+        final int id = j;
+        executor.submit(new Runnable() {
+          @Override
+          public void run() {
+            assertNotNull(store.fetchTasks(Query.jobScoped(
+                JobKeys.from("role", "env", "name" + id))));
+            read.countDown();
+          }
+        });
+        executor.submit(new Runnable() {
+          @Override
+          public void run() {
+            store.saveTasks(ImmutableSet.of(makeTask("TaskNew1" + id)));
+          }
+        });
+      }
+
+      read.await();
+    } finally {
+      new ExecutorServiceShutdown(executor, Amount.of(1L, Time.SECONDS)).execute();
+    }
+  }
+
   private void assertStoreContents(IScheduledTask... tasks) {
     assertQueryResults(Query.unscoped(), tasks);
   }


Mime
View raw message