db

package
v0.0.0-...-5f1191e Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Overview

Package db implements a wrapper over the go-redis/redis.

There may be an attempt to mimic sonic-py-swsssdk to ease porting of code written in python using that SDK to Go Language.

Example:

  • Initialization:

    d, _ := db.NewDB(db.Options { DBNo : db.ConfigDB, InitIndicator : "CONFIG_DB_INITIALIZED", TableNameSeparator: "|", KeySeparator : "|", })

  • Close:

    d.DeleteDB()

  • No-Transaction SetEntry

    tsa := db.TableSpec { Name: "ACL_TABLE" } tsr := db.TableSpec { Name: "ACL_RULE" }

    ca := make([]string, 1, 1)

    ca[0] = "MyACL1_ACL_IPV4" akey := db.Key { Comp: ca} avalue := db.Value {map[string]string {"ports":"eth0","type":"mirror" }}

    d.SetEntry(&tsa, akey, avalue)

  • GetEntry

    avalue, _ := d.GetEntry(&tsa, akey)

  • GetKeys

    keys, _ := d.GetKeys(&tsa);

  • GetKeysPattern

    keys, _ := d.GetKeys(&tsa, akeyPattern);

  • No-Transaction DeleteEntry

    d.DeleteEntry(&tsa, akey)

  • GetTable

    ta, _ := d.GetTable(&tsa)

  • No-Transaction DeleteTable

    d.DeleteTable(&ts)

  • Transaction

    rkey := db.Key { Comp: []string { "MyACL2_ACL_IPV4", "RULE_1" }} rvalue := db.Value { Field: map[string]string { "priority" : "0", "packet_action" : "eth1", }, }

    d.StartTx([]db.WatchKeys { {Ts: &tsr, Key: &rkey} }, []*db.TableSpec { &tsa, &tsr })

    d.SetEntry( &tsa, akey, avalue) d.SetEntry( &tsr, rkey, rvalue)

    e := d.CommitTx()

  • Transaction Abort

    d.StartTx([]db.WatchKeys {}, []*db.TableSpec { &tsa, &tsr }) d.DeleteEntry( &tsa, rkey) d.AbortTx()

Package db implements a wrapper over the go-redis/redis.

Package db implements a wrapper over the go-redis/redis.

Index

Constants

View Source
const (
	DefaultRedisUNIXSocket  string = "/var/run/redis/redis.sock"
	DefaultRedisLocalTCPEP  string = "localhost:6379"
	DefaultRedisRemoteTCPEP string = "127.0.0.1:6379"
	DefaultRedisUNIXNetwork string = "unix"
	DefaultRedisTCPNetwork  string = "tcp"
)
View Source
const (
	InitialTxPipelineSize    int = 100
	InitialTablesCount       int = 20
	InitialTableEntryCount   int = 50
	InitialTablePatternCount int = 5
	InitialMapsCount         int = 10
	InitialMapKeyCount       int = 50
)
View Source
const (
	ConnectionClosed = tlerr.TranslibDBInvalidState("connection closed")
	OnChangeDisabled = tlerr.TranslibDBInvalidState("OnChange disabled")
	SupportsReadOnly = tlerr.TranslibDBInvalidState("Supported on read only")

	OnChangeNoSupport = tlerr.TranslibDBInvalidState("OnChange not supported")
	SupportsCfgDBOnly = tlerr.TranslibDBInvalidState("Supported on CfgDB only")
	UseGetEntry       = tlerr.TranslibDBInvalidState("Use GetEntry()")
)
View Source
const (
	InitTable2sDBSize int = 20
	InitSDBArraySize  int = 5
)
View Source
const (
	InitialDebugDBSize int = 20
)

Variables

This section is empty.

Functions

func ClearCache

func ClearCache() error

func ClearDBStats

func ClearDBStats() error

func ConfigDBClearLock

func ConfigDBClearLock() error

func ConfigDBTryLock

func ConfigDBTryLock(token string) error

func ConfigDBUnlock

func ConfigDBUnlock(token string) error

func GetDBStatsTotals

func GetDBStatsTotals() (uint, time.Duration, time.Duration)

func HandleSIGUSR2

func HandleSIGUSR2()

func NewValidationSession

func NewValidationSession() (*cvl.CVL, error)

func ReconfigureCache

func ReconfigureCache() error

func ReconfigureStats

func ReconfigureStats() error

func SignalHandler

func SignalHandler()

Types

type CommitIdDbDs

type CommitIdDbDs struct {
	CommitID string
}

CommitIdDbDs is a Datastore modeled from a saved-to-disk CONFIG_DB of a commit-id which is stored in the CHECKPOINTS_DIR, with a CHECKPOINT_EXT (cp.json)

func (*CommitIdDbDs) Attributes

func (ds *CommitIdDbDs) Attributes() map[string]string

type DB

type DB struct {
	Opts *Options
	// contains filtered or unexported fields
}

DB is the main type.

func NewDB

func NewDB(opt Options) (*DB, error)

NewDB is the factory method to create new DB's.

func PubSubRpcDB

func PubSubRpcDB(opt Options, responseChannel string) (*DB, error)

func SubscribeDB

func SubscribeDB(opt Options, skeys []*SKey, handler HFunc) (*DB, error)

SubscribeDB is the factory method to create a subscription to the DB. The returned instance can only be used for Subscription.

func SubscribeDBSA

func SubscribeDBSA(opt Options, skeys []*SKey, handler HFuncSA) (*DB, error)

SubscribeDBSA is Session Aware factory method to create a subscription to DB The returned instance can only be used for Subscription.

func (*DB) AbortSessTx

func (d *DB) AbortSessTx() error

func (*DB) AbortTx

func (d *DB) AbortTx() error

func (*DB) AppendWatchTx

func (d *DB) AppendWatchTx(w []WatchKeys, tss []*TableSpec) error

func (*DB) ClosePubSubRpcDB

func (d *DB) ClosePubSubRpcDB() error

func (*DB) CommitSessTx

func (d *DB) CommitSessTx() error

func (*DB) CommitTx

func (d *DB) CommitTx() error

func (*DB) CreateEntry

func (d *DB) CreateEntry(ts *TableSpec, key Key, value Value) error

CreateEntry creates an entry(row) in the table.

func (*DB) DeclareSP

func (d *DB) DeclareSP() error

func (*DB) DeleteDB

func (d *DB) DeleteDB() error

DeleteDB is the gentle way to close the DB connection.

func (*DB) DeleteEntry

func (d *DB) DeleteEntry(ts *TableSpec, key Key) error

DeleteEntry deletes an entry(row) in the table.

func (*DB) DeleteEntryFields

func (d *DB) DeleteEntryFields(ts *TableSpec, key Key, value Value) error

DeleteEntryFields deletes some fields/columns in an entry(row) in the table.

func (*DB) DeleteKeys

func (d *DB) DeleteKeys(ts *TableSpec, key Key) error

DeleteKeys deletes all entry/row keys matching a pattern.

func (*DB) DeleteMapAll

func (d *DB) DeleteMapAll(ts *TableSpec) error

DeleteMapAll - There is no transaction support on these. TBD: Unexport this. : Lower case it, and reference too

func (*DB) DeleteTable

func (d *DB) DeleteTable(ts *TableSpec) error

DeleteTable deletes the entire table.

func (*DB) ExistKeysPattern

func (d *DB) ExistKeysPattern(ts *TableSpec, pat Key) (bool, error)

ExistKeysPattern checks if a key pattern exists in a table Note:

  1. Statistics do not capture when the CAS Tx Cache results in a quicker response. This is to avoid mis-interpreting per-connection statistics.

func (*DB) Export

func (d *DB) Export(filePath string) (outFile string, err error)

Export writes the full DB contents to a file in sonic db json format. Includes contents from transaction cache, if present. Uses the sonic-cfggen tool to remove system default entries/keys and apply standard format.

If filePath is empty or has '*', it will be expanded to a random name similar to the os.CreateTemp() API. Actual file path will be returned to the caller (outFile). Contents will be written and formatted in multiple steps. Hence outFile may a valid path (but with garbage contents) even if there was an error. Caller must disregard its contents and cleanup the file when outFile != "" && err != nil.

func (*DB) ExportRaw

func (d *DB) ExportRaw(filePath string) (outFile string, err error)

ExportRaw is similar to Export(), but does not process the output using sonic-cfggen tool.

func (*DB) Get

func (d *DB) Get(key string) (string, error)

Get gets the value of the key

func (*DB) GetConfig

func (d *DB) GetConfig(tables []*TableSpec, opt *GetConfigOptions) (map[TableSpec]Table, error)

GetConfig API to get some tables. Very expensive operation (time/resources) If len(tables) == 0, return all tables in the CONFIG_DB Notes:

  • Only supported on the CONFIG_DB
  • The keys of the table should not contain TableSeparator, or KeySeparator (CONFIG_DB table keys should not contain "|" (defaults for TableSeparator, or KeySeparator))
  • Only supported when write/set is disabled [IsWriteDisabled == true ]
  • OnChange not supported [IsEnableOnChange == false]
  • PCC (per_connection_cache) is not supported, and it will log an error/ warning.

func (*DB) GetDebugCvlECD

func (d *DB) GetDebugCvlECD() interface{}

func (*DB) GetDebugDB

func (d *DB) GetDebugDB() interface{}

func (*DB) GetDebugTxCmds

func (d *DB) GetDebugTxCmds() interface{}

func (*DB) GetEntries

func (d *DB) GetEntries(ts *TableSpec, keys []Key) ([]Value, []error)

GetEntries retrieves the entries from the table for the given keys using redis pipelining, if the key is not present in the cache. returns slice of value and error; Note: error slice will be nil, if there is no error occurred for any of the given keys.

func (*DB) GetEntry

func (d *DB) GetEntry(ts *TableSpec, key Key) (Value, error)

GetEntry retrieves an entry(row) from the table.

func (*DB) GetKeys

func (d *DB) GetKeys(ts *TableSpec) ([]Key, error)

GetKeys retrieves all entry/row keys.

func (*DB) GetKeysByPattern

func (d *DB) GetKeysByPattern(ts *TableSpec, pattern string) ([]Key, error)

GetKeysByPattern retrieves all entry/row keys matching with the given pattern Deprecated: use GetKeysPattern()

func (*DB) GetKeysPattern

func (d *DB) GetKeysPattern(ts *TableSpec, pat Key) ([]Key, error)

func (*DB) GetMAP

func (d *DB) GetMAP(ts *TableSpec) (MAP, error)

GetMAP gets the entire Map.

func (*DB) GetMap

func (d *DB) GetMap(ts *TableSpec, mapKey string) (string, error)

func (*DB) GetMapAll

func (d *DB) GetMapAll(ts *TableSpec) (Value, error)

func (*DB) GetRpcResponse

func (d *DB) GetRpcResponse(numResponses int, timeout int) ([]string, error)

func (*DB) GetStats

func (d *DB) GetStats() *DBStats

GetStats primarily returns CAS Transaction Cmds list length in AllTables The TxCmdsLen is always in the ret.AllTables.TxCmdsLen

func (*DB) GetTable

func (d *DB) GetTable(ts *TableSpec) (Table, error)

GetTable gets the entire table.

func (*DB) GetTablePattern

func (d *DB) GetTablePattern(ts *TableSpec, pat Key) (Table, error)

GetTablePattern is similar to GetTable, except, it gets a subset of the table restricted by the key pattern "pat". It is expected that there will be a single call to the underlying go-redis layer, perhaps through the use of a script. However, the caller is not advised to rely on this, and encouraged to use this instead of the current GetTable() for reasonably sized subsets of tables ("reasonably sized" to be determined by experiments) to obtain a more performant behavior. Note: The time/hit statistics do not cover the error cases.

func (*DB) HasSP

func (d *DB) HasSP() bool

func (*DB) IsDirtified

func (d *DB) IsDirtified() bool

func (*DB) IsOpen

func (d *DB) IsOpen() bool

func (*DB) ModEntry

func (d *DB) ModEntry(ts *TableSpec, key Key, value Value) error

ModEntry modifies an entry(row) in the table.

func (*DB) Name

func (d *DB) Name() string

func (*DB) NewScanCursor

func (d *DB) NewScanCursor(ts *TableSpec, pattern Key, scOpts *ScanCursorOpts) (*ScanCursor, error)

NewScanCursor Factory method to create ScanCursor; Scan cursor will not be supported for write enabled DB.

func (*DB) NewValidationSession

func (d *DB) NewValidationSession() (*cvl.CVL, error)

func (*DB) OnChangeCacheDelete

func (d *DB) OnChangeCacheDelete(ts *TableSpec, key Key) (Value, error)

OnChangeCacheDelete deletes an entry from the on_change cache. Returns the previously cached Value object; or an empty Value if there was no such cache entry.

func (*DB) OnChangeCacheUpdate

func (d *DB) OnChangeCacheUpdate(ts *TableSpec, key Key) (Value, Value, error)

OnChangeCacheUpdate reads a db entry from redis and updates the on_change cache. Returns both previously cached Value and current Value. Previous Value will be empty if there was no such cache entry earlier. Returns an error if DB entry does not exists or could not be read.

func (*DB) Publish

func (d *DB) Publish(channel string, message interface{}) error

func (*DB) RegisterTableForOnChangeCaching

func (d *DB) RegisterTableForOnChangeCaching(ts *TableSpec) error

func (*DB) ReleaseSP

func (d *DB) ReleaseSP() error

func (*DB) Rollback2SP

func (d *DB) Rollback2SP() error

func (*DB) RunScript

func (d *DB) RunScript(script *redis.Script, keys []string, args ...interface{}) *redis.Cmd

func (*DB) SendRpcRequest

func (d *DB) SendRpcRequest(requestChannel string, message string) (int, error)

func (*DB) SetEntry

func (d *DB) SetEntry(ts *TableSpec, key Key, value Value) error

SetEntry sets an entry(row) in the table.

func (*DB) SetMap

func (d *DB) SetMap(ts *TableSpec, mapKey string, mapValue string) error

SetMap - There is no transaction support on these.

func (*DB) StartSessTx

func (d *DB) StartSessTx(w []WatchKeys, tss []*TableSpec) error

StartSessTx CommitSessTx AbortSessTx Originally (roughly 4.0.x and before) we have StartTx(), CommitTx(), and AbortTx() which represented the API for invoking redis CAS (Check-And-Set) Transactions. With the attempt at Config Sessions a.k.a. Two-Phase Commit, these APIs may have to be re-arranged, because a few of the Action Callback handlers in the transformer invoke these API directly. Ideally all db.[Start|Commit|Abort]Tx need to be rewritten to cs.[Start|Commit|Abort]Tx. But, that would mean changing App code.

func (*DB) StartTx

func (d *DB) StartTx(w []WatchKeys, tss []*TableSpec) error

func (*DB) StoreCVLHint

func (d *DB) StoreCVLHint(key string, value interface{}) error

StoreCVLHint Stores a key, value hint for CVL Session Custom Validation CBs

func (DB) String

func (d DB) String() string

func (*DB) UnsubscribeDB

func (d *DB) UnsubscribeDB() error

UnsubscribeDB is used to close a DB subscription

type DBCacheConfig

type DBCacheConfig struct {
	PerConnection bool            // Enable per DB conn cache
	Global        bool            // Enable global cache (TBD)
	CacheTables   map[string]bool // Only cache these tables.
	// Empty == Cache all tables
	NoCacheTables map[string]bool // Do not cache these tables.
	// "all" == Do not cache any tables
	CacheMaps map[string]bool // Only cache these maps.
	// Empty == Cache all maps
	NoCacheMaps map[string]bool // Do not cache these maps

}

type DBDatastore

type DBDatastore interface {

	// Eg: Commit-ID, Filename(Future), Snapshot-ID(Future), Writable(Future)
	Attributes() map[string]string
}

type DBGlobalCache

type DBGlobalCache struct {
	Databases [MaxDB]dbCache
}

type DBGlobalStats

type DBGlobalStats struct {
	New      uint `json:"new-db"`
	Delete   uint `json:"delete-db"`
	PeakOpen uint `json:"peak-open"`

	NewTime time.Duration `json:"new-time,omitempty"`
	NewPeak time.Duration `json:"peak-new-time,omitempty"`

	ZeroGetHits uint `json:"zero-get-ops-db"`

	Databases []DBStats `json:"dbs,omitempty"`
}

func GetDBStats

func GetDBStats() (*DBGlobalStats, error)

type DBNum

type DBNum int

DBNum type indicates the type of DB (Eg: ConfigDB, ApplDB, ...).

const (
	ApplDB        DBNum = iota // 0
	AsicDB                     // 1
	CountersDB                 // 2
	LogLevelDB                 // 3
	ConfigDB                   // 4
	FlexCounterDB              // 5
	StateDB                    // 6
	SnmpDB                     // 7
	ErrorDB                    // 8
	EventDB                    // 9
	// All DBs added above this line, please ----
	MaxDB //  The Number of DBs
)

func GetdbNameToIndex

func GetdbNameToIndex(dbName string) DBNum

func (DBNum) ID

func (dbNo DBNum) ID() int

ID returns the redis db id for this DBNum

func (DBNum) Name

func (dbNo DBNum) Name() string

func (DBNum) String

func (dbNo DBNum) String() string

type DBStats

type DBStats struct {
	Name      string           `json:"name"`
	AllTables Stats            `json:"all-tables"`
	AllMaps   Stats            `json:"all-maps"`
	Tables    map[string]Stats `json:"tables,omitempty"`
	Maps      map[string]Stats `json:"maps,omitempty"`
}

func (*DBStats) Empty

func (dbstats *DBStats) Empty() bool

type DBStatsConfig

type DBStatsConfig struct {
	TimeStats  bool
	TableStats bool
	MapStats   bool
}

type DefaultDbDs

type DefaultDbDs struct {
}

DefaultDbDs is the default Datastore representing the data stored in the CONFIG_DB database(/selection) of the redis-server

func (*DefaultDbDs) Attributes

func (ds *DefaultDbDs) Attributes() map[string]string

type GetConfigOptions

type GetConfigOptions struct {
	ScanCountHint int64 // Hint of redis work required for Scan
	AllowWritable bool  // Allow on writable enabled DB object too
}

type HFunc

type HFunc func(*DB, *SKey, *Key, SEvent) error

HFunc gives the name of the table, and other per-table customizations.

type HFuncSA

type HFuncSA func(*DB, SessNotif, string, *SKey, *Key, SEvent)

HFuncSA is Session Aware HFunc

type Key

type Key struct {
	Comp []string
}

Key is the db key components without table name prefix. (Eg: { Comp : [] string { "acl1", "rule1" } } ).

func NewKey

func NewKey(comps ...string) *Key

NewKey returns a Key object with given key components

func (Key) Copy

func (k Key) Copy() (rK Key)

Copy returns a (deep) copy of the given Key

func (Key) Equals

func (k Key) Equals(other Key) bool

Equals checks if db key k equals to the other key.

func (Key) Get

func (k Key) Get(index int) string

Get returns the key component at given index

func (*Key) IsAllKeyPattern

func (k *Key) IsAllKeyPattern() bool

IsAllKeyPattern returns true if it is an all key wildcard pattern. (i.e. A key with a single component "*")

func (Key) IsPattern

func (k Key) IsPattern() bool

IsPattern checks if the key has redis glob-style pattern. Supports only '*' and '?' wildcards.

func (Key) Len

func (k Key) Len() int

Len returns number of components in the Key

