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
|
|
|
|
|
|
|
"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.
|
|
|
|
func (g *Graveyard) GetMaxIndexTxn(tx ReadTxn, prefix string, _ *structs.EnterpriseMeta) (uint64, error) {
|
|
|
|
var lindex uint64
|
|
|
|
q := Query{Value: prefix}
|
|
|
|
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
|
|
|
|
}
|