Skip to content

Conversation

Xtpacz
Copy link

@Xtpacz Xtpacz commented Oct 2, 2025

What changes were proposed in this pull request?

Improved two classes:
core/src/main/scala/org/apache/spark/internal/io/HadoopMapReduceCommitProtocol.scala.
sql/hive/src/main/scala/org/apache/spark/sql/hive/execution/InsertIntoHiveDirCommand.scala .
Added a configuration item:
spark.files.rename.numThreads in core/src/main/scala/org/apache/spark/internal/config/package.scala.

Why are the changes needed?

For example, during the insert overwrite directory operation, each rename operation triggers an RPC request. Therefore, when there are too many files, it can be time-consuming.
Converting the serial rename operations to multi-threaded operations can save job execution time.

Does this PR introduce any user-facing change?

Yes. A spark configuration item has been added: spark.files.rename.numThreads.

How was this patch tested?

Verified that the affected tests are passing successfully.

Was this patch authored or co-authored using generative AI tooling?

No.

@Xtpacz Xtpacz changed the title [SPARK-issuesNo][CORE][SQL] Make the rename operations multi-threaded. [SPARK-53791][CORE][SQL] Make the rename operations multi-threaded. Oct 2, 2025
@Xtpacz Xtpacz force-pushed the multi-threaded-rename branch from 1fd74df to 14614f9 Compare October 2, 2025 15:35
@Xtpacz
Copy link
Author

Xtpacz commented Oct 9, 2025

cc @huaxingao @cloud-fan could you review this PR? This is my first PR in the Spark community. Thank you :)

.booleanConf
.createWithDefault(false)

private[spark] val FILES_RENAME_NUM_THREADS = ConfigBuilder("spark.files.rename.numThreads")
Copy link
Contributor

Choose a reason for hiding this comment

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

can this be a dynamic session config in SQLConf?

Copy link
Author

Choose a reason for hiding this comment

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

can this be a dynamic session config in SQLConf?

My understanding is to add a session-scoped SQLConf (e.g., spark.sql.files.rename.numThreads) and have SQL paths read it first, while retaining the global key (spark.files.rename.numThreads) as a fallback since core (e.g., HadoopMapReduceCommitProtocol) cannot depend on SQL. Please let me know if I’ve misunderstood. Thank you!

case Some(sc) => sc.conf.get(FILES_RENAME_NUM_THREADS)
case None => FILES_RENAME_NUM_THREADS.defaultValue.get
}
val pool = ThreadUtils.newDaemonFixedThreadPool(numThreads, "file-rename")
Copy link
Contributor

Choose a reason for hiding this comment

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

shall we have a global long-standing thread pool to do this work?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants