glusterfs
92 строки · 2.3 Кб
1#!/bin/bash
2
3# Test that the rsync and "extra" regexes cause rename-in-place without
4# creating linkfiles, when they're supposed to. Without the regex we'd have a
5# 1/4 chance of each file being assigned to the right place, so with 16 files
6# we have a 1/2^32 chance of getting the correct result by accident.
7
8. $(dirname $0)/../../include.rc
9. $(dirname $0)/../../volume.rc
10
11function count_linkfiles {
12local i
13local count=0
14for i in $(seq $2 $3); do
15x=$(find $1$i -perm -1000 | wc -l)
16# Divide by two because of the .glusterfs links.
17count=$((count+x/2))
18done
19echo $count
20}
21
22# This function only exists to get around quoting difficulties in TEST.
23function set_regex {
24$CLI volume set $1 cluster.extra-hash-regex '^foo(.+)bar$'
25}
26
27cleanup;
28
29TEST glusterd
30TEST pidof glusterd
31
32mkdir -p $H0:$B0/${V0}0
33mkdir -p $H0:$B0/${V0}1
34mkdir -p $H0:$B0/${V0}2
35mkdir -p $H0:$B0/${V0}3
36
37# Create and start a volume.
38TEST $CLI volume create $V0 $H0:$B0/${V0}0 $H0:$B0/${V0}1 \
39$H0:$B0/${V0}2 $H0:$B0/${V0}3
40TEST $CLI volume start $V0
41EXPECT_WITHIN $PROCESS_UP_TIMEOUT 'Started' volinfo_field $V0 'Status';
42
43# Mount it.
44TEST glusterfs --volfile-server=$H0 --volfile-id=$V0 $M0
45
46# Make sure the rsync regex works, by verifying that no linkfiles are
47# created.
48rm -f $M0/file*
49for i in $(seq 0 15); do
50fn=$(printf file%x $i)
51tmp_fn=$(printf .%s.%d $fn $RANDOM)
52echo testing > $M0/$tmp_fn
53mv $M0/$tmp_fn $M0/$fn
54done
55lf=$(count_linkfiles $B0/$V0 0 3)
56TEST [ "$lf" -eq "0" ]
57
58# Make sure that linkfiles *are* created for normal files.
59rm -f $M0/file*
60for i in $(seq 0 15); do
61fn=$(printf file%x $i)
62tmp_fn=$(printf foo%sbar $fn)
63echo testing > $M0/$tmp_fn
64mv $M0/$tmp_fn $M0/$fn
65done
66lf=$(count_linkfiles $B0/$V0 0 3)
67TEST [ "$lf" -ne "0" ]
68
69# Make sure that setting an extra regex suppresses the linkfiles.
70TEST set_regex $V0
71rm -f $M0/file*
72for i in $(seq 0 15); do
73fn=$(printf file%x $i)
74tmp_fn=$(printf foo%sbar $fn)
75echo testing > $M0/$tmp_fn
76mv $M0/$tmp_fn $M0/$fn
77done
78lf=$(count_linkfiles $B0/$V0 0 3)
79TEST [ "$lf" -eq "0" ]
80
81# Re-test the rsync regex, to make sure the extra one didn't break it.
82rm -f $M0/file*
83for i in $(seq 0 15); do
84fn=$(printf file%x $i)
85tmp_fn=$(printf .%s.%d $fn $RANDOM)
86echo testing > $M0/$tmp_fn
87mv $M0/$tmp_fn $M0/$fn
88done
89lf=$(count_linkfiles $B0/$V0 0 3)
90TEST [ "$lf" -eq "0" ]
91
92cleanup
93