示例#1
0
// Initialize distributed locking only in case of distributed setup.
// Returns if the setup is distributed or not on success.
func initDsyncNodes(disks []string, port int) error {
	serverPort := strconv.Itoa(port)
	cred := serverConfig.GetCredential()
	// Initialize rpc lock client information only if this instance is a distributed setup.
	var clnts []dsync.RPC
	myNode := -1
	for _, disk := range disks {
		if idx := strings.LastIndex(disk, ":"); idx != -1 {
			clnts = append(clnts, newAuthClient(&authConfig{
				accessKey: cred.AccessKeyID,
				secretKey: cred.SecretAccessKey,
				// Construct a new dsync server addr.
				address: disk[:idx] + ":" + serverPort,
				// Construct a new rpc path for the disk.
				path:        pathutil.Join(lockRPCPath, disk[idx+1:]),
				loginMethod: "Dsync.LoginHandler",
			}))

			if isLocalStorage(disk) && myNode == -1 {
				myNode = len(clnts) - 1
			}
		}
	}

	return dsync.SetNodesWithClients(clnts, myNode)
}
示例#2
0
// Initialize distributed locking only in case of distributed setup.
// Returns if the setup is distributed or not on success.
func initDsyncNodes(eps []*url.URL) error {
	cred := serverConfig.GetCredential()
	// Initialize rpc lock client information only if this instance is a distributed setup.
	clnts := make([]dsync.RPC, len(eps))
	myNode := -1
	for index, ep := range eps {
		if ep == nil {
			return errInvalidArgument
		}
		clnts[index] = newAuthClient(&authConfig{
			accessKey: cred.AccessKeyID,
			secretKey: cred.SecretAccessKey,
			// Construct a new dsync server addr.
			secureConn: isSSL(),
			address:    ep.Host,
			// Construct a new rpc path for the endpoint.
			path:        pathutil.Join(lockRPCPath, getPath(ep)),
			loginMethod: "Dsync.LoginHandler",
		})
		if isLocalStorage(ep) && myNode == -1 {
			myNode = index
		}
	}
	return dsync.SetNodesWithClients(clnts, myNode)
}