Skip to content

Commit

Permalink
optimize when we run the commit logic, no use starting, commit transa…
Browse files Browse the repository at this point in the history
…ction that we do not use
  • Loading branch information
vangheem committed Mar 21, 2018
1 parent 7c52fcd commit 454f4fe
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.rst
@@ -1,7 +1,8 @@
2.5.7 (unreleased)
------------------

- Nothing changed yet.
- Only do commit and voting if we have objects to do it with
[vangheem]


2.5.6 (2018-03-21)
Expand Down
5 changes: 4 additions & 1 deletion guillotina/db/storages/pg.py
Expand Up @@ -691,6 +691,8 @@ async def start_transaction(self, txn, retries=0):

async def get_conflicts(self, txn):
async with self._lock:
if len(txn.modified) == 0:
return []
# use storage lock instead of transaction lock
if len(txn.modified) < 1000:
# if it's too large, we're not going to check on object ids
Expand All @@ -704,7 +706,8 @@ async def commit(self, transaction):
if transaction._db_txn is not None:
async with transaction._lock:
await transaction._db_txn.commit()
elif self._transaction_strategy not in ('none', 'tidonly'):
elif (self._transaction_strategy not in ('none', 'tidonly') and
not transaction._skip_commit):
log.warning('Do not have db transaction to commit')
return transaction._tid

Expand Down
12 changes: 9 additions & 3 deletions guillotina/db/transaction.py
Expand Up @@ -74,6 +74,7 @@ async def _wrapper(self, *args, **kwargs):
@implementer(ITransaction)
class Transaction(object):
_status = 'empty'
_skip_commit = False

def __init__(self, manager, request=None, loop=None):
self._txn_time = None
Expand Down Expand Up @@ -310,9 +311,14 @@ async def _commit(self):
await self._call_before_commit_hooks()
self.status = Status.COMMITTING
try:
await self.tpc_commit()
# vote will do conflict resolution if there are conflicting writes
await self.tpc_vote()
if len(self.modified) > 0 or len(self.deleted) > 0 or len(self.added) > 0:
# only do the commit steps if we have objects to commit
await self.tpc_commit()
# vote will do conflict resolution if there are conflicting writes
await self.tpc_vote()
else:
# signal to not worry about not making a transaction here..
self._skip_commit = True
await self.tpc_finish()
except (ConflictError, TIDConflictError) as ex:
# this exception should bubble up
Expand Down

0 comments on commit 454f4fe

Please sign in to comment.