---
title: "Afr中4种触发自修复的过程"
author: "lancelotwjq"
date: "2012-09-03T15:57:22Z"
tags: []
categories: ["开源软件"]
slug: "afr-4"
draft: false
lastmod: "2012-09-04T14:16:23Z"
id: 1670541
url: "https://glusterfs.iteye.com/blog/1670541"
---

**Afr(Auto File Replication) 由于其有副本， 使得自修复（Self Heal）的特性得以实现。 self heal以下简称SH。副本数为n**

 

 

**1. afr\_lookup触发**

 

在afr模块中的调用先后关系是 afr\_lookup -&gt; n次 afr\_lookup\_cbk -&gt; afr\_lookup\_done -&gt; afr\_lookup\_perform\_self\_heal -&gt;  afr\_lookup\_set\_self\_heal\_params -&gt;  afr\_can\_self\_heal\_proceed? -&gt; **afr\_launch\_self\_heal.** 

 

**2. opendir 触发**

 

afr\_opendir -&gt; n次 afr\_opendir\_cbk -&gt; afr\_examine\_dir -&gt; 2\*n(?) 次 afr\_examine\_dir\_readdir\_cbk -&gt; \_\_checksums\_differ? -&gt;  **afr\_launch\_self\_heal.** 

 

**3. 发现stale subvolume时,且data\_self\_heal设置为open**

 

afr\_open\_ftruncate\_cbk / afr\_open\_cbk -&gt; afr\_open\_only\_data\_self\_heal (priv-&gt;data\_self\_heal)? 只有在这个data\_self\_heal设置为open时，才返回true. -&gt;  afr\_perform\_data\_self\_heal -&gt; **afr\_launch\_self\_heal**.

 

**4. 发现subvolume came online 时**

 

在afr\_open\_fd\_fix函数中，会比较当前subvolume与之前subvolume的个数，如果发现新增subvolume,就启动自修复

 

 

```
                if (fd_ctx->up_count < priv->up_count) {
                        need_self_heal = _gf_true;
                        fd_ctx->up_count   = priv->up_count;
                        fd_ctx->down_count = priv->down_count;
                }
....
        if (need_self_heal)
                afr_trigger_open_fd_self_heal (frame, this);
....
```