projects
/
arvados.git
/ blobdiff
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
16263: Rename no_federation -> bypass_federation
[arvados.git]
/
services
/
ws
/
event_source.go
diff --git
a/services/ws/event_source.go
b/services/ws/event_source.go
index 1cc5ae75fee296874ec3893d834e069896adf07d..3a82bf62b3e9351a95d2abe4c56ae942fededa4c 100644
(file)
--- a/
services/ws/event_source.go
+++ b/
services/ws/event_source.go
@@
-1,33
+1,23
@@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
package main
import (
"context"
"database/sql"
package main
import (
"context"
"database/sql"
+ "errors"
+ "fmt"
"strconv"
"strconv"
- "strings"
"sync"
"sync/atomic"
"time"
"sync"
"sync/atomic"
"time"
- "git.
curoverse.com
/arvados.git/sdk/go/stats"
+ "git.
arvados.org
/arvados.git/sdk/go/stats"
"github.com/lib/pq"
)
"github.com/lib/pq"
)
-type pgConfig map[string]string
-
-func (c pgConfig) ConnectionString() string {
- s := ""
- for k, v := range c {
- s += k
- s += "='"
- s += strings.Replace(
- strings.Replace(v, `\`, `\\`, -1),
- `'`, `\'`, -1)
- s += "' "
- }
- return s
-}
-
type pgEventSource struct {
DataSource string
MaxOpenConns int
type pgEventSource struct {
DataSource string
MaxOpenConns int
@@
-116,6
+106,9
@@
func (ps *pgEventSource) Run() {
logger(nil).WithError(err).Error("sql.Open failed")
return
}
logger(nil).WithError(err).Error("sql.Open failed")
return
}
+ if ps.MaxOpenConns <= 0 {
+ logger(nil).Warn("no database connection limit configured -- consider setting PostgresPool>0 in arvados-ws configuration file")
+ }
db.SetMaxOpenConns(ps.MaxOpenConns)
if err = db.Ping(); err != nil {
logger(nil).WithError(err).Error("db.Ping failed")
db.SetMaxOpenConns(ps.MaxOpenConns)
if err = db.Ping(); err != nil {
logger(nil).WithError(err).Error("db.Ping failed")
@@
-175,11
+168,15
@@
func (ps *pgEventSource) Run() {
case <-ticker.C:
logger(nil).Debug("listener ping")
case <-ticker.C:
logger(nil).Debug("listener ping")
- ps.pqListener.Ping()
+ err := ps.pqListener.Ping()
+ if err != nil {
+ ps.listenerProblem(-1, fmt.Errorf("pqListener ping failed: %s", err))
+ continue
+ }
case pqEvent, ok := <-ps.pqListener.Notify:
if !ok {
case pqEvent, ok := <-ps.pqListener.Notify:
if !ok {
- logger(nil).
Debug
("pqListener Notify chan closed")
+ logger(nil).
Error
("pqListener Notify chan closed")
return
}
if pqEvent == nil {
return
}
if pqEvent == nil {
@@
-187,7
+184,7
@@
func (ps *pgEventSource) Run() {
// itself in addition to sending us a
// nil event, so this might be
// superfluous:
// itself in addition to sending us a
// nil event, so this might be
// superfluous:
- ps.listenerProblem(-1,
nil
)
+ ps.listenerProblem(-1,
errors.New("pqListener Notify chan received nil event")
)
continue
}
if pqEvent.Channel != "logs" {
continue
}
if pqEvent.Channel != "logs" {
@@
-236,9
+233,17
@@
func (ps *pgEventSource) NewSink() eventSink {
}
func (ps *pgEventSource) DB() *sql.DB {
}
func (ps *pgEventSource) DB() *sql.DB {
+ ps.WaitReady()
return ps.db
}
return ps.db
}
+func (ps *pgEventSource) DBHealth() error {
+ ctx, cancel := context.WithDeadline(context.Background(), time.Now().Add(time.Second))
+ defer cancel()
+ var i int
+ return ps.db.QueryRowContext(ctx, "SELECT 1").Scan(&i)
+}
+
func (ps *pgEventSource) DebugStatus() interface{} {
ps.mtx.Lock()
defer ps.mtx.Unlock()
func (ps *pgEventSource) DebugStatus() interface{} {
ps.mtx.Lock()
defer ps.mtx.Unlock()
@@
-254,6
+259,7
@@
func (ps *pgEventSource) DebugStatus() interface{} {
"QueueDelay": stats.Duration(ps.lastQDelay),
"Sinks": len(ps.sinks),
"SinksBlocked": blocked,
"QueueDelay": stats.Duration(ps.lastQDelay),
"Sinks": len(ps.sinks),
"SinksBlocked": blocked,
+ "DBStats": ps.db.Stats(),
}
}
}
}
@@
-272,7
+278,7
@@
func (sink *pgEventSink) Stop() {
// Ensure this sink cannot fill up and block the
// server-side queue (which otherwise could in turn
// block our mtx.Lock() here)
// Ensure this sink cannot fill up and block the
// server-side queue (which otherwise could in turn
// block our mtx.Lock() here)
- for
_ =
range sink.channel {
+ for range sink.channel {
}
}()
sink.source.mtx.Lock()
}
}()
sink.source.mtx.Lock()