You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by amdam23000 <62...@qq.com> on 2016/09/18 09:57:11 UTC

Data grid client errors out when datasource not defined

Hi,

I have one single server node as data grid server, which loads some data
from db.

Also i create one single client, which reads and/or updates some cache data
which is loaded by the ignite server.

1. When there is no datasource defined (in spring config) in client,
client's read/write will error out as below:
   
    
<http://apache-ignite-users.70518.x6.nabble.com/file/n7820/capture2.png> 

2. When datasource is defined in client, client's read/write will work.

PS. Server node works fine (Of course datacource and mapping are all defined
there).

Is datasource a must or do i miss something here in such use case?


Thanks,
Jason



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Data-grid-client-errors-out-when-datasource-not-defined-tp7820.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Re: Data grid client errors out when datasource not defined

Posted by Anton Vinogradov <av...@gridgain.com>.
Hi Jason,

Without going into detail, Ignite Client node is the same as Server node
but can't keep data.
And, if I remember correctly, it can finish transactions itself, so it need
ability to store data to datastore.

On Thu, Sep 22, 2016 at 4:35 AM, amdam23000 <62...@qq.com> wrote:

> Hi Anton,
>
> really appreciate your help.
>
> Yes, with datasource specified in client side (datasource as property or a
> bean) it works fine.
>
> But i wonder why client need to have datasource to successfully access
> cache,
> i think client has no need to access database directly but instead just
> communicates with server node,
> it's the server node's responsibility to read-through/write-through
> database.
>
> What do you see about that?
>
>
>
> --
> View this message in context: http://apache-ignite-users.
> 70518.x6.nabble.com/Data-grid-client-errors-out-when-
> datasource-not-defined-tp7820p7868.html
> Sent from the Apache Ignite Users mailing list archive at Nabble.com.
>

Re: Data grid client errors out when datasource not defined

Posted by amdam23000 <62...@qq.com>.
Hi Anton,

really appreciate your help.

Yes, with datasource specified in client side (datasource as property or a
bean) it works fine.

But i wonder why client need to have datasource to successfully access
cache,
i think client has no need to access database directly but instead just
communicates with server node,
it's the server node's responsibility to read-through/write-through
database.

What do you see about that?



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Data-grid-client-errors-out-when-datasource-not-defined-tp7820p7868.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Re: Data grid client errors out when datasource not defined

Posted by Anton Vinogradov <av...@gridgain.com>.
Jason,

Thanks for tips,

I found that CacheJdbcPojoStoreFactory required to have bean specified at
 <property name="*dataSourceBean*" value="dataSource"/>
inside client config to use this cache.

Another way is to specify *dataSource *property instead.

for example:

<bean id="storeDataSource"
class="org.apache.ignite.cache.store.jdbc.CacheJdbcPojoStore">
    <property name="dataSource">
        <bean class="org.h2.jdbcx.JdbcConnectionPool" factory-method="create">
            <constructor-arg value="jdbc:h2:tcp://0.0.0.0/mem:db"/>
            <constructor-arg value="sa"/>
            <constructor-arg value=""/>
        </bean>
    </property>
</bean>

Here's the code explaining how it works:

if (dataSrc != null) // Use this case.
    store.setDataSource(dataSrc);
else {
    if (dataSrcBean != null) {
        if (appCtx == null)
            throw new IgniteException("Spring application context
resource is not injected.");

        IgniteSpringHelper spring;

        try {
            spring = IgniteComponentType.SPRING.create(false);

            DataSource data = spring.loadBeanFromAppContext(appCtx,
dataSrcBean);

            store.setDataSource(data);

Let me know in case it will not help.

On Wed, Sep 21, 2016 at 9:57 AM, amdam23000 <62...@qq.com> wrote:

> Hi Anton,
>
> I'm sorry that for some reason i can't copy stack trace to text file out of
> the box.
> The more detail about the exception is as below:
>
> at
> org.apache.ignite.internal.processors.cache.distributed.dht.preloader.
> GridDhtPartitionsExchangeFuture.startCaches(GridDhtPartitionsExchangeFutur
> e.java:956)
> at
> org.apache.ignite.internal.processors.cache.distributed.dht.preloader.
> GridDhtPartitionsExchangeFuture.init(GridDhtPartitionsExchangeFutur
> e.java:523)
> at
> org.apache.ignite.internal.processors.cache.GridCachePartitionExchangeMana
> ger$ExchangeWorker.body(GridCachePartitionExchangeManager.java:1297)
> at
> org.apache.ignite.internal.util.worker.GridWorker.run(GridWorker.java:110)
>
> The ignite version i use is 1.5.0, please notice this.
>
> I debug a little and find that client side will first receive cache config
> from server side,
> and then client will try to create an instance of that cache
> store(cfg.getCacheStoreFactory().create()).
> During the process of the instance creation, "datasource" cannot been found
> locally so error occurs.
>
>
>
>
> --
> View this message in context: http://apache-ignite-users.
> 70518.x6.nabble.com/Data-grid-client-errors-out-when-
> datasource-not-defined-tp7820p7852.html
> Sent from the Apache Ignite Users mailing list archive at Nabble.com.
>

Re: Data grid client errors out when datasource not defined

Posted by amdam23000 <62...@qq.com>.
Hi Anton,

I'm sorry that for some reason i can't copy stack trace to text file out of
the box.
The more detail about the exception is as below:

at
org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture.startCaches(GridDhtPartitionsExchangeFuture.java:956)
at
org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture.init(GridDhtPartitionsExchangeFuture.java:523)
at
org.apache.ignite.internal.processors.cache.GridCachePartitionExchangeManager$ExchangeWorker.body(GridCachePartitionExchangeManager.java:1297)
at
org.apache.ignite.internal.util.worker.GridWorker.run(GridWorker.java:110)

The ignite version i use is 1.5.0, please notice this.

I debug a little and find that client side will first receive cache config
from server side,
and then client will try to create an instance of that cache
store(cfg.getCacheStoreFactory().create()).
During the process of the instance creation, "datasource" cannot been found
locally so error occurs.




--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Data-grid-client-errors-out-when-datasource-not-defined-tp7820p7852.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Re: Data grid client errors out when datasource not defined

Posted by Anton Vinogradov <av...@gridgain.com>.
Jason,

Could you please reattach stacktrace as a text. Nabble is down now and I
can't recheck exception details.

Also, is it possible to create simple maven project with test running
server and client node as you described?
I tried to run similar configuration but gain no failures.


On Tue, Sep 20, 2016 at 11:58 AM, amdam23000 <62...@qq.com> wrote:

> Hi,
>
> please take a look at my config and code below, i think i did not specify
> some bean depending on dataSource on client side.
>
> 1. In client side, the spring config is as below:
>
> <bean id="ignite.cfg"
> class="org.apache.ignite.configuration.IgniteConfiguration">
>     <property name="peerClassLoadingEnabled" value="false"></property>
>     <property name="clientMode" value="true"></property>
> </bean>
>
> 2. In server side, config is as below:
>
> <bean id="ignite.cfg"
> class="org.apache.ignite.configuration.IgniteConfiguration">
>     <property name="peerClassLoadingEnabled" value="false"></property>
>     <property name="cacheConfiguration">
>         <list>
>             <bean
> class="org.apache.ignite.configuration.CacheConfiguration">
>                 <property name="name" value="xxx" />
>                 <property name="copyOnRead" value="false" />
>                 <property name="cacheMode" value="PARTITIONED" />
>                 <property name="backups" value="1" />
>                 <property name="cacheStoreFactory" value="xxx" >
>                     <bean
> class="org.apache.ignite.cache.store.jdbc.CacheJdbcPojoStoreFactory">
>                         <property name="dataSourceBean" value="dataSource"
> />
>                         <property name="types" >
>                             ... some db table and field mappings here, mean
> to load all data from the table ...
>                         </property>
>                     </bean>
>                 </property>
>             </bean>
>         </list>
>     </property>
> </bean>
> <bean name="dataSource"
> class="org.springframework.jdbc.datasource.DriverManagerDataSource">
>     ... db connection config here ...
> </bean>
>
> 3. Server code
> IgniteCache cache = ignite.getOrCreateCache("xxx");
> cache.loadAll(null, null); // loading succeeds
> cache.get(xxxKey);   // here it works, we can get entity with specified
> key.
>
> 4. Client code (executed after server node launched)
> IgniteCache cache = ignite.getOrCreateCache("xxx");
> cache.get(xxxKey);   // here it failed as i posted previously, no
> datasource
> found.
>
> 5. If i add <bean name="dataSource" ... to client spring config, then
> client
> code works.
>
>
> Is it possible that client side need to connect db using datasource?
> In this case, client just perform a simple query of the cache.
>
> Thanks,
> Jason
>
>
>
> --
> View this message in context: http://apache-ignite-users.
> 70518.x6.nabble.com/Data-grid-client-errors-out-when-
> datasource-not-defined-tp7820p7841.html
> Sent from the Apache Ignite Users mailing list archive at Nabble.com.
>

Re: Data grid client errors out when datasource not defined

Posted by amdam23000 <62...@qq.com>.
Hi, 

please take a look at my config and code below, i think i did not specify
some bean depending on dataSource on client side.

1. In client side, the spring config is as below:

<bean id="ignite.cfg"
class="org.apache.ignite.configuration.IgniteConfiguration">
    <property name="peerClassLoadingEnabled" value="false"></property>
    <property name="clientMode" value="true"></property>
</bean>

2. In server side, config is as below:

<bean id="ignite.cfg"
class="org.apache.ignite.configuration.IgniteConfiguration">
    <property name="peerClassLoadingEnabled" value="false"></property>
    <property name="cacheConfiguration">
        <list>
            <bean
class="org.apache.ignite.configuration.CacheConfiguration">
                <property name="name" value="xxx" />
                <property name="copyOnRead" value="false" />
                <property name="cacheMode" value="PARTITIONED" />
                <property name="backups" value="1" />
                <property name="cacheStoreFactory" value="xxx" >
                    <bean
class="org.apache.ignite.cache.store.jdbc.CacheJdbcPojoStoreFactory">
                        <property name="dataSourceBean" value="dataSource"
/>
                        <property name="types" >
                            ... some db table and field mappings here, mean
to load all data from the table ...
                        </property>
                    </bean>
                </property>
            </bean>
        </list>
    </property>
</bean>
<bean name="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    ... db connection config here ...
</bean>

3. Server code
IgniteCache cache = ignite.getOrCreateCache("xxx");
cache.loadAll(null, null); // loading succeeds
cache.get(xxxKey);   // here it works, we can get entity with specified key.

4. Client code (executed after server node launched)
IgniteCache cache = ignite.getOrCreateCache("xxx");
cache.get(xxxKey);   // here it failed as i posted previously, no datasource
found.

5. If i add <bean name="dataSource" ... to client spring config, then client
code works.


Is it possible that client side need to connect db using datasource? 
In this case, client just perform a simple query of the cache.

Thanks,
Jason



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Data-grid-client-errors-out-when-datasource-not-defined-tp7820p7841.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Re: Data grid client errors out when datasource not defined

Posted by Anton Vinogradov <av...@gridgain.com>.
Hi, seems you have some bean depending on bean "dataSource". 
And when you removing "dataSource" from config Spring configuration can't be
parsed.

In case fixing this does not help, please provide full Spring config.

P.s. Please properly subscribe to the mailing list so that the community can
receive email notifications for your messages. To subscribe, send empty
email to user-subscribe@ignite.apache.org and follow simple instructions in
the reply.



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Data-grid-client-errors-out-when-datasource-not-defined-tp7820p7840.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.