3333import org .smartdata .conf .SmartConfKeys ;
3434import org .smartdata .model .CompressionFileInfo ;
3535import org .smartdata .model .CompressionFileState ;
36+ import org .smartdata .utils .StringUtil ;
3637
3738import java .io .IOException ;
3839import java .io .InputStream ;
@@ -63,7 +64,6 @@ public class CompressionAction extends HdfsAction {
6364 public static final String BUF_SIZE = "-bufSize" ;
6465 public static final String COMPRESS_IMPL = "-compressImpl" ;
6566 private static List <String > compressionImplList = Arrays .asList ("Lz4" ,"Bzip2" ,"Zlib" ,"snappy" );
66- private static final String COMPRESS_DIR = "/system/ssm/compress_tmp" ;
6767
6868 private String filePath ;
6969 private Configuration conf ;
@@ -78,6 +78,9 @@ public class CompressionAction extends HdfsAction {
7878 private CompressionFileInfo compressionFileInfo ;
7979 private CompressionFileState compressionFileState ;
8080
81+ private String compressionTmpPath ;
82+ public static final String COMPRESSION_TMP = "-compressionTmp" ;
83+
8184 @ Override
8285 public void init (Map <String , String > args ) {
8386 super .init (args );
@@ -89,14 +92,17 @@ public void init(Map<String, String> args) {
8992 SmartConfKeys .SMART_COMPRESSION_MAX_SPLIT ,
9093 SmartConfKeys .SMART_COMPRESSION_MAX_SPLIT_DEFAULT );
9194 this .xAttrName = SmartConstants .SMART_FILE_STATE_XATTR_NAME ;
92-
9395 this .filePath = args .get (FILE_PATH );
94- if (args .containsKey (BUF_SIZE )) {
95- this .UserDefinedbuffersize = Integer . valueOf (args .get (BUF_SIZE ));
96+ if (args .containsKey (BUF_SIZE ) && ! args . get ( BUF_SIZE ). isEmpty () ) {
97+ this .UserDefinedbuffersize = ( int ) StringUtil . parseToByte (args .get (BUF_SIZE ));
9698 }
9799 if (args .containsKey (COMPRESS_IMPL )) {
98100 this .compressionImpl = args .get (COMPRESS_IMPL );
99101 }
102+ if (args .containsKey (COMPRESSION_TMP )) {
103+ // this is a temp file kept for compressing a file.
104+ this .compressionTmpPath = args .get (COMPRESSION_TMP );
105+ }
100106 }
101107
102108 @ Override
@@ -120,8 +126,6 @@ protected void execute() throws Exception {
120126 if (srcFile .getLen () == 0 ) {
121127 compressionFileInfo = new CompressionFileInfo (false , compressionFileState );
122128 } else {
123- String tempPath = COMPRESS_DIR + filePath + "_" + "aid" + getActionId () +
124- "_" + System .currentTimeMillis ();
125129 short replication = srcFile .getReplication ();
126130 long blockSize = srcFile .getBlockSize ();
127131 long fileSize = srcFile .getLen ();
@@ -142,12 +146,12 @@ protected void execute() throws Exception {
142146
143147 DFSInputStream dfsInputStream = dfsClient .open (filePath );
144148
145- OutputStream compressedOutputStream = dfsClient .create (tempPath ,
149+ OutputStream compressedOutputStream = dfsClient .create (compressionTmpPath ,
146150 true , replication , blockSize );
147151 compress (dfsInputStream , compressedOutputStream );
148- HdfsFileStatus destFile = dfsClient .getFileInfo (tempPath );
152+ HdfsFileStatus destFile = dfsClient .getFileInfo (compressionTmpPath );
149153 compressionFileState .setCompressedLength (destFile .getLen ());
150- compressionFileInfo = new CompressionFileInfo (true , tempPath , compressionFileState );
154+ compressionFileInfo = new CompressionFileInfo (true , compressionTmpPath , compressionFileState );
151155 }
152156 compressionFileState .setBufferSize (bufferSize );
153157 appendLog ("Final compression bufferSize = " + bufferSize );
0 commit comments