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 DynamoDBLeaseTaker logging of available leases #846

Merged
merged 1 commit into from
Oct 4, 2021

Conversation

rtyley
Copy link
Contributor

@rtyley rtyley commented Aug 6, 2021

When DynamoDBLeaseTaker is deciding what leases to take to satisfy the target lease-count of it's worker, it can take either expired leases that haven't been updated by any other worker for a while, or failing that, 'steal' a limited number (by default, 1) of leases from other workers, in order to ensure its worker is gradually getting closer to its target number.

It turns out that the log message it prints out when taking expired leases is misleading. For instance, in this message - the leases weren't stolen, they were taken from the available 'expired' leases:

Worker xxxxxx saw 68 total leases, 0 available leases, 6 workers. Target is 12 leases, I have 2 leases, I will take 10 leases

...yet the message says there were 0 available leases, so how is that possible? The truth is, there were 10 available expired leases, but the log message was printing out the value of expiredLeases.size() - and expiredLeases was mutated over the course of the method, with entries removed and added to leasesToTake:

The fix to logging in this commit just records numAvailableLeases at the start of the method, so we can give an accurate log message:

Worker xxxxxx saw 68 total leases, 10 available leases, 6 workers. Target is 12 leases, I have 2 leases, I will take 10 leases

While I was investigating #845 I found the broken log messaging quite confusing!

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@rtyley rtyley changed the title Fix DynamoDBLeaseTaker logging of available leases Fix DynamoDBLeaseTaker logging of available leases Aug 6, 2021
@rtyley rtyley force-pushed the fix-logging-of-available-leases branch from 5542a7b to cc6a370 Compare August 6, 2021 21:44
@rtyley
Copy link
Contributor Author

rtyley commented Aug 6, 2021

Although the Travis CI build is failing for this small change, it looks like this is probably due to some kind of flakiness in the build, rather than a problem with the PR:

https://github.com/awslabs/amazon-kinesis-client/pull/846/checks?check_run_id=3266235711

image

When `DynamoDBLeaseTaker` is deciding what leases to take to satisfy the
target lease-count of it's worker, it can either take *expired* leases
that haven't been updated by any other worker for a while, or failing
that, 'steal' a limited number (by default, 1) of leases from other
workers, in order to ensure its worker is gradually getting closer to
it's target.

It turns out that the log message it prints out when taking expired
leases is misleading. For instance, in this message - the leases
weren't stolen, they were taken from the available 'expired' leases:

```
Worker xxxxxx saw 68 total leases, 0 available leases, 6 workers. Target is 12 leases, I have 2 leases, I will take 10 leases
```

...yet the message says there were 0 available leases, so how is that
possible? The truth is, there were 10 available expired leases, but the
log message was printing out the value of `expiredLeases.size()` - and
`expiredLeases` has been mutated over the course of the method, with
entries removed and added to `leasesToTake`:

https://github.com/awslabs/amazon-kinesis-client/blob/0c5042dadf794fe988438436252a5a8fe70b6b0b/amazon-kinesis-client/src/main/java/software/amazon/kinesis/leases/dynamodb/DynamoDBLeaseTaker.java#L421

The fix to logging in this commit just records `numAvailableLeases` at
the start of the method, so we can give an accurate log message:

```
Worker xxxxxx saw 68 total leases, 10 available leases, 6 workers. Target is 12 leases, I have 2 leases, I will take 10 leases
```
@joshua-kim
Copy link
Contributor

LGTM. Thanks for the fix.

@joshua-kim joshua-kim merged commit 2447513 into awslabs:master Oct 4, 2021
@shanmsac shanmsac added this to the v2.3.7 milestone Oct 11, 2021
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.

3 participants