Skip to content
Closed
Changes from 3 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
7 changes: 3 additions & 4 deletions bin/spark-class2.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,9 @@ if not "x%JAVA_HOME%"=="x" (
rem The launcher library prints the command to be executed in a single line suitable for being
rem executed by the batch interpreter. So read all the output of the launcher into a variable.
:gen
set LAUNCHER_OUTPUT=%temp%\spark-class-launcher-output-%RANDOM%.txt
rem SPARK-28302: %RANDOM% would return the same number if we call it instantly after last call,
rem so we should make it sure to generate unique file to avoid process collision of writing into
rem the same file concurrently.
FOR /F %%a IN ('POWERSHELL -COMMAND "$([guid]::NewGuid().ToString())"') DO (SET NEWGUID=%%a)
Copy link
Contributor

Choose a reason for hiding this comment

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

If we use the GUID mechanism, do we still need this logic?

:gen
...
if exist %LAUNCHER_OUTPUT% goto :gen

Copy link
Contributor

Choose a reason for hiding this comment

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

In addition, the current logic strongly relies on Powershell. I am worried about that the lack of Powershell on older versions of Windows will cause launch Spark failures.
Can we eliminate this strong dependence?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we use the GUID mechanism, do we still need this logic?

:gen
...
if exist %LAUNCHER_OUTPUT% goto :gen

You are correct, we shouldn't need this anymore. I can remove it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In addition, the current logic strongly relies on Powershell. I am worried about that the lack of Powershell on older versions of Windows will cause launch Spark failures. Can we eliminate this strong dependence?

As for this concern, I think this is the most lightweight way to generate a GUID in a .cmd script (without installing any dependencies). Powershell is available in Windows 7+ and Windows Server 2008R2+. I would be surprised if there were users running Spark on Windows XP/Vista or Server versions older than 2008. In its current state, you can't reliably instantiate multiple Spark instances on Windows, so I think it's a worthwhile tradeoff.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated to remove below goto statement.

:gen
...
if exist %LAUNCHER_OUTPUT% goto :gen

Copy link
Contributor

Choose a reason for hiding this comment

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

In addition, the current logic strongly relies on Powershell. I am worried about that the lack of Powershell on older versions of Windows will cause launch Spark failures. Can we eliminate this strong dependence?

As for this concern, I think this is the most lightweight way to generate a GUID in a .cmd script (without installing any dependencies). Powershell is available in Windows 7+ and Windows Server 2008R2+. I would be surprised if there were users running Spark on Windows XP/Vista or Server versions older than 2008. In its current state, you can't reliably instantiate multiple Spark instances on Windows, so I think it's a worthwhile tradeoff.

Perhaps we can first check whether Powershell has been installed. If not, use the original logic (until we find a simpler way to generate GUID), and if it is installed, use the logic based on Powershell to generate GUID?

Or prompt to install Powershell if it is not installed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated to add a simple check for powershell.exe and if not exists, fall back to using the Windows %RANDOM% which is the current behavior of this script.

set LAUNCHER_OUTPUT=%temp%\spark-class-launcher-output-%NEWGUID%.txt

if exist %LAUNCHER_OUTPUT% goto :gen
rem unset SHELL to indicate non-bash environment to launcher/Main
set SHELL=
Expand Down