Do we really need a cache?
Is it a network roundtrip problem or the query on the database?
What might work to reduce the query
metaData.getTables(factory.getCatalog(), databaseName, tableName, new
String[] { "TABLE", "VIEW" } )
A problem I have seen with db drivers is that the name lookup takes very
long for the db host. The oracle driver for example will always try to
find an ip-address even when you use an ip-address as hostname. WHen it
is a lookup problem then you will see a thread stack (In a thread dump,
kill -3) waiting on a lookup call of a socket
Another problem I see with the current code is that multiple schemas in
the same database can have the same table name. A getTables could return
a table from a different schema.
Nico
marcel maatkamp wrote:
Since we have fysically moved our database, our development machines
experience much long startup times for mmbase, around the order of 3min.
I did some investigation and found a nice little speedup which will reduce
starting mmbase with 30 seconds. Not really groundbreaking but it helps!
mmbase/src/org/mmbase/storage/implementation/database/DatabaseStorageManager.java
this is the original code which gets called for each builder:
protected synchronized boolean exists(String tableName)
throws StorageException {
try {
getActiveConnection();
DatabaseMetaData metaData = activeConnection.getMetaData();
ResultSet res = metaData.getTables(null, null, tableName, null);
try {
boolean result = res.next();
return result;
} finally {
res.close();
}
} catch (Exception e) {
throw new StorageException(e.getMessage());
} finally {
releaseActiveConnection();
}
}
I did some digging and found our that the jdbc-spec says that wildcards ('%')
can be used to find out which tables are in the database. Well, you know where
this will lead to, so this is the proposed code:
static Set cache = null;
protected synchronized boolean exists(String tableName)
throws StorageException {
// cache
if(cache == null) {
try {
cache = new HashSet();
getActiveConnection();
DatabaseMetaData metaData = activeConnection.getMetaData();
ResultSet res =
metaData.getTables(null, null, factory.getMMBase().getBaseName()+"_%", null);
try {
while(res.next())
cache.add(res.getString(3));
} finally {
res.close();
}
} catch(Exception e) {
throw new StorageException(e.getMessage());
} finally {
releaseActiveConnection();
}
}
return cache.contains(tableName);
}
I post this because I dont know if the original maintainer didn't use this feature
with a reason.
_______________________________________________
Developers mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/developers
_______________________________________________
Developers mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/developers