GlusterFS文档翻译 - Understanding AFR Translator 中文化

说明

本人能力有限,如果翻译过来的内容使你产生疑惑,请见原始文档:http://www.gluster.org/docs/inde ... ding_AFR_Translator

AFR 提供了类似 RAID-1 的功能。AFR 跨 subvolume 地复制文件和目录。所以,如果将4个 subvolume 配置为一个AFR,那么对于每个文件或者目录就会有4个副本。AFR 给GlusterFS 提供了HA高可用。比如说,如果一个subvolume失效了(服务器死机、网络中断等等),AFR 会保证client的请求被转移到其他subvolume的副本上响应。尽管如此,你也要读一读下面的 split brain 章节,以更好的理解一些可能在使用中潜在的问题。

AFR 也提供了自我修复的功能,以解决文件或目录的副本们出现不一致的情况。这个机制实现了:当一个节点或者网络失效后,数据能够被修复。在修复的过程中,文件或者目录会被更新到最新的版本。AFR 使用了后台文件系统的扩展属性来跟踪文件和目录的版本,并以此实现修复功能。
配置

这是一个配置的例子,他将要把所有文件和目录同时存放在brick1、brick2和brick3上。subvolume 可以使用别的translator(storage/posix or protocol/client)

volume afr-example
  type cluster/afr
  option replicate *:3                 #  1.3.7及以前的版本需要
  subvolumes brick1 brick2 brick3
end-volume

注意: 1.3.7 以前的版本为了能够实现复制,"option replicate *html:2,*txt:1" 模式匹配功能是需要的。以后的版本将这种模式匹配功能从AFR中去除了。取而代之,会以switch.case调度器来实现。

read()操作将被在subvolumes之间的负载均衡中调用。举个例子,subvolumes中有一个是本地存储,那么用它来处理所与的读操作是,效果会很好,那么在这种情况下,我们假设他是brick2,那么我们可以设置"option read-subvolume brick2"。如果是"option read-subvolume *" ,那么将会在所有的brick中来进行读的调度。一个文件将总是从同一个subvolume中读取,所以我们利用了server的caching优势。
修复

AFR 有修复的功能,文件和目录的副本都有版本的记录。AFR内建的修复功能使用一种懒散的修复算法。懒散的修复意味着文件和目录在他们没有被需要的时候是不会被修复的。
扩展属性

为了实现修复,AFR 使用了后台文件系统的扩展属性来跟踪文件和目录的版本。所以,使用AFR translator很重要的一点是你要确认你的后台文件系统是否在编译的时候加入了扩展属性的支持。

举个例子:

volume afr-example
  type cluster/afr
  option replicate *:2                 # 1.3.7及以前的版本需要
  subvolumes brick1 brick2
end-volume

文件修复

现在,如果我们在afr-example里创建了一个名为foo.txt的文件,这个文件将会被创建在brick1和brick2。这个文件将拥有两个与它所在后台文件系统相关的扩展属性。一个是trusted.glusterfs.createtime,另一个是 trusted.glusterfs.version。trusted.glusterfs.createtime扩展属性包含了文件的创建时间 (秒),trusted.glusterfs.version是一个数字,当文件修改时,值会自动增加。在文件关闭时触发。

如果brick1失效,我们修改foo.txt文件,那么version就增加了。现在,如果brick1又恢复了,当我们在这个文件上触发open()的动作时,AFR 会检查他的版本号是否一致。如果不一致,会用最新版本号的文件覆盖。当同步完成后,open()操作就会像以前一样来访问这个文件了。

如果brick1失效,我们删除了foo.txt,而且同时建立了一个同名的文件。现在,如果brick1又恢复了,明显的,brick1上的版本号会比brick2上的版本号要大,这里就用到了扩展属性中的文件创建时间来帮助决定哪一个是最新的版本。以此,我们使用创建时间和版本号来决定最终正确的副本。

这个版本属性在close()是被触发增加其值。版本不会在write()没有执行完时触发。万一,create()没有触发close(),我们也会建立一个创建时间的属性值。
目录修复

假设brick1失效了,我们删除foo.txt文件后brick1又回复了,现在我们不能建立在brick2上foo.txt,但是我们可以在 brick1上删除foo.txt。我们以这样的方式处理也是基于对目录,也有与文件类似的创建时间和版本的属性。当在目录执行lookup()后,我们会比较两个目录的创建时间和版本,检查哪个文件需要被删除,并更新目录各副本的版本。每次当一个目录或者他的subvolume中的一个被修改(一个文件或者一个子目录被建立、删除),我们都会增加该目录的版本号。

lookup()是在文件和目录被访问前的一个内核调用。在GlusterFS里,默认的,在文件或目录在过去的一秒钟内被访问过,lookup()不会再次被触发。

扩展属性,使用getfattr命令可以从后台文件里看到(getfattr -n trusted.glusterfs.version <file>)
修复功能的缺陷

因为修复机制依赖时间戳来决定哪一个subvolume有最新的文件或目录版本,这使得在所有的节点保持时间同步是很重要的。一个方法是使用NTP。如果节点的时间不能同步,就会使得AFR工作不正常。
强制自我修复

通常情况下,AFR不会强制的修复自己,而是以懒散的方式工作。这样,他不会自动的去修复所有的数据差异情况。但是取而代之的,他会在文件被打开的时候去执行修复。因此,如果你想要手动的达到数据副本间的移植,可以用下面的方法:

$ find /mnt/glusterfs -type f -exec head -n 1 {} \;

还有一个更快的修复方法:

$ find /mnt/glusterfs -type f -print0 | xargs -0 head -c1 >/dev/null


Split Brain(大脑分裂)

当集群中一些数据设置不同的节点读写时就会造成Split brain的作用,这些节点都相信他们正在写入的是正确的、权威的数据。想象一下这种情况:有一个简单的集群两个server A & B,两个client Foo & Bar。如果这个集群的网络突然被阻断隔离了,Foo只能看到server A,Bar只能看到server B,这就成了Split brain的情形。这会导致当数据写入ServerA和ServerB时不再一致。当网络恢复以后,在每一个节点上文件或者目录都会被尝试恢复到最高的版本号,这会最终导致数据可能有效,也可能无效。同样,如果一个文件或者目录在节点被分割的情况下,写入了同样多的次数,那么他在各自节点上的版本也会同样,这会使得它不会接受任何修复操作,从而使得每个subvolume上的数据变得不可治愈了。

这里有一些其它的情况会导致AFR发生'split brain'的症状,尽管没有遇到任何网络或者节点失效。通常情况下,没有一种机制能够保证每一个AFR的subvolume按同样的顺序处理从 client过来的操作。这就可能导致两个不同的写入端,同时写入同一个文件的同一部分,但是可以成功的以不同顺序在不同subvolume上写入。这潜在的能够导致不同卷上的同一个文件不一致。GlusterFS v1.5的版本将会关注这个现象。


已经存在的数据

当你想要把已有数据,并且已经镜像的两个subvolume进行变更至AFR时,会遇到这样的问题。无论如何,不建议。要知道更多的信息,请看:(http://www.gluster.org/docs/index.php/AFR_with_Existing_Data)


例子
一个Brick和一个Mirror

Master Brick:

### Export volume "brick" with the contents of "/home/export" directory.
volume brick
  type storage/posix                   # POSIX FS translator
  option directory /home/export        # Export this directory
end-volume

volume server
  type protocol/server
  subvolumes brick
  option transport-type tcp/server     # For TCP/IP transport
  option auth.ip.brick.allow *         # access to "brick" volume
end-volume

Mirror Brick:

### Export volume "brick" with the contents of "/home/mirror-export" directory.
volume brick
  type storage/posix                   # POSIX FS translator
  option directory /home/mirror-export # Export this directory
end-volume

volume server
  type protocol/server
  subvolumes brick
  option transport-type tcp/server     # For TCP/IP transport
  option auth.ip.brick.allow *         # access to "brick" volume
end-volume

Client:

volume brick
  type protocol/client
  option transport-type tcp/client     # for TCP/IP transport
  option remote-host 192.168.1.10      # IP address of the remote brick
  option remote-subvolume brick        # name of the remote volume
end-volume

volume brick-afr
  type protocol/client
  option transport-type tcp/client     # for TCP/IP transport
  option remote-host 192.168.1.11      # IP address of the remote brick
  option remote-subvolume brick        # name of the remote volume
end-volume

### 添加AFR给brick
volume afr
  type cluster/afr
  option replicate *:2                 # required for rev <= 1.3.7
  subvolumes brick brick-afr
end-volume

Clustered Mode

Two bricks clustered file system with AFR'ing each other. (the files are the same except for the commented IP address)

Brick 1:

### Export volume "brick" with the contents of "/home/export" directory.
volume brick
  type storage/posix                   # POSIX FS translator
  option directory /home/export        # Export this directory
end-volume

### Export volume "brick-afr" with the contents of "/home/afr-export" directory.
volume brick-afr
  type storage/posix                   # POSIX FS translator
  option directory /home/afr-export    # Export this directory
end-volume

volume brick-ns
type storage/posix
option directory /home/namespace
end-volume

### Add network serving capability to above brick.
volume server
  type protocol/server
  subvolumes brick brick-afr brick-ns
  option transport-type tcp/server     # For TCP/IP transport
  option auth.ip.brick.allow *         # access to "brick" volume
  option auth.ip.brick-afr.allow *     # access to "brick" volume
  option auth.ip.brick-ns.allow *     # access to "brick" volume
end-volume

Brick 2:

### Export volume "brick" with the contents of "/home/export" directory.
volume brick
  type storage/posix                   # POSIX FS translator
  option directory /home/export        # Export this directory
end-volume

### Export volume "brick-afr" with the contents of "/home/afr-export" directory.
volume brick-afr
  type storage/posix                   # POSIX FS translator
  option directory /home/afr-export    # Export this directory
end-volume

### Add network serving capability to above brick.
volume server
  type protocol/server
  subvolumes brick brick-afr
  option transport-type tcp/server     # For TCP/IP transport
  option auth.ip.brick.allow *         # access to "brick" volume
  option auth.ip.brick-afr.allow *     # access to "brick" volume
end-volume

Client:

### Add client feature and attach to remote subvolume of server1
volume brick1
  type protocol/client
  option transport-type tcp/client     # for TCP/IP transport
  option remote-host 192.168.1.10      # IP address of the remote brick
  option remote-subvolume brick        # name of the remote volume
end-volume

### Add client feature and attach to remote subvolume of brick1
volume brick1-afr
  type protocol/client
  option transport-type tcp/client     # for TCP/IP transport
  option remote-host 192.168.1.10      # IP address of the remote brick
  option remote-subvolume brick-afr    # name of the remote volume
end-volume

### Add client feature and attach to remote subvolume of brick2
volume brick2
  type protocol/client
  option transport-type tcp/client     # for TCP/IP transport
  option remote-host 192.168.1.11      # IP address of the remote brick
  option remote-subvolume brick        # name of the remote volume
end-volume

### Add client feature and attach to remote subvolume of server1
volume brick2-afr
  type protocol/client
  option transport-type tcp/client     # for TCP/IP transport
  option remote-host 192.168.1.11      # IP address of the remote brick
  option remote-subvolume brick-afr    # name of the remote volume
end-volume

### Add AFR feature to brick1
volume afr1
  type cluster/afr
  option replicate *:2                 # required for rev <= 1.3.7
  subvolumes brick1 brick2-afr
end-volume

### Add AFR feature to brick2
volume afr2
  type cluster/afr
  option replicate *:2                 # required for rev <= 1.3.7
  subvolumes brick2 brick1-afr
end-volume

## Name space option for unify
volume brick-ns
  type protocol/client
  option transport-type tcp/client     # for TCP/IP transport
  option remote-host 192.168.1.10      # IP address of the remote brick
  option remote-subvolume brick-ns        # name of the remote volume
end-volume

### Add unify feature to cluster the servers. Associate an
### appropriate scheduler that matches your I/O demand.
volume bricks
  type cluster/unify
  subvolumes afr1 afr2
  option scheduler rr
  option namespace brick-ns
  option rr.limits.min-free-disk 5%
end-volume

原文地址 http://www.gluster.org/docs/inde ... ding_AFR_Translator

http://blog.chinaunix.net/u2/88421/showart_1721432.html
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值