Skip to content

Commit 4fed82d

Browse files
committed
fix: pulsar bookie member leave fail
1 parent f118228 commit 4fed82d

File tree

2 files changed

+18
-89
lines changed

2 files changed

+18
-89
lines changed

addons/pulsar/scripts-ut-spec/bookies_member_leave_spec.sh

Lines changed: 10 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -16,73 +16,27 @@ Describe "Pulsar Bookies Member Leave Bash Script Tests"
1616
}
1717
BeforeAll "init"
1818

19-
Describe "format_bookie()"
20-
It "formats bookie with force and deleteCookie"
21-
bin/bookkeeper() {
22-
if [ "$1" = "shell" ] && [ "$2" = "bookieformat" ] && [ "$3" = "-nonInteractive" ] && [ "$4" = "-force" ] && [ "$5" = "-deleteCookie" ]; then
23-
echo "Bookie formatted with force and deleteCookie"
24-
return 0
25-
fi
26-
return 1
27-
}
28-
29-
When call format_bookie "true" "true"
30-
The output should include "Formatting Bookie..."
31-
The output should include "Bookie formatted with force and deleteCookie"
32-
The status should be success
33-
End
34-
35-
It "formats bookie without force and deleteCookie"
36-
bin/bookkeeper() {
37-
if [ "$1" = "shell" ] && [ "$2" = "bookieformat" ] && [ "$3" = "-nonInteractive" ]; then
38-
echo "Bookie formatted"
39-
return 0
40-
fi
41-
return 1
42-
}
43-
44-
When call format_bookie "false" "false"
45-
The output should include "Formatting Bookie..."
46-
The output should include "Bookie formatted"
47-
The status should be success
48-
End
49-
End
50-
51-
Describe "should_format_bookie()"
52-
It "returns true when pod index is greater than or equal to replicas"
53-
When call should_format_bookie "pod-3" "2"
54-
The status should be success
55-
End
56-
57-
It "returns false when pod index is less than replicas"
58-
When call should_format_bookie "pod-1" "2"
59-
The status should be failure
60-
End
61-
End
19+
bin/bookkeeper() {
20+
return 0
21+
}
6222

6323
Describe "bookies_member_leave()"
64-
setup() {
65-
export CURRENT_POD_NAME="pod-3"
66-
export BOOKKEEPER_COMP_REPLICAS="2"
67-
}
68-
6924
It "formats bookie when condition is met"
70-
setup
71-
72-
format_bookie() {
73-
echo "format_bookie called with $1 $2"
74-
}
25+
export CURRENT_POD_NAME="pod-3"
26+
export KB_LEAVE_MEMBER_POD_NAME="pod-3"
7527

7628
When call bookies_member_leave
77-
The output should include "format_bookie called with true true"
29+
The output should include "Formatting Bookie..."
30+
The output should include "Bookie formatted"
7831
End
7932

8033
It "skips formatting when condition is not met"
8134
export CURRENT_POD_NAME="pod-1"
82-
export BOOKKEEPER_COMP_REPLICAS="2"
35+
export KB_LEAVE_MEMBER_POD_NAME="pod-2"
8336

8437
When call bookies_member_leave
85-
The output should include "Skipping Bookie formatting"
38+
The output should include "Member to leave is not current pod, skipping Bookie formatting"
39+
The status should be failure
8640
End
8741
End
8842
End

addons/pulsar/scripts/bookies-member-leave.sh

Lines changed: 8 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,16 @@
11
#!/bin/bash
22

3-
format_bookie() {
4-
local force=$1
5-
local delete_cookie=$2
6-
7-
echo "Formatting Bookie..."
8-
if [[ $force == "true" && $delete_cookie == "true" ]]; then
9-
bin/bookkeeper shell bookieformat -nonInteractive -force -deleteCookie || true
10-
else
11-
bin/bookkeeper shell bookieformat -nonInteractive || true
12-
fi
13-
echo "Bookie formatted"
14-
}
15-
16-
# TODO: this logic should be refactored rather than judging by pod name index
17-
should_format_bookie() {
18-
local current_pod_name=$1
19-
local current_component_replicas=$2
20-
21-
local idx=${current_pod_name##*-}
22-
if [[ $idx -ge $current_component_replicas && $current_component_replicas -ne 0 ]]; then
23-
return 0
24-
else
3+
bookies_member_leave() {
4+
if [[ "$KB_LEAVE_MEMBER_POD_NAME" != "$CURRENT_POD_NAME" ]]; then
5+
echo "Member to leave is not current pod, skipping Bookie formatting"
256
return 1
267
fi
27-
}
28-
29-
bookies_member_leave() {
30-
# shellcheck disable=SC2153
31-
local current_pod_name=${CURRENT_POD_NAME}
32-
local current_component_replicas=${BOOKKEEPER_COMP_REPLICAS}
338

34-
if should_format_bookie "$current_pod_name" "$current_component_replicas"; then
35-
format_bookie "true" "true"
36-
else
37-
echo "Skipping Bookie formatting"
38-
fi
9+
# TODO: consider using decommissionbookie? But decommissionbookie needs bookie to stop first, kb doesn't support a "postMemberLeave" hook.
10+
echo "Formatting Bookie..."
11+
export BOOKIE_CONF=/opt/pulsar/conf/bookkeeper.conf
12+
bin/bookkeeper shell bookieformat -nonInteractive -force -deleteCookie
13+
echo "Bookie formatted"
3914
}
4015

4116
# This is magic for shellspec ut framework.

0 commit comments

Comments
 (0)