Skip to content

Commit

Permalink
Merge pull request #181 from openvstorage/0.1.x_transaction_keyerror
Browse files Browse the repository at this point in the history
Transactions are cleared from memory when the transaction succeed. Not during retry
  • Loading branch information
JeffreyDevloo authored Sep 13, 2018
2 parents 2ed6b14 + 487f17d commit dcfa82d
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions src/db/arakoon/pyrakoon/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,13 +281,13 @@ def delete(self, key, must_exist=True, transaction=None):
@locked()
@handle_arakoon_errors(is_read_only=False)
def delete_prefix(self, prefix, transaction=None):
# type: (str) -> None
# type: (str, Optional[str]) -> None
"""
Removes a given prefix from the store
:param prefix: Prefix of the key
:type prefix: str
:param transaction: Transaction to apply the update too
:type transaction: id
:type transaction: str
:return None
;:rtype: NoneType
"""
Expand Down Expand Up @@ -367,9 +367,8 @@ def begin_transaction(self):
return key

@locked()
@handle_arakoon_errors(is_read_only=False, max_duration=1)
def apply_transaction(self, transaction, delete=True):
# type: (str) -> None
# type: (str, Optional[bool]) -> None
"""
Applies a transaction
:param transaction: Identifier of the transaction
Expand All @@ -380,8 +379,21 @@ def apply_transaction(self, transaction, delete=True):
:return: None
:rtype: NoneType
"""
@handle_arakoon_errors(is_read_only=False, max_duration=1)
def apply_transaction(pyrakoon_client):
# type: (PyrakoonClient) -> None
"""
Decorated inner function. Used to shadow the name of the outer function so the decorator provides
useful logging
:param pyrakoon_client: The pyrakoon client to use. (Captured by the decorator. Cannot use self of outer scope)
:type pyrakoon_client: PyrakoonClient
:return: None
:rtype: NoneType
"""
pyrakoon_client._client.sequence(pyrakoon_client._sequences[transaction])

try:
return self._client.sequence(self._sequences[transaction])
return apply_transaction(self)
finally:
if delete:
self.delete_transaction(transaction)
Expand Down Expand Up @@ -450,17 +462,6 @@ def apply_callback_transaction(self, transaction_callback, max_retries=0, retry_
:return: None
:rtype: NoneType
"""
# Apply transaction will retry on itself when connection failures happened
# This callback function will retry on failures when the request was already sent
# The callback aspect is required to re-evaluate the transaction
@handle_arakoon_errors(is_read_only=False, max_duration=1, override_retry=True)
def apply_callback_transaction(self):
_ = self # Self is added for the decorator
# This inner function will execute the callback again on retry
transaction = transaction_callback()

self.apply_transaction(transaction)

def default_retry_wait(retry):
_ = retry
time.sleep(random.randint(0, 25) / 100.0)
Expand All @@ -471,7 +472,8 @@ def default_retry_wait(retry):
while success is False:
tries += 1
try:
return apply_callback_transaction(self)
transaction = transaction_callback() # type: str
return self.apply_transaction(transaction)
except ArakoonAssertionFailed as ex:
self._logger.warning('Asserting failed. Retrying {0} more times'.format(max_retries - tries))
last_exception = ex
Expand Down

0 comments on commit dcfa82d

Please sign in to comment.