summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Vatamaniuc <vatamane@apache.org>2019-10-14 16:30:22 -0400
committerNick Vatamaniuc <nickva@users.noreply.github.com>2019-10-14 17:22:06 -0400
commit76bdf1b5c34b6a3c9568e828fb1910fc26dde764 (patch)
tree32b085f405a9d7125bb34473ca785e0a77793429
parent577dd7f188ce74ef793920d5886ad26bb8288e0e (diff)
downloadcouchdb-76bdf1b5c34b6a3c9568e828fb1910fc26dde764.tar.gz
DRY out CouchDB FDB prefix fetching
It was suggested in another PR's discussion: https://github.com/apache/couchdb/pull/2107#pullrequestreview-274431487
-rw-r--r--src/couch_jobs/src/couch_jobs_fdb.erl5
-rw-r--r--src/fabric/src/fabric2_fdb.erl15
-rw-r--r--src/fabric/src/fabric2_txids.erl10
3 files changed, 12 insertions, 18 deletions
diff --git a/src/couch_jobs/src/couch_jobs_fdb.erl b/src/couch_jobs/src/couch_jobs_fdb.erl
index 6903801a2..00a8ddf72 100644
--- a/src/couch_jobs/src/couch_jobs_fdb.erl
+++ b/src/couch_jobs/src/couch_jobs_fdb.erl
@@ -615,10 +615,7 @@ init_jtx(undefined) ->
fabric2_fdb:transactional(fun(Tx) -> init_jtx(Tx) end);
init_jtx({erlfdb_transaction, _} = Tx) ->
- Root = erlfdb_directory:root(),
- Dir = fabric2_server:fdb_directory(),
- CouchDB = erlfdb_directory:create_or_open(Tx, Root, Dir),
- LayerPrefix = erlfdb_directory:get_name(CouchDB),
+ LayerPrefix = fabric2_fdb:create_or_open_couchdb_dir(Tx),
Jobs = erlfdb_tuple:pack({?JOBS}, LayerPrefix),
Version = erlfdb:wait(erlfdb:get(Tx, ?METADATA_VERSION_KEY)),
% layer_prefix, md_version and tx here match db map fields in fabric2_fdb
diff --git a/src/fabric/src/fabric2_fdb.erl b/src/fabric/src/fabric2_fdb.erl
index 5c58da482..5471f99f2 100644
--- a/src/fabric/src/fabric2_fdb.erl
+++ b/src/fabric/src/fabric2_fdb.erl
@@ -24,6 +24,8 @@
delete/1,
exists/1,
+ create_or_open_couchdb_dir/1,
+
list_dbs/4,
get_info/1,
@@ -274,11 +276,15 @@ exists(#{name := DbName} = Db) when is_binary(DbName) ->
end.
-list_dbs(Tx, Callback, AccIn, Options) ->
+create_or_open_couchdb_dir(Tx) ->
Root = erlfdb_directory:root(),
Dir = fabric2_server:fdb_directory(),
CouchDB = erlfdb_directory:create_or_open(Tx, Root, Dir),
- LayerPrefix = erlfdb_directory:get_name(CouchDB),
+ erlfdb_directory:get_name(CouchDB).
+
+
+list_dbs(Tx, Callback, AccIn, Options) ->
+ LayerPrefix = create_or_open_couchdb_dir(Tx),
Prefix = erlfdb_tuple:pack({?ALL_DBS}, LayerPrefix),
fold_range({tx, Tx}, Prefix, fun({K, _V}, Acc) ->
{DbName} = erlfdb_tuple:unpack(K, Prefix),
@@ -781,10 +787,7 @@ debug_cluster(Start, End) ->
init_db(Tx, DbName, Options) ->
- Root = erlfdb_directory:root(),
- Dir = fabric2_server:fdb_directory(),
- CouchDB = erlfdb_directory:create_or_open(Tx, Root, Dir),
- Prefix = erlfdb_directory:get_name(CouchDB),
+ Prefix = create_or_open_couchdb_dir(Tx),
Version = erlfdb:wait(erlfdb:get(Tx, ?METADATA_VERSION_KEY)),
#{
name => DbName,
diff --git a/src/fabric/src/fabric2_txids.erl b/src/fabric/src/fabric2_txids.erl
index 06704f021..f1a75243c 100644
--- a/src/fabric/src/fabric2_txids.erl
+++ b/src/fabric/src/fabric2_txids.erl
@@ -44,10 +44,7 @@ start_link() ->
create(Tx, undefined) ->
- Root = erlfdb_directory:root(),
- Dir = fabric2_server:fdb_directory(),
- CouchDB = erlfdb_directory:create_or_open(Tx, Root, Dir),
- Prefix = erlfdb_directory:get_name(CouchDB),
+ Prefix = fabric2_fdb:create_or_open_couchdb_dir(Tx),
create(Tx, Prefix);
create(_Tx, LayerPrefix) ->
@@ -136,10 +133,7 @@ clean(St, NeedsSweep) ->
sweep(Tx, {Mega, Secs, Micro}) ->
- Root = erlfdb_directory:root(),
- Dir = fabric2_server:fdb_directory(),
- CouchDB = erlfdb_directory:create_or_open(Tx, Root, Dir),
- Prefix = erlfdb_directory:get_name(CouchDB),
+ Prefix = fabric2_fdb:create_or_open_couchdb_dir(Tx),
StartKey = erlfdb_tuple:pack({?TX_IDS}, Prefix),
EndKey = erlfdb_tuple:pack({?TX_IDS, Mega, Secs, Micro}, Prefix),
erlfdb:set_option(Tx, next_write_no_write_conflict_range),