Giter VIP home page Giter VIP logo

Comments (3)

artembilan avatar artembilan commented on August 27, 2024 1

I also find this logic as a bit odd: we don't check existing lock status on the first iteration and we may not pass this condition:

if (LockClientUtils.INSTANCE.millisecondTime() - currentTimeMillis > millisecondsToWait) {
          throw new LockNotGrantedException("Didn't acquire lock after sleeping for " + (LockClientUtils.INSTANCE.millisecondTime() - currentTimeMillis) + " milliseconds");
}

To go to the Thread.sleep(refreshPeriodInMilliseconds); and to the second iteration.
The millisecondsToWait might be small enough and DynamoDB request might be long enough do not let us to overcome that condition.
Therefore it would be great to check an expiration status on existing lock even from the first iteration. We definitely might even not need extra iteration and that unnecessary sleep in between.

Also the current logic doesn't meet boolean tryLock(long time, TimeUnit unit) throws InterruptedException; contract.
I may agree about some timeout approximation during request to the DB and back, but there is definitely no any reason for me to wait for the lock more than tryLock() requests from me.

Originally I did a mistake like:

long timeToWaitForLock = System.currentTimeMillis() - start + TimeUnit.MILLISECONDS.convert(time, unit) - DynamoDbLockRegistry.this.leaseDuration;

this.acquireLockOptionsBuilder
			.withAdditionalTimeToWaitForLock(timeToWaitForLock)
			.withRefreshPeriod(0);

I'm really not interested to wait for the leaseDuration (remember: tryLock() contract ?), so i decided to minus it, but I missed the fact that you don't check status on the first iteration, therefore I failed to meet a condition for the second iteration.

Anyway, independently of my misinterpretation, there is that flaw, when we always fail with the condition because a millisecondsToWait is so small in comparison with the request time, that we never know an existing lock state.

Thanks

from amazon-dynamodb-lock-client.

softwareengineerprogrammer avatar softwareengineerprogrammer commented on August 27, 2024

Yeah, I don't get this either. I wound up having to write my own locking library because this issue prevents usage in Lambda where the lease duration is a significant percentage of the Lambda timeout.

from amazon-dynamodb-lock-client.

amcp avatar amcp commented on August 27, 2024

@jazir1979 @artembilan @softwareengineerprogrammer This issue is related and may be identical to #12 . Stay tuned, there will be an update to #12 very soon.

from amazon-dynamodb-lock-client.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.