fix for "negative seek offset" error during extension of heap files.

This would have always happend when a heap file exceeds 2GB.
should fix https://github.com/yacy/yacy_search_server/issues/372
pull/607/head
Michael Peter Christen 1 year ago
parent 9c8fb97985
commit 4a54b24703

@ -117,7 +117,6 @@ public final class Heap extends HeapModifier implements BLOB {
return super.size() + ((this.buffer == null) ? 0 : this.buffer.size()); return super.size() + ((this.buffer == null) ? 0 : this.buffer.size());
} }
/** /**
* test if a key is in the heap file. This does not need any IO, because it uses only the ram index * test if a key is in the heap file. This does not need any IO, because it uses only the ram index
* @param key * @param key
@ -147,7 +146,7 @@ public final class Heap extends HeapModifier implements BLOB {
private void add(byte[] key, final byte[] blob) throws IOException { private void add(byte[] key, final byte[] blob) throws IOException {
assert blob.length > 0; assert blob.length > 0;
if ((blob == null) || (blob.length == 0)) return; if ((blob == null) || (blob.length == 0)) return;
final int pos = (int) this.file.length(); final long pos = this.file.length();
try { try {
this.index.put(key, pos); this.index.put(key, pos);
this.file.seek(pos); this.file.seek(pos);
@ -283,7 +282,7 @@ public final class Heap extends HeapModifier implements BLOB {
ConcurrentLog.info("Heap", "clearing heap " + this.name()); ConcurrentLog.info("Heap", "clearing heap " + this.name());
assert this.buffer != null; assert this.buffer != null;
if (this.buffer == null) this.buffer = new TreeMap<byte[], byte[]>(this.ordering); if (this.buffer == null) this.buffer = new TreeMap<byte[], byte[]>(this.ordering);
this.buffer.clear(); this.buffer.clear();
this.buffersize = 0; this.buffersize = 0;
super.clear(); super.clear();
} }
@ -294,16 +293,16 @@ public final class Heap extends HeapModifier implements BLOB {
@Override @Override
public synchronized void close(final boolean writeIDX) { public synchronized void close(final boolean writeIDX) {
ConcurrentLog.info("Heap", "closing heap " + this.name()); ConcurrentLog.info("Heap", "closing heap " + this.name());
if (this.file != null && this.buffer != null) { if (this.file != null && this.buffer != null) {
try { try {
flushBuffer(); flushBuffer();
} catch (final IOException e) { } catch (final IOException e) {
ConcurrentLog.logException(e); ConcurrentLog.logException(e);
} }
} }
this.buffer = null; this.buffer = null;
super.close(writeIDX); super.close(writeIDX);
assert this.file == null; assert this.file == null;
} }
@Override @Override

Loading…
Cancel
Save