5 Replies Latest reply on Aug 3, 2014 10:17 PM by ncavallo33

    Errors while restoring the ModeShape repository

    vpeddireddi

      I'm trying to perform backup and restore operations using ModeShape API, running into some issues. Please find the details below, appreciate any inputs


      Cache configuration in standalone.xml

      <cache-container name="modeshape">

                      <local-cache name="cache_instance_1">

                          <transaction mode="NON_XA"/>

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

                          <string-keyed-jdbc-store datasource="java:/jdbc/modeshape" preload="false" passivation="false" purge="false">

                              <property name="databaseType">

                                  postgres

                              </property>

                              <property name="createTableOnStart">

                                  true

                              </property>

                              <string-keyed-table prefix="stringbased">

                                  <id-column name="id" type="VARCHAR(200)"/>

                                  <data-column name="data" type="BYTEA"/>

                                  <timestamp-column name="version" type="BIGINT"/>

                              </string-keyed-table>

                          </string-keyed-jdbc-store>

                      </local-cache>

      </cache-container>

      Repository backup code


      InitialContext initialContext = new InitialContext();

              Repository repo =  (Repository)initialContext.lookup("java:/jcr/repositoryName");

       

              Problems problems = null;

              Session session =  null;

       

              try {

                  session = (Session) repo.login("default");

                  RepositoryManager manager = session.getWorkspace().getRepositoryManager();

                  problems = manager.backupRepository(backupPath);

                 

       

                  if (problems.hasProblems()) {

                      throw new RepositoryException("Problems detected during backup");

                  }

       

              } catch (RepositoryException e) {

                  System.out.println("@@ BackupRepository : "+e);

                  if (problems != null && problems.hasProblems()) {

                      model.put("problems", problems);

                  }

       

                  // Delete the backup directory so we can never restore from it

                  backupPath.delete();

                  throw e;

              }finally{

                  if(session != null){

                      session.logout();

                  }

              }

       

      Restore code

      Session session = null;

              try {

                  InitialContext initialContext = new InitialContext();

       

                  Repository repo =  (Repository)initialContext.lookup("java:/jcr/repositoryName");

                  session = (Session) repo.login("default");

       

                  RepositoryManager manager = session.getWorkspace().getRepositoryManager();

                  Problems problems = manager.restoreRepository(backupPath);       

       

                  if (problems.hasProblems()) {

                      model.put("problems", problems);

                      return ResponseBodyStatus.ERROR.withResultOnModel(model);

                  }

              } catch (Exception e) {

                  // TODO Auto-generated catch block

                  //e.printStackTrace();

                  System.out.println("@@ RestoreRepositoryFromBackup : "+e);

              }finally{

                  if(session != null){

                      session.refresh(true);

                      session.logout();

                  }

              }

       

      ERROR Message

      javax.jcr.RepositoryException: The 'xyg' repository is not running and may have been shutdown by the administrator.

        • 1. Re: Errors while restoring the ModeShape repository
          rhauch

          We have a known issue when backing up and restoring from within code running on EAP:

           

          [MODE-2253] Backup/Restore does not work in JBoss EAP - JBoss Issue Tracker

           

          I've added this thread to that issue, so we'll look at it then.

          • 2. Re: Errors while restoring the ModeShape repository
            vpeddireddi

            Thank you for the quick response Randall.. Any idea when can we expect the fix for this? Would you suggest any other alternatives/workarounds to perform backup and restores?  Appreciate your help..

            • 3. Re: Errors while restoring the ModeShape repository
              rhauch

              The bug is marked to be fixed by 4.0.0.Beta1, though since we're timeboxed we may push it to one of the later betas or CRs. We will fixed it by 4.0.0.Final.

               

              It would hep if you tried backup/restore outside of JavaEE (e.g., just in a JavaSE app) to see if that also has issues. I think it works there, since that's where we use it in our testing. But if there is a regression our tests haven't caught, it'd save us time when we investigate the problem.

              • 4. Re: Errors while restoring the ModeShape repository
                hchiorean

                IMO this is not the same issue as the above mentioned JIRA, which is solely related to existing transactions. We need a new reproducible test case & issue for this.

                • 5. Re: Errors while restoring the ModeShape repository
                  ncavallo33

                  This is not at all related to the bug while running in a transaction.

                   

                  The issue that I and vpeddireddi are having (hes working on the same project as me) is that restore fails inside or outside of EAP (with Tomcat 7).  It only fails for me if I have files inside the repo when I back it up.  For testing purposes, I can always get the restore to fail by uploading the text files from the Tomcat distribution (license, notice, release-notes, and running.txt)  I can attach a backup of my repo if you want.

                   

                  The reason why is because of the JSON parsing during a restore.  Long base64 values will not restore correctly because they have newline characters in them.  The JSON parser just assumes that the property value has not been terminated correctly.  Take a look at JsonReader.java line 1128.  I'd love to submit a patch, but I'm not sure what the proper solution should be.  Maybe we can just replace the newlines in the base64 string when the backup is written to disk?

                   

                  The method read() on BackupDocumentReader swallows the exception thrown from this method.

                   

                  If I comment out the newline check the restore works perfectly.  Let me know if I should create a Jira ticket for this.