tez-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ss...@apache.org
Subject [22/23] git commit: TEZ-1135. Fix ShuffledUnorderedKVInput handling of empty partitions. (sseth)
Date Fri, 20 Jun 2014 22:36:00 GMT
TEZ-1135. Fix ShuffledUnorderedKVInput handling of empty partitions.
(sseth)


Project: http://git-wip-us.apache.org/repos/asf/incubator-tez/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tez/commit/250aee20
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tez/tree/250aee20
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tez/diff/250aee20

Branch: refs/heads/branch-0.4.1-incubating
Commit: 250aee2043c8dfb10ff4d854643d63a8e0337cda
Parents: 5aa8a12
Author: Siddharth Seth <sseth@apache.org>
Authored: Fri Jun 20 15:17:50 2014 -0700
Committer: Siddharth Seth <sseth@apache.org>
Committed: Fri Jun 20 15:34:46 2014 -0700

----------------------------------------------------------------------
 .../library/common/InputAttemptIdentifier.java  |   2 +-
 .../impl/ShuffleInputEventHandlerImpl.java      |  24 +--
 .../impl/TestShuffleInputEventHandlerImpl.java  | 159 +++++++++++++++++++
 3 files changed, 172 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tez/blob/250aee20/tez-runtime-library/src/main/java/org/apache/tez/runtime/library/common/InputAttemptIdentifier.java
----------------------------------------------------------------------
diff --git a/tez-runtime-library/src/main/java/org/apache/tez/runtime/library/common/InputAttemptIdentifier.java
b/tez-runtime-library/src/main/java/org/apache/tez/runtime/library/common/InputAttemptIdentifier.java
index 4c9d525..7c8a23b 100644
--- a/tez-runtime-library/src/main/java/org/apache/tez/runtime/library/common/InputAttemptIdentifier.java
+++ b/tez-runtime-library/src/main/java/org/apache/tez/runtime/library/common/InputAttemptIdentifier.java
@@ -43,7 +43,7 @@ public class InputAttemptIdentifier {
     this.pathComponent = pathComponent;
     if (pathComponent != null && !pathComponent.startsWith(PATH_PREFIX)) {
       throw new TezUncheckedException(
-          "Path component must start with: " + PATH_PREFIX + this);
+          "Path component must start with: " + PATH_PREFIX + " " + this);
     }
   }
   

http://git-wip-us.apache.org/repos/asf/incubator-tez/blob/250aee20/tez-runtime-library/src/main/java/org/apache/tez/runtime/library/shuffle/common/impl/ShuffleInputEventHandlerImpl.java
----------------------------------------------------------------------
diff --git a/tez-runtime-library/src/main/java/org/apache/tez/runtime/library/shuffle/common/impl/ShuffleInputEventHandlerImpl.java
b/tez-runtime-library/src/main/java/org/apache/tez/runtime/library/shuffle/common/impl/ShuffleInputEventHandlerImpl.java
index ac5da74..7fe6207 100644
--- a/tez-runtime-library/src/main/java/org/apache/tez/runtime/library/shuffle/common/impl/ShuffleInputEventHandlerImpl.java
+++ b/tez-runtime-library/src/main/java/org/apache/tez/runtime/library/shuffle/common/impl/ShuffleInputEventHandlerImpl.java
@@ -111,20 +111,20 @@ public class ShuffleInputEventHandlerImpl implements ShuffleEventHandler
{
         shuffleManager.addCompletedInputWithNoData(srcAttemptIdentifier);
         return;
       }
