Skip to content

Commit c3b62a8

Browse files
committed
CDM-29 default behaviour no longer autocorrects counters unless explicitly enabled
1 parent b4b8561 commit c3b62a8

File tree

8 files changed

+46
-1
lines changed

8 files changed

+46
-1
lines changed

SIT/smoke/04_counters/breakData.cql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
UPDATE source.smoke_counters SET col1=col1+1 WHERE key='record2';
33

44
-- CDM-29 discovered that this record will "zombie"...
5+
-- fixData will not correct it, fixForce will
56
DELETE FROM target.smoke_counters where key='record3';
67

78
-- change by same amount on both sides, records should match

SIT/smoke/04_counters/cdm.fixData.assert

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ Read Record Count: 5
22
Mismatch Record Count: 2
33
Corrected Mismatch Record Count: 2
44
Missing Record Count: 1
5-
Corrected Missing Record Count: 1
5+
Corrected Missing Record Count: 0
66
Valid Record Count: 2
77
Skipped Record Count: 0
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Read Record Count: 5
2+
Mismatch Record Count: 0
3+
Corrected Mismatch Record Count: 0
4+
Missing Record Count: 1
5+
Corrected Missing Record Count: 1
6+
Valid Record Count: 4
7+
Skipped Record Count: 0

SIT/smoke/04_counters/cdm.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
migrateData datastax.astra.migrate.Migrate migrate.properties
22
validateData datastax.astra.migrate.DiffData migrate.properties
33
fixData datastax.astra.migrate.DiffData fix.properties
4+
fixForce datastax.astra.migrate.DiffData fix-force.properties

SIT/smoke/04_counters/execute.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@ cqlsh -u $CASS_USERNAME -p $CASS_PASSWORD $CASS_CLUSTER -f $workingDir/breakData
1313

1414
/local/cdm.sh -f cdm.txt -s fixData -d "$workingDir" > cdm.fixData.out 2>cdm.fixData.err
1515
/local/cdm-assert.sh -f cdm.fixData.out -a cdm.fixData.assert -d "$workingDir"
16+
17+
/local/cdm.sh -f cdm.txt -s fixForce -d "$workingDir" > cdm.fixForce.out 2>cdm.fixForce.err
18+
/local/cdm-assert.sh -f cdm.fixForce.out -a cdm.fixForce.assert -d "$workingDir"
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
spark.origin.host cdm-sit-cass
2+
spark.origin.port 9042
3+
spark.origin.username cassandra
4+
spark.origin.password cassandra
5+
spark.origin.keyspaceTable source.smoke_counters
6+
7+
spark.target.host cdm-sit-cass
8+
spark.target.port 9042
9+
spark.target.username cassandra
10+
spark.target.password cassandra
11+
spark.target.keyspaceTable target.smoke_counters
12+
13+
spark.numSplits 1
14+
15+
spark.query.origin key,col1,col2
16+
spark.query.types 0,2,2
17+
spark.query.origin.partitionKey key
18+
spark.query.target.id key
19+
20+
spark.counterTable.cql.index 1,2
21+
spark.counterTable.missing.force true
22+
23+
spark.target.autocorrect.missing true
24+
spark.target.autocorrect.mismatch true

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public class DiffJobSession extends CopyJobSession {
4141
private final AtomicLong skippedCounter = new AtomicLong(0);
4242

4343
private final boolean isCounterTable;
44+
private final boolean forceCounterWhenMissing;
4445
private final List<Integer> targetToOriginColumnIndexes;
4546
private final List<MigrateDataType> targetColumnTypes;
4647
private final int explodeMapKeyIndex;
@@ -56,6 +57,7 @@ private DiffJobSession(CqlSession originSession, CqlSession targetSession, Spark
5657
logger.info("PARAM -- Autocorrect Mismatch: {}", autoCorrectMismatch);
5758

5859
this.isCounterTable = cqlHelper.isCounterTable();
60+
this.forceCounterWhenMissing = propertyHelper.getBoolean(KnownProperties.ORIGIN_COUNTER_FORCE_WHEN_MISSING);
5961
this.targetToOriginColumnIndexes = cqlHelper.getPKFactory().getTargetToOriginColumnIndexes();
6062
this.targetColumnTypes = cqlHelper.getPKFactory().getTargetColumnTypes();
6163

@@ -167,6 +169,10 @@ private void diff(Record record) {
167169
if (targetRow == null) {
168170
missingCounter.incrementAndGet();
169171
logger.error("Missing target row found for key: {}", record.getPk());
172+
if (autoCorrectMissing && isCounterTable && !forceCounterWhenMissing) {
173+
logger.error("{} is true, but not Inserting as {} is not enabled; key : {}", KnownProperties.TARGET_AUTOCORRECT_MISSING, KnownProperties.ORIGIN_COUNTER_FORCE_WHEN_MISSING, record.getPk());
174+
return;
175+
}
170176

171177
//correct data
172178
if (autoCorrectMissing) {

src/main/java/datastax/astra/migrate/properties/KnownProperties.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ public enum PropertyType {
7171
public static final String ORIGIN_IS_COUNTER = "spark.counterTable"; // false
7272
public static final String ORIGIN_COUNTER_CQL = "spark.counterTable.cql";
7373
public static final String ORIGIN_COUNTER_INDEXES = "spark.counterTable.cql.index"; // 0
74+
public static final String ORIGIN_COUNTER_FORCE_WHEN_MISSING = "spark.counterTable.missing.force"; // false
7475
public static final String ORIGIN_PRIMARY_KEY = "spark.query.origin.id"; // Defaults to TARGET_PRIMARY_KEY, same config rules
7576
public static final String ORIGIN_PRIMARY_KEY_TYPES = "spark.cdm.cql.origin.id.types"; // Code-managed, not an external property
7677

@@ -89,6 +90,8 @@ public enum PropertyType {
8990
defaults.put(ORIGIN_IS_COUNTER, "false");
9091
types.put(ORIGIN_COUNTER_CQL, PropertyType.STRING);
9192
types.put(ORIGIN_COUNTER_INDEXES, PropertyType.NUMBER_LIST);
93+
types.put(ORIGIN_COUNTER_FORCE_WHEN_MISSING, PropertyType.BOOLEAN);
94+
defaults.put(ORIGIN_COUNTER_FORCE_WHEN_MISSING, "false");
9295
types.put(ORIGIN_PRIMARY_KEY, PropertyType.STRING_LIST);
9396
required.add(ORIGIN_PRIMARY_KEY);
9497
types.put(ORIGIN_PRIMARY_KEY_TYPES, PropertyType.MIGRATION_TYPE_LIST);

0 commit comments

Comments
 (0)