From 62226ac38c414965aef0f90857cb32a829e27c48 Mon Sep 17 00:00:00 2001 From: Henry Cai Date: Sat, 3 Jun 2017 18:11:23 -0700 Subject: [PATCH 1/2] Add new method putUUIDSet to GTIDSet Allow the client program add or replace the UUIDSet in GTIDSet This might be useful when the client program want to adjust the intervals in GTIDSet/UUIDSet, e.g. when the client program don't have contiguous gtid ranges. --- .../java/com/github/shyiko/mysql/binlog/GtidSet.java | 10 ++++++++++ .../com/github/shyiko/mysql/binlog/GtidSetTest.java | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/main/java/com/github/shyiko/mysql/binlog/GtidSet.java b/src/main/java/com/github/shyiko/mysql/binlog/GtidSet.java index b37ff527..040fbe5f 100644 --- a/src/main/java/com/github/shyiko/mysql/binlog/GtidSet.java +++ b/src/main/java/com/github/shyiko/mysql/binlog/GtidSet.java @@ -83,6 +83,16 @@ public UUIDSet getUUIDSet(String uuid) { return map.get(uuid); } + /** + * Add or replace the UUIDSet + * @param uuidSet UUIDSet to be added + * @return the old {@link UUIDSet} for the server given in uuidSet param, + * or {@code null} if there are no UUIDSet for the given server. + */ + public UUIDSet putUUIDSet(UUIDSet uuidSet) { + return map.put(uuidSet.getUUID(), uuidSet); + } + /** * @param gtid GTID ("source_id:transaction_id") * @return whether or not gtid was added to the set (false if it was already there) diff --git a/src/test/java/com/github/shyiko/mysql/binlog/GtidSetTest.java b/src/test/java/com/github/shyiko/mysql/binlog/GtidSetTest.java index b2215a9c..79318aa6 100644 --- a/src/test/java/com/github/shyiko/mysql/binlog/GtidSetTest.java +++ b/src/test/java/com/github/shyiko/mysql/binlog/GtidSetTest.java @@ -154,4 +154,14 @@ public void testMultipleIntervalsThatMayBeAdjacent() { assertEquals(gtidSet.toString(), UUID + ":1-199:1000-1033:1035-1036:1038-1039"); } + @Test + public void testPutUUIDSet() { + GtidSet gtidSet = new GtidSet(UUID + ":1-191"); + UUIDSet uuidSet = gtidSet.getUUIDSet(UUID); + GtidSet gtidSet2 = new GtidSet(UUID + ":1-190"); + UUIDSet uuidSet2 = gtidSet2.getUUIDSet(UUID); + gtidSet.putUUIDSet(uuidSet2); + assertEquals(gtidSet, gtidSet2); + } + } From 0e5e8e1043ce0d7c626978176771419164dbde0c Mon Sep 17 00:00:00 2001 From: Henry Cai Date: Sat, 3 Jun 2017 18:57:16 -0700 Subject: [PATCH 2/2] Make UUIDSet and Interval class's constructor public --- src/main/java/com/github/shyiko/mysql/binlog/GtidSet.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/github/shyiko/mysql/binlog/GtidSet.java b/src/main/java/com/github/shyiko/mysql/binlog/GtidSet.java index 040fbe5f..6899eafe 100644 --- a/src/main/java/com/github/shyiko/mysql/binlog/GtidSet.java +++ b/src/main/java/com/github/shyiko/mysql/binlog/GtidSet.java @@ -180,7 +180,7 @@ public static final class UUIDSet { private String uuid; private List intervals; - UUIDSet(String uuid, List intervals) { + public UUIDSet(String uuid, List intervals) { this.uuid = uuid; this.intervals = intervals; if (intervals.size() > 1) { @@ -349,7 +349,7 @@ public static final class Interval implements Comparable { private long start; private long end; - Interval(long start, long end) { + public Interval(long start, long end) { this.start = start; this.end = end; }