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

ClusterCanalConnector 多个实例监听多个 Destination 只有一个能竞争到 #66

Closed
LucaslEliane opened this issue Mar 9, 2021 · 1 comment
Labels
bug Something isn't working

Comments

@LucaslEliane
Copy link
Contributor

你好,我们在用 canal-go 来消费多个 Destination 的 binlog 做数据同步,但是发现多个实例只有一个能够竞争到并且连接到 canal-server。

看代码实现 doConnect 的时候,zk 的 path 都是 /canal-consumer,如果启动了多个实例,要去监听不同的 Destination,看起来只有一个实例能够竞争到去 Connect。

修改了一下用 "/canal-consumer/" + destination 拼接成 zk 的 path 就可以了。不知道这里这样实现会不会有坑。

const 	(
	runningFlag = byte(0)
	notRunningFlag = byte(0)
	path = "/canal-consumer"
)

func NewClusterCanalConnector(canalNode *CanalClusterNode, username string, password string, destination string,
	soTimeOut int32, idleTimeOut int32) (*ClusterCanalConnector,error) {

	destinationPath := fmt.Sprintf("%s/%s", path, destination)

	err := checkRootPath(canalNode.zkClient, destinationPath)
	if err != nil {
		return nil, err
	}

	currentSequence, err := createEphemeralSequence(canalNode.zkClient, destinationPath)
	if err != nil {
		return nil,err
	}

	cluster := &ClusterCanalConnector{
		canalNode:   canalNode,
		username:    username,
		password:    password,
		destination: destination,
		soTimeOut:   soTimeOut,
		idleTimeOut: idleTimeOut,
		RetryTimes:  0,
		currentSequence:currentSequence,
		zkVersion:	 0,
		Path:		 destinationPath,
	}

	return cluster, nil
}
@withlin
Copy link
Owner

withlin commented Mar 16, 2021

你好,可以考虑给我提个pr.

@withlin withlin added the bug Something isn't working label Mar 16, 2021
@withlin withlin closed this as completed Apr 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants