major bugfix (searched a whole week for the bug) for

the kelondroRowBuffer, which has effect mostly to the
kelondroFlexTable but also to all other database functions

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@2260 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
orbiter 19 years ago
parent f9b9d085c4
commit dd2865178a

@ -3,7 +3,7 @@ javacSource=1.4
javacTarget=1.4 javacTarget=1.4
# Release Configuration # Release Configuration
releaseVersion=0.455 releaseVersion=0.456
releaseFile=yacy_dev_v${releaseVersion}_${DSTAMP}_${releaseNr}.tar.gz releaseFile=yacy_dev_v${releaseVersion}_${DSTAMP}_${releaseNr}.tar.gz
#releaseFile=yacy_v${releaseVersion}_${DSTAMP}_${releaseNr}.tar.gz #releaseFile=yacy_v${releaseVersion}_${DSTAMP}_${releaseNr}.tar.gz
releaseDir=yacy_dev_v${releaseVersion}_${DSTAMP}_${releaseNr} releaseDir=yacy_dev_v${releaseVersion}_${DSTAMP}_${releaseNr}

@ -70,8 +70,10 @@ public abstract class kelondroAbstractOrder implements kelondroOrder {
return compare(((Node) a).getKey(), ((Node) b).getKey()); return compare(((Node) a).getKey(), ((Node) b).getKey());
} else if ((a instanceof String) && (b instanceof String)) { } else if ((a instanceof String) && (b instanceof String)) {
return compare(((String) a).getBytes(), ((String) b).getBytes()); return compare(((String) a).getBytes(), ((String) b).getBytes());
} else } /* else if ((a instanceof Integer) && (b instanceof Integer)) {
throw new IllegalArgumentException("Object type or Object type combination not supported: a=" + a + ", b=" + b); return ((Integer) a).compareTo((Integer) b);
} */ else
throw new IllegalArgumentException("Object type or Object type combination not supported: a=" + a + "[" + a.getClass().getName() + "], b=" + b + "[" + b.getClass().getName() + "]");
} }
public byte[] zero() { public byte[] zero() {

@ -33,19 +33,19 @@ public class kelondroRowBufferedSet extends kelondroRowSet {
private static final long memBlockLimit = 2000000; // do not fill cache further if the amount of available memory is less that this private static final long memBlockLimit = 2000000; // do not fill cache further if the amount of available memory is less that this
private static final int bufferFlushLimit = 10000; private static final int bufferFlushLimit = 10000;
private static final int bufferFlushMinimum = 1000; private static final int bufferFlushMinimum = 1000;
private final boolean useRowCollection = false; private final boolean useRowCollection = true;
private kelondroProfile profile; private kelondroProfile profile;
private TreeMap buffer; private TreeMap buffer;
public kelondroRowBufferedSet(kelondroRow rowdef) { public kelondroRowBufferedSet(kelondroRow rowdef) {
super(rowdef); super(rowdef);
buffer = new TreeMap(); buffer = new TreeMap(kelondroNaturalOrder.naturalOrder);
profile = new kelondroProfile(); profile = new kelondroProfile();
} }
public kelondroRowBufferedSet(kelondroRow rowdef, int objectCount) { public kelondroRowBufferedSet(kelondroRow rowdef, int objectCount) {
super(rowdef, objectCount); super(rowdef, objectCount);
buffer = new TreeMap(); buffer = new TreeMap(kelondroNaturalOrder.naturalOrder);
profile = new kelondroProfile(); profile = new kelondroProfile();
} }
@ -72,7 +72,8 @@ public class kelondroRowBufferedSet extends kelondroRowSet {
if (buffer.size() == 0) { if (buffer.size() == 0) {
super.removeOne(); super.removeOne();
} else { } else {
buffer.remove(buffer.keySet().iterator().next()); //buffer.remove(buffer.keySet().iterator().next());
buffer.remove(buffer.lastKey());
} }
} }
} }
@ -118,6 +119,7 @@ public class kelondroRowBufferedSet extends kelondroRowSet {
} }
} }
/*
public void add(byte[] a) { public void add(byte[] a) {
this.add(super.rowdef.newEntry(a)); this.add(super.rowdef.newEntry(a));
} }
@ -125,12 +127,13 @@ public class kelondroRowBufferedSet extends kelondroRowSet {
public void add(kelondroRow.Entry a) { public void add(kelondroRow.Entry a) {
this.put(a); this.put(a);
} }
*/
public kelondroRow.Entry get(byte[] key) { public kelondroRow.Entry get(byte[] key) {
long handle = profile.startRead(); long handle = profile.startRead();
kelondroRow.Entry entry = null; kelondroRow.Entry entry = null;
synchronized (buffer) { synchronized (buffer) {
entry = (kelondroRow.Entry) buffer.get(new Integer((int) kelondroNaturalOrder.decodeLong(key))); entry = (kelondroRow.Entry) buffer.get(key);
if ((entry == null) && (useRowCollection)) entry = super.get(key); if ((entry == null) && (useRowCollection)) entry = super.get(key);
} }
profile.stopRead(handle); profile.stopRead(handle);
@ -141,16 +144,15 @@ public class kelondroRowBufferedSet extends kelondroRowSet {
long handle = profile.startWrite(); long handle = profile.startWrite();
byte[] key = newentry.getColBytes(super.sortColumn); byte[] key = newentry.getColBytes(super.sortColumn);
kelondroRow.Entry oldentry = null; kelondroRow.Entry oldentry = null;
Integer intk = new Integer((int) kelondroNaturalOrder.decodeLong(key));
synchronized (buffer) { synchronized (buffer) {
if (useRowCollection) { if (useRowCollection) {
oldentry = (kelondroRow.Entry) buffer.get(intk); oldentry = (kelondroRow.Entry) buffer.get(key);
if (oldentry == null) { if (oldentry == null) {
// try the collection // try the collection
oldentry = super.get(key); oldentry = super.get(key);
if (oldentry == null) { if (oldentry == null) {
// this was not anywhere // this was not anywhere
buffer.put(intk, newentry); buffer.put(key, newentry);
if (((buffer.size() > bufferFlushMinimum) && (kelondroRecords.availableMemory() > memBlockLimit)) || if (((buffer.size() > bufferFlushMinimum) && (kelondroRecords.availableMemory() > memBlockLimit)) ||
(buffer.size() > bufferFlushLimit)) flush(); (buffer.size() > bufferFlushLimit)) flush();
} else { } else {
@ -160,10 +162,10 @@ public class kelondroRowBufferedSet extends kelondroRowSet {
} else { } else {
// the entry is already in buffer // the entry is already in buffer
// simply replace old entry // simply replace old entry
buffer.put(intk, newentry); buffer.put(key, newentry);
} }
} else { } else {
oldentry = (kelondroRow.Entry) buffer.put(intk, newentry); oldentry = (kelondroRow.Entry) buffer.put(key, newentry);
} }
} }
profile.stopWrite(handle); profile.stopWrite(handle);
@ -174,7 +176,7 @@ public class kelondroRowBufferedSet extends kelondroRowSet {
long handle = profile.startDelete(); long handle = profile.startDelete();
kelondroRow.Entry oldentry = null; kelondroRow.Entry oldentry = null;
synchronized (buffer) { synchronized (buffer) {
oldentry = (kelondroRow.Entry) buffer.remove(new Integer((int) kelondroNaturalOrder.decodeLong(key))); oldentry = (kelondroRow.Entry) buffer.remove(key);
if ((oldentry == null) && (useRowCollection)) { if ((oldentry == null) && (useRowCollection)) {
// try the collection // try the collection
oldentry = super.removeShift(key); oldentry = super.removeShift(key);
@ -188,7 +190,7 @@ public class kelondroRowBufferedSet extends kelondroRowSet {
long handle = profile.startDelete(); long handle = profile.startDelete();
kelondroRow.Entry oldentry = null; kelondroRow.Entry oldentry = null;
synchronized (buffer) { synchronized (buffer) {
oldentry = (kelondroRow.Entry) buffer.remove(new Integer((int) kelondroNaturalOrder.decodeLong(key))); oldentry = (kelondroRow.Entry) buffer.remove(key);
if ((oldentry == null) && (useRowCollection)) { if ((oldentry == null) && (useRowCollection)) {
// try the collection // try the collection
return super.removeMarked(key); return super.removeMarked(key);

Loading…
Cancel
Save