2023-03-28 18:39:22 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2021-11-16 18:04:01 +00:00
|
|
|
//go:build !consulent
|
2021-08-17 18:29:39 +00:00
|
|
|
// +build !consulent
|
|
|
|
|
|
|
|
package state
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2022-04-05 21:10:06 +00:00
|
|
|
"github.com/hashicorp/consul/acl"
|
2021-08-17 18:29:39 +00:00
|
|
|
"github.com/hashicorp/consul/agent/structs"
|
|
|
|
)
|
|
|
|
|
2022-04-05 21:10:06 +00:00
|
|
|
func coordinatesMaxIndex(tx ReadTxn, entMeta *acl.EnterpriseMeta) uint64 {
|
2021-08-17 18:29:39 +00:00
|
|
|
return maxIndexTxn(tx, tableCoordinates)
|
|
|
|
}
|
|
|
|
|
2022-04-05 21:10:06 +00:00
|
|
|
func updateCoordinatesIndexes(tx WriteTxn, idx uint64, entMeta *acl.EnterpriseMeta) error {
|
2021-08-17 18:29:39 +00:00
|
|
|
// Update the index.
|
|
|
|
if err := indexUpdateMaxTxn(tx, idx, tableCoordinates); err != nil {
|
|
|
|
return fmt.Errorf("failed updating index: %s", err)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func ensureCoordinateTxn(tx WriteTxn, idx uint64, coord *structs.Coordinate) error {
|
|
|
|
// ensure that the Partition is always empty within the state store
|
|
|
|
coord.Partition = ""
|
|
|
|
|
|
|
|
if err := tx.Insert(tableCoordinates, coord); err != nil {
|
|
|
|
return fmt.Errorf("failed inserting coordinate: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := updateCoordinatesIndexes(tx, idx, coord.GetEnterpriseMeta()); err != nil {
|
|
|
|
return fmt.Errorf("failed updating coordinate index: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|