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
1 change: 1 addition & 0 deletions LICENSE-binary
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,7 @@ jakarta.annotation:jakarta-annotation-api https://projects.eclipse.org/projects/
jakarta.servlet:jakarta.servlet-api https://projects.eclipse.org/projects/ee4j.servlet
jakarta.ws.rs:jakarta.ws.rs-api https://github.com/eclipse-ee4j/jaxrs-api
org.glassfish.hk2.external:jakarta.inject
com.github.jnr:jnr-posix


Public Domain
Expand Down
5 changes: 5 additions & 0 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@
<groupId>com.twitter</groupId>
<artifactId>chill-java</artifactId>
</dependency>
<dependency>
<groupId>com.github.jnr</groupId>
<artifactId>jnr-posix</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.xbean</groupId>
<artifactId>xbean-asm9-shaded</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import java.util.HashMap

import com.fasterxml.jackson.core.`type`.TypeReference
import com.fasterxml.jackson.databind.ObjectMapper
import jnr.posix.{POSIX, POSIXFactory}
import org.apache.commons.io.FileUtils
import org.scalatest.{BeforeAndAfterAll, BeforeAndAfterEach}

Expand Down Expand Up @@ -141,28 +142,46 @@ class DiskBlockManagerSuite extends SparkFunSuite with BeforeAndAfterEach with B
assert(attemptId.equals("1"))
}

// Use jnr to get and override the current process umask.
// Expects the input mask to be an octal number
private def getAndSetUmask(posix: POSIX, mask: String): String = {
val prev = posix.umask(BigInt(mask, 8).toInt)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any existing utility for setting umask? I thought Hadoop APIs had this somewhere and that we use it. No big deal if not. But if we have other places we use umask, could be good to standardize

Copy link
Contributor Author

@mridulm mridulm May 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We dont currently get/set process umask. I did see use of jna in hadoop, but that is shaded now.
Any library which allows us to set process umask would do actually, jnr simply seemed to be more easy to use across platforms (this is for tests anyway).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only place I know of is in the native code for the container executor

"0" + "%o".format(prev)
}

test("SPARK-37618: Sub dirs are group writable when removing from shuffle service enabled") {
val conf = testConf.clone
conf.set("spark.local.dir", rootDirs)
conf.set("spark.shuffle.service.enabled", "true")
conf.set("spark.shuffle.service.removeShuffle", "false")
val diskBlockManager = new DiskBlockManager(conf, deleteFilesOnStop = true, isDriver = false)
val blockId = new TestBlockId("test")
val newFile = diskBlockManager.getFile(blockId)
val parentDir = newFile.getParentFile()
assert(parentDir.exists && parentDir.isDirectory)
val permission = Files.getPosixFilePermissions(parentDir.toPath)
assert(!permission.contains(PosixFilePermission.GROUP_WRITE))

assert(parentDir.delete())

conf.set("spark.shuffle.service.removeShuffle", "true")
val diskBlockManager2 = new DiskBlockManager(conf, deleteFilesOnStop = true, isDriver = false)
val newFile2 = diskBlockManager2.getFile(blockId)
val parentDir2 = newFile2.getParentFile()
assert(parentDir2.exists && parentDir2.isDirectory)
val permission2 = Files.getPosixFilePermissions(parentDir2.toPath)
assert(permission2.contains(PosixFilePermission.GROUP_WRITE))
val posix = POSIXFactory.getPOSIX

assume(posix.isNative, "Skipping test for SPARK-37618, native posix support not found")

val oldUmask = getAndSetUmask(posix, "077")
try {
val diskBlockManager = new DiskBlockManager(conf, deleteFilesOnStop = true,
isDriver = false)
val blockId = new TestBlockId("test")
val newFile = diskBlockManager.getFile(blockId)
val parentDir = newFile.getParentFile()
assert(parentDir.exists && parentDir.isDirectory)
val permission = Files.getPosixFilePermissions(parentDir.toPath)
assert(!permission.contains(PosixFilePermission.GROUP_WRITE))

assert(parentDir.delete())

conf.set("spark.shuffle.service.removeShuffle", "true")
val diskBlockManager2 = new DiskBlockManager(conf, deleteFilesOnStop = true,
isDriver = false)
val newFile2 = diskBlockManager2.getFile(blockId)
val parentDir2 = newFile2.getParentFile()
assert(parentDir2.exists && parentDir2.isDirectory)
val permission2 = Files.getPosixFilePermissions(parentDir2.toPath)
assert(permission2.contains(PosixFilePermission.GROUP_WRITE))
} finally {
getAndSetUmask(posix, oldUmask)
}
}

def writeToFile(file: File, numBytes: Int): Unit = {
Expand Down
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,12 @@
<artifactId>chill-java</artifactId>
<version>${chill.version}</version>
</dependency>
<dependency>
<groupId>com.github.jnr</groupId>
<artifactId>jnr-posix</artifactId>
<version>3.1.15</version>
<scope>test</scope>
</dependency>
<!-- This artifact is a shaded version of ASM 9.x. The POM that was used to produce this
is at https://github.com/apache/geronimo-xbean/tree/trunk/xbean-asm9-shaded
For context on why we shade ASM, see SPARK-782 and SPARK-6152. -->
Expand Down