www.openlinksw.com
docs.openlinksw.com

Book Home

Contents
Preface

Data Access Interfaces

ADO.Net Data Provider
Interactive SQL Utility
Virtuoso Driver for ODBC
Virtuoso Driver for JDBC
OLE DB Provider for Virtuoso
Virtuoso In-Process Client
Unix Domain Socket Connections
Virtuoso Data Access Clients Connection Fail over and Load Balancing Support
ODBC ADO.Net JDBC OLE DB Sesame

7.8. Virtuoso Data Access Clients Connection Fail over and Load Balancing Support

The Virtuoso Data Access Clients ODBC, JDBC, ADO.Net, OLE DB, Sesame, Jena and Redland as of Release 6.1 and above support round robin connections to Virtuoso server instances enabling server fail over, load balancing and fault tolerant connections to be performed across multiple server instances configured in a cluster or as separate server instances.

Fail over connections are enabled by specifying a comma delimited list of servers to failover to, in the "Host" or 'Server" connect string attribute, with the list being worked through in the order presented to determine which Virtuoso Server instance is used. A Round robin (load balanced) connection can be configured by adding the connect string attribute "RoundRobin" = [True | Yes | False | No], in which case the server for the connection is chosen at random from the comma delimited provided as for a Failover connection above.

Example connect strings for Virtuoso ODBC, JDBC, ADO.Net and OLE DB driver/providers are provided below. The Virtuoso Sesame and Jena providers which make use of the JDBC driver and Redland Provider which makes use of the ODBC driver, would simply make use of a suitably configured JDBC or ODBC connect string to enable Failover or Round Robin connections to be made with them.

7.8.1. ODBC

7.8.1.1. Failover Connect String format

Driver={OpenLink Virtuoso};Host=server1:port1,server2:port2,server3:port3;UID=dba;PWD=dba;

7.8.1.2. Round Robin Connect String format

Driver={OpenLink Virtuoso};Host=server1:port1,server2:port2,server3:port3;UID=dba;PWD=dba;RoundRobin=Yes"

Or alternatively ensure the "use Round Robin for failover connection" check box in the setup dialog.

ODBC Round Robin Connect String format
Figure: 7.8.1.2.1. ODBC Round Robin Connect String format


7.8.2. ADO.Net

7.8.2.1. Failover Connect String format

Server=server1:port1,server2:port2,server3;UserId=dba;Password=dba;

7.8.2.2. Round Robin Connect String format

Server=server1:port1,server2:port2,server3;UserId=dba;Password=dba;Round Robin=true;Pooling=false;


7.8.3. JDBC

7.8.3.1. Failover Connect String format

jdbc:virtuoso://server1:port1,server2:port2,server3/UID=dba/PWD=dba/;

7.8.3.2. Round Robin Connect String format

jdbc:virtuoso://server1:port1,server2:port2,server3:1111/UID=dba/PWD=dba/ROUNDROBIN=yes;


7.8.4. OLE DB

7.8.4.1. Failover Connect String format

Provider=VIRTOLEDB;Data Source=server1:port1,server2:port2,server3;User Id=dba;Password=dba;Initial Catalog=Demo;Prompt=NoPrompt;

7.8.4.2. Round Robin Connect String format

  Provider=VIRTOLEDB;Data Source=server1:port1,server2:port2,server3;User Id=dba;
Password=dba;Initial Catalog=Demo;Prompt=NoPrompt;Round Robin=true


7.8.5. Sesame

7.8.5.1. Failover Connect String format

VirtuosoRepository("server1:port1,server2:port2,server3", "uid", "pwd");

7.8.5.2. Round Robin Connect String format

VirtuosoRepository("server1:port1,server2:port2,server3", "uid", "pwd");
((VirtuosoRepository)repository).setRoundrobin(true);

7.8.5.3. Sample program

/*
 *  $Id: accessinterfaces.xml,v 1.6.2.5 2010/03/30 17:59:29 source Exp $
 *
 *  This file is part of the OpenLink Software Virtuoso Open-Source (VOS)
 *  project.
 *
 *  Copyright (C) 1998-2009 OpenLink Software
 *
 *  This project is free software; you can redistribute it and/or modify it
 *  under the terms of the GNU General Public License as published by the
 *  Free Software Foundation; only version 2 of the License, dated June 1991.
 *
 *  This program is distributed in the hope that it will be useful, but
 *  WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 *  General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License along
 *  with this program; if not, write to the Free Software Foundation, Inc.,
 *  51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 */

import java.sql.*;
import java.util.*;
import java.lang.*;

import org.openrdf.model.*;
import org.openrdf.query.*;
import org.openrdf.repository.*;
import org.openrdf.rio.*;
import virtuoso.jdbc4.*;

import virtuoso.sesame2.driver.*;

public class TestSesame2 {

  public static void main(String[] args) {

      Repository repository = new
	VirtuosoRepository("localhost:1111,localhost:1311,localhost:1312,localhost:1313", "dba", "dba");
      ((VirtuosoRepository)repository).setRoundrobin(true);

      RepositoryConnection con = null;
      Random rnd = new Random();
      for (int i = 0; i < 1000000; ) {
	  try {
	      if (null == con) {
		  System.out.println("New connection");
		  con = repository.getConnection();
	      }

	      TupleQuery query = con.prepareTupleQuery(
		      QueryLanguage.SPARQL, "INSERT INTO <test_g> { <sub" + i + "> <pred> <obj" + i+ "> . " +
		      " <r" + Math.abs (rnd.nextInt()) + "> <rndpred> <r" + Math.abs (rnd.nextInt ()) + "> . }");
	      TupleQueryResult queryResult = query.evaluate();
	      /*long count = 0;
	      while (queryResult.hasNext())
	      {
		  queryResult.next();
		  count++;
		  if (count % 1000 == 0)
		  {
		      System.out.println("Passed " + count + " results...");
		  }
	      }
	      */
	      queryResult.close();
	      i++;
	      try { Thread.sleep(100); } catch (InterruptedException ie) { }

	  } catch (Exception e) {
	      String state = "";
	      if (e.getCause() instanceof SQLException) {
		  state = ((SQLException)e.getCause()).getSQLState();
	      }
	      System.out.println("ERROR:" + state + " " + e.getCause());
	      try { Thread.sleep(2000); } catch (InterruptedException ie) { }
	      System.out.println("ERROR:" + e.toString ());
	      if (state == "")
	        e.printStackTrace();
	      try {
		  if (con != null /*&& (state == "08U01" || state == "S2801")*/) {
		      System.out.println("Closing Connection.");
		      con.close();
		      con = null;
		  }
	      } catch (RepositoryException re) {
		  System.out.println("Test Failed.");
		  re.printStackTrace();
		  System.exit (1);
	      }
	  } finally {
	  }
      }
  }
}