EnvironmentImpl envImpl = DbInternal.getEnvironmentImpl(env);
/* If no database is specified, verify all. */
List<String> dbNameList = null;
List<String> internalDbs = null;
DbTree dbMapTree = envImpl.getDbTree();
if (dbName == null) {
dbNameList = env.getDatabaseNames();
dbNameList.addAll(dbMapTree.getInternalNoRepDbNames());
if (envImpl.isReplicated()) {
dbNameList.addAll(dbMapTree.getInternalRepDbNames());
}
internalDbs = dbMapTree.getInternalNoLookupDbNames();
} else {
dbNameList = new ArrayList<String>();
dbNameList.add(dbName);
internalDbs = new ArrayList<String>();
}
/* Check application data. */
Iterator<String> iter = dbNameList.iterator();
while (iter.hasNext()) {
String targetDb = iter.next();
LoggerUtils.envLogMsg(Level.INFO, envImpl,
"DbVerify.verify of " + targetDb + " starting");
DatabaseConfig dbConfig = new DatabaseConfig();
dbConfig.setReadOnly(true);
dbConfig.setAllowCreate(false);
DbInternal.setUseExistingConfig(dbConfig, true);
Database db;
try {
db = env.openDatabase(null, targetDb, dbConfig);
} catch (DatabaseNotFoundException e) {
/* DB was removed after getting names -- ignore it. */
continue;
} catch (DatabaseExistsException e) {
/* Should never happen, ExclusiveCreate is false. */
throw EnvironmentFailureException.unexpectedException(e);
}
try {
if (!verifyOneDbImpl(DbInternal.getDatabaseImpl(db),
targetDb,
verifyConfig,
out)) {
ret = false;
}
} finally {
if (db != null) {
db.close();
}
LoggerUtils.envLogMsg(Level.INFO, envImpl,
"DbVerify.verify of " + targetDb +
" ending");
}
}
/*
* Check internal databases, which don't have to be opened
* through a Database handle.
*/
iter = internalDbs.iterator();
while (iter.hasNext()) {
String targetDb = iter.next();
LoggerUtils.envLogMsg(Level.INFO, envImpl,
"DbVerify.verify of " + targetDb + " starting");
try {
DatabaseImpl dbImpl = dbMapTree.getDb(null, targetDb,
null);
try {
if (!verifyOneDbImpl(dbImpl, targetDb,
verifyConfig, out)) {
ret = false;
}
} finally {
dbMapTree.releaseDb(dbImpl);
}
} finally {
LoggerUtils.envLogMsg(Level.INFO, envImpl,
"DbVerify.verify of " + targetDb +
" ending");