mirror of
https://github.com/internetarchive/heritrix3.git
synced 2026-09-26 07:35:39 +00:00
[HER-1706] PersistLoadProcessor and PersistStoreProcessor can't share same BdbModule
* BdbModule.java
allow Database instance reuse if BdbConfig is identical instance
* PersistProcessor.java
convert shared BdbConfig for history db to static constant HISTORY_DB_CONFIG
* PersistOnlineProcessor.java
use HISTORY_DB_CONFIG, don't close possibly-shared DB on stop()
* PrecedenceLoader.java, PreloadedUriPrecedencePolicy.java
use HISTORY_DB_CONFIG
This commit is contained in:
@@ -329,6 +329,12 @@ Serializable, Closeable {
|
||||
"BdbModule not started; as a Lifecycle bean it must not be an inner bean.");
|
||||
}
|
||||
if (databases.containsKey(name)) {
|
||||
DatabasePlusConfig dpc = databases.get(name);
|
||||
if(dpc.config == config) {
|
||||
// object-identical configs: OK to share DB
|
||||
return dpc.database;
|
||||
}
|
||||
// unshared config object: might be name collision; error
|
||||
throw new IllegalStateException("Database already exists: " +name);
|
||||
}
|
||||
|
||||
|
||||
@@ -110,7 +110,7 @@ public class PrecedenceLoader {
|
||||
Database historyDB = targetEnv.openDatabase(
|
||||
null,
|
||||
PersistProcessor.URI_HISTORY_DBNAME,
|
||||
PersistProcessor.historyDatabaseConfig().toDatabaseConfig());
|
||||
PersistProcessor.HISTORY_DB_CONFIG.toDatabaseConfig());
|
||||
StoredSortedMap historyMap = new StoredSortedMap(historyDB,
|
||||
new StringBinding(), new SerialBinding(classCatalog,
|
||||
Map.class), true);
|
||||
|
||||
+1
-1
@@ -79,7 +79,7 @@ implements Lifecycle {
|
||||
StoredSortedMap historyMap;
|
||||
try {
|
||||
StoredClassCatalog classCatalog = bdb.getClassCatalog();
|
||||
BdbModule.BdbConfig dbConfig = PersistProcessor.historyDatabaseConfig();
|
||||
BdbModule.BdbConfig dbConfig = PersistProcessor.HISTORY_DB_CONFIG;
|
||||
|
||||
historyDb = bdb.openManagedDatabase(dbName, dbConfig, true);
|
||||
historyMap = new StoredSortedMap(historyDb,
|
||||
|
||||
@@ -74,7 +74,7 @@ implements Lifecycle {
|
||||
StoredSortedMap<String,Map> historyMap;
|
||||
try {
|
||||
StoredClassCatalog classCatalog = bdb.getClassCatalog();
|
||||
BdbModule.BdbConfig dbConfig = historyDatabaseConfig();
|
||||
BdbModule.BdbConfig dbConfig = HISTORY_DB_CONFIG;
|
||||
|
||||
historyDb = bdb.openManagedDatabase(getHistoryDbName(), dbConfig, true);
|
||||
historyMap =
|
||||
@@ -94,11 +94,10 @@ implements Lifecycle {
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
// TODO leave this cleanup to BdbModule?
|
||||
if (!isRunning()) {
|
||||
return;
|
||||
}
|
||||
bdb.closeDatabase(historyDb);
|
||||
// leave other cleanup to BdbModule
|
||||
historyDb = null;
|
||||
}
|
||||
|
||||
|
||||
@@ -73,15 +73,13 @@ public abstract class PersistProcessor extends Processor {
|
||||
/** name of history Database */
|
||||
public static final String URI_HISTORY_DBNAME = "uri_history";
|
||||
|
||||
/**
|
||||
* @return DatabaseConfig for history Database
|
||||
*/
|
||||
public static BdbModule.BdbConfig historyDatabaseConfig() {
|
||||
public static final BdbModule.BdbConfig HISTORY_DB_CONFIG;
|
||||
static {
|
||||
BdbModule.BdbConfig dbConfig = new BdbModule.BdbConfig();
|
||||
dbConfig.setTransactional(false);
|
||||
dbConfig.setAllowCreate(true);
|
||||
dbConfig.setDeferredWrite(true);
|
||||
return dbConfig;
|
||||
HISTORY_DB_CONFIG = dbConfig;
|
||||
}
|
||||
|
||||
public PersistProcessor() {
|
||||
@@ -145,7 +143,7 @@ public abstract class PersistProcessor extends Processor {
|
||||
EnhancedEnvironment sourceEnv = setupEnvironment(sourceDir, true);
|
||||
StoredClassCatalog sourceClassCatalog = sourceEnv.getClassCatalog();
|
||||
Database sourceHistoryDB = sourceEnv.openDatabase(
|
||||
null, URI_HISTORY_DBNAME, historyDatabaseConfig().toDatabaseConfig());
|
||||
null, URI_HISTORY_DBNAME, HISTORY_DB_CONFIG.toDatabaseConfig());
|
||||
StoredSortedMap<String,Map> sourceHistoryMap = new StoredSortedMap<String,Map>(sourceHistoryDB,
|
||||
new StringBinding(), new SerialBinding<Map>(sourceClassCatalog,
|
||||
Map.class), true);
|
||||
@@ -244,7 +242,7 @@ public abstract class PersistProcessor extends Processor {
|
||||
targetEnv = setupEnvironment(envFile);
|
||||
classCatalog = targetEnv.getClassCatalog();
|
||||
historyDB = targetEnv.openDatabase(null, URI_HISTORY_DBNAME,
|
||||
historyDatabaseConfig().toDatabaseConfig());
|
||||
HISTORY_DB_CONFIG.toDatabaseConfig());
|
||||
historyMap = new StoredSortedMap<String,Map>(historyDB,
|
||||
new StringBinding(), new SerialBinding<Map>(classCatalog,
|
||||
Map.class), true);
|
||||
|
||||
Reference in New Issue
Block a user