手机版
你好,游客 登录 注册 搜索
背景:
阅读新闻

OpenStack Swift 云存储技术详解

[日期:2013-08-01] 来源:cnblogs.com  作者:余兴超 [字体:大 中 小]

7. Container to Container Synchronization 容器同步

7.1 Overview 概述

Swift has a feature where all the contents of a container can be mirrored to another container through background synchronization. Swift cluster operators configure their cluster to allow/accept sync requests to/from other clusters, and the user specifies where to sync their container to along with a secret synchronization key.

swift有一个特性:容器的内容可以通过后端的同步镜像到其他的容器。Swift集群操作员配置他们的集群来允许/接受同步请求到/来自其他的集群,用户使用同步密钥来指定要同步的容器。

Note 注意

Container sync will sync object POSTs only if the proxy server is set to use “object_post_as_copy = true” which is the default. So-called fast object posts, “object_post_as_copy = false” do not update the container listings and therefore can’t be detected for synchronization.

只有代理服务器设置使用 “object_post_as_copy = true”默认值时,容器同步将会同步对象的POSTs。所谓快速对象的posts,使用“object_post_as_copy = false”不升级容器列表并且因此不能被同步检测到。

Note 注意

If you are using the large objects feature you will need to ensure both your manifest file and your segment files are synced if they happen to be in different containers.

如果你使用大对象特性你将需要确保你的描述文件和你的分卷文件被同步了,如果它们在不同的容器内。

7.2 Configuring a Cluster’s Allowable Sync Hosts

配置一个集群容许的同步主机

The Swift cluster operator must allow synchronization with a set of hosts before the user can enable container synchronization. First, the backend container server needs to be given this list of hosts in the container-server.conf file:

Swift集群操作员必须在用户开启容器同步之前允许和一组主机同步。首先,后端的容器服务器需要在container-server.conf文件中给定这些主机列表:

[DEFAULT]

# This is a comma separated list of hosts allowed in the

# X-Container-Sync-To field for containers.

# allowed_sync_hosts = 127.0.0.1

allowed_sync_hosts = host1,host2,etc.

...

 

[container-sync]

# You can override the default log routing for this app here (don't

# use set!):

# log_name = container-sync

# log_facility = LOG_LOCAL0

# log_level = INFO

# Will sync, at most, each container once per interval

# interval = 300

# Maximum amount of time to spend syncing each container

# container_time = 60

Tracking sync progress, problems, and just general activity can only be achieved with log processing for this first release of container synchronization. In that light, you may wish to set the above log_ options to direct the container-sync logs to a different file for easier monitoring. Additionally, it should be noted there is no way for an end user to detect sync progress or problems other than HEADing both containers and comparing the overall information.

跟踪同步的进度,问题,以及只是一般的活动可以只用日志处理来实现容器同步的第一次分布。基于此,你可能希望设置以上的log选项将contaniner-sync导向不同的文件方便监控。此外,需要主要的是对于终端用户来说他们除了使用HEAD两个容器并且比较它们的整体信息以外没有方法来检测同步的进度或问题。

The authentication system also needs to be configured to allow synchronization requests. Here is an example with TempAuth:

认真系统也需要进行配置来允许同步请求。这里有一个关于TempAuth的例子:

[filter:tempauth]

# This is a comma separated list of hosts allowed to send

# X-Container-Sync-Key requests.

# allowed_sync_hosts = 127.0.0.1

allowed_sync_hosts = host1,host2,etc.

The default of 127.0.0.1 is just so no configuration is required for SAIO setups – for testing.

默认值127.0.0.1只是因为SAIO设置不需要配置-用于测试。

7.3 Using the swift tool to set up synchronized containers

使用swift工具来设置同步容器

Note 注意

You must be the account admin on the account to set synchronization targets and keys.

你必须使用该帐号的帐号管理权限来设置同步目标和键。

You simply tell each container where to sync to and give it a secret synchronization key. First, let’s get the account details for our two cluster accounts:

