Search in sources :

Example 1 with ClientConfig

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

the class Client method runStatusLoop.

/**
     * Loop until all auctions have closed, printing status for each auction at
     * specific intervals.
     */
static void runStatusLoop() {
    // create a second client handle for this second thread
    org.voltdb.client.Client client = null;
    try {
        ClientConfig config = new ClientConfig("program", "pass");
        client = ClientFactory.createClient(config);
        client.createConnection("localhost");
    } catch (java.io.IOException e) {
        e.printStackTrace();
        System.exit(-1);
    }
    boolean auctionsOver = false;
    while (auctionsOver == false) {
        try {
            // assume auctions have ended. if any open auctions are found, then set this false
            auctionsOver = true;
            // print out the status header
            System.out.printf("\nAUCTION STATUS AS OF: %tT\n", new Date());
            System.out.printf("+-----------------------------------------------------" + "-----------------------------------------------+\n");
            System.out.printf("| %-20s | %-16s | %-16s | %5s | %8s | %9s | %-6s |\n", "ITEM", "BIDDER", "SELLER", "BIDS", "PRICE", "END", "STATUS");
            System.out.printf("+-----------------------------------------------------" + "-----------------------------------------------+\n");
            // loop over all auction ids, printing a row of status for each one
            for (int auctionId : allAuctionIds) {
                VoltTable[] statusResultSet = client.callProcedure("AuctionStatus", auctionId).getResults();
                if (statusResultSet.length != 1)
                    throw new Exception("AuctionStatus returned no results");
                VoltTable statusTable = statusResultSet[0];
                VoltTableRow row = statusTable.fetchRow(0);
                System.out.printf("| %-20s | %-16s | %-16s | %5d | %8.2f | %9tT | %-6s |\n", row.getString("item"), row.getString("bidder"), row.getString("seller"), row.getLong("bidcount"), row.getDouble("price"), row.getTimestampAsTimestamp("endtime").asApproximateJavaDate(), row.getString("status"));
                if (row.getString("status").equals("OPEN"))
                    auctionsOver = false;
            }
            // print the status footer
            System.out.printf("+-----------------------------------------------------" + "-----------------------------------------------+\n");
            // wait for next status update
            Thread.sleep(1000 * statusPeriodInSeconds);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    try {
        client.close();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}
Also used : VoltTable(org.voltdb.VoltTable) Date(java.util.Date) ClientConfig(org.voltdb.client.ClientConfig) VoltTableRow(org.voltdb.VoltTableRow)

Example 2 with ClientConfig

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

the class Client method main.

/**
     * Load the initial data, then run the simulation.
     *
     * @param args This program uses no command line arguments.
     */
public static void main(String[] args) {
    System.out.println("***************************************");
    System.out.println("* Welcome to Bobbi's Awesome Auctions *");
    System.out.println("*                                     *");
    System.out.println("* Connecting to Server...             *");
    // connect to VoltDB server
    org.voltdb.client.Client client = null;
    ClientConfig config = new ClientConfig("program", "pass");
    client = ClientFactory.createClient(config);
    int sleep = 1000;
    while (true) {
        try {
            client.createConnection("localhost");
            break;
        } catch (Exception e) {
            System.out.println("Connection failed - retrying in " + (sleep / 1000) + " second(s).");
            try {
                Thread.sleep(sleep);
            } catch (Exception tie) {
            }
            if (sleep < 8000)
                sleep += sleep;
        }
    }
    System.out.println("* Connected                           *");
    System.out.println("* Running loader                      *");
    System.out.println("***************************************\n");
    // get itemId and userId from database
    try {
        VoltTable modCount = client.callProcedure("@AdHoc", "SELECT ITEMID FROM ITEM").getResults()[0];
        allAuctionIds = new ArrayList<Integer>();
        userIds = new ArrayList<Integer>();
        while (modCount.advanceRow()) {
            Integer i = (Integer) modCount.get(0, VoltType.INTEGER);
            allAuctionIds.add(i);
        }
        modCount = client.callProcedure("@AdHoc", "SELECT USERID FROM USER").getResults()[0];
        while (modCount.advanceRow()) {
            Integer i = (Integer) modCount.get(0, VoltType.INTEGER);
            userIds.add(i);
        }
        activeAuctionIds.addAll(allAuctionIds);
    } catch (Exception e) {
        e.printStackTrace();
    }
    // since we create 1 bid per auction
    nextBidId = allAuctionIds.size() + 1;
    System.out.println("***************************************");
    System.out.println("* Finished running loader             *");
    System.out.println("* Running auctions                    *");
    System.out.println("***************************************");
    // create and start a thread that prints auction status every
    // 10 seconds, ending when all auctions have closed
    Thread statusThread = new Thread(new Runnable() {

        public void run() {
            runStatusLoop();
        }
    });
    statusThread.start();
    // runloop executes bids until all auctions have ended
    runBidLoop(client);
    // wait for the status-printing thread to finish
    try {
        statusThread.join();
    } catch (Exception e) {
    }
    // print out a joke with dramatic pauses
    System.out.println("\n***************************************");
    System.out.println("* Complete...                         *");
    System.out.println("*                                     *");
    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {
    }
    System.out.println("* Where do ghosts shop?               *");
    System.out.println("*                                     *");
    try {
        Thread.sleep(3000);
    } catch (InterruptedException e) {
    }
    System.out.println("* In Boo-tiques!                      *");
    System.out.println("***************************************");
    try {
        client.close();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}
Also used : ClientConfig(org.voltdb.client.ClientConfig) VoltTable(org.voltdb.VoltTable)

Example 3 with ClientConfig

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

the class InProcessVoltDBServer method getClient.

/**
     * Create and connect a client to the in-process VoltDB server.
     * Note, client will be automatically closed when the in-process server
     * is shut down.
     * Must be called after {@link #start()}.
     * @return Connected client.
     * @throws Exception on failure to connect properly.
     */
public Client getClient() throws Exception {
    ClientConfig config = new ClientConfig();
    // turn off the timeout for debugging
    config.setProcedureCallTimeout(0);
    Client client = ClientFactory.createClient(config);
    // track this client so it can be closed at shutdown
    trackedClients.add(client);
    client.createConnection("localhost");
    return client;
}
Also used : ClientConfig(org.voltdb.client.ClientConfig) Client(org.voltdb.client.Client)

Example 4 with ClientConfig

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

the class AsyncExportClient method createClient.

static Client createClient() {
    ClientConfig clientConfig = new ClientConfig("", "");
    clientConfig.setReconnectOnConnectionLoss(true);
    if (config.autoTune) {
        clientConfig.enableAutoTune();
        clientConfig.setAutoTuneTargetInternalLatency(config.latencyTarget);
    } else {
        clientConfig.setMaxTransactionsPerSecond(config.rateLimit);
    }
    Client client = ClientFactory.createClient(clientConfig);
    clientRef.set(client);
    periodicStatsContext = client.createStatsContext();
    fullStatsContext = client.createStatsContext();
    return client;
}
Also used : ClientConfig(org.voltdb.client.ClientConfig) Client(org.voltdb.client.Client)

Example 5 with ClientConfig

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

the class CheckReplicaConsistency method checkForCorrectness.

/**
     * Core benchmark code. Connect. Initialize. Run the loop. Cleanup. Print
     * Results.
     *
     * @throws Exception
     *             if anything unexpected happens.
     */
public void checkForCorrectness(int ptnOrRep) throws Exception {
    // compare state of all nodes
    // we're employing "short circuit" read queries to get the data on the node
    // exit with nonzero if there is an error
    String z = config.servers;
    String[] servers = z.split(",");
    String[] tblSuffix_ = new String[] { "Ptn", "Rep" };
    String sPtnOrRep = tblSuffix_[ptnOrRep];
    // used for catalog check
    int nTables = 0;
    System.out.printf("Checking data across nodes, case: %s, servers: %s ...\n", sPtnOrRep, z);
    ClientConfig clientConfig = new ClientConfig(config.user, config.password);
    long[] counters = null;
    long[] crcs = null;
    int crcCount = -1;
    for (int iServer = 0; iServer < servers.length; iServer++) {
        String server = servers[iServer];
        Client client = ClientFactory.createClient(clientConfig);
        try {
            client.createConnection(server);
        } catch (Exception e) {
            System.err.printf("Error connecting to node %d %s\n", iServer, server);
            e.printStackTrace();
            throw new RuntimeException();
        }
        ClientResponse resp = null;
        if (iServer == 0) {
            // get the partition count
            resp = client.callProcedure("@Statistics", "PARTITIONCOUNT", 0);
            if (resp.getStatus() != ClientResponse.SUCCESS) {
                System.err.printf("Get partition count failed %s\n", resp.getStatusString());
                throw new RuntimeException();
            }
            VoltTable[] tpc = resp.getResults();
            nPartitions = 0;
            while (tpc[0].advanceRow()) {
                nPartitions = (int) tpc[0].getLong("PARTITION_COUNT");
            }
            System.out.printf("partition count: %d\n", nPartitions);
            if (nPartitions < 2) {
                System.err.printf("Less than 2 partitions\n", nPartitions);
                throw new RuntimeException();
            }
            counters = new long[nPartitions];
            crcs = new long[nPartitions];
        }
        if (nPartitions == 0) {
            System.err.println("Zero partitions should not happen");
            throw new RuntimeException();
        }
        // check the catalog by comparing the number of tables
        resp = client.callProcedure("@Statistics", "TABLE", 0);
        int nt = resp.getResults()[0].getRowCount();
        System.out.printf("table count: %d\n", nt);
        if (iServer == 0)
            nTables = nt;
        else {
            if (nTables != nt) {
                System.err.printf("TEST FAILED Catalog Table count mismatch %d != %d %s %s\n", nTables, nt, server, servers[0]);
                System.exit(1);
            //throw new RuntimeException();
            } else {
                System.out.printf("Catalog test passed\n");
            }
        }
        for (int pid = 0; pid < nPartitions; pid++) {
            // techniques ie. "short circuit" read.
            try {
                long counter = checkAndReturnCounter(server, client, pid, sPtnOrRep);
                if (iServer == 0)
                    counters[pid] = counter;
                else if (counters[pid] != counter) {
                    System.err.printf("TEST FAILED Node counter datacompare mismatch %d != %d %s %s\n", counter, counters[pid], server, servers[0]);
                    System.exit(1);
                //throw new RuntimeException();
                }
            } catch (Exception e) {
                System.err.printf("Exception received calling checkAndReturnCounter: server: %s pid: %d\n%s\n", server, pid, e.getMessage());
                e.printStackTrace();
                throw new RuntimeException();
            }
            // short circuit read techniques) and compare the crc's.
            try {
                long crc = returnCRC(server, client, pid, sPtnOrRep);
                if (iServer == 0)
                    crcs[pid] = crc;
                else if (crcs[pid] != crc) {
                    System.err.printf("TEST FAILED Node crc datacompare mismatch %d != %d %s %s\n", crc, crcs[pid], server, servers[0]);
                    System.exit(1);
                //throw new RuntimeException();
                }
            } catch (Exception e) {
                System.err.printf("Exception received calling returnCRC: server: %s pid: %d\n%s\n", server, pid, e.getMessage());
                e.printStackTrace();
                throw new RuntimeException();
            }
        }
        client.drain();
        client.close();
    }
    System.out.printf("case: %s All nodes of counter identical\n", sPtnOrRep);
}
Also used : ClientResponse(org.voltdb.client.ClientResponse) ClientConfig(org.voltdb.client.ClientConfig) Client(org.voltdb.client.Client) VoltTable(org.voltdb.VoltTable) ProcCallException(org.voltdb.client.ProcCallException) NoConnectionsException(org.voltdb.client.NoConnectionsException) IOException(java.io.IOException)

Aggregations

ClientConfig (org.voltdb.client.ClientConfig)38 Client (org.voltdb.client.Client)25 IOException (java.io.IOException)11 VoltTable (org.voltdb.VoltTable)10 Configuration (org.voltdb.VoltDB.Configuration)9 File (java.io.File)7 VoltProjectBuilder (org.voltdb.compiler.VoltProjectBuilder)7 ClientResponse (org.voltdb.client.ClientResponse)6 ServerThread (org.voltdb.ServerThread)5 ConnectException (java.net.ConnectException)4 UnknownHostException (java.net.UnknownHostException)4 Random (java.util.Random)4 Test (org.junit.Test)4 ClientConfigForTest (org.voltdb.client.ClientConfigForTest)4 ClientImpl (org.voltdb.client.ClientImpl)4 ProcCallException (org.voltdb.client.ProcCallException)4 FileNotFoundException (java.io.FileNotFoundException)3 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 VoltDB (org.voltdb.VoltDB)3