Skip to content

Commit 8b2b286

Browse files
committed
TEZ-4413: Fix permission may not be set after crash.
1 parent 174d4e3 commit 8b2b286

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

tez-plugins/tez-protobuf-history-plugin/src/main/java/org/apache/tez/dag/history/logging/proto/DatePartitionedLogger.java

+11-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
package org.apache.tez.dag.history.logging.proto;
2020

21+
import java.io.FileNotFoundException;
2122
import java.io.IOException;
2223
import java.time.LocalDate;
2324
import java.time.LocalDateTime;
@@ -71,10 +72,19 @@ public DatePartitionedLogger(Parser<T> parser, Path baseDir, Configuration conf,
7172

7273
private void createDirIfNotExists(Path path) throws IOException {
7374
FileSystem fileSystem = path.getFileSystem(conf);
75+
FileStatus fileStatus = null;
7476
try {
75-
if (!fileSystem.exists(path)) {
77+
fileStatus = fileSystem.getFileStatus(path);
78+
} catch (FileNotFoundException fnf) {
79+
// ignore
80+
}
81+
try {
82+
if (fileStatus == null) {
7683
fileSystem.mkdirs(path);
7784
fileSystem.setPermission(path, DIR_PERMISSION);
85+
} else if (!fileStatus.getPermission().equals(DIR_PERMISSION)) {
86+
LOG.info("Permission on path {} is {}, setting it to {}", path, fileStatus.getPermission(), DIR_PERMISSION);
87+
fileSystem.setPermission(path, DIR_PERMISSION);
7888
}
7989
} catch (IOException e) {
8090
// Ignore this exception, if there is a problem it'll fail when trying to read or write.

tez-plugins/tez-protobuf-history-plugin/src/test/java/org/apache/tez/dag/history/logging/proto/TestProtoHistoryLoggingService.java

+20
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@
3232

3333
import com.google.protobuf.CodedInputStream;
3434
import org.apache.hadoop.conf.Configuration;
35+
import org.apache.hadoop.fs.FileSystem;
3536
import org.apache.hadoop.fs.Path;
37+
import org.apache.hadoop.fs.permission.FsPermission;
38+
import org.apache.hadoop.util.Time;
3639
import org.apache.hadoop.yarn.api.records.ApplicationAttemptId;
3740
import org.apache.hadoop.yarn.api.records.ApplicationId;
3841
import org.apache.hadoop.yarn.api.records.ContainerId;
@@ -267,6 +270,23 @@ public void testServiceSplitEvents() throws Exception {
267270
scanner.close();
268271
}
269272

273+
@Test
274+
public void testDirPermissions() throws IOException {
275+
Path basePath = new Path(tempFolder.newFolder().getAbsolutePath());
276+
Configuration conf = new Configuration();
277+
FileSystem fs = basePath.getFileSystem(conf);
278+
FsPermission expectedPermissions = FsPermission.createImmutable((short) 01777);
279+
280+
// Check the directory already exists and doesn't have the expected permissions.
281+
Assert.assertTrue(fs.exists(basePath));
282+
Assert.assertNotEquals(expectedPermissions, fs.getFileStatus(basePath).getPermission());
283+
284+
new DatePartitionedLogger<>(HistoryEventProto.PARSER, basePath, conf, new FixedClock(Time.now()));
285+
286+
// Check the permissions they should be same as the expected permissions
287+
Assert.assertEquals(expectedPermissions, fs.getFileStatus(basePath).getPermission());
288+
}
289+
270290
private List<DAGHistoryEvent> makeHistoryEvents(TezDAGID dagId,
271291
ProtoHistoryLoggingService service) {
272292
List<DAGHistoryEvent> historyEvents = new ArrayList<>();

0 commit comments

Comments
 (0)