---
title: 断链
description: "调用UnLinkLlmClusters接口断开并清理PD之间的通信链路。"
url: https://www.hiascend.com/document/detail/zh/canncommercial/latest/API/hixlug/llmcdv2_42_15.html
sourcePath: /source/zh/canncommercial/900/API/hixlug/llmcdv2_42_15.html
indexId: 4d27101ef9bfbe04f3b7a3a7ae7f54a1cd420372403b6038febcba6008b8c75659
---
# 断链

#### 功能介绍

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


#### 使用场景

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


#### 功能示例

调用断链方式有两种：

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

```
// 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";
// 替换成Server侧初始化时的侦听端口
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是本地的Host IP地址
cluster_info.remote_ip_infos.emplace_back(std::move(remote_ip_info)); // remote_ip_infos的IP是对端的Host 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失败时，如果是网络故障场景，可改用强制断链方式。
