Search in sources :

Example 1 with ExpectedProcedureException

use of org.voltdb.ExpectedProcedureException in project voltdb by VoltDB.

the class ProcedureTask method processInitiateTask.

/** Mostly copy-paste of old ExecutionSite.processInitiateTask() */
protected InitiateResponseMessage processInitiateTask(Iv2InitiateTaskMessage task, SiteProcedureConnection siteConnection) {
    final InitiateResponseMessage response = new InitiateResponseMessage(task);
    try {
        Object[] callerParams = null;
        /*
             * Parameters are lazily deserialized. We may not find out until now
             * that the parameter set is corrupt
             */
        try {
            callerParams = task.getParameters();
        } catch (RuntimeException e) {
            Writer result = new StringWriter();
            PrintWriter pw = new PrintWriter(result);
            e.printStackTrace(pw);
            response.setResults(new ClientResponseImpl(ClientResponse.GRACEFUL_FAILURE, new VoltTable[] {}, "Exception while deserializing procedure params, procedure=" + m_procName + "\n" + result.toString()));
        }
        if (callerParams == null) {
            return response;
        }
        ClientResponseImpl cr = null;
        ProcedureRunner runner = siteConnection.getProcedureRunner(m_procName);
        if (runner == null) {
            String error = "Procedure " + m_procName + " is not present in the catalog. " + "This can happen if a catalog update removing the procedure occurred " + "after the procedure was submitted " + "but before the procedure was executed.";
            RateLimitedLogger.tryLogForMessage(System.currentTimeMillis(), 60, TimeUnit.SECONDS, hostLog, Level.WARN, error + " %s", "This log message is rate limited to once every 60 seconds.");
            response.setResults(new ClientResponseImpl(ClientResponse.UNEXPECTED_FAILURE, new VoltTable[] {}, error));
            return response;
        }
        // Check partitioning of single-partition and n-partition transactions.
        if (runner.checkPartition(m_txnState, siteConnection.getCurrentHashinator())) {
            runner.setupTransaction(m_txnState);
            // execute the procedure
            cr = runner.call(callerParams);
            // pass in the first value in the hashes array if it's not null
            Integer hash = null;
            int[] hashes = cr.getHashes();
            if (hashes != null && hashes.length > 0) {
                hash = hashes[0];
            }
            m_txnState.setHash(hash);
            //Don't pay the cost of returning the result tables for a replicated write
            //With reads don't apply the optimization just in case
            //                    if (!task.shouldReturnResultTables() && !task.isReadOnly()) {
            //                        cr.dropResultTable();
            //                    }
            response.setResults(cr);
            //  have the real results
            if ((!task.isReadOnly()) && task.isSinglePartition()) {
                m_txnState.storeResults(cr);
            }
        } else {
            // mis-partitioned invocation, reject it and let the ClientInterface restart it
            response.setMispartitioned(true, task.getStoredProcedureInvocation(), TheHashinator.getCurrentVersionedConfig());
        }
    } catch (final ExpectedProcedureException e) {
        execLog.l7dlog(Level.TRACE, LogKeys.org_voltdb_ExecutionSite_ExpectedProcedureException.name(), e);
        response.setResults(new ClientResponseImpl(ClientResponse.GRACEFUL_FAILURE, new VoltTable[] {}, e.toString()));
    } catch (final Exception e) {
        // Should not be able to reach here. VoltProcedure.call caught all invocation target exceptions
        // and converted them to error responses. Java errors are re-thrown, and not caught by this
        // exception clause. A truly unexpected exception reached this point. Crash. It's a defect.
        hostLog.l7dlog(Level.ERROR, LogKeys.host_ExecutionSite_UnexpectedProcedureException.name(), e);
        VoltDB.crashLocalVoltDB(e.getMessage(), true, e);
    }
    return response;
}
Also used : InitiateResponseMessage(org.voltdb.messaging.InitiateResponseMessage) VoltTable(org.voltdb.VoltTable) ExpectedProcedureException(org.voltdb.ExpectedProcedureException) StringWriter(java.io.StringWriter) ProcedureRunner(org.voltdb.ProcedureRunner) ExpectedProcedureException(org.voltdb.ExpectedProcedureException) ClientResponseImpl(org.voltdb.ClientResponseImpl) PrintWriter(java.io.PrintWriter) StringWriter(java.io.StringWriter) Writer(java.io.Writer) PrintWriter(java.io.PrintWriter)

Aggregations

PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 Writer (java.io.Writer)1 ClientResponseImpl (org.voltdb.ClientResponseImpl)1 ExpectedProcedureException (org.voltdb.ExpectedProcedureException)1 ProcedureRunner (org.voltdb.ProcedureRunner)1 VoltTable (org.voltdb.VoltTable)1 InitiateResponseMessage (org.voltdb.messaging.InitiateResponseMessage)1