kvstore

package
v7.6.1 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2024 License: Apache-2.0 Imports: 15 Imported by: 1

Documentation

Overview

* Copyright 2018-2024 Open Networking Foundation (ONF) and the ONF Contributors

* Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at

* http://www.apache.org/licenses/LICENSE-2.0

* Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License.

  • Copyright 2020-2024 Open Networking Foundation (ONF) and the ONF Contributors *
  • Licensed under the Apache License, Version 2.0 (the "License");
  • you may not use this file except in compliance with the License.
  • You may obtain a copy of the License at *
  • http://www.apache.org/licenses/LICENSE-2.0 *
  • Unless required by applicable law or agreed to in writing, software
  • distributed under the License is distributed on an "AS IS" BASIS,
  • WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  • See the License for the specific language governing permissions and
  • limitations under the License.

* Copyright 2018-2024 Open Networking Foundation (ONF) and the ONF Contributors

* Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at

* http://www.apache.org/licenses/LICENSE-2.0

* Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License.

* Copyright 2021-2024 Open Networking Foundation (ONF) and the ONF Contributors

* Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at

* http://www.apache.org/licenses/LICENSE-2.0

* Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License.

* Copyright 2018-2024 Open Networking Foundation (ONF) and the ONF Contributors

* Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at

* http://www.apache.org/licenses/LICENSE-2.0

* Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License.

* Copyright 2018-2024 Open Networking Foundation (ONF) and the ONF Contributors

* Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at

* http://www.apache.org/licenses/LICENSE-2.0

* Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License.

Index

Constants

View Source
const (
	PUT = iota
	DELETE
	CONNECTIONDOWN
	UNKNOWN
)

These constants represent the event types returned by the KV client

Variables

This section is empty.

Functions

func ToByte

func ToByte(value interface{}) ([]byte, error)

ToByte converts an interface value to a []byte. The interface should either be of a string type or []byte. Otherwise, an error is returned.

func ToString

func ToString(value interface{}) (string, error)

ToString converts an interface value to a string. The interface should either be of a string type or []byte. Otherwise, an error is returned.

Types

type Client

type Client interface {
	List(ctx context.Context, key string) (map[string]*KVPair, error)
	Get(ctx context.Context, key string) (*KVPair, error)
	Put(ctx context.Context, key string, value interface{}) error
	Delete(ctx context.Context, key string) error
	DeleteWithPrefix(ctx context.Context, prefixKey string) error
	Watch(ctx context.Context, key string, withPrefix bool) chan *Event
	IsConnectionUp(ctx context.Context) bool // timeout in second
	CloseWatch(ctx context.Context, key string, ch chan *Event)
	Close(ctx context.Context)

	// These APIs are not used.  They will be cleaned up in release Voltha 2.9.
	// It's not cleaned now to limit changes in all components
	Reserve(ctx context.Context, key string, value interface{}, ttl time.Duration) (interface{}, error)
	ReleaseReservation(ctx context.Context, key string) error
	ReleaseAllReservations(ctx context.Context) error
	RenewReservation(ctx context.Context, key string) error
	AcquireLock(ctx context.Context, lockName string, timeout time.Duration) error
	ReleaseLock(lockName string) error
}

Client represents the set of APIs a KV Client must implement

type EtcdClient

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

EtcdClient represents the Etcd KV store client

func NewEtcdClient

func NewEtcdClient(ctx context.Context, addr string, timeout time.Duration, level log.LogLevel) (*EtcdClient, error)

NewEtcdClient returns a new client for the Etcd KV store

func NewEtcdCustomClient

func NewEtcdCustomClient(ctx context.Context, addr string, timeout time.Duration, level log.LogLevel) (*EtcdClient, error)

NewEtcdCustomClient returns a new client for the Etcd KV store allowing the called to specify etcd client configuration

func (*EtcdClient) AcquireLock

func (c *EtcdClient) AcquireLock(ctx context.Context, lockName string, timeout time.Duration) error

AcquireLock is deprecated

func (*EtcdClient) Close

func (c *EtcdClient) Close(ctx context.Context)

Close closes all the connection in the pool store client

func (*EtcdClient) CloseWatch

func (c *EtcdClient) CloseWatch(ctx context.Context, key string, ch chan *Event)

CloseWatch closes a specific watch. Both the key and the channel are required when closing a watch as there may be multiple listeners on the same key. The previously created channel serves as a key

func (*EtcdClient) Delete

func (c *EtcdClient) Delete(ctx context.Context, key string) error

Delete removes a key from the KV store. Timeout defines how long the function will wait for a response

func (*EtcdClient) DeleteWithPrefix

func (c *EtcdClient) DeleteWithPrefix(ctx context.Context, prefixKey string) error

func (*EtcdClient) Get

func (c *EtcdClient) Get(ctx context.Context, key string) (*KVPair, error)

Get returns a key-value pair for a given key. Timeout defines how long the function will wait for a response

func (*EtcdClient) IsConnectionUp

func (c *EtcdClient) IsConnectionUp(ctx context.Context) bool

IsConnectionUp returns whether the connection to the Etcd KV store is up. If a timeout occurs then it is assumed the connection is down or unreachable.

func (*EtcdClient) List

func (c *EtcdClient) List(ctx context.Context, key string) (map[string]*KVPair, error)

List returns an array of key-value pairs with key as a prefix. Timeout defines how long the function will wait for a response

func (*EtcdClient) Put

func (c *EtcdClient) Put(ctx context.Context, key string, value interface{}) error

Put writes a key-value pair to the KV store. Value can only be a string or []byte since the etcd API accepts only a string as a value for a put operation. Timeout defines how long the function will wait for a response

func (*EtcdClient) ReleaseAllReservations

func (c *EtcdClient) ReleaseAllReservations(ctx context.Context) error

ReleaseAllReservations is deprecated

func (*EtcdClient) ReleaseLock

func (c *EtcdClient) ReleaseLock(lockName string) error

ReleaseLock is deprecated

func (*EtcdClient) ReleaseReservation

func (c *EtcdClient) ReleaseReservation(ctx context.Context, key string) error

ReleaseReservation is deprecated

func (*EtcdClient) RenewReservation

func (c *EtcdClient) RenewReservation(ctx context.Context, key string) error

RenewReservation is deprecated

func (*EtcdClient) Reserve

func (c *EtcdClient) Reserve(ctx context.Context, key string, value interface{}, ttl time.Duration) (interface{}, error)

Reserve is deprecated

func (*EtcdClient) Watch

func (c *EtcdClient) Watch(ctx context.Context, key string, withPrefix bool) chan *Event

Watch provides the watch capability on a given key. It returns a channel onto which the callee needs to listen to receive Events.

type EtcdClientAllocator

type EtcdClientAllocator interface {
	Get(context.Context) (*clientv3.Client, error)
	Put(*clientv3.Client)
	Close(ctx context.Context)
}

EtcdClientAllocator represents a generic interface to allocate an Etcd Client

func NewRoundRobinEtcdClientAllocator

func NewRoundRobinEtcdClientAllocator(endpoints []string, timeout time.Duration, capacity, maxUsage int, level log.LogLevel) (EtcdClientAllocator, error)

NewRoundRobinEtcdClientAllocator creates a new ETCD Client Allocator using a Round Robin scheme

type Event

type Event struct {
	EventType int
	Key       interface{}
	Value     interface{}
	Version   int64
}

Event is generated by the KV client when a key change is detected

func NewEvent

func NewEvent(eventType int, key interface{}, value interface{}, version int64) *Event

NewEvent creates a new Event object

type KVPair

type KVPair struct {
	Key     string
	Value   interface{}
	Version int64
	Session string
	Lease   int64
}

KVPair is a common wrapper for key-value pairs returned from the KV store

func NewKVPair

func NewKVPair(key string, value interface{}, session string, lease int64, version int64) *KVPair

NewKVPair creates a new KVPair object

type RedisClient

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

func NewRedisClient

func NewRedisClient(addr string, timeout time.Duration, useSentinel bool) (*RedisClient, error)

func (*RedisClient) AcquireLock

func (c *RedisClient) AcquireLock(ctx context.Context, lockName string, timeout time.Duration) error

func (*RedisClient) Close

func (c *RedisClient) Close(ctx context.Context)

func (*RedisClient) CloseWatch

func (c *RedisClient) CloseWatch(ctx context.Context, key string, ch chan *Event)

func (*RedisClient) Delete

func (c *RedisClient) Delete(ctx context.Context, key string) error

func (*RedisClient) DeleteWithPrefix

func (c *RedisClient) DeleteWithPrefix(ctx context.Context, prefixKey string) error

func (*RedisClient) Get

func (c *RedisClient) Get(ctx context.Context, key string) (*KVPair, error)

func (*RedisClient) IsConnectionUp

func (c *RedisClient) IsConnectionUp(ctx context.Context) bool

func (*RedisClient) List

func (c *RedisClient) List(ctx context.Context, key string) (map[string]*KVPair, error)

func (*RedisClient) Put

func (c *RedisClient) Put(ctx context.Context, key string, value interface{}) error

func (*RedisClient) ReleaseAllReservations

func (c *RedisClient) ReleaseAllReservations(ctx context.Context) error

func (*RedisClient) ReleaseLock

func (c *RedisClient) ReleaseLock(lockName string) error

func (*RedisClient) ReleaseReservation

func (c *RedisClient) ReleaseReservation(ctx context.Context, key string) error

func (*RedisClient) RenewReservation

func (c *RedisClient) RenewReservation(ctx context.Context, key string) error

func (*RedisClient) Reserve

func (c *RedisClient) Reserve(ctx context.Context, key string, value interface{}, ttl time.Duration) (interface{}, error)

func (*RedisClient) Watch

func (c *RedisClient) Watch(ctx context.Context, key string, withPrefix bool) chan *Event

Jump to

Keyboard shortcuts

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