db

package
v0.0.0-...-2fb23c1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 15, 2026 License: Apache-2.0 Imports: 46 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Factory

type Factory struct {
	DB    *gorm.DB
	SQLDB *sql.DB
	// contains filtered or unexported fields
}

func NewFactory

func NewFactory(schema *runtime.Scheme, dsn string) (*Factory, error)

func (*Factory) Check

func (f *Factory) Check(req *http.Request) error

func (*Factory) Close

func (f *Factory) Close()

Close releases the change listener's connection. The pool is shared with every strategy this factory built and is closed by Strategy.Destroy.

func (*Factory) Name

func (f *Factory) Name() string

func (*Factory) NewDBStrategy

func (f *Factory) NewDBStrategy(obj types.Object) (strategy.CompleteStrategy, error)

func (*Factory) Refresh

func (f *Factory) Refresh()

Refresh wakes every watch in this process so that each one lists again. Call it when the process is promoted to leader. As a standby its watches were waiting on notifications, and if a peer was not sending them, for instance during a rolling upgrade, the cache behind those watches can be up to a poll interval behind. A leader should not start acting on that. Without a listener there is nothing to do, because the watches are already on the short poll.

func (*Factory) Scheme

func (f *Factory) Scheme() *runtime.Scheme

type Listener

type Listener struct {
	// contains filtered or unexported fields
}

Listener carries change notifications between processes over a Postgres LISTEN/NOTIFY channel.

Every write announces its table on statements.NotifyChannel from inside the writing transaction. One connection per process listens on that channel and calls the broadcast function each Strategy registered, which is the same wake up the in process write path uses, so a process hears about another process's write as soon as it commits rather than at its next poll.

The connection cannot come from the database/sql pool, because a pooled connection cannot stay blocked waiting for a notification.

func NewListener

func NewListener(dsn string) *Listener

NewListener returns a listener for dsn. It does nothing until Start is called.

func (*Listener) Close

func (l *Listener) Close()

Close stops the listener and waits for its connection to be released.

func (*Listener) Connected

func (l *Listener) Connected() bool

Connected reports whether notifications are being delivered. When they are not, polling is a watch's only way to see another process's writes.

func (*Listener) Register

func (l *Listener) Register(table string, broadcast func()) func()

Register asks for broadcast to be called whenever another process writes to table. The returned function unregisters it.

func (*Listener) Start

func (l *Listener) Start()

Start opens the listening connection in the background and keeps it open until Close is called. It does not wait for the connection to come up, and calling it a second time does nothing.

type Strategy

type Strategy struct {
	// contains filtered or unexported fields
}

func New

func New(ctx context.Context, sqlDB *sql.DB, gvk schema.GroupVersionKind, scheme *runtime.Scheme, tableName string, postgres bool, listener *Listener) (*Strategy, error)

New builds the strategy for one table.

postgres selects the Postgres statements. It is passed in rather than inferred from the pool, because a Postgres pool may hold one connection and then looks like sqlite.

A non-nil listener makes writes to this table announce themselves to other processes and makes this process act on theirs. sqlite passes nil.

func (*Strategy) Create

func (s *Strategy) Create(ctx context.Context, object types.Object) (types.Object, error)

func (*Strategy) Delete

func (s *Strategy) Delete(ctx context.Context, obj types.Object) (types.Object, error)

func (*Strategy) Destroy

func (s *Strategy) Destroy()

func (*Strategy) Get

func (s *Strategy) Get(ctx context.Context, namespace, name string) (types.Object, error)

func (*Strategy) List

func (s *Strategy) List(ctx context.Context, namespace string, opts storage.ListOptions) (types.ObjectList, error)

func (*Strategy) New

func (s *Strategy) New() types.Object

func (*Strategy) NewList

func (s *Strategy) NewList() types.ObjectList

func (*Strategy) Scheme

func (s *Strategy) Scheme() *runtime.Scheme

func (*Strategy) Update

func (s *Strategy) Update(ctx context.Context, obj types.Object) (types.Object, error)

func (*Strategy) UpdateStatus

func (s *Strategy) UpdateStatus(ctx context.Context, obj types.Object) (types.Object, error)

func (*Strategy) Watch

func (s *Strategy) Watch(ctx context.Context, namespace string, opts storage.ListOptions) (<-chan watch.Event, error)

type TableNamer

type TableNamer interface {
	TableName() string
}

Directories

Path Synopsis
Package glogrus provides a gorm logger that wraps a logrus.Logger.
Package glogrus provides a gorm logger that wraps a logrus.Logger.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL