Search in sources :

Example 46 with NoConnectionsException

use of org.voltdb.client.NoConnectionsException in project voltdb by VoltDB.

the class ClientDelete method main.

public static void main(String[] args) {
    long numDeletes = (long) Long.valueOf(args[0]);
    String serverList = args[1];
    m_logger.info(String.format("Executing %,d deletes per transaction", numDeletes));
    int num_partitions = 0;
    int intCounter;
    long longCounter;
    final org.voltdb.client.Client voltclient = ClientFactory.createClient();
    String[] voltServers = serverList.split(",");
    for (String thisServer : voltServers) {
        try {
            thisServer = thisServer.trim();
            m_logger.info(String.format("Connecting to server: %s", thisServer));
            voltclient.createConnection(thisServer, "program", "none");
        } catch (IOException e) {
            m_logger.error(e.toString());
            System.exit(-1);
        }
    }
    long startTime = System.currentTimeMillis();
    // get the # of partitions in my cluster
    try {
        VoltTable[] vtPartitionInfo = voltclient.callProcedure("@Statistics", "partitioncount", 0l).getResults();
        num_partitions = (int) vtPartitionInfo[0].fetchRow(0).getLong(0);
        m_logger.info("System is running with " + num_partitions + " partition(s).");
    } catch (ProcCallException e) {
        m_logger.error("ProcCallException:");
        m_logger.error(e.toString());
    } catch (IOException e) {
        m_logger.error("IOException:");
        m_logger.error(e.toString());
    }
    boolean foundRows = true;
    while (foundRows) {
        // do a single delete at each partition
        foundRows = false;
        for (longCounter = 0; longCounter < num_partitions; longCounter++) {
            try {
                long callTimeBegin = System.currentTimeMillis();
                VoltTable[] vtDeleteVisits = voltclient.callProcedure("DeleteVisits", longCounter, numDeletes, callTimeBegin).getResults();
                int rowCount = (int) vtDeleteVisits[0].fetchRow(0).getLong(0);
                long callTimeEnd = System.currentTimeMillis();
                String currentDate = new Date().toString();
                m_logger.info(String.format("[%s] Ran delete on partition %d : deleted %,d row(s) in %,d milliseconds", currentDate, longCounter, rowCount, (callTimeEnd - callTimeBegin)));
                if (rowCount > 0) {
                    foundRows = true;
                }
            } catch (ProcCallException e) {
                m_logger.error("ProcCallException:");
                m_logger.error(e.toString());
            } catch (IOException e) {
                m_logger.error("IOException:");
                m_logger.error(e.toString());
                System.exit(-1);
            }
        }
    }
    String currentDate2 = new Date().toString();
    m_logger.info(String.format("[%s] Finished deletion job, shutting down.", currentDate2));
    try {
        voltclient.drain();
    } catch (InterruptedException e) {
        m_logger.error(e.toString());
        System.exit(-1);
    } catch (NoConnectionsException e) {
        m_logger.error(e.toString());
        System.exit(-1);
    }
    try {
        voltclient.close();
    } catch (Exception e) {
        m_logger.error(e.toString());
        System.exit(-1);
    }
}
Also used : IOException(java.io.IOException) VoltTable(org.voltdb.VoltTable) Date(java.util.Date) ProcCallException(org.voltdb.client.ProcCallException) NoConnectionsException(org.voltdb.client.NoConnectionsException) IOException(java.io.IOException) NoConnectionsException(org.voltdb.client.NoConnectionsException) ProcCallException(org.voltdb.client.ProcCallException)

Example 47 with NoConnectionsException

use of org.voltdb.client.NoConnectionsException in project voltdb by VoltDB.

the class ClientMover method main.

public static void main(String[] args) {
    long numMoves = (long) Long.valueOf(args[0]);
    String serverList = args[1];
    long clientDurationSeconds = (long) Long.valueOf(args[2]);
    long loopPauseSeconds = (long) Long.valueOf(args[3]);
    m_logger.info(String.format("Executing %,d moves per transaction", numMoves));
    m_logger.info(String.format("Running for %,d second(s)", clientDurationSeconds));
    int num_partitions = 0;
    long playerId;
    long gameId;
    long socialId;
    long clientId;
    long visitTime;
    int intCounter;
    long longCounter;
    final org.voltdb.client.Client voltclient = ClientFactory.createClient();
    String[] voltServers = serverList.split(",");
    for (String thisServer : voltServers) {
        try {
            thisServer = thisServer.trim();
            m_logger.info(String.format("Connecting to server: %s", thisServer));
            voltclient.createConnection(thisServer, "program", "none");
        } catch (IOException e) {
            m_logger.error(e.toString());
            System.exit(-1);
        }
    }
    java.util.Random rand = new java.util.Random(0);
    long startTime = System.currentTimeMillis();
    long endTime = startTime + (1000l * clientDurationSeconds);
    long currentTime = startTime;
    // get the # of partitions in my cluster
    try {
        VoltTable[] vtPartitionInfo = voltclient.callProcedure("@Statistics", "partitioncount", 0l).getResults();
        num_partitions = (int) vtPartitionInfo[0].fetchRow(0).getLong(0);
        m_logger.info("System is running with " + num_partitions + " partition(s).");
    } catch (ProcCallException e) {
        m_logger.error("ProcCallException:");
        m_logger.error(e.toString());
    } catch (IOException e) {
        m_logger.error("IOException:");
        m_logger.error(e.toString());
        System.exit(-1);
    }
    boolean foundRows = true;
    boolean foundFullRowset = false;
    while (endTime > currentTime) {
        // do a single archive at each partition
        foundRows = false;
        foundFullRowset = false;
        long callTimeMillis = System.currentTimeMillis();
        FileOutputStream fout;
        try {
            String outFileName = "/tmp/" + callTimeMillis + "_rows.txt";
            fout = new FileOutputStream(outFileName, true);
            for (longCounter = 0; longCounter < num_partitions; longCounter++) {
                try {
                    long callTimeBegin = System.currentTimeMillis();
                    VoltTable[] vtArchiveVisits = voltclient.callProcedure("ArchiveVisits", longCounter, numMoves, callTimeMillis).getResults();
                    long callTimeEnd = System.currentTimeMillis();
                    int rowCount = vtArchiveVisits[0].getRowCount();
                    if (rowCount > 0) {
                        // write out the rows
                        foundRows = true;
                        if (rowCount == numMoves) {
                            foundFullRowset = true;
                        }
                        // write out the rows
                        for (intCounter = 0; intCounter < rowCount; intCounter++) {
                            VoltTableRow row = vtArchiveVisits[0].fetchRow(intCounter);
                            playerId = row.getLong(0);
                            gameId = row.getLong(1);
                            socialId = row.getLong(2);
                            clientId = row.getLong(3);
                            visitTime = row.getLong(4);
                            Date visitDate = new Date(visitTime);
                            new PrintStream(fout).print(playerId + "\t" + gameId + "\t" + socialId + "\t" + clientId + "\t" + visitDate + "\n");
                        }
                    }
                    String currentDate = new Date().toString();
                    m_logger.info(String.format("[%s] Ran archive on partition %d : archived %,d row(s) in %,d milliseconds", currentDate, longCounter, rowCount, (callTimeEnd - callTimeBegin)));
                } catch (ProcCallException e) {
                    m_logger.error("ProcCallException:");
                    m_logger.error(e.toString());
                } catch (NoConnectionsException e) {
                    m_logger.error("IOException:");
                    m_logger.error(e.toString());
                    System.exit(-1);
                }
            }
            fout.close();
            if (!foundRows) {
                // no rows found, delete file
                boolean success = (new File(outFileName)).delete();
                if (success) {
                    m_logger.info("No rows found for this run, deleted " + outFileName);
                } else {
                    m_logger.info("No rows found for this run, BUT unable to delete " + outFileName);
                }
                // pause for 5 seconds
                m_logger.info(String.format("Pausing for %d seconds...", loopPauseSeconds));
                long pauseCurrentMillis = System.currentTimeMillis();
                long pauseEndMillis = pauseCurrentMillis + (loopPauseSeconds * 1000l);
                while (pauseCurrentMillis < pauseEndMillis) {
                    pauseCurrentMillis = System.currentTimeMillis();
                }
            } else if (!foundFullRowset) {
                // none of the rowsets were full (amount requested)
                // pause for given number seconds
                m_logger.info(String.format("No full rowsets found, pausing for %d seconds...", loopPauseSeconds));
                long pauseCurrentMillis = System.currentTimeMillis();
                long pauseEndMillis = pauseCurrentMillis + (loopPauseSeconds * 1000l);
                while (pauseCurrentMillis < pauseEndMillis) {
                    pauseCurrentMillis = System.currentTimeMillis();
                }
            }
        } catch (IOException e) {
            m_logger.error(e.toString());
            System.exit(-1);
        }
        currentTime = System.currentTimeMillis();
    }
    try {
        voltclient.drain();
    } catch (InterruptedException e) {
        m_logger.error(e.toString());
        System.exit(-1);
    } catch (NoConnectionsException e) {
        m_logger.error(e.toString());
        System.exit(-1);
    }
    try {
        voltclient.close();
    } catch (Exception e) {
        m_logger.error(e.toString());
        System.exit(-1);
    }
}
Also used : PrintStream(java.io.PrintStream) IOException(java.io.IOException) VoltTable(org.voltdb.VoltTable) Date(java.util.Date) ProcCallException(org.voltdb.client.ProcCallException) NoConnectionsException(org.voltdb.client.NoConnectionsException) IOException(java.io.IOException) NoConnectionsException(org.voltdb.client.NoConnectionsException) FileOutputStream(java.io.FileOutputStream) VoltTableRow(org.voltdb.VoltTableRow) File(java.io.File) ProcCallException(org.voltdb.client.ProcCallException)

