Skip to content
This repository was archived by the owner on May 25, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/setup.erl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ require_admins(undefined, {undefined, undefined}) ->
require_admins(_,_) ->
ok.

require_node_count(undefined) ->
throw({error, "Cluster setup requires node_count to be configured"});
require_node_count(_) ->
ok.

error_bind_address() ->
throw({error, "Cluster setup requires bind_addres != 127.0.0.1"}).

Expand Down Expand Up @@ -83,7 +88,8 @@ enable_cluster_http(Options) ->
{<<"username">>, couch_util:get_value(username, Options)},
{<<"password">>, couch_util:get_value(password, Options)},
{<<"bind_address">>, couch_util:get_value(bind_address, Options)},
{<<"port">>, couch_util:get_value(port, Options)}
{<<"port">>, couch_util:get_value(port, Options)},
{<<"node_count">>, couch_util:get_value(node_count, Options)}
]}),

Headers = [
Expand Down Expand Up @@ -134,6 +140,10 @@ enable_cluster_int(Options, no) ->
config:set("httpd", "bind_address", binary_to_list(NewBindAddress))
end,

NodeCount = couch_util:get_value(node_count, Options),
ok = require_node_count(NodeCount),
config:set_integer("cluster", "n", NodeCount),
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

N should not be set to the number of nodes in the cluster; those parameters are largely orthogonal.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@banjiewen can you explain to what we would have to set N instead?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the issue we are trying to fix: https://issues.apache.org/jira/browse/COUCHDB-2594

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bob's last comment on that ticket sounds right to me. I'd have N set to:

N = case NodeCount of
    1 -> 1;
    NC when NC >= 3 -> 3
end

Wherein bad cluster sizes (2, or < 1) are rejected (but I don't know what the project's stance on 2 node clusters is).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@banjiewen @rnewson what the reasons stands behind magic number 3? Why it shouldn't be bigger? If it really shouldn't, why we allow user to configure it?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sure larger values haven't been extensively tested, but IIUC they should work fine. N should be odd, of course.

The parameter exists to allow users/operators to manage the fault tolerance of their system, or a database within it. It should be configurable, and 3 is a very good default - it allows ~unimpeded operation of the system when one copy of the data is unavailable. If a user is willing to pay more latency, CPU, and disk space for additional fault tolerance, they can increase it.


Port = proplists:get_value(port, Options),
case Port of
undefined ->
Expand All @@ -142,7 +152,6 @@ enable_cluster_int(Options, no) ->
config:set("httpd", "port", integer_to_list(Port))
end,
couch_log:notice("Enable Cluster: ~p~n", [Options]).
%cluster_state:set(enabled).

maybe_set_admin(Username, Password) ->
case couch_auth_cache:get_admin(Username) of
Expand Down
3 changes: 2 additions & 1 deletion src/setup_httpd.erl
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ handle_action("enable_cluster", Setup) ->
{port, <<"port">>},
{remote_node, <<"remote_node">>},
{remote_current_user, <<"remote_current_user">>},
{remote_current_password, <<"remote_current_password">>}
{remote_current_password, <<"remote_current_password">>},
{node_count, <<"node_count">>}
], Setup),
case setup:enable_cluster(Options) of
{error, cluster_enabled} ->
Expand Down
7 changes: 5 additions & 2 deletions test/t-frontend-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ HEADERS="-HContent-Type:application/json"
curl a:b@127.0.0.1:15986/_nodes/_all_docs

# Enable Cluster on node A
curl a:b@127.0.0.1:15984/_cluster_setup -d '{"action":"enable_cluster","username":"foo","password":"baz","bind_address":"0.0.0.0"}' $HEADERS
curl a:b@127.0.0.1:15984/_cluster_setup -d '{"action":"enable_cluster","username":"foo","password":"baz","bind_address":"0.0.0.0","node_count":2}' $HEADERS

# Enable Cluster on node B
curl a:b@127.0.0.1:15984/_cluster_setup -d '{"action":"enable_cluster","remote_node":"127.0.0.1","port":"25984","remote_current_user":"a","remote_current_password":"b","username":"foo","password":"baz","bind_address":"0.0.0.0"}' $HEADERS
curl a:b@127.0.0.1:15984/_cluster_setup -d '{"action":"enable_cluster","remote_node":"127.0.0.1","port":"25984","remote_current_user":"a","remote_current_password":"b","username":"foo","password":"baz","bind_address":"0.0.0.0","node_count":2}' $HEADERS

# Add node B on node A
curl a:b@127.0.0.1:15984/_cluster_setup -d '{"action":"add_node","username":"foo","password":"baz","host":"127.0.0.1","port":25984}' $HEADERS
Expand Down Expand Up @@ -57,4 +57,7 @@ curl a:b@127.0.0.1:25984/_replicator
curl a:b@127.0.0.1:25984/_metadata
curl a:b@127.0.0.1:25984/_global_changes

# Number of nodes is set to 2
curl a:b@127.0.0.1:25984/_node/node2@127.0.0.1/_config/cluster/n

echo "YAY ALL GOOD"
7 changes: 5 additions & 2 deletions test/t.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ HEADERS="-HContent-Type:application/json"
curl a:b@127.0.0.1:15986/_nodes/_all_docs

# Enable Cluster on node A
curl a:b@127.0.0.1:15984/_cluster_setup -d '{"action":"enable_cluster","username":"foo","password":"baz","bind_address":"0.0.0.0"}' $HEADERS
curl a:b@127.0.0.1:15984/_cluster_setup -d '{"action":"enable_cluster","username":"foo","password":"baz","bind_address":"0.0.0.0","node_count":2}' $HEADERS

# Enable Cluster on node B
curl a:b@127.0.0.1:25984/_cluster_setup -d '{"action":"enable_cluster","username":"foo","password":"baz","bind_address":"0.0.0.0"}' $HEADERS
curl a:b@127.0.0.1:25984/_cluster_setup -d '{"action":"enable_cluster","username":"foo","password":"baz","bind_address":"0.0.0.0","node_count":2}' $HEADERS

# Add node B on node A
curl a:b@127.0.0.1:15984/_cluster_setup -d '{"action":"add_node","username":"foo","password":"baz","host":"127.0.0.1","port":25984}' $HEADERS
Expand Down Expand Up @@ -57,4 +57,7 @@ curl a:b@127.0.0.1:25984/_replicator
curl a:b@127.0.0.1:25984/_metadata
curl a:b@127.0.0.1:25984/_global_changes

# Number of nodes is set to 2
curl a:b@127.0.0.1:25984/_node/node2@127.0.0.1/_config/cluster/n

echo "YAY ALL GOOD"