Skip to content

Commit

Permalink
Add hash of the offloaded value for caching
Browse files Browse the repository at this point in the history
Signed-off-by: pmahindrakar-oss <[email protected]>
  • Loading branch information
pmahindrakar-oss committed Sep 26, 2024
1 parent 7c96c60 commit d96bd3e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ func (m *CatalogClient) createArtifact(ctx context.Context, key catalog.Key, dat
createArtifactRequest := &datacatalog.CreateArtifactRequest{Artifact: cachedArtifact}
_, err := m.client.CreateArtifact(ctx, createArtifactRequest)
if err != nil {
logger.Errorf(ctx, "Failed to create Artifact %+v, err: %v", cachedArtifact, err)
logger.Errorf(ctx, "Failed to create Artifact %+v, err: %v", cachedArtifact.Id, err)
return catalog.Status{}, err
}
logger.Debugf(ctx, "Created artifact: %v, with %v outputs from execution %+v", cachedArtifact.Id, len(artifactDataList), metadata)
Expand Down
13 changes: 13 additions & 0 deletions flytepropeller/pkg/controller/nodes/common/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package common

import (
"context"
"encoding/base64"
"fmt"

"strconv"

"github.com/golang/protobuf/proto"
Expand All @@ -17,6 +19,7 @@ import (
"github.com/flyteorg/flyte/flytepropeller/pkg/controller/nodes/handler"
"github.com/flyteorg/flyte/flytepropeller/pkg/controller/nodes/interfaces"
"github.com/flyteorg/flyte/flytestdlib/logger"
"github.com/flyteorg/flyte/flytestdlib/pbhash"
"github.com/flyteorg/flyte/flytestdlib/storage"
)

Expand Down Expand Up @@ -125,6 +128,12 @@ 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
}

// update the literal with the offloaded URI, size and inferred type
toBeOffloaded.Value = &idlcore.Literal_OffloadedMetadata{
Expand All @@ -134,6 +143,10 @@ 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
}
Expand Down

0 comments on commit d96bd3e

Please sign in to comment.