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/server.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/server.go')
-rw-r--r-- | tvix/nar-bridge/pkg/http/server.go | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/tvix/nar-bridge/pkg/http/server.go b/tvix/nar-bridge/pkg/http/server.go index e8eb229ab41a..aa8037e2ba38 100644 --- a/tvix/nar-bridge/pkg/http/server.go +++ b/tvix/nar-bridge/pkg/http/server.go @@ -25,11 +25,17 @@ type Server struct { // When uploading NAR files to a HTTP binary cache, the .nar // files are uploaded before the .narinfo files. // We need *both* to be able to fully construct a PathInfo object. - // Keep a in-memory map of narhash(es) (in SRI) to sparse PathInfo. + // Keep a in-memory map of narhash(es) (in SRI) to (unnamed) root node and nar + // size. // This is necessary until we can ask a PathInfoService for a node with a given // narSha256. - narHashToPathInfoMu sync.Mutex - narHashToPathInfo map[string]*storev1pb.PathInfo + narDbMu sync.Mutex + narDb map[string]*narData +} + +type narData struct { + rootNode *castorev1pb.Node + narSize uint64 } func New( @@ -64,7 +70,7 @@ func New( directoryServiceClient: directoryServiceClient, blobServiceClient: blobServiceClient, pathInfoServiceClient: pathInfoServiceClient, - narHashToPathInfo: make(map[string]*storev1pb.PathInfo), + narDb: make(map[string]*narData), } registerNarPut(s) |