From 5cd07d7f846f7e13e474122f58cebe43a7cfe8d9 Mon Sep 17 00:00:00 2001 From: sixcooler Date: Tue, 2 Aug 2011 15:52:33 +0000 Subject: [PATCH] early freeing resources on deleting index reference if search-verification fails (aka Switchboard.cleanupJob) doing same thingy on other methods of touched files as well git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@7860 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- source/de/anomic/data/WorkTables.java | 18 +++++++++------- .../net/yacy/kelondro/blob/BEncodedHeap.java | 12 ++++++----- source/net/yacy/kelondro/blob/Tables.java | 11 +++++----- source/net/yacy/kelondro/util/BDecoder.java | 21 +++++++++++-------- 4 files changed, 36 insertions(+), 26 deletions(-) diff --git a/source/de/anomic/data/WorkTables.java b/source/de/anomic/data/WorkTables.java index 5d2296ff6..c9130bd64 100644 --- a/source/de/anomic/data/WorkTables.java +++ b/source/de/anomic/data/WorkTables.java @@ -216,9 +216,11 @@ public class WorkTables extends Tables { final HTTPClient client = new HTTPClient(); client.setRealm(realm); client.setTimout(120000); + Tables.Row row; + String url; LinkedHashMap l = new LinkedHashMap(); - for (String pk: pks) { - Tables.Row row = null; + for (final String pk: pks) { + row = null; try { row = select(WorkTables.TABLE_API_NAME, UTF8.getBytes(pk)); } catch (IOException e) { @@ -227,7 +229,7 @@ public class WorkTables extends Tables { Log.logException(e); } if (row == null) continue; - String url = "http://" + host + ":" + port + UTF8.String(row.get(WorkTables.TABLE_API_COL_URL)); + url = "http://" + host + ":" + port + UTF8.String(row.get(WorkTables.TABLE_API_COL_URL)); url += "&" + WorkTables.TABLE_API_COL_APICALL_PK + "=" + UTF8.String(row.getPK()); Log.logInfo("WorkTables", "executing url: " + url); try { @@ -299,7 +301,7 @@ public class WorkTables extends Tables { public void failURLsRegisterMissingWord(IndexCell indexCell, final DigestURI url, HandleSet queryHashes, final String reason) { // remove words from index - for (byte[] word: queryHashes) { + for (final byte[] word: queryHashes) { indexCell.removeDelayed(word, url.hash()); } @@ -333,10 +335,12 @@ public class WorkTables extends Tables { public void cleanFailURLS(long timeout) { if (timeout >= 0) { try { - Iterator iter = this.iterator(WorkTables.TABLE_SEARCH_FAILURE_NAME); + Row row; + Date date; + Iterator iter = this.iterator(WorkTables.TABLE_SEARCH_FAILURE_NAME); while (iter.hasNext()) { - Row row = iter.next(); - Date date = new Date(); + row = iter.next(); + date = new Date(); date = row.get(TABLE_SEARCH_FAILURE_COL_DATE, date); if(date.before(new Date(System.currentTimeMillis() - timeout))) { this.delete(TABLE_SEARCH_FAILURE_NAME, row.getPK()); diff --git a/source/net/yacy/kelondro/blob/BEncodedHeap.java b/source/net/yacy/kelondro/blob/BEncodedHeap.java index c8324425e..af28b4b08 100644 --- a/source/net/yacy/kelondro/blob/BEncodedHeap.java +++ b/source/net/yacy/kelondro/blob/BEncodedHeap.java @@ -145,7 +145,7 @@ public class BEncodedHeap implements Map>, Iterable< if (bobj.getType() != BDecoder.BType.dictionary) return null; Map map = bobj.getMap(); Map m = new HashMap(); - for (Map.Entry entry: map.entrySet()) { + for (final Map.Entry entry: map.entrySet()) { if (entry.getValue().getType() != BDecoder.BType.string) continue; m.put(entry.getKey(), entry.getValue().getString()); } @@ -404,7 +404,7 @@ public class BEncodedHeap implements Map>, Iterable< * @param m mappings to be stored in this map */ public void putAll(Map> map) { - for (Map.Entry> me: map.entrySet()) { + for (final Map.Entry> me: map.entrySet()) { try { this.insert(me.getKey(), me.getValue()); } catch (RowSpaceExceededException e) { @@ -548,7 +548,7 @@ public class BEncodedHeap implements Map>, Iterable< */ public ArrayList columns() { if (this.columnames.size() == 0) { - for (Map.Entry> row: this) { + for (final Map.Entry> row: this) { this.columnames.addAll(row.getValue().keySet()); } } @@ -572,9 +572,10 @@ public class BEncodedHeap implements Map>, Iterable< m.put("k", "111".getBytes()); map.insert("456".getBytes(), m); m.put("k", "222".getBytes()); map.insert("789".getBytes(), m); // iterate over keys + Map.Entry> entry; Iterator>> i = map.iterator(); while (i.hasNext()) { - Map.Entry> entry = i.next(); + entry = i.next(); System.out.println(ASCII.String(entry.getKey()) + ": " + entry.getValue()); } // clean up @@ -587,10 +588,11 @@ public class BEncodedHeap implements Map>, Iterable< } else { File f = new File(args[0]); try { + Map.Entry> entry; BEncodedHeap map = new BEncodedHeap(f, 12); Iterator>> i = map.iterator(); while (i.hasNext()) { - Map.Entry> entry = i.next(); + entry = i.next(); System.out.println(ASCII.String(entry.getKey()) + ": " + entry.getValue()); } map.close(); diff --git a/source/net/yacy/kelondro/blob/Tables.java b/source/net/yacy/kelondro/blob/Tables.java index 853d71036..ab8e68b5b 100644 --- a/source/net/yacy/kelondro/blob/Tables.java +++ b/source/net/yacy/kelondro/blob/Tables.java @@ -72,7 +72,7 @@ public class Tables { String[] files = this.location.list(); String tablename; File file; - for (String f: files) { + for (final String f: files) { if (f.endsWith(suffix)) { file = new File(this.location, f); if (file.length() == 0) { @@ -99,7 +99,7 @@ public class Tables { } public void close() { - for (BEncodedHeap heap: this.tables.values()) heap.close(); + for (final BEncodedHeap heap: this.tables.values()) heap.close(); this.tables.clear(); } @@ -362,14 +362,15 @@ public class Tables { } protected Row next0() { + Row r; while (i.hasNext()) { - Row r = new Row(i.next()); + r = new Row(i.next()); if (this.whereValue != null) { if (ByteBuffer.equals(r.get(this.whereColumn), this.whereValue)) return r; } else if (this.wherePattern != null) { if (this.whereColumn == null) { // shall match any column - for (byte[] b: r.values()) { + for (final byte[] b: r.values()) { if (this.wherePattern.matcher(UTF8.String(b)).matches()) return r; } } else { @@ -461,7 +462,7 @@ public class Tables { public String toString() { StringBuilder sb = new StringBuilder(this.size() * 40); sb.append('{'); - for (Map.Entry entry: this.entrySet()) { + for (final Map.Entry entry: this.entrySet()) { sb.append(entry.getKey()).append('=').append(UTF8.String(entry.getValue())).append(", "); } if (sb.length() > 1) sb.setLength(sb.length() - 2); diff --git a/source/net/yacy/kelondro/util/BDecoder.java b/source/net/yacy/kelondro/util/BDecoder.java index eb34422df..dbeb8e2d8 100644 --- a/source/net/yacy/kelondro/util/BDecoder.java +++ b/source/net/yacy/kelondro/util/BDecoder.java @@ -149,14 +149,14 @@ public class BDecoder { public String toString() { StringBuilder s = new StringBuilder(l.size() * 40 + 1); s.append("["); - for (BObject o: l) s.append(o.toString()).append(","); + for (final BObject o: l) s.append(o.toString()).append(","); s.setLength(s.length() - 1); s.append("]"); return s.toString(); } public void toStream(OutputStream os) throws IOException { os.write(_l); - for (BObject bo: this.l) bo.toStream(os); + for (final BObject bo: this.l) bo.toStream(os); os.write(_e); } } @@ -178,14 +178,14 @@ public class BDecoder { public String toString() { StringBuilder s = new StringBuilder(m.size() * 40 + 1); s.append('{'); - for (Map.Entry e: m.entrySet()) s.append(e.getKey()).append(':').append(e.getValue().toString()).append(','); + for (final Map.Entry e: m.entrySet()) s.append(e.getKey()).append(':').append(e.getValue().toString()).append(','); s.setLength(s.length() - 1); s.append('}'); return s.toString(); } public void toStream(OutputStream os) throws IOException { os.write(_d); - for (Map.Entry e: this.m.entrySet()) { + for (final Map.Entry e: this.m.entrySet()) { BStringObject.toStream(os, e.getKey()); e.getValue().toStream(os); } @@ -226,9 +226,11 @@ public class BDecoder { private Map convertToMap(final List list) { final Map m = new LinkedHashMap(); final int length = list.size(); + byte[] key; + BObject value; for (int i = 0; i < length; i += 2) { - final byte[] key = list.get(i).getString(); - BObject value = null; + key = list.get(i).getString(); + value = null; if (i + 1 < length) { value = list.get(i + 1); } @@ -240,8 +242,9 @@ public class BDecoder { private List readList() { final List list = new ArrayList(); char ch = (char) b[pos]; + BObject bo; while (ch != 'e') { - BObject bo = parse(); + bo = parse(); if (bo == null) {pos++; break;} list.add(bo); ch = (char) b[pos]; @@ -287,13 +290,13 @@ public class BDecoder { if (bo.getType() == BType.list) { System.out.println("["); //for (int i = 0; i < t + 1; i++) System.out.print(" "); - for (BObject o: bo.getList()) print(o, t + 1); + for (final BObject o: bo.getList()) print(o, t + 1); for (int i = 0; i < t; i++) System.out.print(" "); System.out.println("]"); } if (bo.getType() == BType.dictionary) { System.out.println("{"); - for (Map.Entry e: bo.getMap().entrySet()) { + for (final Map.Entry e: bo.getMap().entrySet()) { for (int i = 0; i < t + 1; i++) System.out.print(" "); System.out.print(e.getKey()); System.out.println(":");