Search in sources :

Example 1 with ClientResponseImpl

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

the class TestLiveTableSchemaMigration method migrateSchema.

/**
     * Assuming given tables have schema metadata, fill them with random data
     * and compare a pure-java schema migration with an EE schema migration.
     */
void migrateSchema(VoltTable t1, VoltTable t2, boolean withData) throws Exception {
    ServerThread server = null;
    Client client = null;
    TableHelper helper = new TableHelper();
    try {
        if (withData) {
            helper.randomFill(t1, 1000, 1024);
        }
        String catPath1 = catalogPathForTable(t1, "t1.jar");
        String catPath2 = catalogPathForTable(t2, "t2.jar");
        byte[] catBytes2 = MiscUtils.fileToBytes(new File(catPath2));
        DeploymentBuilder depBuilder = new DeploymentBuilder(1, 1, 0);
        depBuilder.setVoltRoot("/tmp/rootbar");
        // disable logging
        depBuilder.configureLogging("/tmp/foobar", "/tmp/goobar", false, false, 1, 1, 3);
        String deployment = depBuilder.getXML();
        File deploymentFile = VoltProjectBuilder.writeStringToTempFile(deployment);
        VoltDB.Configuration config = new VoltDB.Configuration();
        config.m_pathToDeployment = deploymentFile.getAbsolutePath();
        config.m_pathToCatalog = catPath1;
        config.m_ipcPort = 10000;
        //config.m_backend = BackendTarget.NATIVE_EE_IPC;
        server = new ServerThread(config);
        server.start();
        server.waitForInitialization();
        System.out.printf("PRE:  %s\n", TableHelper.ddlForTable(t1, false));
        System.out.printf("POST: %s\n", TableHelper.ddlForTable(t2, false));
        ClientConfig clientConfig = new ClientConfig();
        client = ClientFactory.createClient(clientConfig);
        client.createConnection("localhost");
        TableHelper.loadTable(client, t1);
        ClientResponseImpl response = (ClientResponseImpl) client.callProcedure("@UpdateApplicationCatalog", catBytes2, null);
        System.out.println(response.toJSONString());
        VoltTable t3 = client.callProcedure("@AdHoc", "select * from FOO").getResults()[0];
        t3 = TableHelper.sortTable(t3);
        // compute the migrated table entirely in Java for comparison purposes
        TableHelper.migrateTable(t1, t2);
        t2 = TableHelper.sortTable(t2);
        // compare the tables
        StringBuilder sb = new StringBuilder();
        if (!TableHelper.deepEqualsWithErrorMsg(t2, t3, sb)) {
            System.out.println("Table Mismatch");
            //System.out.printf("PRE:  %s\n", t2.toFormattedString());
            //System.out.printf("POST: %s\n", t3.toFormattedString());
            System.out.println(sb.toString());
            fail();
        }
    } finally {
        if (client != null) {
            client.close();
        }
        if (server != null) {
            server.shutdown();
        }
    }
}
Also used : Configuration(org.voltdb.VoltDB.Configuration) VoltTable(org.voltdb.VoltTable) VoltDB(org.voltdb.VoltDB) ServerThread(org.voltdb.ServerThread) TableHelper(org.voltdb.TableHelper) Configuration(org.voltdb.VoltDB.Configuration) ClientResponseImpl(org.voltdb.ClientResponseImpl) Client(org.voltdb.client.Client) ClientConfig(org.voltdb.client.ClientConfig) File(java.io.File) DeploymentBuilder(org.voltdb.compiler.DeploymentBuilder)

Example 2 with ClientResponseImpl

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

the class VoltBulkLoader method generateError.

void generateError(Object rowHandle, Object[] objectList, String errMessage) {
    VoltTable[] dummyTable = new VoltTable[1];
    dummyTable[0] = new VoltTable(m_colInfo);
    ClientResponse dummyResponse = new ClientResponseImpl(ClientResponse.GRACEFUL_FAILURE, dummyTable, errMessage);
    m_notificationCallBack.failureCallback(rowHandle, objectList, dummyResponse);
    m_loaderCompletedCnt.incrementAndGet();
}
Also used : ClientResponse(org.voltdb.client.ClientResponse) ClientResponseImpl(org.voltdb.ClientResponseImpl) VoltTable(org.voltdb.VoltTable)

