-
Notifications
You must be signed in to change notification settings - Fork 916
Fixed issue relating to cancelling scheduled flush and removing requests. #2636
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
Fixed issue relating to cancelling scheduled flush and removing requests. #2636
Conversation
…-explanatory. Also refactored sdk-core tests
…-response correlation checking
… need for requestBufferCopy
…g to IdentifiableRequest
…s null but was not very efficient)
…to use IdentifiableMessage
…synchronized block in batchBuffer
I forgot to sync my fork after the PR was approved so the number of commits in this PR is quite inflated. The changes since the last PR start with commit fcee2ad ("Removing isManual"). |
88a82e9
to
a7965d7
Compare
Code smells reported by sonarcloud mostly have to do with how I name some generics but those follow the style of the V2 SDK (ex. RequestT as opposed to just T). There is one major code smell for unused method parameters but this is because I am passing class types to the builder() method like what is done in the Waiters class. |
core/sdk-core/src/main/java/software/amazon/awssdk/core/internal/batchmanager/BatchBuffer.java
Outdated
Show resolved
Hide resolved
core/sdk-core/src/main/java/software/amazon/awssdk/core/internal/batchmanager/BatchBuffer.java
Outdated
Show resolved
Hide resolved
core/sdk-core/src/test/java/software/amazon/awssdk/core/BatchOverrideConfigurationTest.java
Show resolved
Hide resolved
...k-core/src/test/java/software/amazon/awssdk/core/internal/batchmanager/BatchManagerTest.java
Show resolved
Hide resolved
@@ -159,14 +157,31 @@ public void scheduleFiveMessagesWithEachThreadToDifferentDestinations() { | |||
checkThreadedResponses(requests, responses, sendRequestFutures); | |||
executorService.shutdownNow(); | |||
} | |||
|
|||
@Test | |||
public void periodicallySendMessagesWithTenThreadsToSameDestination() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What behavior is this test trying to verify?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might have been more of a debugging test to see how periodically sending requests would work (since it would involve a combination of scheduling and manually flushing the buffers).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, sounds like this is not needed here if it's only used for debugging purpose
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should I still include this test since no other test verifies how periodically sending requests might work with the BatchManager?
core/sdk-core/src/main/java/software/amazon/awssdk/core/internal/batchmanager/BatchManager.java
Outdated
Show resolved
Hide resolved
...src/test/java/software/amazon/awssdk/core/internal/batchmanager/IdentifiableMessageTest.java
Outdated
Show resolved
Hide resolved
core/sdk-core/src/main/java/software/amazon/awssdk/core/internal/batchmanager/BatchBuffer.java
Outdated
Show resolved
Hide resolved
core/sdk-core/src/main/java/software/amazon/awssdk/core/internal/batchmanager/BatchManager.java
Outdated
Show resolved
Hide resolved
4275334
to
3436043
Compare
Kudos, SonarCloud Quality Gate passed! |
Motivation and Context
Code from the last PR removed requests in a way that was very unintuitive and hacky. This PR attempts to solve that issue by not only making it more intuitive in how it removes requests, but hopefully also makes the removal of requests more thread safe.
Description
Originally, entries in the
BatchBuffer
were removed only when the entry's corresponding response was completed. Since a request and response were tied together in aBatchingExecutionContext
, this required some hacky manipulation of anAtomicInteger
(numRequests
) to prevent excessive and inefficient flushes triggered by buffer sizes greater than the configuredmaxBatchItems
. To fix this, requests are now removed when checking if a buffer can be flushed (look atcanManualFlush()
andcanScheduledFlush()
methods inBatchBuffer
). By putting these methods inside a flushLock as well, it removed the need for a separateCancellableFlush
andScheduledFlush
class since these synchronized blocks ensured that a manual flush could not occur while a scheduled flush had completed.Other changes in this PR involved refactoring the code and cleaning it up to make it more readable and intuitive. More unit tests were also added.
Testing
In addition to tests implemented in the last PR, more JUnit unit tests were added to test the functionality of the supplementary classes involved with BatchManager. This specifically involved tests for BatchUtils and the IdentifiableMessage class. An additional multi-threading unit test was also added to test how the BatchManager might operate when faced with a combination of scheduled and manual flushes.
Types of changes
Checklist
mvn install
succeedsLicense