Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

YARN-5924 - Resource Manager fails to load state with InvalidProtocolBufferException #164

Closed
wants to merge 3 commits into from
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