Skip to content

Commit 62df712

Browse files
committed
增加测试用例
1 parent 3764c6d commit 62df712

File tree

1 file changed

+30
-33
lines changed

1 file changed

+30
-33
lines changed

flink-cdc-connect/flink-cdc-source-connectors/flink-connector-mysql-cdc/src/main/java/org/apache/flink/cdc/connectors/mysql/source/offset/BinlogOffset.java

Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -186,40 +186,37 @@ public int compareTo(BinlogOffset that) {
186186
String targetGtidSetStr = that.getGtidSet();
187187
if (StringUtils.isNotEmpty(targetGtidSetStr)) {
188188
// The target offset uses GTIDs, so we ideally compare using GTIDs ...
189-
if (StringUtils.isEmpty(gtidSetStr)) {
190-
// The target offset did use GTIDs while this did not use GTIDs. So, we assume
191-
// that this offset is older since GTIDs are often enabled but rarely disabled.
192-
// And if they are disabled,
193-
// it is likely that this offset would not include GTIDs as we would be trying
194-
// to read the binlog of a
195-
// server that no longer has GTIDs. And if they are enabled, disabled, and
196-
// re-enabled, per
197-
// https://dev.mysql.com/doc/refman/5.7/en/replication-gtids-failover.html
198-
// all properly configured slaves that
199-
// use GTIDs should always have the complete set of GTIDs copied from the master, in
200-
// which case
201-
// again we know that this offset not having GTIDs is before the target offset ...
202-
return -1;
189+
if (StringUtils.isNotEmpty(gtidSetStr)) {
190+
// Both have GTIDs, so base the comparison entirely on the GTID sets.
191+
GtidSet gtidSet = new GtidSet(gtidSetStr);
192+
GtidSet targetGtidSet = new GtidSet(targetGtidSetStr);
193+
if (!gtidSet.equals(targetGtidSet)) {
194+
// The GTIDs are not an exact match, so figure out if this is a subset of the
195+
// target offset ...
196+
return gtidSet.isContainedWithin(targetGtidSet) ? -1 : 1;
197+
}
198+
// The GTIDs are the same, so compare the completed events in the transaction ...
199+
long restartSkipEvents = this.getRestartSkipEvents();
200+
long targetRestartSkipEvents = that.getRestartSkipEvents();
201+
if (restartSkipEvents != targetRestartSkipEvents) {
202+
return Long.compare(restartSkipEvents, targetRestartSkipEvents);
203+
}
204+
// The completed events are the same, so compare the row number ...
205+
return Long.compare(this.getRestartSkipRows(), that.getRestartSkipRows());
203206
}
204-
// Both have GTIDs, so base the comparison entirely on the GTID sets.
205-
GtidSet gtidSet = new GtidSet(gtidSetStr);
206-
GtidSet targetGtidSet = new GtidSet(targetGtidSetStr);
207-
if (!gtidSet.equals(targetGtidSet)) {
208-
// The GTIDs are not an exact match, so figure out if this is a subset of the target
209-
// offset
210-
// ...
211-
return gtidSet.isContainedWithin(targetGtidSet) ? -1 : 1;
212-
}
213-
214-
// The GTIDs are the same, so compare the completed events in the transaction ...
215-
long restartSkipEvents = this.getRestartSkipEvents();
216-
long targetRestartSkipEvents = that.getRestartSkipEvents();
217-
if (restartSkipEvents != targetRestartSkipEvents) {
218-
return Long.compare(restartSkipEvents, targetRestartSkipEvents);
219-
}
220-
221-
// The completed events are the same, so compare the row number ...
222-
return Long.compare(this.getRestartSkipRows(), that.getRestartSkipRows());
207+
// The target offset did use GTIDs while this did not use GTIDs. So, we assume
208+
// that this offset is older since GTIDs are often enabled but rarely disabled.
209+
// And if they are disabled,
210+
// it is likely that this offset would not include GTIDs as we would be trying
211+
// to read the binlog of a
212+
// server that no longer has GTIDs. And if they are enabled, disabled, and re-enabled,
213+
// per
214+
// https://dev.mysql.com/doc/refman/5.7/en/replication-gtids-failover.html all properly
215+
// configured slaves that
216+
// use GTIDs should always have the complete set of GTIDs copied from the master, in
217+
// which case
218+
// again we know that this offset not having GTIDs is before the target offset ...
219+
return -1;
223220
} else if (StringUtils.isNotEmpty(gtidSetStr)) {
224221
// This offset has a GTID but the target offset does not, so per the previous paragraph
225222
// we

0 commit comments

Comments
 (0)