summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul J. Davis <paul.joseph.davis@gmail.com>2019-10-30 13:32:01 -0500
committerPaul J. Davis <paul.joseph.davis@gmail.com>2019-10-30 14:01:39 -0500
commit8bb0718fccb9e283538ab75d6070d47f10003b9e (patch)
tree61d5a1dbb0a3a7bdd772a2dd9d235156f023581a
parent8d5c10717479a4aaa434f2d5bdb3899e6c07e122 (diff)
downloadcouchdb-8bb0718fccb9e283538ab75d6070d47f10003b9e.tar.gz
Abandon a view job if the db or ddoc is deleted
If we don't explicitly bail out of running the job it will loop indefinitely in the couch_jobs retry logic.
-rw-r--r--src/couch_views/src/couch_views_indexer.erl23
1 files changed, 21 insertions, 2 deletions
diff --git a/src/couch_views/src/couch_views_indexer.erl b/src/couch_views/src/couch_views_indexer.erl
index 55ce06311..7c05c1d60 100644
--- a/src/couch_views/src/couch_views_indexer.erl
+++ b/src/couch_views/src/couch_views_indexer.erl
@@ -42,8 +42,27 @@ init() ->
<<"sig">> := JobSig
} = Data,
- {ok, Db} = fabric2_db:open(DbName, [?ADMIN_CTX]),
- {ok, DDoc} = fabric2_db:open_doc(Db, DDocId),
+ {ok, Db} = try
+ fabric2_db:open(DbName, [?ADMIN_CTX])
+ catch error:database_does_not_exist ->
+ couch_jobs:finish(undefined, Job, Data#{
+ error => db_deleted,
+ reason => "Database was deleted"
+ }),
+ exit(normal)
+ end,
+
+ {ok, DDoc} = case fabric2_db:open_doc(Db, DDocId) of
+ {ok, DDoc0} ->
+ {ok, DDoc0};
+ {not_found, _} ->
+ couch_jobs:finish(undefined, Job, Data#{
+ error => ddoc_deleted,
+ reason => "Design document was deleted"
+ }),
+ exit(normal)
+ end,
+
{ok, Mrst} = couch_views_util:ddoc_to_mrst(DbName, DDoc),
HexSig = fabric2_util:to_hex(Mrst#mrst.sig),