Skip to content
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

Fix Lease release/acquire operation logic #1289

Merged
merged 4 commits into from Feb 8, 2023

Conversation

Arkatufus
Copy link
Contributor

@Arkatufus Arkatufus commented Feb 6, 2023

Posible Fix for #1251

Changes

  • Lease release op when lease not acquired is a no-op
  • Lease acquire when lease was being acquired returns idempotent operation task instead of timing out

* Lease release op when lease not acquired is a no-op
* Lease acquire when lease was not acquired returns idempotent operation task instead of timing out
return true;
case LeaseActor.InvalidReleaseRequest:
_log.Info("Tried to release a lease that is not acquired");
return true;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logically, since we didn't have the lease, we should return true.
This will cause the plugins to report that the lease have been successfully released, which can be confusing.
This is why the log should be emitted in info level so that we can track that the lease was "successfully released" because we didn't have it in the first place.

@@ -109,25 +120,59 @@ public override async Task<bool> Release()
public override Task<bool> Acquire()
=> Acquire(null);

public override async Task<bool> Acquire(Action<Exception?>? leaseLostCallback)
public override Task<bool> Acquire(Action<Exception?>? leaseLostCallback)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make this idempotent, we could not use async...await pattern

Copy link
Member

@Aaronontheweb Aaronontheweb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

{
if(_log.IsDebugEnabled)
_log.Debug("Lease is already being acquired");
return _acquireTask;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

case LeaseActor.LeaseReleased:
return true;
case LeaseActor.InvalidReleaseRequest:
_log.Info("Tried to release a lease that is not acquired");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd mark this as DEBUG

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it needs to be INFO because if its not, we could not debug if a lease was "released" because it was actually released or because we didn't have it in the first place

throw new LeaseTimeoutException(
$"Timed out trying to acquire lease [{_leaseName}, {_settings.OwnerName}]. It may still be taken.");
_acquireTask = _leaseActor.Ask(new LeaseActor.Acquire(leaseLostCallback), _timeout)
.ContinueWith(t =>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Aaronontheweb Aaronontheweb merged commit dcf6d81 into akkadotnet:dev Feb 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants