agent: Support the ?cas parameter to KV DELETE

This commit is contained in:
Armon Dadgar 2015-01-08 17:08:58 -08:00
parent 65bebca0f5
commit 3e0f77682a
1 changed files with 17 additions and 1 deletions

View File

@ -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