@@ -76,7 +76,7 @@ public void getDataAndInsert(BigInteger min, BigInteger max) {
76
76
for (int retryCount = 1 ; retryCount <= maxAttempts ; retryCount ++) {
77
77
78
78
try {
79
- ResultSet resultSet = sourceSession .execute (sourceSelectStatement .bind (hasRandomPartitioner ? min : min .longValueExact (), hasRandomPartitioner ? max : max .longValueExact ()));
79
+ ResultSet resultSet = sourceSession .execute (sourceSelectStatement .bind (hasRandomPartitioner ? min : min .longValueExact (), hasRandomPartitioner ? max : max .longValueExact ()));
80
80
Collection <CompletionStage <AsyncResultSet >> writeResults = new ArrayList <CompletionStage <AsyncResultSet >>();
81
81
82
82
// cannot do batching if the writeFilter is greater than 0 or
@@ -85,7 +85,7 @@ public void getDataAndInsert(BigInteger min, BigInteger max) {
85
85
for (Row sourceRow : resultSet ) {
86
86
readLimiter .acquire (1 );
87
87
88
- if (writeTimeStampFilter ) {
88
+ if (writeTimeStampFilter ) {
89
89
// only process rows greater than writeTimeStampFilter
90
90
Long sourceWriteTimeStamp = getLargestWriteTimeStamp (sourceRow );
91
91
if (sourceWriteTimeStamp < minWriteTimeStampFilter
@@ -99,22 +99,16 @@ public void getDataAndInsert(BigInteger min, BigInteger max) {
99
99
logger .info ("TreadID: " + Thread .currentThread ().getId () + " Read Record Count: "
100
100
+ readCounter .get ());
101
101
}
102
- if (minWriteTimeStampFilter > 0l ) {
103
- Row astraRow = null ;
104
- if (isCounterTable ) {
105
- ResultSet astraReadResultSet = astraSession
106
- .execute (selectFromAstra (astraSelectStatement , sourceRow ));
107
- astraRow = astraReadResultSet .one ();
108
- }
109
-
110
- CompletionStage <AsyncResultSet > astraWriteResultSet = astraSession
111
- .executeAsync (bindInsert (astraInsertStatement , sourceRow , astraRow ));
112
- writeResults .add (astraWriteResultSet );
113
- } else {
114
- CompletionStage <AsyncResultSet > astraWriteResultSet = astraSession
115
- .executeAsync (bindInsert (astraInsertStatement , sourceRow ));
116
- writeResults .add (astraWriteResultSet );
102
+ Row astraRow = null ;
103
+ if (isCounterTable ) {
104
+ ResultSet astraReadResultSet = astraSession
105
+ .execute (selectFromAstra (astraSelectStatement , sourceRow ));
106
+ astraRow = astraReadResultSet .one ();
117
107
}
108
+
109
+ CompletionStage <AsyncResultSet > astraWriteResultSet = astraSession
110
+ .executeAsync (bindInsert (astraInsertStatement , sourceRow , astraRow ));
111
+ writeResults .add (astraWriteResultSet );
118
112
if (writeResults .size () > 1000 ) {
119
113
iterateAndClearWriteResults (writeResults , 1 );
120
114
}
@@ -124,13 +118,19 @@ public void getDataAndInsert(BigInteger min, BigInteger max) {
124
118
iterateAndClearWriteResults (writeResults , 1 );
125
119
} else {
126
120
BatchStatement batchStatement = BatchStatement .newInstance (BatchType .UNLOGGED );
127
- for (Row row : resultSet ) {
121
+ for (Row sourceRow : resultSet ) {
128
122
readLimiter .acquire (1 );
129
123
writeLimiter .acquire (1 );
130
124
if (readCounter .incrementAndGet () % 1000 == 0 ) {
131
125
logger .info ("TreadID: " + Thread .currentThread ().getId () + " Read Record Count: " + readCounter .get ());
132
126
}
133
- batchStatement = batchStatement .add (bindInsert (astraInsertStatement , row ));
127
+ Row astraRow = null ;
128
+ if (isCounterTable ) {
129
+ ResultSet astraReadResultSet = astraSession
130
+ .execute (selectFromAstra (astraSelectStatement , sourceRow ));
131
+ astraRow = astraReadResultSet .one ();
132
+ }
133
+ batchStatement = batchStatement .add (bindInsert (astraInsertStatement , sourceRow , astraRow ));
134
134
135
135
// if batch threshold is met, send the writes and clear the batch
136
136
if (batchStatement .size () >= batchSize ) {
@@ -166,11 +166,9 @@ public void getDataAndInsert(BigInteger min, BigInteger max) {
166
166
}
167
167
}
168
168
169
-
170
-
171
169
}
172
170
173
- private void iterateAndClearWriteResults (Collection <CompletionStage <AsyncResultSet >> writeResults , int incrementBy ) throws Exception {
171
+ private void iterateAndClearWriteResults (Collection <CompletionStage <AsyncResultSet >> writeResults , int incrementBy ) throws Exception {
174
172
for (CompletionStage <AsyncResultSet > writeResult : writeResults ) {
175
173
//wait for the writes to complete for the batch. The Retry policy, if defined, should retry the write on timeouts.
176
174
writeResult .toCompletableFuture ().get ().one ();
@@ -181,41 +179,34 @@ private void iterateAndClearWriteResults(Collection<CompletionStage<AsyncResultS
181
179
writeResults .clear ();
182
180
}
183
181
184
- public BoundStatement bindInsert (PreparedStatement insertStatement , Row sourceRow ) {
185
- return bindInsert (insertStatement , sourceRow , null );
186
- }
187
-
188
182
public BoundStatement bindInsert (PreparedStatement insertStatement , Row sourceRow , Row astraRow ) {
189
- if ( isCounterTable ) {
183
+ BoundStatement boundInsertStatement = insertStatement . bind ();
190
184
191
- BoundStatement boundInsertStatement = insertStatement . bind ();
185
+ if ( isCounterTable ) {
192
186
for (int index = 0 ; index < insertColTypes .size (); index ++) {
193
187
MigrateDataType dataType = insertColTypes .get (index );
194
188
// compute the counter delta if reading from astra for the difference
195
189
if (astraRow != null && isCounterTable && index <= counterDeltaMaxIndex ) {
196
- boundInsertStatement = boundInsertStatement .set (index ,getCounterDelta (sourceRow .getLong (updateSelectMapping .get (index )), astraRow .getLong (updateSelectMapping .get (index ))),Long .class );
190
+ boundInsertStatement = boundInsertStatement .set (index , getCounterDelta (sourceRow .getLong (updateSelectMapping .get (index )), astraRow .getLong (updateSelectMapping .get (index ))), Long .class );
197
191
} else {
198
192
boundInsertStatement = boundInsertStatement .set (index , getData (dataType , updateSelectMapping .get (index ), sourceRow ), dataType .typeClass );
199
193
}
200
194
}
201
-
202
- return boundInsertStatement ;
203
-
204
195
} else {
205
- BoundStatement boundInsertStatement = insertStatement .bind ();
206
196
int index = 0 ;
207
197
for (index = 0 ; index < insertColTypes .size (); index ++) {
208
- MigrateDataType dataType = insertColTypes .get (index );
198
+ MigrateDataType dataTypeObj = insertColTypes .get (index );
199
+ Class dataType = dataTypeObj .typeClass ;
209
200
210
201
try {
211
- Object colData = getData (dataType , index , sourceRow );
212
- if (index < idColTypes .size () && colData == null && dataType . typeClass == String .class ){
213
- colData = "" ;
202
+ Object colData = getData (dataTypeObj , index , sourceRow );
203
+ if (index < idColTypes .size () && colData == null && dataType == String .class ) {
204
+ colData = "" ;
214
205
}
215
- boundInsertStatement = boundInsertStatement .set (index , colData , dataType . typeClass );
206
+ boundInsertStatement = boundInsertStatement .set (index , colData , dataType );
216
207
} catch (NullPointerException e ) {
217
208
// ignore the exception for map values being null
218
- if (dataType . typeClass != Map .class ) {
209
+ if (dataType != Map .class ) {
219
210
throw e ;
220
211
}
221
212
}
@@ -226,9 +217,9 @@ public BoundStatement bindInsert(PreparedStatement insertStatement, Row sourceRo
226
217
index ++;
227
218
boundInsertStatement = boundInsertStatement .set (index , getLargestWriteTimeStamp (sourceRow ), Long .class );
228
219
}
229
- return boundInsertStatement ;
230
-
231
220
}
221
+
222
+ return boundInsertStatement ;
232
223
}
233
224
234
225
public Long getCounterDelta (Long sourceRow , Long astraRow ) {
0 commit comments