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 @@ -254,7 +254,9 @@ private[state] class HDFSBackedStateStoreProvider(
private def commitUpdates(newVersion: Long, map: MapType, tempDeltaFile: Path): Path = {
synchronized {
val finalDeltaFile = deltaFile(newVersion)
fs.rename(tempDeltaFile, finalDeltaFile)
if (!fs.rename(tempDeltaFile, finalDeltaFile)) {
throw new IOException(s"Failed to rename $tempDeltaFile to $finalDeltaFile")
}
loadedMaps.put(newVersion, map)
finalDeltaFile
}
Expand Down Expand Up @@ -525,7 +527,7 @@ private[state] class HDFSBackedStateStoreProvider(

val deltaFiles = allFiles.filter { file =>
file.version > snapshotFile.version && file.version <= version
}
}.toList
Copy link
Contributor Author

Choose a reason for hiding this comment

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

the line returns a Stream which is a Scala Iterator like class, therefore the logging below doesn't work

verify(
deltaFiles.size == version - snapshotFile.version,
s"Unexpected list of delta files for version $version for $this: $deltaFiles"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@

package org.apache.spark.sql.execution.streaming.state

import java.io.File
import java.io.{File, IOException}
import java.net.URI

import scala.collection.mutable
import scala.util.Random

import org.apache.hadoop.conf.Configuration
import org.apache.hadoop.fs.Path
import org.apache.hadoop.fs.{FileStatus, Path, RawLocalFileSystem}
import org.scalatest.{BeforeAndAfter, PrivateMethodTester}
import org.scalatest.concurrent.Eventually._
import org.scalatest.time.SpanSugar._
Expand Down Expand Up @@ -455,6 +456,18 @@ class StateStoreSuite extends SparkFunSuite with BeforeAndAfter with PrivateMeth
}
}

test("SPARK-18342: commit fails when rename fails") {
import RenameReturnsFalseFileSystem._
val dir = scheme + "://" + Utils.createDirectory(tempDir, Random.nextString(5)).toString
val conf = new Configuration()
conf.set(s"fs.$scheme.impl", classOf[RenameReturnsFalseFileSystem].getName)
val provider = newStoreProvider(dir = dir, hadoopConf = conf)
val store = provider.getStore(0)
put(store, "a", 0)
val e = intercept[IllegalStateException](store.commit())
assert(e.getCause.getMessage.contains("Failed to rename"))
}

def getDataFromFiles(
provider: HDFSBackedStateStoreProvider,
version: Int = -1): Set[(String, Int)] = {
Expand Down Expand Up @@ -524,17 +537,18 @@ class StateStoreSuite extends SparkFunSuite with BeforeAndAfter with PrivateMeth
def newStoreProvider(
opId: Long = Random.nextLong,
partition: Int = 0,
minDeltasForSnapshot: Int = SQLConf.STATE_STORE_MIN_DELTAS_FOR_SNAPSHOT.defaultValue.get
minDeltasForSnapshot: Int = SQLConf.STATE_STORE_MIN_DELTAS_FOR_SNAPSHOT.defaultValue.get,
dir: String = Utils.createDirectory(tempDir, Random.nextString(5)).toString,
hadoopConf: Configuration = new Configuration()
): HDFSBackedStateStoreProvider = {
val dir = Utils.createDirectory(tempDir, Random.nextString(5)).toString
val sqlConf = new SQLConf()
sqlConf.setConf(SQLConf.STATE_STORE_MIN_DELTAS_FOR_SNAPSHOT, minDeltasForSnapshot)
new HDFSBackedStateStoreProvider(
StateStoreId(dir, opId, partition),
keySchema,
valueSchema,
new StateStoreConf(sqlConf),
new Configuration())
hadoopConf)
}

def remove(store: StateStore, condition: String => Boolean): Unit = {
Expand Down Expand Up @@ -598,3 +612,20 @@ private[state] object StateStoreSuite {
}}.toSet
}
}

/**
* Fake FileSystem to test that the StateStore throws an exception while committing the
* delta file, when `fs.rename` returns `false`.
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

Wrong docs.

class RenameReturnsFalseFileSystem extends RawLocalFileSystem {
import RenameReturnsFalseFileSystem._
override def getUri: URI = {
URI.create(s"$scheme:///")
}

override def rename(src: Path, dst: Path): Boolean = false
}

object RenameReturnsFalseFileSystem {
val scheme = s"StateStoreSuite${math.abs(Random.nextInt)}fs"
}