Example 3 with ClientResponseImpl

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

the class PerPartitionTable method loadTable.

private void loadTable(ProcedureCallback callback, VoltTable toSend) throws Exception {
    if (toSend.getRowCount() <= 0) {
        return;
    }
    try {
        if (m_isMP) {
            m_clientImpl.callProcedure(callback, m_procName, m_tableName, m_upsert, toSend);
        } else {
            Object rpartitionParam = VoltType.valueToBytes(toSend.fetchRow(0).get(m_partitionedColumnIndex, m_partitionColumnType));
            m_clientImpl.callProcedure(callback, m_procName, rpartitionParam, m_tableName, m_upsert, toSend);
        }
    } catch (IOException e) {
        final ClientResponse r = new ClientResponseImpl(ClientResponse.CONNECTION_LOST, new VoltTable[0], "Connection to database was lost");
        callback.clientCallback(r);
    }
    toSend.clearRowData();
}
Also used : ClientResponse(org.voltdb.client.ClientResponse) IOException(java.io.IOException) ClientResponseImpl(org.voltdb.ClientResponseImpl) VoltTable(org.voltdb.VoltTable)

Example 4 with ClientResponseImpl

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

the class MpProcedureTask method run.

/** Run is invoked by a run-loop to execute this transaction. */
@Override
public void run(SiteProcedureConnection siteConnection) {
    // Thread name has to be materialized here
    final String threadName = Thread.currentThread().getName();
    final VoltTrace.TraceEventBatch traceLog = VoltTrace.log(VoltTrace.Category.MPSITE);
    if (traceLog != null) {
        traceLog.add(() -> VoltTrace.meta("thread_name", "name", threadName)).add(() -> VoltTrace.meta("thread_sort_index", "sort_index", Integer.toString(1000))).add(() -> VoltTrace.beginDuration("mpinittask", "txnId", TxnEgo.txnIdToString(getTxnId())));
    }
    hostLog.debug("STARTING: " + this);
    // Cast up. Could avoid ugliness with Iv2TransactionClass baseclass
    MpTransactionState txn = (MpTransactionState) m_txnState;
    // Check for restarting sysprocs
    String spName = txn.m_initiationMsg.getStoredProcedureName();
    // restarted, the run() method is not rerun. Let the elastic join coordinator reissue it.
    if (m_isRestart && spName.startsWith("@") && !spName.startsWith("@AdHoc") && !spName.startsWith("@LoadMultipartitionTable") && !spName.equals("@UpdateCore") && !spName.equals("@ApplyBinaryLogMP")) {
        InitiateResponseMessage errorResp = new InitiateResponseMessage(txn.m_initiationMsg);
        errorResp.setResults(new ClientResponseImpl(ClientResponse.UNEXPECTED_FAILURE, new VoltTable[] {}, "Failure while running system procedure " + txn.m_initiationMsg.getStoredProcedureName() + ", and system procedures can not be restarted."));
        txn.setNeedsRollback(true);
        completeInitiateTask(siteConnection);
        errorResp.m_sourceHSId = m_initiator.getHSId();
        m_initiator.deliver(errorResp);
        hostLog.debug("SYSPROCFAIL: " + this);
        return;
    }
    // at the masters we're going to try to use this time around.
    if (m_isRestart) {
        CompleteTransactionMessage restart = new CompleteTransactionMessage(// who is the "initiator" now??
        m_initiator.getHSId(), m_initiator.getHSId(), m_txnState.txnId, m_txnState.isReadOnly(), 0, true, // really don't want to have ack the ack.
        false, !m_txnState.isReadOnly(), m_msg.isForReplay());
        restart.setTruncationHandle(m_msg.getTruncationHandle());
        m_initiator.send(com.google_voltpatches.common.primitives.Longs.toArray(m_initiatorHSIds), restart);
    }
    final InitiateResponseMessage response = processInitiateTask(txn.m_initiationMsg, siteConnection);
    // We currently don't want to restart read-only MP transactions because:
    // 1) We're not writing the Iv2InitiateTaskMessage to the first
    // FragmentTaskMessage in read-only case in the name of some unmeasured
    // performance impact,
    // 2) We don't want to perturb command logging and/or DR this close to the 3.0 release
    // 3) We don't guarantee the restarted results returned to the client
    // anyway, so not restarting the read is currently harmless.
    // We could actually restart this here, since we have the invocation, but let's be consistent?
    int status = response.getClientResponseData().getStatus();
    if (status != ClientResponse.TXN_RESTART || (status == ClientResponse.TXN_RESTART && m_msg.isReadOnly())) {
        if (!response.shouldCommit()) {
            txn.setNeedsRollback(true);
        }
        completeInitiateTask(siteConnection);
        // Set the source HSId (ugh) to ourselves so we track the message path correctly
        response.m_sourceHSId = m_initiator.getHSId();
        m_initiator.deliver(response);
        execLog.l7dlog(Level.TRACE, LogKeys.org_voltdb_ExecutionSite_SendingCompletedWUToDtxn.name(), null);
        hostLog.debug("COMPLETE: " + this);
    } else {
        restartTransaction();
        hostLog.debug("RESTART: " + this);
    }
    if (traceLog != null) {
        traceLog.add(VoltTrace::endDuration);
    }
}
Also used : VoltTrace(org.voltdb.utils.VoltTrace) CompleteTransactionMessage(org.voltdb.messaging.CompleteTransactionMessage) InitiateResponseMessage(org.voltdb.messaging.InitiateResponseMessage) ClientResponseImpl(org.voltdb.ClientResponseImpl) VoltTable(org.voltdb.VoltTable)

