persistencemgr

package
v0.0.0-...-81c02da Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2023 License: Apache-2.0 Imports: 19 Imported by: 4

Documentation

Overview

Package persistencemgr provides an interfaces for database communication

Package persistencemgr provides an interfaces for database communication

Package persistencemgr provides an interfaces for database communication

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetCurrentMasterHostPort

func GetCurrentMasterHostPort(dbConfig *Config) (string, string, error)

GetCurrentMasterHostPort is to get the current Redis Master IP and Port from Sentinel.

func IsRetriable

func IsRetriable(err error) bool

IsRetriable checks fi the redis db operation can be retried or not by validating the error returned by redis

Types

type Config

type Config struct {
	Port         string
	Protocol     string
	Host         string
	SentinelHost string
	SentinelPort string
	MasterSet    string
	Password     string
}

Config is the configuration for db which is set by the wrapper package.

Port is the port number for the database connection Protocol is the type of protocol with which the connection takes place Host is hostname/IP on which the database is running

func GetMockDBConfig

func GetMockDBConfig() (*Config, *errors.Error)

GetMockDBConfig will initiate mock db and will provide the config file

func (*Config) Connection

func (c *Config) Connection() (*ConnPool, *errors.Error)

Connection returns connection pool Connection does not take any input and returns a connection object used to interact with the DB

type Conn

type Conn struct {
	WriteConn *redis.Client
}

Conn contains the write connection instance retrieved from the connection pool

func MockDBWriteConnection

func MockDBWriteConnection(t *testing.T) (*Conn, *errors.Error)

MockDBWriteConnection provides a mock db write connection for unit testing

func (*Conn) Close

func (c *Conn) Close()

Close closes the write connection retrieved from the connection pool

func (*Conn) IsBadConn

func (c *Conn) IsBadConn() bool

IsBadConn checks if the connection to DB is active or not

func (*Conn) SetExpiryTimeForKeys

func (c *Conn) SetExpiryTimeForKeys(taskKeys map[string]int64, keyExpiryInterval int) *errors.Error

SetExpiryTimeForKeys will create the expiry time using pipelined transaction

SetExpiryTimeForKeys takes the taskID  as input:

func (*Conn) UpdateTransaction

func (c *Conn) UpdateTransaction(data map[string]interface{}) *errors.Error

UpdateTransaction will update the database using pipelined transaction

UpdateTransaction takes the following keys as input:

1."data" is of type map[string]interface{} and is the user data sent to be updated in DB. key of map should be the key in database.

type ConnPool

type ConnPool struct {
	ReadPool  *redis.Client
	WritePool *redis.Client
	MasterIP  string
	Mux       sync.Mutex
}

ConnPool is the established connection

func GetDBConnection

func GetDBConnection(dbFlag DbType) (*ConnPool, *errors.Error)

GetDBConnection is used to get the new Connection Pool for Inmemory/OnDisk DB

func MockDBConnection

func MockDBConnection(t *testing.T) (*ConnPool, *errors.Error)

MockDBConnection provides a mock db for unit testing

func (*ConnPool) AddMemberToSet

func (p *ConnPool) AddMemberToSet(key string, member string) *errors.Error

AddMemberToSet add a member to the redis set Following are the input parameters for adding member to redis set: 1. key - redis set name 2. member - member id that to be added to the redis set

func (*ConnPool) AddResourceData

func (p *ConnPool) AddResourceData(table, key string, data interface{}) *errors.Error

AddResourceData will make an entry into the database with the given values

AddResourceData takes the following keys as input:

1."table" is a string which is used identify what kind of data we are storing. 2."data" is of type interface and is the userdata sent to be stored in DB. 3."key" is a string which acts as a unique ID to the data entry.

func (*ConnPool) CleanUpDB

func (p *ConnPool) CleanUpDB() *errors.Error

CleanUpDB will delete all database entries The flush command will be executed without warnings please be cautious in using this

func (*ConnPool) Create

func (p *ConnPool) Create(table, key string, data interface{}) *errors.Error

Create will make an entry into the database with the given values

Create takes the following keys as input:

1."table" is a string which is used identify what kind of data we are storing. 2."data" is of type interface and is the userdata sent to be stored in DB. 3."key" is a string which acts as a unique ID to the data entry.

