08
Tue, Oct
2 New Articles

DRDA Lvl 2 & Two Phase Commitment Cntrl in DB2/400

Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

As an AS/400 programmer for a growing, dynamic company, you're always facing new challenges. A couple of months ago, you implemented referential integrity and triggers in the Order Entry System to address data integrity needs and to provide more flexibility in managing accounts receivable and special sales promotions.

This month, the challenges continue as your company grows and opens up new markets. It's going to add remote warehouses in Chicago and Dallas to supplement the home office warehouse in New York and establish a remote sales force to service the new markets. Each of the two remote locations will need a small AS/400 to provide support for the warehouse staff and sales force. The inventory application will coordinate inventory control with the home office and the database on each of the remote systems, as illustrated in 1.

This month, the challenges continue as your company grows and opens up new markets. It's going to add remote warehouses in Chicago and Dallas to supplement the home office warehouse in New York and establish a remote sales force to service the new markets. Each of the two remote locations will need a small AS/400 to provide support for the warehouse staff and sales force. The inventory application will coordinate inventory control with the home office and the database on each of the remote systems, as illustrated in Figure 1.

These two additional AS/400s have you unexpectedly plunging headfirst into the world of distributed database. In the past, modifying or developing applications to work with a database that was spread across multiple systems represented a significant amount of complex, unique design and coding effort- especially to ensure a reasonable level of application performance and database integrity across systems.

Distributed Relational Database Architecture Level 2 (DRDA Level 2) offers an alternative to help minimize the performance impact of operating in the distributed database environment; two phase commitment control (two phase commit) can be used to ensure data integrity in the same environment. These are two of the new features of DB2/400, so every AS/400 programmer needs to know how to use them effectively. This article shows you how. It begins by defining DRDA Level 2 and two phase commit at a conceptual level. After that, you'll learn how to use these features of DB2/400 to solve the problems presented by moving into distributed database. Along the way, you'll become familiar with the key concepts you need to understand to effectively use these new database functions.

DRDA Level 2

DRDA Level 2 supports application-directed distributed unit of work (DUW). A unit of work is a single application program transaction that can contain one or more database transactions that are logically related. DRDA Level 2 is called application directed because the application program uses SQL statements to direct or control which database it is working with.

DUW is only available through the SQL interface. It lets DB2/400 connect to, access, and update multiple relational databases within the same unit of work in an application program. When the unit of work is completed, two phase commit can be used to ensure that all databases have been successfully updated.

Unlike DRDA Level 1 (the initial DRDA offering), DRDA Level 2 needs to physically establish a communications session with a remote system only once per application. Once established, the communications session can be logically disconnected and reconnected as required by the application, significantly reducing the overhead required and improving application performance compared to DRDA Level 1. This makes DRDA Level 2 a powerful tool to minimize communication overhead in a distributed database or client/server environment.

Two Phase Commitment Control

Two phase commit lets DB2/400 apply a single application transaction-which may be composed of several database updates-to two or more databases spread across multiple systems, and ensures that all the database updates are completed before committing the changes. If the update to any database is not completed, updates are rolled back from all the databases participating in the transaction. This makes two phase commit a powerful tool to ensure database integrity across multiple systems.

The Challenge: Distributed Inventory Database

With DRDA Level 2 and two phase commit, we can begin to see how to solve the problems of implementing a distributed inventory database. The problems are connecting to, and communicating with, the three AS/400s in the network, and maintaining the inventory database when it is distributed across these three systems.

When a single inventory transaction affects the database on each of the three systems, a communications session has to be established with each system, and the database on each system has to be updated correctly. Then the integrity of the transaction needs to be ensured across all three systems. If the database is correctly updated on the New York and Dallas systems, but there is a communications failure before the Chicago database can be updated, how can the integrity of the database be ensured? To resolve these problems, IBM has now implemented DRDA level 2 and two phase commit in DB2/400.

DRDA Level 2 and two phase commit are often discussed in the same context and are used together in a large number of application programs. Because of their relationship to each other, they are included in the same discussion in this article. However, they are separate functions that can stand alone and be used independently. Let's begin by discussing DRDA Level 2.

DRDA Level 2 Concepts

As discussed earlier in this article, DRDA Level 2 supports DUW, which allows an application program using SQL to connect to and update multiple relational databases within the same unit of work. DUW allows multiple SQL statements within the unit of work, and each SQL statement can be directed to a different database.

Application Requester and Application Server

In all levels of DRDA, SQL statements in an application program residing on a local system request data from a database residing on a remote system. The local system is called the Application Requester (AR) or source system, since it is the source of the SQL statements. The remote system is called the Application Server (AS) or target system, since it is the target of the SQL request from the AR and will serve the request by returning the data that satisfies it. These terms will be used throughout the rest of this discussion. 2 illustrates the concept.

In all levels of DRDA, SQL statements in an application program residing on a local system request data from a database residing on a remote system. The local system is called the Application Requester (AR) or source system, since it is the source of the SQL statements. The remote system is called the Application Server (AS) or target system, since it is the target of the SQL request from the AR and will serve the request by returning the data that satisfies it. These terms will be used throughout the rest of this discussion. Figure 2 illustrates the concept.

DRDA uses SQL statements that originate from an AR to request information from an AS database. DRDA can be used by application programs that contain embedded SQL statements. It can also be used by interactive SQL, Query Manager/400, Query Management/400, and the application programming interfaces(APIs) that access databases for PCs used as workstations. There is no native support (CL commands) for DRDA in DB2/400.

Unit of Work and Remote Unit of Work

To better understand DUW, let's look at unit of work and DRDA Level 1: Remote Unit of Work (RUW). A unit of work is a single transaction from an application program. This transaction can contain one database update or multiple updates that are logically grouped or related. In a commitment control environment, a unit of work is defined as the database updates that occur between COMMIT statements.

DRDA Level 1 supports RUW, which limits the unit of work to one AS database. This means that the application program can be connected to only one AS database at a time. 3 uses your new AS/400 network to illustrate RUW. Note that the transaction from the application program on the AR has several database updates that apply to the AS databases on the Chicago and Dallas systems. RUW limits each unit of work from the AR to a single AS database at a time, so the application transaction in this case has to be split into two separate units of work.

DRDA Level 1 supports RUW, which limits the unit of work to one AS database. This means that the application program can be connected to only one AS database at a time. Figure 3 uses your new AS/400 network to illustrate RUW. Note that the transaction from the application program on the AR has several database updates that apply to the AS databases on the Chicago and Dallas systems. RUW limits each unit of work from the AR to a single AS database at a time, so the application transaction in this case has to be split into two separate units of work.

When the connection is established for the Dallas system, the Chicago system automatically disconnects and ends its communications session with the application on the AR. Each time a connection is made to an AS database, the previous communications session is ended and is disconnected from the application on the AR. A new session is then established for the next AS database. The system resources required to perform these functions can be significant.

Distributed Unit of Work-Application Directed

Because DUW allows an application program to connect to and update multiple relational databases within the same unit of work, it does not end a communications session with an AS database when a connection is made to a different AS database. After the unit of work is completed, two phase commit can be used to ensure that all the databases have been successfully updated. The example for RUW can be changed to illustrate DUW. (See 4.) The application program on the AR applies the same database transactions to the AS databases on the Chicago and Dallas systems. However, unlike RUW, DUW allows a unit of work from the AR to span multiple AS databases, so the application transaction can now be handled as a single unit of work.

Because DUW allows an application program to connect to and update multiple relational databases within the same unit of work, it does not end a communications session with an AS database when a connection is made to a different AS database. After the unit of work is completed, two phase commit can be used to ensure that all the databases have been successfully updated. The example for RUW can be changed to illustrate DUW. (See Figure 4.) The application program on the AR applies the same database transactions to the AS databases on the Chicago and Dallas systems. However, unlike RUW, DUW allows a unit of work from the AR to span multiple AS databases, so the application transaction can now be handled as a single unit of work.

When the connection is made to the Dallas system, the Chicago system is logically disconnected; the physical connection and communications session still exist but are inactive. Under DUW, any communications sessions established with AS databases during a unit of work remain in effect throughout the unit of work, though they are rendered inactive after serving the requested data. Any connection or session can be reactivated by reconnecting to the AS database associated with it. As a result, DUW uses significantly fewer resources than RUW.

Implementation Considerations

