mirror of
https://github.com/status-im/consul.git
synced 2025-01-29 23:15:08 +00:00
state: remove duplication of Query indexer
This commit is contained in:
parent
08ee12ab34
commit
341265ec69
@ -39,7 +39,7 @@ func nodesTableSchema() *memdb.TableSchema {
|
|||||||
AllowMissing: false,
|
AllowMissing: false,
|
||||||
Unique: true,
|
Unique: true,
|
||||||
Indexer: indexerSingle{
|
Indexer: indexerSingle{
|
||||||
readIndex: indexFromNodeQuery,
|
readIndex: indexFromQuery,
|
||||||
writeIndex: indexFromNode,
|
writeIndex: indexFromNode,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -77,18 +77,6 @@ func indexFromNode(raw interface{}) ([]byte, error) {
|
|||||||
return b.Bytes(), nil
|
return b.Bytes(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: remove once all uses of indexFromQuery are ported
|
|
||||||
func indexFromNodeQuery(arg interface{}) ([]byte, error) {
|
|
||||||
q, ok := arg.(Query)
|
|
||||||
if !ok {
|
|
||||||
return nil, fmt.Errorf("unexpected type %T for Query index", arg)
|
|
||||||
}
|
|
||||||
|
|
||||||
var b indexBuilder
|
|
||||||
b.String(strings.ToLower(q.Value))
|
|
||||||
return b.Bytes(), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// servicesTableSchema returns a new table schema used to store information
|
// servicesTableSchema returns a new table schema used to store information
|
||||||
// about services.
|
// about services.
|
||||||
func servicesTableSchema() *memdb.TableSchema {
|
func servicesTableSchema() *memdb.TableSchema {
|
||||||
@ -110,7 +98,7 @@ func servicesTableSchema() *memdb.TableSchema {
|
|||||||
AllowMissing: false,
|
AllowMissing: false,
|
||||||
Unique: false,
|
Unique: false,
|
||||||
Indexer: indexerSingle{
|
Indexer: indexerSingle{
|
||||||
readIndex: indexFromNodeQuery,
|
readIndex: indexFromQuery,
|
||||||
writeIndex: indexFromNodeIdentity,
|
writeIndex: indexFromNodeIdentity,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -225,7 +213,7 @@ func checksTableSchema() *memdb.TableSchema {
|
|||||||
AllowMissing: true,
|
AllowMissing: true,
|
||||||
Unique: false,
|
Unique: false,
|
||||||
Indexer: indexerSingle{
|
Indexer: indexerSingle{
|
||||||
readIndex: indexFromNodeQuery,
|
readIndex: indexFromQuery,
|
||||||
writeIndex: indexFromNodeIdentity,
|
writeIndex: indexFromNodeIdentity,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -21,6 +21,19 @@ func (q Query) NamespaceOrDefault() string {
|
|||||||
return q.EnterpriseMeta.NamespaceOrDefault()
|
return q.EnterpriseMeta.NamespaceOrDefault()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// indexFromQuery builds an index key where Query.Value is lowercase, and is
|
||||||
|
// a required value.
|
||||||
|
func indexFromQuery(arg interface{}) ([]byte, error) {
|
||||||
|
q, ok := arg.(Query)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("unexpected type %T for Query index", arg)
|
||||||
|
}
|
||||||
|
|
||||||
|
var b indexBuilder
|
||||||
|
b.String(strings.ToLower(q.Value))
|
||||||
|
return b.Bytes(), nil
|
||||||
|
}
|
||||||
|
|
||||||
// uuidStringToBytes is a modified version of memdb.UUIDFieldIndex.parseString
|
// uuidStringToBytes is a modified version of memdb.UUIDFieldIndex.parseString
|
||||||
func uuidStringToBytes(uuid string) ([]byte, error) {
|
func uuidStringToBytes(uuid string) ([]byte, error) {
|
||||||
l := len(uuid)
|
l := len(uuid)
|
||||||
|
@ -9,19 +9,6 @@ import (
|
|||||||
"github.com/hashicorp/consul/agent/structs"
|
"github.com/hashicorp/consul/agent/structs"
|
||||||
)
|
)
|
||||||
|
|
||||||
// indexFromQuery builds an index key where Query.Value is lowercase, and is
|
|
||||||
// a required value.
|
|
||||||
func indexFromQuery(arg interface{}) ([]byte, error) {
|
|
||||||
q, ok := arg.(Query)
|
|
||||||
if !ok {
|
|
||||||
return nil, fmt.Errorf("unexpected type %T for Query index", arg)
|
|
||||||
}
|
|
||||||
|
|
||||||
var b indexBuilder
|
|
||||||
b.String(strings.ToLower(q.Value))
|
|
||||||
return b.Bytes(), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func prefixIndexFromQuery(arg interface{}) ([]byte, error) {
|
func prefixIndexFromQuery(arg interface{}) ([]byte, error) {
|
||||||
var b indexBuilder
|
var b indexBuilder
|
||||||
switch v := arg.(type) {
|
switch v := arg.(type) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user