Skip to content

Commit 79d7537

Browse files
authored
K8SPSMDB-1064 improve getting of latest_restorable_time (#1499)
* K8SPSMDB-1055 improve getting of latest_restorable_time * add comment * fix misprint
1 parent 3ead3c4 commit 79d7537

File tree

1 file changed

+34
-9
lines changed

1 file changed

+34
-9
lines changed

e2e-tests/functions

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1449,29 +1449,54 @@ start_cluster() {
14491449

14501450
get_latest_restorable_time() {
14511451
local cluster=$1
1452-
local timestamp
1453-
local timeout
1452+
local first_timestamp
1453+
local second_timestamp
1454+
local retry=0
14541455

1455-
until [[ $timestamp != "" && $timestamp != "null" ]]; do
1456+
# "pbm-agent status" can return different timestamp in first few seconds
1457+
# we need to get it twice to be sure that timestamp was not changed
1458+
until [[ $first_timestamp != "" && $first_timestamp != "null" && $first_timestamp == $second_timestamp ]]; do
14561459
sleep 5
1457-
timestamp=$(kubectl exec "$cluster-0" -c backup-agent -- pbm status -o json | jq '.backups.pitrChunks.pitrChunks | last | .range.end')
1458-
timeout=$((timeout + 5))
1459-
if [[ $timeout -gt 30 ]]; then
1460+
if [[ $first_timestamp != "" && $first_timestamp != "null" ]]; then
1461+
second_timestamp=$(kubectl_bin exec "$cluster-0" -c backup-agent -- pbm status -o json | jq '.backups.pitrChunks.pitrChunks | last | .range.end')
1462+
else
1463+
first_timestamp=$(kubectl_bin exec "$cluster-0" -c backup-agent -- pbm status -o json | jq '.backups.pitrChunks.pitrChunks | last | .range.end')
1464+
fi
1465+
let retry+=1
1466+
if [[ $retry -gt 30 ]]; then
14601467
echo "Error: timeout waiting for timestamp"
14611468
exit 1
14621469
fi
14631470
done
14641471

1465-
$date -u -d @"$timestamp" "+%Y-%m-%dT%H:%M:%SZ"
1472+
$date -u -d @"$first_timestamp" "+%Y-%m-%dT%H:%M:%SZ"
14661473
}
14671474

1475+
get_latest_restorable_time_from_backup_object() {
1476+
local backup_name=$1
1477+
local latestRestorableTime
1478+
local retry=0
1479+
1480+
until [[ $latestRestorableTime != "" && $latestRestorableTime != "null" ]]; do
1481+
sleep 5
1482+
latestRestorableTime=$(kubectl_bin get psmdb-backup "$backup_name" -o jsonpath='{.status.latestRestorableTime}')
1483+
let retry+=1
1484+
if [[ $retry -gt 30 ]]; then
1485+
echo "Error: timeout waiting for latestRestorableTime"
1486+
exit 1
1487+
fi
1488+
done
1489+
1490+
echo "$latestRestorableTime"
1491+
}
14681492
compare_latest_restorable_time() {
14691493
local cluster=$1
14701494
local backup_name=$2
14711495
local latest_restorable_time
1472-
latest_restorable_time=$(get_latest_restorable_time "$cluster")
14731496
local backup_time
1474-
backup_time=$(kubectl get psmdb-backup "$backup_name" -o jsonpath='{.status.latestRestorableTime}')
1497+
1498+
latest_restorable_time=$(get_latest_restorable_time "$cluster")
1499+
backup_time=$(get_latest_restorable_time_from_backup_object "$backup_name")
14751500

14761501
if [[ $latest_restorable_time != "$backup_time" ]]; then
14771502
echo "Error: latestRestorableTime is not equal to the latest timestamp of the backup $backup_name: $latest_restorable_time != $backup_time"

0 commit comments

Comments
 (0)