func (*ConnPool) CreateAggregateHostIndex

func (p *ConnPool) CreateAggregateHostIndex(index, aggregateID string, hostIP []string) error

CreateAggregateHostIndex is used to create and save secondary index

CreateAggregateHostIndex take the following keys are input:

1. index is the name of the index to be created 2. key is for the index

func (*ConnPool) CreateDeviceSubscriptionIndex

func (p *ConnPool) CreateDeviceSubscriptionIndex(index, hostIP, location string, originResources []string) error

CreateDeviceSubscriptionIndex is used to create and save secondary index

CreateDeviceSubscriptionIndex take the following keys are input:

1. index is the name of the index to be created 2. key is for the index

func (*ConnPool) CreateEvtSubscriptionIndex

func (p *ConnPool) CreateEvtSubscriptionIndex(index string, key interface{}) error

CreateEvtSubscriptionIndex is used to create and save secondary index

CreateSubscriptionIndex take the following keys are input:

1. index is the name of the index to be created 2. key and value are the key value pair for the index

func (*ConnPool) CreateIndex

func (p *ConnPool) CreateIndex(form map[string]interface{}, uuid string) error

CreateIndex is used to create and save secondary index

CreateIndex take the following keys are input:

1. form is a map of the index to be created and the data along with it 2. uuid is the resource id with witch the value is stored

func (*ConnPool) CreateTaskIndex

func (p *ConnPool) CreateTaskIndex(index string, value int64, key string) error

CreateTaskIndex is used to create secondary indexing for task service Following are the input parameters for creating task index: 1. index name 2. value takes the Endtime for sorting with range 3. key if of the format `UserName::Endtime::TaskID`

func (*ConnPool) Decr

func (p *ConnPool) Decr(table, key string) (int, *errors.Error)

Decr is for decrementing the count Decr takes "key" string as input which acts as a unique ID to decrement the count and return same

func (*ConnPool) Del

func (p *ConnPool) Del(index string, k string) error

Del is used to delete the index key

1. index is the name of the index under which the key needs to be deleted 2. key is the id of the resource to be deleted under an index

func (*ConnPool) Delete

func (p *ConnPool) Delete(table, key string) *errors.Error

Delete data entry Read takes "key" sting as input which acts as a unique ID to delete specific data from DB

func (*ConnPool) DeleteAggregateHosts

func (p *ConnPool) DeleteAggregateHosts(index, aggregateID string) error

DeleteAggregateHosts is for to Delete subscription details of aggregate 1. index is the name of the index to be created 2. removeKey is string parameter for remove

func (*ConnPool) DeleteDeviceSubscription

func (p *ConnPool) DeleteDeviceSubscription(index, hostIP string) error

DeleteDeviceSubscription is for to Delete subscription details of Device 1. index is the name of the index to be created 2. removeKey is string parameter for remove

func (*ConnPool) DeleteEvtSubscriptions

func (p *ConnPool) DeleteEvtSubscriptions(index, removeKey string) error

DeleteEvtSubscriptions is for to Delete subscription details 1. index is the name of the index to be created 2. removeKey is string parameter for remove

func (*ConnPool) DeleteKey

func (p *ConnPool) DeleteKey(key string) *errors.Error

DeleteKey takes "key" sting as input which acts as a unique ID to delete specific data from DB

func (*ConnPool) DeleteMultipleKeys

func (p *ConnPool) DeleteMultipleKeys(keys []string) *errors.Error

DeleteMultipleKeys data entry takes "keys" array of sting as input to delete data from DB at once

func (*ConnPool) DeleteServer

func (p *ConnPool) DeleteServer(key string) *errors.Error

DeleteServer data entry without table Read takes "key" sting as input which acts as a unique ID to delete specific data from DB

func (*ConnPool) EnableKeySpaceNotifier

func (p *ConnPool) EnableKeySpaceNotifier(notifierType, filterType string) *errors.Error

EnableKeySpaceNotifier enable keyspace event notifications takes notifierType ad filterType as input to set value to filter redis event

func (*ConnPool) FindOrNull

func (p *ConnPool) FindOrNull(table, key string) (string, error)

FindOrNull is a wrapper for Read function. If requested asset doesn't exist errors.DBKeyNotFound error returned by Read is converted to nil

func (*ConnPool) GetAggregateHosts

func (p *ConnPool) GetAggregateHosts(index string, match string) ([]string, error)

GetAggregateHosts is used to retrive index values of type string

Inputs:

1. index is the index name to search with 2. match is the value to match with

TODO : Handle cursor

func (*ConnPool) GetAllDataByIndex

func (p *ConnPool) GetAllDataByIndex(index string) ([]string, error)

GetAllDataByIndex - This function retrieves all data for a given index from sorted sets This maybe used to get all event/device subscriptions and aggregate hosts

func (*ConnPool) GetAllDetails

func (p *ConnPool) GetAllDetails(table string) ([]string, *errors.Error)

GetAllDetails will fetch all the keys present in the database

func (*ConnPool) GetAllKeysFromDb

func (p *ConnPool) GetAllKeysFromDb(table, pattern string, nextCursor int) ([]string, int, *errors.Error)

GetAllKeysFromDb will fetch all the keys which matches pattern present in the database using scan command, return list of key and nextCursor

func (*ConnPool) GetAllMatchingDetails

func (p *ConnPool) GetAllMatchingDetails(table, pattern string) ([]string, *errors.Error)

GetAllMatchingDetails will fetch all the keys which matches pattern present in the database

func (*ConnPool) GetAllMembersInSet

func (p *ConnPool) GetAllMembersInSet(key string) ([]string, *errors.Error)

GetAllMembersInSet get all members in a redis set Following are the input parameters to get embers from redis set: 1. key - redis set name

func (*ConnPool) GetDeviceSubscription

func (p *ConnPool) GetDeviceSubscription(index string, match string) ([]string, error)

GetDeviceSubscription is used to retrive index values of type string

Inputs:

1. index is the index name to search with 2. match is the value to match with

TODO : Handle cursor

func (*ConnPool) GetEvtSubscriptions

func (p *ConnPool) GetEvtSubscriptions(index, searchKey string) ([]string, error)

GetEvtSubscriptions is for to get subscription details 1. index is the name of the index to be created 2. searchKey is for search TODO: Add support for cursors and multiple data

func (*ConnPool) GetKeyValue

func (p *ConnPool) GetKeyValue(key string) (string, *errors.Error)

GetKeyValue takes "key" sting as input which acts as a unique ID to fetch specific data from DB

func (*ConnPool) GetRange

func (p *ConnPool) GetRange(index string, min, max int, regexFlag bool) ([]string, error)

GetRange is used to range over float type values

1. index is the name of the index to search under 2. min is the minimum value for the search 3. max is the maximum value for the search

func (*ConnPool) GetResourceDetails

func (p *ConnPool) GetResourceDetails(key string) (string, *errors.Error)

GetResourceDetails will fetch the key and also fetch the data

func (*ConnPool) GetStorageList

func (p *ConnPool) GetStorageList(index string, cursor, match float64, condition string, regexFlag bool) ([]string, error)

GetStorageList is used to storage list of capacity

1.index name to search with 2. cursor is the redis cursor value 3. match is the search for list float type 4. condition is the value for condition operation

func (*ConnPool) GetString

func (p *ConnPool) GetString(index string, cursor float64, match string, regexFlag bool) ([]string, error)

GetString is used to retrive index values of type string

Inputs:

1. index is the index name to search with 2. cursor is the redis db cursor value 3. match is the value to match with

func (*ConnPool) GetTaskList

func (p *ConnPool) GetTaskList(index string, min, max int) ([]string, error)

GetTaskList is used to range over float type values

1. index is the name of the index to search under 2. min is the minimum value for the search 3. max is the maximum value for the search

func (*ConnPool) GetWriteConnection

func (p *ConnPool) GetWriteConnection() (*Conn, *errors.Error)

GetWriteConnection retrieve a write connection from the connection pool

func (*ConnPool) Incr

func (p *ConnPool) Incr(table, key string) (int, *errors.Error)

Incr is for incrementing the count Incr takes "key" string as input which acts as a unique ID to increment the count and return same

func (*ConnPool) Ping

func (p *ConnPool) Ping() error

Ping will check the DB connection health

func (*ConnPool) Read

func (p *ConnPool) Read(table, key string) (string, *errors.Error)

Read is for getting singular data Read takes "key" sting as input which acts as a unique ID to fetch specific data from DB

