2021-11-08 14:35:56 +00:00
|
|
|
//go:build !consulent
|
2019-11-25 17:57:35 +00:00
|
|
|
// +build !consulent
|
|
|
|
|
|
|
|
package state
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2021-11-08 14:35:56 +00:00
|
|
|
|
2022-04-05 21:10:06 +00:00
|
|
|
"github.com/hashicorp/consul/acl"
|
2021-11-08 14:35:56 +00:00
|
|
|
"github.com/hashicorp/consul/agent/structs"
|
2019-11-25 17:57:35 +00:00
|
|
|
)
|
|
|
|
|
2020-09-03 23:38:03 +00:00
|
|
|
func (g *Graveyard) insertTombstoneWithTxn(tx WriteTxn, _ string, stone *Tombstone, updateMax bool) error {
|
2019-11-25 17:57:35 +00:00
|
|
|
if err := tx.Insert("tombstones", stone); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if updateMax {
|
|
|
|
if err := indexUpdateMaxTxn(tx, stone.Index, "tombstones"); err != nil {
|
|
|
|
return fmt.Errorf("failed updating tombstone index: %v", err)
|
|
|
|
}
|
|
|
|
} else {
|
2021-03-08 18:02:41 +00:00
|
|
|
if err := tx.Insert(tableIndex, &IndexEntry{"tombstones", stone.Index}); err != nil {
|
2019-11-25 17:57:35 +00:00
|
|
|
return fmt.Errorf("failed updating tombstone index: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2021-11-08 14:35:56 +00:00
|
|
|
|
|
|
|
// GetMaxIndexTxn returns the highest index tombstone whose key matches the
|
|
|
|
// given context, using a prefix match.
|
2022-04-05 21:10:06 +00:00
|
|
|
func (g *Graveyard) GetMaxIndexTxn(tx ReadTxn, prefix string, _ *acl.EnterpriseMeta) (uint64, error) {
|
2021-11-08 14:35:56 +00:00
|
|
|
var lindex uint64
|
2021-11-08 21:20:50 +00:00
|
|
|
q := Query{Value: prefix, EnterpriseMeta: *structs.DefaultEnterpriseMetaInDefaultPartition()}
|
2021-11-08 14:35:56 +00:00
|
|
|
stones, err := tx.Get(tableTombstones, indexID+"_prefix", q)
|
|
|
|
if err != nil {
|
|
|
|
return 0, fmt.Errorf("failed querying tombstones: %s", err)
|
|
|
|
}
|
|
|
|
for stone := stones.Next(); stone != nil; stone = stones.Next() {
|
|
|
|
s := stone.(*Tombstone)
|
|
|
|
if s.Index > lindex {
|
|
|
|
lindex = s.Index
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return lindex, nil
|
|
|
|
}
|