---
title: 断链
description: "调用UnlinkLlmClusters接口断开并清理PD之间的通信链路。"
url: https://www.hiascend.com/document/detail/zh/canncommercial/latest/others/llmdatadistdev/llmcdv1_42_14.html
sourcePath: /source/zh/canncommercial/900/others/llmdatadistdev/llmcdv1_42_14.html
indexId: 73f5a42445defc31ce56efb7b81e6e5176b97e1fd7862b7f8743f1d4ab97a72f70
---
# 断链

#### 功能介绍

调用UnlinkLlmClusters接口断开并清理PD之间的通信链路。


#### 使用场景

当P或者D集群节点出现异常时，通过断链清理异常链路，或者需要调整集群PD节点配比时，通过断链关闭已建立的链路。


#### 功能示例

调用断链方式有如下两种。

一种是通过在D侧发起断链，常用在链路非故障场景。

```
// clusters同建链的clusters
auto ret = llm_data_dist.UnLinkLlmClusters(clusters, rets);
if (ret != LLM_SUCCESS) {
    printf("[ERROR] UnLinkLlmClusters failed, ret = %u\n", ret);
    return -1;
}
for (const auto &inner_ret : rets) {
    if (inner_ret != LLM_SUCCESS) {
        printf("[ERROR] UnLinkLlmClusters failed, ret = %u\n", inner_ret);
        return -1;
    }
}
```


一种是通过在PD两侧都发起强制断链，常用在链路故障场景。

```
// PD两侧
std::vector<Status> rets;
std::vector<ClusterInfo> clusters;
ClusterInfo cluster_info;
IpInfo local_ip_info;
// 替换为本地真实IP
local_ip_info.ip = "ip";
IpInfo remote_ip_info;
// 替换为对端真实IP
remote_ip_info.ip = "ip";
// 替换为P侧初始化时的侦听端口
remote_ip_info.port = "port";
cluster_info.remote_cluster_id = PROMPT_CLUSTER_ID;
cluster_info.local_ip_infos.emplace_back(std::move(local_ip_info)); // local_ip_infos的IP是本地的Device IP地址
cluster_info.remote_ip_infos.emplace_back(std::move(remote_ip_info)); // remote_ip_infos的IP是对端的Device IP地址
clusters.emplace_back(std::move(cluster_info));
auto ret = llmDataDist.UnLinkLlmClusters(clusters, rets, 1000, true);
if (ret != LLM_SUCCESS) {
    printf("[ERROR] UnLinkLlmClusters failed, ret = %u\n", ret);
    return -1;
}
for (const auto &inner_ret : rets) {
    if (inner_ret != LLM_SUCCESS) {
        printf("[ERROR] UnLinkLlmClusters failed, ret = %u\n", inner_ret);
        return -1;
    }
}
```


#### 异常处理

当调用UnLinkLlmClusters失败时，如果是网络故障场景，可改用强制断链方式。

更多异常处理请参考错误码。
