From 3e1f60244e47d8714e6a5b0c9ef8271dc2b3c20f Mon Sep 17 00:00:00 2001 From: Madhu Rajanna Date: Tue, 1 Nov 2022 16:02:18 +0100 Subject: [PATCH] rbd: check for empty lastSyncTime Sometime the json unmarshal might get success and return empty time stamp. add a check to make sure the time is not zero always. Signed-off-by: Madhu Rajanna --- internal/rbd/replicationcontrollerserver.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/internal/rbd/replicationcontrollerserver.go b/internal/rbd/replicationcontrollerserver.go index 7c63faa72..83d516633 100644 --- a/internal/rbd/replicationcontrollerserver.go +++ b/internal/rbd/replicationcontrollerserver.go @@ -828,6 +828,12 @@ func getLastSyncTime(description string) (*timestamppb.Timestamp, error) { return nil, fmt.Errorf("failed to unmarshal description: %w", err) } + // If the json unmarsal is successful but the local snapshot time is 0, we + // need to consider it as an error as the LastSyncTime is required. + if localSnapTime.LocalSnapshotTime == 0 { + return nil, fmt.Errorf("empty local snapshot timestamp: %w", ErrLastSyncTimeNotFound) + } + lastUpdateTime := time.Unix(localSnapTime.LocalSnapshotTime, 0) lastSyncTime := timestamppb.New(lastUpdateTime)