6 Replies Latest reply on Jun 23, 2008 10:31 AM by manik

    Clustered and JDBCCacheLoader access to DB

    jorgemoralespou_2

      Hi,
      I`m trying to configure my cache loader to achieve the following:
      1- Firts node incluster starts. Unable to retrieve state from memory (another cluster` node) so get it from DB
      2- Second clustered node starts. Gets state from memory (another cluster`node)

      On cache put. The cache that receives the local put, transmits state to the rest of the cluster, and persist data to DB.

      On cache get. Get value from memory, if miss, retrieve it from cluster, if miss, retrieve it from DB.

      Is this possible?

      I have try 2 approaches:

      Approach 1

      <attribute name="FetchInMemoryState">true</attribute>
      <attribute name="InitialStateRetrievalTimeout">15000</attribute>
      
      <attribute name="CacheLoaderConfiguration">
       <config>
       <passivation>false</passivation>
       <preload>/</preload>
       <shared>true</shared>
       <cacheloader>
       <class>org.jboss.cache.loader.JDBCCacheLoader</class>
       <properties>
       cache.jdbc.datasource=java:jdbc/som
       cache.jdbc.table.name=core_data
       cache.jdbc.table.create=true
       cache.jdbc.table.drop=false
       cache.jdbc.table.primarykey=jbosscache_pk
       cache.jdbc.fqn.column=fqn
       cache.jdbc.fqn.type=varchar(255)
       cache.jdbc.node.column=node
       cache.jdbc.node.type=blob
       cache.jdbc.parent.column=parent
       </properties>
       <async>true</async>
       <fetchPersistentState>false</fetchPersistentState>
       <ignoreModifications>false</ignoreModifications>
       </cacheloader>
      </config>
      


      Approach 2
      <attribute name="FetchInMemoryState">true</attribute>
      <attribute name="InitialStateRetrievalTimeout">15000</attribute>
       <config>
       <passivation>false</passivation>
       <preload>/</preload>
       <shared>true</shared>
       <cacheloader>
       <class>
       org.jboss.cache.loader.ClusteredCacheLoader
       </class>
       <properties>timeout=1000</properties>
       <async>true</async>
       <fetchPersistentState>false</fetchPersistentState>
       <ignoreModifications>false</ignoreModifications>
       </cacheloader>
       <cacheloader>
       <class>
       org.jboss.cache.loader.JDBCCacheLoader
       </class>
       <properties>
       cache.jdbc.datasource=java:jdbc/somservices
       cache.jdbc.table.name=provisioning_data
       cache.jdbc.table.create=true
       cache.jdbc.table.drop=false
       cache.jdbc.table.primarykey=provisioning_data_pk
       cache.jdbc.fqn.column=fqn
       cache.jdbc.fqn.type=varchar(255)
       cache.jdbc.node.column=node
       cache.jdbc.node.type=blob
       cache.jdbc.parent.column=parent
       </properties>
       <async>true</async>
       <fetchPersistentState>true</fetchPersistentState>
       <ignoreModifications>false</ignoreModifications>
      </cacheloader>
      
      
      What I see, with both of this configs, is that when I start second node in the cluster, it retrieves state from the other node, but it seems to update the database. It performs a delete all, and insert every retrieved value. I see the deletes , inserts in logs.
      
      Anyone can help? Is it possible what I want?


        • 1. Re: Clustered and JDBCCacheLoader access to DB
          brian.stansberry

          In your Approach 2 in the JDBCCacheLoader turn fetchPersistentState to false. There's no reason to move the persistent state over the wire from another cache, since the cacheloader already has access to it in the shared db.

          There used to be logic to ignore the fetchPersistentState=true if shared=true. Sounds like that isn't working any more. Suspect it's due to the addition of cache loader chaning.

          • 2. Re: Clustered and JDBCCacheLoader access to DB
            jorgemoralespou_2

            What I don`t understund is why, with this configurations (both) the cache loader does:

            1.- Retrieve state from cluster and delete data in JDBCCacheLoader


            [org.jboss.cache.TreeCache] received the state (size=131072 bytes)
            2008-06-23 13:33:42,733 DEBUG [org.jboss.cache.loader.JDBCCacheLoader] executing sql: delete from core_data
            2008-06-23 13:33:42,736 INFO [org.jboss.cache.TreeCache] state was retrieved successfully (in 677 milliseconds)


            2.- Store received stat into database




            2008-06-23 13:33:42,736 DEBUG [org.jboss.cache.loader.CacheLoaderManager] preloading transient state from cache loader org.jboss.cache.loader.AsyncCacheLoader@142e6767 delegate=[org.jboss.cache.loader.JDBCCacheLoader@7286a58a] processor=TQ t=Thread[AsyncCacheLoader-2,5,jboss] stopped=false batchSize=100 pollWait=100 returnOld=true asyncPut=true queue.capacity()=10000 queue.peek()=null
            2008-06-23 13:33:42,737 DEBUG [org.jboss.cache.loader.JDBCCacheLoader] executing sql: select fqn from core_data where parent=? (/)
            2008-06-23 13:33:42,783 DEBUG [org.jboss.cache.loader.JDBCCacheLoader] executing sql: select fqn from core_data where parent=? (/DB_CAPABILITY)
            2008-06-23 13:33:42,789 DEBUG [org.jboss.cache.loader.JDBCCacheLoader] executing sql: select fqn from core_data where parent=? (/DB_CAPABILITY/SESIONES)
            2008-06-23 13:33:42,792 DEBUG [org.jboss.cache.loader.JDBCCacheLoader] executing sql: select fqn from core_data where parent=? (/TRAP)
            2008-06-23 13:33:42,824 DEBUG [org.jboss.cache.loader.JDBCCacheLoader] total rows deleted: 152
            2008-06-23 13:33:42,824 DEBUG [org.jboss.cache.loader.JDBCCacheLoader] executing sql: select node from core_data where fqn=? (/)
            2008-06-23 13:33:42,829 DEBUG [org.jboss.cache.loader.JDBCCacheLoader] executing sql: insert into core_data (fqn, node, parent) values (?, ?, ?) (/)
            


            3.- Leave some interleaved messages


            2008-06-23 13:33:42,954 DEBUG [org.jboss.cache.loader.JDBCCacheLoader] executing sql: select node from core_data where fqn=? (/TRAP)
            2008-06-23 13:33:42,960 DEBUG [org.jboss.cache.loader.CacheLoaderManager] preloading transient state from cache loader was successful (in 223 milliseconds)
            2008-06-23 13:33:43,001 DEBUG [org.jboss.cache.loader.JDBCCacheLoader] executing sql: insert into core_data (fqn, node, parent) values (?, ?, ?) (/TRAP)
            2008-06-23 13:33:43,240 DEBUG [org.jboss.cache.TreeCache] Starting jboss.cache:service=SOMServicesProvisioningCache
            2008-06-23 13:33:43,246 DEBUG [org.jboss.cache.loader.JDBCCacheLoader] executing sql: insert into core_data (fqn, node, parent) values (?, ?, ?) (/TRAP/TA_START_ERROR)
            2008-06-23 13:33:43,246 INFO [org.jboss.cache.loader.AsyncCacheLoader] Async cache loader starting: org.jboss.cache.loader.AsyncCacheLoader@2b51574b delegate=[org.jboss.cache.loader.ClusteredCacheLoader@693a1324] processor=null stopped=true batchSize=100 pollWait=100 returnOld=true asyncPut=true queue.capacity()=10000 queue.peek()=null
            2008-06-23 13:33:43,276 DEBUG [org.jboss.cache.loader.JDBCCacheLoader] executing sql: select node from core_data where fqn=? (/TRAP/WS_DEPLOYMENT)
            


            Why is it updating the persistent state from the data I`m receiving from the cluster?

            Also, I see that every time I do a read from cache, it is retrieving the data from database. Why?


            2008-06-23 13:38:50,012 DEBUG [org.jboss.cache.loader.JDBCCacheLoader] executing sql: select node from core_data where fqn=? (/STATISTIC_LOGGING_MONITOR)
            


            • 3. Re: Clustered and JDBCCacheLoader access to DB
              jorgemoralespou_2

              Forgot to mention:

              Cache is 1.4.1.SP9

              • 4. Re: Clustered and JDBCCacheLoader access to DB
                jorgemoralespou_2

                 

                "jorgemoralespou_2" wrote:

                Also, I see that every time I do a read from cache, it is retrieving the data from database. Why?


                It seems this is only happening when there is a cache miss.

                • 5. Re: Clustered and JDBCCacheLoader access to DB
                  manik

                   

                  "jorgemoralespou_2" wrote:
                  "jorgemoralespou_2" wrote:

                  Also, I see that every time I do a read from cache, it is retrieving the data from database. Why?


                  It seems this is only happening when there is a cache miss.


                  Do you see any messages in your logs pertaining to not being able to fetch state from the ClusteredCacheLoader and hence it hits the database?

                  • 6. Re: Clustered and JDBCCacheLoader access to DB
                    manik

                    Regarding deleting stuff in your JDBC cache loader, I would set fetchPersistentState to false on both cache loaders. This is unnecessary since the DB is shared anyway.