GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • V15 Documentation
  • Privacy Statement
  • License Agreement
  • Contact Us

This view

  • Original page
  • New address

GeezerVison is showing docs.voltdb.com — Appendix B. Using the Original VoltDB Client Interface

  • Volt Active Data
  • Developer Hub
  • Books
    • VoltDB Tutorial
    • Using VoltDB
    • VoltDB Guide to Performance and Customization
    • VoltDB Administrator's Guide
    • Volt Kubernetes Administrator's Guide
    • VoltDB Quick Reference
  • Current docs ▶
  • VoltDB V15
    • VoltDB V16
    • VoltDB V15.3 LTS
    • VoltDB V14.3 LTS
    • VoltDB V13.3 LTS
    • VoltDB V12.3 LTS
    • VoltDB V11.4
    • VoltDB V10.2
    • VoltDB V9.3
Appendix B. Using the Original VoltDB Client Interface

Upgrade Guide

  • Preface▶
    • 1. Structure of This Book
    • 2. Related Documents
  • 1. Software Releases and Long-Term Support (LTS)▶
    • 1.1. The Software Release Schedule
    • 1.2. Staying Current
  • 2. The Software Upgrade Process▶
    • 2.1. Preparing for the Upgrade
    • 2.2. Upgrading Volt Databases on Managed Servers
      • 2.2.1. Upgrading the VoltDB Software
      • 2.2.2. Upgrading VoltDB Using Save and Restore
      • 2.2.3. Performing an In-Service Upgrade of a Single Cluster
      • 2.2.4. Performing an Online Upgrade Using Multiple XDCR Clusters
    • 2.3. Upgrading Volt in Kubernetes
      • 2.3.1. Updating Your Helm Repository
      • 2.3.2. Updating the Custom Resource Definition (CRD)
      • 2.3.3. Upgrading the VoltDB Operator and Software
      • 2.3.4. Using In-Service Upgrade to Update the VoltDB Software
      • 2.3.5. Updating VoltDB for XDCR Clusters
  • 3. Upgrading to Volt Active Data V8▶
    • 3.1. What's New in Volt V8.0
    • 3.2. Special Considerations for Existing Customers
  • 4. Upgrading to Volt Active Data V9▶
    • 4.1. What's New in Volt V9.0
    • 4.2. Special Considerations for Existing Customers
  • 5. Upgrading to Volt Active Data V10▶
    • 5.1. What's New in Volt V10.0
    • 5.2. Special Considerations for Existing Customers
  • 6. Upgrading to Volt Active Data V11▶
    • 6.1. What's New in Volt V11.0
    • 6.2. Special Considerations for Existing Customers
  • 7. Upgrading to Volt Active Data V12▶
    • 7.1. What's New in Volt V12.0
    • 7.2. Special Considerations for Existing Customers
  • 8. Upgrading to Volt Active Data V13▶
    • 8.1. What's New in Volt V13
    • 8.2. Special Considerations for Existing Customers
  • 9. Upgrading to Volt Active Data V14▶
    • 9.1. What's New in Volt Active Data V14
    • 9.2. Special Considerations for Existing Customers
  • 10. Upgrading to Volt Active Data V15▶
    • 10.1. What's New in Volt Active Data V15
    • 10.2. Special Considerations for Existing Customers
  • A. Configuration File (deployment.xml)▶
    • A.1. Understanding XML Syntax
    • A.2. The Structure of the XML Configuration File
  • B. Using the Original VoltDB Client Interface▶
    • B.1. Connecting to the VoltDB Database
      • B.1.1. Connecting to Multiple Servers
      • B.1.2. Using the Auto-Connecting Client
    • B.2. Invoking Stored Procedures
    • B.3. Invoking Stored Procedures Asynchronously
    • B.4. Closing the Connection
    • B.5. Handling Errors
      • B.5.1. Interpreting Execution Errors
      • B.5.2. Handling Timeouts
      • B.5.3. Writing a Status Listener to Interpret Other Errors

Appendix B. Using the Original VoltDB Client Interface

