state: use constants for mesh-topology table operations
This commit is contained in:
parent
a736a9cec4
commit
8a1a11814d
|
@ -2992,9 +2992,9 @@ func downstreamsFromRegistrationTxn(tx ReadTxn, ws memdb.WatchSet, sn structs.Se
|
||||||
func linkedFromRegistrationTxn(tx ReadTxn, ws memdb.WatchSet, service structs.ServiceName, downstreams bool) (uint64, []structs.ServiceName, error) {
|
func linkedFromRegistrationTxn(tx ReadTxn, ws memdb.WatchSet, service structs.ServiceName, downstreams bool) (uint64, []structs.ServiceName, error) {
|
||||||
// To fetch upstreams we query services that have the input listed as a downstream
|
// To fetch upstreams we query services that have the input listed as a downstream
|
||||||
// To fetch downstreams we query services that have the input listed as an upstream
|
// To fetch downstreams we query services that have the input listed as an upstream
|
||||||
index := "downstream"
|
index := indexDownstream
|
||||||
if downstreams {
|
if downstreams {
|
||||||
index = "upstream"
|
index = indexUpstream
|
||||||
}
|
}
|
||||||
|
|
||||||
iter, err := tx.Get(tableMeshTopology, index, service)
|
iter, err := tx.Get(tableMeshTopology, index, service)
|
||||||
|
@ -3053,7 +3053,7 @@ func updateMeshTopology(tx WriteTxn, idx uint64, node string, svc *structs.NodeS
|
||||||
upstreamMeta := structs.NewEnterpriseMeta(u.DestinationNamespace)
|
upstreamMeta := structs.NewEnterpriseMeta(u.DestinationNamespace)
|
||||||
upstream := structs.NewServiceName(u.DestinationName, &upstreamMeta)
|
upstream := structs.NewServiceName(u.DestinationName, &upstreamMeta)
|
||||||
|
|
||||||
obj, err := tx.First(tableMeshTopology, "id", upstream, downstream)
|
obj, err := tx.First(tableMeshTopology, indexID, upstream, downstream)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("%q lookup failed: %v", tableMeshTopology, err)
|
return fmt.Errorf("%q lookup failed: %v", tableMeshTopology, err)
|
||||||
}
|
}
|
||||||
|
@ -3097,7 +3097,7 @@ func updateMeshTopology(tx WriteTxn, idx uint64, node string, svc *structs.NodeS
|
||||||
|
|
||||||
for u := range oldUpstreams {
|
for u := range oldUpstreams {
|
||||||
if !inserted[u] {
|
if !inserted[u] {
|
||||||
if _, err := tx.DeleteAll(tableMeshTopology, "id", u, downstream); err != nil {
|
if _, err := tx.DeleteAll(tableMeshTopology, indexID, u, downstream); err != nil {
|
||||||
return fmt.Errorf("failed to truncate %s table: %v", tableMeshTopology, err)
|
return fmt.Errorf("failed to truncate %s table: %v", tableMeshTopology, err)
|
||||||
}
|
}
|
||||||
if err := indexUpdateMaxTxn(tx, idx, tableMeshTopology); err != nil {
|
if err := indexUpdateMaxTxn(tx, idx, tableMeshTopology); err != nil {
|
||||||
|
@ -3119,7 +3119,7 @@ func cleanupMeshTopology(tx WriteTxn, idx uint64, service *structs.ServiceNode)
|
||||||
sid := service.CompoundServiceID()
|
sid := service.CompoundServiceID()
|
||||||
uid := structs.UniqueID(service.Node, sid.String())
|
uid := structs.UniqueID(service.Node, sid.String())
|
||||||
|
|
||||||
iter, err := tx.Get(tableMeshTopology, "downstream", sn)
|
iter, err := tx.Get(tableMeshTopology, indexDownstream, sn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("%q lookup failed: %v", tableMeshTopology, err)
|
return fmt.Errorf("%q lookup failed: %v", tableMeshTopology, err)
|
||||||
}
|
}
|
||||||
|
@ -3190,7 +3190,7 @@ func deleteGatewayServiceTopologyMapping(tx WriteTxn, idx uint64, gs *structs.Ga
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := tx.DeleteAll(tableMeshTopology, "id", gs.Service, gs.Gateway); err != nil {
|
if _, err := tx.DeleteAll(tableMeshTopology, indexID, gs.Service, gs.Gateway); err != nil {
|
||||||
return fmt.Errorf("failed to truncate %s table: %v", tableMeshTopology, err)
|
return fmt.Errorf("failed to truncate %s table: %v", tableMeshTopology, err)
|
||||||
}
|
}
|
||||||
if err := indexUpdateMaxTxn(tx, idx, tableMeshTopology); err != nil {
|
if err := indexUpdateMaxTxn(tx, idx, tableMeshTopology); err != nil {
|
||||||
|
@ -3206,7 +3206,7 @@ func truncateGatewayServiceTopologyMappings(tx WriteTxn, idx uint64, gateway str
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := tx.DeleteAll(tableMeshTopology, "downstream", gateway); err != nil {
|
if _, err := tx.DeleteAll(tableMeshTopology, indexDownstream, gateway); err != nil {
|
||||||
return fmt.Errorf("failed to truncate %s table: %v", tableMeshTopology, err)
|
return fmt.Errorf("failed to truncate %s table: %v", tableMeshTopology, err)
|
||||||
}
|
}
|
||||||
if err := indexUpdateMaxTxn(tx, idx, tableMeshTopology); err != nil {
|
if err := indexUpdateMaxTxn(tx, idx, tableMeshTopology); err != nil {
|
||||||
|
|
|
@ -24,6 +24,8 @@ const (
|
||||||
indexStatus = "status"
|
indexStatus = "status"
|
||||||
indexNodeService = "node_service"
|
indexNodeService = "node_service"
|
||||||
indexNode = "node"
|
indexNode = "node"
|
||||||
|
indexUpstream = "upstream"
|
||||||
|
indexDownstream = "downstream"
|
||||||
)
|
)
|
||||||
|
|
||||||
// nodesTableSchema returns a new table schema used for storing struct.Node.
|
// nodesTableSchema returns a new table schema used for storing struct.Node.
|
||||||
|
@ -245,16 +247,16 @@ func meshTopologyTableSchema() *memdb.TableSchema {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"upstream": {
|
indexUpstream: {
|
||||||
Name: "upstream",
|
Name: indexUpstream,
|
||||||
AllowMissing: true,
|
AllowMissing: true,
|
||||||
Unique: false,
|
Unique: false,
|
||||||
Indexer: &ServiceNameIndex{
|
Indexer: &ServiceNameIndex{
|
||||||
Field: "Upstream",
|
Field: "Upstream",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"downstream": {
|
indexDownstream: {
|
||||||
Name: "downstream",
|
Name: indexDownstream,
|
||||||
AllowMissing: false,
|
AllowMissing: false,
|
||||||
Unique: false,
|
Unique: false,
|
||||||
Indexer: &ServiceNameIndex{
|
Indexer: &ServiceNameIndex{
|
||||||
|
|
|
@ -278,7 +278,7 @@ func deleteConfigEntryTxn(tx WriteTxn, idx uint64, kind, name string, entMeta *s
|
||||||
}
|
}
|
||||||
// Also clean up associations in the mesh topology table for ingress gateways
|
// Also clean up associations in the mesh topology table for ingress gateways
|
||||||
if kind == structs.IngressGateway {
|
if kind == structs.IngressGateway {
|
||||||
if _, err := tx.DeleteAll(tableMeshTopology, "downstream", sn); err != nil {
|
if _, err := tx.DeleteAll(tableMeshTopology, indexDownstream, sn); err != nil {
|
||||||
return fmt.Errorf("failed to truncate %s table: %v", tableMeshTopology, err)
|
return fmt.Errorf("failed to truncate %s table: %v", tableMeshTopology, err)
|
||||||
}
|
}
|
||||||
if err := indexUpdateMaxTxn(tx, idx, tableMeshTopology); err != nil {
|
if err := indexUpdateMaxTxn(tx, idx, tableMeshTopology); err != nil {
|
||||||
|
|
Loading…
Reference in New Issue