state: move config-entries table to new pattern

This commit is contained in:
Daniel Nephin 2021-01-28 20:34:15 -05:00
parent 825b8ade39
commit 7d17e20270
3 changed files with 67 additions and 59 deletions

View File

@ -12,10 +12,6 @@ import (
"github.com/hashicorp/consul/lib"
)
const (
configTableName = "config-entries"
)
type ConfigEntryLinkIndex struct {
}

View File

@ -3,63 +3,10 @@
package state
import (
"github.com/hashicorp/consul/agent/structs"
memdb "github.com/hashicorp/go-memdb"
)
// configTableSchema returns a new table schema used to store global
// config entries.
func configTableSchema() *memdb.TableSchema {
return &memdb.TableSchema{
Name: configTableName,
Indexes: map[string]*memdb.IndexSchema{
"id": {
Name: "id",
AllowMissing: false,
Unique: true,
Indexer: &memdb.CompoundIndex{
Indexes: []memdb.Indexer{
&memdb.StringFieldIndex{
Field: "Kind",
Lowercase: true,
},
&memdb.StringFieldIndex{
Field: "Name",
Lowercase: true,
},
},
},
},
"kind": {
Name: "kind",
AllowMissing: false,
Unique: false,
Indexer: &memdb.StringFieldIndex{
Field: "Kind",
Lowercase: true,
},
},
"link": {
Name: "link",
AllowMissing: true,
Unique: false,
Indexer: &ConfigEntryLinkIndex{},
},
"intention-legacy-id": {
Name: "intention-legacy-id",
AllowMissing: true,
Unique: true,
Indexer: &ServiceIntentionLegacyIDIndex{},
},
"intention-source": {
Name: "intention-source",
AllowMissing: true,
Unique: false,
Indexer: &ServiceIntentionSourceIndex{},
},
},
}
}
"github.com/hashicorp/consul/agent/structs"
)
func firstConfigEntryWithTxn(tx ReadTxn, kind, name string, _ *structs.EnterpriseMeta) (interface{}, error) {
return tx.First(configTableName, "id", kind, name)

View File

@ -0,0 +1,65 @@
package state
import "github.com/hashicorp/go-memdb"
const (
configTableName = "config-entries"
indexLink = "link"
indexIntentionLegacyID = "intention-legacy-id"
indexSource = "intention-source"
)
// configTableSchema returns a new table schema used to store global
// config entries.
func configTableSchema() *memdb.TableSchema {
return &memdb.TableSchema{
Name: configTableName,
Indexes: map[string]*memdb.IndexSchema{
indexID: {
Name: indexID,
AllowMissing: false,
Unique: true,
Indexer: &memdb.CompoundIndex{
Indexes: []memdb.Indexer{
&memdb.StringFieldIndex{
Field: "Kind",
Lowercase: true,
},
&memdb.StringFieldIndex{
Field: "Name",
Lowercase: true,
},
},
},
},
indexKind: {
Name: indexKind,
AllowMissing: false,
Unique: false,
Indexer: &memdb.StringFieldIndex{
Field: "Kind",
Lowercase: true,
},
},
indexLink: {
Name: indexLink,
AllowMissing: true,
Unique: false,
Indexer: &ConfigEntryLinkIndex{},
},
indexIntentionLegacyID: {
Name: indexIntentionLegacyID,
AllowMissing: true,
Unique: true,
Indexer: &ServiceIntentionLegacyIDIndex{},
},
indexSource: {
Name: indexSource,
AllowMissing: true,
Unique: false,
Indexer: &ServiceIntentionSourceIndex{},
},
},
}
}