-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds in basic query template lookups and vendors newly-updated memdb …
…as well as improved iradix tree.
- Loading branch information
James Phillips
committed
Mar 2, 2016
1 parent
3f33f70
commit e29604f
Showing
9 changed files
with
210 additions
and
79 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package state | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/hashicorp/consul/consul/prepared_query" | ||
) | ||
|
||
// PreparedQueryIndex is a custom memdb indexer used to manage index prepared | ||
// query templates. None of the built-in indexers do what we need, and our | ||
// use case is pretty specific so it's better to put the logic here. | ||
type PreparedQueryIndex struct { | ||
} | ||
|
||
// FromObject is used to compute the index key when inserting or updating an | ||
// object. | ||
func (*PreparedQueryIndex) FromObject(obj interface{}) (bool, []byte, error) { | ||
wrapped, ok := obj.(*queryWrapper) | ||
if !ok { | ||
return false, nil, fmt.Errorf("invalid object given to index as prepared query") | ||
} | ||
|
||
query := toPreparedQuery(wrapped) | ||
if !prepared_query.IsTemplate(query) { | ||
return false, nil, nil | ||
} | ||
|
||
// Always prepend a null so that we can represent even an empty name. | ||
out := "\x00" + strings.ToLower(query.Name) | ||
return true, []byte(out), nil | ||
} | ||
|
||
// FromArgs is used when querying for an exact match. Since we don't add any | ||
// suffix we can just call the prefix version. | ||
func (p *PreparedQueryIndex) FromArgs(args ...interface{}) ([]byte, error) { | ||
return p.PrefixFromArgs(args...) | ||
} | ||
|
||
// PrefixFromArgs is used when doing a prefix scan for an object. | ||
func (*PreparedQueryIndex) PrefixFromArgs(args ...interface{}) ([]byte, error) { | ||
if len(args) != 1 { | ||
return nil, fmt.Errorf("must provide only a single argument") | ||
} | ||
arg, ok := args[0].(string) | ||
if !ok { | ||
return nil, fmt.Errorf("argument must be a string: %#v", args[0]) | ||
} | ||
arg = "\x00" + strings.ToLower(arg) | ||
return []byte(arg), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.