aurora-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kevi...@apache.org
Subject incubator-aurora git commit: Avoid creating garbage copies of Snapshot#tasks and AssignedTask#task.
Date Fri, 21 Nov 2014 21:01:54 GMT
Repository: incubator-aurora
Updated Branches:
  refs/heads/master f43700c0d -> 6f92724fd


Avoid creating garbage copies of Snapshot#tasks and AssignedTask#task.

Testing Done:
./gradlew -Pq build

Suggestions on how to better test this are welcome.

Bugs closed: AURORA-930

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


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

Branch: refs/heads/master
Commit: 6f92724fd8b4b3e8472e78330027ceab2c9b4adc
Parents: f43700c
Author: Kevin Sweeney <kevints@apache.org>
Authored: Fri Nov 21 13:01:37 2014 -0800
Committer: Kevin Sweeney <kevints@apache.org>
Committed: Fri Nov 21 13:01:37 2014 -0800

----------------------------------------------------------------------
 .../storage/log/SnapshotDeduplicator.java       | 45 +++++++++++++++++---
 1 file changed, 38 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/6f92724f/src/main/java/org/apache/aurora/scheduler/storage/log/SnapshotDeduplicator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/storage/log/SnapshotDeduplicator.java
b/src/main/java/org/apache/aurora/scheduler/storage/log/SnapshotDeduplicator.java
index 7b46740..620b6b6 100644
--- a/src/main/java/org/apache/aurora/scheduler/storage/log/SnapshotDeduplicator.java
+++ b/src/main/java/org/apache/aurora/scheduler/storage/log/SnapshotDeduplicator.java
@@ -23,12 +23,17 @@ import com.google.common.collect.Multimaps;
 import com.twitter.common.inject.TimedInterceptor.Timed;
 
 import org.apache.aurora.codec.ThriftBinaryCodec.CodingException;
+import org.apache.aurora.gen.AssignedTask;
 import org.apache.aurora.gen.ScheduledTask;
 import org.apache.aurora.gen.TaskConfig;
 import org.apache.aurora.gen.storage.DeduplicatedScheduledTask;
 import org.apache.aurora.gen.storage.DeduplicatedSnapshot;
 import org.apache.aurora.gen.storage.Snapshot;
 
+import static org.apache.aurora.gen.AssignedTask._Fields.TASK;
+import static org.apache.aurora.gen.ScheduledTask._Fields.ASSIGNED_TASK;
+import static org.apache.aurora.gen.storage.Snapshot._Fields.TASKS;
+
 /**
  * Converter between denormalized storage Snapshots and de-duplicated snapshots.
  *
@@ -65,9 +70,38 @@ public interface SnapshotDeduplicator {
         };
 
     private static ScheduledTask deepCopyWithoutTaskConfig(ScheduledTask scheduledTask) {
-      ScheduledTask task = scheduledTask.deepCopy();
-      task.getAssignedTask().unsetTask();
-      return task;
+      ScheduledTask scheduledTaskCopy = new ScheduledTask();
+      for (ScheduledTask._Fields scheduledTaskField : ScheduledTask._Fields.values()) {
+        if (scheduledTaskField == ASSIGNED_TASK) {
+          AssignedTask assignedTask = scheduledTask.getAssignedTask();
+          AssignedTask assignedTaskCopy = new AssignedTask();
+          for (AssignedTask._Fields assignedTaskField : AssignedTask._Fields.values()) {
+            // Copy all fields in AssignedTask except the TASK field.
+            if (assignedTaskField != TASK && assignedTask.isSet(assignedTaskField))
{
+              assignedTaskCopy.setFieldValue(
+                  assignedTaskField, assignedTask.getFieldValue(assignedTaskField));
+            }
+          }
+          scheduledTaskCopy.setAssignedTask(assignedTaskCopy);
+        } else if (scheduledTask.isSet(scheduledTaskField)) {
+          scheduledTaskCopy.setFieldValue(
+              scheduledTaskField, scheduledTask.getFieldValue(scheduledTaskField));
+        }
+      }
+      return scheduledTaskCopy.deepCopy();
+    }
+
+    // NOTE: We intentionally try to minimize the number of copies of the Snapshot#tasks
field
+    // we make. The simpler implementation of deepCopy followed by unsetTasks creates a
+    // lot of GC pressure.
+    private static Snapshot deepCopyWithoutTasks(Snapshot snapshot) {
+      Snapshot snapshotCopy = new Snapshot();
+      for (Snapshot._Fields field : Snapshot._Fields.values()) {
+        if (field != TASKS && snapshot.isSet(field)) {
+          snapshotCopy.setFieldValue(field, snapshot.getFieldValue(field));
+        }
+      }
+      return snapshotCopy.deepCopy();
     }
 
     @Override
@@ -76,11 +110,8 @@ public interface SnapshotDeduplicator {
       int numInputTasks = snapshot.getTasksSize();
       LOG.info(String.format("Starting deduplication of a snapshot with %d tasks.", numInputTasks));
 
-      Snapshot partialSnapshot = snapshot.deepCopy();
-      partialSnapshot.unsetTasks();
-
       DeduplicatedSnapshot deduplicatedSnapshot = new DeduplicatedSnapshot()
-          .setPartialSnapshot(partialSnapshot);
+          .setPartialSnapshot(deepCopyWithoutTasks(snapshot));
 
       // Nothing to do if we don't have any input tasks.
       if (!snapshot.isSetTasks()) {


Mime
View raw message