Fix interval tree unused node markers.
[lightning.git] / arvados.go
index 6d76aded264124ff33d6bee7c24ef39346325145..e2932a00d20c1f62ae125c484ec5137b5e10b324 100644 (file)
@@ -1,3 +1,7 @@
+// Copyright (C) The Lightning Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
 package lightning
 
 import (
@@ -264,9 +268,12 @@ func (runner *arvadosContainerRunner) RunContext(ctx context.Context) (string, e
                        "priority":            runner.Priority,
                        "state":               arvados.ContainerRequestStateCommitted,
                        "scheduling_parameters": arvados.SchedulingParameters{
-                               Preemptible: true,
+                               Preemptible: false,
                                Partitions:  []string{},
                        },
+                       "environment": map[string]string{
+                               "GOMAXPROCS": fmt.Sprintf("%d", rc.VCPUs),
+                       },
                },
        })
        if err != nil {
@@ -385,16 +392,20 @@ func (runner *arvadosContainerRunner) TranslatePaths(paths ...*string) error {
                if m == nil {
                        return fmt.Errorf("cannot find uuid in path: %q", *path)
                }
-               uuid := m[2]
-               mnt, ok := runner.Mounts["/mnt/"+uuid]
+               collID := m[2]
+               mnt, ok := runner.Mounts["/mnt/"+collID]
                if !ok {
                        mnt = map[string]interface{}{
                                "kind": "collection",
-                               "uuid": uuid,
                        }
-                       runner.Mounts["/mnt/"+uuid] = mnt
+                       if len(collID) == 27 {
+                               mnt["uuid"] = collID
+                       } else {
+                               mnt["portable_data_hash"] = collID
+                       }
+                       runner.Mounts["/mnt/"+collID] = mnt
                }
-               *path = "/mnt/" + uuid + m[3]
+               *path = "/mnt/" + collID + m[3]
        }
        return nil
 }
@@ -511,7 +522,13 @@ var (
        siteFSMtx            sync.Mutex
 )
 
-func open(fnm string) (io.ReadCloser, error) {
+type file interface {
+       io.ReadCloser
+       io.Seeker
+       Readdir(n int) ([]os.FileInfo, error)
+}
+
+func open(fnm string) (file, error) {
        if os.Getenv("ARVADOS_API_HOST") == "" {
                return os.Open(fnm)
        }
@@ -519,11 +536,8 @@ func open(fnm string) (io.ReadCloser, error) {
        if m == nil {
                return os.Open(fnm)
        }
-       uuid := m[2]
-       mnt := "/mnt/" + uuid + "/"
-       if !strings.HasPrefix(fnm, mnt) {
-               return os.Open(fnm)
-       }
+       collectionUUID := m[2]
+       collectionPath := m[3]
 
        siteFSMtx.Lock()
        defer siteFSMtx.Unlock()
@@ -540,9 +554,23 @@ func open(fnm string) (io.ReadCloser, error) {
                keepClient.BlockCache = &keepclient.BlockCache{MaxBlocks: 4}
                siteFS = arvadosClientFromEnv.SiteFileSystem(keepClient)
        } else {
-               keepClient.BlockCache.MaxBlocks++
+               keepClient.BlockCache.MaxBlocks += 2
        }
 
-       log.Infof("reading %q from %s using Arvados client", fnm[len(mnt):], uuid)
-       return siteFS.Open("by_id/" + uuid + "/" + fnm[len(mnt):])
+       log.Infof("reading %q from %s using Arvados client", collectionPath, collectionUUID)
+       f, err := siteFS.Open("by_id/" + collectionUUID + collectionPath)
+       if err != nil {
+               return nil, err
+       }
+       return &reduceCacheOnClose{file: f}, nil
+}
+
+type reduceCacheOnClose struct {
+       file
+       once sync.Once
+}
+
+func (rc *reduceCacheOnClose) Close() error {
+       rc.once.Do(func() { keepClient.BlockCache.MaxBlocks -= 2 })
+       return rc.file.Close()
 }