(UCP) in a Tomcat Application Container Requires the Following Steps
Total Page:16
File Type:pdf, Size:1020Kb
Design and Deploy TomCat AppliCations for Planned, Unplanned Database Downtimes and Runtime Load BalanCing with UCP In OraCle Database RAC and Active Data Guard environments ORACLE WHITE PAPER NOVEMBER 2017 DESIGN AND DEPLOY TOMCAT SERVLETS FOR PLANNED AND UNPLANNED DATABASE DOWNTIME AND LOAD BALANCING WITH UCP Table of Contents IntroduCtion 3 Issues to be addressed 3 OraCle Database 12C High-Availability and Load BalanCing ConCepts 4 Configure TomCat for UCP 4 Create a New Database Resource 4 Create a JNDI lookup in the servlet 5 Create a web.xml for the servlet 6 Hiding Planned MaintenanCe from TomCat Servlets 6 Web Applications Steps 6 DBA or RDBMS Steps 7 Hiding Unplanned Database downtime from TomCat Servlets 9 Developer or Web Application Steps 9 DBA or RDBMS Steps 10 Application Continuity Checklist 10 Runtime Load BalanCing (RLB) with TomCat Servlets 12 Web AppliCation steps 12 Appendix 13 Enable JDBC & UCP logging for debugging 13 ConClusion 14 2 DESIGN AND DEPLOY TOMCAT SERVLETS FOR PLANNED AND UNPLANNED DATABASE DOWNTIME AND LOAD BALANCING WITH UCP IntroduCtion Achieving maximum appliCation uptime without interruptions is a CritiCal business requirement. There are a number of requirements such as outage detection, transparent planned maintenanCe, and work load balanCing that influenCe appliCation availability and performance. The purpose of this paper is to help Java Web applications deployed with ApaChe TomCat, achieve maximum availability and sCalability when using Oracle. Are you looking for best praCtiCes to hide your tomCat applications from database outages? Are you looking at, smooth & stress-free maintenanCes of your tomCat appliCations? Are you looking at leveraging Oracle Database’s runtime load balancing in your tomCat web appliCations? This paper Covers the configuration of your database and tomCat servlets for resilienCy to planned maintenanCe, unplanned database outages, and dynamic balancing of the workload across 1 database instances, using RAC, ADG, GDS , and UCP. Issues to be addressed The key issues that impede continuous application availability and performance are: » Planned Maintenance: » Achieve transparent maintenance: Make the maintenanCe proCess fast and transparent to appliCations for continuous availability. » Session draining: When the targeted instanCe is brought down for maintenanCe, ensure that all work completes. We will desCribe how to drain sessions without impaCting in-flight work and also avoid logon storms on active instance(s) during the planned maintenance. » Unplanned Downtimes: » Outage detection: Web appliCation’s timeouts are unprediCtable and unreliable. This paper desCribes how to configure TomCat servlets to be notified of outages as fast as possible. » Error handling: Several types of SQL exCeptions may be received by your servlets; how to determine that such errors are indiCative of database serviCe failure? » Recovery with Response Time Targets: Upon outage, the OraCle Database RAC system needs a short period of time to recover before becoming fully operational again. How to reaCt quiCkly and keep such “brownout” period under SLA targets? » Outcome of in-flight work: Have you ever paid twiCe for books, flights, or taxes? Making a reliable determination of the outCome of the in-flight transaCtion in the faCe of database outages was a Challenge until OraCle Database 12C. We will desCribe, how to design servlets and Configure Oracle Database 12c for solving this challenge. » Continuation of in-flight work: How to design servlets and Configure OraCle Database 12c and UCP to allow safe and transparent replay of in-flight transaCtions in the event of unplanned database outages. » Workload Balancing: In RAC, RAC ONE, and ADG environments, Connection requests are by default distributed randomly by the Net Listener. How to Configure your web appliCations and Configure the database for optimal distribution of the workload when the node/serviCes are added/removed? 1 http://www.oracle.com/technetwork/database/availability/maa-consolidation-2186395.pdf 3 DESIGN AND DEPLOY TOMCAT SERVLETS FOR PLANNED AND UNPLANNED DATABASE DOWNTIME AND LOAD BALANCING WITH UCP If you are a Java developer or arChiteCt looking to exploit OraCle Database Real AppliCation Cluster (RAC), Exadata, Active Data Guard (ADG), Global Data ServiCes (GDS) and OraCle Universal ConneCtion Pool (UCP) solutions for planned and unplanned database downtime and workload balancing, this is the paper for you. If you are a DBA looking for database Configuration steps to meet Web apps high-availability and load balancing requirements, this is the paper for you too. OraCle Database 12c High-Availability and Load Balancing ConCepts To support high-availability and load balancing solutions, Oracle Database 12c Release 2 (12.2) and prior releases furnish HA Configurations (RAC, Data Guard) and features whiCh are leveraged by OraCle Database drivers (e.g., Oracle JDBC) and Connection pools (e.g., UCP). This paper will refer to the following features, meChanisms, and conCepts desCribed in 2 Java Programming with Oracle Database 12c RAC and Active Data Guard white paper: » Universal ConneCtion Pool (UCP) » Fast AppliCation NotifiCation (FAN) » OraCle NotifiCation ServiCe (ONS) » Fast Connection Failover (FCF) » LogiCal Transaction ID (LTXID) » Database Request » ReCoverable Errors » Mutable FunCtions » Transaction Guard (TG) » AppliCation Continuity (AC) Configure TomCat for UCP Universal ConneCtion Pool (UCP) has the built in support for planned maintenanCe, unplanned downtimes, and runtime load balanCing. UCP along with RAC, RAC One, and ADG is a tested and certified combination for handling database failovers. UCP has been suCCessfully used by many Customers to handle failovers seamlessly. Configuring UCP in ApaChe TomCat is explained in detail, hereafter. Deploying a servlet whiCh aCCesses Oracle Database through Oracle JDBC driver and Oracle Universal Connection Pool (UCP) in a TomCat appliCation Container requires the following steps: » Create a New Database ResourCe » Create a JNDI lookup in the servlet » Create a web.xml for the Servlet Create a New Database Resource 3 First ensure that OraCle JDBC jar ojdbC8.jar , uCp.jar, and ons.jar from the version 12.2 are present in $CATALINA_HOME/lib. Make sure that all three jar files are from the same database version. DO NOT mix the version of these jars. Always, try to use the latest JDBC driver and UCP in order to leverage the latest capabilities and performance 2 http://www-content.oracle.com/technetwork/database/application-development/12c-ha-concepts-2408080.pdf 3 http://www.oracle.com/technetwork/database/features/jdbc/jdbc-ucp-122-3110062.html 4 DESIGN AND DEPLOY TOMCAT SERVLETS FOR PLANNED AND UNPLANNED DATABASE DOWNTIME AND LOAD BALANCING WITH UCP improvements. UCP is Configured either as a global resourCe in server.xml for all applications, or as an appliCation specific resourCe in context.xml ($CATALINA_HOME/webapps/<APPLICATION_NAME>/META-INF/context.xml) as shown in Fig 1a below. Note that all required UCP properties such as minPoolSize, maxPoolSize, are mentioned while Creating a new database resource. Two connection properties and their settings related to high availability are summarized here. (a) fastConnectionFailoverEnabled (a.k.a FCF): The12.2 UCP has FCF enabled by default. However, FCF should be set to true (fastConneCtionFailoverEnabled=true) when using UCP 12.1.0.2,12.1.0.1 and 11.2.0.4. (b) ONSConfiguration: The 12.2 UCP has auto-ONS capability and receives the ONS notifiCations automatiCally. However, if you are using pre 12.1 RAC database, this property must be set expliCitly. Example: onsConfiguration="nodes=<RAC_node1>:<port1>, <RAC_node2>:<port2>, <RAC_node3>:<port3> Fig 1a: Database Resource in Tomcat with 12.2 UCP <Context docBase="UCPTomcat" path="/UCPTomcat" reloadable="true" source="org.eclipse.jst.jee.server:UCPTomcat"> <Resource name="tomcat/UCPPool" auth="Container" <!-- Defines UCP or JDBC factory for connections --> factory="oracle.ucp.jdbc.PoolDataSourceImpl" <!-- Defines type of the datasource instance --> type="oracle.ucp.jdbc.PoolDataSource" description="UCP Pool in Tomcat" <!-- Defines the Connection Factory to get the physical connections --> connectionFactoryClassName="oracle.jdbc.pool.OracleDataSource” minPoolSize="2" maxPoolSize="60" initialPoolSize="15" autoCommit="false" user="scott" password="tiger" <!-- FCF is auto-enabled in 12.2. Use this property only if you are using Pre 12.2 UCP fastConnectionFailoverEnabled=”true” --> <!-- Database URL --> url="jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=tcp)(HOST=proddbclust er-scan)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=proddb)))" </Resource> </Context> Create a JNDI lookup in the servlet The following Code snippet shows how to get a database Connection by referring to the JNDI datasourCe Created in TomCat. Context ctx = new InitialContext(); Context envContext = (Context)ctx.lookup("java:/comp/env"); 5 DESIGN AND DEPLOY TOMCAT SERVLETS FOR PLANNED AND UNPLANNED DATABASE DOWNTIME AND LOAD BALANCING WITH UCP // Look up a data source javax.sql.DataSource ds=(javax.sql.DataSource)envContext.lookup ("tomcat/UCPPool"); PoolDataSource pds= (PoolDataSource)ds; Connection conn = pds.getConnection(); Create a web.xml for the servlet The data sourCe resourCe reference should also be present in web.xml as illustrated hereafter. <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee"