From 9edd5f9824451a03d51b68b701296b303102d95a Mon Sep 17 00:00:00 2001 From: pmahindrakar-oss Date: Fri, 27 Sep 2024 14:21:02 -0700 Subject: [PATCH] review comments Signed-off-by: pmahindrakar-oss --- .../pkg/controller/nodes/common/utils.go | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/flytepropeller/pkg/controller/nodes/common/utils.go b/flytepropeller/pkg/controller/nodes/common/utils.go index 14ea44e24b..dd16b53f3a 100644 --- a/flytepropeller/pkg/controller/nodes/common/utils.go +++ b/flytepropeller/pkg/controller/nodes/common/utils.go @@ -87,8 +87,11 @@ func ReadLargeLiteral(ctx context.Context, datastore *storage.DataStore, if tobeRead.GetOffloadedMetadata() == nil { return fmt.Errorf("unsupported type for reading offloaded literal") } - // read the offloaded literal dataReference := tobeRead.GetOffloadedMetadata().GetUri() + if dataReference == "" { + return fmt.Errorf("uri is empty for offloaded literal") + } + // read the offloaded literal size := tobeRead.GetOffloadedMetadata().GetSizeBytes() if err := datastore.ReadProtobuf(ctx, storage.DataReference(dataReference), tobeRead); err != nil { logger.Errorf(ctx, "Failed to read the offloaded literal at location [%s] with error [%s]", dataReference, err) @@ -127,13 +130,17 @@ func OffloadLargeLiteral(ctx context.Context, datastore *storage.DataStore, data logger.Errorf(ctx, "Failed to offload literal at location [%s] with error [%s]", dataReference, err) return err } - // compute the hash of the literal - literalDigest, err := pbhash.ComputeHash(ctx, toBeOffloaded) - if err != nil { - logger.Errorf(ctx, "Failed to compute hash for offloaded literal with error [%s]", err) - return err - } + if toBeOffloaded.GetHash() == "" { + // compute the hash of the literal + literalDigest, err := pbhash.ComputeHash(ctx, toBeOffloaded) + if err != nil { + logger.Errorf(ctx, "Failed to compute hash for offloaded literal with error [%s]", err) + return err + } + // Set the hash or else respect what the user set in the literal + toBeOffloaded.Hash = base64.RawURLEncoding.EncodeToString(literalDigest) + } // update the literal with the offloaded URI, size and inferred type toBeOffloaded.Value = &idlcore.Literal_OffloadedMetadata{ OffloadedMetadata: &idlcore.LiteralOffloadedMetadata{ @@ -142,10 +149,6 @@ func OffloadLargeLiteral(ctx context.Context, datastore *storage.DataStore, data InferredType: inferredType, }, } - if toBeOffloaded.GetHash() == "" { - // Set the hash or else respect what the user set in the literal - toBeOffloaded.Hash = base64.RawURLEncoding.EncodeToString(literalDigest) - } logger.Infof(ctx, "Offloaded literal at location [%s] with size [%d] MB and inferred type [%s]", dataReference, literalSizeMB, inferredType) return nil }