Skip to content

Commit

Permalink
Workbench using SQL Server cluster based on windows failover cluster …
Browse files Browse the repository at this point in the history
…with S2D storage.

PiperOrigin-RevId: 568367684
  • Loading branch information
p3rf Team authored and copybara-github committed Sep 26, 2023
1 parent c6b4b05 commit 6f4d215
Show file tree
Hide file tree
Showing 23 changed files with 601 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
try {
$scriptsFolder = 'c:\scripts'
$domainUser = 'perflab\administrator'
$localServerName = [System.Net.Dns]::GetHostName()
$clearPassword = $args[1]
$taskScriptPath = $scriptsFolder + '\fci-cluster-task.ps1'
$clusterIpAddress = $args[0]

if (-not (Test-Path $scriptsFolder)) {
New-Item -Path $scriptsFolder -ItemType directory
}

Write-Host 'Install SQL Server'
# SQL Server 2022 needs /PRODUCTCOVEREDBYSA=False
$sql2022InstallParam = '/PRODUCTCOVEREDBYSA=False'
$sql2022InstallParam = ''
$sqlInstallString = [string]::Format('c:\sql_server_install\Setup.exe /Action=AddNode /UpdateEnabled=True {2} /ENU=True /CONFIRMIPDEPENDENCYCHANGE=false /SQLSVCACCOUNT=''perflab\sql_server'' /SQLSVCPASSWORD=''{0}'' /AGTSVCACCOUNT=''perflab\sql_server'' /AGTSVCPASSWORD=''{0}'' /INSTANCENAME=''MSSQLSERVER'' /FAILOVERCLUSTERNETWORKNAME=''sql'' /FAILOVERCLUSTERIPADDRESSES=''IPv4;{1};Cluster Network 1;255.255.240.0'' /FAILOVERCLUSTERGROUP=''SQL Server (MSSQLSERVER)'' /SQLSVCINSTANTFILEINIT=''False'' /FTSVCACCOUNT=''NT Service\MSSQLFDLauncher'' /IAcceptSQLServerLicenseTerms=1 /INDICATEPROGRESS /Q 2>&1 > c:\scripts\sqlsetuplog.log',$clearPassword,$clusterIpAddress,$sql2022InstallParam)

Out-File -FilePath $taskScriptPath -InputObject $sqlInstallString

$currentDateTime = Get-Date

$taskName = 'Run-Cluster-Tasks'
$taskAction = New-ScheduledTaskAction -Execute 'PowerShell.exe' -Argument $taskScriptPath
$taskTrigger = New-ScheduledTaskTrigger -Once -At $currentDateTime.AddMinutes(120).ToString('HH:mm:sstt')
$scheduledTask = New-ScheduledTask -Action $taskAction -Trigger $taskTrigger

Register-ScheduledTask -TaskName $taskName -InputObject $scheduledTask -User $domainUser -Password $clearPassword
Start-ScheduledTask -TaskName $taskName


Write-Host 'Running task'
Write-Host (Get-ScheduledTask -TaskName $taskName).State

while ((Get-ScheduledTask -TaskName $taskName).State -ne 'Ready') {
Write-Host -Message 'Waiting on scheduled task...'
Start-Sleep -Seconds 10
}
Start-Sleep -Seconds 10
Disable-ScheduledTask -TaskName $taskName

}
catch {
Write-Host $_.Exception.Message
throw $_.Exception.Message
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
try {
$scriptsFolder = 'c:\scripts'
$diskpartCmdFile = $scriptsFolder + '\diskpartcmd.txt'

if (-not (Test-Path $scriptsFolder)) {
New-Item -Path $scriptsFolder -ItemType directory
}

$physicalDisks = Get-PhysicalDisk | where-object {$_.CanPool -eq $true} | Select-Object -exp DeviceID

New-Item -Path $diskpartCmdFile -itemtype file -force | OUT-NULL

foreach($pd in $physicalDisks) {
Add-Content -path $diskpartCmdFile "select disk $pd"
Add-Content -path $diskpartCmdFile 'clean'
}

diskpart /s $diskpartCmdFile
}
catch {
Write-Host $_.Exception.Message
throw $_.Exception.Message
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
try {
icacls C:\QWitness\ /grant 'sql-fci$:(OI)(CI)(M)'
Grant-SmbShareAccess -Name QWitness -AccountName 'sql-fci$' -AccessRight Full -Force
}
catch {
Write-Host $_.Exception.Message
throw $_.Exception.Message
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
try {
$ErrorActionPreference = 'stop'
Write-Host 'Installing cluster components.'
# Install required Windows features
Install-WindowsFeature Failover-Clustering -IncludeManagementTools
Install-WindowsFeature RSAT-AD-PowerShell

# Open firewall for WSFC
Set-NetFirewallProfile -Profile Domain, Public, Private -Enabled False

}
catch {
Write-Host $_.Exception.Message
throw $_.Exception.Message
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
$dnsServerIpAddress=$args[0]

$nic = Get-NetAdapter

Write-Host "Set DNS Server to $dnsServerIpAddress"

Set-DnsClientServerAddress -InterfaceIndex $nic[0].ifIndex -ServerAddresses $dnsServerIpAddress

$dns_server = Get-DnsClientServerAddress -InterfaceIndex $nic[0].ifIndex -AddressFamily IPv4

if ($dns_server.ServerAddresses -eq $dnsServerIpAddress) {
Write-Host 'DNS Set completed.'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
$domainUser = 'perflab\administrator'
$dnsServerIpAddress=$args[0]

$passwordSecureString = (ConvertTo-SecureString -AsPlainText $args[1] -Force)
$nic = Get-NetAdapter

Write-Host "Set DNS Server to $dnsServerIpAddress"

Set-DnsClientServerAddress -InterfaceIndex $nic[0].ifIndex -ServerAddresses $dnsServerIpAddress

$dns_server = Get-DnsClientServerAddress -InterfaceIndex $nic[0].ifIndex -AddressFamily IPv4

if ($dns_server.ServerAddresses -eq $dnsServerIpAddress) {
Write-Host 'DNS Set. Joining perflab.local Domain'
$credObject = New-Object System.Management.Automation.PSCredential ($domainUser, $passwordSecureString)

Add-Computer -DomainName perflab.local -credential $credObject
Write-Host 'Done'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
$domainName = 'perflab.local'
$netBIOSname = 'perflab'
$mode = 'WinThreshold'

$scriptsFolder = 'c:\scripts'


try {
Write-Host "Pass=$args[0]"
$PasswordSecureString = (ConvertTo-SecureString -AsPlainText $args[0] -Force)
Start-Sleep -Seconds 30

New-LocalUser 'adminuser' -Password $PasswordSecureString -FullName 'Admin User' -PasswordNeverExpires
Add-LocalGroupMember -Group 'Administrators' -Member 'adminuser'


$AdminUserAccount = Get-LocalUser -Name 'Administrator'
$AdminUserAccount | Set-LocalUser -Password $PasswordSecureString
$AdminUserAccount | Enable-LocalUser



Install-WindowsFeature AD-Domain-Services -IncludeAllSubFeature -IncludeManagementTools



Import-Module ADDSDeployment

$forestProperties = @{

DomainName = $domainName
DomainNetbiosName = $netBIOSname
ForestMode = $mode
DomainMode = $mode
CreateDnsDelegation = $false
InstallDns = $true
DatabasePath = 'C:\Windows\NTDS'
LogPath = 'C:\Windows\NTDS'
SysvolPath = 'C:\Windows\SYSVOL'
NoRebootOnCompletion = $true
SafeModeAdministratorPassword = $PasswordSecureString
Force = $true
}

Install-ADDSForest @forestProperties

}
catch {
throw $_.Exception.Message
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
try {
$domainUser = 'perflab\administrator'
$localServerName = [System.Net.Dns]::GetHostName()

$passwordSecureString = (ConvertTo-SecureString -AsPlainText $args[2] -Force)
$node1 = $localServerName + '.perflab.local'
$node2 = $args[0] + '.perflab.local'
$fulldcname = $args[1] + '.perflab.local'

Write-Host $args[2]

$domainCredential = New-Object System.Management.Automation.PSCredential ($domainUser, $passwordSecureString)

Write-Host 'Create failover cluster'
Invoke-Command -ComputerName $fulldcname -Credential $domainCredential -ArgumentList $node1,$node2 -ScriptBlock {
New-Cluster -Name sql-fci -Node $args[0],$args[1] -NoStorage -ManagementPointNetworkType Distributed
}
}
catch {
Write-Host $_.Exception.Message
throw $_.Exception.Message
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
try {
$domainUser = 'perflab\administrator'
$localServerName = [System.Net.Dns]::GetHostName()

$passwordSecureString = (ConvertTo-SecureString -AsPlainText $args[0] -Force)
$node1 = $localServerName + '.perflab.local'

$partVmName = $localServerName.Substring(0, $localServerName.Length - 1)

$node2 = $partVmName + '2.perflab.local'
$dc = $partVmName + '3.perflab.local'

$domainCredential = New-Object System.Management.Automation.PSCredential ($domainUser, $passwordSecureString)

$cacheDiskModel = 'EphemeralDisk'

$nvme_disks = Get-PhysicalDisk | Where-Object { $_.FriendlyName -like 'nvme_card' }
$scsi_disks = Get-PhysicalDisk | Where-Object { $_.FriendlyName -like 'EphemeralDisk' }

if ($nvme_disks.count -gt 0) {
$cacheDiskModel = 'nvme_card'
}
if ($scsi_disks.count -gt 0) {
$cacheDiskModel = 'EphemeralDisk'
}
Write-Host $cacheDiskModel
if ([string]::IsNullOrEmpty($cacheDiskModel)) {
Enable-ClusterStorageSpacesDirect -PoolFriendlyName 's2dpool' -Confirm:0;
}
else {
Invoke-Command -ComputerName $node1 -Credential $domainCredential -ArgumentList $cacheDiskModel -ScriptBlock {
Enable-ClusterStorageSpacesDirect -CacheDeviceModel $args[0] -PoolFriendlyName 's2dpool' -Confirm:0;
}
}
Start-Sleep -Seconds 40
(Get-Cluster).BlockCacheSize = 2048

New-Volume -StoragePoolFriendlyName S2D* -FriendlyName 'Data' -FileSystem CSVFS_ReFS `
-AllocationUnitSize 65536 -ProvisioningType 'Fixed' `
-UseMaximumSize

Write-Host 'Test Cluster'
Invoke-Command -ComputerName $dc -Credential $domainCredential -ArgumentList $node1,$node2 -ScriptBlock {
Test-Cluster -Node $args[0],$args[1] -Confirm:0;
}
Write-Host 'Add SQL service account'
Invoke-Command -ComputerName $dc -Credential $domainCredential -ArgumentList $passwordSecureString -ScriptBlock {
New-ADUser -Name 'sql_server' -Description 'SQL Agent and SQL Admin account.' -AccountPassword $args[0] -Enabled $true -PasswordNeverExpires $true
}
}
catch {
Write-Host $_.Exception.Message
throw $_.Exception.Message
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
try {
$scriptsFolder = 'c:\scripts'
$domainUser = 'perflab\administrator'
$localServerName = [System.Net.Dns]::GetHostName()
$clearPassword = $args[1]
$taskScriptPath = $scriptsFolder + '\fci-cluster-task.ps1'
$clusterIpAddress = $args[0]

if (-not(Test-Path $scriptsFolder)) {
New-Item -Path $scriptsFolder -ItemType directory
}

Write-Host 'Install SQL Server'
# SQL Server 2022 needs /PRODUCTCOVEREDBYSA=False
$sql2022InstallParam = '/PRODUCTCOVEREDBYSA=False'
$sql2022InstallParam = ''
$sqlInstallString = [string]::Format('c:\sql_server_install\Setup.exe /Action=InstallFailoverCluster /UpdateEnabled=True {2} /ENU=True /SQLSVCACCOUNT=''perflab\sql_server'' /SQLSVCPASSWORD=''{0}'' /SAPWD=''{0}'' /AGTSVCACCOUNT=''perflab\sql_server'' /AGTSVCPASSWORD=''{0}'' /FEATURES=SQLENGINE,REPLICATION,FULLTEXT,DQ /INSTANCEID=''MSSQLSERVER'' /INSTANCENAME=''MSSQLSERVER'' /INSTALLSHAREDDIR=''C:\Program Files\Microsoft SQL Server'' /INSTANCEDIR=''C:\Program Files\Microsoft SQL Server'' /FAILOVERCLUSTERDISKS=''Cluster Virtual Disk (Data)'' /FAILOVERCLUSTERNETWORKNAME=''sql'' /FAILOVERCLUSTERIPADDRESSES=''IPv4;{1};Cluster Network 1;255.255.240.0'' /FAILOVERCLUSTERGROUP=''SQL Server (MSSQLSERVER)'' /SQLSVCINSTANTFILEINIT=''True'' /SQLSYSADMINACCOUNTS=''perflab\domain admins'' /IACCEPTSQLSERVERLICENSETERMS=1 /INSTALLSQLDATADIR=''C:\ClusterStorage\Data\'' /SQLUSERDBLOGDIR=''C:\ClusterStorage\Data\MSSQL\Log'' /SQLTEMPDBDIR=''C:\ClusterStorage\Data\MSSQL\Temp'' /FTSVCACCOUNT=''NT Service\MSSQLFDLauncher'' /INDICATEPROGRESS /SECURITYMODE=SQL /Q 2>&1 > c:\scripts\sqlsetuplog.log',$clearPassword, $clusterIpAddress,$sql2022InstallParam)

Out-File -FilePath $taskScriptPath -InputObject $sqlInstallString
Add-Content $taskScriptPath 'Add-ClusterResource -Name fci-dnn -ResourceType ''Distributed Network Name'' -Group ''SQL Server (MSSQLSERVER)'''
Add-Content $taskScriptPath 'Get-ClusterResource -Name fci-dnn | Set-ClusterParameter -Name DnsName -Value fcidnn'
Add-Content $taskScriptPath 'Start-ClusterResource -Name fci-dnn'

$currentDateTime = Get-Date

$taskName = 'Run-Cluster-Tasks'
$taskAction = New-ScheduledTaskAction -Execute 'PowerShell.exe' -Argument $taskScriptPath
$taskTrigger = New-ScheduledTaskTrigger -Once -At $currentDateTime.AddMinutes(120).ToString('HH:mm:sstt')
$scheduledTask = New-ScheduledTask -Action $taskAction -Trigger $taskTrigger

Register-ScheduledTask -TaskName $taskName -InputObject $scheduledTask -User $domainUser -Password $clearPassword
Start-ScheduledTask -TaskName $taskName


Write-Host 'Running task'
Write-Host (Get-ScheduledTask -TaskName $taskName).State

while ((Get-ScheduledTask -TaskName $taskName).State -ne 'Ready') {
Write-Host -Message 'Waiting on scheduled task...'
Start-Sleep -Seconds 10
}
Start-Sleep -Seconds 25
Disable-ScheduledTask -TaskName $taskName

}
catch {
Write-Host $_.Exception.Message
throw $_.Exception.Message
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
try {

Install-WindowsFeature FS-FileServer

# Open firewall for WSFC
Set-NetFirewallProfile -Profile Domain, Public, Private -Enabled False

$local_name = [System.Net.Dns]::GetHostName()
$joined_computers = (Get-AdComputer -filter "Name -NotLike '$local_name'" | Select-Object Name)

New-Item 'C:\QWitness' -type directory

New-SmbShare -Name QWitness -Path 'C:\QWitness' -Description 'SQL File Share Witness' -FullAccess $env:username

foreach ($comp in $joined_computers) {
$node = $comp.Name + '$'
Write-Host $node
icacls C:\QWitness\ /grant '$($node):(OI)(CI)(M)'
Grant-SmbShareAccess -Name 'QWitness' -AccountName $node -AccessRight Full -Force
}
}
catch {
Write-Host $_.Exception.Message
throw $_.Exception.Message
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
$url = 'https://download.microsoft.com/download/6/e/7/6e72dddf-dfa4-4889-bc3d-e5d3a0fd11ce/SQLServer2019-KB5027702-x64.exe'
$dest = 'c:\scripts\SQLServer2019-KB5027702-x64.exe'

# Download the file
(New-Object System.Net.WebClient).DownloadFile($url, $dest)

c:\scripts\SQLServer2019-KB5027702-x64.exe /q /IAcceptSQLServerLicenseTerms /Action=Patch /InstanceName=MSSQLSERVER
5 changes: 4 additions & 1 deletion perfkitbenchmarker/iaas_relational_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,12 @@ def GetDefaultEngineVersion(engine):
def _Create(self):
"""Setup the underlying resource."""
self._SetupUnmanagedDatabase()
self.endpoint = self.server_vm.internal_ip
self.unmanaged_db_exists = True

def _SetEndpoint(self):
"""Set the DB endpoint for this instance during _PostCreate."""
self.endpoint = self.server_vm.internal_ip

def _Delete(self):
"""Deletes the underlying resource.
Expand Down
4 changes: 4 additions & 0 deletions perfkitbenchmarker/os_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@
WINDOWS2019_SQLSERVER_2019_ENTERPRISE = 'windows2019_desktop_sqlserver_2019_enterprise'
WINDOWS2022_SQLSERVER_2019_STANDARD = 'windows2022_desktop_sqlserver_2019_standard'
WINDOWS2022_SQLSERVER_2019_ENTERPRISE = 'windows2022_desktop_sqlserver_2019_enterprise'
WINDOWS2022_SQLSERVER_2022_STANDARD = 'windows2022_desktop_sqlserver_2022_standard'
WINDOWS2022_SQLSERVER_2022_ENTERPRISE = 'windows2022_desktop_sqlserver_2022_enterprise'

# Base-only OS types
DEBIAN = 'debian'
Expand Down Expand Up @@ -146,6 +148,8 @@
WINDOWS2019_SQLSERVER_2019_ENTERPRISE,
WINDOWS2022_SQLSERVER_2019_STANDARD,
WINDOWS2022_SQLSERVER_2019_ENTERPRISE,
WINDOWS2022_SQLSERVER_2022_STANDARD,
WINDOWS2022_SQLSERVER_2022_ENTERPRISE
]

CENTOS_TYPES = [CENTOS7, CENTOS8, CENTOS_STREAM8, CENTOS_STREAM9]
Expand Down
Loading

0 comments on commit 6f4d215

Please sign in to comment.