示例#1
0
  public void merge() throws Exception {
    LOG.info("start merge");
    Database crawldbDatabase = env.openDatabase(null, "crawldb", BerkeleyDBUtils.defaultDBConfig);
    /*合并fetch库*/
    LOG.info("merge fetch database");
    Database fetchDatabase = env.openDatabase(null, "fetch", BerkeleyDBUtils.defaultDBConfig);
    Cursor fetchCursor = fetchDatabase.openCursor(null, null);
    DatabaseEntry key = new DatabaseEntry();
    DatabaseEntry value = new DatabaseEntry();
    while (fetchCursor.getNext(key, value, LockMode.DEFAULT) == OperationStatus.SUCCESS) {
      crawldbDatabase.put(null, key, value);
    }
    fetchCursor.close();
    fetchDatabase.close();
    /*合并link库*/
    LOG.info("merge link database");
    Database linkDatabase = env.openDatabase(null, "link", BerkeleyDBUtils.defaultDBConfig);
    Cursor linkCursor = linkDatabase.openCursor(null, null);
    while (linkCursor.getNext(key, value, LockMode.DEFAULT) == OperationStatus.SUCCESS) {
      if (!(crawldbDatabase.get(null, key, value, LockMode.DEFAULT) == OperationStatus.SUCCESS)) {
        crawldbDatabase.put(null, key, value);
      }
    }
    linkCursor.close();
    linkDatabase.close();
    LOG.info("end merge");
    crawldbDatabase.sync();
    crawldbDatabase.close();

    env.removeDatabase(null, "fetch");
    LOG.debug("remove fetch database");
    env.removeDatabase(null, "link");
    LOG.debug("remove link database");
  }
示例#2
0
 public void remove(String csName) {
   try {
     m_env.removeDatabase(null, csName);
   } catch (DatabaseException e) {
     e.printStackTrace();
   }
   m_env = null;
 }
 @Test
 public void testCleanAfterDbRemoval() {
   open(true /*runCleaner*/);
   writeFiles(5 /*nActive*/, 0 /*nObsolete*/);
   expectNothingToClean();
   db.close();
   db = null;
   env.removeDatabase(null, DB_NAME);
   expectBackgroundCleaning();
   close();
 }
示例#4
0
 public void remove(String dbName) {
   env.removeDatabase(null, dbName);
 }
示例#5
0
 /** removes database */
 public void removeDatabase() {
   final Transaction txn = myEnv.beginTransaction(null, null);
   // close();
   myEnv.removeDatabase(txn, dbName);
   txn.commit();
 }