Documentation
¶
Index ¶
- type DatabaseStore
- type DualStore
- func (d *DualStore) AddSubscription(ctx context.Context, subscriberKey string, serviceGroup string) error
- func (d *DualStore) Close() error
- func (d *DualStore) DeleteService(ctx context.Context, key string) error
- func (d *DualStore) GetAllServices(ctx context.Context) ([]*models.ServiceInfo, error)
- func (d *DualStore) GetDatabase() DatabaseStore
- func (d *DualStore) GetService(ctx context.Context, key string) (*models.ServiceInfo, error)
- func (d *DualStore) GetServicesByName(ctx context.Context, serviceName string) ([]*models.ServiceInfo, error)
- func (d *DualStore) GetSubscriberServices(ctx context.Context, serviceGroup string) ([]*models.ServiceInfo, error)
- func (d *DualStore) GetSubscribers(ctx context.Context, serviceGroup string) ([]string, error)
- func (d *DualStore) Ping(ctx context.Context) error
- func (d *DualStore) RemoveAllSubscriptions(ctx context.Context, subscriberKey string) error
- func (d *DualStore) RemoveSubscription(ctx context.Context, subscriberKey string, serviceGroup string) error
- func (d *DualStore) SaveService(ctx context.Context, service *models.ServiceInfo) error
- func (d *DualStore) SyncFromDatabase(ctx context.Context) (servicesSynced int, subscriptionsSynced int, err error)
- func (d *DualStore) SyncToDatabase(ctx context.Context) error
- func (d *DualStore) UpdateHealthStatus(ctx context.Context, key string, status models.ServiceStatus, ...) error
- type RegistryStore
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DatabaseStore ¶
type DatabaseStore interface {
// SaveService stores or updates a service entry in the database
SaveService(ctx context.Context, service *models.ServiceInfo) error
// GetService retrieves a single service by its composite key (serviceName:podName)
GetService(ctx context.Context, key string) (*models.ServiceInfo, error)
// GetAllServices retrieves all registered services from database
// Used during reconciliation to sync with cache
GetAllServices(ctx context.Context) ([]*models.ServiceInfo, error)
// DeleteService removes a service entry by its composite key
DeleteService(ctx context.Context, key string) error
// UpdateHealthStatus updates the health status and last check timestamp
UpdateHealthStatus(ctx context.Context, key string, status models.ServiceStatus, timestamp time.Time) error
// SaveSubscriptions saves all subscriptions for a service
// This replaces all existing subscriptions for the given subscriber
SaveSubscriptions(ctx context.Context, subscriberKey string, subscriptions []string) error
// GetSubscriptions retrieves all service groups that a subscriber is subscribed to
GetSubscriptions(ctx context.Context, subscriberKey string) ([]string, error)
// GetAllSubscriptions retrieves all subscription relationships from database
// Used during reconciliation to sync with cache
// Returns map[subscriberKey][]serviceGroups
GetAllSubscriptions(ctx context.Context) (map[string][]string, error)
// DeleteSubscriptions removes all subscriptions for a subscriber
DeleteSubscriptions(ctx context.Context, subscriberKey string) error
// Close closes the database connection and cleans up resources
Close() error
// Ping checks if the database is accessible
Ping(ctx context.Context) error
}
DatabaseStore defines the interface for database persistence layer. This is simpler than RegistryStore - it's only for persistence, not for runtime queries. The in-memory cache handles all runtime operations.
type DualStore ¶
type DualStore struct {
// contains filtered or unexported fields
}
DualStore combines in-memory cache with optional database persistence. All reads/writes go to memory for performance. Database writes happen asynchronously (fire-and-forget).
func NewDualStore ¶
func NewDualStore(db DatabaseStore) *DualStore
NewDualStore creates a new dual-layer storage. If db is nil, only in-memory cache is used (no persistence).
func (*DualStore) AddSubscription ¶
func (d *DualStore) AddSubscription(ctx context.Context, subscriberKey string, serviceGroup string) error
AddSubscription adds to cache immediately, then persists to database asynchronously
func (*DualStore) DeleteService ¶
DeleteService deletes from cache immediately, then from database asynchronously
func (*DualStore) GetAllServices ¶
GetAllServices retrieves from cache (fast)
func (*DualStore) GetDatabase ¶
func (d *DualStore) GetDatabase() DatabaseStore
GetDatabase returns the underlying database store (may be nil)
func (*DualStore) GetService ¶
GetService retrieves from cache (fast)
func (*DualStore) GetServicesByName ¶
func (d *DualStore) GetServicesByName(ctx context.Context, serviceName string) ([]*models.ServiceInfo, error)
GetServicesByName retrieves from cache (fast)
func (*DualStore) GetSubscriberServices ¶
func (d *DualStore) GetSubscriberServices(ctx context.Context, serviceGroup string) ([]*models.ServiceInfo, error)
GetSubscriberServices retrieves from cache (fast)
func (*DualStore) GetSubscribers ¶
GetSubscribers retrieves from cache (fast)
func (*DualStore) RemoveAllSubscriptions ¶
RemoveAllSubscriptions removes from cache immediately, then from database asynchronously
func (*DualStore) RemoveSubscription ¶
func (d *DualStore) RemoveSubscription(ctx context.Context, subscriberKey string, serviceGroup string) error
RemoveSubscription removes from cache immediately, then from database asynchronously
func (*DualStore) SaveService ¶
SaveService stores to cache immediately, then persists to database asynchronously
func (*DualStore) SyncFromDatabase ¶
func (d *DualStore) SyncFromDatabase(ctx context.Context) (servicesSynced int, subscriptionsSynced int, err error)
SyncFromDatabase loads all data from database into cache. This is called during reconciliation to ensure cache and database are in sync. Returns the number of services and subscriptions synced.
func (*DualStore) SyncToDatabase ¶
SyncToDatabase writes all cache data to database. This is useful for initial database population or full sync.
type RegistryStore ¶
type RegistryStore interface {
// SaveService stores or updates a service entry
SaveService(ctx context.Context, service *models.ServiceInfo) error
// GetService retrieves a single service by its composite key (serviceName:podName)
GetService(ctx context.Context, key string) (*models.ServiceInfo, error)
// GetServicesByName retrieves all pods for a given service name
GetServicesByName(ctx context.Context, serviceName string) ([]*models.ServiceInfo, error)
// GetAllServices retrieves all registered services across all service groups
GetAllServices(ctx context.Context) ([]*models.ServiceInfo, error)
// DeleteService removes a service entry by its composite key
DeleteService(ctx context.Context, key string) error
// UpdateHealthStatus updates the health status and last check timestamp for a service
UpdateHealthStatus(ctx context.Context, key string, status models.ServiceStatus, timestamp time.Time) error
// AddSubscription adds a subscriber to a service group
// subscriberKey is the composite key (serviceName:podName) of the subscriber
// serviceGroup is the name of the service being subscribed to
AddSubscription(ctx context.Context, subscriberKey string, serviceGroup string) error
// RemoveSubscription removes a subscriber from a service group
RemoveSubscription(ctx context.Context, subscriberKey string, serviceGroup string) error
// RemoveAllSubscriptions removes all subscriptions for a given subscriber
RemoveAllSubscriptions(ctx context.Context, subscriberKey string) error
// GetSubscribers returns all subscriber keys for a given service group
GetSubscribers(ctx context.Context, serviceGroup string) ([]string, error)
// GetSubscriberServices returns full ServiceInfo objects for all subscribers of a service group
GetSubscriberServices(ctx context.Context, serviceGroup string) ([]*models.ServiceInfo, error)
// Close closes the storage connection and cleans up resources
Close() error
// Ping checks if the storage backend is accessible
Ping(ctx context.Context) error
}
RegistryStore defines the interface for persisting service registry data. Implementations can use different storage backends (memory, MySQL, PostgreSQL, MongoDB, etc.)