|
29 | 29 | import java.util.List;
|
30 | 30 | import java.util.function.LongConsumer;
|
31 | 31 |
|
32 |
| -import org.apache.commons.lang3.StringUtils; |
33 | 32 | import org.apache.commons.lang3.time.DateUtils;
|
34 | 33 | import org.apache.commons.lang3.time.FastDateFormat;
|
35 | 34 | import org.jumpmind.db.platform.DatabaseNamesConstants;
|
@@ -234,7 +233,7 @@ private long[] getMinMax(long[] minMax, long notOkBatchId, long[] rangeMinMax) {
|
234 | 233 | if (rangeMinMax[1] == minMax[1]) {
|
235 | 234 | minMax[1] = -1;
|
236 | 235 | } else {
|
237 |
| - minMax[0] = notOkBatchId + 1; |
| 236 | + minMax[0] = notOkBatchId; |
238 | 237 | }
|
239 | 238 | return minMax;
|
240 | 239 | }
|
@@ -281,8 +280,8 @@ private long purgeLingeringBatches(OutgoingContext context) {
|
281 | 280 | } else {
|
282 | 281 | break;
|
283 | 282 | }
|
284 |
| - log.info("Done purging {} lingering batches and {} rows", totalBatchesPurged, totalRowsPurged); |
285 | 283 | }
|
| 284 | + log.info("Done purging {} lingering batches and {} rows", totalBatchesPurged, totalRowsPurged); |
286 | 285 | return totalRowsPurged;
|
287 | 286 | }
|
288 | 287 |
|
@@ -926,22 +925,25 @@ private OutgoingContext buildOutgoingContext(Calendar retentionCutoff) {
|
926 | 925 | context.setMinEventBatchId(startEventBatchId);
|
927 | 926 | // Leave 1 batch and its data around so MySQL auto increment doesn't reset
|
928 | 927 | long endBatchId = sequenceService.currVal(Constants.SEQUENCE_OUTGOING_BATCH) - 1;
|
929 |
| - List<Long> batchIds = sqlTemplateDirty.query(getSql("maxBatchIdByChannel"), new LongMapper(), |
| 928 | + List<Long> batchIds = sqlTemplateDirty.query(getSql("maxBatchIdForOldBatches"), new LongMapper(), |
930 | 929 | new Object[] { startBatchId, endBatchId, new Timestamp(context.getRetentionCutoff().getTime().getTime()) },
|
931 | 930 | new int[] { symmetricDialect.getSqlTypeForIds(), symmetricDialect.getSqlTypeForIds(), Types.TIMESTAMP });
|
932 | 931 | if (batchIds != null && batchIds.size() > 0) {
|
933 |
| - int[] types = new int[batchIds.size()]; |
934 |
| - for (int i = 0; i < batchIds.size(); i++) { |
935 |
| - types[i] = symmetricDialect.getSqlTypeForIds(); |
936 |
| - if (batchIds.get(i) > context.getMaxBatchId()) { |
937 |
| - context.setMaxBatchId(batchIds.get(i)); |
| 932 | + context.setMaxBatchId(batchIds.get(0)); |
| 933 | + log.info("Max eligible batch ID: {}", context.getMaxBatchId()); |
| 934 | + List<Row> rows = sqlTemplateDirty.query(getSql("minMaxDataIdForOldBatches"), new Object[] { startBatchId, |
| 935 | + context.getMaxBatchId() }, new int[] { symmetricDialect.getSqlTypeForIds(), symmetricDialect.getSqlTypeForIds() }); |
| 936 | + if (rows != null && rows.size() > 0) { |
| 937 | + Row row = rows.get(0); |
| 938 | + long minDataId = row.getLong("min_data_id"); |
| 939 | + long maxDataId = row.getLong("max_data_id"); |
| 940 | + context.setMaxDataId(maxDataId); |
| 941 | + log.info("Max eligible data ID: {}", context.getMaxDataId()); |
| 942 | + if (minDataId < context.getMinDataId()) { |
| 943 | + log.info("Moving starting data ID back from {} to {}", context.getMinDataId(), minDataId); |
| 944 | + context.setMinDataId(minDataId); |
938 | 945 | }
|
939 | 946 | }
|
940 |
| - String sql = getSql("maxDataIdForBatches").replace("?", StringUtils.repeat("?", ",", batchIds.size())); |
941 |
| - List<Long> ids = sqlTemplateDirty.query(sql, new LongMapper(), batchIds.toArray(), types); |
942 |
| - if (ids != null && ids.size() > 0) { |
943 |
| - context.setMaxDataId(ids.get(0)); |
944 |
| - } |
945 | 947 | }
|
946 | 948 | context.setMinDataGapStartId(sqlTemplateDirty.queryForLong(getSql("minDataGapStartId")));
|
947 | 949 | context.setDataGapsExpired(dataService.findDataGapsExpired());
|
|
0 commit comments