2019-11-28 20:56:04 +00:00
|
|
|
package kv
|
|
|
|
|
|
|
|
import (
|
2022-08-11 13:42:07 +00:00
|
|
|
"context"
|
|
|
|
|
2022-01-12 13:42:21 +00:00
|
|
|
"github.com/kvtools/valkeyrie/store"
|
2020-09-16 13:46:04 +00:00
|
|
|
"github.com/traefik/traefik/v2/pkg/log"
|
2019-11-28 20:56:04 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type storeWrapper struct {
|
|
|
|
store.Store
|
|
|
|
}
|
|
|
|
|
2022-08-11 13:42:07 +00:00
|
|
|
func (s *storeWrapper) Put(ctx context.Context, key string, value []byte, options *store.WriteOptions) error {
|
2019-11-28 20:56:04 +00:00
|
|
|
log.WithoutContext().Debugf("Put: %s", key, string(value))
|
|
|
|
|
|
|
|
if s.Store == nil {
|
|
|
|
return nil
|
|
|
|
}
|
2022-08-11 13:42:07 +00:00
|
|
|
return s.Store.Put(ctx, key, value, options)
|
2019-11-28 20:56:04 +00:00
|
|
|
}
|
|
|
|
|
2022-08-11 13:42:07 +00:00
|
|
|
func (s *storeWrapper) Get(ctx context.Context, key string, options *store.ReadOptions) (*store.KVPair, error) {
|
2019-11-28 20:56:04 +00:00
|
|
|
log.WithoutContext().Debugf("Get: %s", key)
|
|
|
|
|
|
|
|
if s.Store == nil {
|
|
|
|
return nil, nil
|
|
|
|
}
|
2022-08-11 13:42:07 +00:00
|
|
|
return s.Store.Get(ctx, key, options)
|
2019-11-28 20:56:04 +00:00
|
|
|
}
|
|
|
|
|
2022-08-11 13:42:07 +00:00
|
|
|
func (s *storeWrapper) Delete(ctx context.Context, key string) error {
|
2019-11-28 20:56:04 +00:00
|
|
|
log.WithoutContext().Debugf("Delete: %s", key)
|
|
|
|
|
|
|
|
if s.Store == nil {
|
|
|
|
return nil
|
|
|
|
}
|
2022-08-11 13:42:07 +00:00
|
|
|
return s.Store.Delete(ctx, key)
|
2019-11-28 20:56:04 +00:00
|
|
|
}
|
|
|
|
|
2022-08-11 13:42:07 +00:00
|
|
|
func (s *storeWrapper) Exists(ctx context.Context, key string, options *store.ReadOptions) (bool, error) {
|
2019-11-28 20:56:04 +00:00
|
|
|
log.WithoutContext().Debugf("Exists: %s", key)
|
|
|
|
|
|
|
|
if s.Store == nil {
|
|
|
|
return true, nil
|
|
|
|
}
|
2022-08-11 13:42:07 +00:00
|
|
|
return s.Store.Exists(ctx, key, options)
|
2019-11-28 20:56:04 +00:00
|
|
|
}
|
|
|
|
|
2022-08-11 13:42:07 +00:00
|
|
|
func (s *storeWrapper) Watch(ctx context.Context, key string, options *store.ReadOptions) (<-chan *store.KVPair, error) {
|
2019-11-28 20:56:04 +00:00
|
|
|
log.WithoutContext().Debugf("Watch: %s", key)
|
|
|
|
|
|
|
|
if s.Store == nil {
|
|
|
|
return nil, nil
|
|
|
|
}
|
2022-08-11 13:42:07 +00:00
|
|
|
return s.Store.Watch(ctx, key, options)
|
2019-11-28 20:56:04 +00:00
|
|
|
}
|
|
|
|
|
2022-08-11 13:42:07 +00:00
|
|
|
func (s *storeWrapper) WatchTree(ctx context.Context, directory string, options *store.ReadOptions) (<-chan []*store.KVPair, error) {
|
2019-11-28 20:56:04 +00:00
|
|
|
log.WithoutContext().Debugf("WatchTree: %s", directory)
|
|
|
|
|
|
|
|
if s.Store == nil {
|
|
|
|
return nil, nil
|
|
|
|
}
|
2022-08-11 13:42:07 +00:00
|
|
|
return s.Store.WatchTree(ctx, directory, options)
|
2019-11-28 20:56:04 +00:00
|
|
|
}
|
|
|
|
|
2022-08-11 13:42:07 +00:00
|
|
|
func (s *storeWrapper) NewLock(ctx context.Context, key string, options *store.LockOptions) (store.Locker, error) {
|
2019-11-28 20:56:04 +00:00
|
|
|
log.WithoutContext().Debugf("NewLock: %s", key)
|
|
|
|
|
|
|
|
if s.Store == nil {
|
|
|
|
return nil, nil
|
|
|
|
}
|
2022-08-11 13:42:07 +00:00
|
|
|
return s.Store.NewLock(ctx, key, options)
|
2019-11-28 20:56:04 +00:00
|
|
|
}
|
|
|
|
|
2022-08-11 13:42:07 +00:00
|
|
|
func (s *storeWrapper) List(ctx context.Context, directory string, options *store.ReadOptions) ([]*store.KVPair, error) {
|
2019-11-28 20:56:04 +00:00
|
|
|
log.WithoutContext().Debugf("List: %s", directory)
|
|
|
|
|
|
|
|
if s.Store == nil {
|
|
|
|
return nil, nil
|
|
|
|
}
|
2022-08-11 13:42:07 +00:00
|
|
|
return s.Store.List(ctx, directory, options)
|
2019-11-28 20:56:04 +00:00
|
|
|
}
|
|
|
|
|
2022-08-11 13:42:07 +00:00
|
|
|
func (s *storeWrapper) DeleteTree(ctx context.Context, directory string) error {
|
2019-11-28 20:56:04 +00:00
|
|
|
log.WithoutContext().Debugf("DeleteTree: %s", directory)
|
|
|
|
|
|
|
|
if s.Store == nil {
|
|
|
|
return nil
|
|
|
|
}
|
2022-08-11 13:42:07 +00:00
|
|
|
return s.Store.DeleteTree(ctx, directory)
|
2019-11-28 20:56:04 +00:00
|
|
|
}
|
|
|
|
|
2022-08-11 13:42:07 +00:00
|
|
|
func (s *storeWrapper) AtomicPut(ctx context.Context, key string, value []byte, previous *store.KVPair, options *store.WriteOptions) (bool, *store.KVPair, error) {
|
2019-11-28 20:56:04 +00:00
|
|
|
log.WithoutContext().Debugf("AtomicPut: %s", key, string(value), previous)
|
|
|
|
|
|
|
|
if s.Store == nil {
|
|
|
|
return true, nil, nil
|
|
|
|
}
|
2022-08-11 13:42:07 +00:00
|
|
|
return s.Store.AtomicPut(ctx, key, value, previous, options)
|
2019-11-28 20:56:04 +00:00
|
|
|
}
|
|
|
|
|
2022-08-11 13:42:07 +00:00
|
|
|
func (s *storeWrapper) AtomicDelete(ctx context.Context, key string, previous *store.KVPair) (bool, error) {
|
2019-11-28 20:56:04 +00:00
|
|
|
log.WithoutContext().Debugf("AtomicDelete: %s", key, previous)
|
|
|
|
|
|
|
|
if s.Store == nil {
|
|
|
|
return true, nil
|
|
|
|
}
|
2022-08-11 13:42:07 +00:00
|
|
|
return s.Store.AtomicDelete(ctx, key, previous)
|
2019-11-28 20:56:04 +00:00
|
|
|
}
|
|
|
|
|
2022-08-11 13:42:07 +00:00
|
|
|
func (s *storeWrapper) Close() error {
|
2019-11-28 20:56:04 +00:00
|
|
|
log.WithoutContext().Debugf("Close")
|
|
|
|
|
|
|
|
if s.Store == nil {
|
2022-08-11 13:42:07 +00:00
|
|
|
return nil
|
2019-11-28 20:56:04 +00:00
|
|
|
}
|
2022-08-11 13:42:07 +00:00
|
|
|
return s.Store.Close()
|
2019-11-28 20:56:04 +00:00
|
|
|
}
|