mirror of
https://github.com/alibaba/canal.git
synced 2026-11-04 00:30:15 +08:00
fixed issue #483 , show slave hosts
This commit is contained in:
@@ -138,6 +138,16 @@ public class BioSocketChannel implements SocketChannel {
|
|||||||
if (socket != null) {
|
if (socket != null) {
|
||||||
return socket.getRemoteSocketAddress();
|
return socket.getRemoteSocketAddress();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SocketAddress getLocalSocketAddress() {
|
||||||
|
Socket socket = this.socket;
|
||||||
|
if (socket != null) {
|
||||||
|
return socket.getLocalSocketAddress();
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -216,6 +216,10 @@ public class NettySocketChannel implements SocketChannel {
|
|||||||
return channel != null ? channel.remoteAddress() : null;
|
return channel != null ? channel.remoteAddress() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public SocketAddress getLocalSocketAddress() {
|
||||||
|
return channel != null ? channel.localAddress() : null;
|
||||||
|
}
|
||||||
|
|
||||||
public void close() {
|
public void close() {
|
||||||
if (channel != null) {
|
if (channel != null) {
|
||||||
channel.close();
|
channel.close();
|
||||||
|
|||||||
@@ -21,5 +21,7 @@ public interface SocketChannel {
|
|||||||
|
|
||||||
public SocketAddress getRemoteSocketAddress();
|
public SocketAddress getRemoteSocketAddress();
|
||||||
|
|
||||||
|
public SocketAddress getLocalSocketAddress();
|
||||||
|
|
||||||
public void close();
|
public void close();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import static com.alibaba.otter.canal.parse.inbound.mysql.dbsync.DirectLogFetche
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
|
import java.net.SocketAddress;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
@@ -254,10 +255,18 @@ public class MysqlConnection implements ErosaConnection {
|
|||||||
|
|
||||||
private void sendRegisterSlave() throws IOException {
|
private void sendRegisterSlave() throws IOException {
|
||||||
RegisterSlaveCommandPacket cmd = new RegisterSlaveCommandPacket();
|
RegisterSlaveCommandPacket cmd = new RegisterSlaveCommandPacket();
|
||||||
cmd.reportHost = authInfo.getAddress().getAddress().getHostAddress();
|
SocketAddress socketAddress = connector.getChannel().getLocalSocketAddress();
|
||||||
|
if (socketAddress == null || !(socketAddress instanceof InetSocketAddress)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
InetSocketAddress address = (InetSocketAddress) socketAddress;
|
||||||
|
String host = address.getHostString();
|
||||||
|
int port = address.getPort();
|
||||||
|
cmd.reportHost = host;
|
||||||
|
cmd.reportPort = port;
|
||||||
cmd.reportPasswd = authInfo.getPassword();
|
cmd.reportPasswd = authInfo.getPassword();
|
||||||
cmd.reportUser = authInfo.getUsername();
|
cmd.reportUser = authInfo.getUsername();
|
||||||
cmd.reportPort = authInfo.getAddress().getPort(); // 暂时先用master节点的port
|
|
||||||
cmd.serverId = this.slaveId;
|
cmd.serverId = this.slaveId;
|
||||||
byte[] cmdBody = cmd.toBytes();
|
byte[] cmdBody = cmd.toBytes();
|
||||||
|
|
||||||
|
|||||||
@@ -20,12 +20,12 @@ public class MysqlBinlogDumpPerformanceTest {
|
|||||||
|
|
||||||
public static void main(String args[]) {
|
public static void main(String args[]) {
|
||||||
final MysqlEventParser controller = new MysqlEventParser();
|
final MysqlEventParser controller = new MysqlEventParser();
|
||||||
final EntryPosition startPosition = new EntryPosition("mysql-bin.001699", 120L, 100L);
|
final EntryPosition startPosition = new EntryPosition("mysql-bin.000007", 89796293L, 100L);
|
||||||
controller.setConnectionCharset(Charset.forName("UTF-8"));
|
controller.setConnectionCharset(Charset.forName("UTF-8"));
|
||||||
controller.setSlaveId(3344L);
|
controller.setSlaveId(3344L);
|
||||||
controller.setDetectingEnable(false);
|
controller.setDetectingEnable(false);
|
||||||
controller.setFilterQueryDml(true);
|
controller.setFilterQueryDml(true);
|
||||||
controller.setMasterInfo(new AuthenticationInfo(new InetSocketAddress("127.0.0.1", 3328), "root", "hello"));
|
controller.setMasterInfo(new AuthenticationInfo(new InetSocketAddress("100.81.154.142", 3306), "canal", "canal"));
|
||||||
controller.setMasterPosition(startPosition);
|
controller.setMasterPosition(startPosition);
|
||||||
controller.setEnableTsdb(false);
|
controller.setEnableTsdb(false);
|
||||||
controller.setDestination("example");
|
controller.setDestination("example");
|
||||||
|
|||||||
Reference in New Issue
Block a user