forked from zendesk/maxwell
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from recurly/DBA-362_vitessMVP
DBA-361: Vitess MVP
- Loading branch information
Showing
7 changed files
with
656 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
133 changes: 133 additions & 0 deletions
133
src/main/java/com/zendesk/maxwell/replication/Vgtid.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
package com.zendesk.maxwell.replication; | ||
|
||
import binlogdata.Binlogdata; | ||
import com.google.gson.Gson; | ||
import com.google.gson.reflect.TypeToken; | ||
|
||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.Set; | ||
|
||
/** Vitess source position coordiates. */ | ||
public class Vgtid { | ||
public static final String CURRENT_GTID = "current"; | ||
private static final Gson gson = new Gson(); | ||
|
||
private final Binlogdata.VGtid rawVgtid; | ||
private final Set<ShardGtid> shardGtids = new HashSet<>(); | ||
|
||
private Vgtid(Binlogdata.VGtid rawVgtid) { | ||
this.rawVgtid = rawVgtid; | ||
for (Binlogdata.ShardGtid shardGtid : rawVgtid.getShardGtidsList()) { | ||
shardGtids.add(new ShardGtid(shardGtid.getKeyspace(), shardGtid.getShard(), shardGtid.getGtid())); | ||
} | ||
} | ||
|
||
private Vgtid(List<ShardGtid> shardGtids) { | ||
this.shardGtids.addAll(shardGtids); | ||
|
||
Binlogdata.VGtid.Builder builder = Binlogdata.VGtid.newBuilder(); | ||
for (ShardGtid shardGtid : shardGtids) { | ||
builder.addShardGtids( | ||
Binlogdata.ShardGtid.newBuilder() | ||
.setKeyspace(shardGtid.getKeyspace()) | ||
.setShard(shardGtid.getShard()) | ||
.setGtid(shardGtid.getGtid()) | ||
.build()); | ||
} | ||
this.rawVgtid = builder.build(); | ||
} | ||
|
||
public static Vgtid of(String shardGtidsInJson) { | ||
List<Vgtid.ShardGtid> shardGtids = gson.fromJson(shardGtidsInJson, new TypeToken<List<ShardGtid>>() { | ||
}.getType()); | ||
return of(shardGtids); | ||
} | ||
|
||
public static Vgtid of(Binlogdata.VGtid rawVgtid) { | ||
return new Vgtid(rawVgtid); | ||
} | ||
|
||
public static Vgtid of(List<ShardGtid> shardGtids) { | ||
return new Vgtid(shardGtids); | ||
} | ||
|
||
public Binlogdata.VGtid getRawVgtid() { | ||
return rawVgtid; | ||
} | ||
|
||
public Set<ShardGtid> getShardGtids() { | ||
return shardGtids; | ||
} | ||
|
||
public boolean isSingleShard() { | ||
return rawVgtid.getShardGtidsCount() == 1; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return gson.toJson(shardGtids); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
Vgtid vgtid = (Vgtid) o; | ||
return Objects.equals(rawVgtid, vgtid.rawVgtid) && | ||
Objects.equals(shardGtids, vgtid.shardGtids); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(rawVgtid, shardGtids); | ||
} | ||
|
||
public static class ShardGtid { | ||
private final String keyspace; | ||
private final String shard; | ||
private final String gtid; | ||
|
||
public ShardGtid(String keyspace, String shard, String gtid) { | ||
this.keyspace = keyspace; | ||
this.shard = shard; | ||
this.gtid = gtid; | ||
} | ||
|
||
public String getKeyspace() { | ||
return keyspace; | ||
} | ||
|
||
public String getShard() { | ||
return shard; | ||
} | ||
|
||
public String getGtid() { | ||
return gtid; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
ShardGtid shardGtid = (ShardGtid) o; | ||
return Objects.equals(keyspace, shardGtid.keyspace) && | ||
Objects.equals(shard, shardGtid.shard) && | ||
Objects.equals(gtid, shardGtid.gtid); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(keyspace, shard, gtid); | ||
} | ||
} | ||
} |
Oops, something went wrong.