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 7.3 (follow-up) #16

Merged
merged 2 commits into from
Apr 4, 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
7 changes: 5 additions & 2 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
ARG FDB_VERSION
ARG ERLANG_VERSION
ARG PIP_INSTALL_FLAGS

# Grab fdbcli and client library from same image as server
FROM foundationdb/foundationdb:${FDB_VERSION} as fdb
Expand All @@ -13,7 +14,7 @@ ARG FDB_VERSION

# Install the FDB client used underneath erlfdb
RUN set -ex; \
wget https://github.com/apple/foundationdb/releases/download/${FDB_VERSION}/foundationdb-clients_${FDB_VERSION}-1_amd64.deb; \
wget -q https://github.com/apple/foundationdb/releases/download/${FDB_VERSION}/foundationdb-clients_${FDB_VERSION}-1_amd64.deb; \
mkdir /var/lib/foundationdb; \
dpkg -i foundationdb-clients_${FDB_VERSION}-1_amd64.deb; \
rm foundationdb-clients_${FDB_VERSION}-1_amd64.deb
Expand All @@ -36,8 +37,10 @@ RUN set -ex; \
python3-pip; \
rm -rf /var/lib/apt/lists/*

ARG PIP_INSTALL_FLAGS

# FDB bindings tester uses the Python bindings
RUN pip3 install foundationdb==${FDB_VERSION}
RUN pip3 install foundationdb==${FDB_VERSION} ${PIP_INSTALL_FLAGS}

COPY create_cluster_file.bash /usr/local/bin/

Expand Down
2 changes: 1 addition & 1 deletion .devcontainer/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ services:
context: .
dockerfile: Dockerfile
args:
ERLANG_VERSION: "25"
ERLANG_VERSION: "26"

# This should always match the value in fdb.image
FDB_VERSION: "7.3.35"
Expand Down
10 changes: 6 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
eunit:
strategy:
matrix:
otp-version: ['24', '25']
otp-version: ['25', '26']
fdb-version: ['7.3.35']
runs-on: ubuntu-22.04
env:
Expand All @@ -33,10 +33,12 @@ jobs:
rebar3-version: '3.17'
- name: Install FoundationDB
run: |
wget https://github.com/apple/foundationdb/releases/download/${FDB_VERSION}/foundationdb-clients_${FDB_VERSION}-1_amd64.deb
wget https://github.com/apple/foundationdb/releases/download/${FDB_VERSION}/foundationdb-server_${FDB_VERSION}-1_amd64.deb
wget -q https://github.com/apple/foundationdb/releases/download/${FDB_VERSION}/foundationdb-clients_${FDB_VERSION}-1_amd64.deb
wget -q https://github.com/apple/foundationdb/releases/download/${FDB_VERSION}/foundationdb-server_${FDB_VERSION}-1_amd64.deb
sudo dpkg -i foundationdb-clients_${FDB_VERSION}-1_amd64.deb
sudo dpkg -i foundationdb-server_${FDB_VERSION}-1_amd64.deb
- name: Initialize FDB database
run: fdbcli --exec "configure tenant_mode=optional_experimental"
- name: Compile
run: rebar3 compile
- name: EUnit tests
Expand All @@ -49,7 +51,7 @@ jobs:
test-name: [api, directory, directory_hca, tuple]
api-version: [730]
container:
image: ghcr.io/emqx/couchdb-erlfdb:erlang-25-fdb-7.3.35
image: ghcr.io/emqx/couchdb-erlfdb:erlang-26-fdb-7.3.35
services:
foundationdb:
image: foundationdb/foundationdb:7.3.35
Expand Down
11 changes: 8 additions & 3 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ jobs:
runs-on: ubuntu-22.04
strategy:
matrix:
otp-version: ['24', '25']
otp:
- version: 25
pip_flags: ''
- version: 26
pip_install_flags: '--break-system-packages'
fdb-version: ['7.3.35']

steps:
Expand All @@ -31,9 +35,10 @@ jobs:
- uses: docker/build-push-action@v3
with:
push: true
tags: ghcr.io/${{ github.repository }}:erlang-${{ matrix.otp-version }}-fdb-${{ matrix.fdb-version }}
tags: ghcr.io/${{ github.repository }}:erlang-${{ matrix.otp.version }}-fdb-${{ matrix.fdb-version }}
file: .devcontainer/Dockerfile
context: .devcontainer
build-args: |
FDB_VERSION=${{ matrix.fdb-version }}
ERLANG_VERSION=${{ matrix.otp-version }}
ERLANG_VERSION=${{ matrix.otp.version }}
PIP_INSTALL_FLAGS=${{ matrix.otp.pip_install_flags }}
32 changes: 32 additions & 0 deletions c_src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,37 @@ erlfdb_database_open_tenant(
}


static ERL_NIF_TERM
erlfdb_tenant_get_id(
ErlNifEnv* env,
int argc,
const ERL_NIF_TERM argv[]
)
{
ErlFDBSt* st = (ErlFDBSt*) enif_priv_data(env);
ErlFDBTenant* t;
void* res;
FDBFuture* future;

if(st->lib_state != ErlFDB_CONNECTED) {
return enif_make_badarg(env);
}

if(argc != 1) {
return enif_make_badarg(env);
}

if(!enif_get_resource(env, argv[0], ErlFDBTenantRes, &res)) {
return enif_make_badarg(env);
}
t = (ErlFDBTenant*) res;

future = fdb_tenant_get_id(t->tenant);

return erlfdb_create_future(env, future, erlfdb_future_get_int64);
}


static ERL_NIF_TERM
erlfdb_tenant_create_transaction(
ErlNifEnv* env,
Expand Down Expand Up @@ -2272,6 +2303,7 @@ static ErlNifFunc funcs[] =
NIF_FUNC(erlfdb_create_database, 1),
NIF_FUNC(erlfdb_database_set_option, 3),
NIF_FUNC(erlfdb_database_open_tenant, 2),
NIF_FUNC(erlfdb_tenant_get_id, 1),
NIF_FUNC(erlfdb_database_create_transaction, 1),

NIF_FUNC(erlfdb_tenant_create_transaction, 1),
Expand Down
6 changes: 6 additions & 0 deletions src/erlfdb_nif.erl
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
database_create_transaction/1,

tenant_create_transaction/1,
tenant_get_id/1,

transaction_set_option/2,
transaction_set_option/3,
Expand Down Expand Up @@ -294,6 +295,10 @@ database_create_transaction({erlfdb_database, Db}) ->
tenant_create_transaction({erlfdb_tenant, Db}) ->
erlfdb_tenant_create_transaction(Db).

-spec tenant_get_id(tenant()) -> future().
tenant_get_id({erlfdb_tenant, Db}) ->
erlfdb_tenant_get_id(Db).

-spec transaction_set_option(transaction(), Option :: transaction_option()) -> ok.
transaction_set_option(Transaction, Option) ->
transaction_set_option(Transaction, Option, <<>>).
Expand Down Expand Up @@ -580,6 +585,7 @@ erlfdb_database_create_transaction(_Database) -> ?NOT_LOADED.

%% Tenants
erlfdb_tenant_create_transaction(_Database) -> ?NOT_LOADED.
erlfdb_tenant_get_id(_Tenant) -> ?NOT_LOADED.

% Transactions
erlfdb_transaction_set_option(_Transaction, _TransactionOption, _Value) -> ?NOT_LOADED.
Expand Down
7 changes: 5 additions & 2 deletions src/erlfdb_tenant.erl
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@

-module(erlfdb_tenant).

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

-define(IS_DB, {erlfdb_database, _}).
-define(TENANT_MAP_PREFIX, <<16#FF, 16#FF, "/management/tenant_map/">>).
-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 @@ -59,6 +59,9 @@ list_tenants(Db, From, To, Limit) ->
[]
end.

get_id(Tenant) ->
erlfdb_nif:tenant_get_id(Tenant).

do_list_tenants(?IS_DB = Db, From, To, Limit) ->
transactional(Db, fun(Tx) ->
list_tenants(Tx, From, To, Limit)
Expand Down
2 changes: 1 addition & 1 deletion src/erlfdb_util.erl
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ init_fdb_db(ClusterFile, Options) ->
DefaultFDBCli -> "fdbcli";
FDBCli0 -> FDBCli0
end,
Fmt = "~s -C ~s --exec \"configure new single ssd\"",
Fmt = "~s -C ~s --exec \"configure new single ssd tenant_mode=optional_experimental\"",
Cmd = lists:flatten(io_lib:format(Fmt, [FDBCli, ClusterFile])),
case os:cmd(Cmd) of
"Database created" ++ _ -> ok;
Expand Down
47 changes: 47 additions & 0 deletions test/erlfdb_07_tenant_test.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
% Licensed under the Apache License, Version 2.0 (the "License"); you may not
% use this file except in compliance with the License. You may obtain a copy of
% the License at
%
% http://www.apache.org/licenses/LICENSE-2.0
%
% Unless required by applicable law or agreed to in writing, software
% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
% License for the specific language governing permissions and limitations under
% the License.

-module(erlfdb_07_tenant_test).

-include_lib("eunit/include/eunit.hrl").

tenant_management_test() ->
Db = erlfdb_util:get_test_db(),
Tenant = gen(10),
?assertEqual(ok, erlfdb_tenant:create_tenant(Db, Tenant)),
?assertEqual({error, tenant_already_exists}, erlfdb_tenant:create_tenant(Db, Tenant)),
?assertEqual(ok, erlfdb_tenant:delete_tenant(Db, Tenant)),
?assertEqual({error, tenant_not_found}, erlfdb_tenant:delete_tenant(Db, Tenant)).

tenant_list_test() ->
Db = erlfdb_util:get_test_db(),
Tenant1 = gen(10),
Tenant2 = gen(10),
?assertEqual(ok, erlfdb_tenant:create_tenant(Db, Tenant1)),
?assertEqual(ok, erlfdb_tenant:create_tenant(Db, Tenant2)),
{Tenants, _} = lists:unzip(erlfdb_tenant:list_tenants(Db, <<>>, <<16#FF>>, 99999999)),
?assert(lists:member(Tenant1, Tenants)),
?assert(lists:member(Tenant2, Tenants)).

tenant_get_id_test() ->
Db = erlfdb_util:get_test_db(),
Tenant = gen(10),
?assertEqual(ok, erlfdb_tenant:create_tenant(Db, Tenant)),
Tn = erlfdb_tenant:open_tenant(Db, Tenant),
?assert(is_integer(erlfdb:wait(erlfdb_tenant:get_id(Tn)))).

gen(N) ->
<< <<(gen_char())>> || _ <- lists:seq(1, N) >>.

gen_char() ->
$a - 1 + rand:uniform($z - $a + 1).

11 changes: 1 addition & 10 deletions test/tester.es
Original file line number Diff line number Diff line change
Expand Up @@ -386,15 +386,6 @@ run_loop(#st{} = 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,
Expand Down Expand Up @@ -804,7 +795,7 @@ execute(_TxObj, #st{tenant = Tenant} = St, <<"TENANT_GET_ID">>) ->
case Tenant of
undefined -> stack_push(St, <<"NO_ACTIVE_TENANT">>);
_ ->
%% TODO: get tenant id actually
_Id = erlfdb:wait(erlfdb_tenant:get_id(Tenant)),
stack_push(St, <<"GOT_TENANT_ID">>)
end,
St;
Expand Down