txn: fix an issue with querying nodes by name instead of ID

pull/5172/head
Kyle Havlovitz 6 years ago
parent 67bac7a815
commit 995e728ea0

@ -127,13 +127,17 @@ func (s *Store) txnNode(tx *memdb.Txn, idx uint64, op *structs.TxnNodeOp) (struc
var entry *structs.Node
var err error
switch op.Verb {
case api.NodeGet:
getNode := func() (*structs.Node, error) {
if op.Node.ID != "" {
entry, err = getNodeIDTxn(tx, op.Node.ID)
return getNodeIDTxn(tx, op.Node.ID)
} else {
entry, err = getNodeTxn(tx, op.Node.Node)
return getNodeTxn(tx, op.Node.Node)
}
}
switch op.Verb {
case api.NodeGet:
entry, err = getNode()
if entry == nil && err == nil {
err = fmt.Errorf("node %q doesn't exist", op.Node.Node)
}
@ -141,7 +145,7 @@ func (s *Store) txnNode(tx *memdb.Txn, idx uint64, op *structs.TxnNodeOp) (struc
case api.NodeSet:
err = s.ensureNodeTxn(tx, idx, &op.Node)
if err == nil {
entry, err = getNodeIDTxn(tx, op.Node.ID)
entry, err = getNode()
}
case api.NodeCAS:
@ -151,7 +155,7 @@ func (s *Store) txnNode(tx *memdb.Txn, idx uint64, op *structs.TxnNodeOp) (struc
err = fmt.Errorf("failed to set node %q, index is stale", op.Node.Node)
break
}
entry, err = getNodeIDTxn(tx, op.Node.ID)
entry, err = getNode()
case api.NodeDelete:
err = s.deleteNodeTxn(tx, idx, op.Node.Node)

@ -119,21 +119,6 @@ func (t *Txn) Apply(args *structs.TxnRequest, reply *structs.TxnResponse) error
return nil
}
str := ""
for _, op := range args.Ops {
switch {
case op.KV != nil:
str += fmt.Sprintf("%#v\n", op.KV)
case op.Node != nil:
str += fmt.Sprintf("%#v\n", op.Node)
case op.Service != nil:
str += fmt.Sprintf("%#v\n", op.Service)
case op.Check != nil:
str += fmt.Sprintf("%#v\n", op.Check)
}
}
//return fmt.Errorf("%s", str)
// Apply the update.
resp, err := t.srv.raftApply(structs.TxnRequestType, args)
if err != nil {

@ -278,7 +278,6 @@ func (s *HTTPServer) Txn(resp http.ResponseWriter, req *http.Request) (interface
// Fast-path a transaction with only writes to the read-only endpoint,
// which bypasses Raft, and allows for staleness.
s.agent.logger.Printf("ops: %d", len(ops))
conflict := false
var ret interface{}
if writes == 0 {
@ -308,7 +307,6 @@ func (s *HTTPServer) Txn(resp http.ResponseWriter, req *http.Request) (interface
return nil, err
}
ret, conflict = reply, len(reply.Errors) > 0
s.agent.logger.Printf("results: %d, errors: %d", len(reply.Results), len(reply.Errors))
}
// If there was a conflict return the response object but set a special

Loading…
Cancel
Save