You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by va...@apache.org on 2019/11/19 17:54:22 UTC
[couchdb] 01/01: Draft implementation of node types
This is an automated email from the ASF dual-hosted git repository.
vatamane pushed a commit to branch fdb-node-types
in repository https://gitbox.apache.org/repos/asf/couchdb.git
commit b374987ef4ac2057e91bf1056423b0052d23c314
Author: Nick Vatamaniuc <va...@apache.org>
AuthorDate: Tue Nov 19 12:52:49 2019 -0500
Draft implementation of node types
---
src/chttpd/src/chttpd_sup.erl | 19 +++++++----
src/couch_views/src/couch_views_server.erl | 17 +++++----
src/fabric/src/fabric2_node_types.erl | 55 ++++++++++++++++++++++++++++++
3 files changed, 78 insertions(+), 13 deletions(-)
diff --git a/src/chttpd/src/chttpd_sup.erl b/src/chttpd/src/chttpd_sup.erl
index d4bdb11..16e5935 100644
--- a/src/chttpd/src/chttpd_sup.erl
+++ b/src/chttpd/src/chttpd_sup.erl
@@ -29,7 +29,15 @@ start_link(Args) ->
supervisor:start_link({local,?MODULE}, ?MODULE, Args).
init([]) ->
- Children = [
+ Children = case fabric2_node_types:is_type("api_frontend") of
+ true -> get_children();
+ false -> []
+ end,
+ {ok, {{one_for_one, 3, 10},
+ couch_epi:register_service(chttpd_epi, Children)}}.
+
+get_children() ->
+ [
{
config_listener_mon,
{config_listener_mon, start_link, [?MODULE, settings()]},
@@ -41,12 +49,9 @@ init([]) ->
?CHILD(chttpd, worker),
?CHILD(chttpd_auth_cache, worker),
{chttpd_auth_cache_lru,
- {ets_lru, start_link, [chttpd_auth_cache_lru, lru_opts()]},
- permanent, 5000, worker, [ets_lru]}
- ],
-
- {ok, {{one_for_one, 3, 10},
- couch_epi:register_service(chttpd_epi, Children)}}.
+ {ets_lru, start_link, [chttpd_auth_cache_lru, lru_opts()]},
+ permanent, 5000, worker, [ets_lru]}
+ ].
handle_config_change("chttpd", "bind_address", Value, _, Settings) ->
maybe_replace(bind_address, Value, Settings);
diff --git a/src/couch_views/src/couch_views_server.erl b/src/couch_views/src/couch_views_server.erl
index d14216e..24c8355 100644
--- a/src/couch_views/src/couch_views_server.erl
+++ b/src/couch_views/src/couch_views_server.erl
@@ -39,13 +39,18 @@ start_link() ->
init(_) ->
- process_flag(trap_exit, true),
couch_views_jobs:set_timeout(),
- St = #{
- workers => #{},
- max_workers => max_workers()
- },
- {ok, spawn_workers(St)}.
+ case fabric2_node_types:is_type("view_indexing") of
+ true ->
+ process_flag(trap_exit, true),
+ St = #{
+ workers => #{},
+ max_workers => max_workers()
+ },
+ {ok, spawn_workers(St)};
+ false ->
+ ignore
+ end.
terminate(_, _St) ->
diff --git a/src/fabric/src/fabric2_node_types.erl b/src/fabric/src/fabric2_node_types.erl
new file mode 100644
index 0000000..7a8cb7e
--- /dev/null
+++ b/src/fabric/src/fabric2_node_types.erl
@@ -0,0 +1,55 @@
+% 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(fabric2_node_types).
+
+
+-export([
+ is_type/1
+]).
+
+
+is_type(Type) when is_list(Type) ->
+ case {from_env(Type), from_config(Type)} of
+ {V, _} when is_boolean(V) ->
+ V;
+ {undefined, V} when is_boolean(V) ->
+ V;
+ {undefined, undefined} ->
+ % When not defined anywhere assume `true`, that is by default a
+ % node will perform all the background tasks
+ true
+ end.
+
+
+from_env(Type) when is_list(Type) ->
+ VarStr = string:to_upper(Type),
+ case os:getenv("COUCHDB_NODE_TYPE_" ++ VarStr) of
+ false ->
+ undefined;
+ Str when is_list(Str) ->
+ case string:to_lower(Str) of
+ "false" -> false;
+ _ -> true
+ end
+ end.
+
+
+from_config(Type) when is_list(Type) ->
+ case config:get("node_type", Type) of
+ undefined ->
+ undefined;
+ "false" ->
+ false;
+ V when is_list(V) ->
+ true
+ end.