summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTony Sun <tony.sun427@gmail.com>2020-07-21 18:47:32 -0700
committerTony Sun <tony.sun427@gmail.com>2020-07-22 12:44:20 -0700
commit0e727438bd1b45247b8dfe21f2e17388c69c205c (patch)
treee6b7b42eae829f4cf51e1499a56a5f5d80f1d0fb
parentc009825f691bcc574ec5439b386879a7a6e00778 (diff)
downloadcouchdb-0e727438bd1b45247b8dfe21f2e17388c69c205c.tar.gz
revert to using job_data
-rw-r--r--src/couch_jobs/src/couch_jobs_fdb.erl8
-rw-r--r--src/couch_views/src/couch_views_active_tasks.erl87
-rw-r--r--src/couch_views/src/couch_views_indexer.erl38
-rw-r--r--src/couch_views/src/couch_views_jobs.erl2
-rw-r--r--src/couch_views/src/couch_views_sup.erl1
-rw-r--r--src/fabric/src/fabric2_active_tasks.erl21
6 files changed, 38 insertions, 119 deletions
diff --git a/src/couch_jobs/src/couch_jobs_fdb.erl b/src/couch_jobs/src/couch_jobs_fdb.erl
index 143e57fd1..891aedc79 100644
--- a/src/couch_jobs/src/couch_jobs_fdb.erl
+++ b/src/couch_jobs/src/couch_jobs_fdb.erl
@@ -33,7 +33,6 @@
get_activity_vs/2,
get_activity_vs_and_watch/2,
- get_active_jobs/1,
get_active_since/3,
get_inactive_since/3,
re_enqueue_inactive/3,
@@ -356,13 +355,6 @@ get_activity_vs_and_watch(#{jtx := true} = JTx, Type) ->
end.
-get_active_jobs(Type) ->
- fabric2_fdb:transactional(fun(Tx) ->
- JTx = init_jtx(Tx),
- get_active_since(JTx, Type, {versionstamp, 0, 0})
- end).
-
-
get_active_since(#{jtx := true} = JTx, Type, Versionstamp) ->
#{tx := Tx, jobs_path := Jobs} = get_jtx(JTx),
Prefix = erlfdb_tuple:pack({?ACTIVITY}, Jobs),
diff --git a/src/couch_views/src/couch_views_active_tasks.erl b/src/couch_views/src/couch_views_active_tasks.erl
deleted file mode 100644
index 5ebba91d8..000000000
--- a/src/couch_views/src/couch_views_active_tasks.erl
+++ /dev/null
@@ -1,87 +0,0 @@
-% Licensed under the Apache License, Version 2.0 (the "License"); you may not
-% use this file except in compliance with the License. You may obtain a copy of
-% the License at
-%
-% http://www.apache.org/licenses/LICENSE-2.0
-%
-% Unless required by applicable law or agreed to in writing, software
-% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-% License for the specific language governing permissions and limitations under
-% the License.
-
-
--module(couch_views_active_tasks).
-
-
--export([
- populate_active_tasks/2
-]).
-
-
--include("couch_views.hrl").
--include_lib("couch/include/couch_db.hrl").
--include_lib("couch_mrview/include/couch_mrview.hrl").
--include_lib("fabric/include/fabric2.hrl").
-
-
-populate_active_tasks(<<"views">>, Data) ->
- #{
- <<"db_name">> := DbName,
- <<"ddoc_id">> := DDocId,
- <<"changes_done">> := ChangesDone,
- <<"db_uuid">> := DbUUID
- } = Data,
-
- {ok, Db} = try
- fabric2_db:open(DbName, [?ADMIN_CTX, {uuid, DbUUID}])
- catch error:database_does_not_exist ->
- {ok, not_found}
- end,
-
- {ok, DDoc} = case fabric2_db:open_doc(Db, DDocId) of
- {ok, DDoc0} ->
- {ok, DDoc0};
- {not_found, _} ->
- {ok, not_found}
- end,
-
- case {Db, DDoc} of
- {not_found, _} ->
- #{};
- {_, not_found} ->
- #{};
- {_, _} ->
- {ok, Mrst} = couch_views_util:ddoc_to_mrst(DbName, DDoc),
- {ViewSeq, DBSeq} = fabric2_fdb:transactional(Db, fun(TxDb) ->
- VSeq = couch_views_fdb:get_update_seq(TxDb, Mrst),
- DBSeq0 = fabric2_fdb:get_last_change(TxDb),
- {VSeq, DBSeq0}
- end),
- VStamp = convert_seq_to_stamp(ViewSeq),
- DBStamp = convert_seq_to_stamp(DBSeq),
- #{
- <<"database">> => DbName,
- <<"changes_done">> => ChangesDone,
- <<"design_document">> => DDocId,
- <<"current_version_stamp">> => VStamp,
- <<"db_version_stamp">> => DBStamp
- }
- end.
-
-populate_active_task(_ , _Data) ->
- #{}.
-
-
-% move this over to util
-convert_seq_to_stamp(<<"0">>) ->
- <<"0-0-0">>;
-
-convert_seq_to_stamp(undefined) ->
- <<"0-0-0">>;
-
-convert_seq_to_stamp(Seq) ->
- {_, Stamp, Batch, DocNumber} = fabric2_fdb:seq_to_vs(Seq),
- VS = integer_to_list(Stamp) ++ "-" ++ integer_to_list(Batch)
- ++ "-" ++ integer_to_list(DocNumber),
- list_to_binary(VS).
diff --git a/src/couch_views/src/couch_views_indexer.erl b/src/couch_views/src/couch_views_indexer.erl
index cabad7714..68cef3144 100644
--- a/src/couch_views/src/couch_views_indexer.erl
+++ b/src/couch_views/src/couch_views_indexer.erl
@@ -490,7 +490,8 @@ report_progress(State, UpdateType) ->
job := Job1,
job_data := JobData,
last_seq := LastSeq,
- changes_done := ChangesDone0
+ db_seq := DBSeq,
+ changes_done := ChangesDone
} = State,
#{
@@ -499,9 +500,16 @@ report_progress(State, UpdateType) ->
<<"ddoc_id">> := DDocId,
<<"sig">> := Sig,
<<"retries">> := Retries,
- <<"changes_done">> := ChangesDone1
+ <<"active_tasks_info">> := ActiveTasks
} = JobData,
+ TotalDone = case maps:get(<<"changes_done">>, ActiveTasks, 0) of
+ 0 -> ChangesDone;
+ N -> N + ChangesDone
+ end,
+
+ NewActiveTasks = active_tasks_info(TotalDone, DbName, DDocId,
+ LastSeq, DBSeq),
% Reconstruct from scratch to remove any
% possible existing error state.
@@ -512,7 +520,7 @@ report_progress(State, UpdateType) ->
<<"sig">> => Sig,
<<"view_seq">> => LastSeq,
<<"retries">> => Retries,
- <<"changes_done">> => ChangesDone0 + ChangesDone1
+ <<"active_tasks_info">> => NewActiveTasks
},
case UpdateType of
@@ -551,3 +559,27 @@ key_size_limit() ->
value_size_limit() ->
config:get_integer("couch_views", "value_size_limit", ?VALUE_SIZE_LIMIT).
+
+
+active_tasks_info(ChangesDone, DbName, DDocId, LastSeq, DBSeq) ->
+ {[
+ {<<"type">>, <<"indexer">>},
+ {<<"database">>, DbName},
+ {<<"changes_done">>, ChangesDone},
+ {<<"design_document">>, DDocId},
+ {<<"current_version_stamp">>, convert_seq_to_stamp(LastSeq)},
+ {<<"db_version_stamp">>, convert_seq_to_stamp(DBSeq)}
+ ]}.
+
+
+convert_seq_to_stamp(<<"0">>) ->
+ <<"0-0-0">>;
+
+convert_seq_to_stamp(undefined) ->
+ <<"0-0-0">>;
+
+convert_seq_to_stamp(Seq) ->
+ {_, Stamp, Batch, DocNumber} = fabric2_fdb:seq_to_vs(Seq),
+ VS = integer_to_list(Stamp) ++ "-" ++ integer_to_list(Batch)
+ ++ "-" ++ integer_to_list(DocNumber),
+ list_to_binary(VS). \ No newline at end of file
diff --git a/src/couch_views/src/couch_views_jobs.erl b/src/couch_views/src/couch_views_jobs.erl
index 5ecfe033a..540aa0060 100644
--- a/src/couch_views/src/couch_views_jobs.erl
+++ b/src/couch_views/src/couch_views_jobs.erl
@@ -151,7 +151,7 @@ job_data(Db, Mrst) ->
ddoc_id => DDocId,
sig => fabric2_util:to_hex(Sig),
retries => 0,
- changes_done => 0
+ active_tasks_info => #{}
}.
diff --git a/src/couch_views/src/couch_views_sup.erl b/src/couch_views/src/couch_views_sup.erl
index ec753a605..94531893d 100644
--- a/src/couch_views/src/couch_views_sup.erl
+++ b/src/couch_views/src/couch_views_sup.erl
@@ -29,7 +29,6 @@
start_link() ->
ok = register_views_index(),
- ok = fabric2_active_tasks:register_tasks(couch_views_active_tasks),
Arg = case fabric2_node_types:is_type(view_indexing) of
true -> normal;
false -> builds_disabled
diff --git a/src/fabric/src/fabric2_active_tasks.erl b/src/fabric/src/fabric2_active_tasks.erl
index 13d26622f..656d48290 100644
--- a/src/fabric/src/fabric2_active_tasks.erl
+++ b/src/fabric/src/fabric2_active_tasks.erl
@@ -2,8 +2,7 @@
-export([
- get_active_tasks/0,
- register_tasks/1
+ get_active_tasks/0
]).
@@ -14,11 +13,6 @@
-define(ACTIVE_TASK_JOB_TYPES, [<<"views">>, <<"replication">>]).
-register_tasks(Mod) when is_atom(Mod) ->
- ActiveTasks = lists:usort([Mod | registrations()]),
- application:set_env(fabric, active_tasks, ActiveTasks).
-
-
get_active_tasks() ->
ActiveTasks = lists:foldl(fun(Type, TaskAcc) ->
Tasks = couch_jobs_fdb:tx(couch_jobs_fdb:get_jtx(undefined),
@@ -26,20 +20,9 @@ get_active_tasks() ->
JobIds = couch_jobs:get_active_jobs(JTx, Type),
maps:map(fun(JobId, _) ->
{ok, Data} = couch_jobs:get_job_data(JTx, Type, JobId),
- populate_active_tasks(Type, Data)
+ maps:get(<<"active_tasks_info">>, Data #{})
end, JobIds)
end),
maps:merge(TaskAcc, Tasks)
end, #{}, ?ACTIVE_TASK_JOB_TYPES),
maps:values(ActiveTasks).
-
-
-populate_active_tasks(Type, Data) ->
- lists:foldl(fun(Mod, TaskAcc) ->
- Tasks = Mod:populate_active_tasks(Type, Data),
- maps:merge(TaskAcc, Tasks)
- end, #{}, registrations()).
-
-
-registrations() ->
- application:get_env(fabric, active_tasks, []).