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

Entries are passivated with wrong ID in DB

    XMLWordPrintable

Details

    Description

      Entry passivation into DB, concretly this class LockSupportCacheStore and method store. Look at lines with "<<<" string for more info

      LockSupportCacheStore.java
        @Override
         public final void store(InternalCacheEntry ed) throws CacheLoaderException {
            if (trace) {
               log.tracef("store(%s)", ed);
            }
            if (ed == null) {
              return;
            }
            if (ed.canExpire() && ed.isExpired(timeService.wallClockTime())) {
               if (containsKey(ed.getKey())) {
                  if (trace) {
                     log.tracef("Entry %s is expired!  Removing!", ed);
                  }
                  remove(ed.getKey());
               } else {
                  if (trace) {
                     log.tracef("Entry %s is expired!  Not doing anything.", ed);
                  }
               }
               return;
            }
      
            L keyHashCode = getLockFromKey(ed.getKey()); <<< here key is generated like ed.getKey().hashCode() & 0xfffffc00;
            lockForWriting(keyHashCode);
            try {
               storeLockSafe(ed, keyHashCode); <<< here it should be stored into Bucket and then stored in DB
            } finally {
               unlock(keyHashCode);
            }
            if (trace) {
               log.tracef("exit store(%s)", ed);
            }
         }
      

      When I use RemoteCacheManager and RemoteCache I am putting entries into cache

      Test.java
         cache.put("key1", "v1");
         cache.put("key2", "v2");
         cache.put("key3", "v3");
      

      Then 2 entries are passivated and stored in DB

      ID DATA TIMESTAMP
      183713792 0301fe032a01034c422b21033e286d7942657374506572736f6e616c4b657957686963684861734e657665724265656e426574746572420521033e02763203620003630000000000000002 -1
      23486464 0301fe032a01034c420721033e046b657931420521033e02763103620003630000000000000001 -1

      IDs are generated from method above and

      Test.java
      byte[] keyBytes = marshaller.objectToByteBuffer("key1"); <<< key is marshalled
      long keyID = ByteArrayEquivalence.INSTANCE.hashCode(keyBytes) & 0xfffffc00 //computation taken from BucketBasedCacheStore <<< this does not work for me
      

      And next step I'd like to retrieve data from DB
      SELECT ID, DATA FROM JDBC_BINARY_DEFAULT WHERE ID=keyID
      But in method

      BucketBasedCacheStore.java
         @Override
         public Integer getLockFromKey(Object key) {
             return key.hashCode() & 0xfffffc00; <<< here should be used Arrays.hashCode((byte[])key)  & 0xfffffc00), if key is represented as byte array, or used ByteArrayEquivalence instead of simple byte array(byte[]) as argument
         }
      

      Attachments

        Activity

          People

            rh-ee-galder Galder ZamarreƱo
            vchepeli_jira Vitalii Chepeliuk (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: