11 Replies Latest reply on Mar 14, 2013 4:44 PM by rhauch

    InvalidItemStateException when trying to add a node

    satyakishor.m

      We have a batch process that reads a big excel file and creates nodes from the excel contents. I am running into InvalidItemStateException when running the batch process. But my code works fine if I comment out the versioning part in the below code or a small excel file is being used.

       

      Following is the method that was throwing the InvalidItemStateException.

       

      public DetailNode createChild(Token token, Reference parent, NodeType type, String name, Workspace workspace) {

               Session session = null;

                          DetailNode detailNode = null;

                          try {

                                    String cleanName = cleanPath(name);

                                    session = this.login(token, workspace);

                     VersionManager vm = session.getWorkspace().getVersionManager();

                                    Node parentNode = session.getNode(parent.getPath());

                     vm.checkout(parent.getPath());

                                    String jcrNodeType = BidiJermsToJCRTypeMapping.getTypemapping().inverseBidiMap().get(type).toString();

                                    Node childNode = parentNode.addNode(cleanName, jcrNodeType);

                                    session.save();

                     vm.checkin(childNode.getPath());

                     vm.checkin(parentNode.getPath());

                                    detailNode = getDetailNode(childNode);

                          } catch (Exception e) {

                                    log.error(e.getMessage(), e);              

                          } finally {

                                    if(session != null) {

                                              session.logout();

                                    }

                          }

                          return detailNode;

      }

       

      Following is the exception stack trace.

       

      14:08:30,863 INFO  [stdout] (EJB default - 1) 2013-03-13 14:08:30,847 [EJB default - 1] ERROR c.j.s.j.jcr.impl.DaoImpl    - This session tried to save changes to node with key 'cc21f74317f1e762563a66-33d4-434e-9172-50d49e7b863f', but it was removed by another session. 

      14:08:30,863 INFO  [stdout] (EJB default - 1) org.modeshape.jcr.cache.DocumentNotFoundException: cc21f74317f1e762563a66-33d4-434e-9172-50d49e7b863f

      14:08:30,863 INFO  [stdout] (EJB default - 1)           at org.modeshape.jcr.cache.document.WritableSessionCache.persistChanges(WritableSessionCache.java:844) ~[modeshape-jcr-3.1.2.Final.jar!/:3.1.2.Final]

      14:08:30,863 INFO  [stdout] (EJB default - 1)           at org.modeshape.jcr.cache.document.WritableSessionCache.save(WritableSessionCache.java:518) ~[modeshape-jcr-3.1.2.Final.jar!/:3.1.2.Final]

      14:08:30,879 INFO  [stdout] (EJB default - 1)           at org.modeshape.jcr.JcrSession.save(JcrSession.java:978) ~[modeshape-jcr-3.1.2.Final.jar!/:3.1.2.Final]

      14:08:30,879 INFO  [stdout] (EJB default - 1) Wrapped by: javax.jcr.InvalidItemStateException: This session tried to save changes to node with key 'cc21f74317f1e762563a66-33d4-434e-9172-50d49e7b863f', but it was removed by another session.

      14:08:30,879 INFO  [stdout] (EJB default - 1)           at org.modeshape.jcr.JcrSession.save(JcrSession.java:985) ~[modeshape-jcr-3.1.2.Final.jar!/:3.1.2.Final]

      14:08:30,894 INFO  [stdout] (EJB default - 1)           at c.j.s.j.jcr.DaoImpl.createChild(DaoImpl.java:458) ~[jerms-impl.jar:na]

       

      I am not sure exactly why I am getting this error. Am I using the versioning correctly??

        • 1. Re: InvalidItemStateException when trying to add a node
          rhauch

          Are you using multiple threads? What is your ModeShape repository configuration and Infinispan configuration?

          • 2. Re: InvalidItemStateException when trying to add a node
            satyakishor.m

            No, we are not using multiple threads for batch processing.

             

            Following is the modeshape and infinispan configuration we were using

             

            <subsystem xmlns="urn:jboss:domain:infinispan:1.2" default-cache-container="hibernate">

                      <cache-container name="modeshape">

                                <local-cache name="SMALL">

                                          <transaction mode="FULL_XA"/>

                                          <eviction strategy="LIRS" max-entries="20000"/>

                                          <store class="org.infinispan.loaders.jdbc.stringbased.JdbcStringBasedCacheStore" passivation="false" fetch-state="false" purge="false">

                                                    <write-behind flush-lock-timeout="1000" thread-pool-size="15"/>

                                                    <property name="stringsTableNamePrefix">

                                                              UJ.JERMS

                                                    </property>

                                                    <property name="idColumnName">

                                                              ID

                                                    </property>

                                                    <property name="dataColumnName">

                                                              DATA_X

                                                    </property>

                                                    <property name="timestampColumnName">

                                                              CREATE_TS

                                                    </property>

                                                    <property name="timestampColumnType">

                                                              BIGINT

                                                    </property>

                                                    <property name="connectionFactoryClass">

                                                              org.infinispan.loaders.jdbc.connectionfactory.ManagedConnectionFactory

                                                    </property>

                                                    <property name="datasourceJndiLocation">

                                                              java:jboss/jdbc/jerms

                                                    </property>

                                                    <property name="idColumnType">

                                                              VARCHAR(254)

                                                    </property>

                                                    <property name="dataColumnType">

                                                              BLOB(1 M)

                                                    </property>

                                                    <property name="dropTableOnExit">

                                                              false

                                                    </property>

                                                    <property name="createTableOnStart">

                                                              false

                                                    </property>

                                          </store>

                                </local-cache>

                                <local-cache name="LARGE">

                                          <transaction mode="FULL_XA"/>

                                          <eviction strategy="LIRS" max-entries="100"/>

                                          <store class="org.infinispan.loaders.jdbc.stringbased.JdbcStringBasedCacheStore" passivation="false" fetch-state="false" purge="false">

                                                    <write-behind flush-lock-timeout="1000" thread-pool-size="2"/>

                                                    <property name="stringsTableNamePrefix">

                                                              UJ.JERMS

                                                    </property>

                                                    <property name="idColumnName">

                                                              ID

                                                    </property>

                                                    <property name="dataColumnName">

                                                              DATA_X

                                                    </property>

                                                    <property name="timestampColumnName">

                                                              CREATE_TS

                                                    </property>

                                                    <property name="timestampColumnType">

                                                              BIGINT

                                                    </property>

                                                    <property name="connectionFactoryClass">

                                                              org.infinispan.loaders.jdbc.connectionfactory.ManagedConnectionFactory

                                                    </property>

                                                    <property name="datasourceJndiLocation">

                                                              java:jboss/jdbc/jerms

                                                    </property>

                                                    <property name="idColumnType">

                                                              VARCHAR(254)

                                                    </property>

                                                    <property name="dataColumnType">

                                                              BLOB(10 M)

                                                    </property>

                                                    <property name="dropTableOnExit">

                                                              false

                                                    </property>

                                                    <property name="createTableOnStart">

                                                              false

                                                    </property>

                                          </store>

                                </local-cache>

                      </cache-container>

                      <cache-container name="modeshape-index" start="EAGER">

                                <local-cache name="INDEX" batching="true">

                                          <transaction mode="NONE"/>

                                          <eviction strategy="LIRS" max-entries="10000"/>

                                          <store class="org.infinispan.loaders.jdbc.stringbased.JdbcStringBasedCacheStore" passivation="false" fetch-state="false" purge="false">

                                                    <write-behind flush-lock-timeout="1000" thread-pool-size="15"/>

                                                    <property name="key2StringMapperClass">

                                                              org.infinispan.lucene.LuceneKey2StringMapper

                                                    </property>

                                                    <property name="stringsTableNamePrefix">

                                                              UJ.JERMS

                                                    </property>

                                                    <property name="idColumnName">

                                                              ID

                                                    </property>

                                                    <property name="dataColumnName">

                                                              DATA_X

                                                    </property>

                                                    <property name="timestampColumnName">

                                                              CREATE_TS

                                                    </property>

                                                    <property name="timestampColumnType">

                                                              BIGINT

                                                    </property>

                                                    <property name="connectionFactoryClass">

                                                              org.infinispan.loaders.jdbc.connectionfactory.ManagedConnectionFactory

                                                    </property>

                                                    <property name="datasourceJndiLocation">

                                                              java:jboss/jdbc/jerms

                                                    </property>

                                                    <property name="idColumnType">

                                                              VARCHAR(254)

                                                    </property>

                                                    <property name="dataColumnType">

                                                              BLOB(100 k)

                                                    </property>

                                                    <property name="dropTableOnExit">

                                                              false

                                                    </property>

                                                    <property name="createTableOnStart">

                                                              false

                                                    </property>

                                          </store>

                                </local-cache>

                      </cache-container>

            </subsystem>

             

             

            <subsystem xmlns="urn:jboss:domain:modeshape:1.0">

                      <repository name="jerms" cache-name="SMALL" cache-container="modeshape" enable-monitoring="false">

                                <indexing mode="ASYNC" systemContentMode="SYNC" rebuild-upon-startup="ALWAYS"/>

                                <cache-index-storage data-cache-name="INDEX" metadata-cache-name="INDEX" cache-container="modeshape-index"/>

                                <cache-binary-storage data-cache-name="LARGE" metadata-cache-name="SMALL" cache-container="modeshape"/>

                                <text-extractors>

                                          <text-extractor name="tika-extractor" classname="tika" module="org.modeshape.extractor.tika"/>

                                </text-extractors>

                      </repository>

            </subsystem>

            • 3. Re: InvalidItemStateException when trying to add a node
              rhauch

              A couple of things.

               

              Is the code you supplied being run from within a transaction? For example, is it being run from within an EJB with container-managed or user transactions?

               

              Second, I don't think it's a good idea to use a cache for both binary storage and content. We've not tested this case, and in fact they are each designed to not consider that the cache is used by other systems. It is possible that the some entries might be removed by one of these when it is still needed in the other. (I'm not convinced this is causing the problem, but it absolutely could cause problems in other cases/scenarios.)

              • 4. Re: InvalidItemStateException when trying to add a node
                satyakishor.m

                Is the code you supplied being run from within a transaction? For example, is it being run from within an EJB with container-managed or user transactions?

                      No

                 

                Second, I don't think it's a good idea to use a cache for both binary storage and content. We've not tested this case, and in fact they are each designed to not consider that the cache is used by other systems. It is possible that the some entries might be removed by one of these when it is still needed in the other. (I'm not convinced this is causing the problem, but it absolutely could cause problems in other cases/scenarios.)

                     What approach you suggest here. I want to test your suggested configuration to see whether I am running into this exception or not.

                • 5. Re: InvalidItemStateException when trying to add a node
                  rhauch

                  Can I ask where or how this code is being called? Servlet?

                   

                   

                  Second, I don't think it's a good idea to use a cache for both binary storage and content. We've not tested this case, and in fact they are each designed to not consider that the cache is used by other systems. It is possible that the some entries might be removed by one of these when it is still needed in the other. (I'm not convinced this is causing the problem, but it absolutely could cause problems in other cases/scenarios.)

                       What approach you suggest here. I want to test your suggested configuration to see whether I am running into this exception or not.

                   

                  I don't grok the names of the caches, so bear with me. Since "LARGE" is already used for the binary store's data cache, I'd suggest just keep using "SMALL" for the metadata cache. Then create a new cache (e.g., "CONTENT") and refer to it in the "cache-name" attribute of the "repository" element.

                   

                  I'd also suggest adding a "locking" attribute with value "PESSIMISTIC" on the "transactions" element in the new "CONTENT" cache.

                  • 6. Re: InvalidItemStateException when trying to add a node
                    satyakishor.m

                    We are calling the batch code from primefaces backing bean method asynchronously using EJB @Asynchronous annotation. I will try to use the configuration you have suggested and will test.

                    • 7. Re: InvalidItemStateException when trying to add a node
                      rhauch

                      Are you sure your EJB is not actually running in a transaction? IIRC, if an EJB doesn't specify the transactional behavior, the container manages the transaction automatically.

                       

                      If that's the case, then your problem may be related to MODE-1822. The exception reported in that issue is different, but I believe that's because you're doing something a little different than what's described in the issue, and the error varies with which method first runs into the missing data. (I vaguely remember an exception similar to yours when working on MODE-1822.)

                       

                      BTW, I should have asked this before: The nodes that you're checking out are "mix:versionable", right? I think you would have gotten an error stating as much if the node was not versionable. It would be interesting to see the node types your using - the "on parent versioning" (or "opv") qualifier on the node types' property definitions and child node definitions greatly affects how a node (and it's descedants) are versioned.

                      • 8. Re: InvalidItemStateException when trying to add a node
                        satyakishor.m

                        Are you sure your EJB is not actually running in a transaction? IIRC, if an EJB doesn't specify the transactional behavior, the container manages the transaction automatically.

                        We are using @TransactionAttribute(TransactionAttributeType.NEVER) annotation for the service class. I believe this means that the service methods are not transactional.

                         

                        Also all of our nodes are mix:versionable. Did you check my problem description?. I did mention that this problem is coming only if I try to upload a huge excel spread sheet that can insert more than 500 nodes. If I use a small excel sheet with say 100 nodes I don't run into this issue.

                        • 9. Re: InvalidItemStateException when trying to add a node
                          rhauch

                          I did read the problem description, but you also said that it works if you comment out the versioning-related code.

                           

                          At this point, I see nothing that looks wrong or invalid. Is there any way you can create a self-contained project that replicates the problem? If so, please log an issue in our JIRA. Thanks.

                          • 10. Re: InvalidItemStateException when trying to add a node
                            satyakishor.m

                            I don't grok the names of the caches, so bear with me. Since "LARGE" is already used for the binary store's data cache, I'd suggest just keep using "SMALL" for the metadata cache. Then create a new cache (e.g., "CONTENT") and refer to it in the "cache-name" attribute of the "repository" element.

                             

                            I'd also suggest adding a "locking" attribute with value "PESSIMISTIC" on the "transactions" element in the new "CONTENT" cache.

                            I tried with the above configuration and I am still running into the same exception (I didn't use the locking attribute, as I am running to exception). I will try to create a simple project and try to reproduce the issue.

                             

                            At this point, the only options we have are either to turn off the versioning or use the small excel files to upload data into repository.

                            • 11. Re: InvalidItemStateException when trying to add a node
                              rhauch

                              Can you replicate this with a small, self-contained test case (even a simple WAR-based one)? If so, then please log a defect and attach your test.