1 Reply Latest reply on Sep 20, 2011 9:27 AM by warjort

    DistributedCache replication

    warjort

      I'm trying to create an alternate to the infinispan replicated cache that has 2 key properties that don't seem to be compatible with the current DistributedCache api.

       

      1) The version/metadata/timestamp/attributes are stored in a blob together unlike the infinispan cache where they are stored seperately - but automatically using the AtomicMap.

      2) The data is stored remotely so retrieving data that I am not told to replicate so as to recreate the full blob is expensive.

       

      The issue comes from the following code in SessionBasedClusteredSession

       

          @Override
          protected OutgoingSessionGranularitySessionData getOutgoingSessionData() {
              Map<String, Object> attrs = isSessionAttributeMapDirty() ? getSessionAttributeMap() : null;
              DistributableSessionMetadata metadata = isSessionMetadataDirty() ? getSessionMetadata() : null;
              Long timestamp = attrs != null || metadata != null || getMustReplicateTimestamp() ? Long.valueOf(getSessionTimestamp())
                      : null;
              return new OutgoingData(getRealId(), getVersion(), timestamp, metadata, attrs);
          }
      

       

      Where the DistributedCache is not told all the data on subsequent replication requests if has not changed.

       

      I'd like to have either;

      1) Some way to tell it to always give me all the data - this data is held in the local cache

      2) Some way of getting access to the local data so I can retrieve the data that hasn't changed without going to my remote store

        • 1. Re: DistributedCache replication
          warjort

          Incidently, I think the following code is wrong in the infinispan implementation of DistributedCacheManager

           

          @Override
          
          public void storeSessionData(final T sessionData) {
              
          final K key = this.keyFactory.createKey(sessionData.getRealId());
          
          
              
          trace("storeSessionData(%s)", key.getSessionId());
          
          
              
          Operation<Void> operation = new Operation<Void>() {
                  
          @Override
                  
          public Void invoke(Cache<K, Map<Object, Object>> cache) {
                      
          Map<Object, Object> map = cache.putIfAbsent(key, null);
          
          
                      
          SessionMapEntry.VERSION.put(map, Integer.valueOf(sessionData.getVersion()));
                      
          SessionMapEntry.METADATA.put(map, sessionData.getMetadata());
                      
          SessionMapEntry.TIMESTAMP.put(map, sessionData.getTimestamp());
                      
          try {
                          
          DistributedCacheManager.this.attributeStorage.store(map, sessionData);
                      
          } catch (IOException e) {
                          
          throw getRuntimeException("Failed to store session attributes for session: " + mask(key.getSessionId()), e);
                      
          }
                      
          return null;
                  
          }
              
          };
          
          
              
          this.batch(operation);
          
          }
          
          
          

          In that it will overwrite thinks like the metadata with null if it hasn't changed.

          see isSessionMetaDataDirty() referenced in the code above.