javaignitegridgain

Ignite fails DELETE query in transaction with "DML statements are not allowed inside a transaction over cache(s) with TRANSACTIONAL atomicity mode"


While trying to execute a DELETE query on a cache with TRANSACTIONAL atomicity mode, Ignite fails it with the error,

javax.cache.CacheException: DML statements are not allowed inside a transaction over cache(s) with TRANSACTIONAL atomicity mode (change atomicity mode to TRANSACTIONAL_SNAPSHOT or disable this error message with system property "-DIGNITE_ALLOW_DML_INSIDE_TRANSACTION=true")

On Ignite documentation there is no reference to such a restriction. In addition both the documentation & the docs clearly mention that "TRANSACTIONAL_SNAPSHOT" is deprecated & would be removed. Yet the error message suggests using that as an option,

TRANSACTIONAL_SNAPSHOT is deprecated since 2.12 and will be removed in the next releases.

I can add the other suggestion of adding the system property, but would love to better understand what is the support & why this error as i didn't expect that DELETE is not possible inside transactions.

Thanks

Below is the error trace,

javax.cache.CacheException: DML statements are not allowed inside a transaction over cache(s) with TRANSACTIONAL atomicity mode (change atomicity mode to TRANSACTIONAL_SNAPSHOT or disable this error message with system property "-DIGNITE_ALLOW_DML_INSIDE_TRANSACTION=true")

 at org.apache.ignite.internal.processors.cache.IgniteCacheProxyImpl.query(IgniteCacheProxyImpl.java:828)

 at org.apache.ignite.internal.processors.cache.IgniteCacheProxyImpl.query(IgniteCacheProxyImpl.java:761)

 at org.apache.ignite.internal.processors.cache.GatewayProtectedCacheProxy.query(GatewayProtectedCacheProxy.java:394)

 at com.xxx.xxx.domain.repositories.rbac.RbacCustomRepositoryImpl.removeRoleByUserId(RbacCustomRepositoryImpl.java:976)

 at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

 at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

 at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

 at java.base/java.lang.reflect.Method.invoke(Method.java:566)

 at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.executeMethodOn(RepositoryFactorySupport.java:515)

 at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:490)

 at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:477)

 at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)

 at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:56)

 at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)

 at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)

 at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)

 at org.springframework.data.repository.core.support.SurroundingTransactionDetectorMethodInterceptor.invoke(SurroundingTransactionDetectorMethodInterceptor.java:57)

 at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)

 at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)

 at com.sun.proxy.$Proxy205.removeRoleByUserId(Unknown Source)

 at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

 at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

 at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

 at java.base/java.lang.reflect.Method.invoke(Method.java:566)

 at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:333)

 at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)

 at com.sun.proxy.$Proxy113.removeRoleByUserId(Unknown Source)

 at com.xxx.xxx.rbac.server.util.RbacPersistenceUtil.modifyUser(RbacPersistenceUtil.java:621)

 at com.xxx.xxx.rbac.server.controller.RbacController.modifyUser(RbacController.java:1818)

 at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

 at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

 at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

 at java.base/java.lang.reflect.Method.invoke(Method.java:566)

 at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205)

 at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:133)

 at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:97)

 at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827)

 at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738)

 at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)

 at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:967)

 at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:901)

 at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)

 at org.springframework.web.servlet.FrameworkServlet.doPut(FrameworkServlet.java:883)

 at javax.servlet.http.HttpServlet.service(HttpServlet.java:664)

 at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)

 at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)

 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)

 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)

 at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)

 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)

 at org.springframework.boot.web.filter.ApplicationContextHeaderFilter.doFilterInternal(ApplicationContextHeaderFilter.java:55)

 at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)

 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)

 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)

 at org.springframework.boot.actuate.trace.WebRequestTraceFilter.doFilterInternal(WebRequestTraceFilter.java:111)

 at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)

 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)

 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)

 at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99)

 at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)

 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)

 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)

 at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:109)

 at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)

 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)

 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)

 at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:93)

 at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)

 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)

 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)

 at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197)

 at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)

 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)

 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)

 at org.springframework.boot.actuate.autoconfigure.MetricsFilter.doFilterInternal(MetricsFilter.java:103)

 at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)

 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)

 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)

 at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)

 at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)

 at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:493)

 at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)

 at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)

 at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)

 at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)

 at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:800)

 at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)

 at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:800)

 at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1471)

 at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)

 at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)

 at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)

 at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)

 at java.base/java.lang.Thread.run(Thread.java:829)

Caused by: org.apache.ignite.internal.processors.query.IgniteSQLException: DML statements are not allowed inside a transaction over cache(s) with TRANSACTIONAL atomicity mode (change atomicity mode to TRANSACTIONAL_SNAPSHOT or disable this error message with system property "-DIGNITE_ALLOW_DML_INSIDE_TRANSACTION=true")

 at org.apache.ignite.internal.processors.query.h2.IgniteH2Indexing.executeDml(IgniteH2Indexing.java:1219)

 at org.apache.ignite.internal.processors.query.h2.IgniteH2Indexing.querySqlFields(IgniteH2Indexing.java:1153)

 at org.apache.ignite.internal.processors.query.GridQueryProcessor$4.applyx(GridQueryProcessor.java:2542)

 at org.apache.ignite.internal.processors.query.GridQueryProcessor$4.applyx(GridQueryProcessor.java:2538)

 at org.apache.ignite.internal.util.lang.IgniteOutClosureX.apply(IgniteOutClosureX.java:35)

 at org.apache.ignite.internal.processors.query.GridQueryProcessor.executeQuery(GridQueryProcessor.java:3054)

 at org.apache.ignite.internal.processors.query.GridQueryProcessor.lambda$querySqlFields$1(GridQueryProcessor.java:2558)

 at org.apache.ignite.internal.processors.query.GridQueryProcessor.executeQuerySafe(GridQueryProcessor.java:2596)

 at org.apache.ignite.internal.processors.query.GridQueryProcessor.querySqlFields(GridQueryProcessor.java:2532)

 at org.apache.ignite.internal.processors.query.GridQueryProcessor.querySqlFields(GridQueryProcessor.java:2459)

 at org.apache.ignite.internal.processors.cache.IgniteCacheProxyImpl.query(IgniteCacheProxyImpl.java:813)

 ... 94 common frames omitted

Solution

  • I'm not sure what to add. As per the documentation you link to:

    [TRANSACTIONAL] Enables support for ACID-compliant transactions executed via the key-value API. SQL transactions are not supported.

    You can do a SQL select to find the records you want to delete and then use the key-value delete operation. Something like:

    try (var c = cache.query(new SqlFieldsQuery("select _key from person where ... "))) {
        var toDelete = c.getAll().stream()
                .map(x -> (Long) x.get(0))
                .collect(Collectors.toSet());
        cache.removeAll(toDelete);
    }
    

    (Yes, this is not semantically identical.)