Documentation ¶
Overview ¶
Package postgres is an implementation of a routes and neighbors store using the postgres database.
Routes and neighbors are stored as jsonb information with indexes for query performance.
Index ¶
- Constants
- Variables
- func Connect(ctx context.Context, opts *config.PostgresConfig) (*pgxpool.Pool, error)
- type Manager
- type NeighborsBackend
- func (b *NeighborsBackend) CountNeighborsAt(ctx context.Context, sourceID string) (int, error)
- func (b *NeighborsBackend) GetNeighborsAt(ctx context.Context, sourceID string) (api.Neighbors, error)
- func (b *NeighborsBackend) GetNeighborsMapAt(ctx context.Context, sourceID string) (map[string]*api.Neighbor, error)
- func (b *NeighborsBackend) SetNeighbors(ctx context.Context, sourceID string, neighbors api.Neighbors) error
- type RoutesBackend
- func (b *RoutesBackend) CountRoutesAt(ctx context.Context, sourceID string) (uint, uint, error)
- func (b *RoutesBackend) FindByNeighbors(ctx context.Context, neighbors []*api.NeighborQuery, ...) (api.LookupRoutes, error)
- func (b *RoutesBackend) FindByPrefix(ctx context.Context, prefix string, filters *api.SearchFilters, limit uint) (api.LookupRoutes, error)
- func (b *RoutesBackend) Init(ctx context.Context) error
- func (b *RoutesBackend) SetRoutes(ctx context.Context, sourceID string, routes api.LookupRoutes) error
- type Status
Constants ¶
const CurrentSchemaVersion = 1
CurrentSchemaVersion is the current version of the schema
Variables ¶
var ( // ErrMaxConnsUnconfigured will be returned, if the // the maximum connections are zero. ErrMaxConnsUnconfigured = errors.New("max connections not configured") )
var ( // ReMatchNonChar will match on all characters not // within a to Z or 0 to 9 ReMatchNonChar = regexp.MustCompile(`[^a-zA-Z0-9]`) )
Functions ¶
Types ¶
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
The Manager supervises the database. It can migrate the schema and retrieve a status.
func NewManager ¶
NewManager creates a new database manager
func (*Manager) Initialize ¶
Initialize will apply the database schema. This will clear the database. However for now we treat the state as disposable.
type NeighborsBackend ¶
type NeighborsBackend struct {
// contains filtered or unexported fields
}
NeighborsBackend implements a neighbors store using a postgres database
func NewNeighborsBackend ¶
func NewNeighborsBackend(pool *pgxpool.Pool) *NeighborsBackend
NewNeighborsBackend initializes the backend with a pool.
func (*NeighborsBackend) CountNeighborsAt ¶
CountNeighborsAt retrieves the current number of stored neighbors.
func (*NeighborsBackend) GetNeighborsAt ¶
func (b *NeighborsBackend) GetNeighborsAt( ctx context.Context, sourceID string, ) (api.Neighbors, error)
GetNeighborsAt retrieves all neighbors associated with a route server (source).
func (*NeighborsBackend) GetNeighborsMapAt ¶
func (b *NeighborsBackend) GetNeighborsMapAt( ctx context.Context, sourceID string, ) (map[string]*api.Neighbor, error)
GetNeighborsMapAt retrieve a neighbor map for a route server. The Neighbor is identified by ID.
func (*NeighborsBackend) SetNeighbors ¶
func (b *NeighborsBackend) SetNeighbors( ctx context.Context, sourceID string, neighbors api.Neighbors, ) error
SetNeighbors updates the current neighbors of a route server identified by sourceID
type RoutesBackend ¶
type RoutesBackend struct {
// contains filtered or unexported fields
}
RoutesBackend implements a postgres store for routes.
func NewRoutesBackend ¶
func NewRoutesBackend( pool *pgxpool.Pool, sources []*config.SourceConfig, ) *RoutesBackend
NewRoutesBackend creates a new instance with a postgres connection pool.
func (*RoutesBackend) CountRoutesAt ¶
CountRoutesAt returns the number of filtered and imported routes and implements the RoutesStoreBackend interface.
func (*RoutesBackend) FindByNeighbors ¶
func (b *RoutesBackend) FindByNeighbors( ctx context.Context, neighbors []*api.NeighborQuery, filters *api.SearchFilters, ) (api.LookupRoutes, error)
FindByNeighbors will return the prefixes for a list of neighbors identified by ID.
func (*RoutesBackend) FindByPrefix ¶
func (b *RoutesBackend) FindByPrefix( ctx context.Context, prefix string, filters *api.SearchFilters, limit uint, ) (api.LookupRoutes, error)
FindByPrefix will return the prefixes matching a pattern
func (*RoutesBackend) Init ¶
func (b *RoutesBackend) Init(ctx context.Context) error
Init will initialize all the route tables
func (*RoutesBackend) SetRoutes ¶
func (b *RoutesBackend) SetRoutes( ctx context.Context, sourceID string, routes api.LookupRoutes, ) error
SetRoutes implements the RoutesStoreBackend interface function for setting all routes of a source identified by ID.