Skip to content

Commit acf2c0c

Browse files
committed
upgraded dbconnection to 2.0.6
1 parent e3396a5 commit acf2c0c

File tree

7 files changed

+49
-23
lines changed

7 files changed

+49
-23
lines changed

lib/mongo.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ defmodule Mongo do
167167

168168
with {:ok, conn, slave_ok, _} <- select_server(topology_pid, :read, opts),
169169
opts = Keyword.put(opts, :slave_ok, slave_ok),
170-
{:ok, version} <- DBConnection.execute(conn, wv_query, [], defaults(opts)) do
170+
{:ok, _query, version} <- DBConnection.execute(conn, wv_query, [], defaults(opts)) do
171171
cursor? = version >= 1 and Keyword.get(opts, :use_cursor, true)
172172
opts = Keyword.drop(opts, ~w(allow_disk_use max_time use_cursor)a)
173173

@@ -530,7 +530,7 @@ defmodule Mongo do
530530
params = [query]
531531
query = %Query{action: :command}
532532

533-
with {:ok, response} <- DBConnection.execute(conn, query, params, defaults(opts)) do
533+
with {:ok, _query, response} <- DBConnection.execute(conn, query, params, defaults(opts)) do
534534
case response do
535535
op_reply(flags: flags, docs: [%{"$err" => reason, "code" => code}]) when (@reply_query_failure &&& flags) != 0 -> {:error, Mongo.Error.exception(message: reason, code: code)}
536536
op_reply(flags: flags) when (@reply_cursor_not_found &&& flags) != 0 -> {:error, Mongo.Error.exception(message: "cursor not found")}

lib/mongo/mongo_db_connection.ex

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ defmodule Mongo.MongoDBConnection do
1111
@find_one_flags ~w(slave_ok exhaust partial)a
1212
@write_concern ~w(w j wtimeout)a
1313

14+
@impl true
1415
def connect(opts) do
1516
{write_concern, opts} = Keyword.split(opts, @write_concern)
1617
write_concern = Keyword.put_new(write_concern, :w, 1)
@@ -32,6 +33,7 @@ defmodule Mongo.MongoDBConnection do
3233
connect(opts, state)
3334
end
3435

36+
@impl true
3537
def disconnect(_error, %{socket: {mod, sock}} = state) do
3638
notify_disconnect(state)
3739
mod.close(sock)
@@ -42,6 +44,7 @@ defmodule Mongo.MongoDBConnection do
4244
end
4345

4446
defp connect(opts, state) do
47+
4548
result =
4649
with {:ok, state} <- tcp_connect(opts, state),
4750
{:ok, state} <- maybe_ssl(opts, state),
@@ -65,7 +68,7 @@ defmodule Mongo.MongoDBConnection do
6568
mod.close(sock)
6669
{:error, reason}
6770

68-
{:error, reason} -> {:error, reason}
71+
{:error, reason} -> {:error, reason}
6972
end
7073
end
7174

@@ -125,17 +128,45 @@ defmodule Mongo.MongoDBConnection do
125128
end
126129
end
127130

131+
@impl true
128132
def checkout(state), do: {:ok, state}
133+
@impl true
129134
def checkin(state), do: {:ok, state}
130135

136+
@impl true
137+
def handle_begin(opts, state), do: {:ok, nil, state}
138+
@impl true
139+
def handle_close(query, opts, state), do: {:ok, nil, state}
140+
@impl true
141+
def handle_commit(opts, state), do: {:ok, nil, state}
142+
@impl true
143+
def handle_deallocate(query, cursor, opts, state), do: {:ok, nil, state}
144+
@impl true
145+
def handle_declare(query, params, opts, state), do: {:ok, query, nil, state}
146+
@impl true
147+
def handle_fetch(query, cursor, opts, state), do: {:halt, nil, state}
148+
@impl true
149+
def handle_prepare(query, opts, state), do: {:ok, query, state}
150+
@impl true
151+
def handle_rollback(opts, state), do: {:ok, nil, state}
152+
@impl true
153+
def handle_status(opts, state), do: {:idle, state}
154+
155+
@impl true
156+
def ping(%{wire_version: wire_version} = state) do
157+
with {:ok, %{wire_version: ^wire_version}} <- wire_version(state), do: {:ok, state}
158+
end
159+
160+
131161
def handle_execute_close(query, params, opts, s) do
132162
handle_execute(query, params, opts, s)
133163
end
134164

135-
def handle_execute(%Mongo.Query{action: action, extra: extra}, params, opts, original_state) do
165+
@impl true
166+
def handle_execute(%Mongo.Query{action: action, extra: extra} = query, params, opts, original_state) do
136167
tmp_state = %{original_state | database: Keyword.get(opts, :database, original_state.database)}
137168
with {:ok, reply, tmp_state} <- handle_execute(action, extra, params, opts, tmp_state) do
138-
{:ok, reply, Map.put(tmp_state, :database, original_state.database)}
169+
{:ok, query, reply, Map.put(tmp_state, :database, original_state.database)}
139170
end
140171
end
141172

@@ -162,8 +193,5 @@ defmodule Mongo.MongoDBConnection do
162193
end)
163194
end
164195

165-
def ping(%{wire_version: wire_version} = state) do
166-
with {:ok, %{wire_version: ^wire_version}} <- wire_version(state), do: {:ok, state}
167-
end
168196

169197
end