你只需告诉每个容器同步到何处并且给予一个同步的密钥。首先,让我们先获得我们的两个集群帐号的帐号细节:

$ swift -A http://cluster1/auth/v1.0 -U test:tester -K testing stat -v

StorageURL: http://cluster1/v1/AUTH_208d1854-e475-4500-b315-81de645d060e

Auth Token: AUTH_tkd5359e46ff9e419fa193dbd367f3cd19

Account: AUTH_208d1854-e475-4500-b315-81de645d060e

Containers: 0

Objects: 0

Bytes: 0

 

$ swift -A http://cluster2/auth/v1.0 -U test2:tester2 -K testing2 stat -v

StorageURL: http://cluster2/v1/AUTH_33cdcad8-09fb-4940-90da-0f00cbf21c7c

Auth Token: AUTH_tk816a1aaf403c49adb92ecfca2f88e430

Account: AUTH_33cdcad8-09fb-4940-90da-0f00cbf21c7c

Containers: 0

Objects: 0

Bytes: 0

Now, let’s make our first container and tell it to synchronize to a second we’ll make next:

现在,让我们获取我们第一个容器并且告诉它我们下一步将会设置的第二个容器:

$ swift -A http://cluster1/auth/v1.0 -U test:tester -K testing post \

-t 'http://cluster2/v1/AUTH_33cdcad8-09fb-4940-90da-0f00cbf21c7c/container2' \

-k 'secret' container1

The -t indicates the URL to sync to, which is the StorageURL from cluster2 we retrieved above plus the container name. The -k specifies the secret key the two containers will share for synchronization. Now, we’ll do something similar for the second cluster’s container:

-t表示同步到的URL,就是我们上一步从cluster2检索得到的StorageURL再加上容器名称。-k指定了两个容器共享用于同步的安全密钥。现在,我们对于第二个集群容器将会做一些类似的操作:

$ swift -A http://cluster2/auth/v1.0 -U test2:tester2 -K testing2 post \

-t 'http://cluster1/v1/AUTH_208d1854-e475-4500-b315-81de645d060e/container1' \

-k 'secret' container2

That’s it. Now we can upload a bunch of stuff to the first container and watch as it gets synchronized over to the second:

就是如此。现在我们可以上载一堆东西到第一个容器并且观察它与第二个容器进行同步:

$ swift -A http://cluster1/auth/v1.0 -U test:tester -K testing \

upload container1 .

photo002.png

photo004.png

photo001.png

photo003.png

 

$ swift -A http://cluster2/auth/v1.0 -U test2:tester2 -K testing2 \

list container2

 

[Nothing there yet, so we wait a bit...]

[If you're an operator running SAIO and just testing, you may need to

run 'swift-init container-sync once' to perform a sync scan.]

 

$ swift -A http://cluster2/auth/v1.0 -U test2:tester2 -K testing2 \

list container2

photo001.png

photo002.png

photo003.png

photo004.png

You can also set up a chain of synced containers if you want more than two. You’d point 1 -> 2, then 2 -> 3, and finally 3 -> 1 for three containers. They’d all need to share the same secret synchronization key.

你也可以设置一个同步容器链如果你想要使用两个以上的容器。对于三个容器,你得将指向1->2,然后2->3,最后3->1。它们须共享同一个同步密钥。

7.4 Using curl (or other tools) instead

使用curl(或其他工具代替)

So what’s swift doing behind the scenes? Nothing overly complicated. It translates the -t <value> option into an X-Container-Sync-To:<value> header and the -k <value> option into an X-Container-Sync-Key: <value> header.

因此swift在这个场景背后做了什么呢?其实没有什么很复杂的操作。它将-t<value>选项转换为一个 X-Container-Sync-To: <value> 头以及将-k <value>选项转换为 X-Container-Sync-Key: <value> 头。

For instance, when we created the first container above and told it to synchronize to the second, we could have used this curl command:

例如,当我们创建以上第一个容器时并且告诉它与第二个容器同步,我们可以使用以下curl命令:

$ curl -i -X POST -H 'X-Auth-Token: AUTH_tkd5359e46ff9e419fa193dbd367f3cd19' \

