Documentation ¶
Overview ¶
Package cache provides a cache of model.Model elements that can be used in an OVSDB client or server.
The cache can be accessed using a simple API:
cache.Table("Open_vSwitch").Row("<ovs-uuid>")
It implements the ovsdb.NotificationHandler interface such that it can be populated automatically by update notifications
It also contains an eventProcessor where callers may registers functions that will get called on every Add/Update/Delete event.
Index ¶
- type Data
- type ErrCacheInconsistent
- type ErrIndexExists
- type EventHandler
- type EventHandlerFuncs
- type RowCache
- func (r *RowCache) Create(uuid string, m model.Model, checkIndexes bool) error
- func (r *RowCache) Delete(uuid string) error
- func (r *RowCache) HasRow(uuid string) bool
- func (r *RowCache) Index(columns ...string) (map[interface{}][]string, error)
- func (r *RowCache) IndexExists(row model.Model) error
- func (r *RowCache) Len() int
- func (r *RowCache) Row(uuid string) model.Model
- func (r *RowCache) RowByModel(m model.Model) (string, model.Model, error)
- func (r *RowCache) Rows() map[string]model.Model
- func (r *RowCache) RowsByCondition(conditions []ovsdb.Condition) (map[string]model.Model, error)
- func (r *RowCache) RowsByModels(models []model.Model) (map[string]model.Model, error)
- func (r *RowCache) RowsShallow() map[string]model.Model
- func (r *RowCache) Update(uuid string, m model.Model, checkIndexes bool) (model.Model, error)
- type TableCache
- func (t *TableCache) AddEventHandler(handler EventHandler)
- func (t *TableCache) ApplyCacheUpdate(update cacheUpdate) error
- func (t *TableCache) DatabaseModel() model.DatabaseModel
- func (t *TableCache) Disconnected()
- func (t *TableCache) Echo([]interface{})
- func (t *TableCache) Locked([]interface{})
- func (t *TableCache) Mapper() mapper.Mapper
- func (t *TableCache) Populate(tableUpdates ovsdb.TableUpdates) error
- func (t *TableCache) Populate2(tableUpdates ovsdb.TableUpdates2) error
- func (t *TableCache) Purge(dbModel model.DatabaseModel)
- func (t *TableCache) Run(stopCh <-chan struct{})
- func (t *TableCache) Stolen([]interface{})
- func (t *TableCache) Table(name string) *RowCache
- func (t *TableCache) Tables() []string
- func (t *TableCache) Update(context interface{}, tableUpdates ovsdb.TableUpdates) error
- func (t *TableCache) Update2(context interface{}, tableUpdates ovsdb.TableUpdates2) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ErrCacheInconsistent ¶
type ErrCacheInconsistent struct {
// contains filtered or unexported fields
}
ErrCacheInconsistent is an error that can occur when an operation would cause the cache to be inconsistent
func NewErrCacheInconsistent ¶
func NewErrCacheInconsistent(details string) *ErrCacheInconsistent
func (*ErrCacheInconsistent) Error ¶
func (e *ErrCacheInconsistent) Error() string
Error implements the error interface
type ErrIndexExists ¶
type ErrIndexExists struct { Table string Value interface{} Index string New string Existing []string }
ErrIndexExists is returned when an item in the database cannot be inserted due to existing indexes
func NewIndexExistsError ¶
func NewIndexExistsError(table string, value interface{}, index string, new string, existing []string) *ErrIndexExists
func (*ErrIndexExists) Error ¶
func (e *ErrIndexExists) Error() string
type EventHandler ¶
type EventHandler interface { OnAdd(table string, model model.Model) OnUpdate(table string, old model.Model, new model.Model) OnDelete(table string, model model.Model) }
EventHandler can handle events when the contents of the cache changes
type EventHandlerFuncs ¶
type EventHandlerFuncs struct { AddFunc func(table string, model model.Model) UpdateFunc func(table string, old model.Model, new model.Model) DeleteFunc func(table string, model model.Model) }
EventHandlerFuncs is a wrapper for the EventHandler interface It allows a caller to only implement the functions they need
func (*EventHandlerFuncs) OnAdd ¶
func (e *EventHandlerFuncs) OnAdd(table string, model model.Model)
OnAdd calls AddFunc if it is not nil
type RowCache ¶
type RowCache struct {
// contains filtered or unexported fields
}
RowCache is a collections of Models hashed by UUID
func (*RowCache) IndexExists ¶
IndexExists checks if any of the schema indexes of the provided model is already in the cache under a different UUID.
func (*RowCache) RowByModel ¶
RowByModel searches the cache by UUID and schema indexes. UUID search is performed first. Then schema indexes are evaluated in turn by the same order with which they are defined in the schema. The model for the first matching index is returned along with its UUID. An empty string and nil is returned if no Model is found.
func (*RowCache) RowsByCondition ¶
RowsByCondition searches models in the cache that match all conditions
func (*RowCache) RowsByModels ¶
RowsByModels searches the cache by UUID, schema indexes and client indexes. UUID search is performed first. Schema indexes are evaluated next in turn by the same order with which they are defined in the schema. Finally, client indexes are evaluated in turn by the same order with which they are defined in the client DB model. The models for the first matching index are returned, which might be more than 1 if they were found through a client index since in that case uniqueness is not enforced. Nil is returned if no Model is found.
func (*RowCache) RowsShallow ¶
RowsShallow returns a clone'd list of f all Rows in the cache, but does not clone the underlying objects. Therefore, the objects returned are READ ONLY. This is, however, thread safe, as the cached objects are cloned before being updated when modifications come in.
type TableCache ¶
type TableCache struct { ovsdb.NotificationHandler // contains filtered or unexported fields }
TableCache contains a collection of RowCaches, hashed by name, and an array of EventHandlers that respond to cache updates It implements the ovsdb.NotificationHandler interface so it may handle update notifications
func NewTableCache ¶
func NewTableCache(dbModel model.DatabaseModel, data Data, logger *logr.Logger) (*TableCache, error)
NewTableCache creates a new TableCache
func (*TableCache) AddEventHandler ¶
func (t *TableCache) AddEventHandler(handler EventHandler)
AddEventHandler registers the supplied EventHandler to receive cache events
func (*TableCache) ApplyCacheUpdate ¶
func (t *TableCache) ApplyCacheUpdate(update cacheUpdate) error
func (*TableCache) DatabaseModel ¶
func (t *TableCache) DatabaseModel() model.DatabaseModel
DatabaseModel returns the DatabaseModelRequest
func (*TableCache) Disconnected ¶
func (t *TableCache) Disconnected()
Disconnected implements the disconnected method of the NotificationHandler interface
func (*TableCache) Echo ¶
func (t *TableCache) Echo([]interface{})
Echo implements the echo method of the NotificationHandler interface
func (*TableCache) Locked ¶
func (t *TableCache) Locked([]interface{})
Locked implements the locked method of the NotificationHandler interface
func (*TableCache) Populate ¶
func (t *TableCache) Populate(tableUpdates ovsdb.TableUpdates) error
Populate adds data to the cache and places an event on the channel
func (*TableCache) Populate2 ¶
func (t *TableCache) Populate2(tableUpdates ovsdb.TableUpdates2) error
Populate2 adds data to the cache and places an event on the channel
func (*TableCache) Purge ¶
func (t *TableCache) Purge(dbModel model.DatabaseModel)
Purge drops all data in the cache and reinitializes it using the provided database model
func (*TableCache) Run ¶
func (t *TableCache) Run(stopCh <-chan struct{})
Run starts the event processing and update processing loops. It blocks until the stop channel is closed. Once closed, it clears the updates/updates2 channels to ensure we don't process stale updates on a new connection
func (*TableCache) Stolen ¶
func (t *TableCache) Stolen([]interface{})
Stolen implements the stolen method of the NotificationHandler interface
func (*TableCache) Table ¶
func (t *TableCache) Table(name string) *RowCache
Table returns the a Table from the cache with a given name
func (*TableCache) Tables ¶
func (t *TableCache) Tables() []string
Tables returns a list of table names that are in the cache
func (*TableCache) Update ¶
func (t *TableCache) Update(context interface{}, tableUpdates ovsdb.TableUpdates) error
Update implements the update method of the NotificationHandler interface this populates a channel with updates so they can be processed after the initial state has been Populated
func (*TableCache) Update2 ¶
func (t *TableCache) Update2(context interface{}, tableUpdates ovsdb.TableUpdates2) error
Update2 implements the update method of the NotificationHandler interface this populates a channel with updates so they can be processed after the initial state has been Populated