Example 48 with NoConnectionsException

use of org.voltdb.client.NoConnectionsException in project voltdb by VoltDB.

the class DeletesClient method deleteBatch.

static void deleteBatch(Client client, long batchesToKeep) {
    long prune_ts = m_batchNumber - batchesToKeep;
    Date date = new Date();
    System.out.println(date.toString() + "\n\tPruning batches older than batch: " + prune_ts);
    m_expectedDeletes = NUM_NAMES;
    long start_time = System.currentTimeMillis();
    for (int i = 0; i < NUM_NAMES; i++) {
        try {
            while (!client.callProcedure(new ProcedureCallback() {

                @Override
                public void clientCallback(ClientResponse response) {
                    if (response.getStatus() != ClientResponse.SUCCESS) {
                        System.out.println("failed delete batch");
                        System.out.println(response.getStatusString());
                    } else {
                        m_totalRows -= response.getResults()[0].asScalarLong();
                        m_totalDeletedRows += response.getResults()[0].asScalarLong();
                    }
                    //we don't care if tx fail, but don't get stuck in yield
                    m_expectedDeletes--;
                }
            }, "DeleteOldBatches", m_names[i], prune_ts)) {
                try {
                    client.backpressureBarrier();
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        } catch (NoConnectionsException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    while (m_expectedDeletes != 0) {
        Thread.yield();
    }
    long elapsed = System.currentTimeMillis() - start_time;
    m_totalDeletes += NUM_NAMES;
    m_totalDeleteTime += elapsed;
    System.out.println("\tAfter delete, total rows: " + m_totalRows);
    System.out.println("\tDeleting batch: " + NUM_NAMES + " took " + elapsed + " millis");
    System.out.println("\t\t (" + ((NUM_NAMES * 1000) / elapsed) + " tps)");
    System.out.println("\tTotal delete TPS: " + (m_totalDeletes * 1000) / m_totalDeleteTime);
    System.out.println("\tTotal delete RPS: " + (m_totalDeletedRows * 1000) / m_totalDeleteTime);
}
Also used : ProcedureCallback(org.voltdb.client.ProcedureCallback) ClientResponse(org.voltdb.client.ClientResponse) NoConnectionsException(org.voltdb.client.NoConnectionsException) IOException(java.io.IOException) Date(java.util.Date)

Example 49 with NoConnectionsException

use of org.voltdb.client.NoConnectionsException in project voltdb by VoltDB.

the class JDBC4ClientConnection method executeAsync.

/**
     * Executes a procedure asynchronously, returning a Future that can be used by the caller to
     * wait upon completion before processing the server response.
     *
     * @param procedure
     *            the name of the procedure to call.
     * @param parameters
     *            the list of parameters to pass to the procedure.
     * @return the Future created to wrap around the asynchronous process.
     */
public Future<ClientResponse> executeAsync(String procedure, Object... parameters) throws NoConnectionsException, IOException {
    ClientImpl currentClient = this.getClient();
    final JDBC4ExecutionFuture future = new JDBC4ExecutionFuture(this.defaultAsyncTimeout);
    try {
        currentClient.callProcedure(new TrackingCallback(this, procedure, new ProcedureCallback() {

            @SuppressWarnings("unused")
            final JDBC4ExecutionFuture result;

            {
                this.result = future;
            }

            @Override
            public void clientCallback(ClientResponse response) throws Exception {
                future.set(response);
            }
        }), procedure, parameters);
    } catch (NoConnectionsException e) {
        this.dropClient(currentClient);
        throw e;
    }
    return future;
}
Also used : ProcedureCallback(org.voltdb.client.ProcedureCallback) ClientResponse(org.voltdb.client.ClientResponse) NoConnectionsException(org.voltdb.client.NoConnectionsException) ClientImpl(org.voltdb.client.ClientImpl)

Example 50 with NoConnectionsException

use of org.voltdb.client.NoConnectionsException in project voltdb by VoltDB.

the class DataUtils method maxInsertTime.

public long maxInsertTime() {
    ClientResponse response = null;
    try {
        response = m_client.callProcedure(m_max);
    } catch (NoConnectionsException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (ProcCallException e) {
        e.printStackTrace();
    }
    VoltTable[] countQueryResult = response.getResults();
    VoltTable data = countQueryResult[0];
    if (data.asScalarLong() == VoltType.NULL_BIGINT)
        return 0;
    return data.asScalarLong();
}
Also used : ClientResponse(org.voltdb.client.ClientResponse) NoConnectionsException(org.voltdb.client.NoConnectionsException) IOException(java.io.IOException) VoltTable(org.voltdb.VoltTable) ProcCallException(org.voltdb.client.ProcCallException)

Aggregations

NoConnectionsException (org.voltdb.client.NoConnectionsException)50 IOException (java.io.IOException)41 ProcCallException (org.voltdb.client.ProcCallException)38 VoltTable (org.voltdb.VoltTable)27 ClientResponse (org.voltdb.client.ClientResponse)21 Client (org.voltdb.client.Client)19 Date (java.util.Date)7 VoltTableRow (org.voltdb.VoltTableRow)6 ProcedureCallback (org.voltdb.client.ProcedureCallback)5 Timestamp (java.sql.Timestamp)4 File (java.io.File)3 AtomicLong (java.util.concurrent.atomic.AtomicLong)3 Tag (org.openstreetmap.osmosis.core.domain.v0_6.Tag)3 ClientResponseImpl (org.voltdb.ClientResponseImpl)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 WayNode (org.openstreetmap.osmosis.core.domain.v0_6.WayNode)2 LineString (org.postgis.LineString)2 VoltCompiler (org.voltdb.compiler.VoltCompiler)2