- more asserts

- bugfix for reading of previously deleted nodex

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@2845 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
orbiter 19 years ago
parent 5a6488256d
commit 278d8c3c7e

@ -48,15 +48,17 @@ package de.anomic.kelondro;
import java.util.Comparator;
import de.anomic.server.logging.serverLog;
public class kelondroBase64Order extends kelondroAbstractOrder implements kelondroOrder, kelondroCoding, Comparator {
private static final char[] alpha_standard = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".toCharArray();
private static final char[] alpha_enhanced = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_".toCharArray();
private static final byte[] ahpla_standard = new byte[256];
private static final byte[] ahpla_enhanced = new byte[256];
private static final byte[] ahpla_standard = new byte[128];
private static final byte[] ahpla_enhanced = new byte[128];
static {
for (int i = 0; i < 256; i++) {
for (int i = 0; i < 128; i++) {
ahpla_standard[i] = -1;
ahpla_enhanced[i] = -1;
}
@ -279,13 +281,28 @@ public class kelondroBase64Order extends kelondroAbstractOrder implements kelond
}
public final int compares(byte[] a, int aoffset, int alength, byte[] b, int boffset, int blength) {
assert (aoffset + alength <= a.length) : "a.length = " + a.length + ", aoffset = " + aoffset + ", alength = " + alength;
assert (boffset + blength <= b.length) : "b.length = " + b.length + ", boffset = " + boffset + ", blength = " + blength;
assert (ahpla.length == 128);
int i = 0;
final int al = Math.min(alength, a.length - aoffset);
final int bl = Math.min(blength, b.length - boffset);
final int len = (al > bl) ? bl : al;
byte ac, bc;
byte acc, bcc;
while (i < len) {
if (ahpla[a[i + aoffset]] > ahpla[b[i + boffset]]) return 1;
if (ahpla[a[i + aoffset]] < ahpla[b[i + boffset]]) return -1;
assert (i + aoffset < a.length) : "i = " + i + ", aoffset = " + aoffset + ", a.length = " + a.length + ", a = " + serverLog.arrayList(a, aoffset, len);
assert (i + boffset < b.length) : "i = " + i + ", boffset = " + boffset + ", b.length = " + b.length + ", b = " + serverLog.arrayList(b, boffset, len);
ac = a[aoffset + i];
assert (ac >= 0) && (ac < 128) : "ac = " + ac + ", a = " + serverLog.arrayList(a, aoffset, len);
bc = b[boffset + i];
assert (bc >= 0) && (bc < 128) : "bc = " + bc + ", b = " + serverLog.arrayList(b, boffset, len);
acc = ahpla[ac];
assert (acc >= 0) : "acc = " + acc + ", a = " + serverLog.arrayList(a, aoffset, len);
bcc = ahpla[bc];
assert (bcc >= 0) : "bcc = " + bcc + ", b = " + serverLog.arrayList(b, boffset, len);
if (acc > bcc) return 1;
if (acc < bcc) return -1;
// else the bytes are equal and it may go on yet undecided
i++;
}

@ -91,7 +91,7 @@ public class kelondroFlexTable extends kelondroFlexWidthArray implements kelondr
node = (kelondroRecords.Node) content.next();
i = node.handle().hashCode();
indexentry = ri.row().newEntry();
indexentry.setCol(0, node.getValueRow());
indexentry.setCol(0, node.getKey());
indexentry.setCol(1, i);
ri.addUnique(indexentry);
if ((i % 10000) == 0) {

@ -1096,10 +1096,12 @@ public class kelondroRecords {
private byte[] bulk;
private int bulksize;
private int bulkstart; // the offset of the bulk array to the node position
private boolean fullyMarked;
public contentNodeIterator(long maxInitTime) throws IOException, kelondroException {
// initialize markedDeleted set of deleted Handles
markedDeleted = deletedHandles(maxInitTime);
fullyMarked = (maxInitTime < 0);
// seek first position according the delete node set
pos = new Handle(0);
@ -1116,6 +1118,21 @@ public class kelondroRecords {
}
public Object next() {
// read Objects until a non-deleted Node appears
while (hasNext()) {
Node nn = next0();
byte[] key = nn.getKey();
if ((key == null) || ((key[0] == 0) && (key[1] == 0)) || ((key[2] == 0) && (key[3] == 0))) {
// this is an deleted node; probably not commited with dispose
if (fullyMarked) try {dispose(nn.handle);} catch (IOException e) {} // mark this now as deleted
continue;
}
return nn;
}
return null;
}
public Node next0() {
try {
// see if the next record is in the bulk, and if not re-fill the bulk
if ((pos.index - bulkstart) >= bulksize) {

@ -264,11 +264,13 @@ public class kelondroRow {
private void setCol(int encoding, int offset, int length, byte[] cell) {
if (cell == null) {
while (length-- > 0) rowinstance[offset + length] = 0;
while (length-- >= 0) rowinstance[offset + length] = 0;
} else {
System.arraycopy(cell, 0, rowinstance, offset, Math.min(cell.length, length));
if (cell.length < length) {
while (length-- > cell.length) rowinstance[offset + length] = 0;
System.arraycopy(cell, 0, rowinstance, offset, cell.length);
while (length-- >= cell.length) rowinstance[offset + length] = 0;
} else {
System.arraycopy(cell, 0, rowinstance, offset, length);
}
}
}

@ -453,10 +453,13 @@ public class kelondroRowCollection {
}
private final int compare(int i, int j) {
assert (i < chunkcount);
assert (j < chunkcount);
assert (chunkcount * this.rowdef.objectsize() <= chunkcache.length) : "chunkcount = " + chunkcount + ", objsize = " + this.rowdef.objectsize() + ", chunkcache.length = " + chunkcache.length;
assert (i >= 0) && (i < chunkcount) : "i = " + i + ", chunkcount = " + chunkcount;
assert (j >= 0) && (j < chunkcount) : "j = " + j + ", chunkcount = " + chunkcount;
if (i == j) return 0;
assert (this.sortColumn == 0) : "this.sortColumn = " + this.sortColumn;
int keylength = this.rowdef.width(this.sortColumn);
assert (keylength <= 12) : "keylength = " + keylength;
int colstart = this.rowdef.colstart[this.sortColumn];
int c = this.sortOrder.compare(
chunkcache,

@ -217,4 +217,12 @@ public final class serverLog {
for (int i = l + n; i > n; n--) sb.insert(0, fillChar);
return sb.toString();
}
public static final String arrayList(byte[] b, int start, int length) {
StringBuffer sb = new StringBuffer(b.length * 4);
sb.append('[').append(Integer.toString((int) b[start])).append(',');
for (int i = 1; i < length; i++) sb.append(' ').append(Integer.toString((int) b[start + i])).append(',');
sb.append(']');
return sb.toString();
}
}

@ -1325,6 +1325,12 @@ public final class yacy {
*/
public static void main(String args[]) {
// check assertion status
//ClassLoader.getSystemClassLoader().setDefaultAssertionStatus(true);
boolean assertionenabled = false;
assert assertionenabled = true;
if (assertionenabled) System.out.println("Asserts are enabled");
// check memory amount
System.gc();
long startupMemFree = Runtime.getRuntime().freeMemory(); // the amount of free memory in the Java Virtual Machine

Loading…
Cancel
Save