Skip to content

Commit 0fe6b7c

Browse files
cubeekIhar Hrachyshka
authored andcommitted
Don't update revision number if object was not modified
If there were not changes made to data in the database there is no reason to bump revision numbers because the underlying drivers won't change too. This saves cycles in case empty updates are incoming to the API. Co-Authored-By: Ihar Hrachyshka <[email protected]> Closes-bug: #2065094 Change-Id: Ib74fdab7a8927ef9cc24ef7810e9cf2c264941eb (cherry picked from commit 5795c19)
1 parent d3303c1 commit 0fe6b7c

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

neutron/services/revisions/revision_plugin.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,14 @@ def _get_objects_to_bump_revision(self, dirty_objects):
7878
def bump_revisions(self, session, context, instances):
7979
self._enforce_if_match_constraints(session)
8080
# bump revision number for updated objects in the session
81+
modified_objs = {o for o in session.dirty if session.is_modified(o)}
8182
self._bump_obj_revisions(
82-
session,
83-
self._get_objects_to_bump_revision(session.dirty))
83+
session, self._get_objects_to_bump_revision(modified_objs))
8484

8585
# see if any created/updated/deleted objects bump the revision
8686
# of another object
8787
objects_with_related_revisions = [
88-
o for o in session.deleted | session.dirty | session.new
88+
o for o in modified_objs | set(session.deleted) | set(session.new)
8989
if getattr(o, 'revises_on_change', ())
9090
]
9191
collected = session.info.setdefault('_related_bumped', set())

neutron/tests/unit/services/revisions/test_revision_plugin.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,13 @@ def test_constrained_port_update_handles_db_retries(self):
143143
# update
144144
with self.port() as port:
145145
rev = port['port']['revision_number']
146-
new = {'port': {'name': 'nigiri'}}
147146

148147
def concurrent_increment(s):
149148
db_api.sqla_remove(se.Session, 'before_commit',
150149
concurrent_increment)
151150
# slip in a concurrent update that will bump the revision
152151
plugin = directory.get_plugin()
152+
new = {'port': {'name': 'nigiri'}}
153153
plugin.update_port(nctx.get_admin_context(),
154154
port['port']['id'], new)
155155
raise db_exc.DBDeadlock()
@@ -160,13 +160,16 @@ def concurrent_increment(s):
160160
# transaction, the revision number is tested only once the first
161161
# time the revision number service is executed for this session and
162162
# object.
163+
new = {'port': {'name': 'sushi'}}
163164
self._update('ports', port['port']['id'], new,
164165
headers={'If-Match': 'revision_number=%s' % rev},
165166
expected_code=exc.HTTPOk.code)
167+
new = {'port': {'name': 'salmon'}}
166168
self._update('ports', port['port']['id'], new,
167169
headers={'If-Match': 'revision_number=%s' %
168170
str(int(rev) + 2)},
169171
expected_code=exc.HTTPOk.code)
172+
new = {'port': {'name': 'tea'}}
170173
self._update('ports', port['port']['id'], new,
171174
headers={'If-Match': 'revision_number=1'},
172175
expected_code=exc.HTTPPreconditionFailed.code)

0 commit comments

Comments
 (0)