From 234f733a3d3585701847526b11493166b6cb4740 Mon Sep 17 00:00:00 2001 From: orbiter Date: Mon, 18 Jan 2010 00:07:20 +0000 Subject: [PATCH] - relocation of seed db is better for network switch than re-initialization because of the embedding of the peers object in other objects - small refactoring of blacklist interface code to remove PMD warnings git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@6593 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- htroot/Blacklist_p.java | 32 ++++++------ source/de/anomic/search/Switchboard.java | 7 +-- source/de/anomic/yacy/yacySeedDB.java | 63 +++++++++++++++++++++--- 3 files changed, 74 insertions(+), 28 deletions(-) diff --git a/htroot/Blacklist_p.java b/htroot/Blacklist_p.java index 419febf63..e9f73a00d 100644 --- a/htroot/Blacklist_p.java +++ b/htroot/Blacklist_p.java @@ -114,8 +114,8 @@ public class Blacklist_p { * Creation of a new blacklist * =========================================================== */ - blacklistToUse = post.get("newListName"); - if (blacklistToUse.trim().length() == 0) { + blacklistToUse = post.get("newListName", "").trim(); + if (blacklistToUse.length() == 0) { prop.put("LOCATION",""); return prop; } @@ -160,7 +160,7 @@ public class Blacklist_p { * =========================================================== */ blacklistToUse = post.get("selectedListName"); - if (blacklistToUse == null || blacklistToUse.trim().length() == 0) { + if (blacklistToUse == null || blacklistToUse.length() == 0) { prop.put("LOCATION",""); return prop; } @@ -187,8 +187,8 @@ public class Blacklist_p { * Activate/Deactivate a blacklist * =========================================================== */ - blacklistToUse = post.get("selectedListName"); - if (blacklistToUse == null || blacklistToUse.trim().length() == 0) { + blacklistToUse = post.get("selectedListName", "").trim(); + if (blacklistToUse == null || blacklistToUse.length() == 0) { prop.put("LOCATION", ""); return prop; } @@ -209,8 +209,8 @@ public class Blacklist_p { * Share a blacklist * =========================================================== */ - blacklistToUse = post.get("selectedListName"); - if (blacklistToUse == null || blacklistToUse.trim().length() == 0) { + blacklistToUse = post.get("selectedListName", "").trim(); + if (blacklistToUse == null || blacklistToUse.length() == 0) { prop.put("LOCATION", ""); return prop; } @@ -227,7 +227,7 @@ public class Blacklist_p { * Delete an entry from a blacklist * =========================================================== */ - blacklistToUse = post.get("currentBlacklist"); + blacklistToUse = post.get("currentBlacklist", "").trim(); String temp = null; final String[] selectedBlacklistEntries = post.getAll("selectedEntry.*"); @@ -249,9 +249,9 @@ public class Blacklist_p { * Add new entry to blacklist * =========================================================== */ - blacklistToUse = post.get("currentBlacklist"); + blacklistToUse = post.get("currentBlacklist", "").trim(); - final String temp = addBlacklistEntry(post.get("currentBlacklist"), post.get("newEntry"), header, supportedBlacklistTypes); + final String temp = addBlacklistEntry(blacklistToUse, post.get("newEntry", "").trim(), header, supportedBlacklistTypes); if (temp != null) { prop.put("LOCATION", temp); return prop; @@ -264,7 +264,7 @@ public class Blacklist_p { * Move an entry from one blacklist to another * =========================================================== */ - blacklistToUse = post.get("currentBlacklist"); + blacklistToUse = post.get("currentBlacklist", "").trim(); String targetBlacklist = post.get("targetBlacklist"); String temp = null; @@ -299,7 +299,7 @@ public class Blacklist_p { * Edit entry of a blacklist * =========================================================== */ - blacklistToUse = post.get("currentBlacklist"); + blacklistToUse = post.get("currentBlacklist", "").trim(); final String[] editedBlacklistEntries = post.getAll("editedBlacklistEntry.*"); @@ -511,11 +511,11 @@ public class Blacklist_p { final RequestHeader header, final String[] supportedBlacklistTypes) { - if (blacklistToUse == null || blacklistToUse.trim().length() == 0) { + if (blacklistToUse == null || blacklistToUse.length() == 0) { return ""; } - if (newEntry == null || newEntry.trim().length() == 0) { + if (newEntry == null || newEntry.length() == 0) { return header.get("PATH") + "?selectList=&selectedListName=" + blacklistToUse; } @@ -539,11 +539,11 @@ public class Blacklist_p { final RequestHeader header, final String[] supportedBlacklistTypes) { - if (blacklistToUse == null || blacklistToUse.trim().length() == 0) { + if (blacklistToUse == null || blacklistToUse.length() == 0) { return ""; } - if (oldEntry == null || oldEntry.trim().length() == 0) { + if (oldEntry == null || oldEntry.length() == 0) { return header.get("PATH") + "?selectList=&selectedListName=" + blacklistToUse; } diff --git a/source/de/anomic/search/Switchboard.java b/source/de/anomic/search/Switchboard.java index b3f3fdc8e..2e91214d5 100644 --- a/source/de/anomic/search/Switchboard.java +++ b/source/de/anomic/search/Switchboard.java @@ -757,7 +757,6 @@ public final class Switchboard extends serverSwitch { synchronized (this) { // shut down this.crawler.close(); - this.peers.close(); this.dhtDispatcher.close(); synchronized (this.indexSegments) { this.indexSegments.close(); @@ -786,11 +785,8 @@ public final class Switchboard extends serverSwitch { // relocate this.crawlQueues.relocate(this.queuesRoot); // cannot be closed because the busy threads are working with that object final File mySeedFile = new File(this.networkRoot, yacySeedDB.DBFILE_OWN_SEED); - peers = new yacySeedDB( + peers.relocate( this.networkRoot, - "seed.new.heap", - "seed.old.heap", - "seed.pot.heap", mySeedFile, redundancy, partitionExponent, @@ -802,6 +798,7 @@ public final class Switchboard extends serverSwitch { wordCacheMaxCount, fileSizeMax, this.useTailCache, + this.exceed134217727); // set the default segment names setDefaultSegments(); diff --git a/source/de/anomic/yacy/yacySeedDB.java b/source/de/anomic/yacy/yacySeedDB.java index 2456feaba..eda7ca88d 100644 --- a/source/de/anomic/yacy/yacySeedDB.java +++ b/source/de/anomic/yacy/yacySeedDB.java @@ -88,7 +88,7 @@ public final class yacySeedDB implements AlternativeDomainNames { public yacyPeerActions peerActions; public yacyNewsPool newsPool; - private final int netRedundancy; + private int netRedundancy; public PartitionScheme scheme; private yacySeed mySeed; // my own seed @@ -115,20 +115,20 @@ public final class yacySeedDB implements AlternativeDomainNames { this.scheme = new VerticalWordPartitionScheme(partitionExponent); // set up seed database - seedActiveDB = openSeedTable(seedActiveDBFile); - seedPassiveDB = openSeedTable(seedPassiveDBFile); - seedPotentialDB = openSeedTable(seedPotentialDBFile); + this.seedActiveDB = openSeedTable(seedActiveDBFile); + this.seedPassiveDB = openSeedTable(seedPassiveDBFile); + this.seedPotentialDB = openSeedTable(seedPotentialDBFile); // start our virtual DNS service for yacy peers with empty cache - nameLookupCache = new Hashtable(); + this.nameLookupCache = new Hashtable(); // cache for reverse name lookup - ipLookupCache = new Hashtable>(); + this.ipLookupCache = new Hashtable>(); // check if we are in the seedCaches: this can happen if someone else published our seed removeMySeed(); - lastSeedUpload_seedDBSize = sizeConnected(); + this.lastSeedUpload_seedDBSize = sizeConnected(); // tell the httpdProxy how to find this table as address resolver HTTPDemon.setAlternativeResolver(this); @@ -140,6 +140,55 @@ public final class yacySeedDB implements AlternativeDomainNames { this.peerActions = new yacyPeerActions(this, newsPool); } + public void relocate( + File newNetworkRoot, + final File myOwnSeedFile, + final int redundancy, + final int partitionExponent, + final boolean useTailCache, + final boolean exceed134217727) { + // close old databases + this.seedActiveDB.close(); + this.seedPassiveDB.close(); + this.seedPotentialDB.close(); + this.newsPool.close(); + this.peerActions.close(); + + // open new according to the newNetworkRoot + this.seedActiveDBFile = new File(newNetworkRoot, seedActiveDBFile.getName()); + this.seedPassiveDBFile = new File(newNetworkRoot, seedPassiveDBFile.getName()); + this.seedPotentialDBFile = new File(newNetworkRoot, seedPotentialDBFile.getName()); + this.mySeed = null; // my own seed + this.myOwnSeedFile = myOwnSeedFile; + this.netRedundancy = redundancy; + this.scheme = new VerticalWordPartitionScheme(partitionExponent); + + // set up seed database + this.seedActiveDB = openSeedTable(seedActiveDBFile); + this.seedPassiveDB = openSeedTable(seedPassiveDBFile); + this.seedPotentialDB = openSeedTable(seedPotentialDBFile); + + // start our virtual DNS service for yacy peers with empty cache + this.nameLookupCache.clear(); + + // cache for reverse name lookup + this.ipLookupCache.clear(); + + // check if we are in the seedCaches: this can happen if someone else published our seed + removeMySeed(); + + this.lastSeedUpload_seedDBSize = sizeConnected(); + + // tell the httpdProxy how to find this table as address resolver + HTTPDemon.setAlternativeResolver(this); + + // create or init news database + this.newsPool = new yacyNewsPool(newNetworkRoot, useTailCache, exceed134217727); + + // deploy peer actions + this.peerActions = new yacyPeerActions(this, newsPool); + } + private synchronized void initMySeed() { if (this.mySeed != null) return;