Skip to content

Commit edbf08e

Browse files
authored
perf: Adapt to Win11(wmic to powershell and compatibility adjustment) (#15350)
1 parent 040f3af commit edbf08e

7 files changed

Lines changed: 36 additions & 39 deletions

File tree

iotdb-client/cli/src/assembly/resources/sbin/start-cli.bat

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
@REM
1919

2020
@echo off
21+
@REM set cmd format
22+
powershell -NoProfile -Command "$v=(Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion').CurrentMajorVersionNumber; if($v -gt 6) { cmd /c 'chcp 65001' }"
23+
2124

2225
@REM DEFAULT_SQL_DIALECT is used to set the default SQL dialect for the CLI.
2326
@REM empty value means using "tree".

iotdb-client/cli/src/assembly/resources/tools/backup.bat

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,10 @@ setlocal
120120
set "pid_to_check=%~1"
121121
set "is_iotdb=0"
122122

123-
for /f "usebackq tokens=*" %%i in (`wmic process where "ProcessId=%pid_to_check%" get CommandLine /format:list ^| findstr /c:"CommandLine="`) do (
124-
set command_line=%%i
125-
)
123+
REM Ensure compatibility by avoiding wmic and using PowerShell if needed
124+
REM No wmic usage detected in this script
125+
126+
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"
126127
echo %command_line% | findstr /i /c:"iotdb" >nul && set is_iotdb=1
127128
endlocal & set "is_iotdb=%is_iotdb%"
128129
exit /b

iotdb-core/confignode/src/assembly/resources/conf/confignode-env.bat

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,19 @@ if %JMX_LOCAL% == "false" (
4949

5050
set CONFIGNODE_JMX_OPTS=%CONFIGNODE_JMX_OPTS% -Diotdb.jmx.local=%JMX_LOCAL%
5151

52-
for /f %%b in ('wmic cpu get numberofcores ^| findstr "[0-9]"') do (
53-
set system_cpu_cores=%%b
52+
REM Replace wmic with PowerShell for CPU core count
53+
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 (
54+
set system_cpu_cores=%%b
5455
)
5556

5657
if %system_cpu_cores% LSS 1 set system_cpu_cores=1
5758

58-
for /f %%b in ('wmic ComputerSystem get TotalPhysicalMemory ^| findstr "[0-9]"') do (
59-
set system_memory=%%b
59+
REM Replace wmic with PowerShell for total physical memory
60+
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 (
61+
set system_memory_in_mb=%%b
6062
)
6163

62-
echo wsh.echo FormatNumber(cdbl(%system_memory%)/(1024*1024), 0) > "%CONFIGNODE_HOME%\sbin\tmp.vbs"
63-
for /f "tokens=*" %%a in ('cscript //nologo "%CONFIGNODE_HOME%\sbin\tmp.vbs"') do set system_memory_in_mb=%%a
64-
del "%CONFIGNODE_HOME%\sbin\tmp.vbs"
64+
REM Remove VBScript usage for memory calculation
6565
set system_memory_in_mb=%system_memory_in_mb:,=%
6666

6767
@REM suggest using memory, system memory 3 / 10

iotdb-core/confignode/src/assembly/resources/sbin/start-confignode.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
@echo off
2121
@REM set cmd format
22-
chcp 65001
22+
powershell -NoProfile -Command "$v=(Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion').CurrentMajorVersionNumber; if($v -gt 6) { cmd /c 'chcp 65001' }"
2323

2424
title IoTDB ConfigNode
2525

iotdb-core/datanode/src/assembly/resources/conf/datanode-env.bat

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,19 @@ if %JMX_LOCAL% == "false" (
4949

5050
set IOTDB_JMX_OPTS=%IOTDB_JMX_OPTS% -Diotdb.jmx.local=%JMX_LOCAL%
5151

52-
for /f %%b in ('wmic cpu get numberofcores ^| findstr "[0-9]"') do (
53-
set system_cpu_cores=%%b
52+
REM Replace wmic with PowerShell for CPU core count
53+
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 (
54+
set system_cpu_cores=%%b
5455
)
5556

5657
if %system_cpu_cores% LSS 1 set system_cpu_cores=1
5758

58-
for /f %%b in ('wmic ComputerSystem get TotalPhysicalMemory ^| findstr "[0-9]"') do (
59-
set system_memory=%%b
59+
REM Replace wmic with PowerShell for total physical memory
60+
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 (
61+
set system_memory_in_mb=%%b
6062
)
6163

62-
echo wsh.echo FormatNumber(cdbl(%system_memory%)/(1024*1024), 0) > "%IOTDB_HOME%\sbin\tmp.vbs"
63-
for /f "tokens=*" %%a in ('cscript //nologo "%IOTDB_HOME%\sbin\tmp.vbs"') do set system_memory_in_mb=%%a
64-
del "%IOTDB_HOME%\sbin\tmp.vbs"
64+
REM Remove VBScript usage for memory calculation
6565
set system_memory_in_mb=%system_memory_in_mb:,=%
6666

6767
set /a suggest_=%system_memory_in_mb%/2

iotdb-core/datanode/src/assembly/resources/sbin/start-datanode.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
@echo off
2121
@REM set cmd format
22-
chcp 65001
22+
powershell -NoProfile -Command "$v=(Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion').CurrentMajorVersionNumber; if($v -gt 6) { cmd /c 'chcp 65001' }"
2323

2424
title IoTDB DataNode
2525

iotdb-core/node-commons/src/assembly/resources/sbin/health_check.bat

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -203,15 +203,13 @@ echo Requirement: Allocate sufficient memory for IoTDB
203203

204204
set "totalMemory="
205205

206-
for /F "skip=1" %%i in ('wmic os get TotalVisibleMemorySize') do (
207-
if not defined totalMemory (
208-
set "totalMemory=%%i"
209-
)
210-
206+
REM Replace wmic with PowerShell for total visible memory size
207+
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 (
208+
set totalMemory=%%i
211209
)
212210

213211
set /A totalMemory=!totalMemory!
214-
set /A totalMemory=totalMemory / 1024 / 1024
212+
215213
if "%confignode_mem%" == "" (
216214
if "%datanode_mem%" == "" (
217215
echo Result: Total Memory %totalMemory% GB
@@ -616,19 +614,15 @@ endlocal
616614
exit /b
617615

618616
:system_settings_check
617+
setlocal enabledelayedexpansion
619618
echo Check: System Settings(Swap)
620619
echo Requirement: disabled
621-
for /f "skip=1" %%s in ('wmic pagefile list /format:list') do (
622-
for /f "tokens=1,2 delims==" %%a in ("%%s") do (
623-
if /i "%%a"=="AllocatedBaseSize" (
624-
if "%%b"=="0" (
625-
echo Result: disabled
626-
) else (
627-
echo Result: enabled
628-
)
629-
)
630-
)
631-
)
620+
621+
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 -EA 0; if(!$page) { 'Disabled' } else { $page | %% { if($_.InitialSize -ne 0 -or $_.MaximumSize -ne 0) { 'Enabled'; exit } } 'Disabled' } } }"
622+
for /f "delims=" %%a in ('powershell -NoProfile -Command "%check_swap_ps_cmd%"') do set "result=%%a"
623+
624+
echo Result: !result!
625+
endlocal
632626
exit /b
633627

634628
:checkIfIOTDBProcess
@@ -637,9 +631,8 @@ setlocal
637631
set "pid_to_check=%~1"
638632
set "is_iotdb=0"
639633

640-
for /f "usebackq tokens=*" %%i in (`wmic process where "ProcessId=%pid_to_check%" get CommandLine /format:list ^| findstr /c:"CommandLine="`) do (
641-
set command_line=%%i
642-
)
634+
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"
635+
643636
echo %command_line% | findstr /i /c:"iotdb" >nul && set is_iotdb=1
644637
endlocal & set "is_iotdb=%is_iotdb%"
645638
exit /b

0 commit comments

Comments
 (0)