[sheepdog] [PATCH v2] dog/vdi: bug fix for voting majority, add test case to test it

Ruoyu liangry at ucweb.com
Thu Apr 3 12:31:32 CEST 2014


There is a critical error in the function vote_majority_object.
When all the three copies are different, the original logic still
choose the last one as majority.
---
 dog/vdi.c                |  7 ++++---
 tests/functional/091     | 34 ++++++++++++++++++++++++++++++++++
 tests/functional/091.out |  7 +++++++
 tests/functional/group   |  1 +
 4 files changed, 46 insertions(+), 3 deletions(-)
 create mode 100755 tests/functional/091
 create mode 100644 tests/functional/091.out

diff --git a/dog/vdi.c b/dog/vdi.c
index 999d4be..b7c6c76 100644
--- a/dog/vdi.c
+++ b/dog/vdi.c
@@ -1596,12 +1596,13 @@ static void vote_majority_object(struct vdi_check_info *info)
 
 	if (!majority)
 		info->result = VDI_CHECK_NO_OBJ_FOUND;
-	else if (count < nr_live_copies / 2) {
+	else if (count > nr_live_copies / 2)
+		info->result = VDI_CHECK_SUCCESS;
+	else {
 		/* no majority found */
 		majority = NULL;
 		info->result = VDI_CHECK_NO_MAJORITY_FOUND;
-	} else
-		info->result = VDI_CHECK_SUCCESS;
+	}
 
 	info->majority = majority;
 }
diff --git a/tests/functional/091 b/tests/functional/091
new file mode 100755
index 0000000..77c1f4d
--- /dev/null
+++ b/tests/functional/091
@@ -0,0 +1,34 @@
+#!/bin/bash
+
+# Test vote majority
+
+. ./common
+
+for i in 0 1 2; do
+    _start_sheep $i
+done
+_wait_for_sheep 3
+
+$DOG cluster format -c 3
+$DOG vdi create test 4M
+echo "hello, copy0" | $DOG vdi write test 0 12
+cp $STORE/0/obj/007c2b2500000000 $STORE/copy0
+echo "hello, copy1" | $DOG vdi write test 0 12
+cp $STORE/1/obj/007c2b2500000000 $STORE/copy1
+echo "hello, copy2" | $DOG vdi write test 0 12
+cp $STORE/2/obj/007c2b2500000000 $STORE/copy2
+
+cp $STORE/copy0 $STORE/0/obj/007c2b2500000000
+cp $STORE/copy1 $STORE/1/obj/007c2b2500000000
+
+$DOG vdi read test 0 12 -p 7000
+echo ""
+$DOG vdi read test 0 12 -p 7001
+echo ""
+$DOG vdi read test 0 12 -p 7002
+echo ""
+
+$DOG vdi check test
+
+$DOG cluster shutdown
+
diff --git a/tests/functional/091.out b/tests/functional/091.out
new file mode 100644
index 0000000..5b430a7
--- /dev/null
+++ b/tests/functional/091.out
@@ -0,0 +1,7 @@
+QA output created by 091
+using backend plain store
+hello, copy0
+hello, copy1
+hello, copy2
+no majority of 7c2b2500000000
+finish check&repair test
diff --git a/tests/functional/group b/tests/functional/group
index 36c2cf4..329f9fc 100644
--- a/tests/functional/group
+++ b/tests/functional/group
@@ -105,3 +105,4 @@
 088 auto quick cluster
 089 auto quick sheepfs
 090 auto quick vdi md
+091 auto quick vdi
-- 
1.8.1.2





More information about the sheepdog mailing list