func (Key) Matches

func (k Key) Matches(pattern Key) bool

Matches checks if db key k matches a key pattern.

func (Key) String

func (k Key) String() string

type LockStruct

type LockStruct struct {
	Name string // Lockname
	Id   string // ID Unique to the executable (Eg: Session-Token, "0-0")
	// contains filtered or unexported fields
}

type MAP

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

func (*MAP) GetMap

func (m *MAP) GetMap(mapKey string) (string, error)

func (*MAP) GetMapAll

func (m *MAP) GetMapAll() (Value, error)

type Options

type Options struct {
	DBNo               DBNum
	InitIndicator      string
	TableNameSeparator string //Overriden by the DB config file's separator.
	KeySeparator       string //Overriden by the DB config file's separator.
	IsWriteDisabled    bool   //Is write/set mode disabled ?
	IsCacheEnabled     bool   //Is cache (Per Connection) allowed?

	// OnChange caching for the DBs passed from Translib's Subscribe Infra
	// to the Apps. SDB is the SubscribeDB() returned handle on which
	// notifications of change are received.
	IsOnChangeEnabled bool // whether OnChange cache enabled

	SDB *DB //The subscribeDB handle (Future Use)

	IsSubscribeDB bool // Opened by SubscribeDB(Sess)?

	IsSession        bool // Is this a Candidate Config DB ?
	ConfigDBLazyLock bool // For Non-CCDB Action()/RPC (may write to ConfigDB)
	TxCmdsLim        int  // Tx Limit for Candidate Config DB

	IsReplaced  bool // Is candidate Config DB updated by config-replace operation.
	IsCommitted bool // Is candidate Config DB committed.

	// Alternate Datastore: By default, we query redis CONFIG_DB.
	// Front-end an alternate source of data. (Eg: config_db.cp.json
	// from a saved commit-id, or snapshot)
	Datastore DBDatastore

	DisableCVLCheck bool
}

Options gives parameters for opening the redis client.

func (Options) String

func (o Options) String() string

type SEvent

type SEvent int
const (
	SEventNone  SEvent = iota // No Op
	SEventHSet                // HSET, HMSET, and its variants
	SEventHDel                // HDEL, also SEventDel generated, if HASH is becomes empty
	SEventDel                 // DEL, & also if key gets deleted (empty HASH, expire,..)
	SEventOther               // Some other command not covered above.

	// The below two are always sent regardless of SEMap.
	SEventClose // Close requested due to Unsubscribe() called.
	SEventErr   // Error condition. Call Unsubscribe, after return.
)

type SKey

type SKey struct {
	Ts     *TableSpec
	Key    *Key
	SEMap  map[SEvent]bool // nil map indicates subscribe to all
	Opaque interface{}     // opaque data set by the caller
}

SKey is (TableSpec, Key, []SEvent) 3-tuples to be watched in a Transaction.

type ScanCursor

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

func (*ScanCursor) DeleteScanCursor

func (sc *ScanCursor) DeleteScanCursor() error

DeleteScanCursor Gently release state/cache of ScanCursor

func (*ScanCursor) GetNextFields

func (sc *ScanCursor) GetNextFields(scOpts *ScanCursorOpts) (Value, bool, error)

GetNextFields retrieves a few matching fields. bool returns true if the scan is complete.

func (*ScanCursor) GetNextKeys

func (sc *ScanCursor) GetNextKeys(scOpts *ScanCursorOpts) ([]Key, bool, error)

GetNextKeys retrieves a few keys. bool returns true if the scan is complete.

func (*ScanCursor) GetNextRedisKeys

func (sc *ScanCursor) GetNextRedisKeys(scOpts *ScanCursorOpts) ([]string, bool, error)

GetNextRedisKeys retrieves a few redisKeys. bool returns true if the scan is complete

type ScanCursorOpts

