1 /** 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 package org.apache.hadoop.mapreduce.task.reduce; 19 20 import java.io.DataInput; 21 import java.io.DataOutput; 22 import java.io.IOException; 23 24 import org.apache.hadoop.classification.InterfaceAudience; 25 import org.apache.hadoop.classification.InterfaceStability; 26 import org.apache.hadoop.io.Text; 27 import org.apache.hadoop.io.Writable; 28 import org.apache.hadoop.io.WritableUtils; 29 30 /** 31 * Shuffle Header information that is sent by the TaskTracker and 32 * deciphered by the Fetcher thread of Reduce task 33 * 34 */ 35 @InterfaceAudience.Private 36 @InterfaceStability.Stable 37 public class ShuffleHeader implements Writable { 38 39 /** Header info of the shuffle http request/response */ 40 public static final String HTTP_HEADER_NAME = "name"; 41 public static final String DEFAULT_HTTP_HEADER_NAME = "mapreduce"; 42 public static final String HTTP_HEADER_VERSION = "version"; 43 public static final String DEFAULT_HTTP_HEADER_VERSION = "1.0.0"; 44 45 /** 46 * The longest possible length of task attempt id that we will accept. 47 */ 48 private static final int MAX_ID_LENGTH = 1000; 49 50 String mapId; 51 long uncompressedLength; 52 long compressedLength; 53 int forReduce; 54 ShuffleHeader()55 public ShuffleHeader() { } 56 ShuffleHeader(String mapId, long compressedLength, long uncompressedLength, int forReduce)57 public ShuffleHeader(String mapId, long compressedLength, 58 long uncompressedLength, int forReduce) { 59 this.mapId = mapId; 60 this.compressedLength = compressedLength; 61 this.uncompressedLength = uncompressedLength; 62 this.forReduce = forReduce; 63 } 64 readFields(DataInput in)65 public void readFields(DataInput in) throws IOException { 66 mapId = WritableUtils.readStringSafely(in, MAX_ID_LENGTH); 67 compressedLength = WritableUtils.readVLong(in); 68 uncompressedLength = WritableUtils.readVLong(in); 69 forReduce = WritableUtils.readVInt(in); 70 } 71 write(DataOutput out)72 public void write(DataOutput out) throws IOException { 73 Text.writeString(out, mapId); 74 WritableUtils.writeVLong(out, compressedLength); 75 WritableUtils.writeVLong(out, uncompressedLength); 76 WritableUtils.writeVInt(out, forReduce); 77 } 78 }