db

package
v0.0.0-...-0805cb3 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2020 License: Apache-2.0 Imports: 9 Imported by: 6

Documentation

Overview

Package db contains the database implementation for uniqush-push, for managing Push Service Providers, Delivery Points, services, etc. Currently, this only supports redis.

Index

Constants

View Source
const (
	// DeliveryPointPrefix is the prefix of keys for a redis STRING - Maps the delivery point name to a json blob of information about a delivery point.
	DeliveryPointPrefix string = "delivery.point:"
	// PushServiceProviderPrefix is the prefix of keys for a redis STRING - Maps a push service provider name to a json blob of information about it.
	PushServiceProviderPrefix string = "push.service.provider:"
	// ServiceSubscriberToDeliveryPointsPrefix is the prefix of keys for a redis SET - Maps a service name + subscriber to a set of delivery point names
	ServiceSubscriberToDeliveryPointsPrefix string = "srv.sub-2-dp:"
	// ServiceDeliveryPointToPushServiceProviderPrefix is the prefix of keys for a redis STRING - Maps a service name + delivery point name to the push service provider
	ServiceDeliveryPointToPushServiceProviderPrefix string = "srv.dp-2-psp:"
	// ServiceToPushServiceProvidersPrefix is the prefix of keys for a redis SET - Maps a service name to a set of PSP names
	ServiceToPushServiceProvidersPrefix string = "srv-2-psp:"
	// DeliveryPointCounterPrefix is the prefix of keys for a redis STRING - Maps a delivery point name to the number of subcribers(summed across each service).
	DeliveryPointCounterPrefix string = "delivery.point.counter:"
	// ServicesSet is the key for a redis SET - This is a set of service names.
	ServicesSet string = "services{0}"
)
View Source
const (
	// DeliveryPointID is the internal identifier for a delivery point(subscription) in Subscription() responses, which may be returned to clients if include_delivery_point_ids=1.
	DeliveryPointID = "delivery_point_id"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type DatabaseConfig

type DatabaseConfig struct {
	Engine    string
	Name      string
	User      string
	Password  string
	Host      string
	Port      int
	CacheSize int

	// Config for read-only slave (uses same Name as master db)
	SlaveHost string
	SlavePort int

	/* dump the dirty data to db every EverySec seconds,
	 * if there are more than LeastDirty dirty items
	 */
	EverySec   int64
	LeastDirty int

	PushServiceManager *push.PushServiceManager
}

DatabaseConfig represents all of the configuration for a database implementation. Currently, the only db implementation is redis.

func (*DatabaseConfig) String

func (c *DatabaseConfig) String() string

type PushDatabase

type PushDatabase interface {

	// The push service provider may by anonymous whose Name is empty string
	// For anonymous push service provider, it will be added to database
	// and its Name will be set
	RemovePushServiceProviderFromService(service string, pushServiceProvider *push.PushServiceProvider) error

	// The push service provider may by anonymous whose Name is empty string
	// For anonymous push service provider, it will be added to database
	// and its Name will be set
	AddPushServiceProviderToService(service string,
		pushServiceProvider *push.PushServiceProvider) error

	ModifyPushServiceProvider(psp *push.PushServiceProvider) error

	// Get a set of all push service providers
	GetPushServiceProviderConfigs() ([]*push.PushServiceProvider, error)

	// RebuildServiceSet() ensures that a set of all PSPs exists. After FixServiceSet is called on a pre-existing uniqush setup, the set of all PSPs will be accurate (Even after calls to AddPushServiceProvider/RemovePushServiceProvider)
	RebuildServiceSet() error

	// The delivery point may be anonymous whose Name is empty string
	// For anonymous delivery point, it will be added to database and its Name will be set
	// Return value: selected push service provider, error
	AddDeliveryPointToService(service string,
		subscriber string,
		deliveryPoint *push.DeliveryPoint) (*push.PushServiceProvider, error)

	// The delivery point may be anonymous whose Name is empty string
	// For anonymous delivery point, it will be added to database and its Name will be set
	// Return value: selected push service provider, error
	RemoveDeliveryPointFromService(service string,
		subscriber string,
		deliveryPoint *push.DeliveryPoint) error

	ModifyDeliveryPoint(dp *push.DeliveryPoint) error

	GetPushServiceProviderDeliveryPointPairs(service string, subscriber string, dpNamesRequested []string) ([]PushServiceProviderDeliveryPointPair, error)

	GetSubscriptions(services []string, user string, logger log.Logger) ([]map[string]string, error)

	FlushCache() error
}

PushDatabase is an interface for any db implementation that uniqush-push can use. Currently, redis is the only supported database.

func NewPushDatabaseWithoutCache

func NewPushDatabaseWithoutCache(conf *DatabaseConfig) (PushDatabase, error)

NewPushDatabaseWithoutCache creates a push database implementation communicating with redis without any in-memory caching

type PushRedisDB

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

PushRedisDB is currently the only uniqush pushRawDatabase implementation. It stores push service providers, delivery points, etc. in redis.

func (*PushRedisDB) AddDeliveryPointToServiceSubscriber

func (r *PushRedisDB) AddDeliveryPointToServiceSubscriber(srv, sub, dp string) error

AddDeliveryPointToServiceSubscriber will associate the name of the given delivery point with the given service name and subscriber name.

func (*PushRedisDB) AddPushServiceProviderToService

func (r *PushRedisDB) AddPushServiceProviderToService(srv, psp string) error

AddPushServiceProviderToService will add the push service provider's name to the list of PSPs for this service.

func (*PushRedisDB) FlushCache

func (r *PushRedisDB) FlushCache() error

FlushCache will ensure that redis data has been saved to disk.

func (*PushRedisDB) GetDeliveryPoint

func (r *PushRedisDB) GetDeliveryPoint(name string) (*push.DeliveryPoint, error)

GetDeliveryPoint fetches the delivery point with a given generated name.

func (*PushRedisDB) GetDeliveryPointsNameByServiceSubscriber

func (r *PushRedisDB) GetDeliveryPointsNameByServiceSubscriber(srv, sub string) (map[string][]string, error)

GetDeliveryPointsNameByServiceSubscriber will get the delivery point for a service and it's subscriber

func (*PushRedisDB) GetPushServiceProvider

func (r *PushRedisDB) GetPushServiceProvider(name string) (*push.PushServiceProvider, error)

GetPushServiceProvider will fetch and unserialize the push service provider with the given name.

func (*PushRedisDB) GetPushServiceProviderConfigs

func (r *PushRedisDB) GetPushServiceProviderConfigs(names []string) ([]*push.PushServiceProvider, []error)

GetPushServiceProviderConfigs will fetch and unserialize the push service providers with the given names.

func (*PushRedisDB) GetPushServiceProviderNameByServiceDeliveryPoint

func (r *PushRedisDB) GetPushServiceProviderNameByServiceDeliveryPoint(srv, dp string) (string, error)

GetPushServiceProviderNameByServiceDeliveryPoint returns the push service provider name of a delivery point belonging to a given service name.

func (*PushRedisDB) GetPushServiceProvidersByService

func (r *PushRedisDB) GetPushServiceProvidersByService(srv string) ([]string, error)

GetPushServiceProvidersByService will return a list of the names of push service providers belonging to the given service name

func (*PushRedisDB) GetServiceNames

func (r *PushRedisDB) GetServiceNames() ([]string, error)

GetServiceNames will return the list of all services that have 1 or more push service providers.

func (*PushRedisDB) GetSubscriptions

func (r *PushRedisDB) GetSubscriptions(queryServices []string, subscriber string, logger log.Logger) ([]map[string]string, error)

GetSubscriptions will fetch the subscriptions of the given subscriber belonging to the given service list. If queryServices is empty, then this will fetch subscriptions from all known services.

func (*PushRedisDB) RebuildServiceSet

func (r *PushRedisDB) RebuildServiceSet() error

RebuildServiceSet builds the set of unique service. It should only be needed for migrating from old uniqush installations.

func (*PushRedisDB) RemoveDeliveryPoint

func (r *PushRedisDB) RemoveDeliveryPoint(dp string) error

RemoveDeliveryPoint will remove the data for a delivery point.

func (*PushRedisDB) RemoveDeliveryPointFromServiceSubscriber

func (r *PushRedisDB) RemoveDeliveryPointFromServiceSubscriber(srv, sub, dp string) error

RemoveDeliveryPointFromServiceSubscriber will remove the given delivery point's name from the subscriber of the provided service.

func (*PushRedisDB) RemovePushServiceProvider

func (r *PushRedisDB) RemovePushServiceProvider(psp string) error

RemovePushServiceProvider will remove a push service provider's configuration

func (*PushRedisDB) RemovePushServiceProviderFromService

func (r *PushRedisDB) RemovePushServiceProviderFromService(srv, psp string) error

RemovePushServiceProviderFromService will remove the given push service provider from the list of services (and remove the service from the list of services, if this results in the service having 0 subscriptions)

func (*PushRedisDB) RemovePushServiceProviderOfServiceDeliveryPoint

func (r *PushRedisDB) RemovePushServiceProviderOfServiceDeliveryPoint(srv, dp string) error

RemovePushServiceProviderOfServiceDeliveryPoint is used when removing a push service provider, to clean up the association to the name of the push service provider for the delivery point+service name.

func (*PushRedisDB) SetDeliveryPoint

func (r *PushRedisDB) SetDeliveryPoint(dp *push.DeliveryPoint) error

SetDeliveryPoint sets (adds or updates) the delivery point representation in the database.

func (*PushRedisDB) SetPushServiceProvider

func (r *PushRedisDB) SetPushServiceProvider(psp *push.PushServiceProvider) error

SetPushServiceProvider will add or update the push service provider psp. The redis key is based on a hash of FixedData.

func (*PushRedisDB) SetPushServiceProviderOfServiceDeliveryPoint

func (r *PushRedisDB) SetPushServiceProviderOfServiceDeliveryPoint(srv, dp, psp string) error

SetPushServiceProviderOfServiceDeliveryPoint will set the name of the push service provider to use when sending pushes to the given delivery point of this service name.

type PushServiceProviderDeliveryPointPair

type PushServiceProviderDeliveryPointPair struct {
	PushServiceProvider *push.PushServiceProvider
	DeliveryPoint       *push.DeliveryPoint
}

PushServiceProviderDeliveryPointPair is a pair of a push service provider and a delivery point belonging to that PSP.

Jump to

Keyboard shortcuts

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