6 Replies Latest reply: Jan 16, 2013 7:47 AM by 984647 RSS

    Not able to put values in Database with replication scheme

    984647
      Hi,
      I am tiring put some data from application to MySQL database. And my cache scheme is Replicated scheme.
      My system architecture is Client-Server.
      Following is my coherence-cache-config.xml file

      <?xml version="1.0"?>
      <cache-config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns="http://xmlns.oracle.com/coherence/coherence-cache-config"
      xsi:schemaLocation="http://xmlns.oracle.com/coherence/coherence-cache-config coherence-cache-config.xsd">

      <defaults>
      <serializer system-property="tangosol.coherence.serializer"/>
      <socket-provider system-property="tangosol.coherence.socketprovider"/>
      </defaults>

      <caching-scheme-mapping>
      <cache-mapping>
      <cache-name>dist-*</cache-name>
      <scheme-name>dist-default</scheme-name>
      </cache-mapping>
      </caching-scheme-mapping>

      <caching-schemes>

      <distributed-scheme>
      <scheme-name>dist-default</scheme-name>
      <lease-granularity>member</lease-granularity>
           <backing-map-scheme>
      <read-write-backing-map-scheme>
      <scheme-ref>SampleDatabaseScheme</scheme-ref>
      </read-write-backing-map-scheme>
      </backing-map-scheme>
           <listener>
      <class-scheme>
           <class-name>com.coherence.listeners.CacheListenerLogger</class-name>
           </class-scheme>
      </listener>
      <autostart>true</autostart>
      </distributed-scheme>


      <!-- for performing DB relaated operations -->
      <read-write-backing-map-scheme>
      <scheme-name>SampleDatabaseScheme</scheme-name>
      <internal-cache-scheme>
      <local-scheme>
      <scheme-ref>example-object-backing-map</scheme-ref>
      </local-scheme>
      </internal-cache-scheme>

      <cachestore-scheme>
      <class-scheme>
      <class-name>com.coherence.listeners.DBCacheStore</class-name>
      <init-params>
      <init-param>
      <param-type>java.lang.String</param-type>
      <param-value>employee</param-value>
      </init-param>
      </init-params>
      </class-scheme>
      </cachestore-scheme>
      <read-only>false</read-only>
      <write-delay-seconds>5</write-delay-seconds>
      </read-write-backing-map-scheme>

           <!--
      A scheme used by backing maps that may store data in object format and
      employ size limitation and/or expiry eviction policies.
      -->
      <local-scheme>
      <scheme-name>example-object-backing-map</scheme-name>

      <eviction-policy>HYBRID</eviction-policy>
      <high-units>{back-size-limit 0}</high-units>
      <expiry-delay>{back-expiry 1h}</expiry-delay>

      <cachestore-scheme></cachestore-scheme>
      </local-scheme>

      <proxy-scheme>
      <service-name>ExtendTcpProxyService</service-name>
      <thread-count>100</thread-count>
      <acceptor-config>
      <tcp-acceptor>
      <local-address>
      <address>localhost</address>
      <port>1095</port>
      </local-address>
      </tcp-acceptor>
      </acceptor-config>
      <autostart>true</autostart>
      </proxy-scheme>
      </caching-schemes>
      </cache-config>


      **Here i m able to connect to the database successfull but not able to put any value in database.**
      **it is giving me following error**
      2013-01-10 10:30:55.532/69.951 Oracle Coherence GE 3.7.1.0 <Error> (thread=ReplicatedCache, member=1): Terminating ReplicatedCache due to unhandled exception: java.lang.ClassCastException
      2013-01-10 10:30:55.532/69.951 Oracle Coherence GE 3.7.1.0 <Error> (thread=ReplicatedCache, member=1):
      java.lang.ClassCastException: java.lang.Integer cannot be cast to com.tangosol.util.Binary
      at com.tangosol.net.cache.ReadWriteBackingMap.instantiateEntry(ReadWriteBackingMap.java:3015)
      at com.tangosol.net.cache.ReadWriteBackingMap.putInternal(ReadWriteBackingMap.java:1232)
      at com.tangosol.net.cache.ReadWriteBackingMap.put(ReadWriteBackingMap.java:913)
      at com.tangosol.coherence.component.util.CacheHandler.onLeaseUpdate(CacheHandler.CDB:45)
      at com.tangosol.coherence.component.util.daemon.queueProcessor.service.grid.ReplicatedCache.performUpdate(ReplicatedCache.CDB:11)
      at com.tangosol.coherence.component.util.daemon.queueProcessor.service.grid.ReplicatedCache.onLeaseUpdateRequest(ReplicatedCache.CDB:22)
      at com.tangosol.coherence.component.util.daemon.queueProcessor.service.grid.ReplicatedCache$LeaseUpdateRequest.onReceived(ReplicatedCache.CDB:5)
      at com.tangosol.coherence.component.util.daemon.queueProcessor.service.Grid.onMessage(Grid.CDB:34)
      at com.tangosol.coherence.component.util.daemon.queueProcessor.service.Grid.onNotify(Grid.CDB:33)
      at com.tangosol.coherence.component.util.daemon.queueProcessor.service.grid.ReplicatedCache.onNotify(ReplicatedCache.CDB:3)
      at com.tangosol.coherence.component.util.Daemon.run(Daemon.CDB:42)
      at java.lang.Thread.run(Unknown Source)


      Help me out to this.....
        • 1. Re: Not able to put values in Database with replication scheme
          User738616-Oracle
          Hi,

          I don't see anything related to ReplicatedScheme in the configuration. Where are you defining the ReplicatedSchem and how are you accessing Coherence cluster in the client application?

          Cheers,
          _NJ                                                                                                                                                                                                                                                                                                                                                                                                                               
          • 2. Re: Not able to put values in Database with replication scheme
            984647
            hi,
            sorry for inconvenience.
            Details r as follows
            1) I am using client/server environment
            ---------------------------------------------------------------------------------------------------------------------------------------------------------
            2) Coherence-cache-config.xml
            <?xml version="1.0" ?>
            - <cache-config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.oracle.com/coherence/coherence-cache-config" xsi:schemaLocation="http://xmlns.oracle.com/coherence/coherence-cache-config coherence-cache-config.xsd">
            - <defaults>
            <serializer system-property="tangosol.coherence.serializer" />
            <socket-provider system-property="tangosol.coherence.socketprovider" />
            </defaults>
            - <caching-scheme-mapping>
            - <!-- For client-server case
            -->
            - <cache-mapping>
            <cache-name>dist-*</cache-name>
            <scheme-name>dist-default</scheme-name>
            </cache-mapping>
            </caching-scheme-mapping>
            -
            <caching-schemes>
            -
            <replicated-scheme>
            <scheme-name>dist-default</scheme-name>
            <lease-granularity>member</lease-granularity>
            - <backing-map-scheme>
            - <read-write-backing-map-scheme>
            <scheme-ref>SampleDatabaseScheme</scheme-ref>
            </read-write-backing-map-scheme>
            </backing-map-scheme>
            - <listener>
            - <class-scheme>
            <class-name>com.lnt.coe.coherence.listeners.CacheListenerLogger</class-name>
            </class-scheme>
            </listener>
            <autostart>true</autostart>
            </replicated-scheme>
            - <!-- for performing DB relaated operations
            -->
            - <read-write-backing-map-scheme>
            <scheme-name>SampleDatabaseScheme</scheme-name>
            - <internal-cache-scheme>
            - <local-scheme>
            <scheme-ref>example-object-backing-map</scheme-ref>
            </local-scheme>
            </internal-cache-scheme>
            - <cachestore-scheme>
            - <class-scheme>
            <class-name>com.lnt.coe.coherence.listeners.DBCacheStore</class-name>
            - <init-params>
            - <init-param>
            <param-type>java.lang.String</param-type>
            <param-value>employee</param-value>
            </init-param>
            </init-params>
            </class-scheme>
            </cachestore-scheme>
            <read-only>false</read-only>
            <write-delay-seconds>5</write-delay-seconds>
            </read-write-backing-map-scheme>
            - <!-- A scheme used by backing maps that may store data in object format and
            employ size limitation and/or expiry eviction policies.

            -->
            - <local-scheme>
            <scheme-name>example-object-backing-map</scheme-name>
            <eviction-policy>HYBRID</eviction-policy>
            <high-units>{back-size-limit 0}</high-units>
            <expiry-delay>{back-expiry 1h}</expiry-delay>
            <cachestore-scheme />
            </local-scheme>
            - <proxy-scheme>
            <service-name>ExtendTcpProxyService</service-name>
            <thread-count>100</thread-count>
            - <acceptor-config>
            - <tcp-acceptor>
            - <local-address>
            <address>localhost</address>
            <port>1095</port>
            </local-address>
            </tcp-acceptor>
            </acceptor-config>
            <autostart>true</autostart>
            </proxy-scheme>
            </caching-schemes>
            </cache-config>

            ---------------------------------------------------------------------------------------------------------------------------------------------------------

            3) I have Employee POJO in my test app and i m tiring to put the relavant values of employee object in Employee table ini database. In cache i m able to put data successfully.
            I m tiring to put some data from cache to MySQL database.
            I m able to connect to the Database successfully.
            ---------------------------------------------------------------------------------------------------------------------------------------------------------
            4) the problem is when i m putting some values using replication scheme.
            It is showing me following exception
            2013-01-15 04:12:32.128/56.042 Oracle Coherence GE 3.7.1.0 <Error> (thread=ReplicatedCache, member=1): Terminating ReplicatedCache due to unhandled exception: java.lang.ClassCastException
            2013-01-15 04:12:32.128/56.042 Oracle Coherence GE 3.7.1.0 <Error> (thread=ReplicatedCache, member=1):
            java.lang.ClassCastException: com.lnt.coe.coherence.entity.Employee cannot be cast to com.tangosol.util.Binary
            at com.tangosol.net.cache.ReadWriteBackingMap.putInternal(ReadWriteBackingMap.java:1261)
            at com.tangosol.net.cache.ReadWriteBackingMap.put(ReadWriteBackingMap.java:913)
            at com.tangosol.coherence.component.util.CacheHandler.onLeaseUpdate(CacheHandler.CDB:45)
            at com.tangosol.coherence.component.util.daemon.queueProcessor.service.grid.ReplicatedCache.performUpdate(ReplicatedCache.CDB:11)
            at com.tangosol.coherence.component.util.daemon.queueProcessor.service.grid.ReplicatedCache.onLeaseUpdateRequest(ReplicatedCache.CDB:22)
            at com.tangosol.coherence.component.util.daemon.queueProcessor.service.grid.ReplicatedCache$LeaseUpdateRequest.onReceived(ReplicatedCache.CDB:5)
            at com.tangosol.coherence.component.util.daemon.queueProcessor.service.Grid.onMessage(Grid.CDB:34)
            at com.tangosol.coherence.component.util.daemon.queueProcessor.service.Grid.onNotify(Grid.CDB:33)
            at com.tangosol.coherence.component.util.daemon.queueProcessor.service.grid.ReplicatedCache.onNotify(ReplicatedCache.CDB:3)
            at com.tangosol.coherence.component.util.Daemon.run(Daemon.CDB:42)
            at java.lang.Thread.run(Unknown Source)
            ---------------------------------------------------------------------------------------------------------------------------------------------------------
            • 3. Re: Not able to put values in Database with replication scheme
              user639604
              First of all, you shouldn't use cache-store scheme for replicated cache. This is from Coherence doc.

              To ensure cache coherence, the backing-map of a replicated cache must not use a read-through pattern to load cache entries. Either use a cache-aside pattern from outside the cache service, or switch to the distributed-scheme, which supports read-through clustered caching.

              Legal backing map scheme for replicated cache are :

              local-scheme
              external-scheme
              paged-external-scheme
              overflow-scheme
              class-scheme
              flashjournal-scheme
              ramjournal-scheme
              • 4. Re: Not able to put values in Database with replication scheme
                984647
                Hi,
                Thanx for the reply.

                What we are trying is,
                from our application data will go inside Replicated cache scheme, and from replicated cache our data must persisted to database.

                **we are not able to get configurations for* Application+Replicated cache+Database_ from coherence doc or from any forum.

                so can you help us with required configurations for above said situation
                • 5. Re: Not able to put values in Database with replication scheme
                  HarveyRaja
                  Hi,

                  By nature of the replicated cache you more than likely do not want every member hosting the replicated cache to persist into the database. If my hunch is right and you do not want this I would suggest you orchestrate the two, caching data in a replicated cache and persisting to a db, in the process inserting or updating the data.

                  If your objective is to take advantage of the grid to scale your interactions with the db I would consider using a partitioned cache with a cache store. This would have an adverse affect on clients wrt access time however this generally can be overcome with near caching or continuous query caches.

                  Thanks,
                  Harvey
                  • 6. Re: Not able to put values in Database with replication scheme
                    984647
                    hi Harvey,
                    can you please elaborate what you are trying to say in first paragraph of your last post.
                    i am not able to get it clearly.

                    can you help me with configuration required for
                    Application + Replication Scheme + Database(MySQL) as mentioned in my previous posts.

                    Thanx