---
title: R 副本切主后 location cache 无法刷新导致无主报错 4038-OceanBase数据库使用指南
description: 了解OceanBase数据库在实际应用中关于R 副本切主后 location cache 无法刷新导致无主报错 4038相关的常见问题和使用技巧，帮助您快速解决R 副本切主后 location cache 无法刷新导致无主报错 4038的难题。
---
切换语言

- 中文站 - 简体中文
- International - English
- 日本站 - 日本語

划线反馈

# R 副本切主后 location cache 无法刷新导致无主报错 4038

更新时间：2026-08-06 07:36

适用版本： V2.2.x、V3.1.x、V3.2.x 内容类型：Troubleshoot  

## 问题现象

集群中的租户曾经通过 locality 变更下掉 R 副本，而且后续删除了 R 副本所在的 OBServer/zone，在切主（运维触发或者故障触发）等场景下 OBServer 需要触发location_cache 刷新，由于一个 OBServer 的 bug，有一定概率会导致 location cache 持续刷新不成功，日志持续报错 `“fail to check is local server(ret=-4018, addr=”`，最终导致相关分区无法成功获取 location 信息，导致 SQL/事务持续报错 4038 直到超时。

```shell
WARN [SHARE.PT] init_batch_rpc_renew_struct (ob_partition_location_cache.cpp:1508) [2117][752][xxxxx-xxxxx] [lt=6] [dc=0] fail to check is local server(ret=-4018, addr="xx.xx.xx.xx:xx")

```

## 问题原因

在上述切主场景下，可能会触发批量 location_cache 刷新的逻辑，但由于 OceanBase 产品 BUG，批量刷新 location_cache 时会误向已下线的R副本持续发 RPC，且在报错后不触发其他刷新方式，进而导致无法成功获取 location 信息。

## 问题的风险及影响

影响业务正常运行。

## 影响的版本

OceanBase 数据库 V2.2.77 GA（oceanbase-2.2.77-20210508211731）及之后版本、V3.1.2 GA（oceanbase-3.1.2-20210618150922）及之后版本、V3.2.3 GA（oceanbase-3.2.3.0-20220418212020）及之后版本、V3.2.4 GA（oceanbase-3.2.4.0-100000072022102819）及之后版本。

#### 注意

OceanBase V2.2.30 和 V1.4.79 版本无问题。

## 解决方法及规避方式

### 解决方法

升级 OBServer 至问题已修复版本。目前已修复的版本包括 V2.2.77 BP15（oceanbase-2.2.77-115000012023010607）、V3.1.2 BP11（oceanbase-3.1.2-111000052023010412）、V3.2.3 BP7（oceanbase-3.2.3.3-107000092023011911）、V3.2.4 BP1（oceanbase-3.2.4.1-101000052023010822）。

### 临时解决方法

触发该问题后，使用系统租户直连 OBServer，触发问题机器的 location_cache 清理，执行命令如下。

```shell
ALTER SYSTEM flush location cache;

```

### 规避方式

如果集群在问题存在的版本，且短时间内无法升级到问题解决版本，在这期间还需要对集群进行运维操作（delete server/zone），运维的目标节点包含曾经通过 locality 变更下掉的 R 副本。规避方式如下（皆以系统租户身份登录执行）。

1. 检查目标节点不含残留的 R 副本，以下语句 svr_ip/svr_port 替换为实际目标节点地址，预期下列语句查询结果为 0。

   ```shell
   select count(*) from oceanbase.__all_virtual_core_meta_table where svr_ip = "127.x.x.x" and svr_port = 2881 and replica_type = 16;

   ```

   ```shell
   select count(*) from oceanbase.__all_root_table where svr_ip = "127.x.x.x" and svr_port = 2881 and replica_type = 16;

   ```

   ```shell
   select count(*) from oceanbase.__all_virtual_meta_table where svr_ip = "127.x.x.x" and svr_port = 2881 and replica_type = 16;

   ```
 2. 直连集群所有节点，执行以下命令清理旧的 location cache（清理 cache 会触发业务 RT 抖动）。

   ```
 3. 执行后续 delete server/zone 的剩余步骤。

上一篇

[选举层面无主问题排查指南](https://www.oceanbase.com/knowledge-base/oceanbase-database-1000000001230231)

下一篇

[OceanBase 数据库 V4.0 版本中无主问题排查手册](https://www.oceanbase.com/knowledge-base/oceanbase-database-1000000001230454) ![有帮助](https://gw.alipayobjects.com/mdn/ob_asset/afts/img/A*y6ocSqN8cqsAAAAAAAAAAAAAARQnAQ)![无帮助](https://gw.alipayobjects.com/mdn/ob_asset/afts/img/A*BG9IQJyLHF8AAAAAAAAAAAAAARQnAQ)![反馈](https://gw.alipayobjects.com/mdn/ob_asset/afts/img/A*eTWdQKCRKHwAAAAAAAAAAAAAARQnAQ)[AI](https://www.oceanbase.com/obi) 咨询热线
