2 Replies Latest reply: Jun 17, 2013 2:43 AM by 1015634 RSS

    Service runs one day, out of memory. Service Unavailable

    1015634

      hello,

      My service use bdb java edition. More than 10,000 people use it,Service runs one day, out of memory. Service Unavailable.

      my code as follow:

      //This code has only been called once during the initialization
           public void create(String dbPath){
               File bdbPath = new File(dbPath+"/bdb");
               if(!bdbPath.exists()){
                 bdbPath.mkdirs();
               }
        
               /* Create a new, transactional database environment */
               EnvironmentConfig envConfig = new EnvironmentConfig();
               envConfig.setTransactional(true);
               envConfig.setAllowCreate(true);
               exampleEnv = new Environment((bdbPath), envConfig);
               //set txn
               TransactionConfig transactionConfig = new TransactionConfig();
               transactionConfig.setReadUncommitted(true);
        
               Transaction envsnInfoTxn = exampleEnv.beginTransaction(null, transactionConfig);

               Transaction myClassTxn =  exampleEnv.beginTransaction(null, transactionConfig);
               //set dbConfig    
               DatabaseConfig dbConfig = new DatabaseConfig();
               dbConfig.setTransactional(true);
               dbConfig.setAllowCreate(true);
               //make sure the key is unique
               dbConfig.setSortedDuplicates(false);
               envsnDb =  exampleEnv.openDatabase(envsnInfoTxn, "envsnDb", dbConfig);
               myClassDb =  exampleEnv.openDatabase(myClassTxn, "myClassDb", dbConfig);
               //set seq
               SequenceConfig config = new SequenceConfig();
               config.setAllowCreate(true);
               DatabaseEntry keyEntry = new DatabaseEntry();
               StringBinding.stringToEntry(KEY_NAME, keyEntry);
               envsnSeq = envsnDb.openSequence(envsnInfoTxn, keyEntry, config);
              //txn commit
              envsnInfoTxn.commit();
              myClassTxn.commit();
           }

       

          //my business as follow

      public String getNewEnvsnInfo(String oldid)
         throws StoragerException {
         String newid = "";
         TransactionConfig transactionConfig = new TransactionConfig();
         transactionConfig.setReadUncommitted(true);
         //begin txn
         Transaction txn = exampleEnv.beginTransaction(null, transactionConfig);
        
         DatabaseEntry keyEntry = new DatabaseEntry();
         DatabaseEntry dataEntry = new DatabaseEntry();
        
         EnvsnInfo tmpEnvsnInfo = new EnvsnInfo();
         EnvsnInfo newEnvsnInfo = new EnvsnInfo();

         // Binding entity
         StoredClassCatalog classCatalog = new StoredClassCatalog(myClassDb);
         EntryBinding dataBinding = new SerialBinding(classCatalog,EnvsnInfo.class);
         //set cursor
         CursorConfig config = new CursorConfig(); 
         config.setReadUncommitted(true);
         Cursor cursor = envsnDb.openCursor(null, config);
         String id = "";
        
         StringBinding.stringToEntry(oldid, keyEntry);

         //find ID
         if(cursor.getSearchKey(keyEntry, dataEntry, LockMode.DEFAULT)== OperationStatus.SUCCESS){
          tmpEnvsnInfo = (EnvsnInfo)dataBinding.entryToObject(dataEntry);
          newid = tmpEnvsnInfo.getNewid();
          txn.commit();
          return newid;
         }else{

          // not found ,use seq
          long sq = envsnSeq.get(txn, 1);
          int b = new Long(sq).intValue();
          id = String.format("%07d", b);
         
         }
         newEnvsnInfo.setId(id);
         newEnvsnInfo.setOldid(oldid);
        
         newid = id;
         newEnvsnInfo.setNewid(newid);
         StringBinding.stringToEntry(oldid, keyEntry);
         dataBinding.objectToEntry(newEnvsnInfo, dataEntry);

         // save envsn
         OperationStatus status =  envsnDb.put(null, keyEntry, dataEntry);
         if (status != OperationStatus.SUCCESS) {
          txn.commit();
          throw new StoragerException("Save Envsn info got status " + status);
         }
         txn.commit();
         return newid;
        }

       

         Why is it so?

      Thanks in advance.