Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to version 7.3 #15

Merged
merged 6 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .devcontainer/add_erlang_bindings.patch
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
diff --git a/bindings/bindingtester/__init__.py b/bindings/bindingtester/__init__.py
index 17d06cf..1f6e1e3 100644
index bfe569e27..9694766d1 100644
--- a/bindings/bindingtester/__init__.py
+++ b/bindings/bindingtester/__init__.py
@@ -22,7 +22,7 @@ import math
import sys
import os

-sys.path[:0] = [os.path.join(os.path.dirname(__file__), '..', '..', 'bindings', 'python')]
+#sys.path[:0] = [os.path.join(os.path.dirname(__file__), '..', '..', 'bindings', 'python')]
+# sys.path[:0] = [os.path.join(os.path.dirname(__file__), '..', '..', 'bindings', 'python')]

import util

from fdb import LATEST_API_VERSION
diff --git a/bindings/bindingtester/known_testers.py b/bindings/bindingtester/known_testers.py
index 70e1f81..85dcde5 100644
index 30a0b72fa..ae77c9507 100644
--- a/bindings/bindingtester/known_testers.py
+++ b/bindings/bindingtester/known_testers.py
@@ -58,6 +58,7 @@ _java_cmd = 'java -ea -cp %s:%s com.apple.foundationdb.test.' % (
@@ -60,6 +60,7 @@ _java_cmd = 'java -ea -cp %s:%s com.apple.foundationdb.test.' % (

# We could set min_api_version lower on some of these if the testers were updated to support them
testers = {
+ 'erlang': Tester('erlang', '/usr/src/erlfdb/test/tester.es', 2040, 710, MAX_API_VERSION, types=ALL_TYPES, tenants_enabled=True),
+ 'erlang': Tester('erlang', '/usr/src/erlfdb/test/tester.es', 2040, 730, MAX_API_VERSION, types=ALL_TYPES, tenants_enabled=True),
'python': Tester('python', 'python ' + _absolute_path('python/tests/tester.py'), 2040, 23, MAX_API_VERSION, types=ALL_TYPES, tenants_enabled=True),
'python3': Tester('python3', 'python3 ' + _absolute_path('python/tests/tester.py'), 2040, 23, MAX_API_VERSION, types=ALL_TYPES, tenants_enabled=True),
'ruby': Tester('ruby', _absolute_path('ruby/tests/tester.rb'), 2040, 23, MAX_API_VERSION),
6 changes: 3 additions & 3 deletions .devcontainer/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ services:
context: .
dockerfile: Dockerfile
args:
ERLANG_VERSION: "24"
ERLANG_VERSION: "25"

# This should always match the value in fdb.image
FDB_VERSION: "7.1.43"
FDB_VERSION: "7.3.35"

environment:
# This needs to match the name of the FoundationDB service below
Expand All @@ -28,4 +28,4 @@ services:
network_mode: service:fdb

fdb:
image: foundationdb/foundationdb:7.1.43
image: foundationdb/foundationdb:7.3.35
10 changes: 5 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
strategy:
matrix:
otp-version: ['24', '25']
fdb-version: ['7.1.43']
fdb-version: ['7.3.35']
runs-on: ubuntu-22.04
env:
FDB_VERSION: ${{ matrix.fdb-version }}
Expand Down Expand Up @@ -47,12 +47,12 @@ jobs:
strategy:
matrix:
test-name: [api, directory, directory_hca, tuple]
api-version: [710]
api-version: [730]
container:
image: ghcr.io/emqx/couchdb-erlfdb:erlang-25-fdb-7.1.43
image: ghcr.io/emqx/couchdb-erlfdb:erlang-25-fdb-7.3.35
services:
foundationdb:
image: foundationdb/foundationdb:7.1.43
image: foundationdb/foundationdb:7.3.35
env:
REBAR_PROFILE: devcontainer
# Set to 1 for verbose rebar3 logging
Expand All @@ -74,7 +74,7 @@ jobs:
shell: bash
run: bash /usr/local/bin/create_cluster_file.bash
- name: Initialize FDB database
run: fdbcli --exec "configure new single ssd"
run: fdbcli --exec "configure new single ssd tenant_mode=optional_experimental"
- name: Execute unit tests
run: rebar3 eunit
- name: Execute binding test
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
strategy:
matrix:
otp-version: ['24', '25']
fdb-version: ['7.1.43']
fdb-version: ['7.3.35']

steps:
- uses: actions/checkout@v4
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
An Erlang Binding to FoundationDB
===

[![CI](https://github.com/apache/couchdb-erlfdb/actions/workflows/ci.yml/badge.svg)](https://github.com/apache/couchdb-erlfdb/actions/workflows/ci.yml)[![Coverage](https://coveralls.io/repos/github/apache/couchdb-erlfdb/badge.svg?branch=main)](https://coveralls.io/github/apache/couchdb-erlfdb?branch=main)
[![CI](https://github.com/emqx/couchdb-erlfdb/actions/workflows/ci.yml/badge.svg)](https://github.com/emqx/couchdb-erlfdb/actions/workflows/ci.yml)
<!-- [![Coverage](https://coveralls.io/repos/github/apache/couchdb-erlfdb/badge.svg?branch=main)](https://coveralls.io/github/apache/couchdb-erlfdb?branch=main) -->

This project is a NIF wrapper for the FoundationDB C API. Documentation on
the main API can be found [here][fdb_docs].
Expand Down
2 changes: 1 addition & 1 deletion scripts/fetch_fdb_cli.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ if [ "$#" -ne 3 ]; then
usage
fi

FDB_VERSION="7.1.43"
FDB_VERSION="7.3.35"
TYPE="${1}"
OUTPUT="${2}"

Expand Down
2 changes: 1 addition & 1 deletion src/erlfdb.app.src
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
{maintainers, ["Paul J. Davis"]},
{links, [{"GitHub", "https://github.com/emqx/couchdb-erlfdb"}]},
{env, [
{api_version, 710},
{api_version, 730},
{network_options, []}
]}
]}.
2 changes: 1 addition & 1 deletion src/erlfdb_nif.erl
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
error_predicate/2
]).

-define(DEFAULT_API_VERSION, 710).
-define(DEFAULT_API_VERSION, 730).

-type error() :: {erlfdb_error, Code :: integer()}.
-type future() :: {erlfdb_future, reference(), reference()}.
Expand Down
54 changes: 53 additions & 1 deletion src/erlfdb_tenant.erl
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@

-module(erlfdb_tenant).

-export([create_tenant/2, open_tenant/2, delete_tenant/2]).
-export([create_tenant/2, open_tenant/2, delete_tenant/2, list_tenants/4]).

-define(IS_DB, {erlfdb_database, _}).
-define(TENANT_MAP_PREFIX, <<16#FF, 16#FF, "/management/tenant_map/">>).
-define(MAX_LIMIT, 2147483647).

-import(erlfdb, [get/2, clear/2, set/3, wait/1, transactional/2, set_option/2]).

Expand Down Expand Up @@ -50,8 +51,59 @@ delete_tenant(Tx, Tenant) ->
clear(Tx, Key)
end.

list_tenants(Db, From, To, Limit) ->
case is_selector(From) andalso is_selector(To) of
true ->
do_list_tenants(Db, From, To, Limit);
false ->
[]
end.

do_list_tenants(?IS_DB = Db, From, To, Limit) ->
transactional(Db, fun(Tx) ->
list_tenants(Tx, From, To, Limit)
end);
do_list_tenants(Tx, From, To, Limit) ->
FullFrom = tenant_selector(From),
FullTo = tenant_selector(To),
lists:map(
fun({K, V}) ->
{unprefix_tenant_key(K), V}
end,
erlfdb:get_range(Tx, FullFrom, FullTo, [{limit, clamp_limit(Limit)}])
).

check_tenant_existence(Tx, Key) ->
wait(get(Tx, Key)).

tenant_key(Tenant) ->
<<?TENANT_MAP_PREFIX/binary, Tenant/binary>>.

is_selector(Key) when is_binary(Key) ->
true;
is_selector({Key, Modifier}) when is_binary(Key) andalso is_atom(Modifier) ->
true;
is_selector({Key, Modifier, Offset}) when
is_binary(Key) andalso is_atom(Modifier) andalso is_integer(Offset)
-> true;
is_selector(_) ->
false.

tenant_selector(Key) when is_binary(Key) ->
tenant_key(Key);
tenant_selector({Key, Modifier}) when is_binary(Key) andalso is_atom(Modifier) ->
{tenant_key(Key), Modifier};
tenant_selector({Key, Modifier, Offset}) when
is_binary(Key) andalso is_atom(Modifier) andalso is_integer(Offset)
->
{tenant_key(Key), Modifier, Offset}.

clamp_limit(Limit) when is_integer(Limit) andalso Limit < 0 ->
0;
clamp_limit(Limit) when is_integer(Limit) andalso Limit > ?MAX_LIMIT ->
?MAX_LIMIT;
clamp_limit(Limit) when is_integer(Limit) ->
Limit.

unprefix_tenant_key(Key) ->
binary:part(Key, byte_size(?TENANT_MAP_PREFIX), byte_size(Key) - byte_size(?TENANT_MAP_PREFIX)).
51 changes: 39 additions & 12 deletions test/tester.es
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
index,
is_db,
is_snapshot,
is_tenant,
last_version,
pids,

Expand Down Expand Up @@ -228,6 +229,9 @@ stack_pop_tuples(St, Count) ->
get_transaction(TxName) ->
get({'$erlfdb_tx', TxName}).

tenant_or_db(#st{db = Db, tenant = undefined}) -> Db;
tenant_or_db(#st{tenant = Tenant}) -> Tenant.

new_transaction(#st{db = Db, tenant = Tenant}, TxName) ->
Src =
case Tenant of
Expand Down Expand Up @@ -321,6 +325,7 @@ init_run_loop(Db, Prefix) ->
index = 0,
is_db = undefined,
is_snapshot = undefined,
is_tenant = undefined,
last_version = 0,
pids = [],

Expand Down Expand Up @@ -362,31 +367,39 @@ run_loop(#st{} = St) ->

IsDb = has_suffix(Op, <<"_DATABASE">>),
IsSS = has_suffix(Op, <<"_SNAPSHOT">>),
IsTenant = has_suffix(Op, <<"_TENANT">>),
IsDir = has_prefix(Op, <<"DIRECTORY_">>),

OpName =
if
not (IsDb or IsSS) ->
Op;
true ->
% strip off _DATABASE/_SNAPSHOT
binary:part(Op, {0, size(Op) - 9})
IsDb -> binary:part(Op, {0, size(Op) - 9});
IsSS -> binary:part(Op, {0, size(Op) - 9});
IsTenant -> binary:part(Op, {0, size(Op) - 7});
true -> Op
end,

TxObj =
case {IsDb, IsSS} of
{true, false} ->
Db;
{false, false} ->
get_transaction(TxName);
{false, true} ->
erlfdb:snapshot(get_transaction(TxName))
if
IsDb -> Db;
IsSS -> erlfdb:snapshot(get_transaction(TxName));
IsTenant -> tenant_or_db(St);
true -> get_transaction(TxName)
end,

% case {IsDb, IsSS} of
% {true, false} ->
% Db;
% {false, false} ->
% get_transaction(TxName);
% {false, true} ->

% end,

PreSt = St#st{
op_tuple = OpTuple,
is_db = IsDb,
is_snapshot = IsSS,
is_tenant = IsTenant,
is_directory_op = IsDir
},

Expand Down Expand Up @@ -781,6 +794,20 @@ execute(_TxObj, #st{db = Db} = St, <<"TENANT_SET_ACTIVE">>) ->
St#st{tenant = Result};
execute(_TxObj, St, <<"TENANT_CLEAR_ACTIVE">>) ->
St#st{tenant = undefined};
execute(_TxObj, #st{db = Db} = St, <<"TENANT_LIST">>) ->
[Start, End, Limit] = stack_pop(St, 3),
TenantsKV = erlfdb_tenant:list_tenants(Db, Start, End, Limit),
{Tenants, _} = lists:unzip(TenantsKV), %% TODO: verify value json?
stack_push(St, erlfdb_tuple:pack(list_to_tuple(Tenants))),
St;
execute(_TxObj, #st{tenant = Tenant} = St, <<"TENANT_GET_ID">>) ->
case Tenant of
undefined -> stack_push(St, <<"NO_ACTIVE_TENANT">>);
_ ->
%% TODO: get tenant id actually
stack_push(St, <<"GOT_TENANT_ID">>)
end,
St;
execute(_TxObj, _St, UnknownOp) ->
erlang:error({unknown_op, UnknownOp}).

Expand Down
Loading