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

Refactor the object cache to better account for race conditions #13204

Closed
wants to merge 12 commits into from

Commits on Jul 4, 2023

  1. Ruby: Refactor the object cache to better account for race conditions

    Superseeds: protocolbuffers#13054
    
    The object cache is fundamentally subject to race conditions.
    Objects must be created before they are registered into the cache,
    so if two threads try to create the same object, we'll inevitably
    end up with two instances mapping to the same underlying memory.
    
    To entirely prevent that we'd need a lot of extra locking which
    I don't think is really worth it compared to a few useless allocations.
    
    Instead we can replace `ObjectCache_Add` by a `getset` type of operation,
    the extra instance is still created, but the later threads will receive
    the "canonical" instance and will be able to abandon their duplicated
    instance.
    
    Additionally, this PR moves the ObjectCache implementation in Ruby,
    as it's much easier to debug there, and the performance difference
    is negligible. The `ObjectCache` instance is also exposed as
    `Google::Protobuf::OBJECT_CACHE` to better allow to debug
    potential memory issues.
    byroot authored and fowles committed Jul 4, 2023
    Configuration menu
    Copy the full SHA
    83942c1 View commit details
    Browse the repository at this point in the history
  2. ignore twiddle files

    fowles committed Jul 4, 2023
    Configuration menu
    Copy the full SHA
    a7fcb44 View commit details
    Browse the repository at this point in the history
  3. add extra asserts

    fowles committed Jul 4, 2023
    Configuration menu
    Copy the full SHA
    ee7a450 View commit details
    Browse the repository at this point in the history

Commits on Jul 5, 2023

  1. Configuration menu
    Copy the full SHA
    c55775b View commit details
    Browse the repository at this point in the history
  2. mark purge private

    fowles committed Jul 5, 2023
    Configuration menu
    Copy the full SHA
    3f82dfe View commit details
    Browse the repository at this point in the history
  3. rename getset to tryadd

    fowles committed Jul 5, 2023
    Configuration menu
    Copy the full SHA
    999ab1a View commit details
    Browse the repository at this point in the history

Commits on Jul 7, 2023

  1. Configuration menu
    Copy the full SHA
    e40194c View commit details
    Browse the repository at this point in the history
  2. Merge pull request #1 from JasonLunn/for_kfm

    Add unit tests for ObjectCache.
    fowles committed Jul 7, 2023
    Configuration menu
    Copy the full SHA
    637ffdb View commit details
    Browse the repository at this point in the history

Commits on Jul 8, 2023

  1. Configuration menu
    Copy the full SHA
    3b5b751 View commit details
    Browse the repository at this point in the history
  2. Improve test

    - hit multiple keys
    - disable on jruby
    fowles committed Jul 8, 2023
    Configuration menu
    Copy the full SHA
    4867e20 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    19f6d4b View commit details
    Browse the repository at this point in the history
  4. disable all tests on jruby

    fowles committed Jul 8, 2023
    Configuration menu
    Copy the full SHA
    9b6aad6 View commit details
    Browse the repository at this point in the history