forked from Azure/elastic-db-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExecuteSampleSplitMerge.ps1
More file actions
143 lines (121 loc) · 5.81 KB
/
Copy pathExecuteSampleSplitMerge.ps1
File metadata and controls
143 lines (121 loc) · 5.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<#
/********************************************************
* *
* © Microsoft. All rights reserved. *
* *
*********************************************************/
.SYNOPSIS
Sends sample split and merge requests to the Split-Merge service
and writes the request status to the console output.
.NOTES
Author: Microsoft SQL Elastic Scale team
Last Updated: 8/22/2014
.EXAMPLES
.\ExecuteSampleSplitMerge.ps1 `
-UserName 'mysqluser' `
-Password '<my-sql-pwd-of-choice>' `
-ShardMapManagerServerName 'abcdefghij.database.windows.net' `
-ShardKeyType 'Int32' `
-SplitMergeServiceEndpoint 'https://mysplitmergeservice.cloudapp.net' `
-CertificateThumbprint '0123456789abcdef0123456789abcdef01234567'
.\ExecuteSampleSplitMerge.ps1 `
-UserName 'mysqluser' `
-Password '<my-sql-pwd-of-choice>' `
-ShardMapManagerServerName 'abcdefghij.database.windows.net' `
-ShardKeyType 'Int64' `
-SplitMergeServiceEndpoint 'https://mysplitmergeservice.cloudapp.net' `
-CertificateThumbprint '0123456789abcdef0123456789abcdef01234567'
.\ExecuteSampleSplitMerge.ps1 `
-UserName 'mysqluser' `
-Password '<my-sql-pwd-of-choice>' `
-ShardMapManagerServerName 'abcdefghij.database.windows.net' `
-ShardKeyType 'Guid' `
-SplitRangeLow '00000000-0000-0000-0000-000000000000' `
-SplitValue '10000000-0000-0000-0000-000000000000' `
-SplitRangeHigh '20000000-0000-0000-0000-000000000000' `
-SplitMergeServiceEndpoint 'https://mysplitmergeservice.cloudapp.net' `
-CertificateThumbprint '0123456789abcdef0123456789abcdef01234567'
.\ExecuteSampleSplitMerge.ps1 `
-UserName 'mysqluser' `
-Password '<my-sql-pwd-of-choice>' `
-ShardMapManagerServerName 'abcdefghij.database.windows.net' `
-ShardKeyType 'Binary' `
-SplitRangeLow '0x00' `
-SplitValue '0x64' `
-SplitRangeHigh '0xc8' `
-SplitMergeServiceEndpoint 'https://mysplitmergeservice.cloudapp.net' `
-CertificateThumbprint '0123456789abcdef0123456789abcdef01234567'
.\ExecuteSampleSplitMerge.ps1 `
-UserName 'mysqluser' `
-Password '<my-sql-pwd-of-choice>' `
-ShardMapManagerServerName 'abcdefghij.database.windows.net' `
-ShardKeyType 'Datetime' `
-SplitRangeLow '2010-3-21 12:00:00' `
-SplitValue '2015-7-1 12:00:00' `
-SplitRangeHigh '2018-9-24 12:00:00' `
-SplitMergeServiceEndpoint 'https://mysplitmergeservice.cloudapp.net' `
-CertificateThumbprint '0123456789abcdef0123456789abcdef01234567'
#>
[CmdletBinding()]
param (
[parameter(Mandatory=$true)][string]$UserName,
[parameter(Mandatory=$true)][string]$Password,
[parameter(Mandatory=$true)][string]$ShardMapManagerServerName,
[parameter(Mandatory=$true)][string]$SplitMergeServiceEndpoint,
[string]$ShardMapManagerDatabaseName = 'SplitMergeShardManagement',
[string]$ShardServerName1 = $ShardMapManagerServerName,
[string]$ShardDatabaseName1 = 'ShardDb1',
[string]$ShardServerName2 = $ShardMapManagerServerName,
[string]$ShardDatabaseName2 = 'ShardDb2',
[string]$ShardMapName = "MyTestShardMap",
$ShardKeyType = 'Int32', # Other accepted values are 'Int64', 'Guid', 'Binary', or 'Datetime'
# Below values must be convertible to ShardKeyType
$SplitRangeLow = 0,
$SplitValue = 100,
$SplitRangeHigh = 200,
# The thumbprint of the client certificate to be used for authentication.
# Do not specify if client certificate authentication is not enabled in the service.
[string]$CertificateThumbprint = $null
)
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"
# Import SplitMerge module
$ScriptDir = Split-Path -parent $MyInvocation.MyCommand.Path
Import-Module $ScriptDir\SplitMerge -Force
# Send split request - split the high end of the range to the second shard
Write-Output 'Sending split request'
$splitOperationId = Submit-SplitRequest `
-SplitMergeServiceEndpoint $SplitMergeServiceEndpoint `
-ShardMapManagerServerName $ShardMapManagerServerName `
-ShardMapManagerDatabaseName $ShardMapManagerDatabaseName `
-TargetServerName $ShardServerName2 `
-TargetDatabaseName $ShardDatabaseName2 `
-UserName $UserName `
-Password $Password `
-ShardMapName $ShardMapName `
-ShardKeyType $ShardKeyType `
-SplitRangeLowKey $SplitRangeLow `
-SplitValue $SplitValue `
-SplitRangeHighKey $SplitRangeHigh `
-CertificateThumbprint $CertificateThumbprint
Write-Output "Began split operation with id $splitOperationId"
# Get split request output
Wait-SplitMergeRequest -SplitMergeServiceEndpoint $SplitMergeServiceEndpoint -OperationId $splitOperationId -CertificateThumbprint $CertificateThumbprint
# Send merge request - merge the high end of the range back where the low end of the range is (i.e. the first shard)
Write-Output 'Sending merge request'
$mergeOperationId = Submit-MergeRequest `
-SplitMergeServiceEndpoint $SplitMergeServiceEndpoint `
-ShardMapManagerServerName $ShardMapManagerServerName `
-ShardMapManagerDatabaseName $ShardMapManagerDatabaseName `
-UserName $UserName `
-Password $Password `
-ShardMapName $ShardMapName `
-ShardKeyType $ShardKeyType `
-SourceRangeLowKey $SplitValue `
-SourceRangeHighKey $SplitRangeHigh `
-TargetRangeLowKey $SplitRangeLow `
-TargetRangeHighKey $SplitValue `
-CertificateThumbprint $CertificateThumbprint
Write-Output "Began merge operation with id $mergeOperationId"
# Get merge request output
Wait-SplitMergeRequest -SplitMergeServiceEndpoint $SplitMergeServiceEndpoint -OperationId $mergeOperationId -CertificateThumbprint $CertificateThumbprint