Skip to content

Commit c3da026

Browse files
committed
Optimized using parallel-stream
1 parent 8f790cb commit c3da026

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

src/main/java/datastax/astra/migrate/CopyPKJobSession.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public static CopyPKJobSession getInstance(CqlSession sourceSession, CqlSession
3939

4040
public void getRowAndInsert(List<SplitPartitions.PKRows> rowsList) {
4141
for (SplitPartitions.PKRows rows : rowsList) {
42-
for (String row : rows.pkRows) {
42+
rows.pkRows.parallelStream().forEach(row -> {
4343
readCounter.incrementAndGet();
4444
String[] pkFields = row.split(" %% ");
4545
int idx = 0;
@@ -52,20 +52,30 @@ public void getRowAndInsert(List<SplitPartitions.PKRows> rowsList) {
5252
if (null == pkRow) {
5353
missingCounter.incrementAndGet();
5454
logger.error("Could not find row with primary-key: " + row);
55-
continue;
55+
return;
5656
}
5757
ResultSet astraWriteResultSet = astraSession
5858
.execute(bindInsert(astraInsertStatement, pkRow, null));
5959
writeCounter.incrementAndGet();
60-
61-
}
60+
if (readCounter.get() % printStatsAfter == 0) {
61+
printCounts(false);
62+
}
63+
});
6264
}
6365

64-
logger.info("################################################################################################");
66+
printCounts(true);
67+
}
68+
69+
public void printCounts(boolean isFinal) {
70+
if (isFinal) {
71+
logger.info("################################################################################################");
72+
}
6573
logger.info("TreadID: " + Thread.currentThread().getId() + " Read Record Count: " + readCounter.get());
6674
logger.info("TreadID: " + Thread.currentThread().getId() + " Read Missing Count: " + missingCounter.get());
6775
logger.info("TreadID: " + Thread.currentThread().getId() + " Inserted Record Count: " + writeCounter.get());
68-
logger.info("################################################################################################");
76+
if (isFinal) {
77+
logger.info("################################################################################################");
78+
}
6979
}
7080

7181
private Object convert(Class<?> targetType, String text) {

0 commit comments

Comments
 (0)