Skip to content

Commit a2088a4

Browse files
committed
#106: work in progress: updated elixir and erlang, added ping command
1 parent 9eff5e2 commit a2088a4

File tree

5 files changed

+42
-51
lines changed

5 files changed

+42
-51
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99
* Enhancements
1010
* Fix for serializing BSON Regex without options (thanks to MillionIntegrals)
1111
* Misc doc changes (thanks to kianmeng)
12+
* Added support for OP_MSG exhaustAllowed flag
13+
* Added support for streaming protocol
14+
* Added Insights app for development
1215

1316
## 0.8.0 (2021-11-07) (0.7.5 was not published)
1417
* Enhancements
@@ -22,7 +25,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2225
* added a new option to specify a timeout, when increasing the connection pool is no option
2326

2427
## 0.7.3 (2021-05-29)
25-
2628
* Enhancements
2729
* added support for OTP 24
2830
* Add support for tls setting in connection string (tschmittni)

config/config.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This file is responsible for configuring your application
22
# and its dependencies with the aid of the Mix.Config module.
3-
use Mix.Config
3+
import Config
44

55
# This configuration is loaded before any dependency and is restricted
66
# to this project. If another project depends on this project, this

lib/mongo/mongo_db_connection.ex

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ defmodule Mongo.MongoDBConnection do
1616
@timeout 5_000
1717
@find_one_flags ~w(slave_ok exhaust partial)a
1818
@write_concern ~w(w j wtimeout)a
19+
@insecure_cmds [:authenticate, :saslStart, :saslContinue, :getnonce, :createUser, :updateUser, :copydbgetnonce, :copydbsaslstart, :copydb, :isMaster, :ismaster]
1920

2021
@impl true
2122
def connect(opts) do
@@ -40,17 +41,6 @@ defmodule Mongo.MongoDBConnection do
4041
connect(opts, state)
4142
end
4243

43-
@impl true
44-
def disconnect(_error, %{connection: {mod, socket}} = state) do
45-
notify_disconnect(state)
46-
mod.close(socket)
47-
:ok
48-
end
49-
50-
defp notify_disconnect(%{connection_type: type, topology_pid: pid, host: host}) do
51-
GenServer.cast(pid, {:disconnect, type, host})
52-
end
53-
5444
defp connect(opts, state) do
5545

5646
result =
@@ -127,24 +117,27 @@ defmodule Mongo.MongoDBConnection do
127117
end
128118
end
129119

130-
defp wire_version(state, client) do
131-
# wire version
132-
# https://github.com/mongodb/mongo/blob/master/src/mongo/db/wire_version.h
133-
120+
defp post_hello_command(state, client) do
134121
cmd = [ismaster: 1, client: client]
135122

136123
case Utils.command(-1, cmd, state) do
137-
{:ok, _flags, %{"ok" => ok, "maxWireVersion" => version}} when ok == 1 -> {:ok, %{state | wire_version: version}}
138-
{:ok, _flags, %{"ok" => ok}} when ok == 1 -> {:ok, %{state | wire_version: 0}}
124+
{:ok, _flags, %{"ok" => ok, "maxWireVersion" => version}} when ok == 1 ->
125+
{:ok, %{state | wire_version: version}}
126+
127+
{:ok, _flags, %{"ok" => ok}} when ok == 1 ->
128+
{:ok, %{state | wire_version: 0}}
129+
139130
{:ok, _flags, %{"ok" => ok, "errmsg" => msg, "code" => code}} when ok == 0 ->
140131
err = Mongo.Error.exception(message: msg, code: code)
141132
{:disconnect, err, state}
142-
{:disconnect, _, _} = error -> error
133+
134+
{:disconnect, _, _} = error ->
135+
error
143136
end
144137
end
145138

146139
defp hand_shake(opts, state) do
147-
wire_version(state, driver(opts[:appname] || "My killer app"))
140+
post_hello_command(state, driver(opts[:appname] || "My killer app"))
148141
end
149142

150143
defp driver(appname) do
@@ -194,6 +187,13 @@ defmodule Mongo.MongoDBConnection do
194187
defp pretty_name("apple"), do: "Mac OS X"
195188
defp pretty_name(name), do: name
196189

190+
@impl true
191+
def disconnect(_error, %{connection: {mod, socket}, connection_type: type, topology_pid: pid, host: host}) do
192+
GenServer.cast(pid, {:disconnect, type, host})
193+
mod.close(socket)
194+
:ok
195+
end
196+
197197
@impl true
198198
def checkout(state), do: {:ok, state}
199199
@impl true
@@ -219,23 +219,23 @@ defmodule Mongo.MongoDBConnection do
219219
def handle_status(_opts, state), do: {:idle, state}
220220

221221
@impl true
222-
def ping(%{wire_version: _wire_version} = state) do
223-
###with {:ok, %{wire_version: ^wire_version}} <- wire_version(state), do: {:ok, state}
224-
## todo Logger.info("Ignoring ping")
225-
{:ok, state}
226-
end
222+
def ping(%{connection_type: :client} = state) do
223+
cmd = [ping: 1]
224+
case Utils.command(-1, cmd, state) do
225+
{:ok, _flags, %{"ok" => ok}} when ok == 1 ->
226+
{:ok, state}
227227

