-
Notifications
You must be signed in to change notification settings - Fork 29k
[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 all commits
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 |
|---|---|---|
|
|
@@ -195,6 +195,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}", ise) | ||
| } finally { | ||
| IOUtils.closeQuietly(input) | ||
| } | ||
|
|
@@ -268,6 +273,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 | ||
| } 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 { | ||
| 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.
I don't think it's useful to assert about the exact message. Assert that it has key substrings.
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; thanks!