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

A PR for reactive streams support #151

Merged
merged 41 commits into from
May 27, 2024
Merged

A PR for reactive streams support #151

merged 41 commits into from
May 27, 2024

Commits on May 12, 2024

  1. Add a proof-of-concept for "Observer-like" batch loading

    **Note**: This commit, as-is, is not (yet) intended for merge. It is
    created to provide a proof-of-concept and gauge interest as
    polishing/testing this requires a non-trivial amount of effort.
    
    Motivation
    ==========
    
    The current DataLoader mechanism completes the corresponding
    `CompletableFuture` for a given key when the corresponding value is
    returned. However, DataLoader's `BatchLoader` assumes that the
    underlying batch function can only return all of its requested items at
    once (as an example, a SQL database query).
    
    However, the batch function may be a service that can return items
    progressively using a subscription-like architecture. Some examples
    include:
    
     - Project Reactor's [Subscriber](https://www.reactive-streams.org/reactive-streams-1.0.4-javadoc/org/reactivestreams/Subscriber.html).
     - gRPC's [StreamObserver](https://grpc.github.io/grpc-java/javadoc/io/grpc/stub/StreamObserver.html).
     - RX Java's [Flowable](https://reactivex.io/RxJava/3.x/javadoc/io/reactivex/rxjava3/core/Flowable.html).
    
    Streaming results in this fashion offers several advantages:
    
     - Certain values may be returned earlier than others (for example, the
       batch function may have cached values it can return early).
     - Memory load is lessened on the batch function (which may be an
       external service), as it does not need to keep hold of the retrieved
       values before it can send them out at once.
     - We are able to save the need to stream individual error values by
       providing an `onError` function to terminate the stream early.
    
    Proposal
    ========
    
    We provide two new `BatchLoader`s and support for them in
    `java-dataloader`:
    
     - `ObserverBatchLoader`, with a load function that accepts:
       - a list of keys.
       - a `BatchObserver` intended as a delegate for publisher-like
         structures found in Project Reactor and Rx Java. This obviates the
         need to depend on external libraries.
     - `MappedObserverBatchLoader`, similar to `ObserverBatchLoader` but
       with an `onNext` that accepts a key _and_ value (to allow for early
       termination of streams without needing to process `null`s).
     - `*WithContext` variants for the above.
    
    The key value-add is that the implementation of `BatchObserver`
    (provided to the load functions) will immediately complete the queued
    future for a given key when `onNext` is called with a value. This means
    that if we have a batch function that can deliver values progressively,
    we can continue evaluating the query as the values arrive. As an
    arbitrary example, let's have a batch function that serves both the
    reporter and project fields on a Jira issue:
    
    ```graphql
    query {
      issue {
        project {
          issueTypes { ... }
        }
        reporter { ... }
      }
    }
    ```
    
    If the batch function can return a `project` immediately but is delayed
    in when it can `reporter`, then our batch loader can return `project`
    and start evaluating the `issueTypes` immediately while we load the
    `reporter` in parallel. This would provide a more performant query
    evaluation.
    
    As mentioned above, this is not in a state to be merged - this is
    intended to gauge whether this is something the maintainers would be
    interested in owning. Should this be the case, the author is willing to
    test/polish this pull request so that it may be merged.
    AlexandreCarlton committed May 12, 2024
    Configuration menu
    Copy the full SHA
    6e30220 View commit details
    Browse the repository at this point in the history

Commits on May 17, 2024

  1. Configuration menu
    Copy the full SHA
    95540ff View commit details
    Browse the repository at this point in the history
  2. Merge remote-tracking branch 'origin/master' into reactive-streams-br…

    …anch
    
    # Conflicts:
    #	build.gradle
    bbakerman committed May 17, 2024
    Configuration menu
    Copy the full SHA
    2cdba8a View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    1d78255 View commit details
    Browse the repository at this point in the history

