PDA

View Full Version : Re : [Mondrian] Re:VirtualCubeTest.testCalculatedMemberAcrossCubesfailing on SMP



michael bienstein
01-23-2007, 09:00 AM
Just two thoughts on this:
1) Currently I think that a HashMap is used for the global cache. HashMap is not safely synchronized. There is a synchronize block that is too large probably - the whole aggregations data.
2) Two-tier using threadlocal sounds good. Can we do this idea:
interface QueryContext {
Connection getConnection(DataSource ds);
some sort of common filter for aggregation cache and hierarchy caches
void dispose();
}

class QueryContextImpl {
private HashMap<DataSource, Connection> openConnections = new HashMap<DataSource,Connection>();
public Connection getConnection(DataSource ds) {
Connection c = openConnections.get(ds);
if (c != null) {
return c;
}
try {
c = ds.getConnection();
openConnections.put(ds, c);
return c;
} catch (SQLException ex) {
throw new MondrianExceptionOrSomething(ex);
}
}
//TODO some filtering to the global aggregation and hierarchy caches
public void dispose() {
for (Connection c : openConnections.valueSet()) {
try {
c.close();
} catch (SQLException ex) {
log it ...
}
}
}
}

RolapResult.java:
{
private static ThreadLocal<QueryContext> qContext = new ThreadLocal<QueryContext>();
public static QueryContext getQueryContext() {
return qContext.get();
}
public RolapResult(....) {
...
if (!execute) {
return;
}
//Going to execute
QueryContext qc = createQueryContext();
qContext.set(qc);
try {
//Do execute stuff here
} finally {
qContext.clear();
qc.dispose();
}
...
}
//Use a property to override the class used? That way we can configure each Connection specifically?
public QueryContext createQueryContext() {
return new QueryContextImpl();
}
}
//All places in the code base that use DataSource to obtain a Connection in the context of a query should use:
Connection c = RolapResult.getQueryContext().getConnection(ds);

That way we only open one connection per query and we use the database's transaction system.

I found this hard to do because of the RolapConnection/RolapCube constructors calling each other somehow (can't remember the details).

Michael
----- Message d'origine ----
De : Julian Hyde <julianhyde (AT) speakeasy (DOT) net>