Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

connection: support connection via an existing socket fd #349

Merged
merged 4 commits into from
Nov 27, 2023

Conversation

askalt
Copy link

@askalt askalt commented Nov 7, 2023

This patch contains several changes:

Now, to connect to the Tarantool, you need to pass an object that satisfies tarantool.Dialer interface.

You can use one of the existing implementations: NetDialer, OpenSslDialer or FdDialer (which connects to the Tarantool using an existing socket fd).

For example:

conn, err := tarantool.Connect(context.Background(), tarantool.NetDialer{
	Address:  "127.0.0.1:3301",
	User:     "user",
	Password: "secret",
}, tarantool.Opts{})

To create a connection pool, you need to pass a map[string]tarantool.Dialer,where each dialer is associated with a unique ID (for example, it can bethe server address). Connections will be distinguished from each other using
these IDs.

For example:

connPool, err := pool.Connect(context.Background(), map[string]tarantool.Dialer{
	"127.0.0.1": tarantool.NetDialer{
		Address:  "127.0.0.1",
		User:     "user",
		Password: "secret",
	},
}, tarantool.Opts{})

The conn.RemoteAddr and conn.LocalAddr functions have been removed. To obtain the connection address, you can use conn.Addr.

Now, NewWatcher checks the actual features of the server, rather than relying
on the features provided by the user during connection creation.

In the case of connection pool, watchers are created for connections that support
this feature.

ClientProtocolInfo, ServerProtocolInfo were removed. Now, there is ProtocolInfo,
which returns the server protocol info.

I didn't forget about (remove if it is not applicable):

Related issues:
Closes #321

connection.go Outdated Show resolved Hide resolved
connection.go Outdated Show resolved Hide resolved
dial.go Outdated Show resolved Hide resolved
dial.go Outdated Show resolved Hide resolved
dial.go Outdated Show resolved Hide resolved
dial.go Outdated Show resolved Hide resolved
@askalt askalt force-pushed the askalt/gh-321-socket-fd branch 7 times, most recently from a858b07 to 4e6d41f Compare November 8, 2023 14:30
pool/connection_pool.go Outdated Show resolved Hide resolved
dial.go Outdated Show resolved Hide resolved
Copy link
Collaborator

@oleg-jukovec oleg-jukovec left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Watchers from the pool use conn.Addr() instead of id.

@askalt askalt force-pushed the askalt/gh-321-socket-fd branch 4 times, most recently from 91146f5 to 41b0ee5 Compare November 10, 2023 19:27
connection.go Outdated Show resolved Hide resolved
connection.go Outdated Show resolved Hide resolved
@askalt askalt force-pushed the askalt/gh-321-socket-fd branch 2 times, most recently from c846d06 to acd3f18 Compare November 10, 2023 20:36
@askalt askalt force-pushed the askalt/gh-321-socket-fd branch 4 times, most recently from a76f6d1 to cd94a86 Compare November 20, 2023 16:57
README.md Outdated Show resolved Hide resolved
connection.go Outdated Show resolved Hide resolved
connection.go Outdated Show resolved Hide resolved
connection.go Outdated Show resolved Hide resolved
Copy link
Collaborator

@oleg-jukovec oleg-jukovec left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the patch! Please, squash two commits into one:

connection: make dialer mandatory
+
tests: correct according to the changes

Although correct the commit headers:

connection: make dialer mandatory -> api: make dialer mandatory
dial: add the ability to connect via socket fd -> api: add the ability to connect via socket fd
docs: update according to the changes -> doc: update according to the changes

And move Closes https://github.com/tarantool/go-tarantool/issues/321 to a latest commit.

dial_test.go Outdated Show resolved Hide resolved
example_test.go Show resolved Hide resolved
@askalt askalt force-pushed the askalt/gh-321-socket-fd branch 2 times, most recently from 8ae96e7 to b030c5f Compare November 24, 2023 08:46
Copy link

@DerekBum DerekBum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm.

@oleg-jukovec
Copy link
Collaborator

Please, rebase the pull request.

Copy link

@better0fdead better0fdead left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, thx for patch. Pls, rebase pull request.

CHANGELOG.md Outdated Show resolved Hide resolved
@askalt askalt force-pushed the askalt/gh-321-socket-fd branch 2 times, most recently from 701ba26 to 7ac35fa Compare November 24, 2023 18:20
README.md Outdated Show resolved Hide resolved
This patch modifies `Connect` api.

Now, to connect to the Tarantool, you need to pass an
object that satisfies `tarantool.Dialer` interface.

You can use one of the existing implementations:
`NetDialer` or `OpenSslDialer`.

For example:
```
conn, err := tarantool.Connect(context.Background(), tarantool.NetDialer{
	Address:  "127.0.0.1:3301",
	User:     "user",
	Password: "secret",
}, tarantool.Opts{})
```

To create a connection pool, you need to pass a `map[string]tarantool.Dialer`,
where each dialer is associated with a unique ID (for example, it can be
the server address). Dialers will be distinguished from each other using
these IDs.

For example:
```
connPool, err := pool.Connect(context.Background(), map[string]tarantool.Dialer{
	"127.0.0.1": tarantool.NetDialer{
		Address:  "127.0.0.1",
		User:     "user",
		Password: "secret",
	},
}, tarantool.Opts{})
```

The `conn.RemoteAddr` and `conn.LocalAddr` functions have been removed.
To obtain the connection address, you can use `conn.Addr`.

Now, `NewWatcher` checks the actual features of the server, rather than relying
on the features provided by the user during connection creation.

In the case of connection pool, watchers are created for connections that support
this feature.

`ClientProtocolInfo`, `ServerProtocolInfo` were removed. Now, there is `ProtocolInfo`,
which returns the server protocol info.

`pool.GetPoolInfo` was renamed to `pool.GetInfo`. Return type changed to
`map[string]ConnectionInfo`.

Part of #321
This patch introduces `FdDialer`, which connects to Tarantool
using an existing socket file descriptor.

`FdDialer` is not authenticated when creating a connection.

Part of #321
@oleg-jukovec oleg-jukovec merged commit b2b800b into master Nov 27, 2023
22 checks passed
@oleg-jukovec oleg-jukovec deleted the askalt/gh-321-socket-fd branch November 27, 2023 09:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create connection from socket fd
4 participants