@@ -29,15 +29,16 @@ public class DiffJobSession extends CopyJobSession {
29
29
private static DiffJobSession diffJobSession ;
30
30
31
31
private AtomicLong readCounter = new AtomicLong (0 );
32
- private AtomicLong diffCounter = new AtomicLong (0 );
32
+ private AtomicLong mismatchCounter = new AtomicLong (0 );
33
33
private AtomicLong missingCounter = new AtomicLong (0 );
34
34
private AtomicLong correctedMissingCounter = new AtomicLong (0 );
35
- private AtomicLong validDiffCounter = new AtomicLong (0 );
35
+ private AtomicLong correctedMismatchCounter = new AtomicLong (0 );
36
+ private AtomicLong validCounter = new AtomicLong (0 );
36
37
private AtomicLong skippedCounter = new AtomicLong (0 );
37
38
38
39
protected List <MigrateDataType > selectColTypes = new ArrayList <MigrateDataType >();
39
- protected Boolean isDiffOnly = false ;
40
-
40
+ protected Boolean autoCorrectMissing = false ;
41
+ protected Boolean autoCorrectMismatch = false ;
41
42
42
43
public static DiffJobSession getInstance (CqlSession sourceSession , CqlSession astraSession , SparkConf sparkConf ) {
43
44
if (diffJobSession == null ) {
@@ -55,7 +56,8 @@ private DiffJobSession(CqlSession sourceSession, CqlSession astraSession, SparkC
55
56
super (sourceSession , astraSession , sparkConf );
56
57
57
58
selectColTypes = getTypes (sparkConf .get ("spark.migrate.diff.select.types" ));
58
- isDiffOnly = Boolean .parseBoolean (sparkConf .get ("spark.migrate.isDiffOnly" , "false" ));
59
+ autoCorrectMissing = Boolean .parseBoolean (sparkConf .get ("spark.migrate.destination.autocorrect.missing" , "false" ));
60
+ autoCorrectMismatch = Boolean .parseBoolean (sparkConf .get ("spark.migrate.destination.autocorrect.mismatch" , "false" ));
59
61
}
60
62
61
63
public void getDataAndDiff (BigInteger min , BigInteger max ) {
@@ -105,14 +107,16 @@ public void getDataAndDiff(BigInteger min, BigInteger max) {
105
107
public void printCounts (String finalStr ) {
106
108
logger .info ("TreadID: " + Thread .currentThread ().getId () + " " + finalStr + " Read Record Count: "
107
109
+ readCounter .get ());
108
- logger .info ("TreadID: " + Thread .currentThread ().getId () + " " + finalStr + " Read Differences Count: "
109
- + diffCounter .get ());
110
- logger .info ("TreadID: " + Thread .currentThread ().getId () + " " + finalStr + " Read Missing Count: "
110
+ logger .info ("TreadID: " + Thread .currentThread ().getId () + " " + finalStr + " Read Mismatch Count: "
111
+ + mismatchCounter .get ());
112
+ logger .info ("TreadID: " + Thread .currentThread ().getId () + " " + finalStr + " Corrected Mismatch Count: "
113
+ + correctedMismatchCounter .get ());
114
+ logger .info ("TreadID: " + Thread .currentThread ().getId () + " " + finalStr + " Read Missing Count: "
111
115
+ missingCounter .get ());
112
- logger .info ("TreadID: " + Thread .currentThread ().getId () + " " + finalStr + " Read Corrected Missing Count: "
116
+ logger .info ("TreadID: " + Thread .currentThread ().getId () + " " + finalStr + " Corrected Missing Count: "
113
117
+ correctedMissingCounter .get ());
114
118
logger .info ("TreadID: " + Thread .currentThread ().getId () + " " + finalStr + " Read Valid Count: "
115
- + validDiffCounter .get ());
119
+ + validCounter .get ());
116
120
logger .info ("TreadID: " + Thread .currentThread ().getId () + " " + finalStr + " Read Skipped Count: "
117
121
+ skippedCounter .get ());
118
122
}
@@ -123,22 +127,30 @@ private void diff(Row sourceRow, Row astraRow) {
123
127
logger .error ("Data is missing in Astra: " + getKey (sourceRow ));
124
128
//correct data
125
129
126
- if (! isDiffOnly ) {
130
+ if (autoCorrectMissing ) {
127
131
astraSession .execute (bindInsert (astraInsertStatement , sourceRow ));
128
132
correctedMissingCounter .incrementAndGet ();
129
133
logger .error ("Corrected missing data in Astra: " + getKey (sourceRow ));
130
134
}
135
+
131
136
return ;
132
137
}
133
138
134
139
String diffData = isDifferent (sourceRow , astraRow );
135
140
if (!diffData .isEmpty ()) {
136
- diffCounter .incrementAndGet ();
137
- logger .error ("Data difference found - Key: " + getKey (sourceRow ) + " Data: " + diffData );
141
+ mismatchCounter .incrementAndGet ();
142
+ logger .error ("Data mismatch found - Key: " + getKey (sourceRow ) + " Data: " + diffData );
143
+
144
+ if (autoCorrectMismatch ) {
145
+ astraSession .execute (bindInsert (astraInsertStatement , sourceRow ));
146
+ correctedMismatchCounter .incrementAndGet ();
147
+ logger .error ("Corrected mismatch data in Astra: " + getKey (sourceRow ));
148
+ }
149
+
138
150
return ;
139
151
}
140
152
141
- validDiffCounter .incrementAndGet ();
153
+ validCounter .incrementAndGet ();
142
154
}
143
155
144
156
private String isDifferent (Row sourceRow , Row astraRow ) {
0 commit comments