When an application program is designed to implement DRDA, the level of DRDA that will be used is specified in a new parameter-RDBCNNMTH-in the Create SQL Program (CRTSQLxxx) command. This parameter has two options: RDBCNNMTH(*RUW)- remote unit of work; and RDBCNNMTH(*DUW)-distributed unit of work (the default value). SQL/400 uses DUW by default and Query Manager has a new feature in V3R1 called a Query Manager Profile that controls the use of DUW and RUW.

Existing DRDA applications may have to be modified to take advantage of DUW. However, the effort will probably be worthwhile because DUW should offer better performance than RUW. This is because of the decrease in system resources required to establish communications sessions.

Now that we have discussed DRDA Level 2 and understand the benefits it provides in a distributed database environment, the next thing to look at is ensuring the integrity of an application transaction in this same environment.

Commitment Control Concepts

As discussed earlier in this article, two phase commit lets DB2/400 apply a single application transaction-which may be composed of several database updates-to two or more databases on multiple systems. It then ensures that all the updates were successfully completed.

To better understand two phase commit, let's look at how single phase commitment control works in conjunction with RUW. Single-Phase Commit was available on earlier versions of the AS/400 database, and is typically used with RUW transactions.

For the purposes of this explanation, let's use the RUW example in 5. The transaction from the application program on the AR has several database transactions that apply to AS databases on the Chicago and Dallas systems. Because RUW limits a unit of work to a single AS database, the application transaction has to be split into two separate units of work. Note that after the SQL statements have been completed for each unit of work, a COMMIT statement is issued to ensure that the database updates have been applied on each AS database.

For the purposes of this explanation, let's use the RUW example in Figure 5. The transaction from the application program on the AR has several database transactions that apply to AS databases on the Chicago and Dallas systems. Because RUW limits a unit of work to a single AS database, the application transaction has to be split into two separate units of work. Note that after the SQL statements have been completed for each unit of work, a COMMIT statement is issued to ensure that the database updates have been applied on each AS database.

Single phase commit cannot ensure the integrity of the entire application transaction because it is composed of two separate units of work, and only a single unit of work can be ensured. If the second unit of work did not complete successfully and was rolled back, the transaction would be in a partially completed state because the first unit of work would have already been committed. To resolve this situation and return the database to its earlier state, the user would have to use journal receiver entries to explicitly remove the database transactions from the Chicago database. Two phase commit and DUW avoid this problem.

Let's look at two phase commit used in conjunction with DUW and see how it ensures the integrity of the entire application transaction. (See 6.) Since DUW is being used, the unit of work can span the AS databases for both Chicago and Dallas. Under two phase commit, only a single COMMIT statement is needed for the entire transaction. The COMMIT statement is issued when the last database update has been applied and the unit of work is completed.

Let's look at two phase commit used in conjunction with DUW and see how it ensures the integrity of the entire application transaction. (See Figure 6.) Since DUW is being used, the unit of work can span the AS databases for both Chicago and Dallas. Under two phase commit, only a single COMMIT statement is needed for the entire transaction. The COMMIT statement is issued when the last database update has been applied and the unit of work is completed.

Two phase commit ensures the completion of the database updates in all the affected AS databases since the entire application transaction is treated as a single unit of work. If a system or resource failure prevents any of the database updates in the unit of work from completing, the updates that have been applied will be rolled back from the affected AS databases automatically.

In the first phase of two phase commit, the AR prepares to perform the commit by asking the AS databases if they have completed their updates and are ready to commit them. If all the affected AS databases respond that they are ready, the second phase occurs and the actual commitment of the database updates takes place on each AS database, as 7 illustrates. If any AS database sends a negative response, the unit of work is rolled back.

In the first phase of two phase commit, the AR prepares to perform the commit by asking the AS databases if they have completed their updates and are ready to commit them. If all the affected AS databases respond that they are ready, the second phase occurs and the actual commitment of the database updates takes place on each AS database, as Figure 7 illustrates. If any AS database sends a negative response, the unit of work is rolled back.

Implementation Considerations

When DB2/400 runs a transaction under two phase commit, it uses journal entries to track the unit of work. Within any unit of work, resynchronization will be required when a resource or system failure occurs during a COMMIT or ROLLBACK operation. When this happens, all database updates in the unit of work will be rolled back if processing has not progressed far enough to make the decision to commit.

Two phase commit is supported by all Distributed Data Management (DDM), DRDA, and CICS/400 applications as well as Intersystem Communication Function (ICF) and Common Programming Interface (CPI-C) communications files. Current applications may have to be modified to take advantage of the facility. Applications need to have one or more commits removed to take advantage of this facility.

Now that you have an understanding of DRDA Level 2 and two phase commit, let's see how they would be used to solve the problems of connecting to and communicating with the three AS/400s in the network and maintaining the inventory database when it is distributed across these three systems.

Advanced Database Functions

8 illustrates how DRDA Level 2 and two phase commit would be implemented within an application program that accesses and updates the inventory databases on multiple systems. Used as illustrated, it solves the problems of connecting to each system in the distributed network and ensures the integrity of the inventory database transactions across the systems.

Figure 8 illustrates how DRDA Level 2 and two phase commit would be implemented within an application program that accesses and updates the inventory databases on multiple systems. Used as illustrated, it solves the problems of connecting to each system in the distributed network and ensures the integrity of the inventory database transactions across the systems.

DUW uses SQL to allow the application on the New York home office system to connect to and update the distributed inventory databases on the New York, Chicago, and Dallas systems within the same unit of work. Under DUW, all communications sessions established remain in effect during the unit of work, though they are rendered inactive after serving the requested data. Any session can be reactivated by reconnecting to the AS database in question. As a result, DRDA Level 2 DUW provides better application performance and uses significantly fewer resources than its predecessor DRDA Level 1 RUW.

Two phase commit lets DB2/400 apply a single application transaction running on the New York home office system (which can be composed of several database updates) to the distributed inventory database on the New York, Chicago, and Dallas systems, and ensures that all the updates were successfully completed. If an update to any database is not completed successfully, updates are automatically rolled back from all the other databases participating in the transaction.

Thus, DRDA Level 2 DUW and two phase commit-two of the new, advanced functions of DB2/400-can be used to design and implement an efficient application solution in the distributed database environment.

Skip Marchesani is the author of DB2/400: The New AS/400 Database. He can be reached through Midrange Computing.


DRDA Lvl 2 & Two Phase Commitment Cntrl in DB2/400

Figure 1 Multiple Systems Database

 UNABLE TO REPRODUCE GRAPHICS 
DRDA Lvl 2 & Two Phase Commitment Cntrl in DB2/400

Figure 1 Demonstrating the Inventory Application

 UNABLE TO REPRODUCE GRAPHICS 
DRDA Lvl 2 & Two Phase Commitment Cntrl in DB2/400

Figure 2 Application Requester and Application Server

 UNABLE TO REPRODUCE GRAPHICS 
DRDA Lvl 2 & Two Phase Commitment Cntrl in DB2/400

Figure 3 Remote Unit of Work

 UNABLE TO REPRODUCE GRAPHICS 
DRDA Lvl 2 & Two Phase Commitment Cntrl in DB2/400

Figure 4 Distributed Unit of Work

 UNABLE TO REPRODUCE GRAPHICS 
DRDA Lvl 2 & Two Phase Commitment Cntrl in DB2/400

Figure 5 Single Phase Commit and Remote Unit of Work

 UNABLE TO REPRODUCE GRAPHICS 
DRDA Lvl 2 & Two Phase Commitment Cntrl in DB2/400

Figure 6 DRDA Level 2 and Two Phase Commit

 UNABLE TO REPRODUCE GRAPHICS 
DRDA Lvl 2 & Two Phase Commitment Cntrl in DB2/400

Figure 7 The Two Phases of Two Phase Commit

 UNABLE TO REPRODUCE GRAPHICS 
BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  • SB Profound WC 5536 Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application. You can find Part 1 here. In Part 2 of our free Node.js Webinar Series, Brian May teaches you the different tooling options available for writing code, debugging, and using Git for version control. Brian will briefly discuss the different tools available, and demonstrate his preferred setup for Node development on IBM i or any platform. Attend this webinar to learn:

  • SB Profound WP 5539More than ever, there is a demand for IT to deliver innovation. Your IBM i has been an essential part of your business operations for years. However, your organization may struggle to maintain the current system and implement new projects. The thousands of customers we've worked with and surveyed state that expectations regarding the digital footprint and vision of the company are not aligned with the current IT environment.

  • SB HelpSystems ROBOT Generic IBM announced the E1080 servers using the latest Power10 processor in September 2021. The most powerful processor from IBM to date, Power10 is designed to handle the demands of doing business in today’s high-tech atmosphere, including running cloud applications, supporting big data, and managing AI workloads. But what does Power10 mean for your data center? In this recorded webinar, IBMers Dan Sundt and Dylan Boday join IBM Power Champion Tom Huntington for a discussion on why Power10 technology is the right strategic investment if you run IBM i, AIX, or Linux. In this action-packed hour, Tom will share trends from the IBM i and AIX user communities while Dan and Dylan dive into the tech specs for key hardware, including:

  • Magic MarkTRY the one package that solves all your document design and printing challenges on all your platforms. Produce bar code labels, electronic forms, ad hoc reports, and RFID tags – without programming! MarkMagic is the only document design and print solution that combines report writing, WYSIWYG label and forms design, and conditional printing in one integrated product. Make sure your data survives when catastrophe hits. Request your trial now!  Request Now.

  • SB HelpSystems ROBOT GenericForms of ransomware has been around for over 30 years, and with more and more organizations suffering attacks each year, it continues to endure. What has made ransomware such a durable threat and what is the best way to combat it? In order to prevent ransomware, organizations must first understand how it works.

  • SB HelpSystems ROBOT GenericIT security is a top priority for businesses around the world, but most IBM i pros don’t know where to begin—and most cybersecurity experts don’t know IBM i. In this session, Robin Tatam explores the business impact of lax IBM i security, the top vulnerabilities putting IBM i at risk, and the steps you can take to protect your organization. If you’re looking to avoid unexpected downtime or corrupted data, you don’t want to miss this session.

  • SB HelpSystems ROBOT GenericCan you trust all of your users all of the time? A typical end user receives 16 malicious emails each month, but only 17 percent of these phishing campaigns are reported to IT. Once an attack is underway, most organizations won’t discover the breach until six months later. A staggering amount of damage can occur in that time. Despite these risks, 93 percent of organizations are leaving their IBM i systems vulnerable to cybercrime. In this on-demand webinar, IBM i security experts Robin Tatam and Sandi Moore will reveal:

  • FORTRA Disaster protection is vital to every business. Yet, it often consists of patched together procedures that are prone to error. From automatic backups to data encryption to media management, Robot automates the routine (yet often complex) tasks of iSeries backup and recovery, saving you time and money and making the process safer and more reliable. Automate your backups with the Robot Backup and Recovery Solution. Key features include:

  • FORTRAManaging messages on your IBM i can be more than a full-time job if you have to do it manually. Messages need a response and resources must be monitored—often over multiple systems and across platforms. How can you be sure you won’t miss important system events? Automate your message center with the Robot Message Management Solution. Key features include:

  • FORTRAThe thought of printing, distributing, and storing iSeries reports manually may reduce you to tears. Paper and labor costs associated with report generation can spiral out of control. Mountains of paper threaten to swamp your files. Robot automates report bursting, distribution, bundling, and archiving, and offers secure, selective online report viewing. Manage your reports with the Robot Report Management Solution. Key features include:

  • FORTRAFor over 30 years, Robot has been a leader in systems management for IBM i. With batch job creation and scheduling at its core, the Robot Job Scheduling Solution reduces the opportunity for human error and helps you maintain service levels, automating even the biggest, most complex runbooks. Manage your job schedule with the Robot Job Scheduling Solution. Key features include:

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • LANSAWhen it comes to creating your business applications, there are hundreds of coding platforms and programming languages to choose from. These options range from very complex traditional programming languages to Low-Code platforms where sometimes no traditional coding experience is needed. Download our whitepaper, The Power of Writing Code in a Low-Code Solution, and:

  • LANSASupply Chain is becoming increasingly complex and unpredictable. From raw materials for manufacturing to food supply chains, the journey from source to production to delivery to consumers is marred with inefficiencies, manual processes, shortages, recalls, counterfeits, and scandals. In this webinar, we discuss how:

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • Profound Logic Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application.

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: