store: Make the `add-to-store' cache per-connection.

* guix/store.scm (<nix-server>)[ats-cache]: New field.
  (open-connection): Update accordingly.
  (add-to-store/cached): Use (nix-server-add-to-store-cache SERVER)
  instead of a weak hash table.
This commit is contained in:
Ludovic Courtès 2013-01-29 23:34:50 +01:00
parent 2fbf053b7b
commit 2c3f47ee3a
1 changed files with 14 additions and 7 deletions

View File

@ -292,11 +292,17 @@
;; remote-store.cc ;; remote-store.cc
(define-record-type <nix-server> (define-record-type <nix-server>
(%make-nix-server socket major minor) (%make-nix-server socket major minor
ats-cache)
nix-server? nix-server?
(socket nix-server-socket) (socket nix-server-socket)
(major nix-server-major-version) (major nix-server-major-version)
(minor nix-server-minor-version)) (minor nix-server-minor-version)
;; Caches. We keep them per-connection, because store paths build
;; during the session are temporary GC roots kept for the duration of
;; the session.
(ats-cache nix-server-add-to-store-cache))
(define-condition-type &nix-error &error (define-condition-type &nix-error &error
nix-error?) nix-error?)
@ -333,7 +339,8 @@ operate, should the disk become full. Return a server object."
(write-int (if reserve-space? 1 0) s)) (write-int (if reserve-space? 1 0) s))
(let ((s (%make-nix-server s (let ((s (%make-nix-server s
(protocol-major v) (protocol-major v)
(protocol-minor v)))) (protocol-minor v)
(make-hash-table))))
(let loop ((done? (process-stderr s))) (let loop ((done? (process-stderr s)))
(or done? (process-stderr s))) (or done? (process-stderr s)))
s)))))))) s))))))))
@ -468,13 +475,13 @@ FIXED? is for backward compatibility with old Nix versions and must be #t."
;; A memoizing version of `add-to-store'. This is important because ;; A memoizing version of `add-to-store'. This is important because
;; `add-to-store' leads to huge data transfers to the server, and ;; `add-to-store' leads to huge data transfers to the server, and
;; because it's often called many times with the very same argument. ;; because it's often called many times with the very same argument.
(let ((add-to-store add-to-store) (let ((add-to-store add-to-store))
(cache (make-weak-value-hash-table 500)))
(lambda (server basename fixed? recursive? hash-algo file-name) (lambda (server basename fixed? recursive? hash-algo file-name)
"Add the contents of FILE-NAME under BASENAME to the store. Note that "Add the contents of FILE-NAME under BASENAME to the store. Note that
FIXED? is for backward compatibility with old Nix versions and must be #t." FIXED? is for backward compatibility with old Nix versions and must be #t."
(let* ((st (stat file-name #f)) (let* ((st (stat file-name #f))
(args `(,basename ,recursive? ,hash-algo ,st))) (args `(,basename ,recursive? ,hash-algo ,st))
(cache (nix-server-add-to-store-cache server)))
(or (and st (hash-ref cache args)) (or (and st (hash-ref cache args))
(let ((path (add-to-store server basename fixed? recursive? (let ((path (add-to-store server basename fixed? recursive?
hash-algo file-name))) hash-algo file-name)))