Skip to content
This repository has been archived by the owner on Jan 3, 2023. It is now read-only.

Support Erasure Coding on HDFS-3.x #1924

Merged
merged 20 commits into from
Sep 14, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
keep attributes consistent
PHILO-HE committed Sep 10, 2018
commit 705b64752c640198e9989ef985e8831dc6905704
Original file line number Diff line number Diff line change
@@ -32,6 +32,7 @@
import org.smartdata.conf.SmartConf;
import org.smartdata.hdfs.HadoopUtil;

import java.io.IOException;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;
@@ -80,16 +81,16 @@ protected void execute() throws Exception {
"The EC policy is set successfully for the given directory.";
final String CONVERT_RESULT =
"The file is converted successfully with the given or default ec policy.";

this.setDfsClient(HadoopUtil.getDFSClient(
HadoopUtil.getNameNodeUri(conf), conf));
// keep attribute consistent
//

HdfsFileStatus fileStatus = dfsClient.getFileInfo(srcPath);
if (fileStatus == null) {
throw new ActionException("File doesn't exist!");
}
ValidateEcPolicy(ecPolicyName);
validateEcPolicy(ecPolicyName);
ErasureCodingPolicy srcEcPolicy = fileStatus.getErasureCodingPolicy();
// if the current ecPolicy is already the target one, no need to convert
if (srcEcPolicy != null){
@@ -121,6 +122,7 @@ protected void execute() throws Exception {
dfsClient.append(srcPath, bufferSize, EnumSet.of(CreateFlag.APPEND), null, null);
}
convert(conf, ecPolicyName);
setAttributes(srcPath, ecTmpPath);
dfsClient.rename(ecTmpPath, srcPath, Options.Rename.OVERWRITE);
appendResult(CONVERT_RESULT);
if (srcEcPolicy == null) {
@@ -139,7 +141,7 @@ protected void execute() throws Exception {
}
}

public void ValidateEcPolicy(String ecPolicyName) throws Exception {
public void validateEcPolicy(String ecPolicyName) throws Exception {
Map<String, ErasureCodingPolicyState> ecPolicyNameToState = new HashMap<>();
for (ErasureCodingPolicyInfo info : dfsClient.getErasureCodingPolicies()) {
ecPolicyNameToState.put(info.getPolicy().getName(), info.getState());
Original file line number Diff line number Diff line change
@@ -18,6 +18,7 @@
package org.smartdata.hdfs.action;

import org.apache.hadoop.fs.CreateFlag;
import org.apache.hadoop.fs.XAttrSetFlag;
import org.apache.hadoop.fs.permission.FsPermission;
import org.apache.hadoop.hdfs.DFSConfigKeys;
import org.apache.hadoop.hdfs.DFSInputStream;
@@ -29,6 +30,7 @@

import java.io.IOException;
import java.util.EnumSet;
import java.util.Map;

abstract public class ErasureCodingBase extends HdfsAction {
public static final String BUF_SIZE = "-bufSize";
@@ -81,4 +83,19 @@ protected void convert(SmartConf conf, String ecPolicyName) throws ActionExcepti
}
}
}

// set attributes for dest to keep them consistent with their counterpart of src
protected void setAttributes(String src, String dest) throws IOException {
HdfsFileStatus fileStatus = dfsClient.getFileInfo(src);
dfsClient.setOwner(dest, fileStatus.getOwner(), fileStatus.getGroup());
dfsClient.setPermission(dest, fileStatus.getPermission());
dfsClient.setStoragePolicy(dest, dfsClient.getStoragePolicy(src).getName());
// check whether mtime is changed after rename
dfsClient.setTimes(dest, fileStatus.getModificationTime(), fileStatus.getAccessTime());
dfsClient.setAcl(dest, dfsClient.getAclStatus(src).getEntries());
for(Map.Entry<String, byte[]> entry : dfsClient.getXAttrs(src).entrySet()) {
dfsClient.setXAttr(dest, entry.getKey(), entry.getValue(),
EnumSet.of(XAttrSetFlag.CREATE, XAttrSetFlag.REPLACE));
}
}
}
Original file line number Diff line number Diff line change
@@ -87,6 +87,7 @@ protected void execute() throws Exception {
}
try {
convert(conf, ecPolicyName);
setAttributes(srcPath, ecTmpPath);
dfsClient.rename(ecTmpPath, srcPath, Options.Rename.OVERWRITE);
appendResult(CONVERT_RESULT);
appendResult(String.format("The previous EC policy is {}.", srcEcPolicy.getName()));
Original file line number Diff line number Diff line change
@@ -44,7 +44,6 @@ public void testEcActionForFile() throws Exception {
assertTrue(ecAction.getExpectedAfterRun());
// the file is stored in ec with default policy
assertEquals(dfsClient.getErasureCodingPolicy(srcPath), ecPolicy);
// compare attribute
}

@Test
@@ -66,6 +65,5 @@ public void testEcActionForDir() throws Exception {
createTestFile(srcFilePath, 1000);
// The newly created file should has the same EC policy as parent directory.
assertEquals(dfsClient.getErasureCodingPolicy(srcFilePath), ecPolicy);
// compare attribute
}
}
Original file line number Diff line number Diff line change
@@ -45,7 +45,6 @@ public void testExecute() throws Exception {
unecAction.execute();
assertTrue(unecAction.getExpectedAfterRun());
assertNull(dfsClient.getErasureCodingPolicy(srcPath));
// compare attribute
}

@Test