From cf0b63d561205524c3b6f297991da6c547793525 Mon Sep 17 00:00:00 2001 From: James Rasell Date: Mon, 28 Feb 2022 10:14:10 +0100 Subject: [PATCH] state: add the table schema for the service_registrations table. --- nomad/state/schema.go | 91 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 90 insertions(+), 1 deletion(-) diff --git a/nomad/state/schema.go b/nomad/state/schema.go index eb6805f04..197a33141 100644 --- a/nomad/state/schema.go +++ b/nomad/state/schema.go @@ -10,7 +10,18 @@ import ( ) const ( - TableNamespaces = "namespaces" + tableIndex = "index" + + TableNamespaces = "namespaces" + TableServiceRegistrations = "service_registrations" +) + +const ( + indexID = "id" + indexJob = "job" + indexNodeID = "node_id" + indexAllocID = "alloc_id" + indexServiceName = "service_name" ) var ( @@ -58,6 +69,7 @@ func init() { scalingPolicyTableSchema, scalingEventTableSchema, namespaceTableSchema, + serviceRegistrationsTableSchema, }...) } @@ -1033,3 +1045,80 @@ func namespaceTableSchema() *memdb.TableSchema { }, } } + +// serviceRegistrationsTableSchema returns the MemDB schema for Nomad native +// service registrations. +func serviceRegistrationsTableSchema() *memdb.TableSchema { + return &memdb.TableSchema{ + Name: TableServiceRegistrations, + Indexes: map[string]*memdb.IndexSchema{ + // The serviceID in combination with namespace forms a unique + // identifier for a service registration. This is used to look up + // and delete services in individual isolation. + indexID: { + Name: indexID, + AllowMissing: false, + Unique: true, + Indexer: &memdb.CompoundIndex{ + Indexes: []memdb.Indexer{ + &memdb.StringFieldIndex{ + Field: "Namespace", + }, + &memdb.StringFieldIndex{ + Field: "ID", + }, + }, + }, + }, + indexServiceName: { + Name: indexServiceName, + AllowMissing: false, + Unique: false, + Indexer: &memdb.CompoundIndex{ + Indexes: []memdb.Indexer{ + &memdb.StringFieldIndex{ + Field: "Namespace", + }, + &memdb.StringFieldIndex{ + Field: "ServiceName", + }, + }, + }, + }, + indexJob: { + Name: indexJob, + AllowMissing: false, + Unique: false, + Indexer: &memdb.CompoundIndex{ + Indexes: []memdb.Indexer{ + &memdb.StringFieldIndex{ + Field: "Namespace", + }, + &memdb.StringFieldIndex{ + Field: "JobID", + }, + }, + }, + }, + // The nodeID index allows lookups and deletions to be performed + // for an entire node. This is primarily used when a node becomes + // lost. + indexNodeID: { + Name: indexNodeID, + AllowMissing: false, + Unique: false, + Indexer: &memdb.StringFieldIndex{ + Field: "NodeID", + }, + }, + indexAllocID: { + Name: indexAllocID, + AllowMissing: false, + Unique: false, + Indexer: &memdb.StringFieldIndex{ + Field: "AllocID", + }, + }, + }, + } +}