You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by he...@apache.org on 2010/11/24 22:52:01 UTC
svn commit: r1038842 - in /hive/trunk: ./
common/src/java/org/apache/hadoop/hive/common/
ql/src/java/org/apache/hadoop/hive/ql/exec/
ql/src/java/org/apache/hadoop/hive/ql/plan/
Author: heyongqiang
Date: Wed Nov 24 21:52:00 2010
New Revision: 1038842
URL: http://svn.apache.org/viewvc?rev=1038842&view=rev
Log:
HIVE-1797 Compressed the hashtable dump file before put into distributed cache (Liyin Tang via He Yongqiang)
Modified:
hive/trunk/CHANGES.txt
hive/trunk/common/src/java/org/apache/hadoop/hive/common/FileUtils.java
hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/ExecDriver.java
hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/HashTableSinkOperator.java
hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/MapJoinOperator.java
hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/PathUtil.java
hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/Utilities.java
hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/plan/MapredLocalWork.java
Modified: hive/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hive/trunk/CHANGES.txt?rev=1038842&r1=1038841&r2=1038842&view=diff
==============================================================================
--- hive/trunk/CHANGES.txt (original)
+++ hive/trunk/CHANGES.txt Wed Nov 24 21:52:00 2010
@@ -277,6 +277,9 @@ Trunk - Unreleased
HIVE-1810 doc followup to HIVE-1785
(Liyin Tang via jvs)
+ HIVE-1797 Compressed the hashtable dump file before put into distributed cache
+ (Liyin Tang via He Yongqiang)
+
OPTIMIZATIONS
BUG FIXES
Modified: hive/trunk/common/src/java/org/apache/hadoop/hive/common/FileUtils.java
URL: http://svn.apache.org/viewvc/hive/trunk/common/src/java/org/apache/hadoop/hive/common/FileUtils.java?rev=1038842&r1=1038841&r2=1038842&view=diff
==============================================================================
--- hive/trunk/common/src/java/org/apache/hadoop/hive/common/FileUtils.java (original)
+++ hive/trunk/common/src/java/org/apache/hadoop/hive/common/FileUtils.java Wed Nov 24 21:52:00 2010
@@ -27,6 +27,7 @@ import org.apache.hadoop.conf.Configurat
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.util.Shell.ShellCommandExecutor;
/**
* Collection of file manipulation utilities common across Hive.
@@ -34,12 +35,12 @@ import org.apache.hadoop.fs.Path;
public final class FileUtils {
/**
- * Variant of Path.makeQualified that qualifies the input path against the
- * default file system indicated by the configuration
+ * Variant of Path.makeQualified that qualifies the input path against the default file system
+ * indicated by the configuration
*
- * This does not require a FileSystem handle in most cases - only requires the
- * Filesystem URI. This saves the cost of opening the Filesystem - which can
- * involve RPCs - as well as cause errors
+ * This does not require a FileSystem handle in most cases - only requires the Filesystem URI.
+ * This saves the cost of opening the Filesystem - which can involve RPCs - as well as cause
+ * errors
*
* @param path
* path to be fully qualified
@@ -70,14 +71,13 @@ public final class FileUtils {
// no scheme - use default file system uri
scheme = fsUri.getScheme();
authority = fsUri.getAuthority();
- if(authority == null) {
+ if (authority == null) {
authority = "";
}
} else {
- if(authority == null) {
+ if (authority == null) {
// no authority - use default one if it applies
- if(scheme.equals(fsUri.getScheme()) &&
- fsUri.getAuthority() != null) {
+ if (scheme.equals(fsUri.getScheme()) && fsUri.getAuthority() != null) {
authority = fsUri.getAuthority();
} else {
authority = "";
@@ -93,8 +93,7 @@ public final class FileUtils {
}
- public static String makePartName(List<String> partCols,
- List<String> vals) {
+ public static String makePartName(List<String> partCols, List<String> vals) {
StringBuilder name = new StringBuilder();
for (int i = 0; i < partCols.size(); i++) {
@@ -122,8 +121,8 @@ public final class FileUtils {
for (char c = 0; c < ' '; c++) {
charToEscape.set(c);
}
- char[] clist = new char[] { '"', '#', '%', '\'', '*', '/', ':', '=', '?',
- '\\', '\u007F', '{', ']' };
+ char[] clist = new char[] {'"', '#', '%', '\'', '*', '/', ':', '=', '?', '\\', '\u007F', '{',
+ ']'};
for (char c : clist) {
charToEscape.set(c);
}
@@ -177,18 +176,20 @@ public final class FileUtils {
}
/**
- * Recursively lists status for all files starting from a particular
- * directory (or individual file as base case).
+ * Recursively lists status for all files starting from a particular directory (or individual file
+ * as base case).
*
- * @param fs file system
+ * @param fs
+ * file system
*
- * @param fileStatus starting point in file system
+ * @param fileStatus
+ * starting point in file system
*
- * @param results receives enumeration of all files found
+ * @param results
+ * receives enumeration of all files found
*/
public static void listStatusRecursively(FileSystem fs, FileStatus fileStatus,
- List<FileStatus> results)
- throws IOException {
+ List<FileStatus> results) throws IOException {
if (fileStatus.isDir()) {
for (FileStatus stat : fs.listStatus(fileStatus.getPath())) {
@@ -198,4 +199,30 @@ public final class FileUtils {
results.add(fileStatus);
}
}
+
+ /**
+ * Archive all the files in the inputFiles into outputFile
+ *
+ * @param inputFiles
+ * @param outputFile
+ * @throws IOException
+ */
+ public static void tar(String parentDir, String[] inputFiles, String outputFile)
+ throws IOException {
+ StringBuffer tarCommand = new StringBuffer();
+ tarCommand.append("cd " + parentDir + " ; ");
+ tarCommand.append(" tar -zcvf ");
+ tarCommand.append(" " + outputFile);
+ for (int i = 0; i < inputFiles.length; i++) {
+ tarCommand.append(" " + inputFiles[i]);
+ }
+ String[] shellCmd = {"bash", "-c", tarCommand.toString()};
+ ShellCommandExecutor shexec = new ShellCommandExecutor(shellCmd);
+ shexec.execute();
+ int exitcode = shexec.getExitCode();
+ if (exitcode != 0) {
+ throw new IOException("Error tarring file " + outputFile
+ + ". Tar process exited with exit code " + exitcode);
+ }
+ }
}
Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/ExecDriver.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/ExecDriver.java?rev=1038842&r1=1038841&r2=1038842&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/ExecDriver.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/ExecDriver.java Wed Nov 24 21:52:00 2010
@@ -49,6 +49,7 @@ import org.apache.hadoop.filecache.Distr
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.hive.common.FileUtils;
import org.apache.hadoop.hive.conf.HiveConf;
import org.apache.hadoop.hive.conf.HiveConf.ConfVars;
import org.apache.hadoop.hive.ql.Context;
@@ -538,6 +539,7 @@ public class ExecDriver extends Task<Map
throw new RuntimeException(e.getMessage());
}
+
// No-Op - we don't really write anything here ..
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(Text.class);
@@ -560,23 +562,21 @@ public class ExecDriver extends Task<Map
if (StringUtils.isNotBlank(addedFiles)) {
initializeFiles("tmpfiles", addedFiles);
}
- // Transfer HIVEADDEDARCHIVES to "tmparchives" so hadoop understands it
- String addedArchives = HiveConf.getVar(job, HiveConf.ConfVars.HIVEADDEDARCHIVES);
- if (StringUtils.isNotBlank(addedArchives)) {
- initializeFiles("tmparchives", addedArchives);
- }
-
int returnVal = 0;
RunningJob rj = null;
-
boolean noName = StringUtils.isEmpty(HiveConf.getVar(job, HiveConf.ConfVars.HADOOPJOBNAME));
if (noName) {
// This is for a special case to ensure unit tests pass
HiveConf.setVar(job, HiveConf.ConfVars.HADOOPJOBNAME, "JOB" + Utilities.randGen.nextInt());
}
- try {
- // propagate the file to distributed cache
+ String addedArchives = HiveConf.getVar(job, HiveConf.ConfVars.HIVEADDEDARCHIVES);
+ // Transfer HIVEADDEDARCHIVES to "tmparchives" so hadoop understands it
+ if (StringUtils.isNotBlank(addedArchives)) {
+ initializeFiles("tmparchives", addedArchives);
+ }
+
+ try{
MapredLocalWork localwork = work.getMapLocalWork();
if (localwork != null) {
boolean localMode = HiveConf.getVar(job, HiveConf.ConfVars.HADOOPJT).equals("local");
@@ -587,32 +587,39 @@ public class ExecDriver extends Task<Map
FileSystem hdfs = hdfsPath.getFileSystem(job);
FileSystem localFS = localPath.getFileSystem(job);
FileStatus[] hashtableFiles = localFS.listStatus(localPath);
- for (int i = 0; i < hashtableFiles.length; i++) {
- FileStatus file = hashtableFiles[i];
- Path path = file.getPath();
- String fileName = path.getName();
- String hdfsFile = hdfsPath + Path.SEPARATOR + fileName;
-
- LOG.info("Upload 1 HashTable from" + path + " to: " + hdfsFile);
- Path hdfsFilePath = new Path(hdfsFile);
-
- hdfs.copyFromLocalFile(path, hdfsFilePath);
- short replication = (short) job.getInt("mapred.submit.replication", 10);
- hdfs.setReplication(hdfsFilePath, replication);
- }
- FileStatus[] hashtableRemoteFiles = hdfs.listStatus(hdfsPath);
- for (int i = 0; i < hashtableRemoteFiles.length; i++) {
- FileStatus file = hashtableRemoteFiles[i];
- Path path = file.getPath();
- DistributedCache.addCacheFile(path.toUri(), job);
+ int fileNumber = hashtableFiles.length;
+ String[] fileNames = new String[fileNumber];
- LOG.info("add 1 hashtable file to distributed cache: " + path.toUri());
+ for ( int i = 0; i < fileNumber; i++){
+ fileNames[i] = hashtableFiles[i].getPath().getName();
}
+
+ //package and compress all the hashtable files to an archive file
+ String parentDir = localPath.toUri().getPath();
+ String stageId = this.getId();
+ String archiveFileURI = Utilities.generateTarURI(parentDir, stageId);
+ String archiveFileName = Utilities.generateTarFileName(stageId);
+ localwork.setStageID(stageId);
+
+ FileUtils.tar(parentDir, fileNames,archiveFileName);
+ Path archivePath = new Path(archiveFileURI);
+ LOG.info("Archive "+ hashtableFiles.length+" hash table files to " + archiveFileURI);
+
+ //upload archive file to hdfs
+ String hdfsFile =Utilities.generateTarURI(hdfsPath, stageId);
+ Path hdfsFilePath = new Path(hdfsFile);
+ short replication = (short) job.getInt("mapred.submit.replication", 10);
+ hdfs.setReplication(hdfsFilePath, replication);
+ hdfs.copyFromLocalFile(archivePath, hdfsFilePath);
+ LOG.info("Upload 1 archive file from" + archivePath + " to: " + hdfsFilePath);
+
+ //add the archive file to distributed cache
+ DistributedCache.createSymlink(job);
+ DistributedCache.addCacheArchive(hdfsFilePath.toUri(), job);
+ LOG.info("Add 1 archive file to distributed cache. Archive file: " + hdfsFilePath.toUri());
}
}
-
-
addInputPaths(job, work, emptyScratchDirStr);
Utilities.setMapRedWork(job, work, ctx.getMRTmpFileURI());
Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/HashTableSinkOperator.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/HashTableSinkOperator.java?rev=1038842&r1=1038841&r2=1038842&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/HashTableSinkOperator.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/HashTableSinkOperator.java Wed Nov 24 21:52:00 2010
@@ -400,7 +400,7 @@ public class HashTableSinkOperator exten
.entrySet()) {
// get the key and value
Byte tag = hashTables.getKey();
- HashMapWrapper hashTable = hashTables.getValue();
+ HashMapWrapper<AbstractMapJoinKey, MapJoinObjectValue> hashTable = hashTables.getValue();
// get current input file name
String bigBucketFileName = this.getExecContext().getCurrentBigBucketFile();
@@ -408,7 +408,7 @@ public class HashTableSinkOperator exten
bigBucketFileName = "-";
}
// get the tmp URI path; it will be a hdfs path if not local mode
- String tmpURIPath = PathUtil.generatePath(tmpURI, tag, bigBucketFileName);
+ String tmpURIPath = Utilities.generatePath(tmpURI, tag, bigBucketFileName);
hashTable.isAbort(rowNumber, console);
console.printInfo(Utilities.now() + "\tDump the hashtable into file: " + tmpURIPath);
// get the hashtable file and path
Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/MapJoinOperator.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/MapJoinOperator.java?rev=1038842&r1=1038841&r2=1038842&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/MapJoinOperator.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/MapJoinOperator.java Wed Nov 24 21:52:00 2010
@@ -27,6 +27,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.filecache.DistributedCache;
+import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hive.conf.HiveConf;
import org.apache.hadoop.hive.ql.exec.HashTableSinkOperator.HashTableSinkObjectCtx;
@@ -144,7 +145,7 @@ public class MapJoinOperator extends Abs
private void loadHashTable() throws HiveException {
boolean localMode = HiveConf.getVar(hconf, HiveConf.ConfVars.HADOOPJT).equals("local");
- String tmpURI = null;
+ String baseDir = null;
HashMapWrapper<AbstractMapJoinKey, MapJoinObjectValue> hashtable;
Byte pos;
@@ -161,57 +162,36 @@ public class MapJoinOperator extends Abs
try {
if (localMode) {
- LOG.info("******* Load from tmp file uri ***");
- tmpURI = this.getExecContext().getLocalWork().getTmpFileURI();
- for (Map.Entry<Byte, HashMapWrapper<AbstractMapJoinKey, MapJoinObjectValue>> entry : mapJoinTables
- .entrySet()) {
- pos = entry.getKey();
- hashtable = entry.getValue();
- String filePath = Utilities.generatePath(tmpURI, pos, currentFileName);
- Path path = new Path(filePath);
- LOG.info("\tLoad back 1 hashtable file from tmp file uri:" + path.toString());
-
- hashtable.initilizePersistentHash(path.toUri().getPath());
- }
+ baseDir = this.getExecContext().getLocalWork().getTmpFileURI();
} else {
-
- Path[] localFiles = DistributedCache.getLocalCacheFiles(this.hconf);
-
- for (Map.Entry<Byte, HashMapWrapper<AbstractMapJoinKey, MapJoinObjectValue>> entry : mapJoinTables
- .entrySet()) {
- pos = entry.getKey();
- hashtable = entry.getValue();
- String suffix = Utilities.generateFileName(pos, currentFileName);
- LOG.info("Looking for hashtable file with suffix: " + suffix);
-
- boolean found = false;
- for (int i = 0; i < localFiles.length; i++) {
- Path path = localFiles[i];
-
- if (path.toString().endsWith(suffix)) {
- LOG.info("Matching suffix with cached file:" + path.toString());
- LOG.info("\tInitializing the hashtable by cached file:" + path.toString());
- hashtable.initilizePersistentHash(path.toString());
- found = true;
- LOG.info("\tLoad back 1 hashtable file from distributed cache:" + path.toString());
- break;
- }
- }
- if (!found) {
- LOG.error("Load nothing from Distributed Cache");
- throw new HiveException();
+ Path[] localArchives;
+ String stageID = this.getExecContext().getLocalWork().getStageID();
+ String suffix = Utilities.generateTarFileName(stageID);
+ FileSystem localFs = FileSystem.getLocal(hconf);
+ localArchives = DistributedCache.getLocalCacheArchives(this.hconf);
+ Path archive;
+ for (int j = 0; j < localArchives.length; j++) {
+ archive = localArchives[j];
+ if (!archive.getName().endsWith(suffix)) {
+ continue;
}
+ Path archiveLocalLink = archive.makeQualified(localFs);
+ baseDir = archiveLocalLink.toUri().getPath();
}
-
+ }
+ for (Map.Entry<Byte, HashMapWrapper<AbstractMapJoinKey, MapJoinObjectValue>> entry : mapJoinTables
+ .entrySet()) {
+ pos = entry.getKey();
+ hashtable = entry.getValue();
+ String filePath = Utilities.generatePath(baseDir, pos, currentFileName);
+ Path path = new Path(filePath);
+ LOG.info("\tLoad back 1 hashtable file from tmp file uri:" + path.toString());
+ hashtable.initilizePersistentHash(path.toUri().getPath());
}
} catch (Exception e) {
- e.printStackTrace();
- LOG.error("Load Hash Table error");
-
- throw new HiveException();
+ LOG.error("Load Distributed Cache Error");
+ throw new HiveException(e.getMessage());
}
-
-
}
@Override
Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/PathUtil.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/PathUtil.java?rev=1038842&r1=1038841&r2=1038842&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/PathUtil.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/PathUtil.java Wed Nov 24 21:52:00 2010
@@ -1,20 +0,0 @@
-package org.apache.hadoop.hive.ql.exec;
-
-import org.apache.hadoop.fs.Path;
-
-public class PathUtil {
- public static String suffix=".hashtable";
- public static String generatePath(String baseURI,Byte tag,String bigBucketFileName){
- String path = new String(baseURI+Path.SEPARATOR+"-"+tag+"-"+bigBucketFileName+suffix);
- return path;
- }
- public static String generateFileName(Byte tag,String bigBucketFileName){
- String fileName = new String("-"+tag+"-"+bigBucketFileName+suffix);
- return fileName;
- }
-
- public static String generateTmpURI(String baseURI,String id){
- String tmpFileURI = new String(baseURI+Path.SEPARATOR+"HashTable-"+id);
- return tmpFileURI;
- }
-}
Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/Utilities.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/Utilities.java?rev=1038842&r1=1038841&r2=1038842&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/Utilities.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/Utilities.java Wed Nov 24 21:52:00 2010
@@ -1572,13 +1572,13 @@ public final class Utilities {
public static String suffix = ".hashtable";
public static String generatePath(String baseURI, Byte tag, String bigBucketFileName) {
- String path = new String(baseURI + Path.SEPARATOR + "-" + tag + "-" + bigBucketFileName
+ String path = new String(baseURI + Path.SEPARATOR + "MapJoin-" + tag + "-" + bigBucketFileName
+ suffix);
return path;
}
public static String generateFileName(Byte tag, String bigBucketFileName) {
- String fileName = new String("-" + tag + "-" + bigBucketFileName + suffix);
+ String fileName = new String("MapJoin-" + tag + "-" + bigBucketFileName + suffix);
return fileName;
}
@@ -1587,6 +1587,26 @@ public final class Utilities {
return tmpFileURI;
}
+ public static String generateTarURI(String baseURI, String filename) {
+ String tmpFileURI = new String(baseURI + Path.SEPARATOR + filename+".tar.gz");
+ return tmpFileURI;
+ }
+
+ public static String generateTarURI(Path baseURI, String filename) {
+ String tmpFileURI = new String(baseURI + Path.SEPARATOR + filename+".tar.gz");
+ return tmpFileURI;
+ }
+
+ public static String generateTarFileName(String name) {
+ String tmpFileURI = new String(name+".tar.gz");
+ return tmpFileURI;
+ }
+
+ public static String generatePath(Path baseURI, String filename) {
+ String path = new String(baseURI + Path.SEPARATOR + filename);
+ return path;
+ }
+
public static String now() {
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/plan/MapredLocalWork.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/plan/MapredLocalWork.java?rev=1038842&r1=1038841&r2=1038842&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/plan/MapredLocalWork.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/plan/MapredLocalWork.java Wed Nov 24 21:52:00 2010
@@ -43,6 +43,7 @@ public class MapredLocalWork implements
private boolean inputFileChangeSensitive;
private BucketMapJoinContext bucketMapjoinContext;
private String tmpFileURI;
+ private String stageID;
private List<Operator<? extends Serializable>> dummyParentOp ;
@@ -81,6 +82,14 @@ public class MapredLocalWork implements
return aliasToWork;
}
+ public String getStageID() {
+ return stageID;
+ }
+
+ public void setStageID(String stageID) {
+ this.stageID = stageID;
+ }
+
public void setAliasToWork(
final LinkedHashMap<String, Operator<? extends Serializable>> aliasToWork) {