Fix 2.4.2 upgrade notes formatting refs #19330
[arvados.git] / lib / controller / localdb / conn.go
index 86e3f371486ebce0cd5126a7dd12744ed4b23f5e..a36822ad6b1f5df1f73ffbc3536d76a7215f1817 100644 (file)
@@ -11,6 +11,7 @@ import (
        "net/http"
        "os"
        "strings"
+       "sync"
        "time"
 
        "git.arvados.org/arvados.git/lib/controller/railsproxy"
@@ -18,6 +19,8 @@ import (
        "git.arvados.org/arvados.git/sdk/go/arvados"
        "git.arvados.org/arvados.git/sdk/go/ctxlog"
        "git.arvados.org/arvados.git/sdk/go/httpserver"
+       "github.com/hashicorp/yamux"
+       "github.com/sirupsen/logrus"
 )
 
 type railsProxy = rpc.Conn
@@ -30,6 +33,8 @@ type Conn struct {
        lastVocabularyRefreshCheck time.Time
        lastVocabularyError        error
        loginController
+       gwTunnels     map[string]*yamux.Session
+       gwTunnelsLock sync.Mutex
 }
 
 func NewConn(cluster *arvados.Cluster) *Conn {
@@ -70,7 +75,7 @@ func (conn *Conn) checkProperties(ctx context.Context, properties interface{}) e
        return nil
 }
 
-func (conn *Conn) maybeRefreshVocabularyCache() error {
+func (conn *Conn) maybeRefreshVocabularyCache(logger logrus.FieldLogger) error {
        if conn.lastVocabularyRefreshCheck.Add(time.Second).After(time.Now()) {
                // Throttle the access to disk to at most once per second.
                return nil
@@ -90,6 +95,7 @@ func (conn *Conn) maybeRefreshVocabularyCache() error {
                }
                conn.vocabularyFileModTime = fi.ModTime()
                conn.lastVocabularyError = nil
+               logger.Info("vocabulary file reloaded successfully")
        }
        return nil
 }
@@ -97,7 +103,7 @@ func (conn *Conn) maybeRefreshVocabularyCache() error {
 func (conn *Conn) loadVocabularyFile() error {
        vf, err := os.ReadFile(conn.cluster.API.VocabularyPath)
        if err != nil {
-               return fmt.Errorf("couldn't reading the vocabulary file: %v", err)
+               return fmt.Errorf("while reading the vocabulary file: %v", err)
        }
        mk := make([]string, 0, len(conn.cluster.Collections.ManagedProperties))
        for k := range conn.cluster.Collections.ManagedProperties {
@@ -113,8 +119,9 @@ func (conn *Conn) loadVocabularyFile() error {
 
 // LastVocabularyError returns the last error encountered while loading the
 // vocabulary file.
+// Implements health.Func
 func (conn *Conn) LastVocabularyError() error {
-       conn.maybeRefreshVocabularyCache()
+       conn.maybeRefreshVocabularyCache(ctxlog.FromContext(context.Background()))
        return conn.lastVocabularyError
 }
 
@@ -134,11 +141,9 @@ func (conn *Conn) VocabularyGet(ctx context.Context) (arvados.Vocabulary, error)
                        return arvados.Vocabulary{}, err
                }
        }
-       err := conn.maybeRefreshVocabularyCache()
+       err := conn.maybeRefreshVocabularyCache(logger)
        if err != nil {
                logger.WithError(err).Error("error reloading vocabulary file - ignoring")
-       } else {
-               logger.Info("vocabulary file reloaded successfully")
        }
        return *conn.vocabularyCache, nil
 }