-
Notifications
You must be signed in to change notification settings - Fork 45
Open
Description
Is your feature request related to a problem? Please describe.
There have been some comments that this could be done better. It was one of the first APIs in weave, and we have learned a lot since then. I'm sure we can improve it.
For example, we now have a much simpler Iterator
type Iterator interface {
Next() (key, value []byte, err error)
Release()
}Let us consider the following interfaces here:
type ReadOnlyKVStore interface {
Get(key []byte) ([]byte, error)
Has(key []byte) (bool, error)
Iterator(start, end []byte) (Iterator, error)
ReverseIterator(start, end []byte) (Iterator, error)
}
type SetDeleter interface {
Set(key, value []byte) error
Delete(key []byte) error
}
// Batch is used to cache writes before commiting to a lower store
type Batch interface {
SetDeleter
Write() error
}
type KVStore interface {
ReadOnlyKVStore
SetDeleter
NewBatch() Batch
}
type CacheableKVStore interface {
KVStore
CacheWrap() KVCacheWrap
}
type KVCacheWrap interface {
// CacheableKVStore allows us to use this Cache recursively
CacheableKVStore
Write() error
Discard()
}Describe the solution you'd like
Some thoughts on cleanup:
- Can we remove
NewBatch()fromKVStore? What was my thinking there? - Can we simplify/unify
CacheableKVStoreandKVCacheWrap? - Can we combine/improve
IteratorandReverseIterator?
Describe alternatives you've considered
One concrete suggestion is to make iterator take functional parameters
// default -> ascending and no limit
type IterConfig struct {
Descending bool
Limit int
}
type IterOpt func(IterConfig) IterConfig
type ReadOnlyKVStore interface {
Iterate(start, end []byte, opts ...IterOpt) (Iterator, error)
}
// example opt we expose
var Reverse IterOpt = func (cfg IterConfig) IterConfig {
cfg.Descending = true
return cfg
}Additional context
Add any other context or screenshots about the feature request here.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels