-
Notifications
You must be signed in to change notification settings - Fork 55
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: abstract batch resource and add method to determine if batch should be flushed #1790
Conversation
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.
lgtm after comments are addressed
gax-java/gax/src/main/java/com/google/api/gax/batching/BatcherImpl.java
Outdated
Show resolved
Hide resolved
gax-java/gax/src/main/java/com/google/api/gax/batching/BatcherImpl.java
Outdated
Show resolved
Hide resolved
gax-java/gax/src/main/java/com/google/api/gax/batching/DefaultBatchResource.java
Show resolved
Hide resolved
gax-java/gax/src/main/java/com/google/api/gax/batching/DefaultBatchResource.java
Outdated
Show resolved
Hide resolved
gax-java/gax/src/main/java/com/google/api/gax/batching/DefaultBatchResource.java
Outdated
Show resolved
Hide resolved
gax-java/gax/src/main/java/com/google/api/gax/batching/DefaultBatchResource.java
Outdated
Show resolved
Hide resolved
@@ -96,4 +96,24 @@ public interface BatchingDescriptor<ElementT, ElementResultT, RequestT, Response | |||
|
|||
/** Returns the size of the passed element object in bytes. */ | |||
long countBytes(ElementT element); | |||
|
|||
/** Creates a new {@link BatchResource} with ElementT. */ | |||
default BatchResource createResource(ElementT element) { |
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.
Do we need this helper method in BatchingDescriptor
? I would prefer to call DefaultBatchResource.create(1, countBytes(element))
directly.
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.
Yes, in bigtable client we want to override the BatchResource implementation, so we don't want to create BatchResource directly in the BatcherImpl code.
} | ||
|
||
/** Create an empty {@link BatchResource}. */ | ||
default BatchResource createEmptyResource() { |
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.
Same comment for this method.
gax-java/gax/src/main/java/com/google/api/gax/batching/DefaultBatchResource.java
Outdated
Show resolved
Hide resolved
* batch needs to be flushed. | ||
*/ | ||
@InternalApi("For google-cloud-java client use only.") | ||
public interface BatchResource { |
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.
Do we have to create an interface for it? The default implementation looks like a POJO to me, I would prefer not to have a separate interface if we don't plan to have multiple implementations.
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.
bigtable client will need to override it and have a different implementation :(
gax-java/gax/src/main/java/com/google/api/gax/batching/BatchingDescriptor.java
Outdated
Show resolved
Hide resolved
gax-java/gax/src/main/java/com/google/api/gax/batching/BatcherImpl.java
Outdated
Show resolved
Hide resolved
[gapic-generator-java-root] Kudos, SonarCloud Quality Gate passed! |
[java_showcase_integration_tests] SonarCloud Quality Gate failed. 0 Bugs 0.0% Coverage Catch issues before they fail your Quality Gate with our IDE extension SonarLint |
[java_showcase_unit_tests] Kudos, SonarCloud Quality Gate passed! |
Abstract the element and byte counting to a
BatchResource
object so client libraries can add other dimensions to it. Also movedshouldBeFull
logic toBatchResource
so libraries can override it and use the other dimensions to determine if the batch should be flushed.