From 3e0f77682a138d3ecc36388d35af5ef3e811d9eb Mon Sep 17 00:00:00 2001 From: Armon Dadgar Date: Thu, 8 Jan 2015 17:08:58 -0800 Subject: [PATCH] agent: Support the ?cas parameter to KV DELETE --- command/agent/kvs_endpoint.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/command/agent/kvs_endpoint.go b/command/agent/kvs_endpoint.go index ffed10f9c9..54f843c917 100644 --- a/command/agent/kvs_endpoint.go +++ b/command/agent/kvs_endpoint.go @@ -226,12 +226,28 @@ func (s *HTTPServer) KVSDelete(resp http.ResponseWriter, req *http.Request, args 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 var out bool if err := s.agent.RPC("KVS.Apply", &applyReq, &out); err != nil { 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