Skip to content

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

fixed new EcoRecords-Nodes. Here I omitted object content copying before to avoid massive System.arraycopy. That did obviously not protect enough the Node objects

orbiter9678d1b2825d
diff --git a/source/de/anomic/kelondro/kelondroEcoRecords.java b/source/de/anomic/kelondro/kelondroEcoRecords.java
index 87b25a029..1c99d893f 100644
--- a/source/de/anomic/kelondro/kelondroEcoRecords.java
+++ b/source/de/anomic/kelondro/kelondroEcoRecords.java
@@ -91,15 +91,15 @@ public class kelondroEcoRecords extends kelondroAbstractRecords {
// create chunks
this.ohChunk = new byte[overhead];
+ this.bodyChunk = new byte[ROW.objectsize()];
for (int i = this.ohChunk.length - 1; i >= 0; i--) this.ohChunk[i] = (byte) 0xff;
if (rowinstance == null) {
- this.bodyChunk = new byte[ROW.objectsize()];
for (int i = this.bodyChunk.length - 1; i >= 0; i--) this.bodyChunk[i] = (byte) 0xff;
} else {
- this.bodyChunk = rowinstance;
+ System.arraycopy(rowinstance, 0, this.bodyChunk, 0, this.bodyChunk.length);
}
- // mark chunks as not changed
+ // mark chunks as not changed, we wrote that already during allocatePayload
this.ohChanged = false;
this.bodyChanged = false;
}
@@ -120,24 +120,24 @@ public class kelondroEcoRecords extends kelondroAbstractRecords {
}
assert ((bulkchunk == null) || (bulkchunk.length - offset >= recordsize)) : "bulkchunk.length = " + bulkchunk.length + ", offset = " + offset + ", recordsize = " + recordsize;
- if ((offset == 0) && (overhead == 0) && ((bulkchunk == null) || (bulkchunk.length == ROW.objectsize()))) {
+ /*if ((offset == 0) && (overhead == 0) && ((bulkchunk == null) || (bulkchunk.length == ROW.objectsize()))) {
this.ohChunk = new byte[0];
if (bulkchunk == null) {
this.bodyChunk = new byte[ROW.objectsize()];
} else {
this.bodyChunk = bulkchunk;
}
- } else {
+ } else { */
// create empty chunks
this.ohChunk = new byte[overhead];
this.bodyChunk = new byte[ROW.objectsize()];
// write content to chunks
if (bulkchunk != null) {
- System.arraycopy(bulkchunk, offset, this.ohChunk, 0, overhead);
+ if (overhead > 0) System.arraycopy(bulkchunk, offset, this.ohChunk, 0, overhead);
System.arraycopy(bulkchunk, offset + overhead, this.bodyChunk, 0, ROW.objectsize());
}
- }
+ //}
// mark chunks as changed
this.ohChanged = changed;
@@ -150,9 +150,7 @@ public class kelondroEcoRecords extends kelondroAbstractRecords {
// but we expect that values are already there in the file.
assert (handle != null): "node handle is null";
assert (handle.index >= 0): "node handle too low: " + handle.index;
- //assert (handle.index < USAGE.allCount()) : "node handle too high: " + handle.index + ", USEDC=" + USAGE.USEDC + ", FREEC=" + USAGE.FREEC;
-
- // the parentNode can be given if an auto-fix in the following case is wanted
+
if (handle == null) throw new kelondroException(filename, "INTERNAL ERROR: node handle is null.");
if (handle.index >= USAGE.allCount()) {
throw new kelondroException(filename, "INTERNAL ERROR, Node/init: node handle index " + handle.index + " exceeds size. No auto-fix node was submitted. This is a serious failure.");
@@ -161,24 +159,11 @@ public class kelondroEcoRecords extends kelondroAbstractRecords {
// use given handle
this.handle = new kelondroHandle(handle.index);
- // read complete record
- byte[] bulkchunk = new byte[recordsize];
- entryFile.readFully(seekpos(this.handle), bulkchunk, 0, recordsize);
-
- if ((overhead == 0) && (bulkchunk.length == ROW.objectsize())) {
- this.ohChunk = new byte[0];
- this.bodyChunk = bulkchunk;
- } else {
- // create empty chunks
- this.ohChunk = new byte[overhead];
- this.bodyChunk = new byte[ROW.objectsize()];
-
- // write content to chunks
- if (bulkchunk != null) {
- System.arraycopy(bulkchunk, 0, this.ohChunk, 0, overhead);
- System.arraycopy(bulkchunk, 0 + overhead, this.bodyChunk, 0, ROW.objectsize());
- }
- }
+ // read record
+ this.ohChunk = new byte[overhead];
+ this.bodyChunk = new byte[ROW.objectsize()];
+ if (overhead > 0) entryFile.readFully(seekpos(this.handle), this.ohChunk, 0, overhead);
+ entryFile.readFully(seekpos(this.handle) + overhead, this.bodyChunk, 0, this.bodyChunk.length);
// mark chunks as not changed
this.ohChanged = false;
@@ -268,7 +253,7 @@ public class kelondroEcoRecords extends kelondroAbstractRecords {
synchronized (entryFile) {
if (this.ohChanged) {
//System.out.println("WRITEH(" + filename + ", " + seekpos(this.handle) + ", " + this.headChunk.length + ")");
- assert (ohChunk == null) || (ohChunk.length == headchunksize);
+ assert (ohChunk == null) || (ohChunk.length == overhead);
entryFile.write(seekpos(this.handle), (this.ohChunk == null) ? new byte[overhead] : this.ohChunk);
this.ohChanged = false;
}
diff --git a/source/de/anomic/kelondro/kelondroFixedWidthArray.java b/source/de/anomic/kelondro/kelondroFixedWidthArray.java
index 37fbbbf7a..2d954cb46 100644
--- a/source/de/anomic/kelondro/kelondroFixedWidthArray.java
+++ b/source/de/anomic/kelondro/kelondroFixedWidthArray.java
@@ -60,6 +60,7 @@ public class kelondroFixedWidthArray extends kelondroEcoRecords implements kelon
public kelondroFixedWidthArray(File file, kelondroRow rowdef, int intprops) throws IOException {
// this creates a new array
+ //super(file, true, -1, thisOHBytes, thisOHHandles, rowdef, intprops, rowdef.columns() /* txtProps */, 80 /* txtPropWidth */);
super(file, thisOHBytes, thisOHHandles, rowdef, intprops, rowdef.columns() /* txtProps */, 80 /* txtPropWidth */);
if (!(super.fileExisted)) {
for (int i = 0; i < intprops; i++) {
@@ -74,6 +75,7 @@ public class kelondroFixedWidthArray extends kelondroEcoRecords implements kelon
public kelondroFixedWidthArray(kelondroRA ra, String filename, kelondroRow rowdef, int intprops) throws IOException {
// this creates a new array
+ //super(ra, filename, true, -1, thisOHBytes, thisOHHandles, rowdef, intprops, rowdef.columns() /* txtProps */, 80 /* txtPropWidth */, false);
super(ra, filename, thisOHBytes, thisOHHandles, rowdef, intprops, rowdef.columns() /* txtProps */, 80 /* txtPropWidth */, false);
for (int i = 0; i < intprops; i++) {
setHandle(i, new kelondroHandle(0));
diff --git a/source/de/anomic/kelondro/kelondroFlexWidthArray.java b/source/de/anomic/kelondro/kelondroFlexWidthArray.java
index 137abdeab..c0571ed54 100644
--- a/source/de/anomic/kelondro/kelondroFlexWidthArray.java
+++ b/source/de/anomic/kelondro/kelondroFlexWidthArray.java
@@ -214,6 +214,7 @@ public class kelondroFlexWidthArray implements kelondroArray {
}
public int size() {
+ //assert ((rowdef.columns() == 1) || (col[0].size() == col[1].size())) : "col[0].size() = " + col[0].size() + ", col[1].size() = " + col[1].size() + ", file = " + filename;
return col[0].size();
}