Skip to content

Commit cc08ff8

Browse files
authored
Enable descentralized counters (#314)
1 parent 893d1a6 commit cc08ff8

File tree

7 files changed

+26
-20
lines changed

7 files changed

+26
-20
lines changed

.github/workflows/ci.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ jobs:
1616
matrix:
1717
include:
1818
- pair:
19-
elixir: 1.8.2
20-
otp: 20.3
19+
elixir: 1.11
20+
otp: 23.0
2121
- pair:
22-
elixir: 1.14.3
22+
elixir: 1.17
2323
otp: 25.3
2424
lint: lint
2525
steps:

integration_test/ownership/test_helper.exs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
excludes = if Version.match?(System.version(), ">= 1.8.0"), do: [], else: [:requires_callers]
2-
31
ExUnit.start(
42
capture_log: true,
53
assert_receive_timeout: 1000,
6-
exclude: [:idle_time, :idle_interval | excludes]
4+
exclude: [:idle_time, :idle_interval]
75
)
86

97
Code.require_file("../../test/test_support.exs", __DIR__)

lib/db_connection/connection_pool.ex

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ defmodule DBConnection.ConnectionPool do
5252
def init({mod, opts}) do
5353
DBConnection.register_as_pool(mod)
5454

55-
queue = :ets.new(__MODULE__.Queue, [:protected, :ordered_set])
55+
queue = :ets.new(__MODULE__.Queue, [:protected, :ordered_set, decentralized_counters: true])
5656
ts = {System.monotonic_time(), 0}
5757
{:ok, _} = DBConnection.ConnectionPool.Pool.start_supervised(queue, mod, opts)
5858
target = Keyword.get(opts, :queue_target, @queue_target)

lib/db_connection/holder.ex

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ defmodule DBConnection.Holder do
1717
@spec new(pid, reference, module, term) :: t
1818
def new(pool, ref, mod, state) do
1919
# Insert before setting heir so that pool can't receive empty table
20-
holder = :ets.new(__MODULE__, [:public, :ordered_set])
20+
holder = :ets.new(__MODULE__, [:public, :ordered_set, decentralized_counters: true])
2121

2222
conn = conn(connection: self(), module: mod, state: state, ts: System.monotonic_time())
2323
true = :ets.insert_new(holder, conn)

lib/db_connection/ownership/manager.ex

+7-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,13 @@ defmodule DBConnection.Ownership.Manager do
7474
ets =
7575
case Keyword.fetch(owner_opts, :name) do
7676
{:ok, name} when is_atom(name) ->
77-
:ets.new(name, [:set, :named_table, :protected, read_concurrency: true])
77+
:ets.new(name, [
78+
:set,
79+
:named_table,
80+
:protected,
81+
read_concurrency: true,
82+
decentralized_counters: true
83+
])
7884

7985
_ ->
8086
nil

mix.exs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ defmodule DBConnection.Mixfile do
33

44
@source_url "https://github.com/elixir-ecto/db_connection"
55
@pools [:connection_pool, :ownership]
6-
@version "2.7.0"
6+
@version "2.8.0-dev"
77

88
def project do
99
[
1010
app: :db_connection,
1111
version: @version,
12-
elixir: "~> 1.8",
12+
elixir: "~> 1.11",
1313
deps: deps(),
1414
docs: docs(),
1515
description: description(),

test/db_connection_test.exs

+11-9
Original file line numberDiff line numberDiff line change
@@ -63,21 +63,23 @@ defmodule DBConnectionTest do
6363
end
6464

6565
describe "connection_module/1" do
66-
test "returns the connection module when given a pool pid" do
67-
{:ok, pool} = P.start_link([])
66+
setup do
67+
{:ok, agent} = A.start_link([{:ok, :state}, {:idle, :state}, {:idle, :state}])
68+
[agent: agent]
69+
end
70+
71+
test "returns the connection module when given a pool pid", %{agent: agent} do
72+
{:ok, pool} = P.start_link(agent: agent)
6873
assert {:ok, TestConnection} = DBConnection.connection_module(pool)
6974
end
7075

71-
test "returns the connection module when given a pool name", %{test: name} do
72-
{:ok, _pool} = P.start_link(name: name)
76+
test "returns the connection module when given a pool name", %{test: name, agent: agent} do
77+
{:ok, _pool} = P.start_link(name: name, agent: agent)
7378
assert {:ok, TestConnection} = DBConnection.connection_module(name)
7479
end
7580

76-
test "returns the connection module when given a locked connection reference" do
77-
{:ok, agent} = A.start_link([{:ok, :state}, {:idle, :state}, {:idle, :state}])
78-
79-
opts = [agent: agent]
80-
{:ok, pool} = P.start_link(opts)
81+
test "returns the connection module when given a locked connection reference", %{agent: agent} do
82+
{:ok, pool} = P.start_link(agent: agent)
8183

8284
P.run(pool, fn conn ->
8385
assert {:ok, TestConnection} = DBConnection.connection_module(conn)

0 commit comments

Comments
 (0)