Skip to content

Introduce ConnectionPool with master discovery #207

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

Merged
merged 3 commits into from
Apr 20, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
connection: introduce common interface
Introduce connection interface to be used in connection pool
implementation. Only CRUD and base connect/close API is required
by the interface.

Part of #196
  • Loading branch information
DifferentialOrange committed Apr 20, 2022
commit e1c0c53cc31ac44e1fa4c4be4c2978122f3db131
87 changes: 86 additions & 1 deletion tarantool/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import time
import errno
import socket
import abc

import ctypes
import ctypes.util
Expand Down Expand Up @@ -76,8 +77,92 @@
ENCODING_DEFAULT,
)

# Based on https://realpython.com/python-interface/
class ConnectionInterface(metaclass=abc.ABCMeta):
@classmethod
def __subclasshook__(cls, subclass):
return (hasattr(subclass, 'close') and
callable(subclass.close) and
hasattr(subclass, 'is_closed') and
callable(subclass.is_closed) and
hasattr(subclass, 'connect') and
callable(subclass.connect) and
hasattr(subclass, 'call') and
callable(subclass.call) and
hasattr(subclass, 'eval') and
callable(subclass.eval) and
hasattr(subclass, 'replace') and
callable(subclass.replace) and
hasattr(subclass, 'insert') and
callable(subclass.insert) and
hasattr(subclass, 'delete') and
callable(subclass.delete) and
hasattr(subclass, 'upsert') and
callable(subclass.upsert) and
hasattr(subclass, 'update') and
callable(subclass.update) and
hasattr(subclass, 'ping') and
callable(subclass.ping) and
hasattr(subclass, 'select') and
callable(subclass.select) and
hasattr(subclass, 'execute') and
callable(subclass.execute) or
NotImplemented)

@abc.abstractmethod
def close(self):
raise NotImplementedError

@abc.abstractmethod
def is_closed(self):
raise NotImplementedError

@abc.abstractmethod
def connect(self):
raise NotImplementedError

@abc.abstractmethod
def call(self, func_name, *args, **kwargs):
raise NotImplementedError

@abc.abstractmethod
def eval(self, expr, *args, **kwargs):
raise NotImplementedError

@abc.abstractmethod
def replace(self, space_name, values):
raise NotImplementedError

@abc.abstractmethod
def insert(self, space_name, values):
raise NotImplementedError

@abc.abstractmethod
def delete(self, space_name, key, **kwargs):
raise NotImplementedError

@abc.abstractmethod
def upsert(self, space_name, tuple_value, op_list, **kwargs):
raise NotImplementedError

@abc.abstractmethod
def update(self, space_name, key, op_list, **kwargs):
raise NotImplementedError

@abc.abstractmethod
def ping(self, notime):
raise NotImplementedError

@abc.abstractmethod
def select(self, space_name, key, **kwargs):
raise NotImplementedError

@abc.abstractmethod
def execute(self, query, params, **kwargs):
raise NotImplementedError


class Connection(object):
class Connection(ConnectionInterface):
'''
Represents connection to the Tarantool server.

Expand Down