Uploaded image for project: 'Ruby Driver'
  1. Ruby Driver
  2. RUBY-2130

Move query cache implementation from Mongoid into driver

    • Done
    • Driver Query Cache
    • Hide

      Engineer(s): Grace Chong (intern), Emily Giurleo
      Summary: To allow Ruby applications using Mongoid to utilize modern retryable reads when they also want to utilize the query cache, the query cache implementation must be moved to the driver from Mongoid where it presently exists.

      2020-09-22: Updating end date to 2020-09-25 (9 weeks)

      • Updating end date by one week as the effort required to support Coinbase’s use of the existing Query Cache implementation in Mongoid waylaid our core progress on the epic. Emily has completed this effort and all changes have been backported to version 6.4.
      • Since the last update, in addition to closing out the Coinbase support issues, Emily has implemented many of the query cache improvements in the driver (such as allowing cursor to cache multi-batch queries).
      • We anticipate finishing this project this week - Emily is currently finishing the final implementation ticket (which is to improve the efficiency of invalidating the cache) and then there are a handful of straightforward documentation tickets to close out.

      2020-09-08: Updating end date to 2020-09-18 (8 weeks)

      • Updating end date to reflect additional work Emily has taken on to support Coinbase’s use of the existing Query Cache implementation in Mongoid. They’ve asked us to backport some of the changes we’re currently making to the new query cache into the old version so they can continue to use it. The old query cache is much more brittle, so working around this is inflating the amount of time and effort we’d initially anticipated needing for implementing the new version.
      • Since the last update, Emily has made changes to the driver query cache fixing a bug where the same multi-batch query cannot be performed more than once, and has added functionality where the driver considers the client readPreference and readConcern when deciding whether to use a cached cursor.
      • The goals for the upcoming weeks are to wrap up the work for Coinbase, which involves resolving a query cache related sessions leak (work is done, just trying to fix the jruby tests), and to backport the fix for the aforementioned bug with performing the same multi-batch query twice. Once that’s done, the goal is to complete the remainder of the work on the new query cache.

      2020-08-25: Updating end date to 2020-09-11 (7 weeks)

      • Moving out the end date by one week to account for the long weekend for Labor Day.
      • Emily has written a new scope for the remaining work (https://tinyurl.com/y5cnuuue)
      • Emily has also begun executing on the first few tickets to fix a bug that was brought over from the Mongoid Query Cache implementation.
      • In the coming weeks Emily plans to address the work outlined in the scope, first addressing bugs (including ensuring the query cache accounts for readPreference and readConcern), and then moving on to new functionality and improvements.

      2020-08-07: Maintaining end date to 2020-09-04 (6 weeks)

      • Grace has completed all the work in this epic that we'd scoped to the timespan of her internship. This includes implementing the query cache and caching cursor in the Ruby driver and utilizing the driver's query cache implementation in Mongoid.
      • Custom cursor in Mongoid is no longer used, though still available for users on older versions of the Ruby driver. The custom cursor will be dropped entirely when we no longer support those older Ruby driver versions.
      • Emily will be taking up the rest of this work and needs to do some scoping and research before continuing to proceed on implementation, however we are generally feeling good about the Sept 4th end date barring any major unexpected discoveries during her research.

      2020-07-24: Setting initial target date to 2020-09-04 (6 weeks)

      • This is the intern project that Grace Chong will be working on for the duration of the internship, ending Aug 7.
      • Grace has been picking up tickets and is making good progress.
      • We expect that there will be some continuing work after the internship ends. We think it should take about 2-3 more weeks after the internship ends, so setting initial end date to Sep 4 to accommodate the long-tail of the estimate and also stay in sync with the two week cadence policy.

      Show
      Engineer(s): Grace Chong (intern), Emily Giurleo Summary: To allow Ruby applications using Mongoid to utilize modern retryable reads when they also want to utilize the query cache, the query cache implementation must be moved to the driver from Mongoid where it presently exists. 2020-09-22: Updating end date to 2020-09-25 (9 weeks) Updating end date by one week as the effort required to support Coinbase’s use of the existing Query Cache implementation in Mongoid waylaid our core progress on the epic. Emily has completed this effort and all changes have been backported to version 6.4. Since the last update, in addition to closing out the Coinbase support issues, Emily has implemented many of the query cache improvements in the driver (such as allowing cursor to cache multi-batch queries). We anticipate finishing this project this week - Emily is currently finishing the final implementation ticket (which is to improve the efficiency of invalidating the cache) and then there are a handful of straightforward documentation tickets to close out. 2020-09-08: Updating end date to 2020-09-18 (8 weeks) Updating end date to reflect additional work Emily has taken on to support Coinbase’s use of the existing Query Cache implementation in Mongoid. They’ve asked us to backport some of the changes we’re currently making to the new query cache into the old version so they can continue to use it. The old query cache is much more brittle, so working around this is inflating the amount of time and effort we’d initially anticipated needing for implementing the new version. Since the last update, Emily has made changes to the driver query cache fixing a bug where the same multi-batch query cannot be performed more than once, and has added functionality where the driver considers the client readPreference and readConcern when deciding whether to use a cached cursor. The goals for the upcoming weeks are to wrap up the work for Coinbase, which involves resolving a query cache related sessions leak (work is done, just trying to fix the jruby tests), and to backport the fix for the aforementioned bug with performing the same multi-batch query twice. Once that’s done, the goal is to complete the remainder of the work on the new query cache. 2020-08-25: Updating end date to 2020-09-11 (7 weeks) Moving out the end date by one week to account for the long weekend for Labor Day. Emily has written a new scope for the remaining work ( https://tinyurl.com/y5cnuuue ) Emily has also begun executing on the first few tickets to fix a bug that was brought over from the Mongoid Query Cache implementation. In the coming weeks Emily plans to address the work outlined in the scope, first addressing bugs (including ensuring the query cache accounts for readPreference and readConcern), and then moving on to new functionality and improvements. 2020-08-07: Maintaining end date to 2020-09-04 (6 weeks) Grace has completed all the work in this epic that we'd scoped to the timespan of her internship. This includes implementing the query cache and caching cursor in the Ruby driver and utilizing the driver's query cache implementation in Mongoid. Custom cursor in Mongoid is no longer used, though still available for users on older versions of the Ruby driver. The custom cursor will be dropped entirely when we no longer support those older Ruby driver versions. Emily will be taking up the rest of this work and needs to do some scoping and research before continuing to proceed on implementation, however we are generally feeling good about the Sept 4th end date barring any major unexpected discoveries during her research. 2020-07-24: Setting initial target date to 2020-09-04 (6 weeks) This is the intern project that Grace Chong will be working on for the duration of the internship, ending Aug 7. Grace has been picking up tickets and is making good progress. We expect that there will be some continuing work after the internship ends. We think it should take about 2-3 more weeks after the internship ends, so setting initial end date to Sep 4 to accommodate the long-tail of the estimate and also stay in sync with the two week cadence policy.

      Epic Summary

      Summary

      To allow Ruby applications using Mongoid to utilize modern retryable reads when they also want to utilize the query cache, the query cache implementation must be moved to the driver from Mongoid where it presently exists.

      The work to be done is as follows:

      1. Implement caching cursor in driver, using the current caching cursor in Mongoid as reference.
      2. Implement query cache (on top of the caching cursor) in driver, using the respective code in Mongoid as reference.
      3. Remove all cursor code from Mongoid.
      4. Modify Mongoid to use the driver's query cache while providing an equivalent or similar API to what is available today.

      A side benefit of this work is the potential to use query cache with the driver only, to cache individual (MQL) queries.

      Motivation

      Currently the query cache, as implemented by Mongoid, duplicates a portion of driver's cursor code plus adds the query caching on top. This has two issues:

      1. The code that was copied is by now outdated. It uses legacy read retries (even when modern read retries are supposed to be used), performs server selection in an outdated way, etc.
      2. Changes to the driver can break the query cache, due to the query cache's reliance on driver internals.

      Since the query cache operates on collection/operation/cursor level, it can be implemented in the driver, with Mongoid only exposing the implementation using a (more) convenient API.

      Cast of Characters

      • Product Owner: Rachelle Palmer
      • Project Lead: Emily Guirleo
      • Program Manager: Alexander Golin

      Documentation

      Scope Document
      [Technical Design Document|]

            Assignee:
            emily.giurleo@mongodb.com Emily Giurleo (Inactive)
            Reporter:
            oleg.pudeyev@mongodb.com Oleg Pudeyev (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:
              8 weeks, 4 days