type ScanCursorOpts struct {
	CountHint       int64  // Hint of redis work required
	ReturnFixed     bool   // (TBD) Return exactly CountHint # of keys
	AllowDuplicates bool   // Do not suppress redis duplicate keys
	ScanType               // To mention the type of scan; default is KeyScanType
	FldScanPatt     string // Field pattern to scan
	AllowWritable   bool   // Allow on write enabled DB object; ignores tx cache
}

type ScanType

type ScanType int

ScanType type indicates the type of scan (Eg: KeyScanType, FieldScanType).

const (
	KeyScanType ScanType = iota // 0
	FieldScanType
)

type SessNotif

type SessNotif uint8
const (
	RunningConfigNotif    SessNotif = iota // 0
	CandidateConfigNotif                   // 1
	CandidateConfigOpened                  // 2
	CandidateConfigClosed                  // 3
)

func (SessNotif) String

func (sN SessNotif) String() string

type Stats

type Stats struct {
	Hits uint `json:"hits,omitempty"`

	Time time.Duration `json:"total-time,omitempty"`
	Peak time.Duration `json:"peak-time,omitempty"`

	GetEntryHits       uint `json:"get-entry-hits,omitempty"`
	GetKeysHits        uint `json:"get-keys-hits,omitempty"`
	GetKeysPatternHits uint `json:"get-keys-pattern-hits,omitempty"`
	GetMapHits         uint `json:"get-map-hits,omitempty"`
	GetMapAllHits      uint `json:"get-map-all-hits,omitempty"`
	GetEntriesHits     uint `json:"get-entries-hits,omitempty"`

	GetTablePatternHits  uint `json:"get-table-pattern-hits,omitempty"`
	ExistsKeyPatternHits uint `json:"exists-key-pattern-hits,omitempty"`

	NewScanCursorHits    uint `json:"new-scan-cursor-hits,omitempty"`
	DeleteScanCursorHits uint `json:"delete-scan-cursor-hits,omitempty"`
	GetNextKeysHits      uint `json:"get-next-keys-hits,omitempty"`

	GetEntryCacheHits       uint `json:"get-entry-cache-hits,omitempty"`
	GetKeysCacheHits        uint `json:"keys-cache-hits,omitempty"`
	GetKeysPatternCacheHits uint `json:"keys-pattern-cache-hits,omitempty"`
	GetMapCacheHits         uint `json:"get-map-cache-hits,omitempty"`
	GetMapAllCacheHits      uint `json:"get-map-all-cache-hits,omitempty"`

	GetTablePatternCacheHits  uint `json:"get-table-pattern-cache-hits,omitempty"`
	ExistsKeyPatternCacheHits uint `json:"exists-key-pattern-cache-hits,omitempty"`

	GetEntryTime       time.Duration `json:"get-entry-time,omitempty"`
	GetKeysTime        time.Duration `json:"get-keys-time,omitempty"`
	GetKeysPatternTime time.Duration `json:"get-keys-pattern-time,omitempty"`
	GetMapTime         time.Duration `json:"get-map-time,omitempty"`
	GetMapAllTime      time.Duration `json:"get-map-all-time,omitempty"`
	GetNextKeysTime    time.Duration `json:"get-next-keys-time,omitempty"`
	GetEntriesTime     time.Duration `json:"get-entries-time,omitempty"`

	GetTablePatternTime  time.Duration `json:"get-table-pattern-time,omitempty"`
	ExistsKeyPatternTime time.Duration `json:"exists-key-pattern-time,omitempty"`

	GetEntryPeak       time.Duration `json:"get-entry-peak-time,omitempty"`
	GetKeysPeak        time.Duration `json:"get-keys-peak-time,omitempty"`
	GetKeysPatternPeak time.Duration `json:"get-keys-pattern-peak-time,omitempty"`
	GetMapPeak         time.Duration `json:"get-map-peak-time,omitempty"`
	GetMapAllPeak      time.Duration `json:"get-map-all-peak-time,omitempty"`
	GetNextKeysPeak    time.Duration `json:"get-next-keys-peak-time,omitempty"`
	GetEntriesPeak     time.Duration `json:"get-entries-peak-time,omitempty"`

	GetTablePatternPeak  time.Duration `json:"get-table-pattern-peak-time,omitempty"`
	ExistsKeyPatternPeak time.Duration `json:"exists-key-pattern-peak-time,omitempty"`

	// CAS Transaction Cmds Stats: Currently Only Used by GetStats() for
	// the Candidate Configuration (CC) DB
	// Running Totals (i.e. over several DB connections) are not maintained
	// reliably.
	TxCmdsLen uint `json:"tx-cmds-len"`
}

