Posts Tagged ‘ lustre ’

lustre的manual上有个用shell写的脚本, 但那个脚本需要等查找整个目录完了才开始重写.如果目录很大(如果不大就不需要做集群了), 这个搜索的时间会非常长. 我用perl重新实现了这个脚本, 可以边搜索边重写.

lustre难免某个ost因为空间变少或其它原因, 要更换ost. 这时, 就需要把这个ost上的数据导出转移到其它ost上,然后再更换设备.

或者, 当新加了一个ost, 但这里面没有数据, 而同时其它的ost上数据过多, 这时负载不均.

这个脚本用来把某个目录中属于某个OST上的文件, 重写来达到均衡.如果你是需要迁移数据, 请先把指定的ost deactivate.( lctl dl; lctl –device n deactivate)

注: 本脚本未保留原文件的属主, 权限位等属性. 如对此有要求, 请暂时用系统的cp命令并加-dp选项.

  1 #!/usr/bin/perl -w
  2
  3 use Digest::MD5;
  4 use File::Copy;
  5 use File::Temp qw/:mktemp/;;
  6 use strict;
  7
  8
  9 if (@ARGV != 2)
 10 {
 11     print “Usage: <obd> <directory>\n”;
 12     exit 1;
 13 }
 14
 15 open IN, ‘-|’, “lfs getstripe -r -O $ARGV[0] $ARGV[1]” or die “$!”;
 16 #open IN, “<felix” or die “$!”;
 17
 18 while (<IN>)
 19 {
 20     chomp;
 21     my $f = $_;
 22     if (-d $f)
 23     {
 24         print “$f : is a directory, skip\n”;
 25         next;
 26     }
 27
 28     ### get the md5
 29     my $md5 = Digest::MD5->new;
 30     open F, $f or die “Can’t read $f: $!”;
 31     binmode(F);
 32     $md5->addfile(*F);
 33     close F;
 34
 35     ### copy to temporary file
 36     my $tpl = $f . ‘.XXXXXX’;
 37     my $new = mktemp($tpl);
 38     unless(copy($f, $new))
 39     {
 40         print “$f: copy error: $!”;
 41         unlink $new;
 42         exit 1;
 43     }
 44
 45     my $newmd5 = Digest::MD5->new;
 46     open NF, $new or die “Can’t read $new: $!”;
 47     binmode(NF);
 48     $newmd5->addfile(*NF);
 49     close NF;
 50     if( $md5->hexdigest ne $newmd5->hexdigest)
 51     {
 52         print “$new bad checksum, $f not moved\n”;
 53         unlink $new;
 54         exit 1;
 55     }
 56     unless (move($new, $f))
 57     {
 58         print “$f move error: $!”;
 59         unlink $new;
 60         exit 1;
 61     }
 62     print  “$f\n”;
 63 }

如下:

Mar 12 14:06:31 mds0 kernel: LustreError: 4826:0:(import.c:647:ptlrpc_connect_interpret()) imp_replayable flag does not match server after reconnect. We should LBUG right here.
Mar 12 14:06:31 mds0 kernel: LustreError: 4826:0:(import.c:657:ptlrpc_connect_interpret()) test-OST0000_UUID went back in time (transno 2639 was previously committed, server now claims 0)!  See https://bugzilla.clusterfs.com/long_list.cgi?buglist=9646
Mar 12 14:06:31 mds0 kernel: LustreError: 167-0: This client was evicted by test-OST0000; in progress operations using this service will fail.

what’s that?

我让我打开链接:https://bugzilla.lustre.org/show_bug.cgi?format=multiple&id=9646

正如里面所说:当client有数据要写到lustre文件系统中,会提交。他有个聚合写入。他提交给ost,就返回,认为写入成功。那这时真的写入成功了吗?NO!大家都知道,现在的高速磁盘有缓存,数据暂时放到了缓存中,并没有真的写入。如果在没有写入的时候,意外掉电了,磁盘咔嚓,缓存里的数据就丢掉了。这时候的数据是不一致的。这个错误,就是说在ost重启后,最后一次的对磁盘修改不完整。

what should i do?

让我们顺着上一个链接,打开bug 8374: https://bugzilla.lustre.org/show_bug.cgi?format=multiple&id=8374

有几个问题需要注意:

  1.  
    1. 第一时间停止使用出错的设备(umount the target)。带错运行时间越长,会引起更多的不一致。一般来讲,如果出现不一致,ext3文件系统会标记为只读以保护数据。
    2. 小心处理。嘿嘿,错误的行动会让你的本来有可能恢复的数据变的更糟糕。
    3. 保存你的处理记录。

好,那让我们来做e2fsck.

当设备变为只读的时候,也可能检查。也可以在lustre正在使用的时候检查。不过这是在极端高可用的情况下。一般来讲,还是拆下来吧。

script是一个记录命令和输出的工具。使用script命令,然后运行e2fsck -fn /path/to/device

可能会出现好多错误。

发现了错误,那下一步是修复。修复之前要做备份:e2image /path/to/device /where/to/save/file.e2image,然后再运行e2fsck -fp /path/to/device.