Browse Source

agent: Support the ?cas parameter to KV DELETE

pull/589/head
Armon Dadgar 10 years ago
parent
commit
3e0f77682a
  1. 18
      command/agent/kvs_endpoint.go

18
command/agent/kvs_endpoint.go

@ -226,12 +226,28 @@ func (s *HTTPServer) KVSDelete(resp http.ResponseWriter, req *http.Request, args
return nil, nil return nil, nil
} }
// Check for cas value
if _, ok := params["cas"]; ok {
casVal, err := strconv.ParseUint(params.Get("cas"), 10, 64)
if err != nil {
return nil, err
}
applyReq.DirEnt.ModifyIndex = casVal
applyReq.Op = structs.KVSDeleteCAS
}
// Make the RPC // Make the RPC
var out bool var out bool
if err := s.agent.RPC("KVS.Apply", &applyReq, &out); err != nil { if err := s.agent.RPC("KVS.Apply", &applyReq, &out); err != nil {
return nil, err return nil, err
} }
return nil, nil
// Only use the out value if this was a CAS
if applyReq.Op == structs.KVSDeleteCAS {
return out, nil
} else {
return true, nil
}
} }
// missingKey checks if the key is missing // missingKey checks if the key is missing

Loading…
Cancel
Save