3 Replies Latest reply on Feb 28, 2013 11:51 AM by Horia Chiorean

    Session save not seen in query

    SEBASTIEN MICHEA Newbie

      Hello,

       

      I use 3.1.2.Final on jboss 7.1.1

       

      and i have a document type like this :

       

      [nbe:document] > nt:file

          - scannDate (DATE) mandatory COPY

          - period (STRING) mandatory COPY

          - journal (STRING) mandatory COPY

          - status (STRING) mandatory COPY

          - rejectionReason (STRING) COPY

          - originalFilename (STRING) COPY

          - originalMD5 (STRING) COPY

          - pieces (REFERENCE) multiple COPY

       

       

      When i create a document, i set its status to UPLOADED and it appears correctly in my queries.

      Then i have a job that update its status to ACKNOLEDGED.

      To create or update nodes i use a stateless bean with a locl instance of JCRSession. I save then logout of the session each time i create or update a node and instanciate a new session in the bean whenever the session is not live.

      I can see using the rest or webdav app that the status of the node is indeed ACKNOLEDGED and this also appear when i query on status ACKNOLEDGED in my app.

      The problem i encounter is that unless i restart my app the document will still appear when i query on statut UPLOADED (i use JCR-SQL2)

      Its like when executing query the document is both in ACKNOLEDGED and UPLOADED state...
      Here is the plan i can see in the JCRQueryResult.result.plan

       

       

      Access [nbe:document]

        Project [nbe:document] <PROJECT_COLUMN_TYPES=[DATE, STRING, STRING, STRING, STRING, STRING, STRING, REFERENCE, STRING, STRING, DATE, STRING, STRING, STRING, DOUBLE, STRING, LONG], PROJECT_COLUMNS=[[nbe:document].scannDate AS [nbe:document.scannDate], [nbe:document].period AS [nbe:document.period], [nbe:document].journal AS [nbe:document.journal], [nbe:document].status AS [nbe:document.status], [nbe:document].rejectionReason AS [nbe:document.rejectionReason], [nbe:document].originalFilename AS [nbe:document.originalFilename], [nbe:document].originalMD5 AS [nbe:document.originalMD5], [nbe:document].pieces AS [nbe:document.pieces], [nbe:document].[jcr:primaryType] AS [nbe:document.jcr:primaryType], [nbe:document].[jcr:mixinTypes] AS [nbe:document.jcr:mixinTypes], [nbe:document].[jcr:created] AS [nbe:document.jcr:created], [nbe:document].[jcr:createdBy] AS [nbe:document.jcr:createdBy], [nbe:document].[jcr:path] AS [nbe:document.jcr:path], [nbe:document].[jcr:name] AS [nbe:document.jcr:name], [nbe:document].[jcr:score] AS [nbe:document.jcr:score], [nbe:document].[mode:localName] AS [nbe:document.mode:localName], [nbe:document].[mode:depth] AS [nbe:document.mode:depth]]>

          Select [nbe:document] <SELECT_CRITERIA=PATH([nbe:document]) LIKE '/accounts/NA02/documents/%'>

            Select [nbe:document] <SELECT_CRITERIA=[nbe:document].period LIKE '%201302%'>

              Select [nbe:document] <SELECT_CRITERIA=[nbe:document].status = 'UPLOADED'>

                Select [nbe:document] <SELECT_CRITERIA=[nbe:document].[jcr:primaryType] = 'nbe:document'>

                  Source [nbe:document] <SOURCE_NAME=__ALLNODES__, SOURCE_ALIAS=nbe:document, SOURCE_COLUMNS=[jcr:frozenUuid(STRING), mode:sharedUuid(REFERENCE), mode:sessionScope(BOOLEAN), jcr:defaultValues(STRING), mode:projectedNodeKey(STRING), jcr:frozenPrimaryType(STRING), jcr:mixinTypes(STRING), jcr:defaultPrimaryType(STRING), datePiece(DATE), documents(REFERENCE), rejectionReason(STRING), noFacture(STRING), comptable(STRING), jcr:statement(STRING), jcr:lastModifiedBy(STRING), jcr:mimeType(STRING), originalFilename(STRING), jcr:hasOrderableChildNodes(BOOLEAN), jcr:etag(STRING), typePiece(STRING), jcr:encoding(STRING), jcr:root(REFERENCE), jcr:supertypes(STRING), jcr:successors(REFERENCE), jcr:primaryItemName(STRING), scannDate(DATE), jcr:hold(STRING), jcr:workspace(STRING), jcr:description(STRING), jcr:primaryType(STRING), mode:initializationState(STRING), tiers(STRING), mode:externalNodeKey(STRING), mode:derivedFrom(STRING), mode:isHeldBySession(BOOLEAN), jcr:baseVersion(REFERENCE), jcr:lastModified(DATE), jcr:mergeFailed(REFERENCE), jcr:requiredPrimaryTypes(STRING), mode:derivedAt(DATE), jcr:multiple(BOOLEAN), mode:generated(BOOLEAN), jcr:activityTitle(STRING), jcr:lifecyclePolicy(REFERENCE), jcr:isMixin(BOOLEAN), devise(STRING), jcr:availableQueryOperators(STRING), jcr:childVersionHistory(REFERENCE), jcr:autoCreated(BOOLEAN), jcr:content(REFERENCE), period(STRING), mode:alias(STRING), jcr:createdBy(STRING), jcr:isFullTextSearchable(BOOLEAN), jcr:uuid(STRING), jcr:onParentVersion(STRING), journal(STRING), mode:expirationDate(DATE), jcr:lockIsDeep(BOOLEAN), jcr:isDeep(BOOLEAN), jcr:copiedFrom(REFERENCE), dateTransmission(DATE), jcr:title(STRING), jcr:isAbstract(BOOLEAN), jcr:versionHistory(REFERENCE), jcr:versionableUuid(STRING), refGED(STRING), jcr:predecessors(REFERENCE), jcr:lockOwner(STRING), status(STRING), exercice(STRING), mode:sha1(STRING), jcr:repository(STRING), jcr:created(DATE), jcr:frozenMixinTypes(STRING), mode:lockedKey(STRING), jcr:text(STRING), jcr:host(STRING), jcr:configuration(REFERENCE), jcr:port(STRING), mode:workspace(STRING), pieces(REFERENCE), jcr:nodeTypeName(STRING), originalMD5(STRING), jcr:isQueryable(BOOLEAN), jcr:data(BINARY), jcr:language(STRING), jcr:isQueryOrderable(BOOLEAN), jcr:isCheckedOut(BOOLEAN), jcr:mandatory(BOOLEAN), jcr:protected(BOOLEAN), jcr:protocol(STRING), jcr:sameNameSiblings(BOOLEAN), jcr:requiredType(STRING), montantTTC(STRING), mode:lockingSession(STRING), jcr:messageId(STRING), mois(STRING), jcr:id(REFERENCE), mode:uri(STRING), jcr:valueConstraints(STRING), jcr:retentionPolicy(REFERENCE), jcr:activity(REFERENCE), dateEcheance(DATE), libelle(STRING), jcr:currentLifecycleState(STRING), jcr:path(STRING), jcr:name(STRING), jcr:score(DOUBLE), mode:localName(STRING), mode:depth(LONG)]>

       

      And the result i get in JCRQueryResult.result.tuple

       

      [2013-02-13T00:00:00.000+01:00, 201302, AC, ACKNOWLEDGED, null, C:\tmp\data\docs\20130213\NA02\20130213_PM_NA02_AC_201302_00234.pdf, null, null, {http://www.business-expert.com/jcr/nbe/1.0}document, [Ljava.lang.Object;@65312b7c, 2013-02-27T08:21:43.090+01:00, admin, /{}accounts/{}NA02/{}documents/{}201302/{}AC/{}20130213_PM_NA02_AC_201302_00234.pdf, {}20130213_PM_NA02_AC_201302_00234.pdf, null, 20130213_PM_NA02_AC_201302_00234.pdf, 6, /{}accounts/{}NA02/{}documents/{}201302/{}AC/{}20130213_PM_NA02_AC_201302_00234.pdf @ 6b001687505d64a111fe4a-6291-4db4-8c08-f7499ec7d9be, 2.455288887023926]

       

       

      here is my standalone.xml

       

       

                  <cache-container name="modeshape">

                      <local-cache name="nbeportal">

                          <transaction mode="NON_XA"/>

                          <file-store relative-to="jboss.server.data.dir" path="modeshape/store/nbeportal" passivation="false" purge="false"/>

                      </local-cache>

                  </cache-container>

       

       

                      <security-domain name="modeshape-security" cache-type="default">

                          <authentication>

                              <login-module code="UsersRoles" flag="required">

                                  <module-option name="usersProperties" value="modeshape-users.properties"/>

                                  <module-option name="rolesProperties" value="modeshape-roles.properties"/>

                              </login-module>

                          </authentication>

                      </security-domain>

       

       

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

                  <repository name="nbeportal" cache-name="nbeportal" cache-container="modeshape">

                      <indexing rebuild-upon-startup="ALWAYS"/>

                  </repository>

              </subsystem>

       

      Here what i tried until now, without success :
      - do not loggout of the session (i cant see what is the effect of logging out)

      - change the stateless bean to a singleton

      - put the session object static

      - call the rebuildIndex method after update is performed

       

      I'm bit stuck here and for now we have to restart the production server after any update ... any idea ?

       

      Also some more generic questions:
      - As you see i rebuild all the indexes at startup (if not my queries just cant see anything in the repo, even the webdav or rest app tell me the repo is empty)... i guess i should not do that and might have to store indexes in files or somewhere but i dont really understand how this works.
      - When we perform tests we often have to clear the repository, for this we delete everything in data/modeshape/store is that the correct way ?

       

      Thank you in advance

        • 1. Re: Session save not seen in query
          Randall Hauch Master

          Are you saving the session after you update the property? If not, the session that makes the change will still see the (transient) change, but when your component logs out of the session those transient changes will be lost. Perhaps you could share a bit of your code that is updating the property.

           

          Here what i tried until now, without success :

          - do not loggout of the session (i cant see what is the effect of logging out)

          - change the stateless bean to a singleton

           

          These things should have no effect on the behavior.

           

           

          - put the session object static

           

          This is actually a bad thing to do.

           

           

          - call the rebuildIndex method after update is performed

           

          This should be unnecessary. The fact that it does nothing suggests there is another problem. (I still suspect the changes are not being saved.) Are you using clustering, or is this just a single web app?

           

          As for your configuration, you should define the index storage to ensure the indexes are stored in the location you expect. Here's an example:

           

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

            <repository name="sample" ...>

               <-- ... -->

              <local-file-index-storage

                        path="modeshape/sample/indexes"

                        relative-to="jboss.server.data.dir"

                        access-type="auto"

                        locking-strategy="native">

              </local-file-index-storage>

              <-- ... -->

            </repository>

          </subsystem>

           

          I'd also suggest trying with 3.1.3.Final, which actually is already available in the JBoss Maven repository but for which I'm still writing the announcements, blog posts, and updating the websites. It includes quite a few fixes, a few of which may affect what you're doing.

          • 2. Re: Session save not seen in query
            SEBASTIEN MICHEA Newbie

            Hi Randall,

             

            Thank you for your answer.

            We do not use clustering. We do save the changes, and we the change are seen in other sessions after transaction is commited (we check the status withe modeshape-rest, while in debug mode).

             

            We found a workaround that works 99.9% of the time, it is to (update, save and logout) twice.

             

            The code is a bit long but i'll share here :

             

            the job that updates the document satus is :

             

            @Startup @Singleton

            public class JobTransfertPrimo implements Job {

                ...

                @Inject

                DocumentService documentService;

                ...

                public JobExecutionResult execute(String parameter) {

                      ...

                      Document document= documentService.findByFileName(fileName);

                      document.setStatus(DocumentStatusEnum.ACKNOWLEDGED);

                      documentService.update(document);

                      ...

                }

                ...

            }

             

             

             

            @Stateless

            public class DocumentService extends JCRPersistenceService<Document> {

                ...

                public Document findByFileName(String filename) {

                String statement = "SELECT * from [nbe:document] WHERE [jcr:name] = '"+filename+"'";

                    ..

                query = getSession().getWorkspace().getQueryManager().createQuery(statement, "JCR-SQL2");

                    QueryResult resultq=query.execute();

                    nodes = resultq.getNodes();

                    ..     

                 }

             

             

             

            public class JCRPersistenceService<E extends JCREntity> extends BaseService {

                public Session getSession() throws LoginException, RepositoryException, NamingException{

                  if(session==null || !session.isLive()){

                        InitialContext context = new InitialContext();

                        javax.jcr.Repository repository = (javax.jcr.Repository) context

                                .lookup(ParamBean.getInstance().getProperty("jcr.jndiName",

                                        "java:/jcr/nbeportal"));

                        session = repository.login(cred);

                    }

                    return session;

                  }

                ...

                @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)

                public void update(E e) throws BusinessException {

                    try{

                        e.merge(getSession().getValueFactory());//update properties of the node

                        getSession().save();

                       

                    } catch (Exception e1) {

                        throw new BusinessEntityException("error while saving JCR session",e1);

                    }

                 }

                 ...

            }

             

            I will try the 1.3.1. and we'll report if it solves the pb or not.

             

            Thank you

            • 3. Re: Session save not seen in query
              Horia Chiorean Master

              Is every node operation happening in the same workspace ("default") ? Reason I'm asking is that nodes/updates to nodes will only be indexed if the session that made the changes is from the same workspace as the node.

               

              Something else you can try: set ModeShape debug level to TRACE and looks for messages like:  "index for "{0}" workspace: UPDATE {1}", after the job thread has saved the session. That would indicate the changes are updated in the indexes.