-H 'X-Container-Sync-To: http://cluster2/v1/AUTH_33cdcad8-09fb-4940-90da-0f00cbf21c7c/container2' \

-H 'X-Container-Sync-Key: secret' \

'http://cluster1/v1/AUTH_208d1854-e475-4500-b315-81de645d060e/container1'

HTTP/1.1 204 No Content

Content-Length: 0

Content-Type: text/plain; charset=UTF-8

Date: Thu, 24 Feb 2011 22:39:14 GMT

7.5 What’s going on behind the scenes, in the cluster?

在集群中,后台正在运行着什么?

The swift-container-sync does the job of sending updates to the remote container.

swift-container-sync执行发送update到远程容器的工作。

This is done by scanning the local devices for container databases and checking for x-container-sync-to and x-container-sync-key metadata values. If they exist, newer rows since the last sync will trigger PUTs or DELETEs to the other container.

通过扫描本地设备的容器数据库并且检测x-container-sync-to和x-container-sync-key元数据值来完成。如果它们存在,上一次更新的较新的行将会触发PUTS和DELETEs到其它的容器。

Note 注意

Container sync will sync object POSTs only if the proxy server is set to use “object_post_as_copy = true” which is the default. So-called fast object posts, “object_post_as_copy = false” do not update the container listings and therefore can’t be detected for synchronization.

容器同步将会同步对象POSTs仅当代理服务器设置使用了“object_post_as_copy = true”的默认值。所谓的快速对象发送,“object_post_as_copy = false”不升级容器列表,所以因此不能被同步检测。

The actual syncing is slightly more complicated to make use of the three (or number-of-replicas) main nodes for a container without each trying to do the exact same work but also without missing work if one node happens to be down.

使用一个容器的三个(或者replicas的数目number-of-replicas)主节点实际的同步稍微更复杂些,没有每个尝试去做完全相同的工作而且如果一个节点发生故障不会丢失工作。

Two sync points are kept per container database. All rows between the two sync points trigger updates. Any rows newer than both sync points cause updates depending on the node’s position for the container (primary nodes do one third, etc. depending on the replica count of course). After a sync run, the first sync point is set to the newest ROWID known and the second sync point is set to newest ROWID for which all updates have been sent.

两个同步点被保存在每个容器数据库中。在两个同步点之间的所有的行触发update。两个同步节点间触发updates的任何一个较新的行取决于节点对于容器的位置(主节点做1/3,等等。当然取决于replica的数量)。在同步运行之后,第一个同步点设置为最新已知的ROWID并且第二个同步点被设置为最新的ROWID表示所有的updates已经被发送。

An example may help. Assume replica count is 3 and perfectly matching ROWIDs starting at 1.

一个例子有助于理解。假设replica数量是3并且完全匹配在1开始的ROWID。

First sync run, database has 6 rows:

SyncPoint1 starts as -1.

SyncPoint2 starts as -1.

No rows between points, so no “all updates” rows.

Six rows newer than SyncPoint1, so a third of the rows are sent by node 1, another third by node 2, remaining third by node 3.

SyncPoint1 is set as 6 (the newest ROWID known).

SyncPoint2 is left as -1 since no “all updates” rows were synced.

Next sync run, database has 12 rows:

SyncPoint1 starts as 6.

SyncPoint2 starts as -1.

The rows between -1 and 6 all trigger updates (most of which should short-circuit on the remote end as having already been done).

Six more rows newer than SyncPoint1, so a third of the rows are sent by node 1, another third by node 2, remaining third by node 3.

SyncPoint1 is set as 12 (the newest ROWID known).

SyncPoint2 is set as 6 (the newest “all updates” ROWID).

In this way, under normal circumstances each node sends its share of updates each run and just sends a batch of older updates to ensure nothing was missed.

用这种方式,在一般情况下每个节点发送它运行的共享的更新并且仅发送一批较老的更新来确保没有丢失信息。

linux
相关资讯       Swift  OpenStack Swift 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款