You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by mlekshma <mu...@gmail.com> on 2018/05/25 03:58:29 UTC

IgniteSpringBean & Ignite SpringTransactionManager broken with 2.4?

Hi,

I see that with a change introduced in 2.4 in IgniteSpringBean to delay
ignite instance start until all other spring beans are initialized may have
broken Ignite  SpringTransactionManager
<https://ignite.apache.org/releases/latest/javadoc/org/apache/ignite/transactions/spring/SpringTransactionManager.html>  
resulting in inability to configure it for Spring transaction abstraction of
Ignite transactions. I really, badly need to find a way to work around this.
Any ideas/suggestions anyone?

Below is the line from  IgniteSpringBean
<https://ignite.apache.org/releases/latest/javadoc/org/apache/ignite/IgniteSpringBean.html>  
java doc
/*"Ignite instance is started after all other Spring beans have been
initialized and right before Spring context is refreshed. That implies that
it's not valid to reference IgniteSpringBean from any kind of Spring bean
init methods like PostConstruct. If it's required to reference
IgniteSpringBean for other bean initialization purposes, it should be done
from a ContextRefreshedEvent listener method declared in that bean. "
*/

The problem is since SpringTransactionManager implements
org.springframework.beans.factory.InitializingBean & in the
afterPropertiesSet() call that spring calls it tries to look for the
igniteInstanceName that's specified but since the instance is started only
AFTER all other Spring beans have been initialized, it fails with
IgniteIllegalStateException,

Please see below stack trace,

lass]: Invocation of init method failed; nested exception is class
org.apache.ignite.IgniteIllegalStateException: Ignite instance with provided
name doesn't exist. Did you call Ignition.start(..) to start an Ignite
instance? [name=ObjectManagerGrid]
	at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1628)
	at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555)
	at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
	at
org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
	at
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
	at
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
	at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
	at
org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761)
	at
org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:866)
	at
org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542)
	at
org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
	at
org.springframework.boot.SpringApplication.refresh(SpringApplication.java:737)
	at
org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:370)
	at
org.springframework.boot.SpringApplication.run(SpringApplication.java:314)
	at com.brocade.dcm.Application.main(Application.java:63)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at
org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
	at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
	at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
	at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51)
*Caused by: org.apache.ignite.IgniteIllegalStateException: Ignite instance
with provided name doesn't exist. Did you call Ignition.start(..) to start
an Ignite instance? [name=ObjectManagerGrid]
	at org.apache.ignite.internal.IgnitionEx.grid(IgnitionEx.java:1376)
	at org.apache.ignite.Ignition.ignite(Ignition.java:530)
	at
org.apache.ignite.transactions.spring.SpringTransactionManager.afterPropertiesSet(SpringTransactionManager.java:357)
	at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1687)
	at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624)*
	... 22 common frames omitted

Thanks



--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/

Re: IgniteSpringBean & Ignite SpringTransactionManager broken with 2.4?

Posted by "ilya.kasnacheev" <il...@gmail.com>.
Hello!

I went ahead and filled a ticket:
https://issues.apache.org/jira/browse/IGNITE-8740

Regards,



--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/

Re: IgniteSpringBean & Ignite SpringTransactionManager broken with 2.4?

Posted by Ilya Kasnacheev <il...@gmail.com>.
Hello!

I have found a relevant ticket that was fixed in 2.4 leading to current
behavior:
https://issues.apache.org/jira/browse/IGNITE-6555

The problem here is that Spring beans may depend on Ignite, but Ignite in
turn may depend on Spring beans. So the decision was made to defer Ignite
start to very late time. Is there a way to defer SpringTransactionManager
initialization, e.g. make it on-demand?

As for your suggestion, it looks reasonable to me. Can you fill a ticket
about Apache JIRA, with pull request possibly? I will make sure it gets
reviewed promptly?

Regards,

-- 
Ilya Kasnacheev

2018-05-25 14:10 GMT+03:00 Muthu <mu...@gmail.com>:

> So looks like one fix may be to,
>
> 1. Have IgniteSpringBean publish an Ignite application event on Ignite
> instance start from inside of its ' afterSingletonsInstantiated()' method
> ( @Override public void afterSingletonsInstantiated())
>
> 2. Then have SpringTransactionManager listen to the event & execute the
> code currently in its 'afterPropertiesSet()' method ( @Override public
> void afterPropertiesSet() throws Exception) by moving it to the event
> handler method.
>
> This way SpringTransactionManager can finish its intended custom
> initialization AFTER ignite instance is started other wise the below
> highlighted line will fail as its happening now,
>
>     @Override public void afterPropertiesSet() throws Exception {
>         assert ignite == null;
>
>         if (cfgPath != null && cfg != null) {
>             throw new IllegalArgumentException("Both 'configurationPath'
> and 'configuration' are " +
>                     "provided. Set only one of these properties if you
> need to start a Ignite node inside of " +
>                     "SpringCacheManager. If you already have a node
> running, omit both of them and set" +
>                     "'igniteInstanceName' property.");
>         }
>
>         if (cfgPath != null)
>             ignite = IgniteSpring.start(cfgPath, springCtx);
>         else if (cfg != null)
>             ignite = IgniteSpring.start(cfg, springCtx);
>         else
> *            ignite = Ignition.ignite(igniteInstanceName);*
>
>         if (transactionConcurrency == null)
>             transactionConcurrency = ignite.configuration().
> getTransactionConfiguration().getDefaultTxConcurrency();
>
>         log = ignite.log();
>     }
>
> Regards,
> Muthu
>
> On Thu, May 24, 2018 at 8:58 PM, mlekshma <mu...@gmail.com>
> wrote:
>
>> Hi,
>>
>> I see that with a change introduced in 2.4 in IgniteSpringBean to delay
>> ignite instance start until all other spring beans are initialized may
>> have
>> broken Ignite  SpringTransactionManager
>> <https://ignite.apache.org/releases/latest/javadoc/org/apach
>> e/ignite/transactions/spring/SpringTransactionManager.html>
>> resulting in inability to configure it for Spring transaction abstraction
>> of
>> Ignite transactions. I really, badly need to find a way to work around
>> this.
>> Any ideas/suggestions anyone?
>>
>> Below is the line from  IgniteSpringBean
>> <https://ignite.apache.org/releases/latest/javadoc/org/apach
>> e/ignite/IgniteSpringBean.html>
>> java doc
>> /*"Ignite instance is started after all other Spring beans have been
>> initialized and right before Spring context is refreshed. That implies
>> that
>> it's not valid to reference IgniteSpringBean from any kind of Spring bean
>> init methods like PostConstruct. If it's required to reference
>> IgniteSpringBean for other bean initialization purposes, it should be done
>> from a ContextRefreshedEvent listener method declared in that bean. "
>> */
>>
>> The problem is since SpringTransactionManager implements
>> org.springframework.beans.factory.InitializingBean & in the
>> afterPropertiesSet() call that spring calls it tries to look for the
>> igniteInstanceName that's specified but since the instance is started only
>> AFTER all other Spring beans have been initialized, it fails with
>> IgniteIllegalStateException,
>>
>> Please see below stack trace,
>>
>> lass]: Invocation of init method failed; nested exception is class
>> org.apache.ignite.IgniteIllegalStateException: Ignite instance with
>> provided
>> name doesn't exist. Did you call Ignition.start(..) to start an Ignite
>> instance? [name=ObjectManagerGrid]
>>         at
>> org.springframework.beans.factory.support.AbstractAutowireCa
>> pableBeanFactory.initializeBean(AbstractAutowir
>> eCapableBeanFactory.java:1628)
>>         at
>> org.springframework.beans.factory.support.AbstractAutowireCa
>> pableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFac
>> tory.java:555)
>>         at
>> org.springframework.beans.factory.support.AbstractAutowireCa
>> pableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
>>         at
>> org.springframework.beans.factory.support.AbstractBeanFactor
>> y$1.getObject(AbstractBeanFactory.java:306)
>>         at
>> org.springframework.beans.factory.support.DefaultSingletonBe
>> anRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
>>         at
>> org.springframework.beans.factory.support.AbstractBeanFactor
>> y.doGetBean(AbstractBeanFactory.java:302)
>>         at
>> org.springframework.beans.factory.support.AbstractBeanFactor
>> y.getBean(AbstractBeanFactory.java:197)
>>         at
>> org.springframework.beans.factory.support.DefaultListableBea
>> nFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761)
>>         at
>> org.springframework.context.support.AbstractApplicationConte
>> xt.finishBeanFactoryInitialization(AbstractApplicationContext.java:866)
>>         at
>> org.springframework.context.support.AbstractApplicationConte
>> xt.refresh(AbstractApplicationContext.java:542)
>>         at
>> org.springframework.boot.context.embedded.EmbeddedWebApplica
>> tionContext.refresh(EmbeddedWebApplicationContext.java:122)
>>         at
>> org.springframework.boot.SpringApplication.refresh(SpringApp
>> lication.java:737)
>>         at
>> org.springframework.boot.SpringApplication.refreshContext(Sp
>> ringApplication.java:370)
>>         at
>> org.springframework.boot.SpringApplication.run(SpringApplica
>> tion.java:314)
>>         at com.brocade.dcm.Application.main(Application.java:63)
>>         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>>         at
>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce
>> ssorImpl.java:62)
>>         at
>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe
>> thodAccessorImpl.java:43)
>>         at java.lang.reflect.Method.invoke(Method.java:498)
>>         at
>> org.springframework.boot.loader.MainMethodRunner.run(MainMet
>> hodRunner.java:48)
>>         at org.springframework.boot.loader.Launcher.launch(Launcher.
>> java:87)
>>         at org.springframework.boot.loader.Launcher.launch(Launcher.
>> java:50)
>>         at org.springframework.boot.loader.JarLauncher.main(JarLauncher
>> .java:51)
>> *Caused by: org.apache.ignite.IgniteIllegalStateException: Ignite
>> instance
>> with provided name doesn't exist. Did you call Ignition.start(..) to start
>> an Ignite instance? [name=ObjectManagerGrid]
>>         at org.apache.ignite.internal.IgnitionEx.grid(IgnitionEx.java:
>> 1376)
>>         at org.apache.ignite.Ignition.ignite(Ignition.java:530)
>>         at
>> org.apache.ignite.transactions.spring.SpringTransactionManag
>> er.afterPropertiesSet(SpringTransactionManager.java:357)
>>         at
>> org.springframework.beans.factory.support.AbstractAutowireCa
>> pableBeanFactory.invokeInitMethods(AbstractAuto
>> wireCapableBeanFactory.java:1687)
>>         at
>> org.springframework.beans.factory.support.AbstractAutowireCa
>> pableBeanFactory.initializeBean(AbstractAutowir
>> eCapableBeanFactory.java:1624)*
>>         ... 22 common frames omitted
>>
>> Thanks
>>
>>
>>
>> --
>> Sent from: http://apache-ignite-users.70518.x6.nabble.com/
>>
>
>

Re: IgniteSpringBean & Ignite SpringTransactionManager broken with 2.4?

Posted by Muthu <mu...@gmail.com>.
So looks like one fix may be to,

1. Have IgniteSpringBean publish an Ignite application event on Ignite
instance start from inside of its ' afterSingletonsInstantiated()' method (
@Override public void afterSingletonsInstantiated())

2. Then have SpringTransactionManager listen to the event & execute the
code currently in its 'afterPropertiesSet()' method ( @Override public void
afterPropertiesSet() throws Exception) by moving it to the event handler
method.

This way SpringTransactionManager can finish its intended custom
initialization AFTER ignite instance is started other wise the below
highlighted line will fail as its happening now,

    @Override public void afterPropertiesSet() throws Exception {
        assert ignite == null;

        if (cfgPath != null && cfg != null) {
            throw new IllegalArgumentException("Both 'configurationPath'
and 'configuration' are " +
                    "provided. Set only one of these properties if you need
to start a Ignite node inside of " +
                    "SpringCacheManager. If you already have a node
running, omit both of them and set" +
                    "'igniteInstanceName' property.");
        }

        if (cfgPath != null)
            ignite = IgniteSpring.start(cfgPath, springCtx);
        else if (cfg != null)
            ignite = IgniteSpring.start(cfg, springCtx);
        else
*            ignite = Ignition.ignite(igniteInstanceName);*

        if (transactionConcurrency == null)
            transactionConcurrency =
ignite.configuration().getTransactionConfiguration().getDefaultTxConcurrency();

        log = ignite.log();
    }

Regards,
Muthu

On Thu, May 24, 2018 at 8:58 PM, mlekshma <mu...@gmail.com> wrote:

> Hi,
>
> I see that with a change introduced in 2.4 in IgniteSpringBean to delay
> ignite instance start until all other spring beans are initialized may have
> broken Ignite  SpringTransactionManager
> <https://ignite.apache.org/releases/latest/javadoc/org/
> apache/ignite/transactions/spring/SpringTransactionManager.html>
> resulting in inability to configure it for Spring transaction abstraction
> of
> Ignite transactions. I really, badly need to find a way to work around
> this.
> Any ideas/suggestions anyone?
>
> Below is the line from  IgniteSpringBean
> <https://ignite.apache.org/releases/latest/javadoc/org/apache/ignite/
> IgniteSpringBean.html>
> java doc
> /*"Ignite instance is started after all other Spring beans have been
> initialized and right before Spring context is refreshed. That implies that
> it's not valid to reference IgniteSpringBean from any kind of Spring bean
> init methods like PostConstruct. If it's required to reference
> IgniteSpringBean for other bean initialization purposes, it should be done
> from a ContextRefreshedEvent listener method declared in that bean. "
> */
>
> The problem is since SpringTransactionManager implements
> org.springframework.beans.factory.InitializingBean & in the
> afterPropertiesSet() call that spring calls it tries to look for the
> igniteInstanceName that's specified but since the instance is started only
> AFTER all other Spring beans have been initialized, it fails with
> IgniteIllegalStateException,
>
> Please see below stack trace,
>
> lass]: Invocation of init method failed; nested exception is class
> org.apache.ignite.IgniteIllegalStateException: Ignite instance with
> provided
> name doesn't exist. Did you call Ignition.start(..) to start an Ignite
> instance? [name=ObjectManagerGrid]
>         at
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFac
> tory.initializeBean(AbstractAutowireCapableBeanFactory.java:1628)
>         at
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFac
> tory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555)
>         at
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFac
> tory.createBean(AbstractAutowireCapableBeanFactory.java:483)
>         at
> org.springframework.beans.factory.support.AbstractBeanFactory$1.
> getObject(AbstractBeanFactory.java:306)
>         at
> org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.
> getSingleton(DefaultSingletonBeanRegistry.java:230)
>         at
> org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(
> AbstractBeanFactory.java:302)
>         at
> org.springframework.beans.factory.support.AbstractBeanFactory.getBean(
> AbstractBeanFactory.java:197)
>         at
> org.springframework.beans.factory.support.DefaultListableBeanFactory.
> preInstantiateSingletons(DefaultListableBeanFactory.java:761)
>         at
> org.springframework.context.support.AbstractApplicationContext.
> finishBeanFactoryInitialization(AbstractApplicationContext.java:866)
>         at
> org.springframework.context.support.AbstractApplicationContext.refresh(
> AbstractApplicationContext.java:542)
>         at
> org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.
> refresh(EmbeddedWebApplicationContext.java:122)
>         at
> org.springframework.boot.SpringApplication.refresh(
> SpringApplication.java:737)
>         at
> org.springframework.boot.SpringApplication.refreshContext(
> SpringApplication.java:370)
>         at
> org.springframework.boot.SpringApplication.run(SpringApplication.java:314)
>         at com.brocade.dcm.Application.main(Application.java:63)
>         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>         at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:
> 62)
>         at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(
> DelegatingMethodAccessorImpl.java:43)
>         at java.lang.reflect.Method.invoke(Method.java:498)
>         at
> org.springframework.boot.loader.MainMethodRunner.run(
> MainMethodRunner.java:48)
>         at org.springframework.boot.loader.Launcher.launch(
> Launcher.java:87)
>         at org.springframework.boot.loader.Launcher.launch(
> Launcher.java:50)
>         at org.springframework.boot.loader.JarLauncher.main(
> JarLauncher.java:51)
> *Caused by: org.apache.ignite.IgniteIllegalStateException: Ignite instance
> with provided name doesn't exist. Did you call Ignition.start(..) to start
> an Ignite instance? [name=ObjectManagerGrid]
>         at org.apache.ignite.internal.IgnitionEx.grid(IgnitionEx.
> java:1376)
>         at org.apache.ignite.Ignition.ignite(Ignition.java:530)
>         at
> org.apache.ignite.transactions.spring.SpringTransactionManager.
> afterPropertiesSet(SpringTransactionManager.java:357)
>         at
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFac
> tory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1687)
>         at
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFac
> tory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624)*
>         ... 22 common frames omitted
>
> Thanks
>
>
>
> --
> Sent from: http://apache-ignite-users.70518.x6.nabble.com/
>