summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrad Anderson <brad@cloudant.com>2010-04-14 23:08:12 -0400
committerBrad Anderson <brad@cloudant.com>2010-05-09 22:56:24 -0400
commitf5bcba1df93803f02e6ecd20b84c5dbbe2f1b4d8 (patch)
tree1f8850753d5fcb436d0940b00be19e8ba268230e
parent97c4e9946cfdeeaf33334f4697c6ac60ac9f55e3 (diff)
removed pinging of nodes based on _cluster endpoint
-rw-r--r--ebin/dynomite.app1
-rw-r--r--src/dynomite.erl1
-rw-r--r--src/dynomite_app.erl68
-rw-r--r--src/dynomite_http.erl21
4 files changed, 2 insertions, 89 deletions
diff --git a/ebin/dynomite.app b/ebin/dynomite.app
index e6e71af2..02a9618d 100644
--- a/ebin/dynomite.app
+++ b/ebin/dynomite.app
@@ -14,7 +14,6 @@
dynomite_app,
dynomite_couch_api,
dynomite_couch_storage,
- dynomite_http,
dynomite_prof,
dynomite_sup,
lib_misc,
diff --git a/src/dynomite.erl b/src/dynomite.erl
index 1b9798c0..bb50986b 100644
--- a/src/dynomite.erl
+++ b/src/dynomite.erl
@@ -1,4 +1,3 @@
-%%% @author Brad Anderson <brad@cloudant.com>
%%% @doc convenience start/stop functions for Dynomite
%%%
-module(dynomite).
diff --git a/src/dynomite_app.erl b/src/dynomite_app.erl
index 417f4c76..949e29ae 100644
--- a/src/dynomite_app.erl
+++ b/src/dynomite_app.erl
@@ -1,13 +1,3 @@
-%%%-------------------------------------------------------------------
-%%% File: dynomite.erl
-%%% @author Cliff Moon <cliff@powerset.com> []
-%%% @copyright 2008 Cliff Moon
-%%% @doc
-%%%
-%%% @end
-%%%
-%%% @since 2008-06-27 by Cliff Moon
-%%%-------------------------------------------------------------------
-module(dynomite_app).
-author('cliff@powerset.com').
-author('brad@cloudant.com').
@@ -20,8 +10,6 @@
%% Application callbacks
-export([start/2, stop/1]).
--define(DEFAULT_CLUSTER_URL, "http://localhost:5984/_cluster").
-
%%====================================================================
%% Application callbacks
%%====================================================================
@@ -40,14 +28,9 @@
%% @doc start required apps, join cluster, start dynomite supervisor
start(_Type, _StartArgs) ->
+ couch_api:create_db(<<"users">>, []), % all nodes have local 'users' db
% start dynomite supervisor
- ok = start_node(),
- case dynomite_sup:start_link() of
- {ok, Supervisor} ->
- {ok, Supervisor};
- Error ->
- Error
- end.
+ dynomite_sup:start_link().
%%--------------------------------------------------------------------
@@ -66,50 +49,3 @@ stop({_, Sup}) ->
%%====================================================================
%% Internal functions
%%====================================================================
-
-%% @spec start_node() -> ok | {error, Reason}
-%% @doc start this node (join to dist. erlang cluster)
-start_node() ->
- PingUrl = couch_config:get("cluster","ping", ?DEFAULT_CLUSTER_URL),
- ?LOG_DEBUG("PingUrl: ~p", [PingUrl]),
- Result = case get_pingnode(PingUrl, 1) of
- {ok, PingNode} ->
- join(PingNode);
- _ ->
- ?LOG_INFO("No pingnode found. Becoming single-node cluster", [])
- end,
- couch_api:create_db(<<"users">>, []), % all nodes have local 'users' db
- Result.
-
-
-%% @spec get_pingnode(Url::string(), Retries::int()) -> node() |
-%% {error, Reason}
-%% @doc make a http get call to Url to get cluster information
-get_pingnode(Url, Retries) ->
- try couch_rep_httpc:request(#http_db{url=Url, retries=Retries}) of
- {[{<<"ping_node">>, Node}]} ->
- {ok, list_to_atom(binary_to_list(Node))};
- _ ->
- {error, pingnode_not_found}
- catch
- _:_ ->
- {error, pingnode_not_found}
- end.
-
-
-join(PingNode) ->
- if
- node() =:= PingNode ->
- ok; % we must be brain, so we'll take over the world
- true ->
- case net_adm:ping(PingNode) of
- pong ->
- % there is a cluster, we just joined it
- ?LOG_DEBUG("ping successful, we're in.", []),
- timer:sleep(1000); %% grr, what a hack, erlang. rly?
- pang ->
- ?LOG_ERROR("ping not successful.", []),
- throw({cluster_error, ?l2b("cluster ping not successful")})
- end
- end,
- ok.
diff --git a/src/dynomite_http.erl b/src/dynomite_http.erl
deleted file mode 100644
index 8b6f7fbb..00000000
--- a/src/dynomite_http.erl
+++ /dev/null
@@ -1,21 +0,0 @@
-%%%-------------------------------------------------------------------
-%%% File : dynomite_http.erl
-%%% Author : Brad Anderson <brad@cloudant.com>
-%%% Description :
-%%%
-%%% Created : 10 Jan 2010 by Brad Anderson <brad@cloudant.com>
-%%%-------------------------------------------------------------------
--module(dynomite_http).
--author('Brad Anderson <brad@cloudant.com>').
-
--include("../couch/src/couch_db.hrl").
--include_lib("eunit/include/eunit.hrl").
-
--export([handle_cluster_info/1]).
-
-
-%% GET /_cluster
-handle_cluster_info(#httpd{method='GET', path_parts=[_]}=Req) ->
- ClusterInfo = [{<<"ping_node">>, ?l2b(atom_to_list(node()))}],
- showroom_log:message(info, "Cluster Info: ~p", [ClusterInfo]),
- couch_httpd:send_json(Req, {ClusterInfo}).