refactor(tvix/nar-bridge): have Export return root node
… 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>
This commit is contained in:
parent
ceb1674e9f
commit
98c17147c6
10 changed files with 211 additions and 297 deletions
|
|
@ -29,7 +29,7 @@ func renderNarinfo(
|
|||
log *log.Entry,
|
||||
pathInfoServiceClient storev1pb.PathInfoServiceClient,
|
||||
narHashToPathInfoMu *sync.Mutex,
|
||||
narHashToPathInfo map[string]*storev1pb.PathInfo,
|
||||
narHashToPathInfo map[string]*narData,
|
||||
outputHash []byte,
|
||||
w io.Writer,
|
||||
headOnly bool,
|
||||
|
|
@ -51,6 +51,7 @@ func renderNarinfo(
|
|||
return fmt.Errorf("unable to get pathinfo: %w", err)
|
||||
}
|
||||
|
||||
// TODO: don't parse
|
||||
narHash, err := nixhash.ParseNixBase32("sha256:" + nixbase32.EncodeToString(pathInfo.GetNarinfo().GetNarSha256()))
|
||||
if err != nil {
|
||||
// TODO: return proper error
|
||||
|
|
@ -59,7 +60,10 @@ func renderNarinfo(
|
|||
|
||||
// add things to the lookup table, in case the same process didn't handle the NAR hash yet.
|
||||
narHashToPathInfoMu.Lock()
|
||||
narHashToPathInfo[narHash.SRIString()] = pathInfo
|
||||
narHashToPathInfo[narHash.SRIString()] = &narData{
|
||||
rootNode: pathInfo.GetNode(),
|
||||
narSize: pathInfo.GetNarinfo().GetNarSize(),
|
||||
}
|
||||
narHashToPathInfoMu.Unlock()
|
||||
|
||||
if headOnly {
|
||||
|
|
@ -102,7 +106,7 @@ func registerNarinfoGet(s *Server) {
|
|||
return
|
||||
}
|
||||
|
||||
err = renderNarinfo(ctx, log, s.pathInfoServiceClient, &s.narHashToPathInfoMu, s.narHashToPathInfo, outputHash, w, false)
|
||||
err = renderNarinfo(ctx, log, s.pathInfoServiceClient, &s.narDbMu, s.narDb, outputHash, w, false)
|
||||
if err != nil {
|
||||
if errors.Is(err, fs.ErrNotExist) {
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue