kura_ets_pool (kura_ets v0.0.1)
View SourceETS pool implementation. There are no connections to pool: the "pool" is a table registry, one gen_server per pool that owns all the ETS data tables so they survive the (arbitrary, short-lived) processes that read and write through the repo API.
Layout
- One gen_server registered under the pool name. It owns every table.
- One named, protected meta table (named after the pool atom) mapping
TableName :: binary()to the data table tid. Callers resolve tables with a plainets:lookup/2; only creation goes through the server, which serializes concurrent create races. - One
set, publicdata table per source table, created on demand at first use (mirroring etso's TableServer-per-schema design).
checkout/2 hands back the pool name itself: reads and writes go
straight to the public data tables, so there is nothing to lease.
Example
{ok, _Pid} = kura_ets_pool:start_pool(my_pool, #{}),
{ok, Tid} = kura_ets_pool:ensure_table(my_pool, ~"users"),
ok = kura_ets_pool:reset(my_pool),
ok = kura_ets_pool:stop_pool(my_pool).
Summary
Functions
The ETS backend returns the affected row from insert/update/delete
(the moral equivalent of RETURNING *), and nothing else from the
standard SQL capability set. Notably absent: transactions — writes
are applied immediately with no rollback.
Return the data table for TableName, creating it on first use.
Delete all rows from every table in the pool. Handy between tests.
Functions
-spec capabilities() -> kura_capabilities:capability_set().
The ETS backend returns the affected row from insert/update/delete
(the moral equivalent of RETURNING *), and nothing else from the
standard SQL capability set. Notably absent: transactions — writes
are applied immediately with no rollback.
-spec checkin(kura_pool:name(), kura_pool:token()) -> ok.
-spec checkout(kura_pool:name(), kura_pool:checkout_opts()) -> {ok, kura_pool:conn(), kura_pool:token()} | {error, term()}.
-spec ensure_table(kura_pool:name(), binary()) -> {ok, ets:tid()} | {error, term()}.
Return the data table for TableName, creating it on first use.
-spec give_away(kura_pool:token(), pid(), term()) -> ok | {error, term()}.
-spec handle_call(term(), gen_server:from(), atom()) -> {reply, term(), atom()}.
-spec reset(kura_pool:name()) -> ok | {error, term()}.
Delete all rows from every table in the pool. Handy between tests.
-spec start_pool(kura_pool:name(), kura_pool:opts()) -> {ok, pid()} | {error, term()}.
-spec stop_pool(kura_pool:name()) -> ok.