+    } 
+    InputAttemptIdentifier srcAttemptIdentifier = new InputAttemptIdentifier(dme.getTargetIndex(),
+        dme.getVersion(), shufflePayload.getPathComponent());
+    if (shufflePayload.hasData()) {
+      DataProto dataProto = shufflePayload.getData();
+      FetchedInput fetchedInput = inputAllocator.allocate(dataProto.getRawLength(),
+          dataProto.getCompressedLength(), srcAttemptIdentifier);
+      moveDataToFetchedInput(dataProto, fetchedInput);
+      shuffleManager.addCompletedInputWithData(srcAttemptIdentifier, fetchedInput);
     } else {
-      InputAttemptIdentifier srcAttemptIdentifier = new InputAttemptIdentifier(dme.getTargetIndex(),
-          dme.getVersion(), shufflePayload.getPathComponent());
-      if (shufflePayload.hasData()) {
-        DataProto dataProto = shufflePayload.getData();
-        FetchedInput fetchedInput = inputAllocator.allocate(dataProto.getRawLength(),
-            dataProto.getCompressedLength(), srcAttemptIdentifier);
-        moveDataToFetchedInput(dataProto, fetchedInput);
-        shuffleManager.addCompletedInputWithData(srcAttemptIdentifier, fetchedInput);
-      } else {
-        shuffleManager.addKnownInput(shufflePayload.getHost(), shufflePayload.getPort(),
-            srcAttemptIdentifier, srcIndex);
-      }
+      shuffleManager.addKnownInput(shufflePayload.getHost(), shufflePayload.getPort(),
+          srcAttemptIdentifier, srcIndex);
     }
