diff options
author | Paul J. Davis <paul.joseph.davis@gmail.com> | 2019-02-25 14:43:29 -0600 |
---|---|---|
committer | Paul J. Davis <paul.joseph.davis@gmail.com> | 2019-02-25 14:43:29 -0600 |
commit | 392374fc558339821a0911ae52961e5b9c66e4de (patch) | |
tree | 974d3dad99689496abe83ab3540514bc890a9652 | |
parent | 8df448381c9fde530068b060ba92a066fb30b725 (diff) | |
download | couchdb-392374fc558339821a0911ae52961e5b9c66e4de.tar.gz |
Initial CouchDB directories on node boot
-rw-r--r-- | src/fabric/src/fabric_server.erl | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/fabric/src/fabric_server.erl b/src/fabric/src/fabric_server.erl index d1d7e9f1c..6deabe5f8 100644 --- a/src/fabric/src/fabric_server.erl +++ b/src/fabric/src/fabric_server.erl @@ -40,8 +40,21 @@ start_link() -> init(_) -> + ets:new(?MODULE, [ + protected, + named_table, + {read_concurrency, true} + ]), + ClusterStr = config:get("erlfdb", "cluster_file", "/usr/local/etc/foundationdb/fdb.cluster"), Db = erlfdb:open(iolist_to_binary(ClusterStr)), + Dirs = init_cluster(Db), + + ets:insert(?MODULE, {'$handle$', Db}), + lists:foreach(fun({K, V}) -> + ets:insert(?MODULE, {K, V}) + end, Dirs), + {ok, #st{db = Db}}. @@ -63,3 +76,21 @@ handle_info(Msg, St) -> code_change(_OldVsn, St, _Extra) -> {ok, St}. + + + +init_cluster(Db) -> + erlfdb:transactional(Db, fun(Tx) -> + Root = erlfdb_directory:root(), + CouchDB = erlfdb_directory:create_or_open(Tx, Root, [<<"couchdb">>]), + Meta = erlfdb_directory:create_or_open(Tx, CouchDB, [<<"meta">>]), + Config = erlfdb_directory:create_or_open(Tx, Meta, [<<"config">>]), + Dbs = erlfdb_directory:create_or_open(Tx, CouchDB, [<<"dbs">>]), + [ + {root, Root}, + {couchdb, CouchDB}, + {meta, Meta}, + {config, Config}, + {dbs, Dbs} + ] + end).
\ No newline at end of file |