5 Replies Latest reply: Jun 14, 2011 9:45 PM by Linda Lee RSS

    Truncate data in replication

    868408
      Hi,

      I have a problem with functions removeDatabase and truncateClass, now I want to clear all data in a database with a small cost and I found these two APIs can meet my needs, but it awalys give me com.sleepycat.je.rep.DatabasePreemptedException when a request comes to replicated node, the master node works fine. Below is my code:

      trans = env.beginTransaction(null, null);
                     closeDatabase(); //Close database and entity store

                     env.removeDatabase(trans,
                               "persist#EntityStore#xxx.BdbMember#mobile");
                     env.removeDatabase(trans,
                               "persist#EntityStore#xxx.BdbMember");
                     env.removeDatabase(trans,
                               "persist#EntityStore#xxx.Card#businessNo");
                     env.removeDatabase(trans,
                               "persist#EntityStore#xxx.Card");

                     env.removeDatabase(trans,
                               "persist#EntityStore#xxx.PointFreeze");

                     env.removeDatabase(trans,
                               "persist#EntityStore#xxx.RedMemberBlockPeriod");

      reOpenDatabase("persist#EntityStore#xxx.BdbMember");
                     reOpenDatabase("persist#EntityStore#xxx.Card");
                     reOpenDatabase("persist#EntityStore#xxx.PointFreeze");
                     reOpenDatabase("persist#EntityStore#xxx.RedMemberBlockPeriod");               
                     trans.commit();




      private Database reOpenDatabase(String dbName) throws Exception {
                Transaction trans = null;
                Database db = null;
                try {
                     trans = env.beginTransaction(null, null);
                     DatabaseConfig dc = new DatabaseConfig();
                     dc.setTransactional(true);
                     dc.setAllowCreate(true);
                     db = env.openDatabase(trans, dbName, dc);
                     trans.commit();
                } catch (Exception e) {
                     if (trans != null) {
                          trans.abort();
                     }
                     throw e;
                }
                return db;
           }

      Please do help me!
      Thanks
        • 1. Re: Truncate data in replication
          868408
          No one can help me or I didn't make myself understood? If this is a common issue, please tell me where can I find the answer.

          Your help will be really appreciated.
          • 2. Re: Truncate data in replication
            524761
            Questions about JE should be posted to the Berkeley DB Java Edition forum.
            • 3. Re: Truncate data in replication
              868408
              Yes, but my question is how to truncate data in a replicated environment correctly, so I think I come to the right place for my question.
              • 4. Re: Truncate data in replication
                868408
                Nobody can help me out? It is very important for me to resolve this problem.
                • 5. Re: Truncate data in replication
                  Linda Lee
                  You are using Berkeley DB, Java Edition, High Availability, which is a different product from Berkeley DB, (C version). That's why we suggested that you move your question to the Berkeley DB, Java Edition forum. I know that the product names are confusing.

                  Please read the javadoc for DatabasePreemptedException at http://download.oracle.com/docs/cd/E17277_02/html/java/com/sleepycat/je/rep/DatabasePreemptedException.html. There you will find out that this happens when a database has been truncated, renamed, or deleted on the master. You will get this exception on the replica node. It tells you that the database has had a major change, and you must close and reopen your cursors, database and environment handles. Please read the javadoc for more details.