open-consul/agent/consul/state/peering_oss_test.go
freddygv 6d368b5eed Update peering state and RPC for deferred deletion
When deleting a peering we do not want to delete the peering and all
imported data in a single operation, since deleting a large amount of
data at once could overload Consul.

Instead we defer deletion of peerings so that:

1. When a peering deletion request is received via gRPC the peering is
   marked for deletion by setting the DeletedAt field.

2. A leader routine will monitor for peerings that are marked for
   deletion and kick off a throttled deletion of all imported resources
   before deleting the peering itself.

This commit mostly addresses point #1 by modifying the peering service
to mark peerings for deletion. Another key change is to add a
PeeringListDeleted state store function which can return all peerings
marked for deletion. This function is what will be watched by the
deferred deletion leader routine.
2022-06-13 12:10:32 -06:00

86 lines
1.9 KiB
Go

//go:build !consulent
// +build !consulent
package state
import (
"time"
"github.com/hashicorp/consul/agent/structs"
"github.com/hashicorp/consul/proto/pbpeering"
)
func testIndexerTablePeering() map[string]indexerTestCase {
id := "432feb2f-5476-4ae2-b33c-e43640ca0e86"
encodedID := []byte{0x43, 0x2f, 0xeb, 0x2f, 0x54, 0x76, 0x4a, 0xe2, 0xb3, 0x3c, 0xe4, 0x36, 0x40, 0xca, 0xe, 0x86}
obj := &pbpeering.Peering{
Name: "TheName",
ID: id,
DeletedAt: structs.TimeToProto(time.Now()),
}
return map[string]indexerTestCase{
indexID: {
read: indexValue{
source: "432feb2f-5476-4ae2-b33c-e43640ca0e86",
expected: encodedID,
},
write: indexValue{
source: obj,
expected: encodedID,
},
},
indexName: {
read: indexValue{
source: Query{
Value: "TheNAME",
EnterpriseMeta: *structs.DefaultEnterpriseMetaInPartition("pArTition"),
},
expected: []byte("thename\x00"),
},
write: indexValue{
source: obj,
expected: []byte("thename\x00"),
},
prefix: []indexValue{
{
source: *structs.DefaultEnterpriseMetaInPartition("pArTition"),
expected: nil,
},
},
},
indexDeleted: {
read: indexValue{
source: BoolQuery{
Value: true,
EnterpriseMeta: *structs.DefaultEnterpriseMetaInPartition("partITION"),
},
expected: []byte("\x01"),
},
write: indexValue{
source: obj,
expected: []byte("\x01"),
},
extra: []indexerTestCase{
{
read: indexValue{
source: BoolQuery{
Value: false,
EnterpriseMeta: *structs.DefaultEnterpriseMetaInPartition("partITION"),
},
expected: []byte("\x00"),
},
write: indexValue{
source: &pbpeering.Peering{
Name: "TheName",
Partition: "PartItioN",
},
expected: []byte("\x00"),
},
},
},
},
}
}