MCPcopy Create free account
hub / github.com/PostHog/duckgres / acquireFileDB

Method acquireFileDB

server/server.go:777–809  ·  view source on GitHub ↗

acquireFileDB returns a shared *sql.DB for the given user, creating one if needed. The caller must call releaseFileDB when the connection is no longer needed.

(username string, passthrough bool)

Source from the content-addressed store, hash-verified

775}
776
777// initConnsMap initializes the connection registry map.
778// This is a separate method to work around cases where a local variable
779// named "clientConn" shadows the type name (e.g., in worker.go).
780func (s *Server) initConnsMap() {
781 s.conns = make(map[int32]*clientConn)
782 if s.recentErrors == nil {
783 s.recentErrors = newRecentErrorRing(0)
784 }
785}
786
787// registerConn adds a client connection to the registry for pg_stat_activity.
788func (s *Server) registerConn(c *clientConn) {
789 s.connsMu.Lock()
790 s.conns[c.pid] = c
791 s.connsMu.Unlock()
792}
793
794// unregisterConn removes a client connection from the registry.
795func (s *Server) unregisterConn(pid int32) {
796 s.connsMu.Lock()
797 delete(s.conns, pid)
798 s.connsMu.Unlock()
799}
800
801// DrainOrgConnections requests a clean close of every PostgreSQL connection
802// for orgID at its next idle protocol boundary. Connections already blocked
803// waiting for client input are woken immediately; executing queries are not
804// cancelled and close after their next ReadyForQuery.
805func (s *Server) DrainOrgConnections(orgID string) int {
806 return s.drainConnections(func(c *clientConn) bool {
807 return c.orgID == orgID
808 })
809}
810
811// DrainUserConnections requests a clean close of every PostgreSQL connection
812// for one org user. It is used when a project reader's credentials or access

Callers 2

serveMethod · 0.80

Calls 3

CreateDBConnectionFunction · 0.85
StartCredentialRefreshFunction · 0.85

Tested by 1