Speed up launch scripts on Windows

Patch by jmckenzie; reviewed by pthompson for CASSANDRA-9615
This commit is contained in:
Joshua McKenzie 2015-08-24 12:44:00 -04:00
parent 941a5dd8a1
commit 2d477a4cc2
2 changed files with 31 additions and 93 deletions

View File

@ -36,8 +36,6 @@ usage: cassandra.ps1 [-f] [-h] [-p pidfile] [-H dumpfile] [-D arg] [-E errorfile
}
#-----------------------------------------------------------------------------
# Note: throughout these scripts we're replacing \ with /. This allows clean
# operation on both command-prompt and cygwin-based environments.
Function Main
{
ValidateArguments
@ -289,89 +287,28 @@ Function VerifyPortsAreAvailable
# native_transport_port
# rpc_port, which we'll match to rpc_address
# and from env: JMX_PORT which we cache in our environment during SetCassandraEnvironment for this check
$toMatch = @("storage_port:","ssl_storage_port:","native_transport_port:","rpc_port")
$yamlRegex = "storage_port:|ssl_storage_port:|native_transport_port:|rpc_port"
$yaml = Get-Content "$env:CASSANDRA_CONF\cassandra.yaml"
$listenAddress = ""
$rpcAddress = ""
foreach ($line in $yaml)
{
if ($line -match "^listen_address:")
{
$args = $line -Split ": "
$listenAddress = $args[1] -replace " ", ""
}
if ($line -match "^rpc_address:")
{
$args = $line -Split ": "
$rpcAddress = $args[1] -replace " ", ""
}
}
if ([string]::IsNullOrEmpty($listenAddress))
{
Write-Error "Failed to parse listen_address from cassandra.yaml to check open ports. Aborting startup."
Exit
}
if ([string]::IsNullOrEmpty($rpcAddress))
{
Write-Error "Failed to parse rpc_address from cassandra.yaml to check open ports. Aborting startup."
Exit
}
$portRegex = ":$env:JMX_PORT |"
foreach ($line in $yaml)
{
foreach ($match in $toMatch)
if ($line -match $yamlRegex)
{
if ($line -match "^$match")
{
if ($line.contains("rpc"))
{
CheckPort $rpcAddress $line
}
else
{
CheckPort $listenAddress $line
}
}
$sa = $line.Split(":")
$portRegex = $portRegex + ":" + ($sa[1] -replace " ","") + " |"
}
}
if ([string]::IsNullOrEmpty($env:JMX_PORT))
{
Write-Error "No JMX_PORT is set in environment. Aborting startup."
Exit
}
CheckPort $listenAddress "jmx_port: $env:JMX_PORT"
}
$portRegex = $portRegex.Substring(0, $portRegex.Length - 2)
#-----------------------------------------------------------------------------
Function CheckPort([string]$listenAddress, [string]$configLine)
{
$split = $configLine -Split ":"
if ($split.Length -ne 2)
{
echo "Invalid cassandra.yaml config line parsed while checking for available ports:"
echo "$configLine"
echo "Aborting startup"
Exit
}
else
{
$port = $split[1] -replace " ", ""
$netstat = netstat -an
# start an async connect to the ip/port combo, give it 25ms, and error out if it succeeded
$tcpobject = new-Object system.Net.Sockets.TcpClient
$connect = $tcpobject.BeginConnect($listenAddress, $port, $null, $null)
$wait = $connect.AsyncWaitHandle.WaitOne(25, $false)
if (!$wait)
foreach ($line in $netstat)
{
if ($line -match "TCP" -and $line -match $portRegex)
{
# still trying to connect, if it's not serviced in 25ms we'll assume it's not open
$tcpobject.Close()
}
else
{
$tcpobject.EndConnect($connect) | out-Null
echo "Cassandra port already in use ($configLine). Aborting"
Write-Error "Found a port already in use. Aborting startup"
Write-Error $line
Exit
}
}
@ -391,6 +328,7 @@ Function ValidateArguments
}
}
#-----------------------------------------------------------------------------
Function CheckEmptyParam($param)
{
if ([String]::IsNullOrEmpty($param))
@ -400,6 +338,8 @@ Function CheckEmptyParam($param)
}
}
#-----------------------------------------------------------------------------
# Populate arguments
for ($i = 0; $i -lt $args.count; $i++)
{
# Skip JVM args

View File

@ -241,13 +241,28 @@ Function ParseJVMInfo
$pinfo.RedirectStandardError = $true
$pinfo.RedirectStandardOutput = $true
$pinfo.UseShellExecute = $false
$pinfo.Arguments = "-version"
$pinfo.Arguments = "-d64 -version"
$p = New-Object System.Diagnostics.Process
$p.StartInfo = $pinfo
$p.Start() | Out-Null
$p.WaitForExit()
$stderr = $p.StandardError.ReadToEnd()
$env:JVM_ARCH = "64-bit"
if ($stderr.Contains("Error"))
{
# 32-bit JVM. re-run w/out -d64
echo "Failed 64-bit check. Re-running to get version from 32-bit"
$pinfo.Arguments = "-version"
$p = New-Object System.Diagnostics.Process
$p.StartInfo = $pinfo
$p.Start() | Out-Null
$p.WaitForExit()
$stderr = $p.StandardError.ReadToEnd()
$env:JVM_ARCH = "32-bit"
}
$sa = $stderr.Split("""")
$env:JVM_VERSION = $sa[1]
@ -266,23 +281,6 @@ Function ParseJVMInfo
$pa = $sa[1].Split("_")
$env:JVM_PATCH_VERSION=$pa[1]
# get 64-bit vs. 32-bit
$pinfo.Arguments = "-d64 -version"
$pArch = New-Object System.Diagnostics.Process
$p.StartInfo = $pinfo
$p.Start() | Out-Null
$p.WaitForExit()
$stderr = $p.StandardError.ReadToEnd()
if ($stderr.Contains("Error"))
{
$env:JVM_ARCH = "32-bit"
}
else
{
$env:JVM_ARCH = "64-bit"
}
}
#-----------------------------------------------------------------------------