From e1acdb952c8357e8b8204508ffc58cdd1ce82ea4 Mon Sep 17 00:00:00 2001 From: orbiter Date: Mon, 8 Dec 2008 00:17:45 +0000 Subject: [PATCH] fix for problem with userDB and bookmarksDB which was caused by changes in kelondroRA in SVN 5376 git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@5385 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- htroot/ConfigAccounts_p.java | 3 +- source/de/anomic/data/bookmarksDB.java | 21 ++++++---- .../anomic/kelondro/kelondroAbstractRA.java | 4 +- source/de/anomic/kelondro/kelondroBLOB.java | 6 +++ .../de/anomic/kelondro/kelondroBLOBArray.java | 4 ++ .../anomic/kelondro/kelondroBLOBBuffer.java | 4 ++ .../de/anomic/kelondro/kelondroBLOBHeap.java | 17 +++++--- .../de/anomic/kelondro/kelondroBLOBTree.java | 40 ++++++++++++++++--- .../anomic/kelondro/kelondroBufferedRA.java | 4 +- .../de/anomic/kelondro/kelondroCachedRA.java | 4 +- .../de/anomic/kelondro/kelondroChannelRA.java | 4 +- source/de/anomic/kelondro/kelondroFileRA.java | 4 +- source/de/anomic/kelondro/kelondroMap.java | 23 +++++++++++ source/de/anomic/kelondro/kelondroRA.java | 2 +- source/de/anomic/kelondro/kelondroTree.java | 4 +- 15 files changed, 111 insertions(+), 33 deletions(-) diff --git a/htroot/ConfigAccounts_p.java b/htroot/ConfigAccounts_p.java index 2b2688063..64d5b155d 100644 --- a/htroot/ConfigAccounts_p.java +++ b/htroot/ConfigAccounts_p.java @@ -151,7 +151,6 @@ public class ConfigAccounts_p { prop.put("text", "0"); prop.put("error", "0"); - final String username=post.get("username"); final String pw1=post.get("password"); final String pw2=post.get("password2"); @@ -191,7 +190,6 @@ public class ConfigAccounts_p { prop.put("error", "3"); } - } else { //edit user entry = sb.userDB.getEntry(username); @@ -223,6 +221,7 @@ public class ConfigAccounts_p { int numUsers=0; while(it.hasNext()){ entry = it.next(); + if (entry == null) continue; prop.putHTML("users_"+numUsers+"_user", entry.getUserName()); numUsers++; } diff --git a/source/de/anomic/data/bookmarksDB.java b/source/de/anomic/data/bookmarksDB.java index 6cbb6578e..0fbbe6b6b 100644 --- a/source/de/anomic/data/bookmarksDB.java +++ b/source/de/anomic/data/bookmarksDB.java @@ -511,7 +511,8 @@ public class bookmarksDB { Tag ret=null; try { map = tagsTable.get(hash); - } catch (final IOException e) { + } catch (final Exception e) { + e.printStackTrace(); return null; } if(map!=null){ @@ -582,6 +583,7 @@ public class bookmarksDB { try { return new tagIterator(up); } catch (final IOException e) { + e.printStackTrace(); return new HashSet().iterator(); } } @@ -1299,17 +1301,21 @@ public class bookmarksDB { public boolean hasNext() { try { return this.tagIter.hasNext(); - } catch (final kelondroException e) { - //resetDatabase(); + } catch (final Exception e) { + e.printStackTrace(); return false; } } public Tag next() { try { - return getTag(new String(this.tagIter.next())); - } catch (final kelondroException e) { - //resetDatabase(); + byte[] b = this.tagIter.next(); + String s = new String(b); + //System.out.println("### DEBUG tagIterator - " + s); + Tag t = getTag(s); + return t; + } catch (final Exception e) { + e.printStackTrace(); return null; } } @@ -1349,7 +1355,8 @@ public class bookmarksDB { public Bookmark next() { try { - return getBookmark(new String(this.bookmarkIter.next())); + String s = new String(this.bookmarkIter.next()); + return getBookmark(s); } catch (final kelondroException e) { //resetDatabase(); return null; diff --git a/source/de/anomic/kelondro/kelondroAbstractRA.java b/source/de/anomic/kelondro/kelondroAbstractRA.java index c223e1460..ea1fd3404 100644 --- a/source/de/anomic/kelondro/kelondroAbstractRA.java +++ b/source/de/anomic/kelondro/kelondroAbstractRA.java @@ -51,14 +51,14 @@ abstract class kelondroAbstractRA implements kelondroRA { // pseudo-native methods: abstract public void readFully(byte[] b, int off, int len) throws IOException; abstract public long length() throws IOException; - abstract public long available() throws IOException; + abstract public int available() throws IOException; abstract public void write(byte[] b, int off, int len) throws IOException; abstract public void seek(long pos) throws IOException; abstract public void close() throws IOException; // derived methods: public byte[] readFully() throws IOException { - int a = (int) this.available(); + int a = this.available(); if (a <= 0) return null; final byte[] buffer = new byte[a]; this.readFully(buffer, 0, a); diff --git a/source/de/anomic/kelondro/kelondroBLOB.java b/source/de/anomic/kelondro/kelondroBLOB.java index 5cd6f4a1e..708c76439 100644 --- a/source/de/anomic/kelondro/kelondroBLOB.java +++ b/source/de/anomic/kelondro/kelondroBLOB.java @@ -30,6 +30,12 @@ import java.io.IOException; public interface kelondroBLOB { + /** + * return a name of the BLOB; can be the file name + * @return + */ + public String name(); + /** * ask for the length of the primary key * @return the length of the key diff --git a/source/de/anomic/kelondro/kelondroBLOBArray.java b/source/de/anomic/kelondro/kelondroBLOBArray.java index e4e1d7850..22a776506 100755 --- a/source/de/anomic/kelondro/kelondroBLOBArray.java +++ b/source/de/anomic/kelondro/kelondroBLOBArray.java @@ -111,6 +111,10 @@ public class kelondroBLOBArray implements kelondroBLOB { } } + public String name() { + return this.heapLocation.getName(); + } + public void setMaxAge(long maxAge) { this.repositoryAgeMax = maxAge; this.fileAgeLimit = Math.min(oneMonth, maxAge / 10); diff --git a/source/de/anomic/kelondro/kelondroBLOBBuffer.java b/source/de/anomic/kelondro/kelondroBLOBBuffer.java index 93cac6d09..3a9722f6d 100644 --- a/source/de/anomic/kelondro/kelondroBLOBBuffer.java +++ b/source/de/anomic/kelondro/kelondroBLOBBuffer.java @@ -83,6 +83,10 @@ public class kelondroBLOBBuffer extends Thread implements kelondroBLOB { initQueues(compress); } + public String name() { + return this.backend.name(); + } + public synchronized void clear() throws IOException { initQueues(this.compressedQueue != null); this.backend.clear(); diff --git a/source/de/anomic/kelondro/kelondroBLOBHeap.java b/source/de/anomic/kelondro/kelondroBLOBHeap.java index 1297a4fc3..aa940627b 100755 --- a/source/de/anomic/kelondro/kelondroBLOBHeap.java +++ b/source/de/anomic/kelondro/kelondroBLOBHeap.java @@ -163,23 +163,28 @@ public final class kelondroBLOBHeap implements kelondroBLOB { e.printStackTrace(); } - // DEBUG /* + // DEBUG Iterator i = index.keys(true, null); - byte[] b; + //byte[] b; int c = 0; while (i.hasNext()) { key = i.next(); - System.out.println("KEY=" + new String(key)); - b = get(key); - System.out.println("BLOB=" + new String(b)); - System.out.println(); + System.out.println("*** DEBUG BLOBHeap " + this.name() + " KEY=" + new String(key)); + //b = get(key); + //System.out.println("BLOB=" + new String(b)); + //System.out.println(); c++; + if (c >= 20) break; } System.out.println("*** DEBUG - counted " + c + " BLOBs"); */ } + public String name() { + return this.heapFile.getName(); + } + /** * the number of BLOBs in the heap * @return the number of BLOBs in the heap diff --git a/source/de/anomic/kelondro/kelondroBLOBTree.java b/source/de/anomic/kelondro/kelondroBLOBTree.java index ddfc09a9f..e4295a9a3 100644 --- a/source/de/anomic/kelondro/kelondroBLOBTree.java +++ b/source/de/anomic/kelondro/kelondroBLOBTree.java @@ -97,6 +97,31 @@ public class kelondroBLOBTree implements kelondroBLOB { //this.segmentCount = 0; //if (!(tree.fileExisted)) writeSegmentCount(); buffer = new kelondroObjectBuffer(file.toString()); + /* + // debug + try { + kelondroCloneableIterator i = keys(true, false); + HashSet t = new HashSet(); + while (i.hasNext()) { + byte[] b = i.next(); + String s = new String(b); + t.add(s); + System.out.println("*** DEBUG BLOBTree " + file.getName() + " KEY=" + s); + } + Iterator j = t.iterator(); + while (j.hasNext()) { + String s = j.next(); + byte[] r = this.get(s.getBytes()); + if (r == null) System.out.println("*** DEBUG BLOBTree " + file.getName() + " KEY=" + s + " cannot be retrieved"); + } + } catch (IOException e) { + e.printStackTrace(); + } + */ + } + + public String name() { + return this.file.getName(); } public static final void delete(final File file) { @@ -376,7 +401,8 @@ public class kelondroBLOBTree implements kelondroBLOB { public class RARecord extends kelondroAbstractRA implements kelondroRA { int seekpos = 0; - + int compLength = -1; + String filekey; public RARecord(final String filekey) { @@ -384,11 +410,15 @@ public class kelondroBLOBTree implements kelondroBLOB { } public long length() throws IOException { - return Long.MAX_VALUE; + if (compLength >= 0) return compLength; + int p = 0; + while (get(filekey, p, reclen) != null) p+= reclen; + compLength = p-1; + return p-1; } - public long available() throws IOException { - return Long.MAX_VALUE; + public int available() throws IOException { + return (int) (length() - seekpos); } public int read() throws IOException { @@ -436,7 +466,7 @@ public class kelondroBLOBTree implements kelondroBLOB { if (args.length == 1) { // open a db and list keys try { - final kelondroBLOB kd = new kelondroBLOBTree(new File(args[0]), true, true, 4 ,100, '_', kelondroNaturalOrder.naturalOrder, false, false, true); + final kelondroBLOB kd = new kelondroBLOBTree(new File(args[0]), true, true, 4 ,100, '_', kelondroNaturalOrder.naturalOrder, true, false, false); System.out.println(kd.size() + " elements in DB"); final Iterator i = kd.keys(true, false); while (i.hasNext()) diff --git a/source/de/anomic/kelondro/kelondroBufferedRA.java b/source/de/anomic/kelondro/kelondroBufferedRA.java index 06245898d..d90fdecc3 100644 --- a/source/de/anomic/kelondro/kelondroBufferedRA.java +++ b/source/de/anomic/kelondro/kelondroBufferedRA.java @@ -45,8 +45,8 @@ public class kelondroBufferedRA extends kelondroAbstractRA implements kelondroRA return this.sbb; } - public long available() throws IOException { - return Long.MAX_VALUE - sbb.length(); + public int available() throws IOException { + return Integer.MAX_VALUE - sbb.length(); } public void close() throws IOException { diff --git a/source/de/anomic/kelondro/kelondroCachedRA.java b/source/de/anomic/kelondro/kelondroCachedRA.java index 23f1a8eb1..dceec32e2 100644 --- a/source/de/anomic/kelondro/kelondroCachedRA.java +++ b/source/de/anomic/kelondro/kelondroCachedRA.java @@ -53,8 +53,8 @@ public class kelondroCachedRA extends kelondroAbstractRA implements kelondroRA { return ra.length(); } - public synchronized long available() throws IOException { - return ra.length() - seekpos; + public synchronized int available() throws IOException { + return (int) (ra.length() - seekpos); } private int cacheElementNumber(final long address) { diff --git a/source/de/anomic/kelondro/kelondroChannelRA.java b/source/de/anomic/kelondro/kelondroChannelRA.java index 083444ced..a66006d25 100644 --- a/source/de/anomic/kelondro/kelondroChannelRA.java +++ b/source/de/anomic/kelondro/kelondroChannelRA.java @@ -45,8 +45,8 @@ public final class kelondroChannelRA extends kelondroAbstractRA implements kelon return channel.size(); } - public long available() throws IOException { - return channel.size() - channel.position(); + public int available() throws IOException { + return (int) (channel.size() - channel.position()); } public final void readFully(final byte[] b, final int off, final int len) throws IOException { diff --git a/source/de/anomic/kelondro/kelondroFileRA.java b/source/de/anomic/kelondro/kelondroFileRA.java index d9b7a2b81..35d30dd60 100644 --- a/source/de/anomic/kelondro/kelondroFileRA.java +++ b/source/de/anomic/kelondro/kelondroFileRA.java @@ -42,8 +42,8 @@ public final class kelondroFileRA extends kelondroAbstractRA implements kelondro return RAFile.length(); } - public long available() throws IOException { - return RAFile.length() - RAFile.getFilePointer(); + public int available() throws IOException { + return (int) (RAFile.length() - RAFile.getFilePointer()); } // pseudo-native method read diff --git a/source/de/anomic/kelondro/kelondroMap.java b/source/de/anomic/kelondro/kelondroMap.java index f5816aaca..84e902364 100644 --- a/source/de/anomic/kelondro/kelondroMap.java +++ b/source/de/anomic/kelondro/kelondroMap.java @@ -52,6 +52,29 @@ public class kelondroMap { this.cacheScore = new kelondroMScoreCluster(); this.startup = System.currentTimeMillis(); this.cachesize = cachesize; + + /* + // debug + try { + kelondroCloneableIterator i = keys(true, false); + int c = 20; + HashSet t = new HashSet(); + while (i.hasNext()) { + c--; if (c <= 0) break; + byte[] b = i.next(); + String s = new String(b); + System.out.println("*** DEBUG kelondroMap " + blob.name() + " KEY=" + s); + t.add(s); + } + Iterator j = t.iterator(); + while (j.hasNext()) { + String s = j.next(); + if (this.get(s) == null) System.out.println("*** DEBUG kelondroMap " + blob.name() + " KEY=" + s + " cannot be found."); + } + } catch (IOException e) { + e.printStackTrace(); + } + */ } /** diff --git a/source/de/anomic/kelondro/kelondroRA.java b/source/de/anomic/kelondro/kelondroRA.java index f98e109b3..57a52b238 100644 --- a/source/de/anomic/kelondro/kelondroRA.java +++ b/source/de/anomic/kelondro/kelondroRA.java @@ -43,7 +43,7 @@ public interface kelondroRA { // pseudo-native methods: public long length() throws IOException; - public long available() throws IOException; + public int available() throws IOException; public void readFully(byte[] b, int off, int len) throws IOException; diff --git a/source/de/anomic/kelondro/kelondroTree.java b/source/de/anomic/kelondro/kelondroTree.java index f28fada21..01d4e8e8c 100644 --- a/source/de/anomic/kelondro/kelondroTree.java +++ b/source/de/anomic/kelondro/kelondroTree.java @@ -1395,8 +1395,8 @@ public class kelondroTree extends kelondroCachedRecords implements kelondroIndex public static void main(final String[] args) { //cmd(args); //iterationtest(); - //bigtest(Integer.parseInt(args[0])); - randomtest(Integer.parseInt(args[0])); + bigtest(Integer.parseInt(args[0])); + //randomtest(Integer.parseInt(args[0])); //smalltest(); }