Skip to content

Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance

- fix for LOG path generation when the DATA/LOG does not exists (fix for bug introduced in SVN 4923) - some more/better asserts - slight performance enhancements in remove method in index management. Works for all who do not run using asserts (the majority)

orbiter31efb8fbee69
diff --git a/source/de/anomic/kelondro/kelondroRAMIndex.java b/source/de/anomic/kelondro/kelondroRAMIndex.java
index 000662e76..ca1cb5e48 100644
--- a/source/de/anomic/kelondro/kelondroRAMIndex.java
+++ b/source/de/anomic/kelondro/kelondroRAMIndex.java
@@ -137,11 +137,13 @@ public class kelondroRAMIndex implements kelondroIndex {
// if the new entry is within the initialization part, just delete it
kelondroRow.Entry indexentry = index0.remove(key, keepOrder);
if (indexentry != null) {
- assert index0.remove(key, true) == null; // check if remove worked
+ assert index0.get(key) == null; // check if remove worked
return indexentry;
}
// else remove it from the index1
- return index1.remove(key, keepOrder);
+ kelondroRow.Entry removed = index1.remove(key, keepOrder);
+ assert index1.get(key) == null : "removed " + ((removed == null) ? " is null" : " is not null") + ", and index entry still exists"; // check if remove worked
+ return removed;
}
public synchronized kelondroRow.Entry removeOne() {
diff --git a/source/de/anomic/kelondro/kelondroRowCollection.java b/source/de/anomic/kelondro/kelondroRowCollection.java
index 709d6a64d..7ddab58af 100644
--- a/source/de/anomic/kelondro/kelondroRowCollection.java
+++ b/source/de/anomic/kelondro/kelondroRowCollection.java
@@ -269,6 +269,7 @@ public class kelondroRowCollection {
assert (index >= 0) : "get: access with index " + index + " is below zero";
assert (index < chunkcount) : "get: access with index " + index + " is above chunkcount " + chunkcount + "; sortBound = " + sortBound;
assert (index * rowdef.objectsize < chunkcache.length);
+ assert sortBound <= chunkcount : "sortBound = " + sortBound + ", chunkcount = " + chunkcount;
if ((chunkcache == null) || (rowdef == null)) return null; // case may appear during shutdown
kelondroRow.Entry entry;
int addr = index * rowdef.objectsize;
@@ -341,19 +342,6 @@ public class kelondroRowCollection {
this.lastTimeWrote = System.currentTimeMillis();
return true;
}
- /*
- private static boolean bugappearance(byte[] a, int astart, int alength) {
- // check strange appearances of '@[B', which is not a b64-value or any other hash fragment
- if (astart + 3 > alength) return false;
- loop: for (int i = astart; i <= alength - 3; i++) {
- if (a[i ] != 64) continue loop;
- if (a[i + 1] != 91) continue loop;
- if (a[i + 2] != 66) continue loop;
- return true;
- }
- return false;
- }
- */
public synchronized final void addAllUnique(kelondroRowCollection c) {
if (c == null) return;
@@ -380,11 +368,12 @@ public class kelondroRowCollection {
assert sortBound <= chunkcount : "sortBound = " + sortBound + ", chunkcount = " + chunkcount;
if (keepOrder && (p < sortBound)) {
// remove by shift (quite expensive for big collections)
+ int addr = p * this.rowdef.objectsize;
System.arraycopy(
- chunkcache, (p + 1) * this.rowdef.objectsize,
- chunkcache, p * this.rowdef.objectsize,
+ chunkcache, addr + this.rowdef.objectsize,
+ chunkcache, addr,
(chunkcount - p - 1) * this.rowdef.objectsize);
- sortBound--;
+ sortBound--; // this is only correct if p < sortBound, but this was already checked above
} else {
// remove by copying the top-element to the remove position
if (p != chunkcount - 1) {
@@ -395,7 +384,7 @@ public class kelondroRowCollection {
}
// we moved the last element to the remove position: (p+1)st element
// only the first p elements keep their order (element p is already outside the order)
- if (sortBound >= p) sortBound = p;
+ if (sortBound > p) sortBound = p;
}
chunkcount--;
this.lastTimeWrote = System.currentTimeMillis();
@@ -944,9 +933,9 @@ public class kelondroRowCollection {
System.out.println("uniq d : " + (t6 - t5) + " nanoseconds, " + d(testsize, (t6 - t5)) + " entries/nanoseconds");
random = new Random(0);
kelondroRowSet e = new kelondroRowSet(r, testsize);
- /*for (int i = 0; i < testsize; i++) {
- //e.put(r.newEntry(randomHash().getBytes()));
- }*/
+ for (int i = 0; i < testsize; i++) {
+ e.put(r.newEntry(randomHash().getBytes()));
+ }
long t7 = System.nanoTime();
System.out.println("create e : " + (t7 - t6) + " nanoseconds, " + d(testsize, (t7 - t6)) + " entries/nanoseconds");
e.sort();
@@ -967,13 +956,15 @@ public class kelondroRowCollection {
random = new Random(0);
boolean allfound = true;
for (int i = 0; i < testsize; i++) {
- if (e.get(randomHash().getBytes()) == null) {
+ String rh = randomHash();
+ if (e.get(rh.getBytes()) == null) {
allfound = false;
+ System.out.println("not found hash " + rh + " at attempt " + i);
break;
}
}
- long t13 = System.currentTimeMillis();
- System.out.println("e allfound = " + ((allfound) ? "true" : "false") + ": " + (t13 - t12) + " milliseconds");
+ long t13 = System.nanoTime();
+ System.out.println("e allfound = " + ((allfound) ? "true" : "false") + ": " + (t13 - t12) + " nanoseconds");
boolean noghosts = true;
for (int i = 0; i < testsize; i++) {
if (e.get(randomHash().getBytes()) != null) {
@@ -981,8 +972,8 @@ public class kelondroRowCollection {
break;
}
}
- long t14 = System.currentTimeMillis();
- System.out.println("e noghosts = " + ((noghosts) ? "true" : "false") + ": " + (t14 - t13) + " milliseconds");
+ long t14 = System.nanoTime();
+ System.out.println("e noghosts = " + ((noghosts) ? "true" : "false") + ": " + (t14 - t13) + " nanoseconds");
System.out.println("Result size: c = " + c.size() + ", d = " + d.size() + ", e = " + e.size());
System.out.println();
if (sortingthreadexecutor != null) sortingthreadexecutor.shutdown();
diff --git a/source/de/anomic/kelondro/kelondroRowSet.java b/source/de/anomic/kelondro/kelondroRowSet.java
index 80ba1db99..17b8b4617 100644
--- a/source/de/anomic/kelondro/kelondroRowSet.java
+++ b/source/de/anomic/kelondro/kelondroRowSet.java
@@ -162,9 +162,9 @@ public class kelondroRowSet extends kelondroRowCollection implements kelondroInd
kelondroRow.Entry entry = super.get(index, true);
super.removeRow(index, keepOrder);
//System.out.println("remove: chunk found at index position (after remove) " + index + ", inset=" + serverLog.arrayList(super.chunkcache, super.rowdef.objectsize() * index, length) + ", searchkey=" + serverLog.arrayList(a, start, length));
- int findagainindex = find(a, start, length);
+ int findagainindex = 0;
//System.out.println("kelondroRowSet.remove");
- assert findagainindex < 0 : "remove: chunk found again at index position (after remove) " + findagainindex + ", index(before) = " + index + ", inset=" + serverLog.arrayList(super.chunkcache, super.rowdef.objectsize * findagainindex, length) + ", searchkey=" + serverLog.arrayList(a, start, length); // check if the remove worked
+ assert (findagainindex = find(a, start, length)) < 0 : "remove: chunk found again at index position (after remove) " + findagainindex + ", index(before) = " + index + ", inset=" + serverLog.arrayList(super.chunkcache, super.rowdef.objectsize * findagainindex, length) + ", searchkey=" + serverLog.arrayList(a, start, length); // check if the remove worked
return entry;
}
diff --git a/source/yacy.java b/source/yacy.java
index 2f8b57d12..04738c28e 100644
--- a/source/yacy.java
+++ b/source/yacy.java
@@ -198,16 +198,16 @@ public final class yacy {
}
// setting up logging
- f = new File(homePath, "DATA/LOG/yacy.logging");
- final File logPath =new File(f.getPath());
- if (!logPath.exists()) logPath.mkdirs();
- if (!f.exists()) try {
- serverFileUtils.copy(new File(homePath, "yacy.logging"), f);
- }catch (IOException e){
+ f = new File(homePath, "DATA/LOG/");
+ if (!f.exists()) f.mkdirs();
+ f = new File(homePath, "DATA/LOG/yacy.logging");
+ if (!f.exists()) try {
+ serverFileUtils.copy(new File(homePath, "yacy.logging"), f);
+ } catch (IOException e){
System.out.println("could not copy yacy.logging");
}
try{
- serverLog.configureLogging(homePath, f);
+ serverLog.configureLogging(homePath, new File(homePath, "DATA/LOG/yacy.logging"));
} catch (IOException e) {
System.out.println("could not find logging properties in homePath=" + homePath);
e.printStackTrace();