Skip to content

Commit

Permalink
*) Remove workaround from SVN 1472: It is not needed anymore
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@1500 6c8d7289-2bf4-0310-a012-ef5d649a1542
  • Loading branch information
hermens committed Jan 31, 2006
1 parent ec5d886 commit bb1664b
Showing 1 changed file with 18 additions and 39 deletions.
57 changes: 18 additions & 39 deletions source/de/anomic/yacy/yacySeedDB.java
Expand Up @@ -338,35 +338,17 @@ public int sizePotential() {
public long countPotentialURL() { return seedPotentialDB.getAcc(yacySeed.LCOUNT); }
public long countPotentialRWI() { return seedPotentialDB.getAcc(yacySeed.ICOUNT); }

/* FIXME: This is an extremely ugly workaround
* kelondroDyn (Backend to the used kelondroMap) removes trailing underscores from keys when
* iterating the database. To get an exact element count it is mandatory to set and remove
* elements with the same key. Failure to do so might result in removed entries staying in the
* ramCache suggesting the entries are still there, thus preventing the element count to be
* raised when the peer returns.
* To avoid duplicates arising from the sortClusters, only add/remove/get trimmed Elements,
* as these shortened hashes are loaded into the clusters during kelondroMap initialization.
* see: http://www.yacy-forum.de/viewtopic.php?p=15955#15955
*/
private String trimHashForKelondroDyn (String hash) {
while ((hash.length() > 1) && (hash.charAt(hash.length() - 1) == '_')) {
hash = hash.substring(0, hash.length() - 1);
}
return hash;
}

public synchronized void addConnected(yacySeed seed) {
if ((seed == null) || (seed.isProper() != null)) return;
//seed.put(yacySeed.LASTSEEN, yacyCore.shortFormatter.format(new Date(yacyCore.universalTime())));
String key = trimHashForKelondroDyn(seed.hash);
try {
nameLookupCache.put(seed.getName(), seed);
Map seedPropMap = seed.getMap();
synchronized(seedPropMap) {
seedActiveDB.set(key, seedPropMap);
seedActiveDB.set(seed.hash, seedPropMap);
}
seedPassiveDB.remove(key);
seedPotentialDB.remove(key);
seedPassiveDB.remove(seed.hash);
seedPotentialDB.remove(seed.hash);
} catch (IOException e){
yacyCore.log.logFine("ERROR add: seed.db corrupt (" + e.getMessage() + "); resetting seed.db", e);
seedActiveDB = resetSeedTable(seedActiveDB, seedActiveDBFile);
Expand All @@ -381,17 +363,16 @@ public synchronized void addConnected(yacySeed seed) {

public synchronized void addDisconnected(yacySeed seed) {
if (seed == null) return;
String key = trimHashForKelondroDyn(seed.hash);
try {
nameLookupCache.remove(seed.getName());
seedActiveDB.remove(key);
seedPotentialDB.remove(key);
seedActiveDB.remove(seed.hash);
seedPotentialDB.remove(seed.hash);
} catch (Exception e) {}
//seed.put(yacySeed.LASTSEEN, yacyCore.shortFormatter.format(new Date(yacyCore.universalTime())));
try {
Map seedPropMap = seed.getMap();
synchronized(seedPropMap) {
seedPassiveDB.set(key, seedPropMap);
seedPassiveDB.set(seed.hash, seedPropMap);
}
} catch (IOException e) {
yacyCore.log.logFine("ERROR add: seed.db corrupt (" + e.getMessage() + "); resetting seed.db", e);
Expand All @@ -407,18 +388,17 @@ public synchronized void addDisconnected(yacySeed seed) {

public synchronized void addPotential(yacySeed seed) {
if (seed == null) return;
String key = trimHashForKelondroDyn(seed.hash);
try {
nameLookupCache.remove(seed.getName());
seedActiveDB.remove(key);
seedPassiveDB.remove(key);
seedActiveDB.remove(seed.hash);
seedPassiveDB.remove(seed.hash);
} catch (Exception e) {}
if (seed.isProper() != null) return;
//seed.put(yacySeed.LASTSEEN, yacyCore.shortFormatter.format(new Date(yacyCore.universalTime())));
try {
Map seedPropMap = seed.getMap();
synchronized(seedPropMap) {
seedPotentialDB.set(key, seedPropMap);
seedPotentialDB.set(seed.hash, seedPropMap);
}
} catch (IOException e) {
yacyCore.log.logFine("ERROR add: seed.db corrupt (" + e.getMessage() + "); resetting seed.db", e);
Expand All @@ -434,23 +414,23 @@ public synchronized void addPotential(yacySeed seed) {

public boolean hasConnected(String hash) {
try {
return (seedActiveDB.get(trimHashForKelondroDyn(hash)) != null);
return (seedActiveDB.get(hash) != null);
} catch (IOException e) {
return false;
}
}

public boolean hasDisconnected(String hash) {
try {
return (seedPassiveDB.get(trimHashForKelondroDyn(hash)) != null);
return (seedPassiveDB.get(hash) != null);
} catch (IOException e) {
return false;
}
}

public boolean hasPotential(String hash) {
try {
return (seedPotentialDB.get(trimHashForKelondroDyn(hash)) != null);
return (seedPotentialDB.get(hash) != null);
} catch (IOException e) {
return false;
}
Expand All @@ -460,7 +440,7 @@ private yacySeed get(String hash, kelondroMap database) {
if (hash == null) return null;
if ((mySeed != null) && (hash.equals(mySeed.hash))) return mySeed;
try {
Map entry = database.get(trimHashForKelondroDyn(hash));
Map entry = database.get(hash);
if (entry == null) return null;
return new yacySeed(hash, entry);
} catch (IOException e) {
Expand Down Expand Up @@ -829,13 +809,12 @@ public yacySeed internalNext() {
if ((it == null) || (!(it.hasNext()))) return null;
Map dna = (Map) it.next();
String hash = (String) dna.remove("key");
/* FIXME: This is an extremely ugly workaround
* kelondroDyn (backend to the used kelondroMap) removes trailing underscores from
* keys when iterating the database. To get correct peer hahes, we have to put them
* back.
* see: http://www.yacy-forum.de/viewtopic.php?p=15955#15955
/* Users of SVN 1498 and 1499 might have extries with shortened hashes in their DBs.
* Those are no problem since they should be eliminated from the active DB quickly.
* They might stay in the passive and potential DB indefinatly, but are not affecting
* normal operations there.
*/
while (hash.length() < commonHashLength) { hash = hash + "_"; }
//while (hash.length() < commonHashLength) { hash = hash + "_"; }
return new yacySeed(hash, dna);
}

Expand Down

0 comments on commit bb1664b

Please sign in to comment.