In this multi-part post, I’m explaining the basics behind how SAP Replication Server works when replicating from a SAP ASE database to a SAP ASE database as part of an HADR (ASE always-on) setup for a SAP Business Suite system. The post will be based on SAP ASE (Adaptive Server Enterprise) 16.0 HADR with SAP Replication Server (SRS) 16.0.
In Part 1 we started with:
What is SRS.
The basic premise of HADR with SRS.
What a transaction is.
In Part 2 we went on to discuss:
What is the ASE transaction log.
Which databases are replicated.
How do transactions move to the SRS.
In Part 3 we covered:
What is the Active SRS.
What are the Key Parts of SRS.
Replication Synchronisation Modes
Open Transaction Handling
What are the Implications of Replication Delay
In this penultimate part we step through the process of replication for an individual transaction, looking at how each of the previously discussed components plays it part along the way.
Step 1 -Begin Transaction
In the first step, our SAP Business Suite application is being used by Bob, our end-user. Bob has a screen open and saves a change to an item of data. The Business Suite application calls the Netweaver application stack to persist the change to the data according to the application’s dictionary model. The dictionary dictates the relationship of the business object (e.g. an invoice) to the relational database tables. The Netweaver code uses the SAP Kernel supplied libraries to save the change to the necessary system database tables.
There could be many tables involved in Bob’s one change. It would not be right to update just one table without also updating the others that are related. Otherwise we would not have consistency. For this reason, a single database transaction can include many data manipulation language (DML) statements. By grouping the DML statements for the related table updates into a single database transaction, the SAP Kernel can enforce consistency.
In our example, our transaction will include updates to 2 different tables: tableA and tableB. To designate the start of the database transaction, the SAP Kernel calls the database library to “BEGIN TRANSACTION”.
The affect of the database call to “BEGIN TRANSACTION”, is that a new transaction log record is OPENened:
Step 2 – Replication Agent – Open Transaction
Once a transaction has started (opened), the ASE HADR Replication Agent will see it. Remember, we discussed the Replication Agent in Part 2 .
The Replication Agent sends the transaction data across the network to the target SAP Replication Server (SRS). It knows where to send the data because of the configuration applied to the Replication Agent during the HADR setup process.
The SRS receives the data from the Replication Agent and writes it to the Simple Persistent Queue (SPQ), then sends an acknowledgement back to the Replication Agent.
Step 3a – Update Tables – DML
So far, all that has happened is a new transaction has been opened. Now Netweaver will apply the required DML to the transaction:
UPDATE tableA SET column1=”ABC” UPDATE tableB SET column1=”123″
The Kernel will apply the required DML to the opened transaction, this will also update the transaction log, which will be seen by the Replication Agent and sent across to the SRS as before.
You will notice that at this point, we are still using transaction log space, but we are also consuming space in the SPQ.
At this step, if one of the required “UPDATE” statements was to fail, then the whole transaction could be cancelled (a rollback) and no changes would be permanently made to any of the tables. This is one of the requirements of the ACID principles.
Step 3b – The SRS Inbound Queue
At the same time as the DML is being applied to the open transaction in step 3a, the SRS continues to process the open transaction.
Inside the SRS, there are various component modules that process the incoming transactions from the SPQ, placing them in the correct order and compacting them (grouping) into larger, more efficient transactions. Once this initial processing has completed, the new transaction is placed into the inbound queue (IBQ).
Something you will notice, is that we now have consumed space in:
Primary database transaction log.
Simple Persistent Queue.
Inbound Queue.
Once the transaction is safely persisted into the IBQ, the record in the SPQ is now free for re-use.
Step 4 – End Transaction
In steps 3a and 3b, we see the opening transaction record and the DML move across to the SRS. At this point in time, Bob’s changes are still not replicated to the companion (secondary/standby) database. In fact, Bob’s changes are not even visible to other users of the primary database, because Bob’s changes are not yet committed.
Once all the DML in Bob’s transaction has been applied at the primary database successfully (still not committed), then the SAP Kernel can issue the “END TRANSACTION”. This signifies that this group of changes are finished. After the “END TRANSACTION”, the SAP Kernel can issue one of two things; a “COMMIT” or a “ROLLBACK”. In our case, the Kernel issues a “COMMIT”.
The “COMMIT” on the primary database is now performed, at the same time, the “COMMIT” record is also sent by the Replication Agent to the SPQ of the SRS.
I can hear the DB experts gasp at this point! Yes, in Part 3 I mentioned that the commit is not allowed on the primary until after the Replication Agent has successfully sent the commit to the SPQ. In actual fact, this is not a hard and fast rule. The Replication Agent will attempt to send the commit record to the SPQ; it will wait for a given amount of time, before switching to asynchronous replication mode (see Part 3 for a description of this mode). The commit to the primary database is therefore allowed to happen, even if it has not yet been acknowledged by the SPQ. This is the trade-off between performance and protection. The HADR solution has flexibility that allows a configurable amount of replication delay before synchronous replication is switched to asynchronous.
The acknowledgement that the “COMMIT” record has been successfully stored in the SRS SPQ, allows the primary database Replication Agent to move the Secondary Truncation Point (STP) forward and release the transaction log record, which allows it to be freed when the next “DUMP TRANSACTION” (transaction log backup) is performed.
The primary database data change becomes visible to all users of the database. Bob’s screen returns a message telling him that his data is saved.
Step 5 – The SRS Outbound Queue
Inside the SRS IBQ, all of our transaction is now complete, we have a “BEGIN” and an “END”, a “COMMIT” and some DML in between that contains the updates to the required tables.
Once the “COMMIT” record is seen by the Inbound Queue (IBQ) of the SRS, then the SRS will process the re-packaged transaction from the IBQ to the Outbound Queue (OBQ).
This processing could involve adjusting the SQL language used, if the target database is not ASE.
From the OBQ, the Data Server Interface (DSI) component of the SRS, applies the transaction to the target database.
Finally, the replicated transaction data is applied to the target secondary database and harmony is achieved.
Bob’s View
Throughout this whole replication cycle, Bob had no idea that his data was being replicated to the target secondary database hundreds of kilometres away. The response time of the database to the SAP Kernel was only slightly impacted by the addition of the Replication Agent processing time, plus the network transfer time to the active SRS, plus the processing and persistence time to the SPQ of the SRS.
As well as the response time, we noticed how the storage requirements of the SRS are bigger than the actual transaction log of the primary database due to the way the transaction is processed/transformed and re-processed through the SRS, then queued for application to the target database.
In the final part 5 , I will discuss some common issues that can occur with HADR, allowing you to comprehensively plan your operational acceptance testing.