type Table

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

func (*Table) GetEntry

func (t *Table) GetEntry(key Key) (Value, error)

GetEntry method retrieves an entry/row from a previously read table.

func (*Table) GetKeys

func (t *Table) GetKeys() ([]Key, error)

GetKeys method retrieves all entry/row keys from a previously read table.

type TableSpec

type TableSpec struct {
	Name string
	// https://github.com/project-arlo/sonic-mgmt-framework/issues/29
	// CompCt tells how many components in the key. Only the last component
	// can have TableSeparator as part of the key. Otherwise, we cannot
	// tell where the key component begins.
	CompCt int
	// NoDelete flag (if it is set to true) is to skip the row entry deletion from
	// the table when the "SetEntry" or "ModEntry" method is called with empty Value Field map.
	NoDelete bool
}

TableSpec gives the name of the table, and other per-table customizations. (Eg: { Name: ACL_TABLE" }).

func Tables2TableSpecs

func Tables2TableSpecs(tables []string) []*TableSpec

Tables2TableSpecs - Convenience function to make TableSpecs from strings. This only works on Tables having key components without TableSeparator as part of the key.

type Value

type Value struct {
	Field map[string]string
}

Value gives the fields as a map. (Eg: { Field: map[string]string { "type" : "l3v6", "ports" : "eth0" } } ).

func (Value) Compare4TxOps

func (v Value) Compare4TxOps(dst Value) (isHSet, isHDel bool)

Compare4TxOps gives the Redis Ops/Notifs that are to be generated whilst going from a v Value to dst Value. Returns if HSet, and/or HDel needs to be performed

func (*Value) ContainsAll

func (v *Value) ContainsAll(other *Value) bool

ContainsAll returns true if this value is a superset of the other value.

func (Value) Copy

func (v Value) Copy() (rV Value)

func (*Value) Equals

func (v *Value) Equals(other *Value) bool

Equals returns true if this value contains same set of attributes as the other value

func (*Value) Get

func (v *Value) Get(name string) string

Get returns the value of a field. Returns empty string if the field does not exists. Use Has() function to check existance of field.

func (*Value) GetInt

func (v *Value) GetInt(name string) (int, error)

GetInt returns value of a field as int. Returns 0 if the field does not exists. Returns an error if the field value is not a number.

func (*Value) GetList

func (v *Value) GetList(name string) []string

GetList returns the value of a an array field. A "@" suffix is automatically appended to the field name if not present (as per swsssdk convention). Field value is split by comma and resulting slice is returned. Empty slice is returned if field not exists.

func (*Value) Has

func (v *Value) Has(name string) bool

Has function checks if a field exists.

func (*Value) IsPopulated

func (v *Value) IsPopulated() bool

func (*Value) Remove

func (v *Value) Remove(name string)

Remove function removes a field from this Value.

func (*Value) Set

func (v *Value) Set(name, value string)

Set function sets a string value for a field.

func (*Value) SetInt

func (v *Value) SetInt(name string, value int)

SetInt sets an integer value for a field.

func (*Value) SetList

func (v *Value) SetList(name string, items []string)

SetList function sets an list value to a field. Field name and value are formatted as per swsssdk conventions: - A "@" suffix is appended to key name - Field value is the comma separated string of list items

func (Value) String

func (v Value) String() string

type WatchKeys

type WatchKeys struct {
	Ts  *TableSpec
	Key *Key
}

WatchKeys is array of (TableSpec, Key) tuples to be watched in a Transaction.

func (WatchKeys) String

func (w WatchKeys) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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