Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.HashMap;
import java.util.List;

import com.google.protobuf.InvalidProtocolBufferException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.classification.InterfaceAudience.Private;
Expand Down Expand Up @@ -298,17 +299,33 @@ private void processDirectoriesOfFiles(
String dirName = dir.getPath().getName();
for (FileStatus fileNodeStatus : listStatusWithRetries(dir.getPath())) {
assert fileNodeStatus.isFile();
String fileName = fileNodeStatus.getPath().getName();
if (checkAndRemovePartialRecordWithRetries(fileNodeStatus.getPath())) {
continue;
try {
String fileName = fileNodeStatus.getPath().getName();
if (checkAndRemovePartialRecordWithRetries(
fileNodeStatus.getPath())) {
continue;
}
byte[] fileData = readFileWithRetries(fileNodeStatus.getPath(),
fileNodeStatus.getLen());
// Set attribute if not already set
setUnreadableBySuperuserXattrib(fileNodeStatus.getPath());

rmAppStateFileProcessor.processChildNode(dirName, fileName,
fileData);
} catch (InvalidProtocolBufferException ex) {
LOG.warn("Removing broken " + dir.getPath() + " app's directory " +
"as its data is invalid, to prevent RM restart failure.", ex);
// removing directory with broken data
if (existsWithRetries(dir.getPath())) {
deleteFileWithRetries(dir.getPath());
}
break;
} catch (Exception ex) {
LOG.warn("Skipping state loading for " + dir.getPath() +
" app's directory because of exception" +
" to prevent RM restart failure", ex);
break;
}
byte[] fileData = readFileWithRetries(fileNodeStatus.getPath(),
fileNodeStatus.getLen());
// Set attribute if not already set
setUnreadableBySuperuserXattrib(fileNodeStatus.getPath());

rmAppStateFileProcessor.processChildNode(dirName, fileName,
fileData);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,41 @@ public void testFSRMStateStore() throws Exception {
}
}

@Test(timeout = 60000)
public void testInvalidAppDataLoad() throws Exception {
HdfsConfiguration conf = new HdfsConfiguration();
MiniDFSCluster cluster =
new MiniDFSCluster.Builder(conf).numDataNodes(1).build();
try {
fsTester = new TestFSRMStateStoreTester(cluster, false);
// If the state store is FileSystemRMStateStore
// then add invalid application data.
// It should discard the entry and remove application
// with broken data from the file system.
FileSystemRMStateStore fileSystemRMStateStore =
(FileSystemRMStateStore) fsTester.getRMStateStore();
String appIdStr = "application_1477986176766_0134";
ApplicationId appId =
ApplicationId.fromString(appIdStr);
Path appDir =
fsTester.store.getAppDir(appId.toString());
Path tempAppFile =
new Path(appDir, appId.toString());

// write invalid data
try (FSDataOutputStream fsOut =
fileSystemRMStateStore.fs.create(tempAppFile, false)) {
fsOut.write("\\00\\00\\00\\00\\00".getBytes());
}

Assert.assertTrue(fileSystemRMStateStore.fs.exists(tempAppFile));
fsTester.getRMStateStore().loadState();
Assert.assertFalse(fileSystemRMStateStore.fs.exists(tempAppFile));
} finally {
cluster.shutdown();
}
}

@Test(timeout = 60000)
public void testHDFSRMStateStore() throws Exception {
final HdfsConfiguration conf = new HdfsConfiguration();
Expand Down