Github user yucai commented on a diff in the pull request:
https://github.com/apache/spark/pull/10225#discussion_r76972643
--- Diff:
core/src/main/scala/org/apache/spark/storage/DiskBlockManager.scala ---
@@ -50,35 +50,98 @@ private[spark] class DiskBlockManager(conf: SparkConf,
deleteFilesOnStop: Boolea
private val shutdownHook = addShutdownHook()
+ private abstract class FileAllocationStrategy {
+ def apply(filename: String): File
+
+ protected def getFile(filename: String, storageDirs: Array[File]):
File = {
+ require(storageDirs.nonEmpty, "could not find file when the
directories are empty")
+
+ // Figure out which local directory it hashes to, and which
subdirectory in that
+ val hash = Utils.nonNegativeHash(filename)
+ val dirId = localDirs.indexOf(storageDirs(hash % storageDirs.length))
+ val subDirId = (hash / storageDirs.length) % subDirsPerLocalDir
+
+ // Create the subdirectory if it doesn't already exist
+ val subDir = subDirs(dirId).synchronized {
+ val old = subDirs(dirId)(subDirId)
+ if (old != null) {
+ old
+ } else {
+ val newDir = new File(localDirs(dirId), "%02x".format(subDirId))
+ if (!newDir.exists() && !newDir.mkdir()) {
--- End diff --
Oh, I see your point now, thanks for explaining!
But I cannot stop the loop, even I get ```availableFile``` from below.
```
if (availableFile == null && file.getParentFile.getUsableSpace >=
layer.threshold) {
availableFile = file
}
```
It is because the file (block) could exist in any hierarchy layers, I have
to go through them.
Anyway to improve?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]