Volt Active Data has two Java client programming interfaces: Client and Client2. Client2 is a modern API using the best features and design patterns of the Java programming language. Client is the original client API. Because of the improvements made to Client2, Client2 is recommended for all new application development and is featured in the documentation. However, the original Client API is still supported and in use in a number of existing customer applications.

Which is why this appendix is provided for anyone needing to support applications that use the original Client API. The following sections explain how to use the original VoltDB Java client interface for runtime access to VoltDB databases and functions. Please see the Using VoltDB guide for information on writing new applications using the Client2 API.

B.1. Connecting to the VoltDB Database

The first task for the calling program is to create a connection to the VoltDB database. You do this with the following steps:

org.voltdb.client.Client client = null;
ClientConfig config = null;
try {
       config = new ClientConfig("advent","xyzzy");       1

       client = ClientFactory.createClient(config);       2
 
       client.createConnection("myserver.xyz.net");       3
} catch (java.io.IOException e) {
       e.printStackTrace();
       System.exit(-1);
}

1

Define the configuration for your connections. In its simplest form, the ClientConfig class specifies the username and password to use. It is not absolutely necessary to create a client configuration object. For example, if security is not enabled (and therefore a username and password are not needed) a configuration object is not required. But it is a good practice to define the client configuration to ensure the same credentials are used for all connections against a single client. It is also possible to define additional characteristics of the client connections as part of the configuration, such as the timeout period for procedure invocations or a status listener. (See Section B.5, “Handling Errors”.)

2

Create an instance of the VoltDB Client class.

3

Call the createConnection() method. After you instantiate your client object, the argument to createConnection() specifies the database node to connect to. You can specify the server node as a hostname (as in the preceding example) or as an IP address. You can also add a second argument if you want to connect to a port other than the default. For example, the following createConnection() call attempts to connect to the admin port, 21211:

client.createConnection("myserver.xyz.net",21211);

If security is enabled and the username and password in the ClientConfig() call do not match a user defined in the configuration file, the call to createConnection() will throw an exception.

When you are done with the connection, you should make sure your application calls the close() method to clean up any memory allocated for the connection. See Section B.4, “Closing the Connection”.

B.1.1. Connecting to Multiple Servers

You can create the connection to any of the nodes in the database cluster and your stored procedure will be routed appropriately. In fact, you can create connections to multiple nodes on the server and your subsequent requests will be distributed to the various connections. For example, the following Java code creates the client object and then connects to all three nodes of the cluster. In this case, security is not enabled so no client configuration is needed:

try {
       client = ClientFactory.createClient();
       client.createConnection("server1.xyz.net");
       client.createConnection("server2.xyz.net");
       client.createConnection("server3.xyz.net");
} catch (java.io.IOException e) {
       e.printStackTrace();
       System.exit(-1);
}

Creating multiple connections has three major benefits:

  • Multiple connections distribute the stored procedure requests around the cluster, avoiding a bottleneck where all requests are queued through a single host. This is particularly important when using asynchronous procedure calls or multiple clients.

  • For Java applications, the VoltDB Java client library uses client affinity. That is, the client knows which server to send each request to based on the partitioning, thereby eliminating unnecessary network hops.

  • Finally, if a server fails for any reason, when using K-safety the client can continue to submit requests through connections to the remaining nodes. This avoids a single point of failure between client and database cluster.

B.1.2. Using the Auto-Connecting Client

An easier way to create connections to all of the database servers is to use the "smart" or topology-aware client. By setting the Java client to be aware of the cluster topology, you only need to connect to one server and the client automatically connects to all of the servers in the cluster.

An additional advantage of the smart client is that it will automatically reconnect whenever the topology changes. That is, if a server fails and then rejoins the cluster, or new nodes are added to the cluster, the client will automatically create connections to the newly available servers.

You enable auto-connecting when you initialize the client object by setting the configuration option before creating the client object. For example:

org.voltdb.client.Client client = null;
ClientConfig config = new ClientConfig("","");
config.setTopologyChangeAware(true);
 try {
       client = ClientFactory.createClient(config);
       client.createConnection("server1.xyz.net");
             . . .

When setTopologyChangeAware() is set to true, the client library will automatically connect to all servers in the cluster and adjust its connections any time the cluster topology changes.

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.