Example 5 with ClientResponseImpl

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

the class AdHocNTBase method processExplainDefaultProc.

/**
     * Explain Proc for a default proc is routed through the regular Explain
     * path using ad hoc planning and all. Take the result from that async
     * process and format it like other explains for procedures.
     */
static CompletableFuture<ClientResponse> processExplainDefaultProc(AdHocPlannedStmtBatch planBatch) {
    Database db = VoltDB.instance().getCatalogContext().database;
    // from a default procedure
    assert (planBatch.getPlannedStatementCount() == 1);
    AdHocPlannedStatement ahps = planBatch.getPlannedStatement(0);
    String sql = new String(ahps.sql, StandardCharsets.UTF_8);
    String explain = planBatch.explainStatement(0, db);
    VoltTable vt = new VoltTable(new VoltTable.ColumnInfo("SQL_STATEMENT", VoltType.STRING), new VoltTable.ColumnInfo("EXECUTION_PLAN", VoltType.STRING));
    vt.addRow(sql, explain);
    ClientResponseImpl response = new ClientResponseImpl(ClientResponseImpl.SUCCESS, ClientResponse.UNINITIALIZED_APP_STATUS_CODE, null, new VoltTable[] { vt }, null);
    CompletableFuture<ClientResponse> fut = new CompletableFuture<>();
    fut.complete(response);
    return fut;
}
Also used : ClientResponse(org.voltdb.client.ClientResponse) CompletableFuture(java.util.concurrent.CompletableFuture) AdHocPlannedStatement(org.voltdb.compiler.AdHocPlannedStatement) Database(org.voltdb.catalog.Database) ClientResponseImpl(org.voltdb.ClientResponseImpl) VoltTable(org.voltdb.VoltTable)

Aggregations

ClientResponseImpl (org.voltdb.ClientResponseImpl)32 VoltTable (org.voltdb.VoltTable)20 IOException (java.io.IOException)10 ClientResponse (org.voltdb.client.ClientResponse)10 InitiateResponseMessage (org.voltdb.messaging.InitiateResponseMessage)7 CompletableFuture (java.util.concurrent.CompletableFuture)5 StoredProcedureInvocation (org.voltdb.StoredProcedureInvocation)4 ProcCallException (org.voltdb.client.ProcCallException)4 Client (org.voltdb.client.Client)3 NoConnectionsException (org.voltdb.client.NoConnectionsException)3 Iv2InitiateTaskMessage (org.voltdb.messaging.Iv2InitiateTaskMessage)3 File (java.io.File)2 ArrayList (java.util.ArrayList)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 CatalogContext (org.voltdb.CatalogContext)2 ServerThread (org.voltdb.ServerThread)2 TableHelper (org.voltdb.TableHelper)2 VoltDB (org.voltdb.VoltDB)2 Configuration (org.voltdb.VoltDB.Configuration)2 Database (org.voltdb.catalog.Database)2