diff options
author | Florian Klink <flokli@flokli.de> | 2023-10-11T10·28+0200 |
---|---|---|
committer | flokli <flokli@flokli.de> | 2023-10-11T11·41+0000 |
commit | 98c17147c64f9898b656f56ab139d4d52248743e (patch) | |
tree | a7fefb1eb20353c78375282387ad32ebb36dfbc5 /tvix/nar-bridge/pkg/http/nar_get.go | |
parent | ceb1674e9f66bcbf382130bb195d367d269ddf86 (diff) |
refactor(tvix/nar-bridge): have Export return root node r/6780
… and nar size / sha256 digest. Instead of producing sparse PathInfo messages when NARs are sent to nar-bridge, the nar-bridge http server now keeps a lookup table (narsha256) -> (rootNode, narSize) This removes a whole bunch of noise, because we don't need to keep sparse fields around. A convenience function `GenPathInfo(rootNode *castorev1pb.Node, narInfo *narinfo.NarInfo)` is added, which is used to produce PathInfo messages, either when receiving a NAR file over http and uploading it to a remote PathInfoService, or to synthesize the PathInfoMessage to return to the client, if nar-bridge is acting as a PathInfoService for a remove Nix HTTP Binary cache. Change-Id: Ibba1ab6238a050816c4fab29cb21ae88877d8613 Reviewed-on: https://cl.tvl.fyi/c/depot/+/9651 Tested-by: BuildkiteCI Reviewed-by: Brian McGee <brian@bmcgee.ie>
Diffstat (limited to 'tvix/nar-bridge/pkg/http/nar_get.go')
-rw-r--r-- | tvix/nar-bridge/pkg/http/nar_get.go | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/tvix/nar-bridge/pkg/http/nar_get.go b/tvix/nar-bridge/pkg/http/nar_get.go index eecc59900784..a226c9da01eb 100644 --- a/tvix/nar-bridge/pkg/http/nar_get.go +++ b/tvix/nar-bridge/pkg/http/nar_get.go @@ -29,16 +29,18 @@ func renderNar( log *log.Entry, directoryServiceClient castorev1pb.DirectoryServiceClient, blobServiceClient castorev1pb.BlobServiceClient, - narHashToPathInfoMu *sync.Mutex, - narHashToPathInfo map[string]*storev1pb.PathInfo, + narHashDbMu *sync.Mutex, + narHashDb map[string]*narData, w io.Writer, narHash *nixhash.Hash, headOnly bool, ) error { // look in the lookup table - narHashToPathInfoMu.Lock() - pathInfo, found := narHashToPathInfo[narHash.SRIString()] - narHashToPathInfoMu.Unlock() + narHashDbMu.Lock() + narData, found := narHashDb[narHash.SRIString()] + narHashDbMu.Unlock() + + rootNode := narData.rootNode // if we didn't find anything, return 404. if !found { @@ -53,7 +55,7 @@ func renderNar( directories := make(map[string]*castorev1pb.Directory) // If the root node is a directory, ask the directory service for all directories - if pathInfoDirectory := pathInfo.GetNode().GetDirectory(); pathInfoDirectory != nil { + if pathInfoDirectory := rootNode.GetDirectory(); pathInfoDirectory != nil { rootDirectoryDigest := pathInfoDirectory.GetDigest() log = log.WithField("root_directory", base64.StdEncoding.EncodeToString(rootDirectoryDigest)) @@ -95,7 +97,7 @@ func renderNar( // render the NAR file err := storev1pb.Export( w, - pathInfo.Node, + rootNode, func(directoryDigest []byte) (*castorev1pb.Directory, error) { log.WithField("directory", base64.StdEncoding.EncodeToString(directoryDigest)).Debug("Get directory") directoryRefStr := hex.EncodeToString(directoryDigest) @@ -177,7 +179,7 @@ func registerNarGet(s *Server) { log := log.WithField("narhash_url", narHash.SRIString()) // TODO: inline more of that function here? - err = renderNar(ctx, log, s.directoryServiceClient, s.blobServiceClient, &s.narHashToPathInfoMu, s.narHashToPathInfo, w, narHash, isHead) + err = renderNar(ctx, log, s.directoryServiceClient, s.blobServiceClient, &s.narDbMu, s.narDb, w, narHash, isHead) if err != nil { if errors.Is(err, fs.ErrNotExist) { w.WriteHeader(http.StatusNotFound) |