Commits on May 18, 2024

  1. Merge remote-tracking branch 'origin/master' into observer-batch-load…

    …er-proof-of-concept
    
    * origin/master:
      Bump to Java 11
    AlexandreCarlton committed May 18, 2024
    Configuration menu
    Copy the full SHA
    2032e33 View commit details
    Browse the repository at this point in the history
  2. Eliminate *BatchObserver in favour of Publisher

    `reactive-streams` has become the de-facto standard for reactive
    frameworks; we thus use this as a base to allow seamless interop (rather
    than prompt an extra adapter layer).
    AlexandreCarlton committed May 18, 2024
    Configuration menu
    Copy the full SHA
    6b5a732 View commit details
    Browse the repository at this point in the history
  3. Use internal Assertions over Java's raw assert

    This gives us more workable exceptions.
    AlexandreCarlton committed May 18, 2024
    Configuration menu
    Copy the full SHA
    68d7f54 View commit details
    Browse the repository at this point in the history
  4. Remove handling of Throwable passed into onNext

    Passing an exception into `onNext` is not typically done in
    reactive-land - we would instead call `onError(Throwable)`. We can thus
    avoid handling this case.
    AlexandreCarlton committed May 18, 2024
    Configuration menu
    Copy the full SHA
    a3132b7 View commit details
    Browse the repository at this point in the history
  5. Expose new*DataLoader methods for *PublisherBatchLoader

    This is keeping in line with the other methods found in
    `DataLoaderFactory`.
    AlexandreCarlton committed May 18, 2024
    Configuration menu
    Copy the full SHA
    fbeffae View commit details
    Browse the repository at this point in the history
  6. Copy/tweak original/ DataLoader tests for publisher equivalents

    Given the large number of existing tests, we copy across this existing
    set for our publisher tests.
    
    What this really indicates is that we should invest in parameterised
    testing, but this is a bit painful in JUnit 4 - so we'll bump to JUnit 5
    independently and parameterise when we have this available.
    
    This is important because re-using the existing test suite reveals a
    failure that we'll need to address.
    AlexandreCarlton committed May 18, 2024
    Configuration menu
    Copy the full SHA
    b2a662d View commit details
    Browse the repository at this point in the history
  7. Rename '*PublisherBatchLoader' to 'BatchPublisher'

    This keeps in line with the original suggestion (because yours truly
    couldn't read, apparently).
    
    We also purge any remaining mention of 'observer', which was the first
    swing at this code.
    AlexandreCarlton committed May 18, 2024
    Configuration menu
    Copy the full SHA
    0d0b2f8 View commit details
    Browse the repository at this point in the history
  8. Ensure DataLoaderSubscriber is only called by one thread

    Multiple threads may call `onNext` - we thus (lazily) chuck a
    `synchronized` to ensure correctness at the cost of speed.
    
    In future, we should examine how we should manage this concurrency
    better.
    AlexandreCarlton committed May 18, 2024
    Configuration menu
    Copy the full SHA
    14002f6 View commit details
    Browse the repository at this point in the history
  9. Configuration menu
    Copy the full SHA
    0f303a8 View commit details
    Browse the repository at this point in the history

Commits on May 19, 2024

  1. Configuration menu
    Copy the full SHA
    ce115fd View commit details
    Browse the repository at this point in the history
  2. Merge pull request #148 from AlexandreCarlton/observer-batch-loader-p…

    …roof-of-concept
    
    Add a proof-of-concept for "Observer-like" batch loading
    bbakerman authored May 19, 2024
    Configuration menu
    Copy the full SHA
    288be41 View commit details
    Browse the repository at this point in the history

Commits on May 20, 2024

  1. Merge remote-tracking branch 'origin/master' into reactive-streams-br…

    …anch
    
    # Conflicts:
    #	build.gradle
    bbakerman committed May 20, 2024
    Configuration menu
    Copy the full SHA
    e16fa65 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    a93112a View commit details
    Browse the repository at this point in the history

Commits on May 21, 2024

  1. Configuration menu
    Copy the full SHA
    74567fe View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    4396624 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    8a64483 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    3e8ac9c View commit details
    Browse the repository at this point in the history
  5. Inline BatchPublisher tests into DataLoaderTest

    We now have the same coverage but with less code. Note that:
    
     - this is currently failing on 'duplicate keys when caching disabled'.
     - we still need to add tests that only make sense for the Publisher
       variants (e.g. half-completed keys).
    AlexandreCarlton committed May 21, 2024
    Configuration menu
    Copy the full SHA
    eb2b40c View commit details
    Browse the repository at this point in the history
  6. Fix MappedBatchPublisher loaders to work without cache

    If we did not cache the futures, then the MappedBatchPublisher
    DataLoader would not work as we were only completing the last future for
    a given key.
    AlexandreCarlton committed May 21, 2024
    Configuration menu
    Copy the full SHA
    651e561 View commit details
    Browse the repository at this point in the history

Commits on May 22, 2024

  1. Merge pull request #155 from AlexandreCarlton/migrate-publisher-tests

    Migrate publisher tests
    bbakerman authored May 22, 2024
    Configuration menu
    Copy the full SHA
    8295396 View commit details
    Browse the repository at this point in the history
  2. Merge remote-tracking branch 'origin/reactive-streams-branch' into re…

    …active-streams-common-publisher-impl
    
    # Conflicts:
    #	src/main/java/org/dataloader/DataLoaderHelper.java
    #	src/test/java/org/dataloader/DataLoaderBatchPublisherTest.java
    #	src/test/java/org/dataloader/DataLoaderMappedBatchPublisherTest.java
    bbakerman committed May 22, 2024
    Configuration menu
    Copy the full SHA
    86ec5c8 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    6d3c4eb View commit details
    Browse the repository at this point in the history
  4. Merge pull request #154 from graphql-java/reactive-streams-common-pub…

    …lisher-impl
    
    Making the Subscribers use a common base class
    bbakerman authored May 22, 2024
    Configuration menu
    Copy the full SHA
    3fddb8b View commit details
    Browse the repository at this point in the history
  5. More tests for Publishers

    bbakerman committed May 22, 2024
    Configuration menu
    Copy the full SHA
    034c68f View commit details
    Browse the repository at this point in the history

Commits on May 23, 2024

  1. Merge remote-tracking branch 'origin/master' into reactive-streams-br…

    …anch-extra-tests-for-reactive
    bbakerman committed May 23, 2024
    Configuration menu
    Copy the full SHA
    b09ac60 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    5d826b8 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    8b344db View commit details
    Browse the repository at this point in the history
  4. Merge pull request #158 from graphql-java/reactive-streams-branch-ext…

    …ra-tests-for-reactive
    
    More tests for Publishers on reactive branch
    bbakerman authored May 23, 2024
    Configuration menu
    Copy the full SHA
    e9bfc2b View commit details
    Browse the repository at this point in the history

Commits on May 24, 2024

  1. This moves the reactive code pout into its own package because DataLo…

    …aderHelper is way too big
    bbakerman committed May 24, 2024
    Configuration menu
    Copy the full SHA
    91d3036 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    e98621b View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    6523015 View commit details
    Browse the repository at this point in the history
  4. reorged method placement

    bbakerman committed May 24, 2024
    Configuration menu
    Copy the full SHA
    170ccf8 View commit details
    Browse the repository at this point in the history
  5. Merge pull request #159 from graphql-java/reactive-streams-branch-mov…

    …e-reactive-classes-out-of-dataloader-helper
    
    Reactive streams branch move reactive classes out of dataloader helper
    bbakerman authored May 24, 2024
    Configuration menu
    Copy the full SHA
    77fd0dd View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    4b9356e View commit details
    Browse the repository at this point in the history

Commits on May 26, 2024

  1. Have MappedBatchPublisher take in a Set<K> keys

    This is more symmetric with `MappedbatchLoader` and preserves
    efficiency; we do not need to emit a `Map.Entry` for duplicate keys
    (given the strong intention that this will be used to create a `Map`).
    AlexandreCarlton committed May 26, 2024
    Configuration menu
    Copy the full SHA
    3c3cc99 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    2e82858 View commit details
    Browse the repository at this point in the history
  3. Merge pull request #160 from AlexandreCarlton/add-documentation-for-p…

    …ublishers
    
    Have MappedBatchPublisher take in a Set<K> keys (and add README sections)
    bbakerman authored May 26, 2024
    Configuration menu
    Copy the full SHA
    c3e6ee5 View commit details
    Browse the repository at this point in the history