Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mycat2 双主故障怎么没切换呢? #792

Open
lhsaq2009 opened this issue Apr 19, 2023 · 3 comments
Open

Mycat2 双主故障怎么没切换呢? #792

lhsaq2009 opened this issue Apr 19, 2023 · 3 comments

Comments

@lhsaq2009
Copy link

在我部署中:Master 1 和 Master 2 双主,然后 Master 1 模拟宕机

[root@Master1 ~]# cat  ~/mycat/conf/clusters/prototype.cluster.json
{
	"clusterType":"MASTER_SLAVE",
	"heartbeat":{
		"heartbeatTimeout":1000,
		"maxRetryCount":3,
		"minSwitchTimeInterval":300,
		"showLog":false,
		"slaveThreshold":0.0
	},
	"masters":[
		"rwSepw",
		"rwSepw2"
	],
	"maxCon":2000,
	"name":"prototype",
	"readBalanceType":"BALANCE_ALL",
	"replicas":[
		"rwSepw2",
		"rwSepr",
		"rwSepr2"
	],
	"switchType":"SWITCH"
}

# Master 1 宕机后,在 mycat 2 查询:显示 WRITE_DS 还是 rwSepw

mysql> /*+ mycat:showClusters{} */;
+-----------+-------------+-------------------+-------------+----------+-------------------------------+-------------------------------------------+-------------------------------------------+-----------+
| NAME      | SWITCH_TYPE | MAX_REQUEST_COUNT | TYPE        | WRITE_DS | READ_DS                       | WRITE_L                                   | READ_L                                    | AVAILABLE |
+-----------+-------------+-------------------+-------------+----------+-------------------------------+-------------------------------------------+-------------------------------------------+-----------+
| prototype | SWITCH      | 2000              | BALANCE_ALL | rwSepw   | rwSepw,rwSepw2,rwSepr,rwSepr2 | io.mycat.plug.loadBalance.BalanceRandom$1 | io.mycat.plug.loadBalance.BalanceRandom$1 | true      |
+-----------+-------------+-------------------+-------------+----------+-------------------------------+-------------------------------------------+-------------------------------------------+-----------+
1 row in set (0.00 sec)

日志报错:

INFO   | jvm 1    | 2023/04/20 01:38:57 | 2023-04-20 01:38:57,710[ERROR]com.alibaba.druid.pool.DruidDataSource.run:2803create connection SQLException, url: jdbc:mysql://47.104.250.4:3306/mydb1?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=UTF-8&autoReconnect=true, errorCode 0, state 08001
INFO   | jvm 1    | 2023/04/20 01:38:57 | java.sql.SQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.
INFO   | jvm 1    | 2023/04/20 01:38:57 | 	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:110)
INFO   | jvm 1    | 2023/04/20 01:38:57 | 	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
INFO   | jvm 1    | 2023/04/20 01:38:57 | 	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:89)
INFO   | jvm 1    | 2023/04/20 01:38:57 | 	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:63)
INFO   | jvm 1    | 2023/04/20 01:38:57 | 	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:73)
INFO   | jvm 1    | 2023/04/20 01:38:57 | 	at com.mysql.cj.jdbc.ConnectionImpl.connectWithRetries(ConnectionImpl.java:903)
INFO   | jvm 1    | 2023/04/20 01:38:57 | 	at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:828)
INFO   | jvm 1    | 2023/04/20 01:38:57 | 	at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:453)
INFO   | jvm 1    | 2023/04/20 01:38:57 | 	at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:246)
INFO   | jvm 1    | 2023/04/20 01:38:57 | 	at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:198)
INFO   | jvm 1    | 2023/04/20 01:38:57 | 	at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1657)
INFO   | jvm 1    | 2023/04/20 01:38:57 | 	at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1723)
INFO   | jvm 1    | 2023/04/20 01:38:57 | 	at com.alibaba.druid.pool.DruidDataSource$CreateConnectionThread.run(DruidDataSource.java:2801)
INFO   | jvm 1    | 2023/04/20 01:38:57 | Caused by: com.mysql.cj.exceptions.CJCommunicationsException: Communications link failure
INFO   | jvm 1    | 2023/04/20 01:38:57 |
INFO   | jvm 1    | 2023/04/20 01:38:57 | The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
INFO   | jvm 1    | 2023/04/20 01:38:57 | 	at sun.reflect.GeneratedConstructorAccessor36.newInstance(Unknown Source)
INFO   | jvm 1    | 2023/04/20 01:38:57 | 	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
INFO   | jvm 1    | 2023/04/20 01:38:57 | 	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
INFO   | jvm 1    | 2023/04/20 01:38:57 | 	at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:61)
INFO   | jvm 1    | 2023/04/20 01:38:57 | 	at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:105)
INFO   | jvm 1    | 2023/04/20 01:38:57 | 	at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:151)
INFO   | jvm 1    | 2023/04/20 01:38:57 | 	at com.mysql.cj.exceptions.ExceptionFactory.createCommunicationsException(ExceptionFactory.java:167)
INFO   | jvm 1    | 2023/04/20 01:38:57 | 	at com.mysql.cj.protocol.a.NativeSocketConnection.connect(NativeSocketConnection.java:89)
INFO   | jvm 1    | 2023/04/20 01:38:57 | 	at com.mysql.cj.NativeSession.connect(NativeSession.java:144)
INFO   | jvm 1    | 2023/04/20 01:38:57 | 	at com.mysql.cj.jdbc.ConnectionImpl.connectWithRetries(ConnectionImpl.java:847)
INFO   | jvm 1    | 2023/04/20 01:38:57 | 	... 7 common frames omitted
INFO   | jvm 1    | 2023/04/20 01:38:57 | Caused by: java.net.ConnectException: 拒绝连接 (Connection refused)
INFO   | jvm 1    | 2023/04/20 01:38:57 | 	at java.net.PlainSocketImpl.socketConnect(Native Method)
INFO   | jvm 1    | 2023/04/20 01:38:57 | 	at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:476)
INFO   | jvm 1    | 2023/04/20 01:38:57 | 	at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:218)
INFO   | jvm 1    | 2023/04/20 01:38:57 | 	at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:200)
INFO   | jvm 1    | 2023/04/20 01:38:57 | 	at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:394)
INFO   | jvm 1    | 2023/04/20 01:38:57 | 	at java.net.Socket.connect(Socket.java:606)
INFO   | jvm 1    | 2023/04/20 01:38:57 | 	at com.mysql.cj.protocol.StandardSocketFactory.connect(StandardSocketFactory.java:155)
INFO   | jvm 1    | 2023/04/20 01:38:57 | 	at com.mysql.cj.protocol.a.NativeSocketConnection.connect(NativeSocketConnection.java:63)
INFO   | jvm 1    | 2023/04/20 01:38:57 | 	... 9 common frames omitted

莫非不支持写节点的故障切换 ??

@zwyqz
Copy link
Collaborator

zwyqz commented May 4, 2023

测过是支持的,宕机之后还是会持续发送心跳,您可以看看是否已经可以正常访问了。

@1a23-pangqiu
Copy link

1a23-pangqiu commented Jul 6, 2023

配置不对, 缺timer

        "clusterType":"MASTER_SLAVE",
        "heartbeat":{
                "heartbeatTimeout":1000,
                "maxRetryCount":3,
                "minSwitchTimeInterval":300,
                "showLog":false,
                "slaveThreshold":0.0
        },
        "masters":[
                "corp_dw0","corp_dw1"
        ],
        "maxCon":2000,
        "name":"corp",
        "readBalanceType":"BALANCE_ALL",
        "replicas":[
                "corp_dr0","corp_dr1"
        ],
        "switchType":"SWITCH",
        "timer":{
                "initialDelay": 30,
                "period":5,
                "timeUnit":"SECONDS"
        }

@jk-tom
Copy link

jk-tom commented Nov 28, 2023

但切换后,就不能再次切换了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants