Skip to content
This repository has been archived by the owner on Dec 7, 2022. It is now read-only.

Commit

Permalink
fixing race condition when initializing a subset of slaves
Browse files Browse the repository at this point in the history
  • Loading branch information
ssandler committed Mar 6, 2013
1 parent affc9d0 commit 525fa08
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
3 changes: 2 additions & 1 deletion scripts/AddTable-ToCT.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Param(
[Parameter(Mandatory=$false)][string]$plinkpath, #path to plink.exe
[Parameter(Mandatory=$false)][string]$nzloadscript, #path to netezza load script on the netezza box
[Parameter(Mandatory=$false)][string]$bcppath, #path to bcp files out to for netezza
[Parameter(Mandatory=$false)][long]$syncstartversion, #once the table finishes initializing Tesla will start from this version
[switch]$reinitialize, #just reinitialize the table, don't drop/recreate it
[switch]$notlast, #is this the last slave being (re)initialized? we only update tblCTInitialize if this the last one
[switch]$notfirstshard #for sharding, we only truncate/recreate the slave table for the first shard
Expand Down Expand Up @@ -361,7 +362,7 @@ Invoke-SqlCmd2 -serverinstance $master -database $masterdb -query $query
#insert table name and current change tracking version into tblCTInitialize
#this will only do anything for the first slave being initialized across multiple slaves
$query = "insert into CT_" + $masterdb + "..tblctinitialize
select '$table', GETDATE(), 1, null, change_tracking_current_version()
select '$table', GETDATE(), 1, null, $syncstartversion
where not exists (select 1 from CT_" + $masterdb + "..tblctinitialize where tablename = '$table ')"
Invoke-SqlCmd2 -serverinstance $master -database $masterdb -query $query

Expand Down
13 changes: 11 additions & 2 deletions scripts/Initialize-DB.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,13 @@ CREATE TABLE [dbo].[tblCTSlaveVersion](
VALUES ($version, '1/1/1990', $version, 0);"
$result = invoke-sqlcmd2 -serverinstance $relay -database $relaydb -query $query
}
} else {
#get $version as the start version of the most recent batch, to make sure
#no transactions are skipped after initializing the tables
Write-Host "getting latest syncStartVersion from relay"
$query = "SELECT TOP 1 syncStartVersion FROM tblCTVersion ORDER BY CTID DESC"
$result = invoke-sqlcmd2 -serverinstance $relay -database $relaydb -query $query
$version = $result.syncStartVersion
}

if ($newdatabase -or $newslave) {
Expand Down Expand Up @@ -648,7 +655,8 @@ foreach ($tableconf in $tables.SelectNodes("table")) {
"reinitialize" = $reinitialize;
"notlast" = $notlastslave;
"notfirstshard" = $notfirstshard;
"directory" = $pwd #$pwd is a magic variable for the current working directory
"directory" = $pwd; #$pwd is a magic variable for the current working directory
"syncstartversion" = $version;
}
$tablestoinitialize += $arguments
}
Expand All @@ -666,7 +674,8 @@ $tablestoinitialize | Foreach-Object {
-table $_.table -schema $_.schema -user $_.user -password $_.password -slavecolumnlist $_.slavecolumnlist `
-mastercolumnlist $_.mastercolumnlist -slavecolumnmodifiers $_.slavecolumnmodifiers -mastercolumnmodifiers $_.mastercolumnmodifiers `
-netezzastringlength $_.netezzastringlength -mappingsfile $_.mappingsfile -sshuser $_.sshuser -pkpath $_.pkpath -plinkpath $_.plinkpath `
-nzloadscript $_.nzloadscript -bcppath $_.bcppath -reinitialize:$_.reinitialize -notlast:$_.notlast -notfirstshard:$_.notfirstshard
-nzloadscript $_.nzloadscript -bcppath $_.bcppath -reinitialize:$_.reinitialize -notlast:$_.notlast `
-notfirstshard:$_.notfirstshard -syncstartversion $_.syncstartversion

$duration = [math]::Round((Get-Date).Subtract($starttime).TotalMinutes, 2)
Write-Host ("Initialization complete for table " + $_.table + " in " + $duration + " minutes")
Expand Down

0 comments on commit 525fa08

Please sign in to comment.