-
Notifications
You must be signed in to change notification settings - Fork 1.1k
PYTHON-2453 Add MongoDB Versioned API #536
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
Changes from all commits
63432d0
c59a9b4
9bf52bf
cde00e3
9d77f97
66a1ada
99041b7
d58596c
a6002d3
3db2688
3fa1f93
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,6 +54,7 @@ Sub-modules: | |
read_preferences | ||
results | ||
son_manipulator | ||
server_api | ||
uri_parser | ||
write_concern | ||
event_loggers |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
:mod:`server_api` -- Support for MongoDB Versioned API | ||
====================================================== | ||
|
||
.. automodule:: pymongo.server_api | ||
:synopsis: Support for MongoDB Versioned API | ||
|
||
.. autoclass:: pymongo.server_api.ServerApi | ||
:members: | ||
|
||
.. autoclass:: pymongo.server_api.ServerApiVersion | ||
:members: |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,6 +60,7 @@ | |
from pymongo.network import (command, | ||
receive_message) | ||
from pymongo.read_preferences import ReadPreference | ||
from pymongo.server_api import _add_to_command | ||
from pymongo.server_type import SERVER_TYPE | ||
from pymongo.socket_checker import SocketChecker | ||
# Always use our backport so we always have support for IP address matching | ||
|
@@ -311,7 +312,7 @@ class PoolOptions(object): | |
'__ssl_context', '__ssl_match_hostname', '__socket_keepalive', | ||
'__event_listeners', '__appname', '__driver', '__metadata', | ||
'__compression_settings', '__max_connecting', | ||
'__pause_enabled') | ||
'__pause_enabled', '__server_api') | ||
|
||
def __init__(self, max_pool_size=MAX_POOL_SIZE, | ||
min_pool_size=MIN_POOL_SIZE, | ||
|
@@ -321,8 +322,7 @@ def __init__(self, max_pool_size=MAX_POOL_SIZE, | |
ssl_match_hostname=True, socket_keepalive=True, | ||
event_listeners=None, appname=None, driver=None, | ||
compression_settings=None, max_connecting=MAX_CONNECTING, | ||
pause_enabled=True): | ||
|
||
pause_enabled=True, server_api=None): | ||
self.__max_pool_size = max_pool_size | ||
self.__min_pool_size = min_pool_size | ||
self.__max_idle_time_seconds = max_idle_time_seconds | ||
|
@@ -339,6 +339,7 @@ def __init__(self, max_pool_size=MAX_POOL_SIZE, | |
self.__compression_settings = compression_settings | ||
self.__max_connecting = max_connecting | ||
self.__pause_enabled = pause_enabled | ||
self.__server_api = server_api | ||
self.__metadata = copy.deepcopy(_METADATA) | ||
if appname: | ||
self.__metadata['application'] = {'name': appname} | ||
|
@@ -495,6 +496,12 @@ def metadata(self): | |
""" | ||
return self.__metadata.copy() | ||
|
||
@property | ||
def server_api(self): | ||
"""A pymongo.server_api.ServerApi or None. | ||
""" | ||
return self.__server_api | ||
|
||
|
||
def _negotiate_creds(all_credentials): | ||
"""Return one credential that needs mechanism negotiation, if any. | ||
|
@@ -705,6 +712,7 @@ def command(self, dbname, spec, slave_ok=False, | |
raise ConfigurationError( | ||
'Must be connected to MongoDB 3.4+ to use a collation.') | ||
|
||
self.add_server_api(spec, session) | ||
if session: | ||
session._apply_to(spec, retryable_write, read_preference) | ||
self.send_cluster_time(spec, session, client) | ||
|
@@ -894,6 +902,14 @@ def send_cluster_time(self, command, session, client): | |
if self.max_wire_version >= 6 and client: | ||
client._send_cluster_time(command, session) | ||
|
||
def add_server_api(self, command, session): | ||
"""Add server_api parameters.""" | ||
if (session and session.in_transaction and | ||
not session._starting_transaction): | ||
return | ||
if self.opts.server_api: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To make this more explicitly adhere to the spec, I think we should use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My point here was that since the spec asks us to check if the user passed a value at all, that's exactly what we should do. Since There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If a user passes something that's not a ServerApi they will get an error when creating the client:
|
||
_add_to_command(command, self.opts.server_api) | ||
|
||
def update_last_checkin_time(self): | ||
self.last_checkin_time = _time() | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the
REQUIRE_API_VERSION
variable used for? I don't see it used anywhere.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need both variables. REQUIRE_API_VERSION tells drivers-evg-tools to start the cluster with the requireApiVersion parameter. MONGODB_API_VERSION tells the test suite which ServerApi.version to use. When we eventually test version 2, we'll need to use:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see! That's certainly going to be hard to figure out for a newcomer. Can we add a comment that
REQUIRE_API_VERSION
is used by cluster orchestration scripts in drivers-evergreen-tools?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.