25
25
public class CqlHelper {
26
26
private final Logger logger = LoggerFactory .getLogger (this .getClass ().getName ());
27
27
28
- private CqlSession originSession ;
29
- private CqlSession targetSession ;
28
+ private CqlSession originSessionInit ;
29
+ private CqlSession targetSessionInit ;
30
30
31
31
private ConsistencyLevel readConsistencyLevel ;
32
32
private ConsistencyLevel writeConsistencyLevel ;
33
33
34
34
public final PropertyHelper propertyHelper ;
35
35
private final Map <Featureset , Feature > featureMap = new HashMap <>(Featureset .values ().length );
36
36
private PKFactory pkFactory ;
37
- private OriginSelectByPartitionRangeStatement originSelectByPartitionRangeStatement ;
38
- private OriginSelectByPKStatement originSelectByPKStatement ;
39
- private TargetInsertStatement targetInsertStatement ;
40
- private TargetUpdateStatement targetUpdateStatement ;
41
- private TargetSelectByPKStatement targetSelectByPKStatement ;
42
37
43
38
private final Map <Codecset , TypeCodec <?>> codecMap = new HashMap <>(Codecset .values ().length );
44
39
@@ -71,22 +66,19 @@ public boolean initialize() {
71
66
feature .alterProperties (this .propertyHelper , this .pkFactory );
72
67
}
73
68
74
- registerTargetCodecs ( );
69
+ registerCodecs ( targetSessionInit );
75
70
76
- originSelectByPartitionRangeStatement = new OriginSelectByPartitionRangeStatement (propertyHelper ,this );
77
- originSelectByPKStatement = new OriginSelectByPKStatement (propertyHelper ,this );
78
- targetInsertStatement = new TargetInsertStatement (propertyHelper ,this );
79
- targetUpdateStatement = new TargetUpdateStatement (propertyHelper ,this );
80
- targetSelectByPKStatement = new TargetSelectByPKStatement (propertyHelper ,this );
71
+ OriginSelectByPartitionRangeStatement originSelectByPartitionRangeStatement = new OriginSelectByPartitionRangeStatement (propertyHelper ,this , null );
72
+ TargetInsertStatement targetInsertStatement = new TargetInsertStatement (propertyHelper ,this , null );
73
+ TargetUpdateStatement targetUpdateStatement = new TargetUpdateStatement (propertyHelper ,this , null );
74
+ TargetSelectByPKStatement targetSelectByPKStatement = new TargetSelectByPKStatement (propertyHelper ,this , null );
81
75
82
76
logger .info ("PARAM -- Read Consistency: {}" , readConsistencyLevel );
83
77
logger .info ("PARAM -- Write Consistency: {}" , writeConsistencyLevel );
84
- logger .info ("PARAM -- Write Batch Size: {}" , getBatchSize ());
78
+ logger .info ("PARAM -- Write Batch Size: {}" , getBatchSize (originSelectByPartitionRangeStatement ));
85
79
logger .info ("PARAM -- Read Fetch Size: {}" , getFetchSizeInRows ());
86
80
logger .info ("PARAM -- Origin Keyspace Table: {}" , ColumnsKeysTypes .getOriginKeyspaceTable (propertyHelper ));
87
81
logger .info ("PARAM -- Target Keyspace Table: {}" , ColumnsKeysTypes .getTargetKeyspaceTable (propertyHelper ));
88
- logger .info ("PARAM -- TTLCols: {}" , getTtlCols ());
89
- logger .info ("PARAM -- WriteTimestampCols: {}" , getWriteTimeStampCols ());
90
82
logger .info ("PARAM -- ORIGIN SELECT Query used: {}" , originSelectByPartitionRangeStatement .getCQL ());
91
83
logger .info ("PARAM -- TARGET INSERT Query used: {}" , targetInsertStatement .getCQL ());
92
84
logger .info ("PARAM -- TARGET UPDATE Query used: {}" , targetUpdateStatement .getCQL ());
@@ -108,17 +100,17 @@ public Boolean isFeatureEnabled(Featureset featureEnum) {
108
100
}
109
101
110
102
public PKFactory getPKFactory () {return pkFactory ;}
111
- public OriginSelectByPartitionRangeStatement getOriginSelectByPartitionRangeStatement () {return originSelectByPartitionRangeStatement ;}
112
- public OriginSelectByPKStatement getOriginSelectByPKStatement () {return originSelectByPKStatement ;}
113
- public TargetInsertStatement getTargetInsertStatement () {return targetInsertStatement ;}
114
- public TargetUpdateStatement getTargetUpdateStatement () {return targetUpdateStatement ;}
115
- public TargetSelectByPKStatement getTargetSelectByPKStatement () {return targetSelectByPKStatement ;}
103
+ public OriginSelectByPartitionRangeStatement getOriginSelectByPartitionRangeStatement (CqlSession session ) {return new OriginSelectByPartitionRangeStatement ( propertyHelper , this , session ) ;}
104
+ public OriginSelectByPKStatement getOriginSelectByPKStatement (CqlSession session ) {return new OriginSelectByPKStatement ( propertyHelper , this , session ) ;}
105
+ public TargetInsertStatement getTargetInsertStatement (CqlSession session ) {return new TargetInsertStatement ( propertyHelper , this , session ) ;}
106
+ public TargetUpdateStatement getTargetUpdateStatement (CqlSession session ) {return new TargetUpdateStatement ( propertyHelper , this , session ) ;}
107
+ public TargetSelectByPKStatement getTargetSelectByPKStatement (CqlSession session ) {return new TargetSelectByPKStatement ( propertyHelper , this , session ) ;}
116
108
117
109
// ----------------- Codec Functions --------------
118
- private void registerTargetCodecs ( ) {
110
+ public void registerCodecs ( CqlSession session ) {
119
111
List <String > codecList = propertyHelper .getStringList (KnownProperties .TRANSFORM_CODECS );
120
112
if (null !=codecList && !codecList .isEmpty ()) {
121
- MutableCodecRegistry registry = getCodecRegistry ();
113
+ MutableCodecRegistry registry = ( MutableCodecRegistry ) session . getContext (). getCodecRegistry ();
122
114
123
115
StringBuilder sb = new StringBuilder ("PARAM -- Codecs Enabled: " );
124
116
for (String codecString : codecList ) {
@@ -137,24 +129,22 @@ public boolean isCodecRegistered(Codecset codecEnum) {
137
129
}
138
130
139
131
public MutableCodecRegistry getCodecRegistry () {
140
- return (MutableCodecRegistry ) targetSession .getContext ().getCodecRegistry ();
132
+ return (MutableCodecRegistry ) targetSessionInit .getContext ().getCodecRegistry ();
141
133
}
142
134
143
135
// --------------- Session and Performance -------------------------
144
- public void setOriginSession (CqlSession originSession ) {
145
- this .originSession = originSession ;
136
+ // TODO: these should only by used when initializing the system, and should be refactored as part of moving schema definition to its own class
137
+ public void setOriginSessionInit (CqlSession originSessionInit ) {
138
+ this .originSessionInit = originSessionInit ;
146
139
}
147
-
148
- public void setTargetSession (CqlSession targetSession ) {
149
- this .targetSession = targetSession ;
140
+ public void setTargetSessionInit (CqlSession targetSessionInit ) {
141
+ this .targetSessionInit = targetSessionInit ;
150
142
}
151
-
152
- public CqlSession getOriginSession () {
153
- return originSession ;
143
+ public CqlSession getOriginSessionInit () {
144
+ return originSessionInit ;
154
145
}
155
-
156
- public CqlSession getTargetSession () {
157
- return targetSession ;
146
+ public CqlSession getTargetSessionInit () {
147
+ return targetSessionInit ;
158
148
}
159
149
160
150
public ConsistencyLevel getReadConsistencyLevel () {
@@ -168,7 +158,7 @@ public Integer getFetchSizeInRows() {
168
158
return propertyHelper .getInteger (KnownProperties .PERF_FETCH_SIZE );
169
159
}
170
160
171
- public Integer getBatchSize () {
161
+ public Integer getBatchSize (OriginSelectByPartitionRangeStatement originSelectByPartitionRangeStatement ) {
172
162
// cannot do batching if the writeFilter is greater than 0 or maxWriteTimeStampFilter is less than max long
173
163
// do not batch for counters as it adds latency & increases chance of discrepancy
174
164
if (originSelectByPartitionRangeStatement .hasWriteTimestampFilter () || isCounterTable ())
@@ -189,15 +179,6 @@ public boolean isCounterTable() {
189
179
return (null != rtn && rtn .size () > 0 );
190
180
}
191
181
192
- //--------------- TTL & Writetime Feature ---------------
193
- public List <Integer > getTtlCols () {
194
- return propertyHelper .getIntegerList (KnownProperties .ORIGIN_TTL_INDEXES );
195
- }
196
-
197
- public List <Integer > getWriteTimeStampCols () {
198
- return propertyHelper .getIntegerList (KnownProperties .ORIGIN_WRITETIME_INDEXES );
199
- }
200
-
201
182
//----------- General Utilities --------------
202
183
public Object getData (MigrateDataType dataType , int index , Row row ) {
203
184
if (dataType .getTypeClass () == Map .class ) {
0 commit comments