-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Enhancement: Added read_mask on ec_inode to specify bricks for read #4496
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
Open
sbk173
wants to merge
1
commit into
gluster:devel
Choose a base branch
from
sbk173:inode_readmask
base: devel
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
#!/bin/bash | ||
. $(dirname $0)/../../include.rc | ||
. $(dirname $0)/../../volume.rc | ||
. $(dirname $0)/../../ec.rc | ||
|
||
EC_READMASK_XATTR="glusterfs.ec.readmask" | ||
|
||
# Parsing XML file to get count of READ calls made on bricks | ||
get_brick_reads() { | ||
local xml_file="$1" | ||
local -n result_array=$2 # Reference to output array | ||
|
||
local index=0 | ||
local brick_reads=0 | ||
local inside_fop=0 | ||
local read_hits=0 | ||
local brick_found=0 | ||
|
||
while IFS= read -r line; do | ||
if [[ $line =~ "<brickName>" ]]; then | ||
if ((brick_found)); then | ||
result_array[index]=$brick_reads | ||
((index++)) | ||
fi | ||
brick_found=1 | ||
brick_reads=0 | ||
fi | ||
|
||
if [[ $line =~ "<fop>" ]]; then | ||
inside_fop=1 | ||
read_hits=0 | ||
fi | ||
|
||
if [[ $inside_fop -eq 1 && $line =~ "<name>READ</name>" ]]; then | ||
read_hits=1 | ||
fi | ||
|
||
if [[ $inside_fop -eq 1 && $line =~ "<hits>" ]]; then | ||
if ((read_hits)); then | ||
brick_reads=$(echo "$line" | sed -E 's/.*<hits>([0-9]+)<\/hits>.*/\1/') | ||
fi | ||
fi | ||
|
||
if [[ $line =~ "</fop>" ]]; then | ||
inside_fop=0 | ||
fi | ||
done < "$xml_file" | ||
|
||
if ((brick_found)); then | ||
result_array[index]=$brick_reads | ||
fi | ||
} | ||
|
||
#Function to compare read_count arrays and verify that only specified bricks have modified read values | ||
compare_arrays() { | ||
local -n arr1=$1 | ||
local -n arr2=$2 | ||
local -a indices=("${@:3}") | ||
|
||
local length1=${#arr1[@]} | ||
local length2=${#arr2[@]} | ||
|
||
|
||
if [[ $length1 -ne $length2 ]]; then | ||
echo "Array lengths differ" | ||
return 1 | ||
fi | ||
|
||
|
||
local -A changed_indices | ||
|
||
for i in "${!arr1[@]}"; do | ||
if [[ "${arr1[i]}" -ne "${arr2[i]}" ]]; then | ||
changed_indices[$i]=1 | ||
fi | ||
done | ||
|
||
for i in "${!changed_indices[@]}"; do | ||
if [[ ! " ${indices[@]} " =~ " $i " ]]; then | ||
echo "Unexpected change at index $i" | ||
return 1 | ||
fi | ||
done | ||
|
||
echo "Only specified indices changed" | ||
return 0 | ||
} | ||
|
||
validate_read() { | ||
local mask="$1" | ||
local space_sep_values="${mask//:/ }" | ||
|
||
$CLI volume profile $V0 info --xml > $tmpdir/preread.xml | ||
local -a brick_reads_array_old | ||
get_brick_reads $tmpdir/preread.xml brick_reads_array_old | ||
echo ${brick_reads_array_old[@]} | ||
|
||
# Set readmask to bricks 0, 1, 3, 5, 8, 9 | ||
if ! setfattr -n "$EC_READMASK_XATTR" -v "$mask" "$M0/newfile"; then | ||
echo "Failed to set readmask xattr" | ||
return 1 | ||
fi | ||
|
||
dd if="$M0/newfile" of=/dev/null iflag=direct bs=4M | ||
|
||
sleep 1 | ||
|
||
$CLI volume profile $V0 info --xml > "$tmpdir/after_mask.xml" | ||
local -a brick_reads_array_new | ||
get_brick_reads "$tmpdir/after_mask.xml" brick_reads_array_new | ||
echo "After readmask: ${brick_reads_array_new[@]}" | ||
|
||
compare_arrays brick_reads_array_new brick_reads_array_old "${space_sep_values[@]}" | ||
return $? | ||
} | ||
|
||
#Setup | ||
cleanup | ||
TEST glusterd | ||
TEST pidof glusterd | ||
TEST $CLI volume info | ||
|
||
TEST mkdir -p $B0/${V0}{0,1,2,3,4,5,6,7,8,9} | ||
TEST $CLI volume create $V0 disperse 10 redundancy 4 $H0:$B0/${V0}{0,1,2,3,4,5,6,7,8,9} | ||
|
||
EXPECT "$V0" volinfo_field $V0 'Volume Name' | ||
EXPECT 'Created' volinfo_field $V0 'Status' | ||
EXPECT '10' brick_count $V0 | ||
|
||
TEST $CLI volume start $V0 | ||
EXPECT_WITHIN $PROCESS_UP_TIMEOUT 'Started' volinfo_field $V0 'Status' | ||
|
||
# Mount FUSE with caching disabled | ||
TEST $GFS -s $H0 --volfile-id $V0 $M0 | ||
EXPECT_WITHIN $CHILD_UP_TIMEOUT "10" ec_child_up_count $V0 0 | ||
|
||
TEST $CLI volume profile $V0 start | ||
|
||
|
||
# Create file | ||
TEST dd if=/dev/urandom of=$M0/newfile bs=4M count=5 | ||
|
||
# Read without setting readmask xattr should not fail | ||
TEST dd if=$M0/newfile of=/dev/null iflag=direct bs=4M | ||
|
||
# Create temporary directory | ||
tmpdir=$(mktemp -d -t ${0##*/}.XXXXXX) | ||
|
||
|
||
# Test 1: Read with mask set to bricks 0, 1, 3, 5, 8, 9 | ||
TEST validate_read "0:1:3:5:8:9" | ||
|
||
# Test 2: Read with mask set to bricks 4, 5, 6, 7, 8, 9 | ||
TEST validate_read "4:5:6:7:8:9" | ||
|
||
# Test 3: setfattr wont set invalid read_masks | ||
TEST ! setfattr -n $EC_READMASK_XATTR -v "1:sm:snb:adi:as" $M0/newfile | ||
|
||
TEST ! setfattr -n $EC_READMASK_XATTR -v "0:1::2ab" $M0/newfile | ||
|
||
# Test 4: setfattr wont set read_mask in case insufficient bricks are provided | ||
TEST ! setfattr -n $EC_READMASK_XATTR -v "0:1:2:3" $M0/newfile | ||
TEST ! setfattr -n $EC_READMASK_XATTR -v "4:5" $M0/newfile | ||
|
||
rm -rf "$tmpdir" | ||
cleanup; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.