Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lxc-images 下载出错 (index 同步先于images完成?) #558

Closed
SadPencil opened this issue May 5, 2019 · 16 comments
Closed

lxc-images 下载出错 (index 同步先于images完成?) #558

SadPencil opened this issue May 5, 2019 · 16 comments

Comments

@SadPencil
Copy link

执行命令

lxc-create -n test -t download -- --server mirrors.tuna.tsinghua.edu.cn/lxc-images --keyserver=hkp://keyserver.ubuntu.com:80 

结果

Setting up the GPG keyring
Downloading the image index

---
DIST    RELEASE ARCH    VARIANT BUILD
---
alpine  3.6     amd64   default 20190504_13:00
alpine  3.6     arm64   default 20190505_13:00
alpine  3.6     armhf   default 20190505_13:00
alpine  3.6     i386    default 20190504_13:00
alpine  3.7     amd64   default 20190504_13:00
alpine  3.7     arm64   default 20190505_13:00
alpine  3.7     armhf   default 20190505_13:00
alpine  3.7     i386    default 20190504_13:22
alpine  3.8     amd64   default 20190504_13:00
alpine  3.8     arm64   default 20190505_13:00
alpine  3.8     armhf   default 20190504_13:00
alpine  3.8     i386    default 20190504_13:06
alpine  3.8     ppc64el default 20190504_13:00
alpine  3.8     s390x   default 20190505_13:00
alpine  3.9     amd64   default 20190504_13:22
alpine  3.9     arm64   default 20190504_13:00
alpine  3.9     armhf   default 20190505_13:00
alpine  3.9     i386    default 20190504_13:22
alpine  3.9     ppc64el default 20190505_13:00
alpine  3.9     s390x   default 20190504_13:22
alpine  edge    amd64   default 20190504_13:00
alpine  edge    arm64   default 20190505_13:01
alpine  edge    armhf   default 20190505_13:00
alpine  edge    i386    default 20190504_13:00
alpine  edge    ppc64el default 20190505_13:00
alpine  edge    s390x   default 20190505_13:00
alt     Sisyphus        amd64   default 20190505_01:17
alt     Sisyphus        arm64   default 20190505_01:17
alt     Sisyphus        i386    default 20190505_01:17
archlinux       current amd64   default 20190505_04:18
archlinux       current arm64   default 20190505_04:18
archlinux       current armhf   default 20190505_04:18
centos  6       amd64   default 20190505_07:08
centos  6       i386    default 20190505_07:08
centos  7       amd64   default 20190505_07:08
centos  7       arm64   default 20190505_07:09
centos  7       armhf   default 20190505_07:08
centos  7       i386    default 20190505_07:08
centos  7       ppc64el default 20190505_07:08
debian  buster  amd64   default 20190505_05:24
debian  buster  arm64   default 20190505_05:25
debian  buster  armel   default 20190505_05:24
debian  buster  armhf   default 20190505_05:24
debian  buster  i386    default 20190505_05:24
debian  buster  ppc64el default 20190505_05:24
debian  buster  s390x   default 20190505_05:24
debian  jessie  amd64   default 20190505_05:24
debian  jessie  arm64   default 20180626_05:25
debian  jessie  armel   default 20190505_05:24
debian  jessie  armhf   default 20190505_05:24
debian  jessie  i386    default 20190505_05:24
debian  jessie  powerpc default 20180626_05:25
debian  jessie  ppc64el default 20180626_05:25
debian  jessie  s390x   default 20180626_05:25
debian  sid     amd64   default 20190505_05:24
debian  sid     arm64   default 20190505_05:25
debian  sid     armel   default 20190505_05:24
debian  sid     armhf   default 20190505_05:24
debian  sid     i386    default 20190505_05:24
debian  sid     powerpc default 20180708_05:25
debian  sid     ppc64el default 20190505_05:24
debian  sid     s390x   default 20190505_05:24
debian  stretch amd64   default 20190505_05:24
debian  stretch arm64   default 20190505_05:24
debian  stretch armel   default 20190505_05:24
debian  stretch armhf   default 20190505_05:24
debian  stretch i386    default 20190505_05:24
debian  stretch ppc64el default 20190505_05:24
debian  stretch s390x   default 20190505_05:24
fedora  28      amd64   default 20190504_20:33
fedora  28      arm64   default 20190504_20:33
fedora  28      armhf   default 20190504_20:33
fedora  28      ppc64el default 20190227_20:33
fedora  28      s390x   default 20190505_20:33
fedora  29      amd64   default 20190504_20:33
fedora  29      arm64   default 20190505_20:34
fedora  29      armhf   default 20190504_20:33
fedora  29      ppc64el default 20190301_20:33
fedora  29      s390x   default 20190505_20:33
gentoo  current amd64   default 20190504_16:44
gentoo  current armhf   default 20190505_16:07
gentoo  current i386    default 20190504_16:07
gentoo  current ppc64el default 20190505_16:07
gentoo  current s390x   default 20190505_16:07
opensuse        15.0    amd64   default 20190502_04:20
opensuse        15.0    arm64   default 20190502_04:20
opensuse        15.0    ppc64el default 20190322_04:20
opensuse        42.3    amd64   default 20190502_04:20
opensuse        tumbleweed      amd64   default 20190505_04:20
opensuse        tumbleweed      arm64   default 20190505_04:48
opensuse        tumbleweed      i386    default 20190505_04:46
opensuse        tumbleweed      ppc64el default 20190505_04:20
oracle  6       amd64   default 20190505_07:46
oracle  6       i386    default 20190504_07:46
oracle  7       amd64   default 20190505_07:46
plamo   6.x     amd64   default 20190505_01:33
plamo   6.x     i386    default 20190505_01:33
plamo   7.x     amd64   default 20190505_01:33
sabayon current amd64   default 20190505_01:52
ubuntu  bionic  amd64   default 20190505_07:42
ubuntu  bionic  arm64   default 20190505_07:42
ubuntu  bionic  armhf   default 20190505_07:42
ubuntu  bionic  i386    default 20190505_07:42
ubuntu  bionic  ppc64el default 20190505_07:42
ubuntu  bionic  s390x   default 20190505_07:42
ubuntu  cosmic  amd64   default 20190505_07:42
ubuntu  cosmic  arm64   default 20190505_07:43
ubuntu  cosmic  armhf   default 20190505_07:42
ubuntu  cosmic  i386    default 20190505_07:42
ubuntu  cosmic  ppc64el default 20190505_07:42
ubuntu  cosmic  s390x   default 20190505_07:42
ubuntu  disco   amd64   default 20190505_07:42
ubuntu  disco   arm64   default 20190505_07:43
ubuntu  disco   armhf   default 20190505_07:42
ubuntu  disco   i386    default 20190505_07:42
ubuntu  disco   ppc64el default 20190505_07:42
ubuntu  disco   s390x   default 20190505_07:42
ubuntu  eoan    amd64   default 20190505_07:42
ubuntu  eoan    arm64   default 20190505_07:42
ubuntu  eoan    armhf   default 20190505_07:42
ubuntu  eoan    i386    default 20190505_07:42
ubuntu  eoan    ppc64el default 20190505_07:42
ubuntu  eoan    s390x   default 20190505_07:42
ubuntu  trusty  amd64   default 20190505_07:42
ubuntu  trusty  arm64   default 20190505_07:42
ubuntu  trusty  armhf   default 20190505_07:42
ubuntu  trusty  i386    default 20190505_07:42
ubuntu  trusty  powerpc default 20180824_07:43
ubuntu  trusty  ppc64el default 20190505_07:42
ubuntu  xenial  amd64   default 20190505_07:42
ubuntu  xenial  arm64   default 20190505_07:43
ubuntu  xenial  armhf   default 20190505_07:42
ubuntu  xenial  i386    default 20190505_07:42
ubuntu  xenial  powerpc default 20180824_07:44
ubuntu  xenial  ppc64el default 20190505_07:42
ubuntu  xenial  s390x   default 20190505_07:42
---

