txn: add pre-check operations to txn endpoint
This commit is contained in:
parent
8a0d7b65d6
commit
bd6b7ad162
|
@ -20,6 +20,13 @@ type Catalog struct {
|
|||
srv *Server
|
||||
}
|
||||
|
||||
// checkPreApply does the verification of a check before it is applied to Raft.
|
||||
func checkPreApply(check *structs.HealthCheck) {
|
||||
if check.CheckID == "" && check.Name != "" {
|
||||
check.CheckID = types.CheckID(check.Name)
|
||||
}
|
||||
}
|
||||
|
||||
// Register is used register that a node is providing a given service.
|
||||
func (c *Catalog) Register(args *structs.RegisterRequest, reply *struct{}) error {
|
||||
if done, err := c.srv.forward("Catalog.Register", args, args, reply); done {
|
||||
|
@ -96,12 +103,10 @@ func (c *Catalog) Register(args *structs.RegisterRequest, reply *struct{}) error
|
|||
args.Check = nil
|
||||
}
|
||||
for _, check := range args.Checks {
|
||||
if check.CheckID == "" && check.Name != "" {
|
||||
check.CheckID = types.CheckID(check.Name)
|
||||
}
|
||||
if check.Node == "" {
|
||||
check.Node = args.Node
|
||||
}
|
||||
checkPreApply(check)
|
||||
}
|
||||
|
||||
// Check the complete register request against the given ACL policy.
|
||||
|
|
|
@ -1592,7 +1592,7 @@ func (s *Store) DeleteCheck(idx uint64, node string, checkID types.CheckID) erro
|
|||
}
|
||||
|
||||
// deleteCheckCASTxn is used to try doing a check delete operation with a given
|
||||
// raft index. If the CAS index specified is not equal to the last bserved index for
|
||||
// raft index. If the CAS index specified is not equal to the last observed index for
|
||||
// the given check, then the call is a noop, otherwise a normal check delete is invoked.
|
||||
func (s *Store) deleteCheckCASTxn(tx *memdb.Txn, idx, cidx uint64, node string, checkID types.CheckID) (bool, error) {
|
||||
// Try to retrieve the existing health check.
|
||||
|
|
|
@ -21,7 +21,8 @@ func (t *Txn) preCheck(authorizer acl.Authorizer, ops structs.TxnOps) structs.Tx
|
|||
|
||||
// Perform the pre-apply checks for any KV operations.
|
||||
for i, op := range ops {
|
||||
if op.KV != nil {
|
||||
switch {
|
||||
case op.KV != nil:
|
||||
ok, err := kvsPreApply(t.srv, authorizer, op.KV.Verb, &op.KV.DirEnt)
|
||||
if err != nil {
|
||||
errors = append(errors, &structs.TxnError{
|
||||
|
@ -35,6 +36,8 @@ func (t *Txn) preCheck(authorizer acl.Authorizer, ops structs.TxnOps) structs.Tx
|
|||
What: err.Error(),
|
||||
})
|
||||
}
|
||||
case op.Check != nil:
|
||||
checkPreApply(&op.Check.Check)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue