6
6
# Migration parameters
7
7
MIGRATOR_VERSION=0.2
8
8
JOB_NAME=CQLReplicator
9
- TILES=1
9
+ TILES=2
10
10
PROCESS_TYPE_DISCOVERY=discovery
11
11
PROCESS_TYPE_REPLICATION=replication
12
12
SOURCE_KS=ks_test_cql_replicator
@@ -23,7 +23,7 @@ DISCOVERED_TOTAL=0
23
23
REPLICATED_TOTAL=0
24
24
OFFLOAD_LARGE_OBJECTS_B64=$( echo " None" | base64)
25
25
BASE_FOLDER=$( pwd -L)
26
- AWS_REGION=" us-east-1 "
26
+ AWS_REGION=" "
27
27
SUBNET=" "
28
28
SG=" "
29
29
AZ=" "
@@ -81,13 +81,17 @@ function check_input() {
81
81
return 0
82
82
}
83
83
84
-
85
84
function check_discovery_runs() {
86
85
local rs
87
- rs=$( aws glue get-job-runs --job-name CQLReplicator --query ' JobRuns[?JobRunState==`RUNNING`] | [].Arguments | [?"--PROCESS_TYPE"==`discovery`]' | jq ' .[0]["--SOURCE_TBL"] == "' " $SOURCE_TBL " ' " and .[0]["--SOURCE_KS"] == "' " $SOURCE_KS " ' "' )
88
- if [[ $rs = " true" ]]; then
89
- # log "ERROR: Discovery job is already running for" $SOURCE_KS.$SOURCE_TBL
90
- return 1
86
+ local mode
87
+ # mode = true, if discovery job is not running return 0
88
+ # mode = false, if discovery job is not running return 1
89
+ mode=$1
90
+ rs=$( aws glue get-job-runs --job-name CQLReplicator --region " $AWS_REGION " --query ' JobRuns[?JobRunState==`RUNNING`] | [].Arguments | [?"--PROCESS_TYPE"==`discovery`]' | jq ' .[0]["--SOURCE_TBL"] == "' " $SOURCE_TBL " ' " and .[0]["--SOURCE_KS"] == "' " $SOURCE_KS " ' "' )
91
+
92
+ if [[ $rs == " $mode " ]]; then
93
+ log " ERROR: The discovery job has failed, check AWS Glue logs"
94
+ exit 1
91
95
fi
92
96
return 0
93
97
}
@@ -96,15 +100,23 @@ function check_replication_runs() {
96
100
local tile
97
101
local rs
98
102
tile=$1
99
- rs=$( aws glue get-job-runs --job-name CQLReplicator --query ' JobRuns[?JobRunState==`RUNNING`] | [].Arguments | [?"--PROCESS_TYPE"==`replication`]' | jq ' .[0]["--SOURCE_TBL"] == "' " $SOURCE_TBL " ' " and .[0]["--SOURCE_KS"] == "' " $SOURCE_KS " ' " and .[]["--TILE"] == "' " $tile " ' "' | grep true)
103
+ rs=$( aws glue get-job-runs --job-name CQLReplicator --region " $AWS_REGION " -- query ' JobRuns[?JobRunState==`RUNNING`] | [].Arguments | [?"--PROCESS_TYPE"==`replication`]' | jq ' .[0]["--SOURCE_TBL"] == "' " $SOURCE_TBL " ' " and .[0]["--SOURCE_KS"] == "' " $SOURCE_KS " ' " and .[]["--TILE"] == "' " $tile " ' "' | grep true)
100
104
101
- if [[ $rs = " true" ]]; then
105
+ if [[ $rs == " true" ]]; then
102
106
# log "ERROR: Replication job is already running per tile $tile for" $SOURCE_KS.$SOURCE_TBL
103
107
return 1
104
108
fi
105
109
return 0
106
110
}
107
111
112
+ function check_num_tiles() {
113
+ if [[ $TILES -lt 2 ]]; then
114
+ log " Total number of tiles should be => 2"
115
+ exit 1
116
+ fi
117
+ return 0
118
+ }
119
+
108
120
function progress {
109
121
local current=" $1 "
110
122
local total=" $2 "
@@ -124,6 +136,7 @@ function progress {
124
136
}
125
137
126
138
function barrier() {
139
+ flag_check_discovery_run=" $1 "
127
140
while true
128
141
do
129
142
cnt=0
@@ -137,6 +150,11 @@ function barrier() {
137
150
if [[ $cnt == " $TILES " ]]; then
138
151
break
139
152
fi
153
+ if [[ $flag_check_discovery_run == " true" ]]; then
154
+ # if the discovery job is not running then fail (return 1)
155
+ sleep 2
156
+ check_discovery_runs " false"
157
+ fi
140
158
done
141
159
}
142
160
@@ -152,6 +170,7 @@ function Usage_Exit {
152
170
log " run - Start migration process"
153
171
log " stats - Upload progress. Only for historical workload"
154
172
log " request-stop - Stop migration process"
173
+ log " cleanup - Delete all CQLReplicator artifacts"
155
174
exit 1
156
175
}
157
176
@@ -161,9 +180,9 @@ function Clean_Up {
161
180
aws s3 rb " $S3_LANDING_ZONE "
162
181
local connection_name
163
182
connection_name=$( aws glue get-job --job-name CQLReplicator --query ' Job.Connections.Connections[0]' --output text)
164
- aws glue delete-connection --connection-name " $connection_name "
165
- aws glue delete-job --job-name CQLReplicator
166
- aws keyspaces delete-keyspace --keyspace-name migration
183
+ aws glue delete-connection --connection-name " $connection_name " --region " $AWS_REGION "
184
+ aws glue delete-job --job-name CQLReplicator --region " $AWS_REGION "
185
+ aws keyspaces delete-keyspace --keyspace-name migration --region " $AWS_REGION "
167
186
}
168
187
169
188
function Init {
@@ -262,22 +281,6 @@ function Init {
262
281
"AvailabilityZone":"' $AZ ' "}
263
282
}' --region " $AWS_REGION " --endpoint https://glue." $AWS_REGION " .amazonaws.com --output json
264
283
265
- # glue_conn_name=$(echo cql-replicator-"$(uuidgen)" | tr ' [:upper:]' ' [:lower:]')
266
- # aws glue create-connection --connection-input '{
267
- # "Name":"'$glue_conn_name'",
268
- # "Description":"CQLReplicator connection to the C* cluster",
269
- # "ConnectionType":"CUSTOM",
270
- # "ConnectionProperties":{
271
- # "CONNECTOR_TYPE": "Spark",
272
- # "CONNECTOR_URL": "'$S3_LANDING_ZONE'/artifacts/spark-cassandra-connector-assembly_2.12-3.4.0.jar",
273
- # "CONNECTOR_CLASS_NAME": "org.apache.spark.sql.cassandra"
274
- # },
275
- # "PhysicalConnectionRequirements":{
276
- # "SubnetId":"'$SUBNET'",
277
- # "SecurityGroupIdList":["'$SG'"],
278
- # "AvailabilityZone":"'$AZ'"}
279
- # }' --region "$AWS_REGION" --endpoint https://glue."$AWS_REGION".amazonaws.com --output json
280
-
281
284
# Create Glue Jobs
282
285
aws glue create-job \
283
286
--name " CQLReplicator" \
@@ -375,22 +378,21 @@ function Start_Discovery {
375
378
check_input " $TARGET_KS " " ERROR: target keyspace name is empty, must be provided"
376
379
check_input " $TARGET_TBL " " ERROR: target table name is empty, must be provided"
377
380
check_input " $S3_LANDING_ZONE " " ERROR: landing zone must be provided"
381
+ check_num_tiles
378
382
379
383
log " TILES:" " $TILES "
380
384
log " SOURCE:" " $SOURCE_KS " ." $SOURCE_TBL "
381
385
log " TARGET:" " $TARGET_KS " ." $TARGET_TBL "
382
386
log " LANDING ZONE:" " $S3_LANDING_ZONE "
383
- log " Writetime column :" $WRITETIME_COLUMN
384
- log " TTL column :" $TTL_COLUMN
387
+ log " WRITE TIME COLUMN :" $WRITETIME_COLUMN
388
+ log " TTL COLUMN :" $TTL_COLUMN
385
389
local workers=$(( 1 + TILES / 2 ))
386
390
log " Checking if the discovery job is already running..."
387
- check_discovery_runs
391
+ check_discovery_runs " true "
388
392
if [ $? = 0 ]; then
389
393
Delete_Stop_Event_D
390
394
log " Starting the discovery job..."
391
- # KEYS_PER_TILE=$(aws s3 cp "$S3_LANDING_ZONE"/"$SOURCE_KS"/"$SOURCE_TBL"/stats/discovery/0/count.json - | head | jq '.primaryKeys')
392
- # log "Average primary keys per tile is $KEYS_PER_TILE"
393
- rs=$( aws glue start-job-run --job-name " $JOB_NAME " --worker-type G.1X --number-of-workers " $workers " --arguments ' {"--PROCESS_TYPE":"' $PROCESS_TYPE_DISCOVERY ' ",
395
+ rs=$( aws glue start-job-run --job-name " $JOB_NAME " --worker-type G.1X --number-of-workers " $workers " --region " $AWS_REGION " --arguments ' {"--PROCESS_TYPE":"' $PROCESS_TYPE_DISCOVERY ' ",
394
396
"--TILE":"0",
395
397
"--TOTAL_TILES":"' $TILES ' ",
396
398
"--S3_LANDING_ZONE":"' $S3_LANDING_ZONE ' ",
@@ -415,7 +417,7 @@ function Start_Replication {
415
417
check_replication_runs $cnt
416
418
if [ $? = 0 ]; then
417
419
Delete_Stop_Event_R $cnt
418
- rs=$( aws glue start-job-run --job-name " $JOB_NAME " --worker-type G.025X --number-of-workers " $workers " --arguments ' {"--PROCESS_TYPE":"' $PROCESS_TYPE_REPLICATION ' ",
420
+ rs=$( aws glue start-job-run --job-name " $JOB_NAME " --worker-type G.025X --number-of-workers " $workers " --region " $AWS_REGION " -- arguments ' {"--PROCESS_TYPE":"' $PROCESS_TYPE_REPLICATION ' ",
419
421
"--TILE":"' $cnt ' ",
420
422
"--TOTAL_TILES":"' $TILES ' ",
421
423
"--S3_LANDING_ZONE":"' $S3_LANDING_ZONE ' ",
@@ -438,7 +440,7 @@ function validate_json() {
438
440
local json_str=$1
439
441
440
442
# Check if the JSON is valid
441
- echo " $json_str " | jq empty # > /dev/null 2>&1
443
+ echo " $json_str " | jq empty
442
444
if [[ $? -ne 0 ]]; then
443
445
log " ERROR: Invalid JSON"
444
446
log ' {"column": "column_name", "bucket": "bucket-name", "prefix": "keyspace_name/table_name/payload", "xref": "reference-column"}'
@@ -595,7 +597,7 @@ eval set -- "$PARAMS"
595
597
596
598
if [[ $STATE == run ]]; then
597
599
Start_Discovery
598
- barrier
600
+ barrier " true "
599
601
Start_Replication
600
602
log " Started jobs:" " ${JOBS[@]} "
601
603
fi
@@ -632,7 +634,8 @@ if [[ $STATE == cleanup ]]; then
632
634
fi
633
635
634
636
if [[ $STATE == stats ]]; then
635
- barrier
637
+ # the barrier without checking if the discovery job is running
638
+ barrier " false"
636
639
tile=0
637
640
while [ $tile -lt " $TILES " ]
638
641
do
0 commit comments