+
   }
   
   private void moveDataToFetchedInput(DataProto dataProto,

http://git-wip-us.apache.org/repos/asf/incubator-tez/blob/250aee20/tez-runtime-library/src/test/java/org/apache/tez/runtime/library/shuffle/common/impl/TestShuffleInputEventHandlerImpl.java
----------------------------------------------------------------------
diff --git a/tez-runtime-library/src/test/java/org/apache/tez/runtime/library/shuffle/common/impl/TestShuffleInputEventHandlerImpl.java
b/tez-runtime-library/src/test/java/org/apache/tez/runtime/library/shuffle/common/impl/TestShuffleInputEventHandlerImpl.java
new file mode 100644
index 0000000..e95c30d
--- /dev/null
+++ b/tez-runtime-library/src/test/java/org/apache/tez/runtime/library/shuffle/common/impl/TestShuffleInputEventHandlerImpl.java
@@ -0,0 +1,159 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.tez.runtime.library.shuffle.common.impl;
+
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
+import java.io.IOException;
+import java.util.BitSet;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.apache.tez.common.TezUtils;
+import org.apache.tez.runtime.api.Event;
+import org.apache.tez.runtime.api.TezInputContext;
+import org.apache.tez.runtime.api.events.DataMovementEvent;
+import org.apache.tez.runtime.library.common.InputAttemptIdentifier;
+import org.apache.tez.runtime.library.shuffle.common.FetchedInputAllocator;
+import org.apache.tez.runtime.library.shuffle.impl.ShuffleUserPayloads.DataMovementEventPayloadProto;
+import org.junit.Test;
+
+import com.google.protobuf.ByteString;
+
+public class TestShuffleInputEventHandlerImpl {
+
+  private static final String HOST = "localhost";
+  private static final int PORT = 8080;
+  private static final String PATH_COMPONENT = "attempttmp";
+
+  @Test
+  public void testSimple() throws IOException {
+    TezInputContext inputContext = mock(TezInputContext.class);
+    ShuffleManager shuffleManager = mock(ShuffleManager.class);
+    FetchedInputAllocator inputAllocator = mock(FetchedInputAllocator.class);
+
+    ShuffleInputEventHandlerImpl handler = new ShuffleInputEventHandlerImpl(inputContext,
+        shuffleManager, inputAllocator, null, false, 0);
+
+    int taskIndex = 1;
+    Event dme = createDataMovementEvent(0, taskIndex, null);
+
+    List<Event> eventList = new LinkedList<Event>();
+    eventList.add(dme);
+    handler.handleEvents(eventList);
+
+    InputAttemptIdentifier expectedIdentifier = new InputAttemptIdentifier(taskIndex, 0,
+        PATH_COMPONENT);
+
+    verify(shuffleManager).addKnownInput(eq(HOST), eq(PORT), eq(expectedIdentifier), eq(0));
+  }
+
+  @Test
+  public void testCurrentPartitionEmpty() throws IOException {
+    TezInputContext inputContext = mock(TezInputContext.class);
+    ShuffleManager shuffleManager = mock(ShuffleManager.class);
+    FetchedInputAllocator inputAllocator = mock(FetchedInputAllocator.class);
+
+    ShuffleInputEventHandlerImpl handler = new ShuffleInputEventHandlerImpl(inputContext,
+        shuffleManager, inputAllocator, null, false, 0);
+
+    int taskIndex = 1;
+    Event dme = createDataMovementEvent(0, taskIndex, createEmptyPartitionByteString(0));
+
+    List<Event> eventList = new LinkedList<Event>();
+    eventList.add(dme);
+    handler.handleEvents(eventList);
+
+    InputAttemptIdentifier expectedIdentifier = new InputAttemptIdentifier(taskIndex, 0);
+
+    verify(shuffleManager).addCompletedInputWithNoData(eq(expectedIdentifier));
+  }
+
+  @Test
+  public void testOtherPartitionEmpty() throws IOException {
+    TezInputContext inputContext = mock(TezInputContext.class);
+    ShuffleManager shuffleManager = mock(ShuffleManager.class);
+    FetchedInputAllocator inputAllocator = mock(FetchedInputAllocator.class);
+
+    ShuffleInputEventHandlerImpl handler = new ShuffleInputEventHandlerImpl(inputContext,
+        shuffleManager, inputAllocator, null, false, 0);
+
+    int taskIndex = 1;
+    Event dme = createDataMovementEvent(0, taskIndex, createEmptyPartitionByteString(1));
+    List<Event> eventList = new LinkedList<Event>();
+    eventList.add(dme);
+    handler.handleEvents(eventList);
+
+    InputAttemptIdentifier expectedIdentifier = new InputAttemptIdentifier(taskIndex, 0,
PATH_COMPONENT);
+
+    verify(shuffleManager).addKnownInput(eq(HOST), eq(PORT), eq(expectedIdentifier), eq(0));
+  }
+
+  @Test
+  public void testMultipleEvents1() throws IOException {
+    TezInputContext inputContext = mock(TezInputContext.class);
+    ShuffleManager shuffleManager = mock(ShuffleManager.class);
+    FetchedInputAllocator inputAllocator = mock(FetchedInputAllocator.class);
+
+    ShuffleInputEventHandlerImpl handler = new ShuffleInputEventHandlerImpl(inputContext,
+        shuffleManager, inputAllocator, null, false, 0);
+
+    int taskIndex1 = 1;
+    Event dme1 = createDataMovementEvent(0, taskIndex1, createEmptyPartitionByteString(0));
+    int taskIndex2 = 2;
+    Event dme2 = createDataMovementEvent(0, taskIndex2, null);
+    
+    List<Event> eventList = new LinkedList<Event>();
+    eventList.add(dme1);
+    eventList.add(dme2);
+    handler.handleEvents(eventList);
+
+    InputAttemptIdentifier expectedIdentifier1 = new InputAttemptIdentifier(taskIndex1, 0);
+    InputAttemptIdentifier expectedIdentifier2 = new InputAttemptIdentifier(taskIndex2, 0,
PATH_COMPONENT);
+
+    verify(shuffleManager).addCompletedInputWithNoData(eq(expectedIdentifier1));
+    verify(shuffleManager).addKnownInput(eq(HOST), eq(PORT), eq(expectedIdentifier2), eq(0));
+  }
+  
+  private Event createDataMovementEvent(int srcIndex, int targetIndex,
+      ByteString emptyPartitionByteString) {
+    DataMovementEventPayloadProto.Builder builder = DataMovementEventPayloadProto.newBuilder();
+    builder.setHost(HOST);
+    builder.setPort(PORT);
+    builder.setPathComponent("attempttmp");
+    if (emptyPartitionByteString != null) {
+      builder.setEmptyPartitions(emptyPartitionByteString);
+    }
+    Event dme = new DataMovementEvent(srcIndex, targetIndex, 0, builder.build().toByteArray());
+    return dme;
+  }
+
+  private ByteString createEmptyPartitionByteString(int... emptyPartitions) throws IOException
{
+    BitSet bitSet = new BitSet();
+    for (int i : emptyPartitions) {
+      bitSet.set(i);
+    }
+    ByteString emptyPartitionsBytesString = TezUtils.compressByteArrayToByteString(TezUtils
+        .toByteArray(bitSet));
+    return emptyPartitionsBytesString;
+  }
+
+}


Mime
View raw message