Distribution: 
ubuntu
Release: 
bionic   
Architecture: 
amd64

The cached copy has expired, re-downloading...
Downloading the image index
Downloading the rootfs
ERROR: Failed to download http://mirrors.tuna.tsinghua.edu.cn/lxc-images//images/ubuntu/bionic/amd64/default/20190505_07:42//rootfs.tar.xz
lxc-create: test: lxccontainer.c: create_run_template: 1617 Failed to create container from template
lxc-create: test: tools/lxc_create.c: main: 327 Failed to create container test

https://mirrors.tuna.tsinghua.edu.cn/lxc-images/images/ubuntu/bionic/amd64/default/20190505_07:42/rootfs.tar.xz 确实不存在。

@SadPencil
Copy link
Author

与 Issue #382 #553 应该是差不多

@SadPencil
Copy link
Author

SadPencil commented May 5, 2019

不太明白为什么 应该属无解问题 @shankerwangmiao
#382 (comment)

即使是同步时无法做到index后于images完成,也可以用一些通用的方法解决原子性。
比如说,利用硬链接或者COW,准备A和B两套文件夹。另有一名为C的软链接。
同步时,假设A是目前同步好的文件夹,B是空文件夹。C指向A。

  1. 利用硬链接或者COW将A的文件全部链接到B。
  2. 对B进行同步。

同步完成后,不忙着把C指向B。额外检查一下index与images是否一致,
若不一致则保持C不动。若一致则C指向B,清空A,下次同步时AB的角色互换。

