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 16:53:05 UTC
[couchdb-erlfdb] branch master updated (d5acd7e -> d4663cf)
This is an automated email from the ASF dual-hosted git repository.
vatamane pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/couchdb-erlfdb.git.
from d5acd7e Add .asf.yaml file for commits and notifications
new 1de3e2e Allow setting some default transaction options on the db handle
new d4663cf 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.
Summary of changes:
c_src/atom_names.h | 6 ++++++
c_src/main.c | 29 ++++++++++++++++++++++++++++-
src/erlfdb_nif.erl | 16 +++++++++++-----
test/erlfdb_03_transaction_options_test.erl | 13 +++++++++++--
4 files changed, 56 insertions(+), 8 deletions(-)
[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 master
in repository https://gitbox.apache.org/repos/asf/couchdb-erlfdb.git
commit 1de3e2e8e876f60c466207817e20cecf52af5aaf
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/atom_names.h | 6 ++++++
c_src/main.c | 29 ++++++++++++++++++++++++++++-
src/erlfdb_nif.erl | 16 +++++++++++-----
test/erlfdb_03_transaction_options_test.erl | 8 ++++++++
4 files changed, 53 insertions(+), 6 deletions(-)
diff --git a/c_src/atom_names.h b/c_src/atom_names.h
index bd4471b..0a6b1ad 100644
--- a/c_src/atom_names.h
+++ b/c_src/atom_names.h
@@ -78,6 +78,7 @@ ATOM_MAP(causal_write_risky);
ATOM_MAP(causal_read_risky);
ATOM_MAP(causal_read_disable);
ATOM_MAP(next_write_no_write_conflict_range);
+ATOM_MAP(read_your_writes_enable);
ATOM_MAP(read_your_writes_disable);
ATOM_MAP(read_ahead_disable);
ATOM_MAP(durability_datacenter);
@@ -90,6 +91,9 @@ ATOM_MAP(access_system_keys);
ATOM_MAP(read_system_keys);
ATOM_MAP(debug_retry_logging);
ATOM_MAP(transaction_logging_enable);
+ATOM_MAP(debug_transaction_identifier);
+ATOM_MAP(transaction_logging_max_field_length);
+ATOM_MAP(log_transaction);
ATOM_MAP(timeout);
ATOM_MAP(retry_limit);
ATOM_MAP(max_retry_delay);
@@ -101,6 +105,8 @@ ATOM_MAP(read_lock_aware);
ATOM_MAP(size_limit);
ATOM_MAP(allow_writes);
ATOM_MAP(disallow_writes);
+ATOM_MAP(include_port_in_address);
+ATOM_MAP(use_provisional_proxies);
// Streaming mode
diff --git a/c_src/main.c b/c_src/main.c
index 674b92b..b693f06 100644
--- a/c_src/main.c
+++ b/c_src/main.c
@@ -752,7 +752,24 @@ 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 {
+ } else if(IS_ATOM(argv[1], read_your_writes_enable)) {
+ option = FDB_DB_OPTION_SNAPSHOT_RYW_ENABLE;
+ } else if(IS_ATOM(argv[1], read_your_writes_disable)) {
+ option = FDB_DB_OPTION_SNAPSHOT_RYW_DISABLE;
+ } else if(IS_ATOM(argv[1], transaction_logging_max_field_length)) {
+ option = FDB_DB_OPTION_TRANSACTION_LOGGING_MAX_FIELD_LENGTH;
+ } 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 if(IS_ATOM(argv[1], causal_read_risky)) {
+ option = FDB_DB_OPTION_TRANSACTION_CAUSAL_READ_RISKY;
+ } else if(IS_ATOM(argv[1], include_port_in_address)) {
+ option = FDB_DB_OPTION_TRANSACTION_INCLUDE_PORT_IN_ADDRESS;
return enif_make_badarg(env);
}
@@ -875,6 +892,8 @@ erlfdb_transaction_set_option(
option = FDB_TR_OPTION_CAUSAL_READ_RISKY;
} else if(IS_ATOM(argv[1], causal_read_disable)) {
option = FDB_TR_OPTION_CAUSAL_READ_DISABLE;
+ } else if(IS_ATOM(argv[1], include_port_in_address)) {
+ option = FDB_TR_OPTION_INCLUDE_PORT_IN_ADDRESS;
} else if(IS_ATOM(argv[1], next_write_no_write_conflict_range)) {
option = FDB_TR_OPTION_NEXT_WRITE_NO_WRITE_CONFLICT_RANGE;
} else if(IS_ATOM(argv[1], read_your_writes_disable)) {
@@ -901,6 +920,12 @@ erlfdb_transaction_set_option(
option = FDB_TR_OPTION_DEBUG_RETRY_LOGGING;
} else if(IS_ATOM(argv[1], transaction_logging_enable)) {
option = FDB_TR_OPTION_TRANSACTION_LOGGING_ENABLE;
+ } else if(IS_ATOM(argv[1], debug_transaction_identifier)) {
+ option = FDB_TR_OPTION_DEBUG_TRANSACTION_IDENTIFIER;
+ } else if(IS_ATOM(argv[1], log_transaction)) {
+ option = FDB_TR_OPTION_LOG_TRANSACTION;
+ } else if(IS_ATOM(argv[1], transaction_logging_max_field_length)) {
+ option = FDB_TR_OPTION_TRANSACTION_LOGGING_MAX_FIELD_LENGTH;
} else if(IS_ATOM(argv[1], timeout)) {
option = FDB_TR_OPTION_TIMEOUT;
} else if(IS_ATOM(argv[1], retry_limit)) {
@@ -919,6 +944,8 @@ erlfdb_transaction_set_option(
option = FDB_TR_OPTION_READ_LOCK_AWARE;
} else if(IS_ATOM(argv[1], size_limit)) {
option = FDB_TR_OPTION_SIZE_LIMIT;
+ } else if(IS_ATOM(argv[1], use_provisional_proxies)) {
+ option = FDB_TR_OPTION_USE_PROVISIONAL_PROXIES;
} 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).
[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 master
in repository https://gitbox.apache.org/repos/asf/couchdb-erlfdb.git
commit d4663cf269cdf30fdedb85d381815af1cd28a011
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>>.