From c8f5443e0998d3d3d43505ff5a6fdf8c438d6c24 Mon Sep 17 00:00:00 2001 From: Micah Anderson Date: Thu, 17 Apr 2014 15:43:11 -0400 Subject: fix for narrow timing issue that occurs when the check for a document existence fails, but then the document appears in the cluster before the script is able to put the document, causing a 409 Conflict (#5523) --- files/couch-doc-update | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/files/couch-doc-update b/files/couch-doc-update index 242ed14..5ceed5e 100644 --- a/files/couch-doc-update +++ b/files/couch-doc-update @@ -90,6 +90,7 @@ end # update document # def set_document(db, id, data) + attempt ||= 1 doc = get_document(db, id) if doc doc.id ||= id @@ -97,6 +98,11 @@ def set_document(db, id, data) else create_document(db, id, data) end +rescue RestClient::Conflict + # retry once, reraise if that does not work + raise if attempt > 1 + attempt += 1 + retry end def get_document(db, doc_id) -- cgit v1.2.3