lib/mongo/monitor.ex

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,7 @@ defmodule Mongo.Monitor do
103103
result = try do
104104
Mongo.direct_command(conn_pid, %{isMaster: 1}, opts)
105105
rescue
106-
e ->
107-
{:error, e}
106+
e -> {:error, e}
108107
end
109108
finish_time = System.monotonic_time
110109
rtt = System.convert_time_unit(finish_time - start_time, :native, :millisecond)

lib/mongo/topology.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ defmodule Mongo.Topology do
231231
server_description,
232232
self(),
233233
@heartbeat_frequency_ms,
234-
Keyword.put(connopts, :pool, DBConnection.Connection)
234+
Keyword.put(connopts, :pool, DBConnection.ConnectionPool)
235235
]
236236

237237
:ok = Mongo.Events.notify(%ServerOpeningEvent{address: address, topology_pid: self()})

mix.exs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,8 @@ defmodule Mongodb.Mixfile do
3737
defp deps do
3838
[
3939
{:connection, "~> 1.0"},
40-
{:db_connection, "~> 1.1"},
40+
{:db_connection, "~> 2.0.6"},
4141
{:decimal, "~> 1.0"},
42-
{:poolboy, ">= 0.0.0", only: :test},
4342
{:jason, "~> 1.0.0", only: :test},
4443
{:ex_doc, ">= 0.0.0", only: :dev},
4544
{:earmark, ">= 0.0.0", only: :dev},

mix.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
%{
22
"connection": {:hex, :connection, "1.0.4", "a1cae72211f0eef17705aaededacac3eb30e6625b04a6117c1b2db6ace7d5976", [:mix], [], "hexpm"},
3-
"db_connection": {:hex, :db_connection, "1.1.3", "89b30ca1ef0a3b469b1c779579590688561d586694a3ce8792985d4d7e575a61", [:mix], [{:connection, "~> 1.0.2", [hex: :connection, repo: "hexpm", optional: false]}, {:poolboy, "~> 1.5", [hex: :poolboy, repo: "hexpm", optional: true]}, {:sbroker, "~> 1.0", [hex: :sbroker, repo: "hexpm", optional: true]}], "hexpm"},
3+
"db_connection": {:hex, :db_connection, "2.0.6", "bde2f85d047969c5b5800cb8f4b3ed6316c8cb11487afedac4aa5f93fd39abfa", [:mix], [{:connection, "~> 1.0.2", [hex: :connection, repo: "hexpm", optional: false]}], "hexpm"},
44
"decimal": {:hex, :decimal, "1.5.0", "b0433a36d0e2430e3d50291b1c65f53c37d56f83665b43d79963684865beab68", [:mix], [], "hexpm"},
55
"dialyxir": {:hex, :dialyxir, "1.0.0-rc.4", "71b42f5ee1b7628f3e3a6565f4617dfb02d127a0499ab3e72750455e986df001", [:mix], [{:erlex, "~> 0.1", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm"},
66
"earmark": {:hex, :earmark, "1.2.4", "99b637c62a4d65a20a9fb674b8cffb8baa771c04605a80c911c4418c69b75439", [:mix], [], "hexpm"},
77
"erlex": {:hex, :erlex, "0.1.6", "c01c889363168d3fdd23f4211647d8a34c0f9a21ec726762312e08e083f3d47e", [:mix], [], "hexpm"},
88
"ex_doc": {:hex, :ex_doc, "0.18.1", "37c69d2ef62f24928c1f4fdc7c724ea04aecfdf500c4329185f8e3649c915baf", [:mix], [{:earmark, "~> 1.1", [hex: :earmark, repo: "hexpm", optional: false]}], "hexpm"},
99
"jason": {:hex, :jason, "1.0.0", "0f7cfa9bdb23fed721ec05419bcee2b2c21a77e926bce0deda029b5adc716fe2", [:mix], [{:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm"},
10-
"poolboy": {:hex, :poolboy, "1.5.1", "6b46163901cfd0a1b43d692657ed9d7e599853b3b21b95ae5ae0a777cf9b6ca8", [:rebar], [], "hexpm"},
10+
"poolboy": {:hex, :poolboy, "1.5.2", "392b007a1693a64540cead79830443abf5762f5d30cf50bc95cb2c1aaafa006b", [:rebar3], [], "hexpm"},
1111
}

test/mongo/connection_test.exs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ defmodule Mongo.ConnectionTest do
7373
username: "mongodb_user", password: "wrong",
7474
backoff_type: :stop]
7575

76-
capture_log fn ->
77-
assert {:ok, pid} = Mongo.start_link(opts)
78-
assert_receive {:EXIT, ^pid, {%Mongo.Error{code: 18}, _}}
79-
end
76+
assert capture_log(fn ->
77+
{:ok, pid} = Mongo.start_link(opts)
78+
assert_receive {:EXIT, ^pid, :killed}, 5000
79+
end)
8080
end
8181

8282
test "auth wrong on db" do
@@ -86,10 +86,10 @@ defmodule Mongo.ConnectionTest do
8686
username: "mongodb_admin_user", password: "wrong",
8787
backoff_type: :stop, auth_source: "admin_test"]
8888

89-
capture_log fn ->
90-
assert {:ok, pid} = Mongo.start_link(opts)
91-
assert_receive {:EXIT, ^pid, {%Mongo.Error{code: 18}, _}}
92-
end
89+
assert capture_log(fn ->
90+
{:ok, pid} = Mongo.start_link(opts)
91+
assert_receive {:EXIT, ^pid, :killed}, 5000
92+
end)
9393
end
9494

9595
test "insert_one flags" do

0 commit comments

Comments
 (0)