-
Notifications
You must be signed in to change notification settings - Fork 29.3k
[SPARK-19721][SS] Good error message for version mismatch in log files #17070
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -204,7 +204,7 @@ class KafkaSourceSuite extends KafkaSourceTest { | |
| override def serialize(metadata: KafkaSourceOffset, out: OutputStream): Unit = { | ||
| out.write(0) | ||
| val writer = new BufferedWriter(new OutputStreamWriter(out, UTF_8)) | ||
| writer.write(s"v0\n${metadata.json}") | ||
| writer.write(s"v99999\n${metadata.json}") | ||
| writer.flush | ||
| } | ||
| } | ||
|
|
@@ -226,7 +226,15 @@ class KafkaSourceSuite extends KafkaSourceTest { | |
| source.getOffset.get // Read initial offset | ||
| } | ||
|
|
||
| assert(e.getMessage.contains("Please upgrade your Spark")) | ||
| Seq( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think it's useful to assert about the exact message. Assert that it has key substrings.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done; thanks! |
||
| s"Failed to read log file ${metadataPath.getCanonicalPath}/0", | ||
| s"UnsupportedLogVersion: maximum supported log version is v${KafkaSource.VERSION}, but " + | ||
| s"encountered v99999", | ||
| "The log file was produced by a newer version of Spark and cannot be read by this version", | ||
| "Please upgrade" | ||
| ).foreach { message => | ||
| assert(e.getMessage.contains(message)) | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ | |
| package org.apache.spark.sql.execution.streaming | ||
|
|
||
| import java.io._ | ||
| import java.lang.IllegalStateException | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You don't need to import from java.lang
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah, what a simple mistake :-) |
||
| import java.nio.charset.StandardCharsets | ||
| import java.util.{ConcurrentModificationException, EnumSet, UUID} | ||
|
|
||
|
|
@@ -195,6 +196,11 @@ class HDFSMetadataLog[T <: AnyRef : ClassTag](sparkSession: SparkSession, path: | |
| val input = fileManager.open(batchMetadataFile) | ||
| try { | ||
| Some(deserialize(input)) | ||
| } catch { | ||
| case ise: IllegalStateException => | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not just let the exception go?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the low-level exception does not know about the log file's path, and I'm trying to put it into the error message to give users very explicit information |
||
| // re-throw the exception with the log file path added | ||
| throw new IllegalStateException( | ||
| s"Failed to read log file $batchMetadataFile. ${ise.getMessage}") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: please also add
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done; thanks! |
||
| } finally { | ||
| IOUtils.closeQuietly(input) | ||
| } | ||
|
|
@@ -268,6 +274,37 @@ class HDFSMetadataLog[T <: AnyRef : ClassTag](sparkSession: SparkSession, path: | |
| new FileSystemManager(metadataPath, hadoopConf) | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Parse the log version from the given `text` -- will throw exception when the parsed version | ||
| * exceeds `maxSupportedVersion`, or when `text` is malformed (such as "xyz", "v", "v-1", | ||
| * "v123xyz" etc.) | ||
| */ | ||
| private[sql] def parseVersion(text: String, maxSupportedVersion: Int): Int = { | ||
| if (text.length > 0 && text(0) == 'v') { | ||
| val version = | ||
| try { text.substring(1, text.length).toInt } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Brace style is wrong
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
| catch { | ||
| case _: NumberFormatException => | ||
| throw new IllegalStateException(s"Log file was malformed: failed to read correct log " + | ||
| s"version from $text.") | ||
| } | ||
| if (version > 0) { | ||
| if (version > maxSupportedVersion) { | ||
| throw new IllegalStateException(s"UnsupportedLogVersion: maximum supported log version " + | ||
| s"is v${maxSupportedVersion}, but encountered v$version. The log file was produced " + | ||
| s"by a newer version of Spark and cannot be read by this version. Please upgrade.") | ||
| } | ||
| else { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Put on previous line; no need to use return
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
| return version | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // reaching here means we failed to read the correct log version | ||
| throw new IllegalStateException(s"Log file was malformed: failed to read correct log " + | ||
| s"version from $text.") | ||
| } | ||
| } | ||
|
|
||
| object HDFSMetadataLog { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Write one string, or write this in 3 steps if you're worried about efficiency? rather than 2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done