From 5a24d37ac05672499a48bef6058e3dc3f99e55b2 Mon Sep 17 00:00:00 2001 From: James Phillips Date: Tue, 28 Nov 2017 17:03:34 -0800 Subject: [PATCH] Creates a registration mechanism for schemas. This also splits out the registration into the table-specific source files. --- agent/consul/state/acl.go | 5 + agent/consul/state/autopilot.go | 22 ++ agent/consul/state/catalog.go | 175 +++++++++++ agent/consul/state/coordinate.go | 43 +++ agent/consul/state/kvs.go | 51 ++++ agent/consul/state/prepared_query.go | 45 +++ agent/consul/state/schema.go | 427 +-------------------------- agent/consul/state/session.go | 87 ++++++ 8 files changed, 441 insertions(+), 414 deletions(-) diff --git a/agent/consul/state/acl.go b/agent/consul/state/acl.go index 8911b604d..283b4b20b 100644 --- a/agent/consul/state/acl.go +++ b/agent/consul/state/acl.go @@ -44,6 +44,11 @@ func aclsBootstrapTableSchema() *memdb.TableSchema { } } +func init() { + registerSchema(aclsTableSchema) + registerSchema(aclsBootstrapTableSchema) +} + // ACLs is used to pull all the ACLs from the snapshot. func (s *Snapshot) ACLs() (memdb.ResultIterator, error) { iter, err := s.tx.Get("acls", "id") diff --git a/agent/consul/state/autopilot.go b/agent/consul/state/autopilot.go index 89f81a984..21514e5be 100644 --- a/agent/consul/state/autopilot.go +++ b/agent/consul/state/autopilot.go @@ -7,6 +7,28 @@ import ( "github.com/hashicorp/go-memdb" ) +// autopilotConfigTableSchema returns a new table schema used for storing +// the autopilot configuration +func autopilotConfigTableSchema() *memdb.TableSchema { + return &memdb.TableSchema{ + Name: "autopilot-config", + Indexes: map[string]*memdb.IndexSchema{ + "id": &memdb.IndexSchema{ + Name: "id", + AllowMissing: true, + Unique: true, + Indexer: &memdb.ConditionalIndex{ + Conditional: func(obj interface{}) (bool, error) { return true, nil }, + }, + }, + }, + } +} + +func init() { + registerSchema(autopilotConfigTableSchema) +} + // Autopilot is used to pull the autopilot config from the snapshot. func (s *Snapshot) Autopilot() (*structs.AutopilotConfig, error) { c, err := s.tx.First("autopilot-config", "id") diff --git a/agent/consul/state/catalog.go b/agent/consul/state/catalog.go index 73a1c75da..9f066d417 100644 --- a/agent/consul/state/catalog.go +++ b/agent/consul/state/catalog.go @@ -10,6 +10,181 @@ import ( "github.com/hashicorp/go-memdb" ) +// nodesTableSchema returns a new table schema used for storing node +// information. +func nodesTableSchema() *memdb.TableSchema { + return &memdb.TableSchema{ + Name: "nodes", + Indexes: map[string]*memdb.IndexSchema{ + "id": &memdb.IndexSchema{ + Name: "id", + AllowMissing: false, + Unique: true, + Indexer: &memdb.StringFieldIndex{ + Field: "Node", + Lowercase: true, + }, + }, + "uuid": &memdb.IndexSchema{ + Name: "uuid", + AllowMissing: true, + Unique: true, + Indexer: &memdb.UUIDFieldIndex{ + Field: "ID", + }, + }, + "meta": &memdb.IndexSchema{ + Name: "meta", + AllowMissing: true, + Unique: false, + Indexer: &memdb.StringMapFieldIndex{ + Field: "Meta", + Lowercase: false, + }, + }, + }, + } +} + +// servicesTableSchema returns a new table schema used to store information +// about services. +func servicesTableSchema() *memdb.TableSchema { + return &memdb.TableSchema{ + Name: "services", + Indexes: map[string]*memdb.IndexSchema{ + "id": &memdb.IndexSchema{ + Name: "id", + AllowMissing: false, + Unique: true, + Indexer: &memdb.CompoundIndex{ + Indexes: []memdb.Indexer{ + &memdb.StringFieldIndex{ + Field: "Node", + Lowercase: true, + }, + &memdb.StringFieldIndex{ + Field: "ServiceID", + Lowercase: true, + }, + }, + }, + }, + "node": &memdb.IndexSchema{ + Name: "node", + AllowMissing: false, + Unique: false, + Indexer: &memdb.StringFieldIndex{ + Field: "Node", + Lowercase: true, + }, + }, + "service": &memdb.IndexSchema{ + Name: "service", + AllowMissing: true, + Unique: false, + Indexer: &memdb.StringFieldIndex{ + Field: "ServiceName", + Lowercase: true, + }, + }, + }, + } +} + +// checksTableSchema returns a new table schema used for storing and indexing +// health check information. Health checks have a number of different attributes +// we want to filter by, so this table is a bit more complex. +func checksTableSchema() *memdb.TableSchema { + return &memdb.TableSchema{ + Name: "checks", + Indexes: map[string]*memdb.IndexSchema{ + "id": &memdb.IndexSchema{ + Name: "id", + AllowMissing: false, + Unique: true, + Indexer: &memdb.CompoundIndex{ + Indexes: []memdb.Indexer{ + &memdb.StringFieldIndex{ + Field: "Node", + Lowercase: true, + }, + &memdb.StringFieldIndex{ + Field: "CheckID", + Lowercase: true, + }, + }, + }, + }, + "status": &memdb.IndexSchema{ + Name: "status", + AllowMissing: false, + Unique: false, + Indexer: &memdb.StringFieldIndex{ + Field: "Status", + Lowercase: false, + }, + }, + "service": &memdb.IndexSchema{ + Name: "service", + AllowMissing: true, + Unique: false, + Indexer: &memdb.StringFieldIndex{ + Field: "ServiceName", + Lowercase: true, + }, + }, + "node": &memdb.IndexSchema{ + Name: "node", + AllowMissing: true, + Unique: false, + Indexer: &memdb.StringFieldIndex{ + Field: "Node", + Lowercase: true, + }, + }, + "node_service_check": &memdb.IndexSchema{ + Name: "node_service_check", + AllowMissing: true, + Unique: false, + Indexer: &memdb.CompoundIndex{ + Indexes: []memdb.Indexer{ + &memdb.StringFieldIndex{ + Field: "Node", + Lowercase: true, + }, + &memdb.FieldSetIndex{ + Field: "ServiceID", + }, + }, + }, + }, + "node_service": &memdb.IndexSchema{ + Name: "node_service", + AllowMissing: true, + Unique: false, + Indexer: &memdb.CompoundIndex{ + Indexes: []memdb.Indexer{ + &memdb.StringFieldIndex{ + Field: "Node", + Lowercase: true, + }, + &memdb.StringFieldIndex{ + Field: "ServiceID", + Lowercase: true, + }, + }, + }, + }, + }, + } +} + +func init() { + registerSchema(nodesTableSchema) + registerSchema(servicesTableSchema) + registerSchema(checksTableSchema) +} + const ( // minUUIDLookupLen is used as a minimum length of a node name required before // we test to see if the name is actually a UUID and perform an ID-based node diff --git a/agent/consul/state/coordinate.go b/agent/consul/state/coordinate.go index c810a8151..95b27fb1c 100644 --- a/agent/consul/state/coordinate.go +++ b/agent/consul/state/coordinate.go @@ -8,6 +8,49 @@ import ( "github.com/hashicorp/go-memdb" ) +// coordinatesTableSchema returns a new table schema used for storing +// network coordinates. +func coordinatesTableSchema() *memdb.TableSchema { + return &memdb.TableSchema{ + Name: "coordinates", + Indexes: map[string]*memdb.IndexSchema{ + "id": &memdb.IndexSchema{ + Name: "id", + AllowMissing: false, + Unique: true, + Indexer: &memdb.CompoundIndex{ + // AllowMissing is required since we allow + // Segment to be an empty string. + AllowMissing: true, + Indexes: []memdb.Indexer{ + &memdb.StringFieldIndex{ + Field: "Node", + Lowercase: true, + }, + &memdb.StringFieldIndex{ + Field: "Segment", + Lowercase: true, + }, + }, + }, + }, + "node": &memdb.IndexSchema{ + Name: "node", + AllowMissing: false, + Unique: false, + Indexer: &memdb.StringFieldIndex{ + Field: "Node", + Lowercase: true, + }, + }, + }, + } +} + +func init() { + registerSchema(coordinatesTableSchema) +} + // Coordinates is used to pull all the coordinates from the snapshot. func (s *Snapshot) Coordinates() (memdb.ResultIterator, error) { iter, err := s.tx.Get("coordinates", "id") diff --git a/agent/consul/state/kvs.go b/agent/consul/state/kvs.go index f4103bb04..070a2fc81 100644 --- a/agent/consul/state/kvs.go +++ b/agent/consul/state/kvs.go @@ -9,6 +9,57 @@ import ( "github.com/hashicorp/go-memdb" ) +// kvsTableSchema returns a new table schema used for storing key/value data for +// Consul's kv store. +func kvsTableSchema() *memdb.TableSchema { + return &memdb.TableSchema{ + Name: "kvs", + Indexes: map[string]*memdb.IndexSchema{ + "id": &memdb.IndexSchema{ + Name: "id", + AllowMissing: false, + Unique: true, + Indexer: &memdb.StringFieldIndex{ + Field: "Key", + Lowercase: false, + }, + }, + "session": &memdb.IndexSchema{ + Name: "session", + AllowMissing: true, + Unique: false, + Indexer: &memdb.UUIDFieldIndex{ + Field: "Session", + }, + }, + }, + } +} + +// tombstonesTableSchema returns a new table schema used for storing tombstones +// during KV delete operations to prevent the index from sliding backwards. +func tombstonesTableSchema() *memdb.TableSchema { + return &memdb.TableSchema{ + Name: "tombstones", + Indexes: map[string]*memdb.IndexSchema{ + "id": &memdb.IndexSchema{ + Name: "id", + AllowMissing: false, + Unique: true, + Indexer: &memdb.StringFieldIndex{ + Field: "Key", + Lowercase: false, + }, + }, + }, + } +} + +func init() { + registerSchema(kvsTableSchema) + registerSchema(tombstonesTableSchema) +} + // KVs is used to pull the full list of KVS entries for use during snapshots. func (s *Snapshot) KVs() (memdb.ResultIterator, error) { iter, err := s.tx.Get("kvs", "id_prefix") diff --git a/agent/consul/state/prepared_query.go b/agent/consul/state/prepared_query.go index 843c9ba1d..285355785 100644 --- a/agent/consul/state/prepared_query.go +++ b/agent/consul/state/prepared_query.go @@ -9,6 +9,51 @@ import ( "github.com/hashicorp/go-memdb" ) +// preparedQueriesTableSchema returns a new table schema used for storing +// prepared queries. +func preparedQueriesTableSchema() *memdb.TableSchema { + return &memdb.TableSchema{ + Name: "prepared-queries", + Indexes: map[string]*memdb.IndexSchema{ + "id": &memdb.IndexSchema{ + Name: "id", + AllowMissing: false, + Unique: true, + Indexer: &memdb.UUIDFieldIndex{ + Field: "ID", + }, + }, + "name": &memdb.IndexSchema{ + Name: "name", + AllowMissing: true, + Unique: true, + Indexer: &memdb.StringFieldIndex{ + Field: "Name", + Lowercase: true, + }, + }, + "template": &memdb.IndexSchema{ + Name: "template", + AllowMissing: true, + Unique: true, + Indexer: &PreparedQueryIndex{}, + }, + "session": &memdb.IndexSchema{ + Name: "session", + AllowMissing: true, + Unique: false, + Indexer: &memdb.UUIDFieldIndex{ + Field: "Session", + }, + }, + }, + } +} + +func init() { + registerSchema(preparedQueriesTableSchema) +} + // validUUID is used to check if a given string looks like a UUID var validUUID = regexp.MustCompile(`(?i)^[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}$`) diff --git a/agent/consul/state/schema.go b/agent/consul/state/schema.go index d7fa449e8..e24b23618 100644 --- a/agent/consul/state/schema.go +++ b/agent/consul/state/schema.go @@ -10,6 +10,15 @@ import ( // new memdb schema structs for constructing an in-memory db. type schemaFn func() *memdb.TableSchema +// schemas is used to register schemas with the state store. +var schemas []schemaFn + +// registerSchema registers a new schema with the state store. This should +// get called at package init() time. +func registerSchema(fn schemaFn) { + schemas = append(schemas, fn) +} + // stateStoreSchema is used to return the combined schema for // the state store. func stateStoreSchema() *memdb.DBSchema { @@ -18,23 +27,6 @@ func stateStoreSchema() *memdb.DBSchema { Tables: make(map[string]*memdb.TableSchema), } - // Collect the needed schemas - schemas := []schemaFn{ - indexTableSchema, - nodesTableSchema, - servicesTableSchema, - checksTableSchema, - kvsTableSchema, - tombstonesTableSchema, - sessionsTableSchema, - sessionChecksTableSchema, - aclsTableSchema, - aclsBootstrapTableSchema, - coordinatesTableSchema, - preparedQueriesTableSchema, - autopilotConfigTableSchema, - } - // Add the tables to the root schema for _, fn := range schemas { schema := fn() @@ -46,8 +38,8 @@ func stateStoreSchema() *memdb.DBSchema { return db } -// indexTableSchema returns a new table schema used for -// tracking various indexes for the Raft log. +// indexTableSchema returns a new table schema used for tracking various indexes +// for the Raft log. func indexTableSchema() *memdb.TableSchema { return &memdb.TableSchema{ Name: "index", @@ -65,399 +57,6 @@ func indexTableSchema() *memdb.TableSchema { } } -// nodesTableSchema returns a new table schema used for -// storing node information. -func nodesTableSchema() *memdb.TableSchema { - return &memdb.TableSchema{ - Name: "nodes", - Indexes: map[string]*memdb.IndexSchema{ - "id": &memdb.IndexSchema{ - Name: "id", - AllowMissing: false, - Unique: true, - Indexer: &memdb.StringFieldIndex{ - Field: "Node", - Lowercase: true, - }, - }, - "uuid": &memdb.IndexSchema{ - Name: "uuid", - AllowMissing: true, - Unique: true, - Indexer: &memdb.UUIDFieldIndex{ - Field: "ID", - }, - }, - "meta": &memdb.IndexSchema{ - Name: "meta", - AllowMissing: true, - Unique: false, - Indexer: &memdb.StringMapFieldIndex{ - Field: "Meta", - Lowercase: false, - }, - }, - }, - } -} - -// servicesTableSchema returns a new TableSchema used to -// store information about services. -func servicesTableSchema() *memdb.TableSchema { - return &memdb.TableSchema{ - Name: "services", - Indexes: map[string]*memdb.IndexSchema{ - "id": &memdb.IndexSchema{ - Name: "id", - AllowMissing: false, - Unique: true, - Indexer: &memdb.CompoundIndex{ - Indexes: []memdb.Indexer{ - &memdb.StringFieldIndex{ - Field: "Node", - Lowercase: true, - }, - &memdb.StringFieldIndex{ - Field: "ServiceID", - Lowercase: true, - }, - }, - }, - }, - "node": &memdb.IndexSchema{ - Name: "node", - AllowMissing: false, - Unique: false, - Indexer: &memdb.StringFieldIndex{ - Field: "Node", - Lowercase: true, - }, - }, - "service": &memdb.IndexSchema{ - Name: "service", - AllowMissing: true, - Unique: false, - Indexer: &memdb.StringFieldIndex{ - Field: "ServiceName", - Lowercase: true, - }, - }, - }, - } -} - -// checksTableSchema returns a new table schema used for -// storing and indexing health check information. Health -// checks have a number of different attributes we want to -// filter by, so this table is a bit more complex. -func checksTableSchema() *memdb.TableSchema { - return &memdb.TableSchema{ - Name: "checks", - Indexes: map[string]*memdb.IndexSchema{ - "id": &memdb.IndexSchema{ - Name: "id", - AllowMissing: false, - Unique: true, - Indexer: &memdb.CompoundIndex{ - Indexes: []memdb.Indexer{ - &memdb.StringFieldIndex{ - Field: "Node", - Lowercase: true, - }, - &memdb.StringFieldIndex{ - Field: "CheckID", - Lowercase: true, - }, - }, - }, - }, - "status": &memdb.IndexSchema{ - Name: "status", - AllowMissing: false, - Unique: false, - Indexer: &memdb.StringFieldIndex{ - Field: "Status", - Lowercase: false, - }, - }, - "service": &memdb.IndexSchema{ - Name: "service", - AllowMissing: true, - Unique: false, - Indexer: &memdb.StringFieldIndex{ - Field: "ServiceName", - Lowercase: true, - }, - }, - "node": &memdb.IndexSchema{ - Name: "node", - AllowMissing: true, - Unique: false, - Indexer: &memdb.StringFieldIndex{ - Field: "Node", - Lowercase: true, - }, - }, - "node_service_check": &memdb.IndexSchema{ - Name: "node_service_check", - AllowMissing: true, - Unique: false, - Indexer: &memdb.CompoundIndex{ - Indexes: []memdb.Indexer{ - &memdb.StringFieldIndex{ - Field: "Node", - Lowercase: true, - }, - &memdb.FieldSetIndex{ - Field: "ServiceID", - }, - }, - }, - }, - "node_service": &memdb.IndexSchema{ - Name: "node_service", - AllowMissing: true, - Unique: false, - Indexer: &memdb.CompoundIndex{ - Indexes: []memdb.Indexer{ - &memdb.StringFieldIndex{ - Field: "Node", - Lowercase: true, - }, - &memdb.StringFieldIndex{ - Field: "ServiceID", - Lowercase: true, - }, - }, - }, - }, - }, - } -} - -// kvsTableSchema returns a new table schema used for storing -// key/value data from consul's kv store. -func kvsTableSchema() *memdb.TableSchema { - return &memdb.TableSchema{ - Name: "kvs", - Indexes: map[string]*memdb.IndexSchema{ - "id": &memdb.IndexSchema{ - Name: "id", - AllowMissing: false, - Unique: true, - Indexer: &memdb.StringFieldIndex{ - Field: "Key", - Lowercase: false, - }, - }, - "session": &memdb.IndexSchema{ - Name: "session", - AllowMissing: true, - Unique: false, - Indexer: &memdb.UUIDFieldIndex{ - Field: "Session", - }, - }, - }, - } -} - -// tombstonesTableSchema returns a new table schema used for -// storing tombstones during KV delete operations to prevent -// the index from sliding backwards. -func tombstonesTableSchema() *memdb.TableSchema { - return &memdb.TableSchema{ - Name: "tombstones", - Indexes: map[string]*memdb.IndexSchema{ - "id": &memdb.IndexSchema{ - Name: "id", - AllowMissing: false, - Unique: true, - Indexer: &memdb.StringFieldIndex{ - Field: "Key", - Lowercase: false, - }, - }, - }, - } -} - -// sessionsTableSchema returns a new TableSchema used for -// storing session information. -func sessionsTableSchema() *memdb.TableSchema { - return &memdb.TableSchema{ - Name: "sessions", - Indexes: map[string]*memdb.IndexSchema{ - "id": &memdb.IndexSchema{ - Name: "id", - AllowMissing: false, - Unique: true, - Indexer: &memdb.UUIDFieldIndex{ - Field: "ID", - }, - }, - "node": &memdb.IndexSchema{ - Name: "node", - AllowMissing: false, - Unique: false, - Indexer: &memdb.StringFieldIndex{ - Field: "Node", - Lowercase: true, - }, - }, - }, - } -} - -// sessionChecksTableSchema returns a new table schema used -// for storing session checks. -func sessionChecksTableSchema() *memdb.TableSchema { - return &memdb.TableSchema{ - Name: "session_checks", - Indexes: map[string]*memdb.IndexSchema{ - "id": &memdb.IndexSchema{ - Name: "id", - AllowMissing: false, - Unique: true, - Indexer: &memdb.CompoundIndex{ - Indexes: []memdb.Indexer{ - &memdb.StringFieldIndex{ - Field: "Node", - Lowercase: true, - }, - &memdb.StringFieldIndex{ - Field: "CheckID", - Lowercase: true, - }, - &memdb.UUIDFieldIndex{ - Field: "Session", - }, - }, - }, - }, - "node_check": &memdb.IndexSchema{ - Name: "node_check", - AllowMissing: false, - Unique: false, - Indexer: &memdb.CompoundIndex{ - Indexes: []memdb.Indexer{ - &memdb.StringFieldIndex{ - Field: "Node", - Lowercase: true, - }, - &memdb.StringFieldIndex{ - Field: "CheckID", - Lowercase: true, - }, - }, - }, - }, - "session": &memdb.IndexSchema{ - Name: "session", - AllowMissing: false, - Unique: false, - Indexer: &memdb.UUIDFieldIndex{ - Field: "Session", - }, - }, - }, - } -} - -// coordinatesTableSchema returns a new table schema used for storing -// network coordinates. -func coordinatesTableSchema() *memdb.TableSchema { - return &memdb.TableSchema{ - Name: "coordinates", - Indexes: map[string]*memdb.IndexSchema{ - "id": &memdb.IndexSchema{ - Name: "id", - AllowMissing: false, - Unique: true, - Indexer: &memdb.CompoundIndex{ - // AllowMissing is required since we allow - // Segment to be an empty string. - AllowMissing: true, - Indexes: []memdb.Indexer{ - &memdb.StringFieldIndex{ - Field: "Node", - Lowercase: true, - }, - &memdb.StringFieldIndex{ - Field: "Segment", - Lowercase: true, - }, - }, - }, - }, - "node": &memdb.IndexSchema{ - Name: "node", - AllowMissing: false, - Unique: false, - Indexer: &memdb.StringFieldIndex{ - Field: "Node", - Lowercase: true, - }, - }, - }, - } -} - -// preparedQueriesTableSchema returns a new table schema used for storing -// prepared queries. -func preparedQueriesTableSchema() *memdb.TableSchema { - return &memdb.TableSchema{ - Name: "prepared-queries", - Indexes: map[string]*memdb.IndexSchema{ - "id": &memdb.IndexSchema{ - Name: "id", - AllowMissing: false, - Unique: true, - Indexer: &memdb.UUIDFieldIndex{ - Field: "ID", - }, - }, - "name": &memdb.IndexSchema{ - Name: "name", - AllowMissing: true, - Unique: true, - Indexer: &memdb.StringFieldIndex{ - Field: "Name", - Lowercase: true, - }, - }, - "template": &memdb.IndexSchema{ - Name: "template", - AllowMissing: true, - Unique: true, - Indexer: &PreparedQueryIndex{}, - }, - "session": &memdb.IndexSchema{ - Name: "session", - AllowMissing: true, - Unique: false, - Indexer: &memdb.UUIDFieldIndex{ - Field: "Session", - }, - }, - }, - } -} - -// autopilotConfigTableSchema returns a new table schema used for storing -// the autopilot configuration -func autopilotConfigTableSchema() *memdb.TableSchema { - return &memdb.TableSchema{ - Name: "autopilot-config", - Indexes: map[string]*memdb.IndexSchema{ - "id": &memdb.IndexSchema{ - Name: "id", - AllowMissing: true, - Unique: true, - Indexer: &memdb.ConditionalIndex{ - Conditional: func(obj interface{}) (bool, error) { return true, nil }, - }, - }, - }, - } +func init() { + registerSchema(indexTableSchema) } diff --git a/agent/consul/state/session.go b/agent/consul/state/session.go index ed958d827..9775ff639 100644 --- a/agent/consul/state/session.go +++ b/agent/consul/state/session.go @@ -9,6 +9,93 @@ import ( "github.com/hashicorp/go-memdb" ) +// sessionsTableSchema returns a new table schema used for storing session +// information. +func sessionsTableSchema() *memdb.TableSchema { + return &memdb.TableSchema{ + Name: "sessions", + Indexes: map[string]*memdb.IndexSchema{ + "id": &memdb.IndexSchema{ + Name: "id", + AllowMissing: false, + Unique: true, + Indexer: &memdb.UUIDFieldIndex{ + Field: "ID", + }, + }, + "node": &memdb.IndexSchema{ + Name: "node", + AllowMissing: false, + Unique: false, + Indexer: &memdb.StringFieldIndex{ + Field: "Node", + Lowercase: true, + }, + }, + }, + } +} + +// sessionChecksTableSchema returns a new table schema used for storing session +// checks. +func sessionChecksTableSchema() *memdb.TableSchema { + return &memdb.TableSchema{ + Name: "session_checks", + Indexes: map[string]*memdb.IndexSchema{ + "id": &memdb.IndexSchema{ + Name: "id", + AllowMissing: false, + Unique: true, + Indexer: &memdb.CompoundIndex{ + Indexes: []memdb.Indexer{ + &memdb.StringFieldIndex{ + Field: "Node", + Lowercase: true, + }, + &memdb.StringFieldIndex{ + Field: "CheckID", + Lowercase: true, + }, + &memdb.UUIDFieldIndex{ + Field: "Session", + }, + }, + }, + }, + "node_check": &memdb.IndexSchema{ + Name: "node_check", + AllowMissing: false, + Unique: false, + Indexer: &memdb.CompoundIndex{ + Indexes: []memdb.Indexer{ + &memdb.StringFieldIndex{ + Field: "Node", + Lowercase: true, + }, + &memdb.StringFieldIndex{ + Field: "CheckID", + Lowercase: true, + }, + }, + }, + }, + "session": &memdb.IndexSchema{ + Name: "session", + AllowMissing: false, + Unique: false, + Indexer: &memdb.UUIDFieldIndex{ + Field: "Session", + }, + }, + }, + } +} + +func init() { + registerSchema(sessionsTableSchema) + registerSchema(sessionChecksTableSchema) +} + // Sessions is used to pull the full list of sessions for use during snapshots. func (s *Snapshot) Sessions() (memdb.ResultIterator, error) { iter, err := s.tx.Get("sessions", "id")