Skip to content

Commit 710cf4f

Browse files
authored
chore: mongodb restore failure (#2294)
1 parent 98a2939 commit 710cf4f

16 files changed

+74
-37
lines changed

addons/mongodb/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: MongoDB is a document database designed for ease of application dev
44

55
type: application
66

7-
version: 0.9.5
7+
version: 0.9.6
88

99
appVersion: "5.0"
1010

addons/mongodb/dataprotection/common-scripts.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,8 @@ storage:
227227
credentials:
228228
access-key-id: ${S3_ACCESS_KEY}
229229
secret-access-key: ${S3_SECRET_KEY}
230+
restore:
231+
numDownloadWorkers: ${PBM_RESTORE_DOWNLOAD_WORKERS:-4}
230232
EOF
231233
echo "INFO: PBM storage configuration completed."
232234
fi

addons/mongodb/dataprotection/rs-pbm-full-restore.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,12 @@ while [ $attempt -le $MAX_RETRIES ]; do
5353
continue
5454
else
5555
echo "ERROR: Failed to get backup metadata: $describe_result"
56+
exit 1
5657
fi
5758
done
5859
set -e
5960

60-
if [ -z "$describe_result" ]; then
61+
if [ -z "$describe_result" ] || echo "$describe_result" | grep -q "not found"; then
6162
echo "ERROR: Failed to get backup metadata after $MAX_RETRIES attempts"
6263
exit 1
6364
fi

addons/mongodb/dataprotection/shard-pbm-full-restore.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,12 @@ while [ $attempt -le $MAX_RETRIES ]; do
5353
continue
5454
else
5555
echo "ERROR: Failed to get backup metadata: $describe_result"
56+
exit 1
5657
fi
5758
done
5859
set -e
5960

60-
if [ -z "$describe_result" ]; then
61+
if [ -z "$describe_result" ] || echo "$describe_result" | grep -q "not found"; then
6162
echo "ERROR: Failed to get backup metadata after $MAX_RETRIES attempts"
6263
exit 1
6364
fi

addons/mongodb/scripts/mongodb-common.sh

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ function wait_restore_completion_by_cluster_cr() {
55
local max_retries=$1
66
local wait_interval=5
77
local retries=0
8+
local state=0
89

910
while true; do
1011
cluster_json=$(kubectl get clusters.apps.kubeblocks.io "${KB_CLUSTER_NAME}" -n "${KB_NAMESPACE}" -o json 2>&1)
@@ -25,7 +26,10 @@ function wait_restore_completion_by_cluster_cr() {
2526
echo "INFO: No restore-from-backup annotation, do not need to restore."
2627
return 0
2728
else
28-
echo "INFO: Waiting for restore completion..."
29+
if [[ "$state" != "1" ]]; then
30+
echo "INFO: Waiting for restore completion..."
31+
state=1
32+
fi
2933
sleep $wait_interval
3034
((retries++))
3135
if [[ -n "$max_retries" && "$retries" -ge "$max_retries" ]]; then
@@ -53,16 +57,25 @@ function process_restore_signal() {
5357
local process="$1"
5458
local target_signal="$2"
5559
local pbm_backupfile=$MONGODB_ROOT/tmp/mongodb_pbm.backup
60+
local last_annotation_value=""
61+
local last_state="0"
5662
restore_signal_cm_name="$KB_CLUSTER_NAME-restore-signal"
5763
restore_signal_cm_namespace="$KB_NAMESPACE"
5864
while true; do
5965
kubectl_get_result=$(kubectl get configmap $restore_signal_cm_name -n $restore_signal_cm_namespace -o json 2>&1)
6066
kubectl_get_exit_code=$?
6167
if [ "$kubectl_get_exit_code" -ne 0 ]; then
62-
echo "INFO: Waiting for restore signal..."
68+
if [[ "$last_state" != "1" ]]; then
69+
echo "INFO: Waiting for restore signal..."
70+
last_state="1"
71+
fi
6372
else
73+
last_state="0"
6474
annotation_value=$(echo "$kubectl_get_result" | jq -r '.metadata.labels["apps.kubeblocks.io/restore-mongodb-shard"] // empty')
65-
echo "INFO: Restore signal is $annotation_value."
75+
if [[ "$annotation_value" != "$last_annotation_value" ]]; then
76+
echo "INFO: Restore signal is $annotation_value."
77+
last_annotation_value="$annotation_value"
78+
fi
6679
if [[ "$annotation_value" == "start" ]]; then
6780
if [[ "$target_signal" == "start" ]]; then
6881
echo "INFO: Restore $annotation_value signal received, starting restore..."

addons/mongodb/scripts/mongodb-shard-setup.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ process="mongod --bind_ip_all --port $PORT --replSet $KB_CLUSTER_COMP_NAME --con
2424
boot_or_enter_restore "$process"
2525

2626
echo "INFO: Startup backup agent for restore."
27-
pbm-agent-entrypoint &
27+
pbm-agent-entrypoint >> $MONGODB_ROOT/tmp/pbm_agent_restore.log 2>&1 &
2828

2929
echo "INFO: Start mongodb for restore."
3030
$process &

addons/mongodb/scripts/replicaset-setup.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ then
5151
fi
5252

5353
echo "INFO: Startup backup agent for restore."
54-
pbm-agent-entrypoint &
54+
pbm-agent-entrypoint >> $MONGODB_ROOT/tmp/pbm_agent_restore.log 2>&1 &
5555

5656
echo "INFO: Start mongodb for restore."
5757
$process &

addons/mongodb/templates/actionset-rs-pbm-physical.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ spec:
1616
- name: PBM_BACKUP_TYPE
1717
value: physical
1818
- name: PBM_COMPRESSION
19-
value: zstd
19+
value: s2 # for big data, use s2 compression to reduce memory usage during restoration
20+
- name: PBM_RESTORE_DOWNLOAD_WORKERS
21+
value: "4"
2022
- name: PBM_IMAGE_TAG
2123
value: {{ .Values.image.percona.backup.tag }}
2224
- name: PSM_IMAGE_TAG

addons/mongodb/templates/actionset-rs-pbm-pitr.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ spec:
1919
- name: PBM_OPLOG_SPAN_MIN_MINUTES
2020
value: "5"
2121
- name: PBM_COMPRESSION
22-
value: zstd
22+
value: s2 # for big data, use s2 compression to reduce memory usage during restoration
23+
- name: PBM_RESTORE_DOWNLOAD_WORKERS
24+
value: "4"
2325
- name: PBM_PURGE_INTERVAL_SECONDS
2426
value: "86400"
2527
- name: PBM_BACKUP_TYPE

addons/mongodb/templates/actionset-shard-pbm-logical.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ spec:
1616
- name: PBM_BACKUP_TYPE
1717
value: logical
1818
- name: PBM_COMPRESSION
19-
value: zstd
19+
value: s2 # for big data, use s2 compression to reduce memory usage during restoration
20+
- name: PBM_RESTORE_DOWNLOAD_WORKERS
21+
value: "4"
2022
- name: PBM_IMAGE_TAG
2123
value: {{ .Values.image.percona.backup.tag }}
2224
- name: PSM_IMAGE_TAG

0 commit comments

Comments
 (0)