summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul J. Davis <paul.joseph.davis@gmail.com>2019-02-25 13:48:14 -0600
committerPaul J. Davis <paul.joseph.davis@gmail.com>2019-02-25 13:48:14 -0600
commit8df448381c9fde530068b060ba92a066fb30b725 (patch)
treefb388fce52699a71bce3482b88fed44fac239d8a
parent730d3605a1f3ca1eb63645fc1ed6ca12e781ab94 (diff)
downloadcouchdb-8df448381c9fde530068b060ba92a066fb30b725.tar.gz
First contact with FoundationDB
-rw-r--r--src/fabric/src/fabric.app.src8
-rw-r--r--src/fabric/src/fabric_app.erl28
-rw-r--r--src/fabric/src/fabric_server.erl65
-rw-r--r--src/fabric/src/fabric_sup.erl43
4 files changed, 142 insertions, 2 deletions
diff --git a/src/fabric/src/fabric.app.src b/src/fabric/src/fabric.app.src
index d7686ca1a..f59108290 100644
--- a/src/fabric/src/fabric.app.src
+++ b/src/fabric/src/fabric.app.src
@@ -13,7 +13,10 @@
{application, fabric, [
{description, "Routing and proxying layer for CouchDB cluster"},
{vsn, git},
- {registered, []},
+ {mod, {fabric_app, []}},
+ {registered, [
+ fabric_server
+ ]},
{applications, [
kernel,
stdlib,
@@ -22,6 +25,7 @@
rexi,
mem3,
couch_log,
- couch_stats
+ couch_stats,
+ erlfdb
]}
]}.
diff --git a/src/fabric/src/fabric_app.erl b/src/fabric/src/fabric_app.erl
new file mode 100644
index 000000000..77d9886a7
--- /dev/null
+++ b/src/fabric/src/fabric_app.erl
@@ -0,0 +1,28 @@
+% 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(fabric_app).
+-behaviour(application).
+
+
+-export([
+ start/2,
+ stop/1
+]).
+
+
+start(_Type, StartArgs) ->
+ fabric_sup:start_link(StartArgs).
+
+
+stop(_State) ->
+ ok.
diff --git a/src/fabric/src/fabric_server.erl b/src/fabric/src/fabric_server.erl
new file mode 100644
index 000000000..d1d7e9f1c
--- /dev/null
+++ b/src/fabric/src/fabric_server.erl
@@ -0,0 +1,65 @@
+% 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(fabric_server).
+-behaviour(gen_server).
+-vsn(1).
+
+
+-export([
+ start_link/0
+]).
+
+
+-export([
+ init/1,
+ terminate/2,
+ handle_call/3,
+ handle_cast/2,
+ handle_info/2,
+ code_change/3
+]).
+
+
+-record(st, {
+ db
+}).
+
+
+start_link() ->
+ gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
+
+
+init(_) ->
+ ClusterStr = config:get("erlfdb", "cluster_file", "/usr/local/etc/foundationdb/fdb.cluster"),
+ Db = erlfdb:open(iolist_to_binary(ClusterStr)),
+ {ok, #st{db = Db}}.
+
+
+terminate(_, _St) ->
+ ok.
+
+
+handle_call(Msg, _From, St) ->
+ {stop, {bad_call, Msg}, {bad_call, Msg}, St}.
+
+
+handle_cast(Msg, St) ->
+ {stop, {bad_cast, Msg}, St}.
+
+
+handle_info(Msg, St) ->
+ {stop, {bad_info, Msg}, St}.
+
+
+code_change(_OldVsn, St, _Extra) ->
+ {ok, St}.
diff --git a/src/fabric/src/fabric_sup.erl b/src/fabric/src/fabric_sup.erl
new file mode 100644
index 000000000..54636638c
--- /dev/null
+++ b/src/fabric/src/fabric_sup.erl
@@ -0,0 +1,43 @@
+% 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(fabric_sup).
+-behaviour(supervisor).
+-vsn(1).
+
+
+-export([
+ start_link/1
+]).
+
+-export([
+ init/1
+]).
+
+
+start_link(Args) ->
+ supervisor:start_link({local, ?MODULE}, ?MODULE, Args).
+
+
+init([]) ->
+ Flags = #{
+ strategy => one_for_one,
+ intensity => 1,
+ period => 5
+ },
+ Children = [
+ #{
+ id => fabric_server,
+ start => {fabric_server, start_link, []}
+ }
+ ],
+ {ok, {Flags, Children}}.