7 Replies Latest reply on Jan 30, 2011 9:16 AM by 655560

    problem open container

    835017
      Hi,
      I use java api and I have a problem when I try to open a container.
      If the container not exist I use the method XmlManage.createContainer and all work fine.
      If the container exist I use the method XmlManage.openContainer but this method remain in block for indefinitely time.
      I don't know what is the possible casue, perhaps I don't close correctly all objects in the previus execution.
      When this happen I can only delete data from file system and recreate the container
      I use version 2.5.16 o windows server 2008 64 bit and jdk 6 32 bit version

      Thank
      Bassanelli Michele
        • 1. Re: problem open container
          637288
          Hi,

          can you please post some code for creation and opening a container? (please use forum code formatting elements)

          Vyacheslav
          • 2. Re: problem open container
            835017
            Hi,
            below a simple program that generate the problem
            note that the transaction is not committed
            when I execute for the second time the program I cannot open the container and I don't know how recovery the data.

            Thank
            Michele
            import java.io.File;
            
            import com.sleepycat.db.Environment;
            import com.sleepycat.db.EnvironmentConfig;
            import com.sleepycat.dbxml.XmlContainer;
            import com.sleepycat.dbxml.XmlContainerConfig;
            import com.sleepycat.dbxml.XmlDocumentConfig;
            import com.sleepycat.dbxml.XmlManager;
            import com.sleepycat.dbxml.XmlManagerConfig;
            import com.sleepycat.dbxml.XmlResults;
            import com.sleepycat.dbxml.XmlTransaction;
            import com.sleepycat.dbxml.XmlValue;
            
            public class Test {
                 private Environment myEnv = null;
                 private XmlManager myManager = null;
                 private XmlContainer myContainer = null;
            
                 public Test() {
                      try {
                           init();
                      } catch (Exception e) {
                           e.printStackTrace();
                      }
                 }
            
                 private void init() throws Exception {
                      File envHome = new File("C:/Program Files (x86)/Oracle/Berkeley DB XML 2.5.16/TestDb");
                      EnvironmentConfig envConf = new EnvironmentConfig();
                      envConf.setAllowCreate(true);
                      envConf.setInitializeCache(true);
                      envConf.setInitializeLocking(true);
                      envConf.setInitializeLogging(true);
                      envConf.setTransactional(true);
                      myEnv = new Environment(envHome, envConf);
            
                      XmlManagerConfig managerConfig = new XmlManagerConfig();
                      myManager = new XmlManager(myEnv, managerConfig);
            
                      XmlContainerConfig containerConf = new XmlContainerConfig();
                      containerConf.setTransactional(true);
                      containerConf.setAllowCreate(true);
            
                      if (myManager.existsContainer("myContainer.dbxml") != 0) {
                           myContainer = myManager.openContainer("myContainer.dbxml");
                      } else {
                           myContainer = myManager.createContainer("myContainer.dbxml");
                      }
                      
                      XmlTransaction txn = myManager.createTransaction();
                      myContainer.putDocument(txn, "test", "<root>test</root>");
                 //     txn.commit();
                      
                      System.out.println("end ");
                 }
            
                 public static void main(String[] args) {
                      new Test();     
                 }
            }
            • 3. Re: problem open container
              637288
              Hi,

              The problem is that you when you create and open a container, you don't provide an XmlContainerConfig object to those methods. Therefore your environment is opened with support for transactions, and a container without --- this is not allowed and will lead to unpredictable hangs.

              Also you should always commit or abort transactions, so uncomment the txn.commit() statement.

              Does it help?
              Vyacheslav
              • 4. Re: problem open container
                835017
                Hi,

                I have added the reference to XmlContainerConfig
                          if (myManager.existsContainer("myContainer.dbxml") != 0) {
                               myContainer = myManager.openContainer("myContainer.dbxml", containerConf);
                          } else {
                               myContainer = myManager.createContainer("myContainer.dbxml", containerConf);
                          }
                but the problem remain.
                Also you should always commit or abort transactions, so uncomment the txn.commit() statement.
                yes, if I commit or abort the transaction I have no problem,

                but I want test how recover data after an unpredictable error, for example the transaction not well termined.
                The really application is more complex and during the development there is this possibility.
                At this moment I don't know how I can use or recover the data already written on db.


                Michele
                • 5. Re: problem open container
                  637288
                  Hi,

                  you might also specify:
                  envConf.setRunRecovery(true);
                  So what is exactly your problem? Just to get you right: If you commit a transaction and create/open a container with transaction support then everything is fine?
                  But if you don't commit a transaction, then the next time you open a container it hangs, instead of throwing RunRecoveryException or something like this?

                  Please try specifying the option above and let me know if I got your problem right

                  Vyacheslav
                  • 6. Re: problem open container
                    835017
                    Hi,


                    thank, I have resolved

                    >
                    If you commit a transaction and create/open a container with transaction support then everything is fine?
                    >
                    Yes, everything is fine.



                    >
                    But if you don't commit a transaction, then the next time you open a container it hangs, instead of throwing RunRecoveryException or something like this?
                    >
                    Yes, the problem is this, when i try to open a container it hangs.



                    but adding
                    envConf.setRunRecovery(true);
                    I can open a container also after the problem described above.


                    Michele
                    • 7. Re: problem open container
                      655560
                      Hi, Michele

                      It's good to see the problem has been solved. As Vyacheslav suggested that "envConf.setRunRecovery(true);" is required in this case.

                      Best regards,
                      Rucong Zhao
                      Oracle Berkeley DB XML