228-
@doc """
229-
Execute a query prepared by `c:handle_prepare/3`. Return
230-
`{:ok, query, result, state}` to return altered query `query` and result
231-
`result` and continue, `{:error, exception, state}` to return an error and
232-
continue or `{:disconnect, exception, state}` to return an error and
233-
disconnect.
228+
{:ok, _flags, %{"ok" => ok, "errmsg" => msg, "code" => code}} when ok == 0 ->
229+
err = Mongo.Error.exception(message: msg, code: code)
230+
{:disconnect, err, state}
234231

235-
This callback is called in the client process.
236-
"""
237-
def handle_execute_close(query, params, opts, s) do
238-
handle_execute(query, params, opts, s)
232+
{:disconnect, _, _} = error ->
233+
error
234+
end
235+
end
236+
@impl true
237+
def ping(state) do
238+
{:ok, state}
239239
end
240240

241241
@impl true
@@ -246,7 +246,7 @@ defmodule Mongo.MongoDBConnection do
246246
end
247247
end
248248

249-
@insecure_cmds [:authenticate, :saslStart, :saslContinue, :getnonce, :createUser, :updateUser, :copydbgetnonce, :copydbsaslstart, :copydb, :isMaster, :ismaster]
249+
250250
defp provide_cmd_data([{command_name,_}|_] = cmd) do
251251
case Enum.member?(@insecure_cmds, command_name) do
252252
true -> {command_name, %{}}

mix.exs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,6 @@ defmodule Mongodb.Mixfile do
1414
deps: deps(),
1515
docs: docs(),
1616
package: package(),
17-
test_coverage: [tool: ExCoveralls],
18-
preferred_cli_env: [
19-
docs: :docs,
20-
coveralls: :test,
21-
"coveralls.detail": :test,
22-
"coveralls.post": :test,
23-
"coveralls.html": :test
24-
],
2517
consolidate_protocols: Mix.env() != :test
2618
]
2719
end
@@ -43,13 +35,10 @@ defmodule Mongodb.Mixfile do
4335

4436
defp deps do
4537
[
46-
{:db_connection, "~> 2.3"},
38+
{:db_connection, "~> 2.4"},
4739
{:decimal, "~> 2.0"},
48-
{:excoveralls, "~> 0.12.1", only: :test},
49-
{:benchee, "~> 1.0", only: :dev},
50-
{:jason, "~> 1.2", only: :test},
40+
{:jason, "~> 1.3", only: :test},
5141
{:ex_doc, ">= 0.0.0", only: :docs, runtime: false},
52-
#{:dialyxir, "~> 0.5", only: :dev, runtime: false}
5342
]
5443
end
5544

mix.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"excoveralls": {:hex, :excoveralls, "0.12.1", "a553c59f6850d0aff3770e4729515762ba7c8e41eedde03208182a8dc9d0ce07", [:mix], [{:hackney, "~> 1.0", [hex: :hackney, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "5c1f717066a299b1b732249e736c5da96bb4120d1e55dc2e6f442d251e18a812"},
1515
"hackney": {:hex, :hackney, "1.15.2", "07e33c794f8f8964ee86cebec1a8ed88db5070e52e904b8f12209773c1036085", [:rebar3], [{:certifi, "2.5.1", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "6.0.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "1.0.1", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "~>1.1", [hex: :mimerl, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "1.1.5", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}], "hexpm", "e0100f8ef7d1124222c11ad362c857d3df7cb5f4204054f9f0f4a728666591fc"},
1616
"idna": {:hex, :idna, "6.0.0", "689c46cbcdf3524c44d5f3dde8001f364cd7608a99556d8fbd8239a5798d4c10", [:rebar3], [{:unicode_util_compat, "0.4.1", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "4bdd305eb64e18b0273864920695cb18d7a2021f31a11b9c5fbcd9a253f936e2"},
17-
"jason": {:hex, :jason, "1.2.2", "ba43e3f2709fd1aa1dce90aaabfd039d000469c05c56f0b8e31978e03fa39052", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "18a228f5f0058ee183f29f9eae0805c6e59d61c3b006760668d8d18ff0d12179"},
17+
"jason": {:hex, :jason, "1.3.0", "fa6b82a934feb176263ad2df0dbd91bf633d4a46ebfdffea0c8ae82953714946", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "53fc1f51255390e0ec7e50f9cb41e751c260d065dcba2bf0d08dc51a4002c2ac"},
1818
"makeup": {:hex, :makeup, "1.0.5", "d5a830bc42c9800ce07dd97fa94669dfb93d3bf5fcf6ea7a0c67b2e0e4a7f26c", [:mix], [{:nimble_parsec, "~> 0.5 or ~> 1.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "cfa158c02d3f5c0c665d0af11512fed3fba0144cf1aadee0f2ce17747fba2ca9"},
1919
"makeup_elixir": {:hex, :makeup_elixir, "0.15.1", "b5888c880d17d1cc3e598f05cdb5b5a91b7b17ac4eaf5f297cb697663a1094dd", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.1", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "db68c173234b07ab2a07f645a5acdc117b9f99d69ebf521821d89690ae6c6ec8"},
2020
"makeup_erlang": {:hex, :makeup_erlang, "0.1.1", "3fcb7f09eb9d98dc4d208f49cc955a34218fc41ff6b84df7c75b3e6e533cc65f", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "174d0809e98a4ef0b3309256cbf97101c6ec01c4ab0b23e926a9e17df2077cbb"},

0 commit comments

Comments
 (0)