You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by va...@apache.org on 2020/06/04 18:05:47 UTC

[couchdb] branch prototype/fdb-layer updated: Include database uuid in db info result

This is an automated email from the ASF dual-hosted git repository.

vatamane pushed a commit to branch prototype/fdb-layer
in repository https://gitbox.apache.org/repos/asf/couchdb.git


The following commit(s) were added to refs/heads/prototype/fdb-layer by this push:
     new 19ae508  Include database uuid in db info result
19ae508 is described below

commit 19ae50815ca1016719f94a2757e08757b37fb949
Author: Nick Vatamaniuc <va...@apache.org>
AuthorDate: Thu Jun 4 12:19:10 2020 -0400

    Include database uuid in db info result
    
    As per ML
    [discussion](https://lists.apache.org/thread.html/rb328513fb932e231cf8793f92dd1cc2269044cb73cb43a6662c464a1%40%3Cdev.couchdb.apache.org%3E)
    add a `uuid` field to db info results in order to be able to uniquely identify
    a particular instance of a database. When a database is deleted and re-created
    with the same name, it will return a new `uuid` value.
---
 src/fabric/src/fabric2_fdb.erl            | 12 ++++++++++--
 src/fabric/test/fabric2_db_crud_tests.erl |  4 ++--
 src/fabric/test/fabric2_db_misc_tests.erl |  5 ++++-
 3 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/src/fabric/src/fabric2_fdb.erl b/src/fabric/src/fabric2_fdb.erl
index 7e736b0..f721ca4 100644
--- a/src/fabric/src/fabric2_fdb.erl
+++ b/src/fabric/src/fabric2_fdb.erl
@@ -107,6 +107,7 @@
     db_prefix,
     changes_future,
     meta_future,
+    uuid_future,
     retries = 0
 }).
 
@@ -494,6 +495,9 @@ get_info_future(Tx, DbPrefix) ->
         {reverse, true}
     ]),
 
+    UUIDKey = erlfdb_tuple:pack({?DB_CONFIG, <<"uuid">>}, DbPrefix),
+    UUIDFuture = erlfdb:get(Tx, UUIDKey),
+
     StatsPrefix = erlfdb_tuple:pack({?DB_STATS}, DbPrefix),
     MetaFuture = erlfdb:get_range_startswith(Tx, StatsPrefix),
 
@@ -508,7 +512,8 @@ get_info_future(Tx, DbPrefix) ->
         tx = SaveTx,
         db_prefix = DbPrefix,
         changes_future = ChangesFuture,
-        meta_future = MetaFuture
+        meta_future = MetaFuture,
+        uuid_future = UUIDFuture
     }.
 
 
@@ -1986,6 +1991,7 @@ get_info_wait_int(#info_future{} = InfoFuture) ->
     #info_future{
         db_prefix = DbPrefix,
         changes_future = ChangesFuture,
+        uuid_future = UUIDFuture,
         meta_future = MetaFuture
     } = InfoFuture,
 
@@ -1998,6 +2004,8 @@ get_info_wait_int(#info_future{} = InfoFuture) ->
     end,
     CProp = {update_seq, RawSeq},
 
+    UUIDProp = {uuid, erlfdb:wait(UUIDFuture)},
+
     MProps = lists:foldl(fun({K, V}, Acc) ->
         case erlfdb_tuple:unpack(K, DbPrefix) of
             {?DB_STATS, <<"doc_count">>} ->
@@ -2014,7 +2022,7 @@ get_info_wait_int(#info_future{} = InfoFuture) ->
         end
     end, [{sizes, {[]}}], erlfdb:wait(MetaFuture)),
 
-    [CProp | MProps].
+    [CProp, UUIDProp | MProps].
 
 
 binary_chunk_size() ->
diff --git a/src/fabric/test/fabric2_db_crud_tests.erl b/src/fabric/test/fabric2_db_crud_tests.erl
index b529935..000f370 100644
--- a/src/fabric/test/fabric2_db_crud_tests.erl
+++ b/src/fabric/test/fabric2_db_crud_tests.erl
@@ -631,7 +631,7 @@ get_info_wait_retry_on_tx_too_old(_) ->
         ok = erlfdb:set_option(Tx, disallow_writes),
 
         InfoF = fabric2_fdb:get_info_future(Tx, DbPrefix),
-        {info_future, _, _, ChangesF, _, _} = InfoF,
+        {info_future, _, _, ChangesF, _, _, _} = InfoF,
 
         raise_in_erlfdb_wait(ChangesF, {erlfdb_error, 1007}, 3),
         ?assertError({erlfdb_error, 1007}, fabric2_fdb:get_info_wait(InfoF)),
@@ -659,7 +659,7 @@ get_info_wait_retry_on_tx_abort(_)->
         ok = erlfdb:set_option(Tx, disallow_writes),
 
         InfoF = fabric2_fdb:get_info_future(Tx, DbPrefix),
-        {info_future, _, _, ChangesF, _, _} = InfoF,
+        {info_future, _, _, ChangesF, _, _, _} = InfoF,
 
         raise_in_erlfdb_wait(ChangesF, {erlfdb_error, 1025}, 3),
         ?assertError({erlfdb_error, 1025}, fabric2_fdb:get_info_wait(InfoF)),
diff --git a/src/fabric/test/fabric2_db_misc_tests.erl b/src/fabric/test/fabric2_db_misc_tests.erl
index 2fad73f..2353214 100644
--- a/src/fabric/test/fabric2_db_misc_tests.erl
+++ b/src/fabric/test/fabric2_db_misc_tests.erl
@@ -75,7 +75,10 @@ empty_db_info({DbName, Db, _}) ->
     ?assertEqual(DbName, fabric2_util:get_value(db_name, Info)),
     ?assertEqual(0, fabric2_util:get_value(doc_count, Info)),
     ?assertEqual(0, fabric2_util:get_value(doc_del_count, Info)),
-    ?assert(is_binary(fabric2_util:get_value(update_seq, Info))).
+    ?assert(is_binary(fabric2_util:get_value(update_seq, Info))),
+    InfoUUID = fabric2_util:get_value(uuid, Info),
+    UUID = fabric2_db:get_uuid(Db),
+    ?assertEqual(UUID, InfoUUID).
 
 
 accessors({DbName, Db, _}) ->