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 <madhupr007@gmail.com>
This commit is contained in:
Madhu Rajanna 2022-11-01 16:02:18 +01:00 committed by mergify[bot]
parent 3cce629b1d
commit 3e1f60244e

View File

@ -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)