Search in sources :

Example 1 with ParameterSet

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

the class HTTPUtils method callProcedure.

public static Response callProcedure(String string, String generateRandomKeyForRetrieval) throws JSONException, IOException, Exception {
    ParameterSet pset = ParameterSet.fromArrayNoCopy(generateRandomKeyForRetrieval);
    System.out.println("Call proc: " + string + ". key: " + generateRandomKeyForRetrieval);
    String resp = callProcOverJSON(string, pset, username, password, prehash);
    System.out.println("Response K resp: " + resp.toString());
    Response response = responseFromJSON(resp);
    System.out.println("Response K: " + response.toString());
    return response;
}
Also used : ParameterSet(org.voltdb.ParameterSet)

Example 2 with ParameterSet

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

the class HTTPUtils method callProcedure.

public static Response callProcedure(String string, String key, byte[] storeValue) throws JSONException, IOException, Exception {
    ParameterSet pset = ParameterSet.fromArrayNoCopy(key, storeValue);
    System.out.println("Call proc: " + string + ". key: " + key + ". len(storeValue): " + storeValue.length);
    String resp = callProcOverJSON(string, pset, username, password, prehash);
    System.out.println("Response KV resp: " + resp.toString());
    Response response = responseFromJSON(resp);
    System.out.println("Response KV: " + response.toString());
    return response;
}
Also used : ParameterSet(org.voltdb.ParameterSet)

Example 3 with ParameterSet

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

the class HTTPBenchmark method runBenchmark.

/**
     * Core benchmark code.
     * Connect. Initialize. Run the loop. Cleanup. Print Results.
     *
     * @throws Exception if anything unexpected happens.
     */
public void runBenchmark() throws Exception {
    System.out.print(HORIZONTAL_RULE);
    System.out.println(" Setup & Initialization");
    System.out.println(HORIZONTAL_RULE);
    System.out.println("\nPopulating Static Tables\n");
    // initialize using JSON over HTTP call
    ParameterSet pset = ParameterSet.fromArrayNoCopy(config.contestants, CONTESTANT_NAMES_CSV);
    String res = callProcOverJSON("Initialize", pset, "myadmin", "voltdbadmin", false);
    System.out.println("JSON response INITIALIZE: " + res);
    System.out.print(HORIZONTAL_RULE);
    System.out.println(" Starting Benchmark");
    System.out.println(HORIZONTAL_RULE);
    // create/start the requested number of threads
    Thread[] voterThreads = new Thread[config.threads];
    for (int i = 0; i < config.threads; ++i) {
        voterThreads[i] = new Thread(new VoterThread());
        voterThreads[i].start();
    }
    // Run the benchmark loop for the requested warmup time
    System.out.println("Warming up...");
    Thread.sleep(1000l * config.warmup);
    // signal to threads to end the warmup phase
    warmupComplete.set(true);
    // print periodic statistics to the console
    benchmarkStartTS = System.currentTimeMillis();
    // Run the benchmark loop for the requested warmup time
    System.out.println("\nRunning benchmark...");
    Thread.sleep(1000l * config.duration);
    // stop the threads
    benchmarkComplete.set(true);
    // join on the threads
    for (Thread t : voterThreads) {
        t.join();
    }
    // print the summary results
    printResults();
}
Also used : ParameterSet(org.voltdb.ParameterSet)

Example 4 with ParameterSet

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

the class TestSpSchedulerDedupe method createMsg.

private Iv2InitiateTaskMessage createMsg(long txnId, boolean readOnly, boolean singlePart, long destHSId) {
    // Mock an invocation for MockSPName.
    StoredProcedureInvocation spi = mock(StoredProcedureInvocation.class);
    when(spi.getProcName()).thenReturn(MockSPName);
    ParameterSet bleh = mock(ParameterSet.class);
    when(spi.getParams()).thenReturn(bleh);
    Iv2InitiateTaskMessage task = new // initHSID
    Iv2InitiateTaskMessage(// initHSID
    destHSId, // coordHSID
    Long.MIN_VALUE, // truncationHandle
    txnId - 1, // txnId
    txnId, // uniqueID
    UniqueIdGenerator.makeIdFromComponents(System.currentTimeMillis(), 0, 0), // readonly
    readOnly, // single-part
    singlePart, // invocation
    spi, // client interface handle
    Long.MAX_VALUE, // connectionId
    Long.MAX_VALUE, // isForReplay
    false);
    // sp: sphandle == txnid
    task.setTxnId(txnId);
    task.setSpHandle(txnId);
    return task;
}
Also used : ParameterSet(org.voltdb.ParameterSet) StoredProcedureInvocation(org.voltdb.StoredProcedureInvocation) Iv2InitiateTaskMessage(org.voltdb.messaging.Iv2InitiateTaskMessage)

Example 5 with ParameterSet

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

the class PlannerTool method planSql.

public synchronized AdHocPlannedStatement planSql(String sqlIn, StatementPartitioning partitioning, boolean isExplainMode, final Object[] userParams, boolean isSwapTables) {
    CacheUse cacheUse = CacheUse.FAIL;
    if (m_plannerStats != null) {
        m_plannerStats.startStatsCollection();
    }
    boolean hasUserQuestionMark = false;
    boolean wrongNumberParameters = false;
    try {
        if ((sqlIn == null) || (sqlIn.length() == 0)) {
            throw new RuntimeException("Can't plan empty or null SQL.");
        }
        // remove any spaces or newlines
        String sql = sqlIn.trim();
        // if the cases tended to have mostly overlapping queries.
        if (partitioning.isInferred()) {
            // Check the literal cache for a match.
            AdHocPlannedStatement cachedPlan = m_cache.getWithSQL(sqlIn);
            if (cachedPlan != null) {
                cacheUse = CacheUse.HIT1;
                return cachedPlan;
            } else {
                cacheUse = CacheUse.MISS;
            }
        }
        // Reset plan node id counter
        AbstractPlanNode.resetPlanNodeIds();
        //////////////////////
        // PLAN THE STMT
        //////////////////////
        TrivialCostModel costModel = new TrivialCostModel();
        DatabaseEstimates estimates = new DatabaseEstimates();
        QueryPlanner planner = new QueryPlanner(sql, "PlannerTool", "PlannerToolProc", m_database, partitioning, m_hsql, estimates, !VoltCompiler.DEBUG_MODE, AD_HOC_JOINED_TABLE_LIMIT, costModel, null, null, DeterminismMode.FASTER);
        CompiledPlan plan = null;
        String[] extractedLiterals = null;
        String parsedToken = null;
        try {
            if (isSwapTables) {
                planner.planSwapTables();
            } else {
                planner.parse();
            }
            parsedToken = planner.parameterize();
            // check the parameters count
            // check user input question marks with input parameters
            int inputParamsLengh = userParams == null ? 0 : userParams.length;
            if (planner.getAdhocUserParamsCount() != inputParamsLengh) {
                wrongNumberParameters = true;
                if (!isExplainMode) {
                    throw new PlanningErrorException(String.format("Incorrect number of parameters passed: expected %d, passed %d", planner.getAdhocUserParamsCount(), inputParamsLengh));
                }
            }
            hasUserQuestionMark = planner.getAdhocUserParamsCount() > 0;
            // do not put wrong parameter explain query into cache
            if (!wrongNumberParameters && partitioning.isInferred()) {
                // QueryPlanner.
                assert (parsedToken != null);
                extractedLiterals = planner.extractedParamLiteralValues();
                List<BoundPlan> boundVariants = m_cache.getWithParsedToken(parsedToken);
                if (boundVariants != null) {
                    assert (!boundVariants.isEmpty());
                    BoundPlan matched = null;
                    for (BoundPlan boundPlan : boundVariants) {
                        if (boundPlan.allowsParams(extractedLiterals)) {
                            matched = boundPlan;
                            break;
                        }
                    }
                    if (matched != null) {
                        CorePlan core = matched.m_core;
                        ParameterSet params = null;
                        if (planner.compiledAsParameterizedPlan()) {
                            params = planner.extractedParamValues(core.parameterTypes);
                        } else if (hasUserQuestionMark) {
                            params = ParameterSet.fromArrayNoCopy(userParams);
                        } else {
                            // No constants AdHoc queries
                            params = ParameterSet.emptyParameterSet();
                        }
                        AdHocPlannedStatement ahps = new AdHocPlannedStatement(sql.getBytes(Constants.UTF8ENCODING), core, params, null);
                        ahps.setBoundConstants(matched.m_constants);
                        // parameterized plan from the cache does not have exception
                        m_cache.put(sql, parsedToken, ahps, extractedLiterals, hasUserQuestionMark, false);
                        cacheUse = CacheUse.HIT2;
                        return ahps;
                    }
                }
            }
            // If not caching or there was no cache hit, do the expensive full planning.
            plan = planner.plan();
            assert (plan != null);
            if (plan != null && plan.getStatementPartitioning() != null) {
                partitioning = plan.getStatementPartitioning();
            }
        } catch (Exception e) {
            /*
                 * Don't log PlanningErrorExceptions or HSQLParseExceptions, as
                 * they are at least somewhat expected.
                 */
            String loggedMsg = "";
            if (!((e instanceof PlanningErrorException) || (e instanceof HSQLParseException))) {
                logException(e, "Error compiling query");
                loggedMsg = " (Stack trace has been written to the log.)";
            }
            throw new RuntimeException("Error compiling query: " + e.toString() + loggedMsg, e);
        }
        if (plan == null) {
            throw new RuntimeException("Null plan received in PlannerTool.planSql");
        }
        //////////////////////
        // OUTPUT THE RESULT
        //////////////////////
        CorePlan core = new CorePlan(plan, m_catalogHash);
        AdHocPlannedStatement ahps = new AdHocPlannedStatement(plan, core);
        // do not put wrong parameter explain query into cache
        if (!wrongNumberParameters && partitioning.isInferred()) {
            // Note either the parameter index (per force to a user-provided parameter) or
            // the actual constant value of the partitioning key inferred from the plan.
            // Either or both of these two values may simply default
            // to -1 and to null, respectively.
            core.setPartitioningParamIndex(partitioning.getInferredParameterIndex());
            core.setPartitioningParamValue(partitioning.getInferredPartitioningValue());
            assert (parsedToken != null);
            // Again, plans with inferred partitioning are the only ones supported in the cache.
            m_cache.put(sqlIn, parsedToken, ahps, extractedLiterals, hasUserQuestionMark, planner.wasBadPameterized());
        }
        return ahps;
    } finally {
        if (m_plannerStats != null) {
            m_plannerStats.endStatsCollection(m_cache.getLiteralCacheSize(), m_cache.getCoreCacheSize(), cacheUse, -1);
        }
    }
}
Also used : CompiledPlan(org.voltdb.planner.CompiledPlan) ParameterSet(org.voltdb.ParameterSet) PlanningErrorException(org.voltdb.planner.PlanningErrorException) CacheUse(org.voltdb.PlannerStatsCollector.CacheUse) CorePlan(org.voltdb.planner.CorePlan) QueryPlanner(org.voltdb.planner.QueryPlanner) PlanningErrorException(org.voltdb.planner.PlanningErrorException) HSQLParseException(org.hsqldb_voltpatches.HSQLInterface.HSQLParseException) HSQLParseException(org.hsqldb_voltpatches.HSQLInterface.HSQLParseException) TrivialCostModel(org.voltdb.planner.TrivialCostModel) BoundPlan(org.voltdb.planner.BoundPlan)

Aggregations

ParameterSet (org.voltdb.ParameterSet)28 IOException (java.io.IOException)9 ByteBuffer (java.nio.ByteBuffer)9 EEException (org.voltdb.exceptions.EEException)5 PlanFragment (org.voltdb.catalog.PlanFragment)3 Statement (org.voltdb.catalog.Statement)3 SerializableException (org.voltdb.exceptions.SerializableException)3 FastDeserializer (org.voltdb.messaging.FastDeserializer)3 Iv2InitiateTaskMessage (org.voltdb.messaging.Iv2InitiateTaskMessage)3 EOFException (java.io.EOFException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)2 DependencyPair (org.voltdb.DependencyPair)2 StoredProcedureInvocation (org.voltdb.StoredProcedureInvocation)2 VoltTable (org.voltdb.VoltTable)2 SQLException (org.voltdb.exceptions.SQLException)2 FragmentResponseMessage (org.voltdb.messaging.FragmentResponseMessage)2 CorePlan (org.voltdb.planner.CorePlan)2 ArrayList (java.util.ArrayList)1 Random (java.util.Random)1