From ba10caf89a7d27361483f9e7e26f0a59ef168709 Mon Sep 17 00:00:00 2001 From: Michael Peter Christen Date: Fri, 8 Jun 2012 09:30:51 +0200 Subject: [PATCH] lazy initialization of database tables --- source/net/yacy/kelondro/blob/Tables.java | 24 ++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/source/net/yacy/kelondro/blob/Tables.java b/source/net/yacy/kelondro/blob/Tables.java index aa459bbe3..73b263845 100644 --- a/source/net/yacy/kelondro/blob/Tables.java +++ b/source/net/yacy/kelondro/blob/Tables.java @@ -70,8 +70,8 @@ public class Tables implements Iterable { this.keymaxlen = keymaxlen; this.tables = new ConcurrentHashMap(); final String[] files = this.location.list(); - String tablename; File file; + // lazy initialization: do not open the database files here for (final String f: files) { if (f.endsWith(suffix)) { file = new File(this.location, f); @@ -79,6 +79,22 @@ public class Tables implements Iterable { file.delete(); continue; } + } + } + } + + @Override + public Iterator iterator() { + // we did a lazy initialization, but here we must discover all actually existing tables + String tablename; + File file; + final String[] files = this.location.list(); + for (final String f: files) { + if (f.endsWith(suffix)) { + file = new File(this.location, f); + if (file.length() == 0) { + continue; + } tablename = f.substring(0, f.length() - suffix.length()); try { getHeap(tablename); @@ -86,10 +102,7 @@ public class Tables implements Iterable { } } } - } - - @Override - public Iterator iterator() { + // now the list of tables is enriched, return an iterator return this.tables.keySet().iterator(); } @@ -376,6 +389,7 @@ public class Tables implements Iterable { this.i = heap.iterator(); } + @Override protected Row next0() { Row r; while (this.i.hasNext()) {