对于 lxc-images 这种仓库,同步的频率不是重点,是否做到daily问题不大,但原子性是很重要的。

@jiegec
Copy link
Member

jiegec commented May 6, 2019

检查index和images是否一致这件事情本身并不好做

@SadPencil
Copy link
Author

SadPencil commented May 6, 2019

@jiegec 非常好做,路径就在index文件里写着,依次检测每个条目对应的xz压缩包是否存在就够了 。

你可以下载那个index文件然后用文本编辑器打开。再简单不过的结构了。

@jiegec
Copy link
Member

jiegec commented May 6, 2019

这一个例子可能简单,但是我们没有这么多精力去研究每一个repo的index格式。

@SadPencil
Copy link
Author

@jiegec 你们代码里对 lxc-images 仓库进行镜像的方式就是对该文件进行解析然后下载,如果“没有精力解析”,你们 lxc-images 的镜像就不会存在。

@jiegec
Copy link
Member

jiegec commented May 6, 2019

大部分都是直接 rsync 的。我的意思就是,可以做,但是我们不会有精力对所有repo去做。

@SadPencil
Copy link
Author

SadPencil commented May 6, 2019 via email

@SadPencil
Copy link
Author

rsync 本身有机制可以保证同步的原子性,所以你们可以什么都不做。
但像 lxc-images 这种你们自己写脚本同步的,就要做了。
当然没有精力对所有 repo 去做。但是你也说了,“大部分都是直接 rsync 的”,那剩下的就是小部分了。

@jiegec
Copy link
Member

jiegec commented May 6, 2019

rsync 不足够保证原子性,这里还涉及到lb的问题。目前index和data不一致是普遍的问题而不是个例。

@SadPencil
Copy link
Author

SadPencil commented May 6, 2019

既然如此,可以考虑用普遍的方法来解决普遍的问题。
比如 #558 (comment)
【稳定状态】--尝试同步,并判断是否稳定--【判断稳定后到达下一个稳定状态】
这个过程在所有节点进行,所有节点都稳定后,统一从上一个稳定状态转移到下一个稳定状态。
对于 rsync,判断稳定的方法可以是【rsync 成功完成+文件修改时间一致】。

@shankerwangmiao
Copy link
Member

如果 lxc 的 images 是可以保证已有的 image 不修改,只增加和删除的话,那么可以先拉取新的 index,再拉取新的包,然后再上线 index。否则无法做到原子性。

我们的同步脚本会尽量避免和减少读取已有的文件的内容,以及扫描文件夹的操作。因为镜像服务器的磁盘 IO 压力非常大。

@SadPencil
Copy link
Author

如果 lxc 的 images 是可以保证已有的 image 不修改,只增加和删除的话,那么可以先拉取新的 index,再拉取新的包,然后再上线 index。否则无法做到原子性。

我们的同步脚本会尽量避免和减少读取已有的文件的内容,以及扫描文件夹的操作。因为镜像服务器的磁盘 IO 压力非常大。

不修改,每次都是新增一些文件(以构建日期开头的文件夹)。旧的文件会在index更新后失效。

@z4yx
Copy link
Member

z4yx commented Feb 22, 2020

想到这样一个同步策略:

  1. 从上游下载索引文件,但不急于替换,先存为临时文件
  2. 根据获得的索引,从上游下载新增image文件,不删除本地旧版本(指不在索引中的版本)。如遇某文件下载失败则退出。
  3. 替换索引文件
  4. 扫描并删除超过一天以上的旧版本image

这样可以一定程度保证同步过程不影响正在使用的用户,并且保证索引中引用的文件都是存在的。

@SadPencil
Copy link
Author

SadPencil commented Feb 22, 2020

想到这样一个同步策略:

  1. 从上游下载索引文件,但不急于替换,先存为临时文件
  2. 根据获得的索引,从上游下载新增image文件,不删除本地旧版本。如遇某文件下载失败则退出。
  3. 替换索引文件
  4. 扫描并删除超过一天以上的旧版本image

这样可以一定程度保证同步过程不影响正在使用的用户,并且保证索引中引用的文件都是存在的。

差不多。
核心是保证每次更新,索引文件对应的image文件全部存在,即永远是从一个有效状态变成下一个有效状态。
而且索引文件和image文件都是用同一个 GPG key 做的签名,所以但凡有一个image文件下载失败,也不能替换索引文件。扫描并删除旧image最好也要根据现在的索引文件来,一直下载失败导致索引文件长时间不更新也是有可能的。lxc-images仓库的性质决定了这个仓库更新频率很不重要,monthly都没问题,但是一致性很重要。

@z4yx
Copy link
Member

z4yx commented Feb 22, 2020

已按照上述思路更新脚本,等待同步完成,之后发现问题再报告吧。

@z4yx z4yx closed this as completed Feb 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants