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/04/23 15:52:10 UTC

[couchdb-erlfdb] branch add-more-database-options created (now c8a61e3)

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

vatamane pushed a change to branch add-more-database-options
in repository https://gitbox.apache.org/repos/asf/couchdb-erlfdb.git.


      at c8a61e3  Avoid the system key range in the eunit test random key generator.

This branch includes the following new commits:

     new 792a664  Allow setting some default transaction options on the db handle
     new c8a61e3  Avoid the system key range in the eunit test random key generator.

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[couchdb-erlfdb] 02/02: Avoid the system key range in the eunit test random key generator.

Posted by va...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

vatamane pushed a commit to branch add-more-database-options
in repository https://gitbox.apache.org/repos/asf/couchdb-erlfdb.git

commit c8a61e3016d6dff92e9cc1c1e6fb48e18e1063c0
Author: Nick Vatamaniuc <va...@apache.org>
AuthorDate: Thu Apr 23 00:57:05 2020 -0400

    Avoid the system key range in the eunit test random key generator.
    
    Previously the generator could sometimes return values in the system
    range and tests would fail with the unexpected 2004 error.
---
 test/erlfdb_03_transaction_options_test.erl | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/test/erlfdb_03_transaction_options_test.erl b/test/erlfdb_03_transaction_options_test.erl
index 58447af..106695c 100644
--- a/test/erlfdb_03_transaction_options_test.erl
+++ b/test/erlfdb_03_transaction_options_test.erl
@@ -90,5 +90,6 @@ size_limit_on_db_handle_test() ->
     end)).
 
 
-gen(Size) ->
-    crypto:strong_rand_bytes(Size).
+gen(Size) when is_integer(Size), Size > 1 ->
+    RandBin = crypto:strong_rand_bytes(Size - 1),
+    <<0, RandBin/binary>>.


[couchdb-erlfdb] 01/02: Allow setting some default transaction options on the db handle

Posted by va...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

vatamane pushed a commit to branch add-more-database-options
in repository https://gitbox.apache.org/repos/asf/couchdb-erlfdb.git

commit 792a664ec4870e8a253c6760326a8eb0570d31d4
Author: Nick Vatamaniuc <va...@apache.org>
AuthorDate: Thu Apr 23 00:48:48 2020 -0400

    Allow setting some default transaction options on the db handle
    
    Since FDB version 6.1 [1] it is possible to set default transaction
    options on database handles, and any transactions created from that
    handle will inherit those options.
    
    [1] https://apple.github.io/foundationdb/old-release-notes/release-notes-610.html
---
 c_src/main.c                                |  8 ++++++++
 src/erlfdb_nif.erl                          | 16 +++++++++++-----
 test/erlfdb_03_transaction_options_test.erl |  8 ++++++++
 3 files changed, 27 insertions(+), 5 deletions(-)

diff --git a/c_src/main.c b/c_src/main.c
index 674b92b..17e15cf 100644
--- a/c_src/main.c
+++ b/c_src/main.c
@@ -752,6 +752,14 @@ erlfdb_database_set_option(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
         option = FDB_DB_OPTION_MACHINE_ID;
     } else if(IS_ATOM(argv[1], datacenter_id)) {
         option = FDB_DB_OPTION_DATACENTER_ID;
+    } else if(IS_ATOM(argv[1], timeout)) {
+        option = FDB_DB_OPTION_TRANSACTION_TIMEOUT;
+    } else if(IS_ATOM(argv[1], retry_limit)) {
+        option = FDB_DB_OPTION_TRANSACTION_RETRY_LIMIT;
+    } else if(IS_ATOM(argv[1], max_retry_delay)) {
+        option = FDB_DB_OPTION_TRANSACTION_MAX_RETRY_DELAY;
+    } else if(IS_ATOM(argv[1], size_limit)) {
+        option = FDB_DB_OPTION_TRANSACTION_SIZE_LIMIT;
     } else {
         return enif_make_badarg(env);
     }
diff --git a/src/erlfdb_nif.erl b/src/erlfdb_nif.erl
index 2c0a944..7ec8e52 100644
--- a/src/erlfdb_nif.erl
+++ b/src/erlfdb_nif.erl
@@ -238,7 +238,8 @@ database_set_option(Database, Option) ->
         Value::option_value()
     ) -> ok.
 database_set_option({erlfdb_database, Db}, Opt, Val) ->
-    erlfdb_database_set_option(Db, Opt, Val).
+    BinVal = option_val_to_binary(Val),
+    erlfdb_database_set_option(Db, Opt, BinVal).
 
 
 -spec database_create_transaction(database()) ->
@@ -258,10 +259,7 @@ transaction_set_option(Transaction, Option) ->
         Value::option_value()
     ) -> ok.
 transaction_set_option({erlfdb_transaction, Tx}, Opt, Val) ->
-    BinVal = case Val of
-        B when is_binary(B) -> B;
-        I when is_integer(I) -> <<I:8/little-unsigned-integer-unit:8>>
-    end,
+    BinVal = option_val_to_binary(Val),
     erlfdb_transaction_set_option(Tx, Opt, BinVal).
 
 
@@ -452,6 +450,14 @@ error_predicate(Predicate, Error) ->
     erlfdb_error_predicate(Predicate, Error).
 
 
+-spec option_val_to_binary(binary() | integer()) -> binary().
+option_val_to_binary(Val) when is_binary(Val) ->
+    Val;
+
+option_val_to_binary(Val) when is_integer(Val) ->
+    <<Val:8/little-unsigned-integer-unit:8>>.
+
+
 init() ->
     PrivDir = case code:priv_dir(?MODULE) of
         {error, _} ->
diff --git a/test/erlfdb_03_transaction_options_test.erl b/test/erlfdb_03_transaction_options_test.erl
index 83c7fe7..58447af 100644
--- a/test/erlfdb_03_transaction_options_test.erl
+++ b/test/erlfdb_03_transaction_options_test.erl
@@ -82,5 +82,13 @@ cannot_set_watches_if_writes_disallowed_test() ->
     end)).
 
 
+size_limit_on_db_handle_test() ->
+    Db1 = erlfdb_util:get_test_db(),
+    erlfdb:set_option(Db1, size_limit, 10000),
+    ?assertError({erlfdb_error, 2101}, erlfdb:transactional(Db1, fun(Tx) ->
+         erlfdb:set(Tx, gen(10), gen(11000))
+    end)).
+
+
 gen(Size) ->
     crypto:strong_rand_bytes(Size).