func (*ConnPool) ReadMultipleKeys

func (p *ConnPool) ReadMultipleKeys(key []string) ([]string, *errors.Error)

ReadMultipleKeys function is used to read data for multiple keys from DB

func (*ConnPool) RemoveMemberFromSet

func (p *ConnPool) RemoveMemberFromSet(key string, member string) *errors.Error

RemoveMemberFromSet removes a member from the redis set Following are the input parameters for removing member from redis set: 1. key - redis set name 2. member - member id that to be added to the redis set

func (*ConnPool) SaveBMCInventory

func (p *ConnPool) SaveBMCInventory(data map[string]interface{}) *errors.Error

SaveBMCInventory function save all bmc inventory data togeter using the transaction model

func (*ConnPool) SaveUndeliveredEvents

func (p *ConnPool) SaveUndeliveredEvents(table, key string, data []byte) *errors.Error

SaveUndeliveredEvents method store undelivered event data in db takes table name ,key data and connection pool as input

func (*ConnPool) SetExpire

func (p *ConnPool) SetExpire(table, key string, data interface{}, expiretime int) *errors.Error

SetExpire key to hold the string value and set key to timeout after a given number of seconds

SetExpire takes the following keys as input:

1."table" is a string which is used identify what kind of data we are storing. 2."data" is of type interface and is the userdata sent to be stored in DB. 3."key" is a string which acts as a unique ID to the data entry. 4. "expiretime" is of type int, which acts as expiry time for the key

func (*ConnPool) TTL

func (p *ConnPool) TTL(table, key string) (int, *errors.Error)

TTL is for getting singular data TTL takes "key" string as input which acts as a unique ID to fetch time left

func (*ConnPool) Transaction

func (p *ConnPool) Transaction(ctx context.Context, key string, cb func(context.Context, string) error) *errors.Error

Transaction is to do a atomic operation using optimistic lock

func (*ConnPool) Update

func (p *ConnPool) Update(table, key string, data interface{}) (string, *errors.Error)

Update data

Update take the following keys as input:

1."uid" is a string which acts as a unique ID to fetch the data from the DB 2."data" is userdata which is of type interface sent by the user to update/patch the already existing data

func (*ConnPool) UpdateAggregateHosts

func (p *ConnPool) UpdateAggregateHosts(index, aggregateID string, hostIP []string) error

UpdateAggregateHosts is for to Update subscription details 1. index is the name of the index to be created 2. key and value are the key value pair for the index

func (*ConnPool) UpdateDeviceSubscription

func (p *ConnPool) UpdateDeviceSubscription(index, hostIP, location string, originResources []string) error

UpdateDeviceSubscription is for to Update subscription details 1. index is the name of the index to be created 2. key and value are the key value pair for the index

func (*ConnPool) UpdateEvtSubscriptions

func (p *ConnPool) UpdateEvtSubscriptions(index, subscritionID string, key interface{}) error

UpdateEvtSubscriptions is for to Update subscription details 1. index is the name of the index to be created 2. key and value are the key value pair for the index

func (*ConnPool) UpdateResourceIndex

func (p *ConnPool) UpdateResourceIndex(form map[string]interface{}, uuid string) error

UpdateResourceIndex is used to update the resource inforamtion which is indexed form contains index name and value:key for the index

func (*ConnPool) Upsert

func (p *ConnPool) Upsert(table, key string, data interface{}) *errors.Error

Upsert will insert new data in DB if the key does not exist. else it will update the existing key

Upsert take the following leys as input:

1."uid" is a string which acts as a unique ID to fetch the data from the DB 2."data" is user data which is of type interface sent by the user to update/patch the already existing data

type DbType

type DbType int32

DbType is a alias name for int32

const (
	//InMemory - To select in-memory db connection pool
	InMemory DbType = iota
	// OnDisk - To select in-disk db connection pool
	OnDisk
)

type RedisExternalCalls

type RedisExternalCalls interface {
	// contains filtered or unexported methods
}

RedisExternalCalls containes the methods to make calls to external client libraries of Redis DB

func NewRedisExternalCalls

func NewRedisExternalCalls() RedisExternalCalls

NewRedisExternalCalls is Constructor for RedisExternalCalls

Jump to

Keyboard shortcuts

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