1
1
package datastax .astra .migrate ;
2
2
3
3
import com .datastax .oss .driver .api .core .CqlSession ;
4
- import com .datastax .oss .driver .api .core .cql .BoundStatement ;
5
- import com .datastax .oss .driver .api .core .cql .PreparedStatement ;
6
- import com .datastax .oss .driver .api .core .cql .Row ;
7
4
import com .datastax .oss .driver .shaded .guava .common .util .concurrent .RateLimiter ;
8
5
import datastax .astra .migrate .properties .KnownProperties ;
9
6
import org .apache .spark .SparkConf ;
10
7
import org .slf4j .Logger ;
11
8
import org .slf4j .LoggerFactory ;
12
9
13
- import java .time .Instant ;
14
- import java .util .Optional ;
15
-
16
10
public class AbstractJobSession extends BaseJobSession {
17
11
18
12
public Logger logger = LoggerFactory .getLogger (this .getClass ().getName ());
19
- protected CqlHelper cqlHelper ;
20
13
21
14
protected AbstractJobSession (CqlSession sourceSession , CqlSession astraSession , SparkConf sc ) {
22
15
this (sourceSession , astraSession , sc , false );
23
16
}
24
17
25
- protected AbstractJobSession (CqlSession sourceSession , CqlSession astraSession , SparkConf sc , boolean isJobMigrateRowsFromFile ) {
18
+ protected AbstractJobSession (CqlSession originSession , CqlSession targetSession , SparkConf sc , boolean isJobMigrateRowsFromFile ) {
26
19
super (sc );
27
20
28
- if (sourceSession == null ) {
21
+ if (originSession == null ) {
29
22
return ;
30
23
}
31
24
32
- this .sourceSession = sourceSession ;
33
- this .astraSession = astraSession ;
34
- this .cqlHelper = new CqlHelper (this .propertyHelper , this .sourceSession , this .astraSession , isJobMigrateRowsFromFile , this );
35
-
36
- batchSize = propertyHelper .getInteger (KnownProperties .SPARK_BATCH_SIZE );
37
- fetchSizeInRows = propertyHelper .getInteger (KnownProperties .READ_FETCH_SIZE );
25
+ cqlHelper .setOriginSession (originSession );
26
+ cqlHelper .setTargetSession (targetSession );
27
+ cqlHelper .setJobMigrateRowsFromFile (isJobMigrateRowsFromFile );
38
28
39
29
printStatsAfter = propertyHelper .getInteger (KnownProperties .SPARK_STATS_AFTER );
40
30
if (!propertyHelper .meetsMinimum (KnownProperties .SPARK_STATS_AFTER , printStatsAfter , 1 )) {
@@ -46,63 +36,11 @@ protected AbstractJobSession(CqlSession sourceSession, CqlSession astraSession,
46
36
writeLimiter = RateLimiter .create (propertyHelper .getInteger (KnownProperties .SPARK_LIMIT_WRITE ));
47
37
maxRetries = propertyHelper .getInteger (KnownProperties .SPARK_MAX_RETRIES );
48
38
49
- ttlCols = propertyHelper .getIntegerList (KnownProperties .ORIGIN_TTL_COLS );
50
- writeTimeStampCols = propertyHelper .getIntegerList (KnownProperties .ORIGIN_WRITETIME_COLS );
51
-
52
- writeTimeStampFilter = propertyHelper .getBoolean (KnownProperties .ORIGIN_FILTER_WRITETS_ENABLED );
53
- if (writeTimeStampFilter ) {
54
- batchSize = 1 ;
55
- propertyHelper .setProperty (KnownProperties .SPARK_BATCH_SIZE , batchSize );
56
- }
57
- minWriteTimeStampFilter = propertyHelper .getLong (KnownProperties .ORIGIN_FILTER_WRITETS_MIN );
58
- maxWriteTimeStampFilter = propertyHelper .getLong (KnownProperties .ORIGIN_FILTER_WRITETS_MAX );
59
-
60
- customWritetime = propertyHelper .getLong (KnownProperties .TARGET_CUSTOM_WRITETIME );
61
- isCounterTable = propertyHelper .getBoolean (KnownProperties .ORIGIN_IS_COUNTER );
62
-
63
- logger .info ("PARAM -- Read Consistency: {}" , readConsistencyLevel );
64
- logger .info ("PARAM -- Write Consistency: {}" , writeConsistencyLevel );
65
- logger .info ("PARAM -- Write Batch Size: {}" , batchSize );
66
39
logger .info ("PARAM -- Max Retries: {}" , maxRetries );
67
- logger .info ("PARAM -- Read Fetch Size: {}" , fetchSizeInRows );
68
- logger .info ("PARAM -- Source Keyspace Table: {}" , sourceKeyspaceTable );
69
- logger .info ("PARAM -- Destination Keyspace Table: {}" , targetKeyspaceTable );
70
40
logger .info ("PARAM -- ReadRateLimit: {}" , readLimiter .getRate ());
71
41
logger .info ("PARAM -- WriteRateLimit: {}" , writeLimiter .getRate ());
72
- logger .info ("PARAM -- TTLCols: {}" , ttlCols );
73
- logger .info ("PARAM -- WriteTimestampFilterCols: {}" , writeTimeStampCols );
74
- logger .info ("PARAM -- WriteTimestampFilter: {}" , writeTimeStampFilter );
75
- if (writeTimeStampFilter ) {
76
- logger .info ("PARAM -- minWriteTimeStampFilter: {} datetime is {}" , minWriteTimeStampFilter ,
77
- Instant .ofEpochMilli (minWriteTimeStampFilter / 1000 ));
78
- logger .info ("PARAM -- maxWriteTimeStampFilter: {} datetime is {}" , maxWriteTimeStampFilter ,
79
- Instant .ofEpochMilli (maxWriteTimeStampFilter / 1000 ));
80
- }
81
-
82
-
83
42
84
43
cqlHelper .initialize ();
85
- String fullSelectQuery = cqlHelper .getCqlString (CqlHelper .CqlStatementType .ORIGIN_SELECT );
86
- logger .info ("PARAM -- ORIGIN SELECT Query used: {}" , fullSelectQuery );
87
- sourceSelectStatement = sourceSession .prepare (fullSelectQuery );
88
-
89
- astraSelectStatement = astraSession .prepare (cqlHelper .getCqlString (CqlHelper .CqlStatementType .TARGET_SELECT_BY_PK ));
90
-
91
- hasRandomPartitioner = propertyHelper .getBoolean (KnownProperties .ORIGIN_HAS_RANDOM_PARTITIONER );
92
-
93
- astraInsertStatement = astraSession .prepare (cqlHelper .getCqlString (CqlHelper .CqlStatementType .TARGET_INSERT ));
94
-
95
- // Handle rows with blank values for 'timestamp' data-type in primary-key fields
96
- if (null != propertyHelper .getLong (KnownProperties .TARGET_REPLACE_MISSING_TS ))
97
- tsReplaceVal = propertyHelper .getLong (KnownProperties .TARGET_REPLACE_MISSING_TS );
98
- }
99
-
100
- public BoundStatement bindInsert (PreparedStatement insertStatement , Row sourceRow , Row astraRow ) {
101
- return cqlHelper .bindInsert (insertStatement , sourceRow , astraRow );
102
- }
103
-
104
- public BoundStatement selectFromAstra (PreparedStatement selectStatement , Row sourceRow ) {
105
- return cqlHelper .selectFromTargetByPK (selectStatement , sourceRow );
106
44
}
107
45
108
46
}
0 commit comments