Skip to content
This repository has been archived by the owner on Sep 26, 2023. It is now read-only.

Bundling restructure #214

Closed

Conversation

michaelbausor
Copy link
Contributor

Updates bundling to accumulate requests in a request builder, rather than a list of requests. The major change is to introduce the Bundle interface and the BundleImpl class, which replaces a list of BundlingContext objects.

@codecov-io
Copy link

codecov-io commented Mar 1, 2017

Codecov Report

Merging #214 into master will increase coverage by 0.23%.
The diff coverage is 94.17%.

@@             Coverage Diff              @@
##             master     #214      +/-   ##
============================================
+ Coverage     70.25%   70.48%   +0.23%     
- Complexity      483      490       +7     
============================================
  Files            67       68       +1     
  Lines          2538     2558      +20     
  Branches        266      264       -2     
============================================
+ Hits           1783     1803      +20     
+ Misses          657      656       -1     
- Partials         98       99       +1
Impacted Files Coverage Δ Complexity Δ
...e/api/gax/bundling/AccumulatingBundleReceiver.java 83.33% <100%> (ø) 3 <1> (ø)
.../com/google/api/gax/bundling/ThresholdBundler.java 96.55% <100%> (-0.03%) 27 <0> (-1)
...n/java/com/google/api/gax/grpc/BundleExecutor.java 100% <100%> (ø) 4 <1> (-2)
...java/com/google/api/gax/grpc/BundlingCallable.java 88.88% <100%> (ø) 3 <0> (ø)
.../com/google/api/gax/grpc/BundledRequestIssuer.java 78.94% <75%> (ø) 6 <2> (?)
...e/api/gax/bundling/ThresholdBundlingForwarder.java 87.5% <83.33%> (ø) 4 <0> (ø)
...n/java/com/google/api/gax/grpc/BundlerFactory.java 81.25% <83.33%> (+0.92%) 12 <9> (+1)
.../main/java/com/google/api/gax/grpc/BundleImpl.java 96.66% <96.66%> (ø) 10 <10> (?)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ec2e656...d449bf3. Read the comment docs.

Copy link
Contributor

@pongad pongad left a comment

Choose a reason for hiding this comment

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

I have a few comments but looks good in general.

I earlier sent a WIP PR to change ThresholdBundlingForwarder from pulling to pushing logic. With this change, that PR becomes much less important. I still think it's valuable because it lets us avoid manual thread-synchronization. If we want the change, I think it should land after this change but before more work on logging flush. WDYT?

@@ -1,5 +1,5 @@
/*
* Copyright 2016, Google Inc. All rights reserved.
* Copyright 2017, Google Inc. All rights reserved.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

package com.google.api.gax.bundling;

public interface BundleFactory<T> {
T createBundle();

This comment was marked as spam.

This comment was marked as spam.


private final Lock lock = new ReentrantLock();
private final Condition bundleCondition = lock.newCondition();
private Bundle currentOpenBundle;
private List<Bundle> closedBundles = new ArrayList<>();
private TrackedBundle currentOpenTrackedBundle;

This comment was marked as spam.

This comment was marked as spam.

final Lock lock = this.lock;
lock.lock();
try {
Bundle outBundle = null;
E outBundle = null;
if (closedBundles.size() > 0) {
outBundle = closedBundles.remove(0);

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

Copy link
Contributor Author

@michaelbausor michaelbausor left a comment

Choose a reason for hiding this comment

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

I agree that we still want the change to a pushing bundler, and that it makes sense to do it before any more work on logging flush.

@@ -1,5 +1,5 @@
/*
* Copyright 2016, Google Inc. All rights reserved.
* Copyright 2017, Google Inc. All rights reserved.

This comment was marked as spam.

package com.google.api.gax.bundling;

public interface BundleFactory<T> {
T createBundle();

This comment was marked as spam.

final Lock lock = this.lock;
lock.lock();
try {
Bundle outBundle = null;
E outBundle = null;
if (closedBundles.size() > 0) {
outBundle = closedBundles.remove(0);

This comment was marked as spam.

*/
void setResponse(ResponseT response);
public interface Bundle<T> {
void merge(T t);

This comment was marked as spam.

This comment was marked as spam.

*/
void processBundle(List<T> bundle);
/** Process the given bundle. */
void processBundle(T bundle);

This comment was marked as spam.

This comment was marked as spam.

* referenced is still the active one.
*/
private class Bundle {
private class TrackedBundle {

This comment was marked as spam.

This comment was marked as spam.


private final Lock lock = new ReentrantLock();
private final Condition bundleCondition = lock.newCondition();
private Bundle currentOpenBundle;
private List<Bundle> closedBundles = new ArrayList<>();
private TrackedBundle currentOpenTrackedBundle;

This comment was marked as spam.

This comment was marked as spam.


private ImmutableList<BundlingThreshold<E>> thresholdPrototypes;
private final Duration maxDelay;
private final BundlingFlowController<E> flowController;
private final BundleSupplier<E> bundleFactory;

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

@@ -182,56 +189,48 @@ public void flush() {
*
* @return the number of items added to 'bundle'.
*/
public int drainNextBundleTo(Collection<? super E> outputCollection) {
public E takeBundle() {

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

import java.util.ArrayList;
import java.util.List;

public class BundleImpl<RequestT, ResponseT> implements Bundle<BundleImpl<RequestT, ResponseT>> {

This comment was marked as spam.

This comment was marked as spam.

Copy link
Contributor Author

@michaelbausor michaelbausor left a comment

Choose a reason for hiding this comment

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

Addressed PR feedback. I have pushed here to help the review process, but I will be closing this PR and reopening against https://github.com/googleapis/gax-java/tree/bundling-flowcontrol-branch

*/
void setResponse(ResponseT response);
public interface Bundle<T> {
void merge(T t);

This comment was marked as spam.

*/
void processBundle(List<T> bundle);
/** Process the given bundle. */
void processBundle(T bundle);

This comment was marked as spam.


private ImmutableList<BundlingThreshold<E>> thresholdPrototypes;
private final Duration maxDelay;
private final BundlingFlowController<E> flowController;
private final BundleSupplier<E> bundleFactory;

This comment was marked as spam.


private final Lock lock = new ReentrantLock();
private final Condition bundleCondition = lock.newCondition();
private Bundle currentOpenBundle;
private List<Bundle> closedBundles = new ArrayList<>();
private TrackedBundle currentOpenTrackedBundle;

This comment was marked as spam.

@@ -182,56 +189,48 @@ public void flush() {
*
* @return the number of items added to 'bundle'.
*/
public int drainNextBundleTo(Collection<? super E> outputCollection) {
public E takeBundle() {

This comment was marked as spam.

* referenced is still the active one.
*/
private class Bundle {
private class TrackedBundle {

This comment was marked as spam.

import java.util.ArrayList;
import java.util.List;

public class BundleImpl<RequestT, ResponseT> implements Bundle<BundleImpl<RequestT, ResponseT>> {

This comment was marked as spam.

@michaelbausor
Copy link
Contributor Author

Replacement PR: #226

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants