Skip to content

Commit

Permalink
fixed new EcoRecords-Nodes. Here I omitted object content copying before
Browse files Browse the repository at this point in the history
to avoid massive System.arraycopy. That did obviously not protect enough the Node objects


git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@4032 6c8d7289-2bf4-0310-a012-ef5d649a1542
  • Loading branch information
orbiter committed Aug 6, 2007
1 parent 1af0e3b commit 9678d1b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 29 deletions.
43 changes: 14 additions & 29 deletions source/de/anomic/kelondro/kelondroEcoRecords.java
Expand Up @@ -91,15 +91,15 @@ public EcoNode(byte[] rowinstance) throws IOException {

// 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;
}
Expand All @@ -120,24 +120,24 @@ public EcoNode(kelondroHandle handle, byte[] bulkchunk, int offset) throws IOExc
}
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;
Expand All @@ -150,9 +150,7 @@ public EcoNode(kelondroHandle handle) throws IOException {
// 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.");
Expand All @@ -161,24 +159,11 @@ public EcoNode(kelondroHandle handle) throws IOException {
// 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;
Expand Down Expand Up @@ -268,7 +253,7 @@ public synchronized void commit() throws IOException {
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;
}
Expand Down
2 changes: 2 additions & 0 deletions source/de/anomic/kelondro/kelondroFixedWidthArray.java
Expand Up @@ -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++) {
Expand All @@ -74,6 +75,7 @@ public kelondroFixedWidthArray(File file, kelondroRow rowdef, int intprops) thro

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));
Expand Down
1 change: 1 addition & 0 deletions source/de/anomic/kelondro/kelondroFlexWidthArray.java
Expand Up @@ -214,6 +214,7 @@ public kelondroRow row() {
}

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();
}

Expand Down

0 comments on commit 9678d1b

Please sign in to comment.