Documentation
¶
Overview ¶
Package syncdata provides for synchronizing data
Index ¶
- func SyncReservationsTest(ctx context.Context, factory SyncFactory)
- type MutexSyncFactory
- type MutexSyncReservations
- func (s *MutexSyncReservations) Get(ctx context.Context) (map[string]string, error)
- func (s *MutexSyncReservations) Release(ctx context.Context, keys ...string) error
- func (s *MutexSyncReservations) ReleaseForOwner(ctx context.Context, ownerID string) error
- func (s *MutexSyncReservations) ReserveValues(ctx context.Context, ...) error
- type Reservations
- type SyncFactory
- type SyncReservations
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SyncReservationsTest ¶
func SyncReservationsTest(ctx context.Context, factory SyncFactory)
Types ¶
type MutexSyncFactory ¶
type MutexSyncFactory struct{}
func NewMutexSyncFactory ¶
func NewMutexSyncFactory() *MutexSyncFactory
func (*MutexSyncFactory) NewSyncReservations ¶
func (s *MutexSyncFactory) NewSyncReservations(name string) SyncReservations
type MutexSyncReservations ¶
type MutexSyncReservations struct {
// contains filtered or unexported fields
}
func NewMutexSyncReservations ¶
func NewMutexSyncReservations(name string) *MutexSyncReservations
func (*MutexSyncReservations) Release ¶
func (s *MutexSyncReservations) Release(ctx context.Context, keys ...string) error
func (*MutexSyncReservations) ReleaseForOwner ¶
func (s *MutexSyncReservations) ReleaseForOwner(ctx context.Context, ownerID string) error
func (*MutexSyncReservations) ReserveValues ¶
func (s *MutexSyncReservations) ReserveValues(ctx context.Context, updateFn func(ctx context.Context, reservations Reservations) error) error
type Reservations ¶
func (Reservations) Add ¶
func (s Reservations) Add(value, ownerID string)
Add a value to the reservations with the given ownerID. The ownerID is used to clean up stale reservations.
func (Reservations) AddIfMissing ¶
func (s Reservations) AddIfMissing(value string)
AddIfMissing adds a reservation that should already be present because it was found to be in use, typically by an external database or underlying infrastructure. In this case we don't know the ownerID, but we'll keep track of it so we can check all actively used values in once place.
func (Reservations) RemoveForOwner ¶
func (s Reservations) RemoveForOwner(ownerID string)
type SyncFactory ¶
type SyncFactory interface {
NewSyncReservations(name string) SyncReservations
}
SyncFactory allows for creating objects to synchronize data across multiple threads and processes.
type SyncReservations ¶
type SyncReservations interface {
// Get the currently reserved values.
// Get should not be used in the update function
Get(ctx context.Context) (map[string]string, error)
// ReserveValues allows for reserving new values. It is done as part of an update
// function to synchronize write-after-read operations.
// Changes to the reservations should be made to the values map.
// The update function may be re-run if there is a conflict in updating
// the reservations.
ReserveValues(ctx context.Context, updateFn func(ctx context.Context, reservations Reservations) error) error
// Release removes reserved values
Release(ctx context.Context, keys ...string) error
// ReleaseForOwner release all values for the given owner
ReleaseForOwner(ctx context.Context, ownerID string) error
}
SyncReservations allows for multiple threads/processes to coordinate reserving values, such as IPs or subnets. The intended use case is when needing to allocate a new subnet CIDR/IP that is not currently in use in the platform, and then commit that change to the platform, without allowing another thread/process running in parallel to choose the same value and cause a conflict. Keys for the reservations should be the values to reserve, the value associated with the key should be an ownerID. Associating an ownerID allows any stale reservations (cause by crashes) to be cleaned up later when the object is updated or deleted.