Uploaded image for project: 'Infinispan'
  1. Infinispan
  2. ISPN-1115

Fine-grained AtomicMaps

This issue belongs to an archived project. You can view it, but you can't modify it. Learn more

    • Icon: Enhancement Enhancement
    • Resolution: Done
    • Icon: Blocker Blocker
    • 5.1.0.BETA3, 5.1.0.FINAL
    • None
    • Core
    • None
    • High

      Atomic Maps are locked by acquiring a single lock on the entire map and this causes concurrency issues for certain use cases. This JIRA is to allow for concurrent modifications of keys within the AtomicMap, provided the keys do not overlap.

      The design is as follows:

      • AtomicMapLookup gets a WL on the AtomicMap's key (AMK) when creating and removing a new AtomicMap
      • Modifications to the AtomicMap (which go through the AtomicMapProxy) do not acquire a WL on AMK. Instead,
      • AdvancedCache exposes a new API, applyDelta(K deltaAwareValueKey, Delta delta, Object... locksToAcquire)
      • AtomicMapProxy makes changes by calling applyDelta and passing in the key within the map that is being modified, along with the delta to apply.
      • The implementation could offer lock pooling to prevent a large number of locks being created for AtomicMaps with a large number of entries
      • On detecting concurrent deletion, updates would fail.

      This can then be used by other Delta/DeltaAware types in future as well, perhaps JSON documents, etc.

            [ISPN-1115] Fine-grained AtomicMaps

            manik_jira, I know you've been busy. Not a problem.

            Randall Hauch (Inactive) added a comment - manik_jira , I know you've been busy. Not a problem.

            @Randall I know I owe you comment on the Soft Schema patch - I'm getting to it, I promise!

            Manik Surtani (Inactive) added a comment - @Randall I know I owe you comment on the Soft Schema patch - I'm getting to it, I promise!

            Thanks for the clarification Randall, that was what I was looking for. I'll give it a look!

            Mircea Markus (Inactive) added a comment - Thanks for the clarification Randall, that was what I was looking for. I'll give it a look!

            Randall Hauch (Inactive) added a comment - - edited

            I've reused the DeltaAware functionality in my prototype for ISPN-1103, which has to do with a soft schema-based solution using JSON documents and JSON Schema documents. (The SchematicValue actually contains an in-memory representation of a JSON/BSON document, since storing a string would require parsing the string before use. These values are externalized using the BSON format.)

            Ideally the SchematicEntry (akin to AtomicMap) could use fine-grained locks on the individual fields (potentially in nested documents). However, we need a way to plug this 'custom' delta-aware value into Infinispan and it's fine-grained locking capability.

            Note that I've tried to follow the same pattern as AtomicMap (interface), AtomicHashMap (impl), AtomicMapDelta (Delta impl), and AtomicHashMapProxy (proxy that hides the delta and atomic-ness). See the branch for details.

            I am looking for feedback on ISPN-1103, so if interested please comment on that issue.

            Randall Hauch (Inactive) added a comment - - edited I've reused the DeltaAware functionality in my prototype for ISPN-1103 , which has to do with a soft schema-based solution using JSON documents and JSON Schema documents. (The SchematicValue actually contains an in-memory representation of a JSON/BSON document, since storing a string would require parsing the string before use. These values are externalized using the BSON format.) Ideally the SchematicEntry (akin to AtomicMap) could use fine-grained locks on the individual fields (potentially in nested documents). However, we need a way to plug this 'custom' delta-aware value into Infinispan and it's fine-grained locking capability. Note that I've tried to follow the same pattern as AtomicMap (interface), AtomicHashMap (impl), AtomicMapDelta (Delta impl), and AtomicHashMapProxy (proxy that hides the delta and atomic-ness). See the branch for details. I am looking for feedback on ISPN-1103 , so if interested please comment on that issue.

            Mircea Markus (Inactive) added a comment - - edited

            @Randhall @Vladimir if there are any other delta aware requirements it's fine by me. An example of a use case, besides fine grained maps, that requires delta aware would be very convincing for me

            Mircea Markus (Inactive) added a comment - - edited @Randhall @Vladimir if there are any other delta aware requirements it's fine by me. An example of a use case, besides fine grained maps, that requires delta aware would be very convincing for me

            I agree with Randall here and I do not see an alternate or even a better approach. Having applyDelta in AdvancedCache makes a lot of sense. Stick DeltaAware object into a cache (this could be some large XML for example) and repeatedly applyDelta on this DeltaAware transactionally!

            Vladimir Blagojevic (Inactive) added a comment - I agree with Randall here and I do not see an alternate or even a better approach. Having applyDelta in AdvancedCache makes a lot of sense. Stick DeltaAware object into a cache (this could be some large XML for example) and repeatedly applyDelta on this DeltaAware transactionally!

            IIUC, one of the important aspects of this feature is to allow custom value implementations that support DeltaAware with fine-grained locks. If there's an alternative way of supporting this rather than a public method, then perhaps that is much better.

            Randall Hauch (Inactive) added a comment - IIUC, one of the important aspects of this feature is to allow custom value implementations that support DeltaAware with fine-grained locks. If there's an alternative way of supporting this rather than a public method, then perhaps that is much better.

            @galderz +1
            Adding a public method(i.e. AdvancedCache.applyDelta) for the single purpose[1] of being invoked by the internal code is a poor API design decision.

            [1] or is this method useful for other clients as well?

            Mircea Markus (Inactive) added a comment - @galderz +1 Adding a public method(i.e. AdvancedCache.applyDelta) for the single purpose [1] of being invoked by the internal code is a poor API design decision. [1] or is this method useful for other clients as well?

            Just thinking out loud, haven't read the design preview email on the dev list: Does the method need to be in the Cache? Couldn't the method be in a particular component which AtomicHashMapProxy gets injected?

            Galder Zamarreño added a comment - Just thinking out loud, haven't read the design preview email on the dev list: Does the method need to be in the Cache? Couldn't the method be in a particular component which AtomicHashMapProxy gets injected?

            I don't think so. How else can we invoke a method on cache from a fairly high-abstraction like AtomicHashMapProxy?

            Vladimir Blagojevic (Inactive) added a comment - I don't think so. How else can we invoke a method on cache from a fairly high-abstraction like AtomicHashMapProxy?

              vblagoje Vladimir Blagojevic (Inactive)
              manik_jira Manik Surtani (Inactive)
              Archiver:
              rhn-support-adongare Amol Dongare

                Created:
                Updated:
                Resolved:
                Archived: