-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-48484][SQL] Fix: V2Write use the same TaskAttemptId for different task attempts #46811
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -38,7 +38,7 @@ case class FileWriterFactory ( | |||||
| @transient private lazy val jobId = SparkHadoopWriterUtils.createJobID(jobTrackerID, 0) | ||||||
|
|
||||||
| override def createWriter(partitionId: Int, realTaskId: Long): DataWriter[InternalRow] = { | ||||||
| val taskAttemptContext = createTaskAttemptContext(partitionId) | ||||||
| val taskAttemptContext = createTaskAttemptContext(partitionId, realTaskId.toInt & Int.MaxValue) | ||||||
|
Contributor
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. is it the same as
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. Yep, it same as
Contributor
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. spark/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/WriteFiles.scala Line 97 in 80addbb
spark/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/FileFormatWriter.scala Line 263 in 45ba922
There are at least two other similar cases here, should we unify them as
Contributor
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 perf matters here, and
Contributor
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. ok, we can unify the above three cases to
Contributor
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. @cloud-fan If overflow, scala> val realTaskId = Long.MaxValue
val realTaskId: Long = 9223372036854775807
scala> val a = realTaskId.toInt
val a: Int = -1
scala> val b = realTaskId.toInt & Int.MaxValue
val b: Int = 2147483647
scala> val c= math.abs(realTaskId.toInt)
val c: Int = 1scala> val realTaskId = Int.MaxValue.toLong + 1
val realTaskId: Long = 2147483648
scala> val a = realTaskId.toInt
val a: Int = -2147483648
scala> val b = realTaskId.toInt & Int.MaxValue
val b: Int = 0
scala> val c= math.abs(realTaskId.toInt)
val c: Int = -2147483648Meanwhile, when an overflow occurs, |
||||||
| committer.setupTask(taskAttemptContext) | ||||||
| if (description.partitionColumns.isEmpty) { | ||||||
| new SingleDirectoryDataWriter(description, taskAttemptContext, committer) | ||||||
|
|
@@ -47,9 +47,11 @@ case class FileWriterFactory ( | |||||
| } | ||||||
| } | ||||||
|
|
||||||
| private def createTaskAttemptContext(partitionId: Int): TaskAttemptContextImpl = { | ||||||
| private def createTaskAttemptContext( | ||||||
| partitionId: Int, | ||||||
| realTaskId: Int): TaskAttemptContextImpl = { | ||||||
| val taskId = new TaskID(jobId, TaskType.MAP, partitionId) | ||||||
| val taskAttemptId = new TaskAttemptID(taskId, 0) | ||||||
| val taskAttemptId = new TaskAttemptID(taskId, realTaskId) | ||||||
| // Set up the configuration object | ||||||
| val hadoopConf = description.serializableHadoopConf.value | ||||||
| hadoopConf.set("mapreduce.job.id", jobId.toString) | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.apache.spark.sql.execution.datasources.v2 | ||
|
|
||
| import org.apache.hadoop.conf.Configuration | ||
| import org.apache.hadoop.mapreduce.task.TaskAttemptContextImpl | ||
| import org.mockito.Mockito._ | ||
| import org.scalatest.PrivateMethodTester | ||
|
|
||
| import org.apache.spark.SparkFunSuite | ||
| import org.apache.spark.internal.io.FileCommitProtocol | ||
| import org.apache.spark.sql.execution.datasources.WriteJobDescription | ||
| import org.apache.spark.util.SerializableConfiguration | ||
|
|
||
| class FileWriterFactorySuite extends SparkFunSuite with PrivateMethodTester { | ||
|
|
||
| test("SPARK-48484: V2Write uses different TaskAttemptIds for different task attempts") { | ||
| val jobDescription = mock(classOf[WriteJobDescription]) | ||
| when(jobDescription.serializableHadoopConf).thenReturn( | ||
| new SerializableConfiguration(new Configuration(false))) | ||
| val committer = mock(classOf[FileCommitProtocol]) | ||
|
|
||
| val writerFactory = FileWriterFactory(jobDescription, committer) | ||
| val createTaskAttemptContext = | ||
| PrivateMethod[TaskAttemptContextImpl](Symbol("createTaskAttemptContext")) | ||
|
|
||
| val attemptContext = | ||
| writerFactory.invokePrivate(createTaskAttemptContext(0, 1)) | ||
| val attemptContext1 = | ||
| writerFactory.invokePrivate(createTaskAttemptContext(0, 2)) | ||
| assert(attemptContext.getTaskAttemptID.getTaskID == attemptContext1.getTaskAttemptID.getTaskID) | ||
| assert(attemptContext.getTaskAttemptID.getId != attemptContext1.getTaskAttemptID.getId) | ||
| } | ||
| } |
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.
Not related to this pr, why not naming it as
taskAttemptId? doesrealTaskIdcan be something else ?