java.lang.NullPointerException
	at net.yacy.kelondro.index.RowCollection.<init>(RowCollection.java:97)
	at net.yacy.kelondro.index.RowSet.<init>(RowSet.java:48)
	at net.yacy.kelondro.rwi.ReferenceContainer.<init>(ReferenceContainer.java:58)
	at net.yacy.kelondro.rwi.ReferenceIterator.next(ReferenceIterator.java:69)
	at net.yacy.kelondro.rwi.ReferenceIterator.next(ReferenceIterator.java:43)
	at net.yacy.kelondro.blob.ArrayStack.merge(ArrayStack.java:1023)
	at net.yacy.kelondro.blob.ArrayStack.mergeWorker(ArrayStack.java:922)
	at net.yacy.kelondro.blob.ArrayStack.mergeMount(ArrayStack.java:869)
	at net.yacy.kelondro.rwi.IODispatcher$MergeJob.merge(IODispatcher.java:267)
	at net.yacy.kelondro.rwi.IODispatcher$MergeJob.access$300(IODispatcher.java:239)
	at net.yacy.kelondro.rwi.IODispatcher.run(IODispatcher.java:180)

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@7822 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
orbiter 14 years ago
parent 719777b2a7
commit 6d2e252bcf

@ -76,29 +76,29 @@ public class RowSet extends RowCollection implements Index, Iterable<Row.Entry>
public final static RowSet importRowSet(final byte[] b, final Row rowdef) throws RowSpaceExceededException { public final static RowSet importRowSet(final byte[] b, final Row rowdef) throws RowSpaceExceededException {
assert b.length >= exportOverheadSize : "b.length = " + b.length; assert b.length >= exportOverheadSize : "b.length = " + b.length;
if (b.length < exportOverheadSize) return new RowSet(rowdef); if (b.length < exportOverheadSize) return new RowSet(rowdef, 0);
final int size = (int) NaturalOrder.decodeLong(b, 0, 4); final int size = (int) NaturalOrder.decodeLong(b, 0, 4);
assert size >= 0 : "size = " + size; assert size >= 0 : "size = " + size;
if (size < 0) return new RowSet(rowdef); if (size < 0) return new RowSet(rowdef, 0);
final int orderbound = (int) NaturalOrder.decodeLong(b, 10, 4); final int orderbound = (int) NaturalOrder.decodeLong(b, 10, 4);
assert orderbound >= 0 : "orderbound = " + orderbound; assert orderbound >= 0 : "orderbound = " + orderbound;
if (orderbound < 0) return new RowSet(rowdef); // error if (orderbound < 0) return new RowSet(rowdef, 0); // error
final long alloc = ((long) size) * ((long) rowdef.objectsize); final long alloc = ((long) size) * ((long) rowdef.objectsize);
assert alloc <= Integer.MAX_VALUE : "alloc = " + alloc; assert alloc <= Integer.MAX_VALUE : "alloc = " + alloc;
if (alloc > Integer.MAX_VALUE) return null; if (alloc > Integer.MAX_VALUE) throw new RowSpaceExceededException((int) alloc, "importRowSet: alloc > Integer.MAX_VALUE");
assert alloc == b.length - exportOverheadSize; assert alloc == b.length - exportOverheadSize;
if (alloc != b.length - exportOverheadSize) return null; if (alloc != b.length - exportOverheadSize) throw new RowSpaceExceededException((int) alloc, "importRowSet: alloc != b.length - exportOverheadSize");
MemoryControl.request((int) alloc, true); MemoryControl.request((int) alloc, true);
final byte[] chunkcache; final byte[] chunkcache;
try { try {
chunkcache = new byte[(int) alloc]; chunkcache = new byte[(int) alloc];
} catch (final OutOfMemoryError e) { } catch (final OutOfMemoryError e) {
throw new RowSpaceExceededException((int) alloc, "importRowSet"); throw new RowSpaceExceededException((int) alloc, "importRowSet: OutOfMemoryError");
} }
//assert b.length - exportOverheadSize == size * rowdef.objectsize : "b.length = " + b.length + ", size * rowdef.objectsize = " + size * rowdef.objectsize; //assert b.length - exportOverheadSize == size * rowdef.objectsize : "b.length = " + b.length + ", size * rowdef.objectsize = " + size * rowdef.objectsize;
if (b.length - exportOverheadSize != alloc) { if (b.length - exportOverheadSize != alloc) {
Log.logSevere("RowSet", "exportOverheadSize wrong: b.length = " + b.length + ", size * rowdef.objectsize = " + size * rowdef.objectsize); Log.logSevere("RowSet", "exportOverheadSize wrong: b.length = " + b.length + ", size * rowdef.objectsize = " + size * rowdef.objectsize);
return new RowSet(rowdef); return new RowSet(rowdef, 0);
} }
System.arraycopy(b, (int) exportOverheadSize, chunkcache, 0, chunkcache.length); System.arraycopy(b, (int) exportOverheadSize, chunkcache, 0, chunkcache.length);
return new RowSet(rowdef, size, chunkcache, orderbound); return new RowSet(rowdef, size, chunkcache, orderbound);

@ -28,7 +28,6 @@ package net.yacy.kelondro.rwi;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.Iterator;
import java.util.Map; import java.util.Map;
import net.yacy.kelondro.blob.HeapReader; import net.yacy.kelondro.blob.HeapReader;
@ -36,62 +35,59 @@ import net.yacy.kelondro.index.RowSet;
import net.yacy.kelondro.index.RowSpaceExceededException; import net.yacy.kelondro.index.RowSpaceExceededException;
import net.yacy.kelondro.logging.Log; import net.yacy.kelondro.logging.Log;
import net.yacy.kelondro.order.CloneableIterator; import net.yacy.kelondro.order.CloneableIterator;
import net.yacy.kelondro.util.LookAheadIterator;
/** /**
* iterator of BLOBHeap files: is used to import heap dumps into a write-enabled index heap * iterator of BLOBHeap files: is used to import heap dumps into a write-enabled index heap
*/ */
public class ReferenceIterator <ReferenceType extends Reference> implements CloneableIterator<ReferenceContainer<ReferenceType>>, Iterable<ReferenceContainer<ReferenceType>> { public class ReferenceIterator <ReferenceType extends Reference> extends LookAheadIterator<ReferenceContainer<ReferenceType>> implements CloneableIterator<ReferenceContainer<ReferenceType>>, Iterable<ReferenceContainer<ReferenceType>> {
HeapReader.entries blobs; HeapReader.entries blobs;
File blobFile; File blobFile;
ReferenceFactory<ReferenceType> factory; ReferenceFactory<ReferenceType> factory;
public ReferenceIterator(final File blobFile, ReferenceFactory<ReferenceType> factory) throws IOException { public ReferenceIterator(final File blobFile, final ReferenceFactory<ReferenceType> factory) throws IOException {
this.blobs = new HeapReader.entries(blobFile, factory.getRow().primaryKeyLength); this.blobs = new HeapReader.entries(blobFile, factory.getRow().primaryKeyLength);
this.blobFile = blobFile; this.blobFile = blobFile;
this.factory = factory; this.factory = factory;
} }
public boolean hasNext() {
if (blobs == null) return false;
if (blobs.hasNext()) return true;
close();
return false;
}
/** /**
* return an index container * return an index container
* because they may get very large, it is wise to deallocate some memory before calling next() * because they may get very large, it is wise to deallocate some memory before calling next()
*/ */
public ReferenceContainer<ReferenceType> next() { public ReferenceContainer<ReferenceType> next0() {
Map.Entry<byte[], byte[]> entry = blobs.next(); if (this.blobs == null) return null;
byte[] payload = entry.getValue(); RowSet row;
Map.Entry<byte[], byte[]> entry;
while (this.blobs.hasNext()) {
entry = this.blobs.next();
try { try {
return new ReferenceContainer<ReferenceType>(factory, entry.getKey(), RowSet.importRowSet(payload, factory.getRow())); row = RowSet.importRowSet(entry.getValue(), this.factory.getRow());
} catch (RowSpaceExceededException e) { if (row == null) {
Log.logSevere("ReferenceIterator", "lost entry '" + entry.getKey() + "' because of too low memory: " + e.toString()); Log.logSevere("ReferenceIterator", "lost entry '" + entry.getKey() + "' because importRowSet returned null");
return null; continue; // thats a fail but not as REALLY bad if the whole method would crash here
} }
return new ReferenceContainer<ReferenceType>(this.factory, entry.getKey(), row);
} catch (final RowSpaceExceededException e) {
Log.logSevere("ReferenceIterator", "lost entry '" + entry.getKey() + "' because of too low memory: " + e.toString());
continue;
} }
public void remove() {
throw new UnsupportedOperationException("heap dumps are read-only");
} }
close();
public Iterator<ReferenceContainer<ReferenceType>> iterator() { return null;
return this;
} }
public void close() { public void close() {
if (blobs != null) this.blobs.close(); if (this.blobs != null) this.blobs.close();
blobs = null; this.blobs = null;
} }
public CloneableIterator<ReferenceContainer<ReferenceType>> clone(Object modifier) { public CloneableIterator<ReferenceContainer<ReferenceType>> clone(final Object modifier) {
if (blobs != null) this.blobs.close(); if (this.blobs != null) this.blobs.close();
blobs = null; this.blobs = null;
try { try {
return new ReferenceIterator<ReferenceType>(this.blobFile, factory); return new ReferenceIterator<ReferenceType>(this.blobFile, this.factory);
} catch (IOException e) { } catch (final IOException e) {
Log.logException(e); Log.logException(e);
return null; return null;
} }

@ -43,7 +43,7 @@ public abstract class LookAheadIterator<A> implements Iterator<A>, Iterable<A> {
public LookAheadIterator() { public LookAheadIterator() {
} }
public Iterator<A> iterator() { public final Iterator<A> iterator() {
return this; return this;
} }
@ -54,21 +54,21 @@ public abstract class LookAheadIterator<A> implements Iterator<A>, Iterable<A> {
protected abstract A next0() ; protected abstract A next0() ;
private final void checkInit() { private final void checkInit() {
if (fresh) { if (this.fresh) {
next = next0(); this.next = next0();
fresh = false; this.fresh = false;
} }
} }
public final boolean hasNext() { public final boolean hasNext() {
checkInit(); checkInit();
return next != null; return this.next != null;
} }
public final A next() { public final A next() {
checkInit(); checkInit();
A n = next; final A n = this.next;
next = next0(); this.next = next0();
return n; return n;
} }

Loading…
Cancel
Save