fix for a OOM in MapView that can cause unavailability of

- seed list
- bookmarks
during very low memory configuration

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@6529 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
orbiter 15 years ago
parent d548bd41ad
commit c14233a933

@ -116,11 +116,12 @@ public class MapView {
return bb.toString(); return bb.toString();
} }
private static Map<String, String> bytes2map(byte[] b) throws IOException { private static Map<String, String> bytes2map(byte[] b) throws IOException, RowSpaceExceededException {
final BufferedReader br = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(b))); final BufferedReader br = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(b)));
final Map<String, String> map = new HashMap<String, String>(); final Map<String, String> map = new HashMap<String, String>();
String line; String line;
int pos; int pos;
try {
while ((line = br.readLine()) != null) { // very slow readLine???? while ((line = br.readLine()) != null) { // very slow readLine????
line = line.trim(); line = line.trim();
if (line.equals("# EOF")) return map; if (line.equals("# EOF")) return map;
@ -129,6 +130,9 @@ public class MapView {
if (pos < 0) continue; if (pos < 0) continue;
map.put(line.substring(0, pos), line.substring(pos + 1)); map.put(line.substring(0, pos), line.substring(pos + 1));
} }
} catch (OutOfMemoryError e) {
throw new RowSpaceExceededException(0, "readLine probably uses too much RAM", e);
}
return map; return map;
} }
@ -229,7 +233,11 @@ public class MapView {
// read object // read object
final byte[] b = blob.get(keyb); final byte[] b = blob.get(keyb);
if (b == null) return null; if (b == null) return null;
map = bytes2map(b); try {
map = bytes2map(b);
} catch (RowSpaceExceededException e) {
throw new IOException(e.getMessage());
}
// write map to cache // write map to cache
cache.put(key, map); cache.put(key, map);
@ -245,7 +253,11 @@ public class MapView {
b = blob.get(keyb); b = blob.get(keyb);
} }
if (b == null) return null; if (b == null) return null;
return bytes2map(b); try {
return bytes2map(b);
} catch (RowSpaceExceededException e) {
throw new IOException(e.getMessage());
}
} }
} }

@ -45,6 +45,14 @@ public class RowSpaceExceededException extends Exception {
this.forUsage = forUsage; this.forUsage = forUsage;
} }
public RowSpaceExceededException(long neededRAM, String forUsage, Throwable t) {
super(Long.toString(neededRAM) + " bytes needed for " + forUsage + ": " + MemoryControl.available() + " free at " + (new Date()).toString(), t);
this.time = System.currentTimeMillis();
this.availableRAM = MemoryControl.available();
this.neededRAM = neededRAM;
this.forUsage = forUsage;
}
public String getUsage() { public String getUsage() {
return forUsage; return forUsage;
} }

Loading…
Cancel
Save