Merge pull request #9663 from hashicorp/dnephin/update-memdb

Update go-memdb
This commit is contained in:
Daniel Nephin 2021-02-16 15:28:16 -05:00 committed by GitHub
commit 06eff8eab1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 51 additions and 17 deletions

2
go.mod
View File

@ -37,7 +37,7 @@ require (
github.com/hashicorp/go-connlimit v0.3.0 github.com/hashicorp/go-connlimit v0.3.0
github.com/hashicorp/go-discover v0.0.0-20200501174627-ad1e96bde088 github.com/hashicorp/go-discover v0.0.0-20200501174627-ad1e96bde088
github.com/hashicorp/go-hclog v0.14.1 github.com/hashicorp/go-hclog v0.14.1
github.com/hashicorp/go-memdb v1.3.0 github.com/hashicorp/go-memdb v1.3.1
github.com/hashicorp/go-msgpack v0.5.5 github.com/hashicorp/go-msgpack v0.5.5
github.com/hashicorp/go-multierror v1.1.0 github.com/hashicorp/go-multierror v1.1.0
github.com/hashicorp/go-raftchunking v0.6.1 github.com/hashicorp/go-raftchunking v0.6.1

4
go.sum
View File

@ -240,8 +240,8 @@ github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjh
github.com/hashicorp/go-immutable-radix v1.3.0 h1:8exGP7ego3OmkfksihtSouGMZ+hQrhxx+FVELeXpVPE= github.com/hashicorp/go-immutable-radix v1.3.0 h1:8exGP7ego3OmkfksihtSouGMZ+hQrhxx+FVELeXpVPE=
github.com/hashicorp/go-immutable-radix v1.3.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= github.com/hashicorp/go-immutable-radix v1.3.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60=
github.com/hashicorp/go-kms-wrapping/entropy v0.1.0/go.mod h1:d1g9WGtAunDNpek8jUIEJnBlbgKS1N2Q61QkHiZyR1g= github.com/hashicorp/go-kms-wrapping/entropy v0.1.0/go.mod h1:d1g9WGtAunDNpek8jUIEJnBlbgKS1N2Q61QkHiZyR1g=
github.com/hashicorp/go-memdb v1.3.0 h1:xdXq34gBOMEloa9rlGStLxmfX/dyIK8htOv36dQUwHU= github.com/hashicorp/go-memdb v1.3.1 h1:EIj6L28rTL41BDHBvwq1VJXzcmY2R2JBrxpWxF7Etyk=
github.com/hashicorp/go-memdb v1.3.0/go.mod h1:Mluclgwib3R93Hk5fxEfiRhB+6Dar64wWh71LpNSe3g= github.com/hashicorp/go-memdb v1.3.1/go.mod h1:Mluclgwib3R93Hk5fxEfiRhB+6Dar64wWh71LpNSe3g=
github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM= github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM=
github.com/hashicorp/go-msgpack v0.5.5 h1:i9R9JSrqIz0QVLz3sz+i3YJdT7TTSLcfLLzJi9aZTuI= github.com/hashicorp/go-msgpack v0.5.5 h1:i9R9JSrqIz0QVLz3sz+i3YJdT7TTSLcfLLzJi9aZTuI=
github.com/hashicorp/go-msgpack v0.5.5/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM= github.com/hashicorp/go-msgpack v0.5.5/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM=

View File

@ -13,17 +13,22 @@ type FilterIterator struct {
iter ResultIterator iter ResultIterator
} }
func NewFilterIterator(wrap ResultIterator, filter FilterFunc) *FilterIterator { // NewFilterIterator wraps a ResultIterator. The filter function is applied
// to each value returned by a call to iter.Next.
//
// See the documentation for ResultIterator to understand the behaviour of the
// returned FilterIterator.
func NewFilterIterator(iter ResultIterator, filter FilterFunc) *FilterIterator {
return &FilterIterator{ return &FilterIterator{
filter: filter, filter: filter,
iter: wrap, iter: iter,
} }
} }
// WatchCh returns the watch channel of the wrapped iterator. // WatchCh returns the watch channel of the wrapped iterator.
func (f *FilterIterator) WatchCh() <-chan struct{} { return f.iter.WatchCh() } func (f *FilterIterator) WatchCh() <-chan struct{} { return f.iter.WatchCh() }
// Next returns the next non-filtered result from the wrapped iterator // Next returns the next non-filtered result from the wrapped iterator.
func (f *FilterIterator) Next() interface{} { func (f *FilterIterator) Next() interface{} {
for { for {
if value := f.iter.Next(); value == nil || !f.filter(value) { if value := f.iter.Next(); value == nil || !f.filter(value) {

View File

@ -52,16 +52,16 @@ func (txn *Txn) TrackChanges() {
} }
} }
// readableIndex returns a transaction usable for reading the given // readableIndex returns a transaction usable for reading the given index in a
// index in a table. If a write transaction is in progress, we may need // table. If the transaction is a write transaction with modifications, a clone of the
// to use an existing modified txn. // modified index will be returned.
func (txn *Txn) readableIndex(table, index string) *iradix.Txn { func (txn *Txn) readableIndex(table, index string) *iradix.Txn {
// Look for existing transaction // Look for existing transaction
if txn.write && txn.modified != nil { if txn.write && txn.modified != nil {
key := tableIndex{table, index} key := tableIndex{table, index}
exist, ok := txn.modified[key] exist, ok := txn.modified[key]
if ok { if ok {
return exist return exist.Clone()
} }
} }
@ -663,15 +663,35 @@ func (txn *Txn) getIndexValue(table, index string, args ...interface{}) (*IndexS
return indexSchema, val, err return indexSchema, val, err
} }
// ResultIterator is used to iterate over a list of results // ResultIterator is used to iterate over a list of results from a query on a table.
// from a Get query on a table. //
// When a ResultIterator is created from a write transaction, the results from
// Next will reflect a snapshot of the table at the time the ResultIterator is
// created.
// This means that calling Insert or Delete on a transaction while iterating is
// allowed, but the changes made by Insert or Delete will not be observed in the
// results returned from subsequent calls to Next. For example if an item is deleted
// from the index used by the iterator it will still be returned by Next. If an
// item is inserted into the index used by the iterator, it will not be returned
// by Next. However, an iterator created after a call to Insert or Delete will
// reflect the modifications.
//
// When a ResultIterator is created from a write transaction, and there are already
// modifications to the index used by the iterator, the modification cache of the
// index will be invalidated. This may result in some additional allocations if
// the same node in the index is modified again.
type ResultIterator interface { type ResultIterator interface {
WatchCh() <-chan struct{} WatchCh() <-chan struct{}
// Next returns the next result from the iterator. If there are no more results
// nil is returned.
Next() interface{} Next() interface{}
} }
// Get is used to construct a ResultIterator over all the // Get is used to construct a ResultIterator over all the rows that match the
// rows that match the given constraints of an index. // given constraints of an index.
//
// See the documentation for ResultIterator to understand the behaviour of the
// returned ResultIterator.
func (txn *Txn) Get(table, index string, args ...interface{}) (ResultIterator, error) { func (txn *Txn) Get(table, index string, args ...interface{}) (ResultIterator, error) {
indexIter, val, err := txn.getIndexIterator(table, index, args...) indexIter, val, err := txn.getIndexIterator(table, index, args...)
if err != nil { if err != nil {
@ -691,7 +711,10 @@ func (txn *Txn) Get(table, index string, args ...interface{}) (ResultIterator, e
// GetReverse is used to construct a Reverse ResultIterator over all the // GetReverse is used to construct a Reverse ResultIterator over all the
// rows that match the given constraints of an index. // rows that match the given constraints of an index.
// The returned ResultIterator's Next() will return the next Previous value // The returned ResultIterator's Next() will return the next Previous value.
//
// See the documentation for ResultIterator to understand the behaviour of the
// returned ResultIterator.
func (txn *Txn) GetReverse(table, index string, args ...interface{}) (ResultIterator, error) { func (txn *Txn) GetReverse(table, index string, args ...interface{}) (ResultIterator, error) {
indexIter, val, err := txn.getIndexIteratorReverse(table, index, args...) indexIter, val, err := txn.getIndexIteratorReverse(table, index, args...)
if err != nil { if err != nil {
@ -715,6 +738,9 @@ func (txn *Txn) GetReverse(table, index string, args ...interface{}) (ResultIter
// range scans within an index. It is not possible to watch the resulting // range scans within an index. It is not possible to watch the resulting
// iterator since the radix tree doesn't efficiently allow watching on lower // iterator since the radix tree doesn't efficiently allow watching on lower
// bound changes. The WatchCh returned will be nill and so will block forever. // bound changes. The WatchCh returned will be nill and so will block forever.
//
// See the documentation for ResultIterator to understand the behaviour of the
// returned ResultIterator.
func (txn *Txn) LowerBound(table, index string, args ...interface{}) (ResultIterator, error) { func (txn *Txn) LowerBound(table, index string, args ...interface{}) (ResultIterator, error) {
indexIter, val, err := txn.getIndexIterator(table, index, args...) indexIter, val, err := txn.getIndexIterator(table, index, args...)
if err != nil { if err != nil {
@ -738,6 +764,9 @@ func (txn *Txn) LowerBound(table, index string, args ...interface{}) (ResultIter
// resulting iterator since the radix tree doesn't efficiently allow watching // resulting iterator since the radix tree doesn't efficiently allow watching
// on lower bound changes. The WatchCh returned will be nill and so will block // on lower bound changes. The WatchCh returned will be nill and so will block
// forever. // forever.
//
// See the documentation for ResultIterator to understand the behaviour of the
// returned ResultIterator.
func (txn *Txn) ReverseLowerBound(table, index string, args ...interface{}) (ResultIterator, error) { func (txn *Txn) ReverseLowerBound(table, index string, args ...interface{}) (ResultIterator, error) {
indexIter, val, err := txn.getIndexIteratorReverse(table, index, args...) indexIter, val, err := txn.getIndexIteratorReverse(table, index, args...)
if err != nil { if err != nil {
@ -850,7 +879,7 @@ func (txn *Txn) getIndexIterator(table, index string, args ...interface{}) (*ira
indexTxn := txn.readableIndex(table, indexSchema.Name) indexTxn := txn.readableIndex(table, indexSchema.Name)
indexRoot := indexTxn.Root() indexRoot := indexTxn.Root()
// Get an interator over the index // Get an iterator over the index
indexIter := indexRoot.Iterator() indexIter := indexRoot.Iterator()
return indexIter, val, nil return indexIter, val, nil
} }

2
vendor/modules.txt vendored
View File

@ -231,7 +231,7 @@ github.com/hashicorp/go-discover/provider/vsphere
github.com/hashicorp/go-hclog github.com/hashicorp/go-hclog
# github.com/hashicorp/go-immutable-radix v1.3.0 # github.com/hashicorp/go-immutable-radix v1.3.0
github.com/hashicorp/go-immutable-radix github.com/hashicorp/go-immutable-radix
# github.com/hashicorp/go-memdb v1.3.0 # github.com/hashicorp/go-memdb v1.3.1
github.com/hashicorp/go-memdb github.com/hashicorp/go-memdb
# github.com/hashicorp/go-msgpack v0.5.5 # github.com/hashicorp/go-msgpack v0.5.5
github.com/hashicorp/go-msgpack/codec github.com/hashicorp/go-msgpack/codec