kura_ets_pool (kura_ets v0.0.1)

View Source

ETS 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 plain ets:lookup/2; only creation goes through the server, which serializes concurrent create races.
  • One set, public data 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

capabilities()

-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.

checkin(Name, Token)

-spec checkin(kura_pool:name(), kura_pool:token()) -> ok.

checkout(Name, Opts)

-spec checkout(kura_pool:name(), kura_pool:checkout_opts()) ->
                  {ok, kura_pool:conn(), kura_pool:token()} | {error, term()}.

ensure_table(Pool, TableName)

-spec ensure_table(kura_pool:name(), binary()) -> {ok, ets:tid()} | {error, term()}.

Return the data table for TableName, creating it on first use.

give_away/3

-spec give_away(kura_pool:token(), pid(), term()) -> ok | {error, term()}.

handle_call/3

-spec handle_call(term(), gen_server:from(), atom()) -> {reply, term(), atom()}.

handle_cast(Msg, Name)

-spec handle_cast(term(), atom()) -> {noreply, atom()}.

init(Name)

-spec init(atom()) -> {ok, atom()}.

reset(Pool)

-spec reset(kura_pool:name()) -> ok | {error, term()}.

Delete all rows from every table in the pool. Handy between tests.

start_pool(Name, Opts)

-spec start_pool(kura_pool:name(), kura_pool:opts()) -> {ok, pid()} | {error, term()}.

stop_pool(Name)

-spec stop_pool(kura_pool:name()) -> ok.