nickva commented on a change in pull request #2712: Handle db re-creation in 
view indexing
URL: https://github.com/apache/couchdb/pull/2712#discussion_r398091904
 
 

 ##########
 File path: src/couch_views/test/couch_views_indexer_test.erl
 ##########
 @@ -372,6 +376,76 @@ index_autoupdater_callback(Db) ->
     ?assertEqual(ok, couch_views_jobs:wait_for_job(JobId, DbSeq)).
 
 
+handle_db_recreated_when_running(Db) ->
+    DbName = fabric2_db:name(Db),
+
+    DDoc = create_ddoc(),
+    {ok, _} = fabric2_db:update_doc(Db, DDoc, []),
+    {ok, _} = fabric2_db:update_doc(Db, doc(0), []),
+    {ok, _} = fabric2_db:update_doc(Db, doc(1), []),
+
+    % To intercept job building while it is running ensure updates happen one
+    % row at a time.
+    config:set("couch_views", "change_limit", "1", false),
+
+    meck_intercept_job_update(self()),
+
+    [{ok, JobId}] = couch_views:build_indices(Db, [DDoc]),
+
+    {Indexer, _Job, _Data} = wait_indexer_update(10000),
+
+    {ok, State} = couch_jobs:get_job_state(undefined, ?INDEX_JOB_TYPE, JobId),
+    ?assertEqual(running, State),
+
+    ok = fabric2_db:delete(DbName, []),
+    {ok, Db1} = fabric2_db:create(DbName, [?ADMIN_CTX]),
+
+    {ok, _} = fabric2_db:update_doc(Db1, DDoc, []),
+    {ok, _} = fabric2_db:update_doc(Db1, doc(2), []),
+    {ok, _} = fabric2_db:update_doc(Db1, doc(3), []),
+
+    reset_intercept_job_update(Indexer),
+
+    {ok, Out2} = run_query(Db1, DDoc, ?MAP_FUN1),
+    ?assertEqual([
 
 Review comment:
   Excellent call. It turns out this was covering up 2(!) bugs in fabric2_fdb 
layer.
   
   After updating the test to subscribe and check for db_deleted error, noticed 
that the job returned as `finished ok` instead of having an error. That was 
because 
   
   1) We had forgotten to update all the place were DbPrefix was constructed in 
the recent HCA commit so we still used the `{?DBS, Name}` pattern.
   
   2) There was another bug discovered where we did not reset the  `metadata 
was checked` before each transaction execution.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to