Search in sources :

Example 1 with Locus

use of mondrian.server.Locus in project mondrian by pentaho.

the class CacheControlImpl method execute.

public void execute(MemberEditCommand cmd) {
    final BooleanProperty prop = MondrianProperties.instance().EnableRolapCubeMemberCache;
    if (prop.get()) {
        throw new IllegalArgumentException("Member cache control operations are not allowed unless " + "property " + prop.getPath() + " is false");
    }
    synchronized (MEMBER_CACHE_LOCK) {
        // Make sure that a Locus is in the Execution stack,
        // since some operations might require DB access.
        Execution execution;
        try {
            execution = Locus.peek().execution;
        } catch (EmptyStackException e) {
            if (connection == null) {
                throw new IllegalArgumentException("Connection required");
            }
            execution = new Execution(connection.getInternalStatement(), 0);
        }
        final Locus locus = new Locus(execution, "CacheControlImpl.execute", "when modifying the member cache.");
        Locus.push(locus);
        try {
            // Execute the command
            final List<CellRegion> cellRegionList = new ArrayList<CellRegion>();
            ((MemberEditCommandPlus) cmd).execute(cellRegionList);
            // Flush the cells touched by the regions
            for (CellRegion memberRegion : cellRegionList) {
                // Iterate over the cubes, create a cross region with
                // its measures, and flush the data cells.
                // It is possible that some regions don't intersect
                // with a cube. We will intercept the exceptions and
                // skip to the next cube if necessary.
                final List<Dimension> dimensions = memberRegion.getDimensionality();
                if (dimensions.size() > 0) {
                    for (Cube cube : dimensions.get(0).getSchema().getCubes()) {
                        try {
                            final List<CellRegionImpl> crossList = new ArrayList<CellRegionImpl>();
                            crossList.add((CellRegionImpl) createMeasuresRegion(cube));
                            crossList.add((CellRegionImpl) memberRegion);
                            final CellRegion crossRegion = new CrossjoinCellRegion(crossList);
                            flush(crossRegion);
                        } catch (UndeclaredThrowableException e) {
                            if (e.getCause() instanceof InvocationTargetException) {
                                final InvocationTargetException ite = (InvocationTargetException) e.getCause();
                                if (ite.getTargetException() instanceof MondrianException) {
                                    final MondrianException me = (MondrianException) ite.getTargetException();
                                    if (me.getMessage().matches("^Mondrian Error:Member " + "'\\[.*\\]' not found$")) {
                                        continue;
                                    }
                                }
                            }
                            throw new MondrianException(e);
                        } catch (MondrianException e) {
                            if (e.getMessage().matches("^Mondrian Error:Member " + "'\\[.*\\]' not found$")) {
                                continue;
                            }
                            throw e;
                        }
                    }
                }
            }
            // Apply it all.
            ((MemberEditCommandPlus) cmd).commit();
        } finally {
            Locus.pop(locus);
        }
    }
}
Also used : BooleanProperty(org.eigenbase.util.property.BooleanProperty) InvocationTargetException(java.lang.reflect.InvocationTargetException) Execution(mondrian.server.Execution) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) Locus(mondrian.server.Locus)

Example 2 with Locus

use of mondrian.server.Locus in project mondrian by pentaho.

the class RolapResult method getCell.

/**
 * Get the Cell for the given Cell position.
 *
 * @param pos Cell position.
 * @return the Cell associated with the Cell position.
 */
public Cell getCell(int[] pos) {
    if (pos.length != point.size()) {
        throw Util.newError("coordinates should have dimension " + point.size());
    }
    for (int i = 0; i < pos.length; i++) {
        if (positionsHighCardinality.get(i)) {
            final Locus locus = new Locus(execution, null, "Loading cells");
            Locus.push(locus);
            try {
                executeBody(evaluator, statement.getQuery(), pos);
            } finally {
                Locus.pop(locus);
            }
            break;
        }
    }
    CellInfo ci = cellInfos.lookup(pos);
    if (ci.value == null) {
        for (int i = 0; i < pos.length; i++) {
            int po = pos[i];
            if (po < 0 || po >= axes[i].getPositions().size()) {
                throw Util.newError("coordinates out of range");
            }
        }
        ci.value = Util.nullValue;
    }
    return new RolapCell(this, pos.clone(), ci);
}
Also used : Locus(mondrian.server.Locus)

Example 3 with Locus

use of mondrian.server.Locus in project mondrian by pentaho.

the class SegmentCacheManager method loadSucceeded.

/**
 * Adds a segment to segment index.
 *
 * <p>Called when a SQL statement has finished loading a segment.</p>
 *
 * <p>Does not add the segment to the external cache. That is a potentially
 * long-duration operation, better carried out by a worker.</p>
 *
 * @param header segment header
 * @param body segment body
 */
public void loadSucceeded(RolapStar star, SegmentHeader header, SegmentBody body) {
    final Locus locus = Locus.peek();
    ACTOR.event(handler, new SegmentLoadSucceededEvent(System.currentTimeMillis(), locus.getServer().getMonitor(), locus.getServer().getId(), locus.execution.getMondrianStatement().getMondrianConnection().getId(), locus.execution.getMondrianStatement().getId(), locus.execution.getId(), star, header, body));
}
Also used : Locus(mondrian.server.Locus)

Example 4 with Locus

use of mondrian.server.Locus in project mondrian by pentaho.

the class SegmentLoader method createExecuteSql.

/**
 * Creates and executes a SQL statement to retrieve the set of cells
 * specified by a GroupingSetsList.
 *
 * <p>This method may be overridden in tests.
 *
 * @param cellRequestCount Number of missed cells that led to this request
 * @param groupingSetsList Grouping
 * @param compoundPredicateList Compound predicate list
 * @return An executed SQL statement, or null
 */
SqlStatement createExecuteSql(int cellRequestCount, final GroupingSetsList groupingSetsList, List<StarPredicate> compoundPredicateList) {
    RolapStar star = groupingSetsList.getStar();
    Pair<String, List<SqlStatement.Type>> pair = AggregationManager.generateSql(groupingSetsList, compoundPredicateList);
    final Locus locus = new SqlStatement.StatementLocus(Locus.peek().execution, "Segment.load", "Error while loading segment", SqlStatementEvent.Purpose.CELL_SEGMENT, cellRequestCount);
    // When caching is enabled, we must register the SQL statement
    // in the index. We don't want to cancel SQL statements that are shared
    // across threads unless it is safe.
    final Util.Functor1<Void, Statement> callbackWithCaching = new Util.Functor1<Void, Statement>() {

        public Void apply(final Statement stmt) {
            cacheMgr.execute(new SegmentCacheManager.Command<Void>() {

                public Void call() throws Exception {
                    boolean atLeastOneActive = false;
                    for (Segment seg : groupingSetsList.getDefaultSegments()) {
                        final SegmentCacheIndex index = cacheMgr.getIndexRegistry().getIndex(seg.star);
                        // then.
                        if (index.contains(seg.getHeader())) {
                            index.linkSqlStatement(seg.getHeader(), stmt);
                            atLeastOneActive = true;
                        }
                        if (!atLeastOneActive) {
                            // knows to stop.
                            throw new AbortException();
                        }
                    }
                    return null;
                }

                public Locus getLocus() {
                    return locus;
                }
            });
            return null;
        }
    };
    // When using no cache, we register the SQL statement directly
    // with the execution instance for cleanup.
    final Util.Functor1<Void, Statement> callbackNoCaching = new Util.Functor1<Void, Statement>() {

        public Void apply(final Statement stmt) {
            locus.execution.registerStatement(locus, stmt);
            return null;
        }
    };
    try {
        return RolapUtil.executeQuery(star.getDataSource(), pair.left, pair.right, 0, 0, locus, -1, -1, // cache the segments or not.
        MondrianProperties.instance().DisableCaching.get() ? callbackNoCaching : callbackWithCaching);
    } catch (Throwable t) {
        if (Util.getMatchingCause(t, AbortException.class) != null) {
            return null;
        } else {
            throw new MondrianException("Failed to load segment form SQL", t);
        }
    }
}
Also used : Statement(java.sql.Statement) Util(mondrian.olap.Util) AbortException(mondrian.rolap.agg.SegmentCacheManager.AbortException) SQLException(java.sql.SQLException) MondrianException(mondrian.olap.MondrianException) SegmentCacheIndex(mondrian.rolap.cache.SegmentCacheIndex) Locus(mondrian.server.Locus) MondrianException(mondrian.olap.MondrianException) AbortException(mondrian.rolap.agg.SegmentCacheManager.AbortException)

Example 5 with Locus

use of mondrian.server.Locus in project mondrian by pentaho.

the class SqlStatisticsProvider method getQueryCardinality.

public long getQueryCardinality(Dialect dialect, DataSource dataSource, String sql, Execution execution) {
    final StringBuilder buf = new StringBuilder();
    buf.append("select count(*) from (").append(sql).append(")");
    if (dialect.requiresAliasForFromQuery()) {
        if (dialect.allowsAs()) {
            buf.append(" as ");
        } else {
            buf.append(" ");
        }
        dialect.quoteIdentifier(buf, "init");
    }
    final String countSql = buf.toString();
    SqlStatement stmt = RolapUtil.executeQuery(dataSource, countSql, new Locus(execution, "SqlStatisticsProvider.getQueryCardinality", "Reading row count from query [" + sql + "]"));
    try {
        ResultSet resultSet = stmt.getResultSet();
        if (resultSet.next()) {
            ++stmt.rowCount;
            return resultSet.getInt(1);
        }
        // huh?
        return -1;
    } catch (SQLException e) {
        throw stmt.handle(e);
    } finally {
        stmt.close();
    }
}
Also used : SqlStatement(mondrian.rolap.SqlStatement) Locus(mondrian.server.Locus)

Aggregations

Locus (mondrian.server.Locus)14 Execution (mondrian.server.Execution)4 SqlStatement (mondrian.rolap.SqlStatement)3 SegmentCacheIndex (mondrian.rolap.cache.SegmentCacheIndex)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)1 SQLException (java.sql.SQLException)1 Statement (java.sql.Statement)1 Future (java.util.concurrent.Future)1 MondrianException (mondrian.olap.MondrianException)1 MondrianServer (mondrian.olap.MondrianServer)1 Util (mondrian.olap.Util)1 AbortException (mondrian.rolap.agg.SegmentCacheManager.AbortException)1 Statement (mondrian.server.Statement)1 StatementImpl (mondrian.server.StatementImpl)1 Monitor (mondrian.server.monitor.Monitor)1 Dialect (mondrian.spi.Dialect)1 SqlPattern (mondrian.test.SqlPattern)1 BooleanProperty (org.eigenbase.util.property.BooleanProperty)1