This is an automated email from the ASF dual-hosted git repository. critas pushed a commit to branch wx_update_bat_to1.3 in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit 8105c4bf8a876baab7513caa42f3cbd9a985904b Author: CritasWang <[email protected]> AuthorDate: Fri Apr 18 10:30:50 2025 +0800 perf: Adapt to Win11(wmic to powershell and compatibility adjustment) (#15350) (cherry picked from commit edbf08ebccde60d40136793d39602f0e46a16e29) --- .../cli/src/assembly/resources/sbin/start-cli.bat | 3 ++ .../cli/src/assembly/resources/tools/backup.bat | 7 +++-- .../src/assembly/resources/conf/confignode-env.bat | 14 ++++----- .../assembly/resources/sbin/start-confignode.bat | 2 +- .../src/assembly/resources/conf/datanode-env.bat | 14 ++++----- .../src/assembly/resources/sbin/start-datanode.bat | 2 +- .../src/assembly/resources/sbin/health_check.bat | 33 +++++++++------------- 7 files changed, 36 insertions(+), 39 deletions(-) diff --git a/iotdb-client/cli/src/assembly/resources/sbin/start-cli.bat b/iotdb-client/cli/src/assembly/resources/sbin/start-cli.bat index d854965b4ec..82c9b46c6d0 100644 --- a/iotdb-client/cli/src/assembly/resources/sbin/start-cli.bat +++ b/iotdb-client/cli/src/assembly/resources/sbin/start-cli.bat @@ -18,6 +18,9 @@ @REM @echo off +@REM set cmd format +powershell -NoProfile -Command "$v=(Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion').CurrentMajorVersionNumber; if($v -gt 6) { cmd /c 'chcp 65001' }" + @REM You can put your env variable here @REM set JAVA_HOME=%JAVA_HOME% diff --git a/iotdb-client/cli/src/assembly/resources/tools/backup.bat b/iotdb-client/cli/src/assembly/resources/tools/backup.bat index e7974164b08..0fa7c82776e 100644 --- a/iotdb-client/cli/src/assembly/resources/tools/backup.bat +++ b/iotdb-client/cli/src/assembly/resources/tools/backup.bat @@ -120,9 +120,10 @@ setlocal set "pid_to_check=%~1" set "is_iotdb=0" -for /f "usebackq tokens=*" %%i in (`wmic process where "ProcessId=%pid_to_check%" get CommandLine /format:list ^| findstr /c:"CommandLine="`) do ( - set command_line=%%i -) +REM Ensure compatibility by avoiding wmic and using PowerShell if needed +REM No wmic usage detected in this script + +for /f "delims=" %%i in ('powershell -NoProfile -Command "$v=$host.Version.Major; if($v -lt 3) {Get-WmiObject Win32_Process -Filter \"ProcessId='%pid_to_check%'\"} else {Get-CimInstance Win32_Process -Filter \"ProcessId='%pid_to_check%'\"}; $process.CommandLine"') do set "command_line=%%i" echo %command_line% | findstr /i /c:"iotdb" >nul && set is_iotdb=1 endlocal & set "is_iotdb=%is_iotdb%" exit /b diff --git a/iotdb-core/confignode/src/assembly/resources/conf/confignode-env.bat b/iotdb-core/confignode/src/assembly/resources/conf/confignode-env.bat index d270c08f54e..819ea62f0ea 100644 --- a/iotdb-core/confignode/src/assembly/resources/conf/confignode-env.bat +++ b/iotdb-core/confignode/src/assembly/resources/conf/confignode-env.bat @@ -49,19 +49,19 @@ if %JMX_LOCAL% == "false" ( set CONFIGNODE_JMX_OPTS=%CONFIGNODE_JMX_OPTS% -Diotdb.jmx.local=%JMX_LOCAL% -for /f %%b in ('wmic cpu get numberofcores ^| findstr "[0-9]"') do ( - set system_cpu_cores=%%b +REM Replace wmic with PowerShell for CPU core count +for /f %%b in ('powershell -NoProfile -Command "$v=$host.Version.Major; if($v -lt 3) {(Get-WmiObject Win32_Processor).NumberOfCores} else {(Get-CimInstance -ClassName Win32_Processor).NumberOfCores}"') do ( + set system_cpu_cores=%%b ) if %system_cpu_cores% LSS 1 set system_cpu_cores=1 -for /f %%b in ('wmic ComputerSystem get TotalPhysicalMemory ^| findstr "[0-9]"') do ( - set system_memory=%%b +REM Replace wmic with PowerShell for total physical memory +for /f %%b in ('powershell -NoProfile -Command "$v=$host.Version.Major; $mem=if($v -lt 3){(Get-WmiObject Win32_ComputerSystem).TotalPhysicalMemory} else{(Get-CimInstance -ClassName Win32_ComputerSystem).TotalPhysicalMemory}; [math]::Round($mem/1048576)"') do ( + set system_memory_in_mb=%%b ) -echo wsh.echo FormatNumber(cdbl(%system_memory%)/(1024*1024), 0) > "%CONFIGNODE_HOME%\sbin\tmp.vbs" -for /f "tokens=*" %%a in ('cscript //nologo "%CONFIGNODE_HOME%\sbin\tmp.vbs"') do set system_memory_in_mb=%%a -del "%CONFIGNODE_HOME%\sbin\tmp.vbs" +REM Remove VBScript usage for memory calculation set system_memory_in_mb=%system_memory_in_mb:,=% @REM suggest using memory, system memory 3 / 10 diff --git a/iotdb-core/confignode/src/assembly/resources/sbin/start-confignode.bat b/iotdb-core/confignode/src/assembly/resources/sbin/start-confignode.bat index 98399a9990b..40c5869549e 100644 --- a/iotdb-core/confignode/src/assembly/resources/sbin/start-confignode.bat +++ b/iotdb-core/confignode/src/assembly/resources/sbin/start-confignode.bat @@ -19,7 +19,7 @@ @echo off @REM set cmd format -chcp 65001 +powershell -NoProfile -Command "$v=(Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion').CurrentMajorVersionNumber; if($v -gt 6) { cmd /c 'chcp 65001' }" title IoTDB ConfigNode diff --git a/iotdb-core/datanode/src/assembly/resources/conf/datanode-env.bat b/iotdb-core/datanode/src/assembly/resources/conf/datanode-env.bat index 16921072dba..df8e8ac6334 100644 --- a/iotdb-core/datanode/src/assembly/resources/conf/datanode-env.bat +++ b/iotdb-core/datanode/src/assembly/resources/conf/datanode-env.bat @@ -49,19 +49,19 @@ if %JMX_LOCAL% == "false" ( set IOTDB_JMX_OPTS=%IOTDB_JMX_OPTS% -Diotdb.jmx.local=%JMX_LOCAL% -for /f %%b in ('wmic cpu get numberofcores ^| findstr "[0-9]"') do ( - set system_cpu_cores=%%b +REM Replace wmic with PowerShell for CPU core count +for /f %%b in ('powershell -NoProfile -Command "$v=$host.Version.Major; if($v -lt 3) {(Get-WmiObject Win32_Processor).NumberOfCores} else {(Get-CimInstance -ClassName Win32_Processor).NumberOfCores}"') do ( + set system_cpu_cores=%%b ) if %system_cpu_cores% LSS 1 set system_cpu_cores=1 -for /f %%b in ('wmic ComputerSystem get TotalPhysicalMemory ^| findstr "[0-9]"') do ( - set system_memory=%%b +REM Replace wmic with PowerShell for total physical memory +for /f %%b in ('powershell -NoProfile -Command "$v=$host.Version.Major; $mem=if($v -lt 3){(Get-WmiObject Win32_ComputerSystem).TotalPhysicalMemory} else{(Get-CimInstance -ClassName Win32_ComputerSystem).TotalPhysicalMemory}; [math]::Round($mem/1048576)"') do ( + set system_memory_in_mb=%%b ) -echo wsh.echo FormatNumber(cdbl(%system_memory%)/(1024*1024), 0) > "%IOTDB_HOME%\sbin\tmp.vbs" -for /f "tokens=*" %%a in ('cscript //nologo "%IOTDB_HOME%\sbin\tmp.vbs"') do set system_memory_in_mb=%%a -del "%IOTDB_HOME%\sbin\tmp.vbs" +REM Remove VBScript usage for memory calculation set system_memory_in_mb=%system_memory_in_mb:,=% set /a suggest_=%system_memory_in_mb%/2 diff --git a/iotdb-core/datanode/src/assembly/resources/sbin/start-datanode.bat b/iotdb-core/datanode/src/assembly/resources/sbin/start-datanode.bat index fcbce7ed4b0..c80aaf6f551 100755 --- a/iotdb-core/datanode/src/assembly/resources/sbin/start-datanode.bat +++ b/iotdb-core/datanode/src/assembly/resources/sbin/start-datanode.bat @@ -19,7 +19,7 @@ @echo off @REM set cmd format -chcp 65001 +powershell -NoProfile -Command "$v=(Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion').CurrentMajorVersionNumber; if($v -gt 6) { cmd /c 'chcp 65001' }" title IoTDB DataNode diff --git a/iotdb-core/node-commons/src/assembly/resources/sbin/health_check.bat b/iotdb-core/node-commons/src/assembly/resources/sbin/health_check.bat index 78b2ce5930c..19c40f3974e 100644 --- a/iotdb-core/node-commons/src/assembly/resources/sbin/health_check.bat +++ b/iotdb-core/node-commons/src/assembly/resources/sbin/health_check.bat @@ -203,15 +203,13 @@ echo Requirement: Allocate sufficient memory for IoTDB set "totalMemory=" -for /F "skip=1" %%i in ('wmic os get TotalVisibleMemorySize') do ( - if not defined totalMemory ( - set "totalMemory=%%i" - ) - +REM Replace wmic with PowerShell for total visible memory size +for /f %%i in ('powershell -NoProfile -Command "$v=$host.Version.Major; $mem=if($v -lt 3){(Get-WmiObject Win32_OperatingSystem).TotalVisibleMemorySize} else{(Get-CimInstance -ClassName Win32_OperatingSystem).TotalVisibleMemorySize}; [math]::Round($mem/1024)"') do ( + set totalMemory=%%i ) set /A totalMemory=!totalMemory! -set /A totalMemory=totalMemory / 1024 / 1024 + if "%confignode_mem%" == "" ( if "%datanode_mem%" == "" ( echo Result: Total Memory %totalMemory% GB @@ -616,19 +614,15 @@ endlocal exit /b :system_settings_check +setlocal enabledelayedexpansion echo Check: System Settings(Swap) echo Requirement: disabled -for /f "skip=1" %%s in ('wmic pagefile list /format:list') do ( - for /f "tokens=1,2 delims==" %%a in ("%%s") do ( - if /i "%%a"=="AllocatedBaseSize" ( - if "%%b"=="0" ( - echo Result: disabled - ) else ( - echo Result: enabled - ) - ) - ) -) + +set "check_swap_ps_cmd=$v=$host.Version.Major; if($v -lt 3) { $sys=Get-WmiObject Win32_ComputerSystem; if($sys.AutomaticManagedPagefile) { 'Enabled' } else { $page=Get-WmiObject Win32_PageFileSetting -EA 0; if(!$page) { 'Disabled' } else { $page | %% { if($_.InitialSize -ne 0 -or $_.MaximumSize -ne 0) { 'Enabled'; exit } } 'Disabled' } } } else { $sys=Get-CimInstance Win32_ComputerSystem; if($sys.AutomaticManagedPagefile) { 'Enabled' } else { $page=Get-CimInstance Win32_PageFileSetting - [...] +for /f "delims=" %%a in ('powershell -NoProfile -Command "%check_swap_ps_cmd%"') do set "result=%%a" + +echo Result: !result! +endlocal exit /b :checkIfIOTDBProcess @@ -637,9 +631,8 @@ setlocal set "pid_to_check=%~1" set "is_iotdb=0" -for /f "usebackq tokens=*" %%i in (`wmic process where "ProcessId=%pid_to_check%" get CommandLine /format:list ^| findstr /c:"CommandLine="`) do ( - set command_line=%%i -) +for /f "delims=" %%i in ('powershell -NoProfile -Command "$v=$host.Version.Major; if($v -lt 3) { (Get-WmiObject Win32_Process -Filter \"ProcessId='%pid_to_check%'\").CommandLine } else { (Get-CimInstance Win32_Process -Filter \"ProcessId='%pid_to_check%'\").CommandLine }"') do set "command_line=%%i" + echo %command_line% | findstr /i /c:"iotdb" >nul && set is_iotdb=1 endlocal & set "is_iotdb=%is_iotdb%" exit /b \ No newline at end of file
